Merge "Support OUT_DIR for license graph."
This commit is contained in:
@@ -116,7 +116,7 @@ func main() {
|
||||
ofile = &bytes.Buffer{}
|
||||
}
|
||||
|
||||
ctx := &context{ofile, os.Stderr, os.DirFS("."), *stripPrefix}
|
||||
ctx := &context{ofile, os.Stderr, compliance.FS, *stripPrefix}
|
||||
|
||||
err := billOfMaterials(ctx, flag.Args()...)
|
||||
if err != nil {
|
||||
|
@@ -21,6 +21,8 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"android/soong/tools/compliance"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@@ -37,6 +39,7 @@ func Test(t *testing.T) {
|
||||
tests := []struct {
|
||||
condition string
|
||||
name string
|
||||
outDir string
|
||||
roots []string
|
||||
stripPrefix string
|
||||
expectedOut []string
|
||||
@@ -282,7 +285,7 @@ func Test(t *testing.T) {
|
||||
rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r)
|
||||
}
|
||||
|
||||
ctx := context{stdout, stderr, os.DirFS("."), []string{tt.stripPrefix}}
|
||||
ctx := context{stdout, stderr, compliance.GetFS(tt.outDir), []string{tt.stripPrefix}}
|
||||
|
||||
err := billOfMaterials(&ctx, rootFiles...)
|
||||
if err != nil {
|
||||
|
@@ -18,6 +18,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@@ -68,7 +69,7 @@ func main() {
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
err := checkShare(os.Stdout, os.Stderr, flag.Args()...)
|
||||
err := checkShare(os.Stdout, os.Stderr, compliance.FS, flag.Args()...)
|
||||
if err != nil {
|
||||
if err != failConflicts {
|
||||
if err == failNoneRequested {
|
||||
@@ -82,14 +83,14 @@ func main() {
|
||||
}
|
||||
|
||||
// checkShare implements the checkshare utility.
|
||||
func checkShare(stdout, stderr io.Writer, files ...string) error {
|
||||
func checkShare(stdout, stderr io.Writer, rootFS fs.FS, files ...string) error {
|
||||
|
||||
if len(files) < 1 {
|
||||
return 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 fmt.Errorf("Unable to read license metadata file(s) %q: %w\n", files, err)
|
||||
}
|
||||
|
@@ -20,6 +20,8 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"android/soong/tools/compliance"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@@ -56,6 +58,7 @@ func Test(t *testing.T) {
|
||||
tests := []struct {
|
||||
condition string
|
||||
name string
|
||||
outDir string
|
||||
roots []string
|
||||
expectedStdout string
|
||||
expectedOutcomes outcomeList
|
||||
@@ -248,7 +251,7 @@ func Test(t *testing.T) {
|
||||
for _, r := range tt.roots {
|
||||
rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r)
|
||||
}
|
||||
err := checkShare(stdout, stderr, rootFiles...)
|
||||
err := checkShare(stdout, stderr, compliance.GetFS(tt.outDir), rootFiles...)
|
||||
if err != nil && err != failConflicts {
|
||||
t.Fatalf("checkshare: error = %v, stderr = %v", err, stderr)
|
||||
return
|
||||
|
@@ -18,6 +18,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@@ -97,7 +98,7 @@ func main() {
|
||||
|
||||
ctx := &context{*graphViz, *labelConditions, *stripPrefix}
|
||||
|
||||
err := dumpGraph(ctx, os.Stdout, os.Stderr, flag.Args()...)
|
||||
err := dumpGraph(ctx, os.Stdout, os.Stderr, compliance.FS, flag.Args()...)
|
||||
if err != nil {
|
||||
if err == failNoneRequested {
|
||||
flag.Usage()
|
||||
@@ -109,13 +110,13 @@ func main() {
|
||||
}
|
||||
|
||||
// dumpGraph implements the dumpgraph utility.
|
||||
func dumpGraph(ctx *context, stdout, stderr io.Writer, files ...string) error {
|
||||
func dumpGraph(ctx *context, stdout, stderr io.Writer, rootFS fs.FS, files ...string) error {
|
||||
if len(files) < 1 {
|
||||
return 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 fmt.Errorf("Unable to read license metadata file(s) %q: %w\n", files, err)
|
||||
}
|
||||
|
@@ -20,6 +20,8 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"android/soong/tools/compliance"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@@ -36,6 +38,7 @@ func Test_plaintext(t *testing.T) {
|
||||
tests := []struct {
|
||||
condition string
|
||||
name string
|
||||
outDir string
|
||||
roots []string
|
||||
ctx context
|
||||
expectedOut []string
|
||||
@@ -491,7 +494,7 @@ func Test_plaintext(t *testing.T) {
|
||||
for _, r := range tt.roots {
|
||||
rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r)
|
||||
}
|
||||
err := dumpGraph(&tt.ctx, stdout, stderr, rootFiles...)
|
||||
err := dumpGraph(&tt.ctx, stdout, stderr, compliance.GetFS(tt.outDir), rootFiles...)
|
||||
if err != nil {
|
||||
t.Fatalf("dumpgraph: error = %v, stderr = %v", err, stderr)
|
||||
return
|
||||
@@ -583,6 +586,7 @@ func Test_graphviz(t *testing.T) {
|
||||
tests := []struct {
|
||||
condition string
|
||||
name string
|
||||
outDir string
|
||||
roots []string
|
||||
ctx context
|
||||
expectedOut []getMatcher
|
||||
@@ -1217,7 +1221,7 @@ func Test_graphviz(t *testing.T) {
|
||||
rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r)
|
||||
}
|
||||
tt.ctx.graphViz = true
|
||||
err := dumpGraph(&tt.ctx, stdout, stderr, rootFiles...)
|
||||
err := dumpGraph(&tt.ctx, stdout, stderr, compliance.GetFS(tt.outDir), rootFiles...)
|
||||
if err != nil {
|
||||
t.Fatalf("dumpgraph: error = %v, stderr = %v", err, stderr)
|
||||
return
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -141,7 +141,7 @@ func main() {
|
||||
|
||||
var deps []string
|
||||
|
||||
ctx := &context{ofile, os.Stderr, os.DirFS("."), *includeTOC, *product, *stripPrefix, *title, &deps}
|
||||
ctx := &context{ofile, os.Stderr, compliance.FS, *includeTOC, *product, *stripPrefix, *title, &deps}
|
||||
|
||||
err := htmlNotice(ctx, flag.Args()...)
|
||||
if err != nil {
|
||||
|
@@ -24,6 +24,8 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"android/soong/tools/compliance"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -54,6 +56,7 @@ func Test(t *testing.T) {
|
||||
tests := []struct {
|
||||
condition string
|
||||
name string
|
||||
outDir string
|
||||
roots []string
|
||||
includeTOC bool
|
||||
stripPrefix string
|
||||
@@ -651,7 +654,7 @@ func Test(t *testing.T) {
|
||||
|
||||
var deps []string
|
||||
|
||||
ctx := context{stdout, stderr, os.DirFS("."), tt.includeTOC, "", []string{tt.stripPrefix}, tt.title, &deps}
|
||||
ctx := context{stdout, stderr, compliance.GetFS(tt.outDir), tt.includeTOC, "", []string{tt.stripPrefix}, tt.title, &deps}
|
||||
|
||||
err := htmlNotice(&ctx, rootFiles...)
|
||||
if err != nil {
|
||||
|
@@ -18,6 +18,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@@ -54,7 +55,7 @@ func main() {
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
err := listShare(os.Stdout, os.Stderr, flag.Args()...)
|
||||
err := listShare(os.Stdout, os.Stderr, compliance.FS, flag.Args()...)
|
||||
if err != nil {
|
||||
if err == failNoneRequested {
|
||||
flag.Usage()
|
||||
@@ -66,14 +67,14 @@ func main() {
|
||||
}
|
||||
|
||||
// listShare implements the listshare utility.
|
||||
func listShare(stdout, stderr io.Writer, files ...string) error {
|
||||
func listShare(stdout, stderr io.Writer, rootFS fs.FS, files ...string) error {
|
||||
// Must be at least one root file.
|
||||
if len(files) < 1 {
|
||||
return 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 fmt.Errorf("Unable to read license metadata file(s) %q: %v\n", files, err)
|
||||
}
|
||||
|
@@ -20,6 +20,8 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"android/soong/tools/compliance"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@@ -40,6 +42,7 @@ func Test(t *testing.T) {
|
||||
tests := []struct {
|
||||
condition string
|
||||
name string
|
||||
outDir string
|
||||
roots []string
|
||||
expectedOut []projectShare
|
||||
}{
|
||||
@@ -481,7 +484,7 @@ func Test(t *testing.T) {
|
||||
for _, r := range tt.roots {
|
||||
rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r)
|
||||
}
|
||||
err := listShare(stdout, stderr, rootFiles...)
|
||||
err := listShare(stdout, stderr, compliance.GetFS(tt.outDir), rootFiles...)
|
||||
if err != nil {
|
||||
t.Fatalf("listshare: error = %v, stderr = %v", err, stderr)
|
||||
return
|
||||
|
@@ -18,6 +18,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@@ -107,7 +108,7 @@ func main() {
|
||||
sources: *sources,
|
||||
stripPrefix: *stripPrefix,
|
||||
}
|
||||
_, err := traceRestricted(ctx, os.Stdout, os.Stderr, flag.Args()...)
|
||||
_, err := traceRestricted(ctx, os.Stdout, os.Stderr, compliance.FS, flag.Args()...)
|
||||
if err != nil {
|
||||
if err == failNoneRequested {
|
||||
flag.Usage()
|
||||
@@ -119,7 +120,7 @@ func main() {
|
||||
}
|
||||
|
||||
// traceRestricted implements the rtrace utility.
|
||||
func traceRestricted(ctx *context, stdout, stderr io.Writer, files ...string) (*compliance.LicenseGraph, error) {
|
||||
func traceRestricted(ctx *context, stdout, stderr io.Writer, rootFS fs.FS, files ...string) (*compliance.LicenseGraph, error) {
|
||||
if len(files) < 1 {
|
||||
return nil, failNoneRequested
|
||||
}
|
||||
@@ -129,7 +130,7 @@ func traceRestricted(ctx *context, stdout, stderr io.Writer, files ...string) (*
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
@@ -20,6 +20,8 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"android/soong/tools/compliance"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@@ -36,6 +38,7 @@ func Test_plaintext(t *testing.T) {
|
||||
tests := []struct {
|
||||
condition string
|
||||
name string
|
||||
outDir string
|
||||
roots []string
|
||||
ctx context
|
||||
expectedOut []string
|
||||
@@ -289,7 +292,7 @@ func Test_plaintext(t *testing.T) {
|
||||
if len(tt.ctx.sources) < 1 {
|
||||
tt.ctx.sources = rootFiles
|
||||
}
|
||||
_, err := traceRestricted(&tt.ctx, stdout, stderr, rootFiles...)
|
||||
_, err := traceRestricted(&tt.ctx, stdout, stderr, compliance.GetFS(tt.outDir), rootFiles...)
|
||||
t.Logf("rtrace: stderr = %v", stderr)
|
||||
t.Logf("rtrace: stdout = %v", stdout)
|
||||
if err != nil {
|
||||
|
@@ -117,7 +117,7 @@ Options:
|
||||
ofile = &bytes.Buffer{}
|
||||
}
|
||||
|
||||
ctx := &context{ofile, os.Stderr, os.DirFS(".")}
|
||||
ctx := &context{ofile, os.Stderr, compliance.FS}
|
||||
|
||||
err = shippedLibs(ctx, flags.Args()...)
|
||||
if err != nil {
|
||||
|
@@ -21,6 +21,8 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"android/soong/tools/compliance"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@@ -37,6 +39,7 @@ func Test(t *testing.T) {
|
||||
tests := []struct {
|
||||
condition string
|
||||
name string
|
||||
outDir string
|
||||
roots []string
|
||||
expectedOut []string
|
||||
}{
|
||||
@@ -201,7 +204,7 @@ func Test(t *testing.T) {
|
||||
rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r)
|
||||
}
|
||||
|
||||
ctx := context{stdout, stderr, os.DirFS(".")}
|
||||
ctx := context{stdout, stderr, compliance.GetFS(tt.outDir)}
|
||||
|
||||
err := shippedLibs(&ctx, rootFiles...)
|
||||
if err != nil {
|
||||
|
@@ -137,7 +137,7 @@ func main() {
|
||||
|
||||
var deps []string
|
||||
|
||||
ctx := &context{ofile, os.Stderr, os.DirFS("."), *product, *stripPrefix, *title, &deps}
|
||||
ctx := &context{ofile, os.Stderr, compliance.FS, *product, *stripPrefix, *title, &deps}
|
||||
|
||||
err := textNotice(ctx, flag.Args()...)
|
||||
if err != nil {
|
||||
|
@@ -23,6 +23,8 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"android/soong/tools/compliance"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -43,6 +45,7 @@ func Test(t *testing.T) {
|
||||
tests := []struct {
|
||||
condition string
|
||||
name string
|
||||
outDir string
|
||||
roots []string
|
||||
stripPrefix string
|
||||
expectedOut []matcher
|
||||
@@ -564,7 +567,7 @@ func Test(t *testing.T) {
|
||||
|
||||
var deps []string
|
||||
|
||||
ctx := context{stdout, stderr, os.DirFS("."), "", []string{tt.stripPrefix}, "", &deps}
|
||||
ctx := context{stdout, stderr, compliance.GetFS(tt.outDir), "", []string{tt.stripPrefix}, "", &deps}
|
||||
|
||||
err := textNotice(&ctx, rootFiles...)
|
||||
if err != nil {
|
||||
|
@@ -139,7 +139,7 @@ func main() {
|
||||
|
||||
var deps []string
|
||||
|
||||
ctx := &context{ofile, os.Stderr, os.DirFS("."), *product, *stripPrefix, *title, &deps}
|
||||
ctx := &context{ofile, os.Stderr, compliance.FS, *product, *stripPrefix, *title, &deps}
|
||||
|
||||
err := xmlNotice(ctx, flag.Args()...)
|
||||
if err != nil {
|
||||
|
@@ -24,6 +24,8 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"android/soong/tools/compliance"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -45,6 +47,7 @@ func Test(t *testing.T) {
|
||||
tests := []struct {
|
||||
condition string
|
||||
name string
|
||||
outDir string
|
||||
roots []string
|
||||
stripPrefix string
|
||||
expectedOut []matcher
|
||||
@@ -459,7 +462,7 @@ func Test(t *testing.T) {
|
||||
|
||||
var deps []string
|
||||
|
||||
ctx := context{stdout, stderr, os.DirFS("."), "", []string{tt.stripPrefix}, "", &deps}
|
||||
ctx := context{stdout, stderr, compliance.GetFS(tt.outDir), "", []string{tt.stripPrefix}, "", &deps}
|
||||
|
||||
err := xmlNotice(&ctx, rootFiles...)
|
||||
if err != nil {
|
||||
|
@@ -18,6 +18,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -31,6 +32,22 @@ var (
|
||||
ConcurrentReaders = 5
|
||||
)
|
||||
|
||||
type globalFS struct{}
|
||||
|
||||
func (s globalFS) Open(name string) (fs.File, error) {
|
||||
return os.Open(name)
|
||||
}
|
||||
|
||||
var FS globalFS
|
||||
|
||||
// GetFS returns a filesystem for accessing files under the OUT_DIR environment variable.
|
||||
func GetFS(outDir string) fs.FS {
|
||||
if len(outDir) > 0 {
|
||||
return os.DirFS(outDir)
|
||||
}
|
||||
return os.DirFS(".")
|
||||
}
|
||||
|
||||
// result describes the outcome of reading and parsing a single license metadata file.
|
||||
type result struct {
|
||||
// file identifies the path to the license metadata file
|
||||
|
Reference in New Issue
Block a user