Loading tools/compliance/cmd/bom/bom.go +29 −7 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ import ( var ( outputFile = flag.String("o", "-", "Where to write the bill of materials. (default stdout)") 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") Loading @@ -39,7 +39,20 @@ type context struct { stdout io.Writer stderr io.Writer rootFS fs.FS 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() { Loading @@ -54,6 +67,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() Loading Loading @@ -135,11 +161,7 @@ func billOfMaterials(ctx *context, files ...string) error { } for path := range ni.InstallPaths() { if 0 < len(ctx.stripPrefix) && strings.HasPrefix(path, ctx.stripPrefix) { fmt.Fprintln(ctx.stdout, path[len(ctx.stripPrefix):]) } else { fmt.Fprintln(ctx.stdout, path) } fmt.Fprintln(ctx.stdout, ctx.strip(path)) } return nil } tools/compliance/cmd/bom/bom_test.go +1 −1 Original line number Diff line number Diff line Loading @@ -282,7 +282,7 @@ func Test(t *testing.T) { rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r) } ctx := context{stdout, stderr, os.DirFS("."), tt.stripPrefix} ctx := context{stdout, stderr, os.DirFS("."), []string{tt.stripPrefix}} err := billOfMaterials(&ctx, rootFiles...) if err != nil { Loading tools/compliance/cmd/dumpgraph/dumpgraph.go +29 −3 Original line number Diff line number Diff line Loading @@ -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") Loading @@ -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() { Loading @@ -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() Loading Loading @@ -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) Loading tools/compliance/cmd/dumpgraph/dumpgraph_test.go +20 −20 Original line number Diff line number Diff line Loading @@ -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", Loading @@ -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", Loading Loading @@ -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", Loading @@ -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", Loading Loading @@ -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", Loading @@ -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", Loading Loading @@ -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", Loading @@ -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", Loading Loading @@ -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", Loading @@ -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", Loading Loading @@ -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"), Loading @@ -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"), Loading Loading @@ -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"), Loading @@ -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"), Loading Loading @@ -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"), Loading @@ -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"), Loading Loading @@ -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"), Loading @@ -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"), Loading Loading @@ -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"), Loading @@ -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"), Loading tools/compliance/cmd/dumpresolutions/dumpresolutions.go +16 −3 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ var ( conditions = newMultiString("c", "License condition to resolve. (may be given multiple times)") 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") Loading @@ -40,7 +40,20 @@ type context struct { conditions []compliance.LicenseCondition 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() { Loading Loading @@ -140,7 +153,7 @@ func dumpResolutions(ctx *context, stdout, stderr io.Writer, files ...string) (* // targetOut calculates the string to output for `target` adding `sep`-separated conditions as needed. 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() if len(conditions) > 0 { Loading Loading
tools/compliance/cmd/bom/bom.go +29 −7 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ import ( var ( outputFile = flag.String("o", "-", "Where to write the bill of materials. (default stdout)") 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") Loading @@ -39,7 +39,20 @@ type context struct { stdout io.Writer stderr io.Writer rootFS fs.FS 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() { Loading @@ -54,6 +67,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() Loading Loading @@ -135,11 +161,7 @@ func billOfMaterials(ctx *context, files ...string) error { } for path := range ni.InstallPaths() { if 0 < len(ctx.stripPrefix) && strings.HasPrefix(path, ctx.stripPrefix) { fmt.Fprintln(ctx.stdout, path[len(ctx.stripPrefix):]) } else { fmt.Fprintln(ctx.stdout, path) } fmt.Fprintln(ctx.stdout, ctx.strip(path)) } return nil }
tools/compliance/cmd/bom/bom_test.go +1 −1 Original line number Diff line number Diff line Loading @@ -282,7 +282,7 @@ func Test(t *testing.T) { rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r) } ctx := context{stdout, stderr, os.DirFS("."), tt.stripPrefix} ctx := context{stdout, stderr, os.DirFS("."), []string{tt.stripPrefix}} err := billOfMaterials(&ctx, rootFiles...) if err != nil { Loading
tools/compliance/cmd/dumpgraph/dumpgraph.go +29 −3 Original line number Diff line number Diff line Loading @@ -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") Loading @@ -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() { Loading @@ -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() Loading Loading @@ -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) Loading
tools/compliance/cmd/dumpgraph/dumpgraph_test.go +20 −20 Original line number Diff line number Diff line Loading @@ -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", Loading @@ -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", Loading Loading @@ -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", Loading @@ -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", Loading Loading @@ -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", Loading @@ -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", Loading Loading @@ -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", Loading @@ -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", Loading Loading @@ -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", Loading @@ -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", Loading Loading @@ -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"), Loading @@ -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"), Loading Loading @@ -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"), Loading @@ -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"), Loading Loading @@ -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"), Loading @@ -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"), Loading Loading @@ -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"), Loading @@ -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"), Loading Loading @@ -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"), Loading @@ -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"), Loading
tools/compliance/cmd/dumpresolutions/dumpresolutions.go +16 −3 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ var ( conditions = newMultiString("c", "License condition to resolve. (may be given multiple times)") 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") Loading @@ -40,7 +40,20 @@ type context struct { conditions []compliance.LicenseCondition 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() { Loading Loading @@ -140,7 +153,7 @@ func dumpResolutions(ctx *context, stdout, stderr io.Writer, files ...string) (* // targetOut calculates the string to output for `target` adding `sep`-separated conditions as needed. 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() if len(conditions) > 0 { Loading