Fix stem to be propagated to output jar name in java_library
Currently, java_library.stem property is not correctly reflected in the
output jar name in java_library when the module specifies
java_resource_dirs property. This change fixes the unexpected behavior
so that setting the stem property behaves as expected.
Test: go test ./java && m
Bug: 285843207
Change-Id: I0941fcea83c92f4c42ae415aa6ad9125da5cf57b
diff --git a/java/base.go b/java/base.go
index cb08ef3..8db7162 100644
--- a/java/base.go
+++ b/java/base.go
@@ -21,6 +21,7 @@
"strings"
"android/soong/ui/metrics/bp2build_metrics_proto"
+
"github.com/google/blueprint/pathtools"
"github.com/google/blueprint/proptools"
@@ -502,6 +503,11 @@
sourceExtensions []string
annoSrcJars android.Paths
+
+ // output file name based on Stem property.
+ // This should be set in every ModuleWithStem's GenerateAndroidBuildActions
+ // or the module should override Stem().
+ stem string
}
func (j *Module) CheckStableSdkVersion(ctx android.BaseModuleContext) error {
@@ -1099,7 +1105,7 @@
j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
}
- jarName := ctx.ModuleName() + ".jar"
+ jarName := j.Stem() + ".jar"
var uniqueJavaFiles android.Paths
set := make(map[string]bool)
@@ -1897,7 +1903,10 @@
}
func (j *Module) Stem() string {
- return proptools.StringDefault(j.overridableDeviceProperties.Stem, j.Name())
+ if j.stem == "" {
+ panic("Stem() called before stem property was set")
+ }
+ return j.stem
}
func (j *Module) JacocoReportClassesFile() android.Path {