Regularize command-line flags.
All the notice binaries have -title All the binaries that can -stripPrefix can strip multiple. Bug: 68860345 Bug: 151177513 Bug: 151953481 Bug: 213388645 Bug: 210912771 Test: m all Test: m systemlicense Test: m bom; out/soong/host/linux-x85/bom ... Test: m dumpgraph; out/soong/host/linux-x85/dumpgraph ... Test: m dumpresolutions; out/soong/host/linux-x85/dumpresolutions ... Test: m htmlnotice; out/soong/host/linux-x85/htmlnotice ... Test: m rtrace; out/soong/host/linux-x85/rtrace ... Test: m textnotice; out/soong/host/linux-x85/textnotice ... Test: m xmlnotice; out/soong/host/linux-x85/xmlnotice ... where ... is the path to the .meta_lic file for the system image. In my case if $ export PRODUCT=$(realpath $ANDROID_PRODUCT_OUT --relative-to=$PWD) ... can be expressed as: ${PRODUCT}/gen/META/lic_intermediates/${PRODUCT}/system.img.meta_lic Change-Id: I08357bf1adb048abba6563cf3cea6ee6d60405e0
This commit is contained in:
@@ -29,7 +29,7 @@ import (
|
||||
var (
|
||||
graphViz = flag.Bool("dot", false, "Whether to output graphviz (i.e. dot) format.")
|
||||
labelConditions = flag.Bool("label_conditions", false, "Whether to label target nodes with conditions.")
|
||||
stripPrefix = flag.String("strip_prefix", "", "Prefix to remove from paths. i.e. path to root")
|
||||
stripPrefix = newMultiString("strip_prefix", "Prefix to remove from paths. i.e. path to root (multiple allowed)")
|
||||
|
||||
failNoneRequested = fmt.Errorf("\nNo license metadata files requested")
|
||||
failNoLicenses = fmt.Errorf("No licenses found")
|
||||
@@ -38,7 +38,20 @@ var (
|
||||
type context struct {
|
||||
graphViz bool
|
||||
labelConditions bool
|
||||
stripPrefix string
|
||||
stripPrefix []string
|
||||
}
|
||||
|
||||
func (ctx context) strip(installPath string) string {
|
||||
for _, prefix := range ctx.stripPrefix {
|
||||
if strings.HasPrefix(installPath, prefix) {
|
||||
p := strings.TrimPrefix(installPath, prefix)
|
||||
if 0 == len(p) {
|
||||
continue
|
||||
}
|
||||
return p
|
||||
}
|
||||
}
|
||||
return installPath
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -60,6 +73,19 @@ Options:
|
||||
}
|
||||
}
|
||||
|
||||
// newMultiString creates a flag that allows multiple values in an array.
|
||||
func newMultiString(name, usage string) *multiString {
|
||||
var f multiString
|
||||
flag.Var(&f, name, usage)
|
||||
return &f
|
||||
}
|
||||
|
||||
// multiString implements the flag `Value` interface for multiple strings.
|
||||
type multiString []string
|
||||
|
||||
func (ms *multiString) String() string { return strings.Join(*ms, ", ") }
|
||||
func (ms *multiString) Set(s string) error { *ms = append(*ms, s); return nil }
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
@@ -107,7 +133,7 @@ func dumpGraph(ctx *context, stdout, stderr io.Writer, files ...string) error {
|
||||
|
||||
// targetOut calculates the string to output for `target` separating conditions as needed using `sep`.
|
||||
targetOut := func(target *compliance.TargetNode, sep string) string {
|
||||
tOut := strings.TrimPrefix(target.Name(), ctx.stripPrefix)
|
||||
tOut := ctx.strip(target.Name())
|
||||
if ctx.labelConditions {
|
||||
conditions := target.LicenseConditions().Names()
|
||||
sort.Strings(conditions)
|
||||
|
@@ -59,7 +59,7 @@ func Test_plaintext(t *testing.T) {
|
||||
condition: "firstparty",
|
||||
name: "apex_trimmed",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/firstparty/"},
|
||||
ctx: context{stripPrefix: []string{"testdata/firstparty/"}},
|
||||
expectedOut: []string{
|
||||
"bin/bin1.meta_lic lib/liba.so.meta_lic static",
|
||||
"bin/bin1.meta_lic lib/libc.a.meta_lic static",
|
||||
@@ -75,7 +75,7 @@ func Test_plaintext(t *testing.T) {
|
||||
condition: "firstparty",
|
||||
name: "apex_trimmed_labelled",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/firstparty/", labelConditions: true},
|
||||
ctx: context{stripPrefix: []string{"testdata/firstparty/"}, labelConditions: true},
|
||||
expectedOut: []string{
|
||||
"bin/bin1.meta_lic:notice lib/liba.so.meta_lic:notice static",
|
||||
"bin/bin1.meta_lic:notice lib/libc.a.meta_lic:notice static",
|
||||
@@ -146,7 +146,7 @@ func Test_plaintext(t *testing.T) {
|
||||
condition: "notice",
|
||||
name: "apex_trimmed",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/notice/"},
|
||||
ctx: context{stripPrefix: []string{"testdata/notice/"}},
|
||||
expectedOut: []string{
|
||||
"bin/bin1.meta_lic lib/liba.so.meta_lic static",
|
||||
"bin/bin1.meta_lic lib/libc.a.meta_lic static",
|
||||
@@ -162,7 +162,7 @@ func Test_plaintext(t *testing.T) {
|
||||
condition: "notice",
|
||||
name: "apex_trimmed_labelled",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/notice/", labelConditions: true},
|
||||
ctx: context{stripPrefix: []string{"testdata/notice/"}, labelConditions: true},
|
||||
expectedOut: []string{
|
||||
"bin/bin1.meta_lic:notice lib/liba.so.meta_lic:notice static",
|
||||
"bin/bin1.meta_lic:notice lib/libc.a.meta_lic:notice static",
|
||||
@@ -233,7 +233,7 @@ func Test_plaintext(t *testing.T) {
|
||||
condition: "reciprocal",
|
||||
name: "apex_trimmed",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/reciprocal/"},
|
||||
ctx: context{stripPrefix: []string{"testdata/reciprocal/"}},
|
||||
expectedOut: []string{
|
||||
"bin/bin1.meta_lic lib/liba.so.meta_lic static",
|
||||
"bin/bin1.meta_lic lib/libc.a.meta_lic static",
|
||||
@@ -249,7 +249,7 @@ func Test_plaintext(t *testing.T) {
|
||||
condition: "reciprocal",
|
||||
name: "apex_trimmed_labelled",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/reciprocal/", labelConditions: true},
|
||||
ctx: context{stripPrefix: []string{"testdata/reciprocal/"}, labelConditions: true},
|
||||
expectedOut: []string{
|
||||
"bin/bin1.meta_lic:notice lib/liba.so.meta_lic:reciprocal static",
|
||||
"bin/bin1.meta_lic:notice lib/libc.a.meta_lic:reciprocal static",
|
||||
@@ -320,7 +320,7 @@ func Test_plaintext(t *testing.T) {
|
||||
condition: "restricted",
|
||||
name: "apex_trimmed",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/restricted/"},
|
||||
ctx: context{stripPrefix: []string{"testdata/restricted/"}},
|
||||
expectedOut: []string{
|
||||
"bin/bin1.meta_lic lib/liba.so.meta_lic static",
|
||||
"bin/bin1.meta_lic lib/libc.a.meta_lic static",
|
||||
@@ -336,7 +336,7 @@ func Test_plaintext(t *testing.T) {
|
||||
condition: "restricted",
|
||||
name: "apex_trimmed_labelled",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/restricted/", labelConditions: true},
|
||||
ctx: context{stripPrefix: []string{"testdata/restricted/"}, labelConditions: true},
|
||||
expectedOut: []string{
|
||||
"bin/bin1.meta_lic:notice lib/liba.so.meta_lic:restricted_allows_dynamic_linking static",
|
||||
"bin/bin1.meta_lic:notice lib/libc.a.meta_lic:reciprocal static",
|
||||
@@ -407,7 +407,7 @@ func Test_plaintext(t *testing.T) {
|
||||
condition: "proprietary",
|
||||
name: "apex_trimmed",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/proprietary/"},
|
||||
ctx: context{stripPrefix: []string{"testdata/proprietary/"}},
|
||||
expectedOut: []string{
|
||||
"bin/bin1.meta_lic lib/liba.so.meta_lic static",
|
||||
"bin/bin1.meta_lic lib/libc.a.meta_lic static",
|
||||
@@ -423,7 +423,7 @@ func Test_plaintext(t *testing.T) {
|
||||
condition: "proprietary",
|
||||
name: "apex_trimmed_labelled",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/proprietary/", labelConditions: true},
|
||||
ctx: context{stripPrefix: []string{"testdata/proprietary/"}, labelConditions: true},
|
||||
expectedOut: []string{
|
||||
"bin/bin1.meta_lic:notice lib/liba.so.meta_lic:by_exception_only:proprietary static",
|
||||
"bin/bin1.meta_lic:notice lib/libc.a.meta_lic:by_exception_only:proprietary static",
|
||||
@@ -613,7 +613,7 @@ func Test_graphviz(t *testing.T) {
|
||||
condition: "firstparty",
|
||||
name: "apex_trimmed",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/firstparty/"},
|
||||
ctx: context{stripPrefix: []string{"testdata/firstparty/"}},
|
||||
expectedOut: []getMatcher{
|
||||
matchTarget("bin/bin1.meta_lic"),
|
||||
matchTarget("bin/bin2.meta_lic"),
|
||||
@@ -636,7 +636,7 @@ func Test_graphviz(t *testing.T) {
|
||||
condition: "firstparty",
|
||||
name: "apex_trimmed_labelled",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/firstparty/", labelConditions: true},
|
||||
ctx: context{stripPrefix: []string{"testdata/firstparty/"}, labelConditions: true},
|
||||
expectedOut: []getMatcher{
|
||||
matchTarget("bin/bin1.meta_lic", "notice"),
|
||||
matchTarget("bin/bin2.meta_lic", "notice"),
|
||||
@@ -735,7 +735,7 @@ func Test_graphviz(t *testing.T) {
|
||||
condition: "notice",
|
||||
name: "apex_trimmed",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/notice/"},
|
||||
ctx: context{stripPrefix: []string{"testdata/notice/"}},
|
||||
expectedOut: []getMatcher{
|
||||
matchTarget("bin/bin1.meta_lic"),
|
||||
matchTarget("bin/bin2.meta_lic"),
|
||||
@@ -758,7 +758,7 @@ func Test_graphviz(t *testing.T) {
|
||||
condition: "notice",
|
||||
name: "apex_trimmed_labelled",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/notice/", labelConditions: true},
|
||||
ctx: context{stripPrefix: []string{"testdata/notice/"}, labelConditions: true},
|
||||
expectedOut: []getMatcher{
|
||||
matchTarget("bin/bin1.meta_lic", "notice"),
|
||||
matchTarget("bin/bin2.meta_lic", "notice"),
|
||||
@@ -857,7 +857,7 @@ func Test_graphviz(t *testing.T) {
|
||||
condition: "reciprocal",
|
||||
name: "apex_trimmed",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/reciprocal/"},
|
||||
ctx: context{stripPrefix: []string{"testdata/reciprocal/"}},
|
||||
expectedOut: []getMatcher{
|
||||
matchTarget("bin/bin1.meta_lic"),
|
||||
matchTarget("bin/bin2.meta_lic"),
|
||||
@@ -880,7 +880,7 @@ func Test_graphviz(t *testing.T) {
|
||||
condition: "reciprocal",
|
||||
name: "apex_trimmed_labelled",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/reciprocal/", labelConditions: true},
|
||||
ctx: context{stripPrefix: []string{"testdata/reciprocal/"}, labelConditions: true},
|
||||
expectedOut: []getMatcher{
|
||||
matchTarget("bin/bin1.meta_lic", "notice"),
|
||||
matchTarget("bin/bin2.meta_lic", "notice"),
|
||||
@@ -979,7 +979,7 @@ func Test_graphviz(t *testing.T) {
|
||||
condition: "restricted",
|
||||
name: "apex_trimmed",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/restricted/"},
|
||||
ctx: context{stripPrefix: []string{"testdata/restricted/"}},
|
||||
expectedOut: []getMatcher{
|
||||
matchTarget("bin/bin1.meta_lic"),
|
||||
matchTarget("bin/bin2.meta_lic"),
|
||||
@@ -1002,7 +1002,7 @@ func Test_graphviz(t *testing.T) {
|
||||
condition: "restricted",
|
||||
name: "apex_trimmed_labelled",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/restricted/", labelConditions: true},
|
||||
ctx: context{stripPrefix: []string{"testdata/restricted/"}, labelConditions: true},
|
||||
expectedOut: []getMatcher{
|
||||
matchTarget("bin/bin1.meta_lic", "notice"),
|
||||
matchTarget("bin/bin2.meta_lic", "notice"),
|
||||
@@ -1101,7 +1101,7 @@ func Test_graphviz(t *testing.T) {
|
||||
condition: "proprietary",
|
||||
name: "apex_trimmed",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/proprietary/"},
|
||||
ctx: context{stripPrefix: []string{"testdata/proprietary/"}},
|
||||
expectedOut: []getMatcher{
|
||||
matchTarget("bin/bin1.meta_lic"),
|
||||
matchTarget("bin/bin2.meta_lic"),
|
||||
@@ -1124,7 +1124,7 @@ func Test_graphviz(t *testing.T) {
|
||||
condition: "proprietary",
|
||||
name: "apex_trimmed_labelled",
|
||||
roots: []string{"highest.apex.meta_lic"},
|
||||
ctx: context{stripPrefix: "testdata/proprietary/", labelConditions: true},
|
||||
ctx: context{stripPrefix: []string{"testdata/proprietary/"}, labelConditions: true},
|
||||
expectedOut: []getMatcher{
|
||||
matchTarget("bin/bin1.meta_lic", "notice"),
|
||||
matchTarget("bin/bin2.meta_lic", "by_exception_only", "proprietary"),
|
||||
|
Reference in New Issue
Block a user