Merge "Correctly add dependencies to java_resource_dirs files"
This commit is contained in:
@@ -408,16 +408,16 @@ func TestResources(t *testing.T) {
|
|||||||
args string
|
args string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
// Test that a module with java_resource_dirs includes a file list file
|
// Test that a module with java_resource_dirs includes the files
|
||||||
name: "resource dirs",
|
name: "resource dirs",
|
||||||
prop: `java_resource_dirs: ["res"]`,
|
prop: `java_resource_dirs: ["res"]`,
|
||||||
args: "-C res -l ",
|
args: "-C res -f res/a -f res/b",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Test that a module with java_resources includes the files
|
// Test that a module with java_resources includes the files
|
||||||
name: "resource files",
|
name: "resource files",
|
||||||
prop: `java_resources: ["res/a", "res/b"]`,
|
prop: `java_resources: ["res/a", "res/b"]`,
|
||||||
args: "-C . -f res/a -C . -f res/b",
|
args: "-C . -f res/a -f res/b",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Test that a module with a filegroup in java_resources includes the files with the
|
// Test that a module with a filegroup in java_resources includes the files with the
|
||||||
@@ -430,13 +430,13 @@ func TestResources(t *testing.T) {
|
|||||||
path: "res",
|
path: "res",
|
||||||
srcs: ["res/a", "res/b"],
|
srcs: ["res/a", "res/b"],
|
||||||
}`,
|
}`,
|
||||||
args: "-C res -f res/a -C res -f res/b",
|
args: "-C res -f res/a -f res/b",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Test that a module with "include_srcs: true" includes its source files in the resources jar
|
// Test that a module with "include_srcs: true" includes its source files in the resources jar
|
||||||
name: "include sources",
|
name: "include sources",
|
||||||
prop: `include_srcs: true`,
|
prop: `include_srcs: true`,
|
||||||
args: "-C . -f a.java -C . -f b.java -C . -f c.java",
|
args: "-C . -f a.java -f b.java -f c.java",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,8 +462,8 @@ func TestResources(t *testing.T) {
|
|||||||
foo.Inputs.Strings(), fooRes.Output.String())
|
foo.Inputs.Strings(), fooRes.Output.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(fooRes.Args["jarArgs"], test.args) {
|
if fooRes.Args["jarArgs"] != test.args {
|
||||||
t.Errorf("foo resource jar args %q does not contain %q",
|
t.Errorf("foo resource jar args %q is not %q",
|
||||||
fooRes.Args["jarArgs"], test.args)
|
fooRes.Args["jarArgs"], test.args)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -489,7 +489,7 @@ func TestExcludeResources(t *testing.T) {
|
|||||||
|
|
||||||
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res.jar")
|
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res.jar")
|
||||||
|
|
||||||
expected := "-C res -l " + fooRes.Implicits[0].String()
|
expected := "-C res -f res/a -f res/b"
|
||||||
if fooRes.Args["jarArgs"] != expected {
|
if fooRes.Args["jarArgs"] != expected {
|
||||||
t.Errorf("foo resource jar args %q is not %q",
|
t.Errorf("foo resource jar args %q is not %q",
|
||||||
fooRes.Args["jarArgs"], expected)
|
fooRes.Args["jarArgs"], expected)
|
||||||
|
@@ -19,8 +19,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/blueprint/bootstrap"
|
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -33,15 +31,6 @@ var resourceExcludes = []string{
|
|||||||
"**/*~",
|
"**/*~",
|
||||||
}
|
}
|
||||||
|
|
||||||
func isStringInSlice(str string, slice []string) bool {
|
|
||||||
for _, s := range slice {
|
|
||||||
if s == str {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func ResourceDirsToJarArgs(ctx android.ModuleContext,
|
func ResourceDirsToJarArgs(ctx android.ModuleContext,
|
||||||
resourceDirs, excludeDirs []string) (args []string, deps android.Paths) {
|
resourceDirs, excludeDirs []string) (args []string, deps android.Paths) {
|
||||||
var excludes []string
|
var excludes []string
|
||||||
@@ -53,22 +42,22 @@ func ResourceDirsToJarArgs(ctx android.ModuleContext,
|
|||||||
|
|
||||||
excludes = append(excludes, resourceExcludes...)
|
excludes = append(excludes, resourceExcludes...)
|
||||||
|
|
||||||
for _, resourceDir := range resourceDirs {
|
for _, dir := range resourceDirs {
|
||||||
if isStringInSlice(resourceDir, excludeDirs) {
|
dir := android.PathForModuleSrc(ctx, dir).String()
|
||||||
continue
|
files := ctx.Glob(filepath.Join(dir, "**/*"), excludes)
|
||||||
}
|
|
||||||
resourceDir := android.PathForModuleSrc(ctx, resourceDir)
|
|
||||||
dirs := ctx.Glob(resourceDir.String(), nil)
|
|
||||||
for _, dir := range dirs {
|
|
||||||
fileListFile := android.ResPathWithName(ctx, dir, "resources.list")
|
|
||||||
depFile := fileListFile.String() + ".d"
|
|
||||||
|
|
||||||
pattern := filepath.Join(dir.String(), "**/*")
|
deps = append(deps, files...)
|
||||||
bootstrap.GlobFile(ctx, pattern, excludes, fileListFile.String(), depFile)
|
|
||||||
args = append(args,
|
if len(files) > 0 {
|
||||||
"-C", dir.String(),
|
args = append(args, "-C", dir)
|
||||||
"-l", fileListFile.String())
|
|
||||||
deps = append(deps, fileListFile)
|
for _, f := range files {
|
||||||
|
path := f.String()
|
||||||
|
if !strings.HasPrefix(path, dir) {
|
||||||
|
panic(fmt.Errorf("path %q does not start with %q", path, dir))
|
||||||
|
}
|
||||||
|
args = append(args, "-f", path)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,14 +87,19 @@ func resourceFilesToJarArgs(ctx android.ModuleContext,
|
|||||||
|
|
||||||
files := ctx.ExpandSources(res, exclude)
|
files := ctx.ExpandSources(res, exclude)
|
||||||
|
|
||||||
for _, f := range files {
|
lastDir := ""
|
||||||
|
for i, f := range files {
|
||||||
rel := f.Rel()
|
rel := f.Rel()
|
||||||
path := f.String()
|
path := f.String()
|
||||||
if !strings.HasSuffix(path, rel) {
|
if !strings.HasSuffix(path, rel) {
|
||||||
panic(fmt.Errorf("path %q does not end with %q", path, rel))
|
panic(fmt.Errorf("path %q does not end with %q", path, rel))
|
||||||
}
|
}
|
||||||
path = filepath.Clean(strings.TrimSuffix(path, rel))
|
dir := filepath.Clean(strings.TrimSuffix(path, rel))
|
||||||
args = append(args, "-C", filepath.Clean(path), "-f", f.String())
|
if i == 0 || dir != lastDir {
|
||||||
|
args = append(args, "-C", dir)
|
||||||
|
}
|
||||||
|
args = append(args, "-f", path)
|
||||||
|
lastDir = dir
|
||||||
}
|
}
|
||||||
|
|
||||||
return args, files
|
return args, files
|
||||||
|
Reference in New Issue
Block a user