From ab5cfbd5b79b0ea3ea91d09229c800f0fc3f3150 Mon Sep 17 00:00:00 2001 From: Bob Badour Date: Mon, 17 Oct 2022 17:40:04 -0700 Subject: [PATCH] Switch noticeindex from regex to proto. Bug: 254534552 Test: m droid dist cts alllicensemetadata Test: repo forall -c 'echo -n "$REPO_PATH " && $ANDROID_BUILD_TOP/out/host/linux-x86/bin/compliance_checkmetadata . 2>&1' | fgrep -v PASS Change-Id: I34dfe143cdc88432d6e33abee096409a37ce3b7e --- tools/compliance/cmd/htmlnotice/htmlnotice.go | 4 +- .../cmd/htmlnotice/htmlnotice_test.go | 179 +++++++++++++++-- tools/compliance/cmd/textnotice/textnotice.go | 4 +- .../cmd/textnotice/textnotice_test.go | 142 +++++++++++++- tools/compliance/cmd/xmlnotice/xmlnotice.go | 4 +- .../cmd/xmlnotice/xmlnotice_test.go | 146 +++++++++++++- tools/compliance/noticeindex.go | 183 +++++++----------- 7 files changed, 516 insertions(+), 146 deletions(-) diff --git a/tools/compliance/cmd/htmlnotice/htmlnotice.go b/tools/compliance/cmd/htmlnotice/htmlnotice.go index 1a4961020e..78371ee599 100644 --- a/tools/compliance/cmd/htmlnotice/htmlnotice.go +++ b/tools/compliance/cmd/htmlnotice/htmlnotice.go @@ -24,6 +24,7 @@ import ( "io/fs" "os" "path/filepath" + "sort" "strings" "android/soong/response" @@ -275,7 +276,8 @@ func htmlNotice(ctx *context, files ...string) error { } fmt.Fprintln(ctx.stdout, "") - *ctx.deps = ni.InputNoticeFiles() + *ctx.deps = ni.InputFiles() + sort.Strings(*ctx.deps) return nil } diff --git a/tools/compliance/cmd/htmlnotice/htmlnotice_test.go b/tools/compliance/cmd/htmlnotice/htmlnotice_test.go index b927018173..8dc1197444 100644 --- a/tools/compliance/cmd/htmlnotice/htmlnotice_test.go +++ b/tools/compliance/cmd/htmlnotice/htmlnotice_test.go @@ -78,7 +78,16 @@ func Test(t *testing.T) { usedBy{"highest.apex/lib/libb.so"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/bin/bin1.meta_lic", + "testdata/firstparty/bin/bin2.meta_lic", + "testdata/firstparty/highest.apex.meta_lic", + "testdata/firstparty/lib/liba.so.meta_lic", + "testdata/firstparty/lib/libb.so.meta_lic", + "testdata/firstparty/lib/libc.a.meta_lic", + "testdata/firstparty/lib/libd.so.meta_lic", + }, }, { condition: "firstparty", @@ -106,7 +115,16 @@ func Test(t *testing.T) { usedBy{"highest.apex/lib/libb.so"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/bin/bin1.meta_lic", + "testdata/firstparty/bin/bin2.meta_lic", + "testdata/firstparty/highest.apex.meta_lic", + "testdata/firstparty/lib/liba.so.meta_lic", + "testdata/firstparty/lib/libb.so.meta_lic", + "testdata/firstparty/lib/libc.a.meta_lic", + "testdata/firstparty/lib/libd.so.meta_lic", + }, }, { condition: "firstparty", @@ -124,7 +142,16 @@ func Test(t *testing.T) { usedBy{"highest.apex/lib/libb.so"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/bin/bin1.meta_lic", + "testdata/firstparty/bin/bin2.meta_lic", + "testdata/firstparty/highest.apex.meta_lic", + "testdata/firstparty/lib/liba.so.meta_lic", + "testdata/firstparty/lib/libb.so.meta_lic", + "testdata/firstparty/lib/libc.a.meta_lic", + "testdata/firstparty/lib/libd.so.meta_lic", + }, }, { condition: "firstparty", @@ -154,7 +181,16 @@ func Test(t *testing.T) { usedBy{"highest.apex/lib/libb.so"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/bin/bin1.meta_lic", + "testdata/firstparty/bin/bin2.meta_lic", + "testdata/firstparty/highest.apex.meta_lic", + "testdata/firstparty/lib/liba.so.meta_lic", + "testdata/firstparty/lib/libb.so.meta_lic", + "testdata/firstparty/lib/libc.a.meta_lic", + "testdata/firstparty/lib/libd.so.meta_lic", + }, }, { condition: "firstparty", @@ -170,7 +206,16 @@ func Test(t *testing.T) { usedBy{"container.zip/libb.so"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/bin/bin1.meta_lic", + "testdata/firstparty/bin/bin2.meta_lic", + "testdata/firstparty/container.zip.meta_lic", + "testdata/firstparty/lib/liba.so.meta_lic", + "testdata/firstparty/lib/libb.so.meta_lic", + "testdata/firstparty/lib/libc.a.meta_lic", + "testdata/firstparty/lib/libd.so.meta_lic", + }, }, { condition: "firstparty", @@ -182,7 +227,13 @@ func Test(t *testing.T) { usedBy{"application"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/application.meta_lic", + "testdata/firstparty/bin/bin3.meta_lic", + "testdata/firstparty/lib/liba.so.meta_lic", + "testdata/firstparty/lib/libb.so.meta_lic", + }, }, { condition: "firstparty", @@ -194,7 +245,12 @@ func Test(t *testing.T) { usedBy{"bin/bin1"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/bin/bin1.meta_lic", + "testdata/firstparty/lib/liba.so.meta_lic", + "testdata/firstparty/lib/libc.a.meta_lic", + }, }, { condition: "firstparty", @@ -206,7 +262,10 @@ func Test(t *testing.T) { usedBy{"lib/libd.so"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/lib/libd.so.meta_lic", + }, }, { condition: "notice", @@ -231,6 +290,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/notice/NOTICE_LICENSE", + "testdata/notice/bin/bin1.meta_lic", + "testdata/notice/bin/bin2.meta_lic", + "testdata/notice/highest.apex.meta_lic", + "testdata/notice/lib/liba.so.meta_lic", + "testdata/notice/lib/libb.so.meta_lic", + "testdata/notice/lib/libc.a.meta_lic", + "testdata/notice/lib/libd.so.meta_lic", }, }, { @@ -256,6 +322,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/notice/NOTICE_LICENSE", + "testdata/notice/bin/bin1.meta_lic", + "testdata/notice/bin/bin2.meta_lic", + "testdata/notice/container.zip.meta_lic", + "testdata/notice/lib/liba.so.meta_lic", + "testdata/notice/lib/libb.so.meta_lic", + "testdata/notice/lib/libc.a.meta_lic", + "testdata/notice/lib/libd.so.meta_lic", }, }, { @@ -275,6 +348,10 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/notice/NOTICE_LICENSE", + "testdata/notice/application.meta_lic", + "testdata/notice/bin/bin3.meta_lic", + "testdata/notice/lib/liba.so.meta_lic", + "testdata/notice/lib/libb.so.meta_lic", }, }, { @@ -296,6 +373,9 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/notice/NOTICE_LICENSE", + "testdata/notice/bin/bin1.meta_lic", + "testdata/notice/lib/liba.so.meta_lic", + "testdata/notice/lib/libc.a.meta_lic", }, }, { @@ -308,7 +388,10 @@ func Test(t *testing.T) { usedBy{"lib/libd.so"}, notice{}, }, - expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"}, + expectedDeps: []string{ + "testdata/notice/NOTICE_LICENSE", + "testdata/notice/lib/libd.so.meta_lic", + }, }, { condition: "reciprocal", @@ -333,6 +416,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", + "testdata/reciprocal/bin/bin1.meta_lic", + "testdata/reciprocal/bin/bin2.meta_lic", + "testdata/reciprocal/highest.apex.meta_lic", + "testdata/reciprocal/lib/liba.so.meta_lic", + "testdata/reciprocal/lib/libb.so.meta_lic", + "testdata/reciprocal/lib/libc.a.meta_lic", + "testdata/reciprocal/lib/libd.so.meta_lic", }, }, { @@ -358,6 +448,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", + "testdata/reciprocal/bin/bin1.meta_lic", + "testdata/reciprocal/bin/bin2.meta_lic", + "testdata/reciprocal/container.zip.meta_lic", + "testdata/reciprocal/lib/liba.so.meta_lic", + "testdata/reciprocal/lib/libb.so.meta_lic", + "testdata/reciprocal/lib/libc.a.meta_lic", + "testdata/reciprocal/lib/libd.so.meta_lic", }, }, { @@ -377,6 +474,10 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", + "testdata/reciprocal/application.meta_lic", + "testdata/reciprocal/bin/bin3.meta_lic", + "testdata/reciprocal/lib/liba.so.meta_lic", + "testdata/reciprocal/lib/libb.so.meta_lic", }, }, { @@ -398,6 +499,9 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", + "testdata/reciprocal/bin/bin1.meta_lic", + "testdata/reciprocal/lib/liba.so.meta_lic", + "testdata/reciprocal/lib/libc.a.meta_lic", }, }, { @@ -410,7 +514,10 @@ func Test(t *testing.T) { usedBy{"lib/libd.so"}, notice{}, }, - expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"}, + expectedDeps: []string{ + "testdata/notice/NOTICE_LICENSE", + "testdata/reciprocal/lib/libd.so.meta_lic", + }, }, { condition: "restricted", @@ -440,6 +547,13 @@ func Test(t *testing.T) { "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", "testdata/restricted/RESTRICTED_LICENSE", + "testdata/restricted/bin/bin1.meta_lic", + "testdata/restricted/bin/bin2.meta_lic", + "testdata/restricted/highest.apex.meta_lic", + "testdata/restricted/lib/liba.so.meta_lic", + "testdata/restricted/lib/libb.so.meta_lic", + "testdata/restricted/lib/libc.a.meta_lic", + "testdata/restricted/lib/libd.so.meta_lic", }, }, { @@ -470,6 +584,13 @@ func Test(t *testing.T) { "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", "testdata/restricted/RESTRICTED_LICENSE", + "testdata/restricted/bin/bin1.meta_lic", + "testdata/restricted/bin/bin2.meta_lic", + "testdata/restricted/container.zip.meta_lic", + "testdata/restricted/lib/liba.so.meta_lic", + "testdata/restricted/lib/libb.so.meta_lic", + "testdata/restricted/lib/libc.a.meta_lic", + "testdata/restricted/lib/libd.so.meta_lic", }, }, { @@ -489,6 +610,10 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/restricted/RESTRICTED_LICENSE", + "testdata/restricted/application.meta_lic", + "testdata/restricted/bin/bin3.meta_lic", + "testdata/restricted/lib/liba.so.meta_lic", + "testdata/restricted/lib/libb.so.meta_lic", }, }, { @@ -513,6 +638,9 @@ func Test(t *testing.T) { "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", "testdata/restricted/RESTRICTED_LICENSE", + "testdata/restricted/bin/bin1.meta_lic", + "testdata/restricted/lib/liba.so.meta_lic", + "testdata/restricted/lib/libc.a.meta_lic", }, }, { @@ -525,7 +653,10 @@ func Test(t *testing.T) { usedBy{"lib/libd.so"}, notice{}, }, - expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"}, + expectedDeps: []string{ + "testdata/notice/NOTICE_LICENSE", + "testdata/restricted/lib/libd.so.meta_lic", + }, }, { condition: "proprietary", @@ -555,6 +686,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/proprietary/PROPRIETARY_LICENSE", + "testdata/proprietary/bin/bin1.meta_lic", + "testdata/proprietary/bin/bin2.meta_lic", + "testdata/proprietary/highest.apex.meta_lic", + "testdata/proprietary/lib/liba.so.meta_lic", + "testdata/proprietary/lib/libb.so.meta_lic", + "testdata/proprietary/lib/libc.a.meta_lic", + "testdata/proprietary/lib/libd.so.meta_lic", "testdata/restricted/RESTRICTED_LICENSE", }, }, @@ -586,6 +724,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/proprietary/PROPRIETARY_LICENSE", + "testdata/proprietary/bin/bin1.meta_lic", + "testdata/proprietary/bin/bin2.meta_lic", + "testdata/proprietary/container.zip.meta_lic", + "testdata/proprietary/lib/liba.so.meta_lic", + "testdata/proprietary/lib/libb.so.meta_lic", + "testdata/proprietary/lib/libc.a.meta_lic", + "testdata/proprietary/lib/libd.so.meta_lic", "testdata/restricted/RESTRICTED_LICENSE", }, }, @@ -606,6 +751,10 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/proprietary/PROPRIETARY_LICENSE", + "testdata/proprietary/application.meta_lic", + "testdata/proprietary/bin/bin3.meta_lic", + "testdata/proprietary/lib/liba.so.meta_lic", + "testdata/proprietary/lib/libb.so.meta_lic", }, }, { @@ -627,6 +776,9 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/proprietary/PROPRIETARY_LICENSE", + "testdata/proprietary/bin/bin1.meta_lic", + "testdata/proprietary/lib/liba.so.meta_lic", + "testdata/proprietary/lib/libc.a.meta_lic", }, }, { @@ -639,7 +791,10 @@ func Test(t *testing.T) { usedBy{"lib/libd.so"}, notice{}, }, - expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"}, + expectedDeps: []string{ + "testdata/notice/NOTICE_LICENSE", + "testdata/proprietary/lib/libd.so.meta_lic", + }, }, } for _, tt := range tests { diff --git a/tools/compliance/cmd/textnotice/textnotice.go b/tools/compliance/cmd/textnotice/textnotice.go index 9beaf58ad1..450290c6d6 100644 --- a/tools/compliance/cmd/textnotice/textnotice.go +++ b/tools/compliance/cmd/textnotice/textnotice.go @@ -23,6 +23,7 @@ import ( "io/fs" "os" "path/filepath" + "sort" "strings" "android/soong/response" @@ -230,7 +231,8 @@ func textNotice(ctx *context, files ...string) error { fmt.Fprintln(ctx.stdout) } - *ctx.deps = ni.InputNoticeFiles() + *ctx.deps = ni.InputFiles() + sort.Strings(*ctx.deps) return nil } diff --git a/tools/compliance/cmd/textnotice/textnotice_test.go b/tools/compliance/cmd/textnotice/textnotice_test.go index e661a44e2c..a90231378e 100644 --- a/tools/compliance/cmd/textnotice/textnotice_test.go +++ b/tools/compliance/cmd/textnotice/textnotice_test.go @@ -65,7 +65,16 @@ func Test(t *testing.T) { usedBy{"highest.apex/lib/libb.so"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/bin/bin1.meta_lic", + "testdata/firstparty/bin/bin2.meta_lic", + "testdata/firstparty/highest.apex.meta_lic", + "testdata/firstparty/lib/liba.so.meta_lic", + "testdata/firstparty/lib/libb.so.meta_lic", + "testdata/firstparty/lib/libc.a.meta_lic", + "testdata/firstparty/lib/libd.so.meta_lic", + }, }, { condition: "firstparty", @@ -81,7 +90,16 @@ func Test(t *testing.T) { usedBy{"container.zip/libb.so"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/bin/bin1.meta_lic", + "testdata/firstparty/bin/bin2.meta_lic", + "testdata/firstparty/container.zip.meta_lic", + "testdata/firstparty/lib/liba.so.meta_lic", + "testdata/firstparty/lib/libb.so.meta_lic", + "testdata/firstparty/lib/libc.a.meta_lic", + "testdata/firstparty/lib/libd.so.meta_lic", + }, }, { condition: "firstparty", @@ -93,7 +111,13 @@ func Test(t *testing.T) { usedBy{"application"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/application.meta_lic", + "testdata/firstparty/bin/bin3.meta_lic", + "testdata/firstparty/lib/liba.so.meta_lic", + "testdata/firstparty/lib/libb.so.meta_lic", + }, }, { condition: "firstparty", @@ -105,7 +129,12 @@ func Test(t *testing.T) { usedBy{"bin/bin1"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/bin/bin1.meta_lic", + "testdata/firstparty/lib/liba.so.meta_lic", + "testdata/firstparty/lib/libc.a.meta_lic", + }, }, { condition: "firstparty", @@ -117,7 +146,10 @@ func Test(t *testing.T) { usedBy{"lib/libd.so"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/lib/libd.so.meta_lic", + }, }, { condition: "notice", @@ -142,6 +174,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/notice/NOTICE_LICENSE", + "testdata/notice/bin/bin1.meta_lic", + "testdata/notice/bin/bin2.meta_lic", + "testdata/notice/highest.apex.meta_lic", + "testdata/notice/lib/liba.so.meta_lic", + "testdata/notice/lib/libb.so.meta_lic", + "testdata/notice/lib/libc.a.meta_lic", + "testdata/notice/lib/libd.so.meta_lic", }, }, { @@ -167,6 +206,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/notice/NOTICE_LICENSE", + "testdata/notice/bin/bin1.meta_lic", + "testdata/notice/bin/bin2.meta_lic", + "testdata/notice/container.zip.meta_lic", + "testdata/notice/lib/liba.so.meta_lic", + "testdata/notice/lib/libb.so.meta_lic", + "testdata/notice/lib/libc.a.meta_lic", + "testdata/notice/lib/libd.so.meta_lic", }, }, { @@ -186,6 +232,10 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/notice/NOTICE_LICENSE", + "testdata/notice/application.meta_lic", + "testdata/notice/bin/bin3.meta_lic", + "testdata/notice/lib/liba.so.meta_lic", + "testdata/notice/lib/libb.so.meta_lic", }, }, { @@ -207,6 +257,9 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/notice/NOTICE_LICENSE", + "testdata/notice/bin/bin1.meta_lic", + "testdata/notice/lib/liba.so.meta_lic", + "testdata/notice/lib/libc.a.meta_lic", }, }, { @@ -219,7 +272,10 @@ func Test(t *testing.T) { usedBy{"lib/libd.so"}, notice{}, }, - expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"}, + expectedDeps: []string{ + "testdata/notice/NOTICE_LICENSE", + "testdata/notice/lib/libd.so.meta_lic", + }, }, { condition: "reciprocal", @@ -244,6 +300,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", + "testdata/reciprocal/bin/bin1.meta_lic", + "testdata/reciprocal/bin/bin2.meta_lic", + "testdata/reciprocal/highest.apex.meta_lic", + "testdata/reciprocal/lib/liba.so.meta_lic", + "testdata/reciprocal/lib/libb.so.meta_lic", + "testdata/reciprocal/lib/libc.a.meta_lic", + "testdata/reciprocal/lib/libd.so.meta_lic", }, }, { @@ -269,6 +332,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", + "testdata/reciprocal/bin/bin1.meta_lic", + "testdata/reciprocal/bin/bin2.meta_lic", + "testdata/reciprocal/container.zip.meta_lic", + "testdata/reciprocal/lib/liba.so.meta_lic", + "testdata/reciprocal/lib/libb.so.meta_lic", + "testdata/reciprocal/lib/libc.a.meta_lic", + "testdata/reciprocal/lib/libd.so.meta_lic", }, }, { @@ -288,6 +358,10 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", + "testdata/reciprocal/application.meta_lic", + "testdata/reciprocal/bin/bin3.meta_lic", + "testdata/reciprocal/lib/liba.so.meta_lic", + "testdata/reciprocal/lib/libb.so.meta_lic", }, }, { @@ -309,6 +383,9 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", + "testdata/reciprocal/bin/bin1.meta_lic", + "testdata/reciprocal/lib/liba.so.meta_lic", + "testdata/reciprocal/lib/libc.a.meta_lic", }, }, { @@ -323,6 +400,7 @@ func Test(t *testing.T) { }, expectedDeps: []string{ "testdata/notice/NOTICE_LICENSE", + "testdata/reciprocal/lib/libd.so.meta_lic", }, }, { @@ -353,6 +431,13 @@ func Test(t *testing.T) { "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", "testdata/restricted/RESTRICTED_LICENSE", + "testdata/restricted/bin/bin1.meta_lic", + "testdata/restricted/bin/bin2.meta_lic", + "testdata/restricted/highest.apex.meta_lic", + "testdata/restricted/lib/liba.so.meta_lic", + "testdata/restricted/lib/libb.so.meta_lic", + "testdata/restricted/lib/libc.a.meta_lic", + "testdata/restricted/lib/libd.so.meta_lic", }, }, { @@ -383,6 +468,13 @@ func Test(t *testing.T) { "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", "testdata/restricted/RESTRICTED_LICENSE", + "testdata/restricted/bin/bin1.meta_lic", + "testdata/restricted/bin/bin2.meta_lic", + "testdata/restricted/container.zip.meta_lic", + "testdata/restricted/lib/liba.so.meta_lic", + "testdata/restricted/lib/libb.so.meta_lic", + "testdata/restricted/lib/libc.a.meta_lic", + "testdata/restricted/lib/libd.so.meta_lic", }, }, { @@ -402,6 +494,10 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/restricted/RESTRICTED_LICENSE", + "testdata/restricted/application.meta_lic", + "testdata/restricted/bin/bin3.meta_lic", + "testdata/restricted/lib/liba.so.meta_lic", + "testdata/restricted/lib/libb.so.meta_lic", }, }, { @@ -426,6 +522,9 @@ func Test(t *testing.T) { "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", "testdata/restricted/RESTRICTED_LICENSE", + "testdata/restricted/bin/bin1.meta_lic", + "testdata/restricted/lib/liba.so.meta_lic", + "testdata/restricted/lib/libc.a.meta_lic", }, }, { @@ -438,7 +537,10 @@ func Test(t *testing.T) { usedBy{"lib/libd.so"}, notice{}, }, - expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"}, + expectedDeps: []string{ + "testdata/notice/NOTICE_LICENSE", + "testdata/restricted/lib/libd.so.meta_lic", + }, }, { condition: "proprietary", @@ -468,6 +570,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/proprietary/PROPRIETARY_LICENSE", + "testdata/proprietary/bin/bin1.meta_lic", + "testdata/proprietary/bin/bin2.meta_lic", + "testdata/proprietary/highest.apex.meta_lic", + "testdata/proprietary/lib/liba.so.meta_lic", + "testdata/proprietary/lib/libb.so.meta_lic", + "testdata/proprietary/lib/libc.a.meta_lic", + "testdata/proprietary/lib/libd.so.meta_lic", "testdata/restricted/RESTRICTED_LICENSE", }, }, @@ -499,6 +608,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/proprietary/PROPRIETARY_LICENSE", + "testdata/proprietary/bin/bin1.meta_lic", + "testdata/proprietary/bin/bin2.meta_lic", + "testdata/proprietary/container.zip.meta_lic", + "testdata/proprietary/lib/liba.so.meta_lic", + "testdata/proprietary/lib/libb.so.meta_lic", + "testdata/proprietary/lib/libc.a.meta_lic", + "testdata/proprietary/lib/libd.so.meta_lic", "testdata/restricted/RESTRICTED_LICENSE", }, }, @@ -519,6 +635,10 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/proprietary/PROPRIETARY_LICENSE", + "testdata/proprietary/application.meta_lic", + "testdata/proprietary/bin/bin3.meta_lic", + "testdata/proprietary/lib/liba.so.meta_lic", + "testdata/proprietary/lib/libb.so.meta_lic", }, }, { @@ -540,6 +660,9 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/proprietary/PROPRIETARY_LICENSE", + "testdata/proprietary/bin/bin1.meta_lic", + "testdata/proprietary/lib/liba.so.meta_lic", + "testdata/proprietary/lib/libc.a.meta_lic", }, }, { @@ -552,7 +675,10 @@ func Test(t *testing.T) { usedBy{"lib/libd.so"}, notice{}, }, - expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"}, + expectedDeps: []string{ + "testdata/notice/NOTICE_LICENSE", + "testdata/proprietary/lib/libd.so.meta_lic", + }, }, } for _, tt := range tests { diff --git a/tools/compliance/cmd/xmlnotice/xmlnotice.go b/tools/compliance/cmd/xmlnotice/xmlnotice.go index 2097b7c5e1..c3f8e4cea3 100644 --- a/tools/compliance/cmd/xmlnotice/xmlnotice.go +++ b/tools/compliance/cmd/xmlnotice/xmlnotice.go @@ -24,6 +24,7 @@ import ( "io/fs" "os" "path/filepath" + "sort" "strings" "android/soong/response" @@ -238,7 +239,8 @@ func xmlNotice(ctx *context, files ...string) error { } fmt.Fprintln(ctx.stdout, "") - *ctx.deps = ni.InputNoticeFiles() + *ctx.deps = ni.InputFiles() + sort.Strings(*ctx.deps) return nil } diff --git a/tools/compliance/cmd/xmlnotice/xmlnotice_test.go b/tools/compliance/cmd/xmlnotice/xmlnotice_test.go index 731e783fb1..551006fc51 100644 --- a/tools/compliance/cmd/xmlnotice/xmlnotice_test.go +++ b/tools/compliance/cmd/xmlnotice/xmlnotice_test.go @@ -65,7 +65,16 @@ func Test(t *testing.T) { target{"highest.apex/lib/libb.so", "Android"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/bin/bin1.meta_lic", + "testdata/firstparty/bin/bin2.meta_lic", + "testdata/firstparty/highest.apex.meta_lic", + "testdata/firstparty/lib/liba.so.meta_lic", + "testdata/firstparty/lib/libb.so.meta_lic", + "testdata/firstparty/lib/libc.a.meta_lic", + "testdata/firstparty/lib/libd.so.meta_lic", + }, }, { condition: "firstparty", @@ -79,7 +88,16 @@ func Test(t *testing.T) { target{"container.zip/libb.so", "Android"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/bin/bin1.meta_lic", + "testdata/firstparty/bin/bin2.meta_lic", + "testdata/firstparty/container.zip.meta_lic", + "testdata/firstparty/lib/liba.so.meta_lic", + "testdata/firstparty/lib/libb.so.meta_lic", + "testdata/firstparty/lib/libc.a.meta_lic", + "testdata/firstparty/lib/libd.so.meta_lic", + }, }, { condition: "firstparty", @@ -89,7 +107,13 @@ func Test(t *testing.T) { target{"application", "Android"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/application.meta_lic", + "testdata/firstparty/bin/bin3.meta_lic", + "testdata/firstparty/lib/liba.so.meta_lic", + "testdata/firstparty/lib/libb.so.meta_lic", + }, }, { condition: "firstparty", @@ -99,7 +123,12 @@ func Test(t *testing.T) { target{"bin/bin1", "Android"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/bin/bin1.meta_lic", + "testdata/firstparty/lib/liba.so.meta_lic", + "testdata/firstparty/lib/libc.a.meta_lic", + }, }, { condition: "firstparty", @@ -109,7 +138,10 @@ func Test(t *testing.T) { target{"lib/libd.so", "Android"}, firstParty{}, }, - expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"}, + expectedDeps: []string{ + "testdata/firstparty/FIRST_PARTY_LICENSE", + "testdata/firstparty/lib/libd.so.meta_lic", + }, }, { condition: "notice", @@ -129,6 +161,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/notice/NOTICE_LICENSE", + "testdata/notice/bin/bin1.meta_lic", + "testdata/notice/bin/bin2.meta_lic", + "testdata/notice/highest.apex.meta_lic", + "testdata/notice/lib/liba.so.meta_lic", + "testdata/notice/lib/libb.so.meta_lic", + "testdata/notice/lib/libc.a.meta_lic", + "testdata/notice/lib/libd.so.meta_lic", }, }, { @@ -149,6 +188,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/notice/NOTICE_LICENSE", + "testdata/notice/bin/bin1.meta_lic", + "testdata/notice/bin/bin2.meta_lic", + "testdata/notice/container.zip.meta_lic", + "testdata/notice/lib/liba.so.meta_lic", + "testdata/notice/lib/libb.so.meta_lic", + "testdata/notice/lib/libc.a.meta_lic", + "testdata/notice/lib/libd.so.meta_lic", }, }, { @@ -164,6 +210,10 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/notice/NOTICE_LICENSE", + "testdata/notice/application.meta_lic", + "testdata/notice/bin/bin3.meta_lic", + "testdata/notice/lib/liba.so.meta_lic", + "testdata/notice/lib/libb.so.meta_lic", }, }, { @@ -180,6 +230,9 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/notice/NOTICE_LICENSE", + "testdata/notice/bin/bin1.meta_lic", + "testdata/notice/lib/liba.so.meta_lic", + "testdata/notice/lib/libc.a.meta_lic", }, }, { @@ -190,7 +243,10 @@ func Test(t *testing.T) { target{"lib/libd.so", "External"}, notice{}, }, - expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"}, + expectedDeps: []string{ + "testdata/notice/NOTICE_LICENSE", + "testdata/notice/lib/libd.so.meta_lic", + }, }, { condition: "reciprocal", @@ -210,6 +266,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", + "testdata/reciprocal/bin/bin1.meta_lic", + "testdata/reciprocal/bin/bin2.meta_lic", + "testdata/reciprocal/highest.apex.meta_lic", + "testdata/reciprocal/lib/liba.so.meta_lic", + "testdata/reciprocal/lib/libb.so.meta_lic", + "testdata/reciprocal/lib/libc.a.meta_lic", + "testdata/reciprocal/lib/libd.so.meta_lic", }, }, { @@ -230,6 +293,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", + "testdata/reciprocal/bin/bin1.meta_lic", + "testdata/reciprocal/bin/bin2.meta_lic", + "testdata/reciprocal/container.zip.meta_lic", + "testdata/reciprocal/lib/liba.so.meta_lic", + "testdata/reciprocal/lib/libb.so.meta_lic", + "testdata/reciprocal/lib/libc.a.meta_lic", + "testdata/reciprocal/lib/libd.so.meta_lic", }, }, { @@ -245,6 +315,10 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", + "testdata/reciprocal/application.meta_lic", + "testdata/reciprocal/bin/bin3.meta_lic", + "testdata/reciprocal/lib/liba.so.meta_lic", + "testdata/reciprocal/lib/libb.so.meta_lic", }, }, { @@ -261,6 +335,9 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", + "testdata/reciprocal/bin/bin1.meta_lic", + "testdata/reciprocal/lib/liba.so.meta_lic", + "testdata/reciprocal/lib/libc.a.meta_lic", }, }, { @@ -271,7 +348,10 @@ func Test(t *testing.T) { target{"lib/libd.so", "External"}, notice{}, }, - expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"}, + expectedDeps: []string{ + "testdata/notice/NOTICE_LICENSE", + "testdata/reciprocal/lib/libd.so.meta_lic", + }, }, { condition: "restricted", @@ -294,6 +374,13 @@ func Test(t *testing.T) { "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", "testdata/restricted/RESTRICTED_LICENSE", + "testdata/restricted/bin/bin1.meta_lic", + "testdata/restricted/bin/bin2.meta_lic", + "testdata/restricted/highest.apex.meta_lic", + "testdata/restricted/lib/liba.so.meta_lic", + "testdata/restricted/lib/libb.so.meta_lic", + "testdata/restricted/lib/libc.a.meta_lic", + "testdata/restricted/lib/libd.so.meta_lic", }, }, { @@ -317,6 +404,13 @@ func Test(t *testing.T) { "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", "testdata/restricted/RESTRICTED_LICENSE", + "testdata/restricted/bin/bin1.meta_lic", + "testdata/restricted/bin/bin2.meta_lic", + "testdata/restricted/container.zip.meta_lic", + "testdata/restricted/lib/liba.so.meta_lic", + "testdata/restricted/lib/libb.so.meta_lic", + "testdata/restricted/lib/libc.a.meta_lic", + "testdata/restricted/lib/libd.so.meta_lic", }, }, { @@ -332,6 +426,10 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/restricted/RESTRICTED_LICENSE", + "testdata/restricted/application.meta_lic", + "testdata/restricted/bin/bin3.meta_lic", + "testdata/restricted/lib/liba.so.meta_lic", + "testdata/restricted/lib/libb.so.meta_lic", }, }, { @@ -350,6 +448,9 @@ func Test(t *testing.T) { "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/reciprocal/RECIPROCAL_LICENSE", "testdata/restricted/RESTRICTED_LICENSE", + "testdata/restricted/bin/bin1.meta_lic", + "testdata/restricted/lib/liba.so.meta_lic", + "testdata/restricted/lib/libc.a.meta_lic", }, }, { @@ -360,7 +461,10 @@ func Test(t *testing.T) { target{"lib/libd.so", "External"}, notice{}, }, - expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"}, + expectedDeps: []string{ + "testdata/notice/NOTICE_LICENSE", + "testdata/restricted/lib/libd.so.meta_lic", + }, }, { condition: "proprietary", @@ -382,6 +486,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/proprietary/PROPRIETARY_LICENSE", + "testdata/proprietary/bin/bin1.meta_lic", + "testdata/proprietary/bin/bin2.meta_lic", + "testdata/proprietary/highest.apex.meta_lic", + "testdata/proprietary/lib/liba.so.meta_lic", + "testdata/proprietary/lib/libb.so.meta_lic", + "testdata/proprietary/lib/libc.a.meta_lic", + "testdata/proprietary/lib/libd.so.meta_lic", "testdata/restricted/RESTRICTED_LICENSE", }, }, @@ -405,6 +516,13 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/proprietary/PROPRIETARY_LICENSE", + "testdata/proprietary/bin/bin1.meta_lic", + "testdata/proprietary/bin/bin2.meta_lic", + "testdata/proprietary/container.zip.meta_lic", + "testdata/proprietary/lib/liba.so.meta_lic", + "testdata/proprietary/lib/libb.so.meta_lic", + "testdata/proprietary/lib/libc.a.meta_lic", + "testdata/proprietary/lib/libd.so.meta_lic", "testdata/restricted/RESTRICTED_LICENSE", }, }, @@ -421,6 +539,10 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/proprietary/PROPRIETARY_LICENSE", + "testdata/proprietary/application.meta_lic", + "testdata/proprietary/bin/bin3.meta_lic", + "testdata/proprietary/lib/liba.so.meta_lic", + "testdata/proprietary/lib/libb.so.meta_lic", }, }, { @@ -437,6 +559,9 @@ func Test(t *testing.T) { expectedDeps: []string{ "testdata/firstparty/FIRST_PARTY_LICENSE", "testdata/proprietary/PROPRIETARY_LICENSE", + "testdata/proprietary/bin/bin1.meta_lic", + "testdata/proprietary/lib/liba.so.meta_lic", + "testdata/proprietary/lib/libc.a.meta_lic", }, }, { @@ -447,7 +572,10 @@ func Test(t *testing.T) { target{"lib/libd.so", "External"}, notice{}, }, - expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"}, + expectedDeps: []string{ + "testdata/notice/NOTICE_LICENSE", + "testdata/proprietary/lib/libd.so.meta_lic", + }, }, } for _, tt := range tests { diff --git a/tools/compliance/noticeindex.go b/tools/compliance/noticeindex.go index 86d42ac560..cb95b76070 100644 --- a/tools/compliance/noticeindex.go +++ b/tools/compliance/noticeindex.go @@ -15,7 +15,6 @@ package compliance import ( - "bufio" "crypto/md5" "fmt" "io" @@ -25,16 +24,11 @@ import ( "regexp" "sort" "strings" -) -const ( - noProjectName = "\u2205" + "android/soong/tools/compliance/projectmetadata" ) var ( - nameRegexp = regexp.MustCompile(`^\s*name\s*:\s*"(.*)"\s*$`) - descRegexp = regexp.MustCompile(`^\s*description\s*:\s*"(.*)"\s*$`) - versionRegexp = regexp.MustCompile(`^\s*version\s*:\s*"(.*)"\s*$`) licensesPathRegexp = regexp.MustCompile(`licen[cs]es?/`) ) @@ -43,6 +37,8 @@ var ( type NoticeIndex struct { // lg identifies the license graph to which the index applies. lg *LicenseGraph + // pmix indexes project metadata + pmix *projectmetadata.Index // rs identifies the set of resolutions upon which the index is based. rs ResolutionSet // shipped identifies the set of target nodes shipped directly or as derivative works. @@ -75,6 +71,7 @@ func IndexLicenseTexts(rootFS fs.FS, lg *LicenseGraph, rs ResolutionSet) (*Notic } ni := &NoticeIndex{ lg: lg, + pmix: projectmetadata.NewIndex(rootFS), rs: rs, shipped: ShippedNodes(lg), rootFS: rootFS, @@ -110,9 +107,12 @@ func IndexLicenseTexts(rootFS fs.FS, lg *LicenseGraph, rs ResolutionSet) (*Notic return hashes, nil } - link := func(tn *TargetNode, hashes map[hash]struct{}, installPaths []string) { + link := func(tn *TargetNode, hashes map[hash]struct{}, installPaths []string) error { for h := range hashes { - libName := ni.getLibName(tn, h) + libName, err := ni.getLibName(tn, h) + if err != nil { + return err + } if _, ok := ni.libHash[libName]; !ok { ni.libHash[libName] = make(map[hash]struct{}) } @@ -145,6 +145,11 @@ func IndexLicenseTexts(rootFS fs.FS, lg *LicenseGraph, rs ResolutionSet) (*Notic } } } + return nil + } + + cacheMetadata := func(tn *TargetNode) { + ni.pmix.MetadataForProjects(tn.Projects()...) } // returns error from walk below. @@ -157,13 +162,17 @@ func IndexLicenseTexts(rootFS fs.FS, lg *LicenseGraph, rs ResolutionSet) (*Notic if !ni.shipped.Contains(tn) { return false } + go cacheMetadata(tn) installPaths := getInstallPaths(tn, path) var hashes map[hash]struct{} hashes, err = index(tn) if err != nil { return false } - link(tn, hashes, installPaths) + err = link(tn, hashes, installPaths) + if err != nil { + return false + } if tn.IsContainer() { return true } @@ -173,7 +182,10 @@ func IndexLicenseTexts(rootFS fs.FS, lg *LicenseGraph, rs ResolutionSet) (*Notic if err != nil { return false } - link(r.actsOn, hashes, installPaths) + err = link(r.actsOn, hashes, installPaths) + if err != nil { + return false + } } return false }) @@ -214,12 +226,20 @@ func (ni *NoticeIndex) Hashes() chan hash { close(c) }() return c + } -// InputNoticeFiles returns the list of files that were hashed during IndexLicenseTexts. -func (ni *NoticeIndex) InputNoticeFiles() []string { - files := append([]string(nil), ni.files...) - sort.Strings(files) +// InputFiles returns the complete list of files read during indexing. +func (ni *NoticeIndex) InputFiles() []string { + licenseMeta := []string(nil) + for f := range ni.lg.targets { + licenseMeta = append(licenseMeta, f) + } + projectMeta := ni.pmix.AllMetadataFiles() + files := make([]string, 0, len(ni.files) + len(licenseMeta) + len(projectMeta)) + files = append(files, ni.files...) + files = append(files, licenseMeta...) + files = append(files, projectMeta...) return files } @@ -308,15 +328,18 @@ func (ni *NoticeIndex) HashText(h hash) []byte { } // getLibName returns the name of the library associated with `noticeFor`. -func (ni *NoticeIndex) getLibName(noticeFor *TargetNode, h hash) string { +func (ni *NoticeIndex) getLibName(noticeFor *TargetNode, h hash) (string, error) { for _, text := range noticeFor.LicenseTexts() { if !strings.Contains(text, ":") { if ni.hash[text].key != h.key { continue } - ln := ni.checkMetadataForLicenseText(noticeFor, text) + ln, err := ni.checkMetadataForLicenseText(noticeFor, text) + if err != nil { + return "", err + } if len(ln) > 0 { - return ln + return ln, nil } continue } @@ -331,17 +354,20 @@ func (ni *NoticeIndex) getLibName(noticeFor *TargetNode, h hash) string { if err != nil { continue } - return ln + return ln, nil } // use name from METADATA if available - ln := ni.checkMetadata(noticeFor) + ln, err := ni.checkMetadata(noticeFor) + if err != nil { + return "", err + } if len(ln) > 0 { - return ln + return ln, nil } // use package_name: from license{} module if available pn := noticeFor.PackageName() if len(pn) > 0 { - return pn + return pn, nil } for _, p := range noticeFor.Projects() { if strings.HasPrefix(p, "prebuilts/") { @@ -385,7 +411,7 @@ func (ni *NoticeIndex) getLibName(noticeFor *TargetNode, h hash) string { match = match[:li] } } - return match + return match, nil } break } @@ -393,9 +419,9 @@ func (ni *NoticeIndex) getLibName(noticeFor *TargetNode, h hash) string { for _, safePathPrefix := range safePathPrefixes { if strings.HasPrefix(p, safePathPrefix.prefix) { if safePathPrefix.strip { - return p[len(safePathPrefix.prefix):] + return p[len(safePathPrefix.prefix):], nil } else { - return p + return p, nil } } } @@ -410,35 +436,26 @@ func (ni *NoticeIndex) getLibName(noticeFor *TargetNode, h hash) string { if fi > 0 { n = n[:fi] } - return n + return n, nil } // checkMetadata tries to look up a library name from a METADATA file associated with `noticeFor`. -func (ni *NoticeIndex) checkMetadata(noticeFor *TargetNode) string { - for _, p := range noticeFor.Projects() { - if name, ok := ni.projectName[p]; ok { - if name == noProjectName { - continue - } - return name - } - name, err := ni.checkMetadataFile(filepath.Join(p, "METADATA")) - if err != nil { - ni.projectName[p] = noProjectName - continue - } - if len(name) == 0 { - ni.projectName[p] = noProjectName - continue - } - ni.projectName[p] = name - return name +func (ni *NoticeIndex) checkMetadata(noticeFor *TargetNode) (string, error) { + pms, err := ni.pmix.MetadataForProjects(noticeFor.Projects()...) + if err != nil { + return "", err } - return "" + for _, pm := range pms { + name := pm.VersionedName() + if name != "" { + return name, nil + } + } + return "", nil } // checkMetadataForLicenseText -func (ni *NoticeIndex) checkMetadataForLicenseText(noticeFor *TargetNode, licenseText string) string { +func (ni *NoticeIndex) checkMetadataForLicenseText(noticeFor *TargetNode, licenseText string) (string, error) { p := "" for _, proj := range noticeFor.Projects() { if strings.HasPrefix(licenseText, proj) { @@ -456,79 +473,17 @@ func (ni *NoticeIndex) checkMetadataForLicenseText(noticeFor *TargetNode, licens p = filepath.Dir(p) continue } - return "" + return "", nil } } - if name, ok := ni.projectName[p]; ok { - if name == noProjectName { - return "" - } - return name - } - name, err := ni.checkMetadataFile(filepath.Join(p, "METADATA")) - if err == nil && len(name) > 0 { - ni.projectName[p] = name - return name - } - ni.projectName[p] = noProjectName - return "" -} - -// checkMetadataFile tries to look up a library name from a METADATA file at `path`. -func (ni *NoticeIndex) checkMetadataFile(path string) (string, error) { - f, err := ni.rootFS.Open(path) + pms, err := ni.pmix.MetadataForProjects(p) if err != nil { return "", err } - name := "" - description := "" - version := "" - s := bufio.NewScanner(f) - for s.Scan() { - line := s.Text() - m := nameRegexp.FindStringSubmatch(line) - if m != nil { - if 1 < len(m) && m[1] != "" { - name = m[1] - } - if version != "" { - break - } - continue - } - m = versionRegexp.FindStringSubmatch(line) - if m != nil { - if 1 < len(m) && m[1] != "" { - version = m[1] - } - if name != "" { - break - } - continue - } - m = descRegexp.FindStringSubmatch(line) - if m != nil { - if 1 < len(m) && m[1] != "" { - description = m[1] - } - } + if pms == nil { + return "", nil } - _ = s.Err() - _ = f.Close() - if name != "" { - if version != "" { - if version[0] == 'v' || version[0] == 'V' { - return name + "_" + version, nil - } else { - return name + "_v_" + version, nil - } - } - return name, nil - } - if description != "" { - return description, nil - } - return "", nil + return pms[0].VersionedName(), nil } // addText reads and indexes the content of a license text file.