Support OUT_DIR for license graph.

Bug: 226066987

Test: OUT_DIR=/tmp/outdir m all listshare checkshare htmlnotice rtrace dumpgraph dumpresolutions compliancenotice_bom compliancenotice_shippedlibs
Test: OUT_DIR=/tmp/outdir m /tmp/outdir/target/product/bonito/obj/NOTICE.xml.gz
Test: m all listshare checkshare htmlnotice rtrace dumpgraph dumpresolutions compliancenotice_bom compliancenotice_shippedlibs
Test: m out/target/product/bonito/obj/NOTICE.xml.gz

Change-Id: I6282c647a389c5935d5ce7c79193f86d32c76365
This commit is contained in:
Bob Badour
2022-03-22 13:05:19 -07:00
parent fb042449e0
commit c778e4cba4
23 changed files with 109 additions and 56 deletions

View File

@@ -18,6 +18,7 @@ import (
"flag"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"sort"
@@ -110,7 +111,7 @@ func main() {
labelConditions: *labelConditions,
stripPrefix: *stripPrefix,
}
_, err := dumpResolutions(ctx, os.Stdout, os.Stderr, flag.Args()...)
_, err := dumpResolutions(ctx, os.Stdout, os.Stderr, compliance.FS, flag.Args()...)
if err != nil {
if err == failNoneRequested {
flag.Usage()
@@ -122,13 +123,13 @@ func main() {
}
// dumpResolutions implements the dumpresolutions utility.
func dumpResolutions(ctx *context, stdout, stderr io.Writer, files ...string) (*compliance.LicenseGraph, error) {
func dumpResolutions(ctx *context, stdout, stderr io.Writer, rootFS fs.FS, files ...string) (*compliance.LicenseGraph, error) {
if len(files) < 1 {
return nil, failNoneRequested
}
// Read the license graph from the license metadata files (*.meta_lic).
licenseGraph, err := compliance.ReadLicenseGraph(os.DirFS("."), stderr, files)
licenseGraph, err := compliance.ReadLicenseGraph(rootFS, stderr, files)
if err != nil {
return nil, fmt.Errorf("Unable to read license metadata file(s) %q: %v\n", files, err)
}

View File

@@ -38,6 +38,7 @@ func Test_plaintext(t *testing.T) {
tests := []struct {
condition string
name string
outDir string
roots []string
ctx context
expectedOut []string
@@ -902,7 +903,7 @@ func Test_plaintext(t *testing.T) {
for _, r := range tt.roots {
rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r)
}
_, err := dumpResolutions(&tt.ctx, stdout, stderr, rootFiles...)
_, err := dumpResolutions(&tt.ctx, stdout, stderr, compliance.GetFS(tt.outDir), rootFiles...)
if err != nil {
t.Fatalf("dumpresolutions: error = %v, stderr = %v", err, stderr)
return
@@ -1011,6 +1012,7 @@ func Test_graphviz(t *testing.T) {
tests := []struct {
condition string
name string
outDir string
roots []string
ctx context
expectedOut []getMatcher
@@ -3298,7 +3300,7 @@ func Test_graphviz(t *testing.T) {
rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r)
}
tt.ctx.graphViz = true
lg, err := dumpResolutions(&tt.ctx, stdout, stderr, rootFiles...)
lg, err := dumpResolutions(&tt.ctx, stdout, stderr, compliance.GetFS(tt.outDir), rootFiles...)
if err != nil {
t.Fatalf("dumpresolutions: error = %v, stderr = %v", err, stderr)
return