From 988708ce75c4e152a6b1f1a02fb096928e5d87c1 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 6 May 2019 14:04:11 -0700 Subject: [PATCH] Allow module types to generate resources Robolectric will need to generate extra resources to be added to the jar. Test: TestResources Change-Id: I028f91ea8fc5d1e59e4e805876d70f57d8899f11 --- java/java.go | 7 +++++++ java/java_resources.go | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/java/java.go b/java/java.go index 47dd95724..b9c06a8e9 100644 --- a/java/java.go +++ b/java/java.go @@ -340,6 +340,9 @@ type Module struct { // list of additional targets for checkbuild additionalCheckedModules android.Paths + // Extra files generated by the module type to be added as java resources. + extraResources android.Paths + hiddenAPI dexpreopter } @@ -1113,6 +1116,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources) fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources) + extraArgs, extraDeps := resourcePathsToJarArgs(j.extraResources), j.extraResources var resArgs []string var resDeps android.Paths @@ -1123,6 +1127,9 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path resArgs = append(resArgs, fileArgs...) resDeps = append(resDeps, fileDeps...) + resArgs = append(resArgs, extraArgs...) + resDeps = append(resDeps, extraDeps...) + if Bool(j.properties.Include_srcs) { srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs) resArgs = append(resArgs, srcArgs...) diff --git a/java/java_resources.go b/java/java_resources.go index 71611689a..1bbeb9a6c 100644 --- a/java/java_resources.go +++ b/java/java_resources.go @@ -98,6 +98,14 @@ func resourceFilesToJarArgs(ctx android.ModuleContext, files := android.PathsForModuleSrcExcludes(ctx, res, exclude) + args = resourcePathsToJarArgs(files) + + return args, files +} + +func resourcePathsToJarArgs(files android.Paths) []string { + var args []string + lastDir := "" for i, f := range files { rel := f.Rel() @@ -113,5 +121,5 @@ func resourceFilesToJarArgs(ctx android.ModuleContext, lastDir = dir } - return args, files + return args }