@@ -311,6 +311,8 @@ func ExtractWithFlags(buildFlags []string, patterns []string, extractTests bool)
311311
312312 extraction .WaitGroup .Wait ()
313313
314+ util .WriteOverlayBaseMetadata ()
315+
314316 log .Println ("Done extracting packages." )
315317
316318 t := time .Now ()
@@ -323,16 +325,17 @@ func ExtractWithFlags(buildFlags []string, patterns []string, extractTests bool)
323325type Extraction struct {
324326 // A lock for preventing concurrent writes to maps and the stat trap writer, as they are not
325327 // thread-safe
326- Lock sync.Mutex
327- LabelKey string
328- Label trap.Label
329- StatWriter * trap.Writer
330- WaitGroup sync.WaitGroup
331- GoroutineSem * semaphore
332- FdSem * semaphore
333- NextFileId int
334- FileInfo map [string ]* FileInfo
335- SeenGoMods map [string ]bool
328+ Lock sync.Mutex
329+ LabelKey string
330+ Label trap.Label
331+ StatWriter * trap.Writer
332+ WaitGroup sync.WaitGroup
333+ GoroutineSem * semaphore
334+ FdSem * semaphore
335+ NextFileId int
336+ FileInfo map [string ]* FileInfo
337+ SeenGoMods map [string ]bool
338+ OverlayChanges map [string ]bool
336339}
337340
338341type FileInfo struct {
@@ -379,6 +382,21 @@ func NewExtraction(buildFlags []string, patterns []string) *Extraction {
379382 }
380383 sum := hash .Sum (nil )
381384
385+ overlayChangeList := util .GetOverlayChanges ()
386+ var overlayChanges map [string ]bool
387+ if overlayChangeList == nil {
388+ overlayChanges = nil
389+ } else {
390+ overlayChanges = make (map [string ]bool )
391+ for _ , changedFilePath := range overlayChangeList {
392+ absPath , err := filepath .Abs (changedFilePath )
393+ if err != nil {
394+ log .Fatalf ("Error resolving absolute path of overlay change %s: %s" , changedFilePath , err .Error ())
395+ }
396+ overlayChanges [absPath ] = true
397+ }
398+ }
399+
382400 i := 0
383401 var path string
384402 // split compilation files into directories to avoid filling a single directory with too many files
@@ -438,10 +456,11 @@ func NewExtraction(buildFlags []string, patterns []string) *Extraction {
438456 FdSem : newSemaphore (100 ),
439457 // this semaphore is used to limit the number of goroutines spawned, so we
440458 // don't run into memory issues
441- GoroutineSem : newSemaphore (MaxGoRoutines ),
442- NextFileId : 0 ,
443- FileInfo : make (map [string ]* FileInfo ),
444- SeenGoMods : make (map [string ]bool ),
459+ GoroutineSem : newSemaphore (MaxGoRoutines ),
460+ NextFileId : 0 ,
461+ FileInfo : make (map [string ]* FileInfo ),
462+ SeenGoMods : make (map [string ]bool ),
463+ OverlayChanges : overlayChanges ,
445464 }
446465}
447466
@@ -720,6 +739,10 @@ func (extraction *Extraction) extractFile(ast *ast.File, pkg *packages.Package)
720739 return nil
721740 }
722741 path := normalizedPath (ast , fset )
742+ if extraction .OverlayChanges != nil && ! extraction .OverlayChanges [path ] {
743+ // This file did not change since the base was extracted
744+ return nil
745+ }
723746
724747 extraction .FdSem .acquire (3 )
725748
0 commit comments