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_test.go b/tools/compliance/cmd/textnotice/textnotice_test.go
index 7993532..39f711d 100644
--- a/tools/compliance/cmd/textnotice/textnotice_test.go
+++ b/tools/compliance/cmd/textnotice/textnotice_test.go
@@ -19,6 +19,7 @@
"bytes"
"fmt"
"os"
+ "reflect"
"regexp"
"strings"
"testing"
@@ -40,11 +41,12 @@
func Test(t *testing.T) {
tests := []struct {
- condition string
- name string
- roots []string
- stripPrefix string
- expectedOut []matcher
+ condition string
+ name string
+ roots []string
+ stripPrefix string
+ expectedOut []matcher
+ expectedDeps []string
}{
{
condition: "firstparty",
@@ -60,6 +62,7 @@
usedBy{"highest.apex/lib/libb.so"},
firstParty{},
},
+ expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"},
},
{
condition: "firstparty",
@@ -75,6 +78,7 @@
usedBy{"container.zip/libb.so"},
firstParty{},
},
+ expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"},
},
{
condition: "firstparty",
@@ -86,6 +90,7 @@
usedBy{"application"},
firstParty{},
},
+ expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"},
},
{
condition: "firstparty",
@@ -97,6 +102,7 @@
usedBy{"bin/bin1"},
firstParty{},
},
+ expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"},
},
{
condition: "firstparty",
@@ -108,6 +114,7 @@
usedBy{"lib/libd.so"},
firstParty{},
},
+ expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"},
},
{
condition: "notice",
@@ -129,6 +136,10 @@
usedBy{"highest.apex/bin/bin1"},
notice{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/notice/NOTICE_LICENSE",
+ },
},
{
condition: "notice",
@@ -150,6 +161,10 @@
usedBy{"container.zip/bin1"},
notice{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/notice/NOTICE_LICENSE",
+ },
},
{
condition: "notice",
@@ -165,6 +180,10 @@
usedBy{"application"},
notice{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/notice/NOTICE_LICENSE",
+ },
},
{
condition: "notice",
@@ -182,6 +201,10 @@
usedBy{"bin/bin1"},
notice{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/notice/NOTICE_LICENSE",
+ },
},
{
condition: "notice",
@@ -193,6 +216,7 @@
usedBy{"lib/libd.so"},
notice{},
},
+ expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"},
},
{
condition: "reciprocal",
@@ -214,6 +238,10 @@
usedBy{"highest.apex/bin/bin1"},
reciprocal{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/reciprocal/RECIPROCAL_LICENSE",
+ },
},
{
condition: "reciprocal",
@@ -235,6 +263,10 @@
usedBy{"container.zip/bin1"},
reciprocal{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/reciprocal/RECIPROCAL_LICENSE",
+ },
},
{
condition: "reciprocal",
@@ -250,6 +282,10 @@
usedBy{"application"},
reciprocal{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/reciprocal/RECIPROCAL_LICENSE",
+ },
},
{
condition: "reciprocal",
@@ -267,6 +303,10 @@
usedBy{"bin/bin1"},
reciprocal{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/reciprocal/RECIPROCAL_LICENSE",
+ },
},
{
condition: "reciprocal",
@@ -278,6 +318,9 @@
usedBy{"lib/libd.so"},
notice{},
},
+ expectedDeps: []string{
+ "testdata/notice/NOTICE_LICENSE",
+ },
},
{
condition: "restricted",
@@ -303,6 +346,11 @@
usedBy{"highest.apex/bin/bin1"},
reciprocal{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/reciprocal/RECIPROCAL_LICENSE",
+ "testdata/restricted/RESTRICTED_LICENSE",
+ },
},
{
condition: "restricted",
@@ -328,6 +376,11 @@
usedBy{"container.zip/bin1"},
reciprocal{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/reciprocal/RECIPROCAL_LICENSE",
+ "testdata/restricted/RESTRICTED_LICENSE",
+ },
},
{
condition: "restricted",
@@ -343,6 +396,10 @@
usedBy{"application"},
restricted{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/restricted/RESTRICTED_LICENSE",
+ },
},
{
condition: "restricted",
@@ -362,6 +419,11 @@
usedBy{"bin/bin1"},
reciprocal{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/reciprocal/RECIPROCAL_LICENSE",
+ "testdata/restricted/RESTRICTED_LICENSE",
+ },
},
{
condition: "restricted",
@@ -373,6 +435,7 @@
usedBy{"lib/libd.so"},
notice{},
},
+ expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"},
},
{
condition: "proprietary",
@@ -399,6 +462,11 @@
usedBy{"highest.apex/bin/bin1"},
proprietary{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/proprietary/PROPRIETARY_LICENSE",
+ "testdata/restricted/RESTRICTED_LICENSE",
+ },
},
{
condition: "proprietary",
@@ -425,6 +493,11 @@
usedBy{"container.zip/bin1"},
proprietary{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/proprietary/PROPRIETARY_LICENSE",
+ "testdata/restricted/RESTRICTED_LICENSE",
+ },
},
{
condition: "proprietary",
@@ -440,6 +513,10 @@
usedBy{"application"},
proprietary{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/proprietary/PROPRIETARY_LICENSE",
+ },
},
{
condition: "proprietary",
@@ -457,6 +534,10 @@
usedBy{"bin/bin1"},
proprietary{},
},
+ expectedDeps: []string{
+ "testdata/firstparty/FIRST_PARTY_LICENSE",
+ "testdata/proprietary/PROPRIETARY_LICENSE",
+ },
},
{
condition: "proprietary",
@@ -468,6 +549,7 @@
usedBy{"lib/libd.so"},
notice{},
},
+ expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"},
},
}
for _, tt := range tests {
@@ -480,7 +562,9 @@
rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r)
}
- ctx := context{stdout, stderr, os.DirFS("."), tt.stripPrefix}
+ var deps []string
+
+ ctx := context{stdout, stderr, os.DirFS("."), tt.stripPrefix, &deps}
err := textNotice(&ctx, rootFiles...)
if err != nil {
@@ -512,6 +596,15 @@
for ; lineno < len(tt.expectedOut); lineno++ {
t.Errorf("textnotice: missing output line %d: ended early, want %q", lineno+1, tt.expectedOut[lineno].String())
}
+
+ t.Logf("got deps: %q", deps)
+
+ t.Logf("want deps: %q", tt.expectedDeps)
+
+ if g, w := deps, tt.expectedDeps; !reflect.DeepEqual(g, w) {
+ t.Errorf("unexpected deps, wanted:\n%s\ngot:\n%s\n",
+ strings.Join(w, "\n"), strings.Join(g, "\n"))
+ }
})
}
}