File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -732,8 +732,13 @@ func (extraction *Extraction) extractFile(ast *ast.File, pkg *packages.Package)
732732 return nil
733733 }
734734 path := normalizedPath (ast , fset )
735- if extraction .OverlayChanges != nil && ! extraction .OverlayChanges [path ] {
736- // This file did not change since the base was extracted
735+ // If we're extracting an overlay, we want to skip extraction of files that haven't changed.
736+ // Since some files may be outside the source directory (e.g. files preprocessed by cgo) we
737+ // can't easily know if they have changed (or came from source files that changed), so we always
738+ // extract a file if it's not in the package directory.
739+ if extraction .OverlayChanges != nil &&
740+ ! extraction .OverlayChanges [path ] &&
741+ strings .HasPrefix (path + string (filepath .Separator ), pkg .Dir ) {
737742 return nil
738743 }
739744
Original file line number Diff line number Diff line change @@ -23,13 +23,30 @@ private predicate discardableLocatable(@file file, @locatable locatable) {
2323 file = getFile ( locatable )
2424}
2525
26+ /**
27+ * Holds if the given `path` is for a file in the base database whose entities should be discarded.
28+ */
29+ bindingset [ path]
30+ private predicate discardableFile ( string path ) {
31+ isOverlay ( ) and
32+ (
33+ overlayChangedFiles ( path )
34+ or
35+ // The extractor unconditionally extracts files outside of the source directory (these are
36+ // typically cgo-processed source files), so all entities in such files should be discarded.
37+ not exists ( string srcLoc | sourceLocationPrefix ( srcLoc ) |
38+ path .substring ( 0 , srcLoc .length ( ) ) = srcLoc
39+ )
40+ )
41+ }
42+
2643/**
2744 * Holds if the given `locatable` should be discarded, because it is part of the overlay base and is
2845 * in a file that was also extracted as part of the overlay database.
2946 */
3047overlay [ discard_entity]
3148private predicate discardLocatable ( @locatable locatable ) {
3249 exists ( @file file , string path | files ( file , path ) |
33- discardableLocatable ( file , locatable ) and overlayChangedFiles ( path )
50+ discardableLocatable ( file , locatable ) and discardableFile ( path )
3451 )
3552}
You can’t perform that action at this time.
0 commit comments