Skip to content

Commit 0874156

Browse files
committed
pkg/aflow/action/kernel: keep build files that codesearch will need
We currently duplicate list of source extensions in the build action and codesearch tool. Unify the lists.
1 parent 5492569 commit 0874156

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

pkg/aflow/action/kernel/build.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/google/syzkaller/pkg/aflow"
1616
"github.com/google/syzkaller/pkg/build"
17+
"github.com/google/syzkaller/pkg/codesearch"
1718
"github.com/google/syzkaller/pkg/hash"
1819
"github.com/google/syzkaller/pkg/osutil"
1920
"github.com/google/syzkaller/sys/targets"
@@ -50,17 +51,23 @@ func buildKernel(ctx *aflow.Context, args buildArgs) (buildResult, error) {
5051
return aflow.FlowError(err)
5152
}
5253
// Remove main intermediate build files, we don't need them anymore
53-
// and they take lots of space. Keep generated source files.
54-
keepExt := map[string]bool{".h": true, ".c": true, ".s": true, ".S": true}
54+
// and they take lots of space. But keep generated source files.
5555
keepFiles := map[string]bool{
56-
filepath.Join(dir, image): true,
57-
filepath.Join(dir, target.KernelObject): true,
58-
filepath.Join(dir, compileCommnads): true,
56+
image: true,
57+
target.KernelObject: true,
58+
compileCommnads: true,
5959
}
6060
return filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
61-
if err != nil || d.IsDir() || keepFiles[path] || keepExt[filepath.Ext(d.Name())] {
61+
if err != nil {
6262
return err
6363
}
64+
relative, err := filepath.Rel(dir, path)
65+
if err != nil {
66+
return err
67+
}
68+
if d.IsDir() || keepFiles[relative] || codesearch.IsSourceFile(relative) {
69+
return nil
70+
}
6471
return os.Remove(path)
6572
})
6673
})

pkg/codesearch/codesearch.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,17 @@ var Commands = []Command{
8282
}},
8383
}
8484

85-
var SourceExtensions = map[string]bool{".c": true, ".h": true, ".S": true, ".rs": true}
85+
func IsSourceFile(file string) bool {
86+
return sourceFiles[file] || sourceExtensions[filepath.Ext(file)]
87+
}
88+
89+
var (
90+
// Files and extensions we want to keep in the build dir and make available to LLM agents.
91+
sourceExtensions = map[string]bool{".c": true, ".h": true, ".S": true, ".rs": true}
92+
sourceFiles = map[string]bool{
93+
".config": true,
94+
}
95+
)
8696

8797
func NewIndex(databaseFile string, srcDirs []string) (*Index, error) {
8898
db, err := osutil.ReadJSON[*Database](databaseFile)
@@ -275,6 +285,7 @@ func escaping(path string) error {
275285
}
276286

277287
func dirIndex(root, subdir string) (bool, []string, []string, error) {
288+
subdir = filepath.Clean(subdir)
278289
dir := filepath.Join(root, subdir)
279290
entries, err := os.ReadDir(dir)
280291
if err != nil {
@@ -293,7 +304,7 @@ func dirIndex(root, subdir string) (bool, []string, []string, error) {
293304
// These are internal things like .git, etc.
294305
} else if entry.IsDir() {
295306
subdirs = append(subdirs, entry.Name())
296-
} else if SourceExtensions[filepath.Ext(entry.Name())] {
307+
} else if IsSourceFile(filepath.Join(subdir, entry.Name())) {
297308
files = append(files, entry.Name())
298309
}
299310
}

0 commit comments

Comments
 (0)