diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2025-07-31 14:37:16 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2025-08-05 13:17:38 +0000 |
| commit | 9e53e3a878f64a974f33589b6f3f1e84c38313c5 (patch) | |
| tree | a50198bc6857bcfc44aaca9a09e820b69859806f /pkg/manager/diff.go | |
| parent | 1458b364e100752374725b0cbf83b70a54b327d3 (diff) | |
pkg/manager: remove a dependency on grep
Instead of calling grep (the implementations of which may differ in
different environments), traverse the directory and grep files with a
special pkg/osutil helper functionality.
Diffstat (limited to 'pkg/manager/diff.go')
| -rw-r--r-- | pkg/manager/diff.go | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/pkg/manager/diff.go b/pkg/manager/diff.go index 6de92e340..ae05f7a97 100644 --- a/pkg/manager/diff.go +++ b/pkg/manager/diff.go @@ -816,25 +816,21 @@ func affectedFiles(cfg *mgrconfig.Config, gitPatches [][]byte) (direct, transiti for _, file := range allFiles { directMap[file] = struct{}{} if strings.HasSuffix(file, ".h") && cfg.KernelSrc != "" { + // For .h files, we want to determine all the .c files that include them. // Ideally, we should combine this with the recompilation process - then we know // exactly which files were affected by the patch. - out, err := osutil.RunCmd(time.Minute, cfg.KernelSrc, "/usr/bin/grep", - "-rl", "--include", `*.c`, `<`+strings.TrimPrefix(file, "include/")+`>`) + matching, err := osutil.GrepFiles(cfg.KernelSrc, `.c`, + []byte(`<`+strings.TrimPrefix(file, "include/")+`>`)) if err != nil { - log.Logf(0, "failed to grep for the header usages: %v", err) + log.Logf(0, "failed to grep for includes: %s", err) continue } - lines := strings.Split(string(out), "\n") - if len(lines) >= maxAffectedByHeader { + if len(matching) >= maxAffectedByHeader { // It's too widespread. It won't help us focus on anything. - log.Logf(0, "the header %q is included in too many files (%d)", file, len(lines)) + log.Logf(0, "the header %q is included in too many files (%d)", file, len(matching)) continue } - for _, name := range lines { - name = strings.TrimSpace(name) - if name == "" { - continue - } + for _, name := range matching { transitiveMap[name] = struct{}{} } } |
