Track dependencies when reading notice files
Track which files are read by the notice file indexer and add a flag
to textnotice and htmlnotice to support writing them out.
Bug: 207445310
Test: textnotice_test
Test: htmlnotice_test
Change-Id: Ib74706b8a87a5ed9268a0fe37982ecf89f4e227d
diff --git a/tools/compliance/cmd/textnotice/textnotice.go b/tools/compliance/cmd/textnotice/textnotice.go
index b89aff1..eebb13d 100644
--- a/tools/compliance/cmd/textnotice/textnotice.go
+++ b/tools/compliance/cmd/textnotice/textnotice.go
@@ -25,10 +25,13 @@
"strings"
"android/soong/tools/compliance"
+
+ "github.com/google/blueprint/deptools"
)
var (
outputFile = flag.String("o", "-", "Where to write the NOTICE text file. (default stdout)")
+ depsFile = flag.String("d", "", "Where to write the deps file")
stripPrefix = flag.String("strip_prefix", "", "Prefix to remove from paths. i.e. path to root")
failNoneRequested = fmt.Errorf("\nNo license metadata files requested")
@@ -40,6 +43,7 @@
stderr io.Writer
rootFS fs.FS
stripPrefix string
+ deps *[]string
}
func init() {
@@ -90,7 +94,9 @@
ofile = &bytes.Buffer{}
}
- ctx := &context{ofile, os.Stderr, os.DirFS("."), *stripPrefix}
+ var deps []string
+
+ ctx := &context{ofile, os.Stderr, os.DirFS("."), *stripPrefix, &deps}
err := textNotice(ctx, flag.Args()...)
if err != nil {
@@ -107,6 +113,13 @@
os.Exit(1)
}
}
+ if *depsFile != "" {
+ err := deptools.WriteDepFile(*depsFile, *outputFile, deps)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "could not write deps to %q: %s\n", *depsFile, err)
+ os.Exit(1)
+ }
+ }
os.Exit(0)
}
@@ -150,5 +163,8 @@
ctx.stdout.Write(ni.HashText(h))
fmt.Fprintln(ctx.stdout)
}
+
+ *ctx.deps = ni.InputNoticeFiles()
+
return nil
}