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:
parent
f19b9bb981
commit
0ead1d75ce
|
@ -143,8 +143,8 @@ func testContext(config android.Config, bp string,
|
|||
"b.kt": nil,
|
||||
"a.jar": nil,
|
||||
"b.jar": nil,
|
||||
"java-res/a": nil,
|
||||
"java-res/b": nil,
|
||||
"java-res/a/a": nil,
|
||||
"java-res/b/b": nil,
|
||||
"java-res2/a": nil,
|
||||
"java-fg/a.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
|
||||
name: "resource dirs",
|
||||
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
|
||||
name: "resource files",
|
||||
prop: `java_resources: ["java-res/a", "java-res/b"]`,
|
||||
args: "-C . -f java-res/a -f java-res/b",
|
||||
prop: `java_resources: ["java-res/a/a", "java-res/b/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
|
||||
|
@ -623,9 +623,9 @@ func TestResources(t *testing.T) {
|
|||
filegroup {
|
||||
name: "foo-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
|
||||
|
@ -633,6 +633,18 @@ func TestResources(t *testing.T) {
|
|||
prop: `include_srcs: true`,
|
||||
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 {
|
||||
|
@ -677,14 +689,14 @@ func TestExcludeResources(t *testing.T) {
|
|||
java_library {
|
||||
name: "bar",
|
||||
srcs: ["a.java"],
|
||||
java_resources: ["java-res/*"],
|
||||
exclude_java_resources: ["java-res/b"],
|
||||
java_resources: ["java-res/*/*"],
|
||||
exclude_java_resources: ["java-res/b/*"],
|
||||
}
|
||||
`)
|
||||
|
||||
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 {
|
||||
t.Errorf("foo resource jar args %q is not %q",
|
||||
fooRes.Args["jarArgs"], expected)
|
||||
|
@ -693,7 +705,7 @@ func TestExcludeResources(t *testing.T) {
|
|||
|
||||
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 {
|
||||
t.Errorf("bar resource jar args %q is not %q",
|
||||
barRes.Args["jarArgs"], expected)
|
||||
|
|
|
@ -32,31 +32,38 @@ var resourceExcludes = []string{
|
|||
}
|
||||
|
||||
func ResourceDirsToJarArgs(ctx android.ModuleContext,
|
||||
resourceDirs, excludeDirs []string) (args []string, deps android.Paths) {
|
||||
var excludes []string
|
||||
resourceDirs, excludeResourceDirs []string) (args []string, deps android.Paths) {
|
||||
var excludeDirs []string
|
||||
var excludeFiles []string
|
||||
|
||||
for _, exclude := range excludeDirs {
|
||||
excludes = append(excludes,
|
||||
filepath.Join(android.PathForModuleSrc(ctx, exclude).String(), "**/*"))
|
||||
for _, exclude := range excludeResourceDirs {
|
||||
dirs := ctx.Glob(android.PathForModuleSrc(ctx).Join(ctx, exclude).String(), nil)
|
||||
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 {
|
||||
dir := android.PathForModuleSrc(ctx, dir).String()
|
||||
files := ctx.Glob(filepath.Join(dir, "**/*"), excludes)
|
||||
for _, resourceDir := range resourceDirs {
|
||||
// resourceDir may be a glob, resolve it first
|
||||
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 {
|
||||
args = append(args, "-C", dir)
|
||||
if len(files) > 0 {
|
||||
args = append(args, "-C", dir.String())
|
||||
|
||||
for _, f := range files {
|
||||
path := f.String()
|
||||
if !strings.HasPrefix(path, dir) {
|
||||
panic(fmt.Errorf("path %q does not start with %q", path, dir))
|
||||
for _, f := range files {
|
||||
path := f.String()
|
||||
if !strings.HasPrefix(path, dir.String()) {
|
||||
panic(fmt.Errorf("path %q does not start with %q", path, dir))
|
||||
}
|
||||
args = append(args, "-f", path)
|
||||
}
|
||||
args = append(args, "-f", path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue