Documentation
¶
Index ¶
- func CleanOrphanedFiles(ctx context.Context, outDir string, newFiles []string, previousFiles []string, ...) error
- func CleanOrphanedFilesByDirWalk(ctx context.Context, outDir string, subDir string, ...) error
- type AddHeaderPattern
- type FileTrackerResult
- type Ignore
- type OnWriteFileFunc
- type Options
- type Tracker
- func (t *Tracker) AddHeaderToFile(file string) bool
- func (t *Tracker) AddUntrackedPattern(pattern *regexp.Regexp)
- func (t *Tracker) Close(ctx context.Context)
- func (t *Tracker) GetResult() FileTrackerResult
- func (t *Tracker) IsUntrackedPatternFile(file string) bool
- func (t *Tracker) TrackFile(file string, data []byte)
- func (t *Tracker) TrackFileImmediate(file string, data []byte) error
- func (t *Tracker) UntrackFile(path string)
- func (t *Tracker) UpdateTrackedFile(path string, id, pristineGitObject string)
- func (t *Tracker) UpdateTrackedFileChecksum(path string, data []byte)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanOrphanedFiles ¶
func CleanOrphanedFiles( ctx context.Context, outDir string, newFiles []string, previousFiles []string, untrackedPatterns []*regexp.Regexp, ignore *Ignore, onRemovedFile func(string), ) error
CleanOrphanedFiles removes any previously generated files that are no longer being generated in a subsequent generation run. These orphaned files cannot stay behind because they can accidentally break builds or augment an SDK's behavior or public interface in unexpected ways.
func CleanOrphanedFilesByDirWalk ¶
func CleanOrphanedFilesByDirWalk( ctx context.Context, outDir string, subDir string, trackedFiles map[string]struct{}, skipSubDirs []string, untrackedPatterns []*regexp.Regexp, ignore *Ignore, onRemovedFile func(string), ) error
CleanOrphanedFilesByDirWalk removes any file under subDir (relative to outDir) that is not present in trackedFiles, ignoring matches against .genignore or untrackedPatterns. Paths in trackedFiles and the keys passed to ignore must be relative to outDir using forward slashes.
skipSubDirs lists directory paths relative to subDir that should not be traversed at all. Useful for subtrees populated by direct file copies that bypass the file tracker, where every entry would otherwise look like an orphan.
Unlike CleanOrphanedFiles, this is anchored to disk state rather than a prior gen.lock, so it removes files that were never recorded in gen.lock for any reason. Callers should only invoke this for subtrees that are fully owned by the generator (e.g. generated test infrastructure).
Types ¶
type AddHeaderPattern ¶
type FileTrackerResult ¶
type FileTrackerResult struct {
NewFiles config.TrackedFiles
PreviousFiles []string
}
type Ignore ¶
type Ignore struct {
// contains filtered or unexported fields
}
Ignore encapsulates zero or more .genignore files and provides the ShouldIgnore method to check whether a given file matches the .genignore loaded files.
func NewIgnore ¶
func NewIgnore() *Ignore
NewIgnore creates an empty Ignore struct. You will need to call AddGenIgnoreFile to add .genignore files to it.
func NewIgnoreFromRoot ¶
NewIgnoreFromRoot creates an Ignore struct by walking the given root directory and adding any .genignore files it finds.
func (*Ignore) AddGenIgnoreFile ¶
AddGenIgnoreFile adds a .genignore file to the Ignore struct. The root parameter is the root directory of the project, and genFile is the path to the .genignore file relative to the root.
func (*Ignore) AddIgnoreOverride ¶
Add a regex pattern that will not be ignored even if its present in the .genignore file
func (*Ignore) HasIgnoredFiles ¶
func (*Ignore) ShouldIgnore ¶
ShouldIgnore returns true if the given path should be ignored, false otherwise.
type OnWriteFileFunc ¶
type Options ¶
type Options struct {
OutDir string
GenLockId string
FS filesystem.FileSystem
// SkipTempLockFile skips writing to the temporary lock file during generation.
// When persistent edits is enabled, files are collected in memory and written
// atomically at the end, so the incremental crash-recovery lock file is unnecessary.
// We still read any existing lock file for orphan cleanup from previous crashes.
SkipTempLockFile bool
// SkipChecksums skips computing and recording last_write_checksum for tracked
// files. When persistent edits is explicitly disabled (enabled: never) nothing
// consumes the checksums, and omitting them keeps gen.lock stable across
// regenerations so parallel branches don't merge-conflict on checksum churn.
SkipChecksums bool
}
type Tracker ¶
type Tracker struct {
// List of file path regular expressions that should not be tracked.
// Automatically instantiated with files such as README.md, .gitignore,
// documentation theme files, and others in [NewTracker]. Targets can
// dynamically add to these via AddUntrackedPattern.
UntrackedPatterns []*regexp.Regexp
// List of file path regular expressions that should not have a header.
AddHeaderPatterns []*AddHeaderPattern
Options Options
// contains filtered or unexported fields
}
Tracker keeps track of all the files created either by generating file content by executing a template or by copying a file. Tracked files are then written to a file called files.gen in the root of the output directory.
func NewTracker ¶
NewTracker creates a new Tracker.
func (*Tracker) AddHeaderToFile ¶
AddHeaderToFile returns true if the file requires a header.
func (*Tracker) AddUntrackedPattern ¶
AddUntrackedPattern appends a compiled regex to the untracked patterns list. It is safe for concurrent use.
func (*Tracker) GetResult ¶
func (t *Tracker) GetResult() FileTrackerResult
func (*Tracker) IsUntrackedPatternFile ¶
IsUntrackedPatternFile returns true if the file matches any regular expressions in the Tracker UntrackedPatterns.
func (*Tracker) TrackFile ¶
TrackFile is called for each generated file that needs to be tracked in the generatedFiles section in the gen.lock file. Some special file names are ignored.
func (*Tracker) TrackFileImmediate ¶
TrackFileImmediate records a generated file outside the normal template tracking channel.
func (*Tracker) UntrackFile ¶
UntrackFile removes a generated file from the current run's tracked set. This is used when a patch file deletes a virtual file after templates have already reported it to the tracker. The removal goes through the tracking channel so it is ordered after any in-flight TrackFile for the same path; once the channel is drained (GetResult) it falls back to a direct delete.
func (*Tracker) UpdateTrackedFile ¶
UpdateTrackedFile updates a tracked file entry with ID and PristineGitObject metadata. This is used by the patches subsystem after the 3-way merge completes.
func (*Tracker) UpdateTrackedFileChecksum ¶
UpdateTrackedFileChecksum updates the checksum for a tracked file. This is used after compilation modifies files to ensure gen.lock checksums match the post-compile file content.