Allow wildcards in java_resource_dirs
Expand java_resource_dirs using ctx.Glob before globbing inside it in case it has wildcards in it. Fixes: internal error: panic in GenerateBuildActions for module "icu4j" variant "linux_glibc_common" path "external/icu/icu4j/main/classes/charset/src/META-INF" does not start with "external/icu/icu4j/main/classes/*/src" Test: java_test.go Change-Id: Icd28b7a3dd14752642fb0ec8d41bbd6e30f81a68
This commit is contained in:
@@ -143,8 +143,8 @@ func testContext(config android.Config, bp string,
|
|||||||
"b.kt": nil,
|
"b.kt": nil,
|
||||||
"a.jar": nil,
|
"a.jar": nil,
|
||||||
"b.jar": nil,
|
"b.jar": nil,
|
||||||
"java-res/a": nil,
|
"java-res/a/a": nil,
|
||||||
"java-res/b": nil,
|
"java-res/b/b": nil,
|
||||||
"java-res2/a": nil,
|
"java-res2/a": nil,
|
||||||
"java-fg/a.java": nil,
|
"java-fg/a.java": nil,
|
||||||
"java-fg/b.java": nil,
|
"java-fg/b.java": nil,
|
||||||
@@ -606,13 +606,13 @@ func TestResources(t *testing.T) {
|
|||||||
// Test that a module with java_resource_dirs includes the files
|
// Test that a module with java_resource_dirs includes the files
|
||||||
name: "resource dirs",
|
name: "resource dirs",
|
||||||
prop: `java_resource_dirs: ["java-res"]`,
|
prop: `java_resource_dirs: ["java-res"]`,
|
||||||
args: "-C java-res -f java-res/a -f java-res/b",
|
args: "-C java-res -f java-res/a/a -f java-res/b/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: ["java-res/a", "java-res/b"]`,
|
prop: `java_resources: ["java-res/a/a", "java-res/b/b"]`,
|
||||||
args: "-C . -f java-res/a -f java-res/b",
|
args: "-C . -f java-res/a/a -f java-res/b/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
|
||||||
@@ -623,9 +623,9 @@ func TestResources(t *testing.T) {
|
|||||||
filegroup {
|
filegroup {
|
||||||
name: "foo-res",
|
name: "foo-res",
|
||||||
path: "java-res",
|
path: "java-res",
|
||||||
srcs: ["java-res/a", "java-res/b"],
|
srcs: ["java-res/a/a", "java-res/b/b"],
|
||||||
}`,
|
}`,
|
||||||
args: "-C java-res -f java-res/a -f java-res/b",
|
args: "-C java-res -f java-res/a/a -f java-res/b/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
|
||||||
@@ -633,6 +633,18 @@ func TestResources(t *testing.T) {
|
|||||||
prop: `include_srcs: true`,
|
prop: `include_srcs: true`,
|
||||||
args: "-C . -f a.java -f b.java -f c.java",
|
args: "-C . -f a.java -f b.java -f c.java",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// Test that a module with wildcards in java_resource_dirs has the correct path prefixes
|
||||||
|
name: "wildcard dirs",
|
||||||
|
prop: `java_resource_dirs: ["java-res/*"]`,
|
||||||
|
args: "-C java-res/a -f java-res/a/a -C java-res/b -f java-res/b/b",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Test that a module exclude_java_resource_dirs excludes the files
|
||||||
|
name: "wildcard dirs",
|
||||||
|
prop: `java_resource_dirs: ["java-res/*"], exclude_java_resource_dirs: ["java-res/b"]`,
|
||||||
|
args: "-C java-res/a -f java-res/a/a",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
@@ -677,14 +689,14 @@ func TestExcludeResources(t *testing.T) {
|
|||||||
java_library {
|
java_library {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
java_resources: ["java-res/*"],
|
java_resources: ["java-res/*/*"],
|
||||||
exclude_java_resources: ["java-res/b"],
|
exclude_java_resources: ["java-res/b/*"],
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar")
|
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar")
|
||||||
|
|
||||||
expected := "-C java-res -f java-res/a -f java-res/b"
|
expected := "-C java-res -f java-res/a/a -f java-res/b/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)
|
||||||
@@ -693,7 +705,7 @@ func TestExcludeResources(t *testing.T) {
|
|||||||
|
|
||||||
barRes := ctx.ModuleForTests("bar", "android_common").Output("res/bar.jar")
|
barRes := ctx.ModuleForTests("bar", "android_common").Output("res/bar.jar")
|
||||||
|
|
||||||
expected = "-C . -f java-res/a"
|
expected = "-C . -f java-res/a/a"
|
||||||
if barRes.Args["jarArgs"] != expected {
|
if barRes.Args["jarArgs"] != expected {
|
||||||
t.Errorf("bar resource jar args %q is not %q",
|
t.Errorf("bar resource jar args %q is not %q",
|
||||||
barRes.Args["jarArgs"], expected)
|
barRes.Args["jarArgs"], expected)
|
||||||
|
@@ -32,31 +32,38 @@ var resourceExcludes = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ResourceDirsToJarArgs(ctx android.ModuleContext,
|
func ResourceDirsToJarArgs(ctx android.ModuleContext,
|
||||||
resourceDirs, excludeDirs []string) (args []string, deps android.Paths) {
|
resourceDirs, excludeResourceDirs []string) (args []string, deps android.Paths) {
|
||||||
var excludes []string
|
var excludeDirs []string
|
||||||
|
var excludeFiles []string
|
||||||
|
|
||||||
for _, exclude := range excludeDirs {
|
for _, exclude := range excludeResourceDirs {
|
||||||
excludes = append(excludes,
|
dirs := ctx.Glob(android.PathForModuleSrc(ctx).Join(ctx, exclude).String(), nil)
|
||||||
filepath.Join(android.PathForModuleSrc(ctx, exclude).String(), "**/*"))
|
for _, dir := range dirs {
|
||||||
|
excludeDirs = append(excludeDirs, dir.String())
|
||||||
|
excludeFiles = append(excludeFiles, dir.(android.ModuleSrcPath).Join(ctx, "**/*").String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
excludes = append(excludes, resourceExcludes...)
|
excludeFiles = append(excludeFiles, resourceExcludes...)
|
||||||
|
|
||||||
for _, dir := range resourceDirs {
|
for _, resourceDir := range resourceDirs {
|
||||||
dir := android.PathForModuleSrc(ctx, dir).String()
|
// resourceDir may be a glob, resolve it first
|
||||||
files := ctx.Glob(filepath.Join(dir, "**/*"), excludes)
|
dirs := ctx.Glob(android.PathForModuleSrc(ctx).Join(ctx, resourceDir).String(), excludeDirs)
|
||||||
|
for _, dir := range dirs {
|
||||||
|
files := ctx.GlobFiles(filepath.Join(dir.String(), "**/*"), excludeFiles)
|
||||||
|
|
||||||
deps = append(deps, files...)
|
deps = append(deps, files...)
|
||||||
|
|
||||||
if len(files) > 0 {
|
if len(files) > 0 {
|
||||||
args = append(args, "-C", dir)
|
args = append(args, "-C", dir.String())
|
||||||
|
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
path := f.String()
|
path := f.String()
|
||||||
if !strings.HasPrefix(path, dir) {
|
if !strings.HasPrefix(path, dir.String()) {
|
||||||
panic(fmt.Errorf("path %q does not start with %q", path, dir))
|
panic(fmt.Errorf("path %q does not start with %q", path, dir))
|
||||||
|
}
|
||||||
|
args = append(args, "-f", path)
|
||||||
}
|
}
|
||||||
args = append(args, "-f", path)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user