summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/app.go11
-rw-r--r--java/dex.go34
-rw-r--r--java/dexpreopt.go31
-rw-r--r--java/java.go16
-rw-r--r--java/java_test.go23
-rw-r--r--java/jdeps.go2
-rw-r--r--java/robolectric.go1
7 files changed, 105 insertions, 13 deletions
diff --git a/java/app.go b/java/app.go
index 9b10bf3cd..17548e74a 100644
--- a/java/app.go
+++ b/java/app.go
@@ -452,6 +452,16 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
android.SetProvider(ctx, AppInfoProvider, appInfo)
a.requiredModuleNames = a.getRequiredModuleNames(ctx)
+
+ if a.dexer.proguardDictionary.Valid() {
+ android.SetProvider(ctx, ProguardProvider, ProguardInfo{
+ ModuleName: ctx.ModuleName(),
+ Class: "APPS",
+ ProguardDictionary: a.dexer.proguardDictionary.Path(),
+ ProguardUsageZip: a.dexer.proguardUsageZip.Path(),
+ ClassesJar: a.implementationAndResourcesJar,
+ })
+ }
}
func (a *AndroidApp) getRequiredModuleNames(ctx android.ModuleContext) []string {
@@ -1636,6 +1646,7 @@ func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Device_common_data)...)
a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Device_first_data)...)
a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Device_first_prefer32_data)...)
+ a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Host_common_data)...)
// Install test deps
if !ctx.Config().KatiEnabled() {
diff --git a/java/dex.go b/java/dex.go
index c9d3f376d..ed2df2103 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -435,6 +435,11 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, dexParams *compileDexParams,
android.PathForSource(ctx, "build/make/core/proguard.flags"),
}
+ if ctx.Config().UseR8GlobalCheckNotNullFlags() {
+ flagFiles = append(flagFiles, android.PathForSource(ctx,
+ "build/make/core/proguard/checknotnull.flags"))
+ }
+
flagFiles = append(flagFiles, d.extraProguardFlagsFiles...)
// TODO(ccross): static android library proguard files
@@ -583,7 +588,6 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam
var description string
var artProfileOutputPath *android.OutputPath
var implicitOutputs android.WritablePaths
- var flags []string
var deps android.Paths
args := map[string]string{
"zipFlags": zipFlags,
@@ -610,18 +614,13 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam
description = "r8"
debugMode := android.InList("--debug", commonFlags)
r8Flags, r8Deps, r8ArtProfileOutputPath := d.r8Flags(ctx, dexParams, debugMode)
- flags = append(flags, r8Flags...)
deps = append(deps, r8Deps...)
args["r8Flags"] = strings.Join(append(commonFlags, r8Flags...), " ")
if r8ArtProfileOutputPath != nil {
artProfileOutputPath = r8ArtProfileOutputPath
- implicitOutputs = append(
- implicitOutputs,
- artProfileOutputPath,
- )
// Add the implicit r8 Art profile output to args so that r8RE knows
// about this implicit output
- args["outR8ArtProfile"] = artProfileOutputPath.String()
+ args["outR8ArtProfile"] = r8ArtProfileOutputPath.String()
}
args["outDict"] = proguardDictionary.String()
args["outConfig"] = proguardConfiguration.String()
@@ -642,16 +641,11 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam
if useD8 {
description = "d8"
d8Flags, d8Deps, d8ArtProfileOutputPath := d.d8Flags(ctx, dexParams)
- flags = append(flags, d8Flags...)
deps = append(deps, d8Deps...)
deps = append(deps, commonDeps...)
args["d8Flags"] = strings.Join(append(commonFlags, d8Flags...), " ")
if d8ArtProfileOutputPath != nil {
artProfileOutputPath = d8ArtProfileOutputPath
- implicitOutputs = append(
- implicitOutputs,
- artProfileOutputPath,
- )
}
// If we are generating both d8 and r8, only use RBE when both are enabled.
switch {
@@ -667,6 +661,12 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam
rule = d8
}
}
+ if artProfileOutputPath != nil {
+ implicitOutputs = append(
+ implicitOutputs,
+ artProfileOutputPath,
+ )
+ }
ctx.Build(pctx, android.BuildParams{
Rule: rule,
Description: description,
@@ -697,3 +697,13 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam
return javalibJar, artProfileOutputPath
}
+
+type ProguardInfo struct {
+ ModuleName string
+ Class string
+ ProguardDictionary android.Path
+ ProguardUsageZip android.Path
+ ClassesJar android.Path
+}
+
+var ProguardProvider = blueprint.NewProvider[ProguardInfo]()
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index 5755dec23..b21cfc968 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -565,6 +565,10 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJa
if !isApexSystemServerJar {
d.builtInstalled = dexpreoptRule.Installs().String()
}
+
+ if isSystemServerJar {
+ checkSystemServerOrder(ctx, libName)
+ }
}
func getModuleInstallPathInfo(ctx android.ModuleContext, fullInstallPath string) (android.InstallPath, string, string) {
@@ -631,3 +635,30 @@ func (d *dexpreopter) GetRewrittenProfile() android.Path {
func (d *dexpreopter) SetRewrittenProfile(p android.Path) {
d.rewrittenProfile = p
}
+
+// Check the order of jars on the system server classpath and give a warning/error if a jar precedes
+// one of its dependencies. This is not an error, but a missed optimization, as dexpreopt won't
+// have the dependency jar in the class loader context, and it won't be able to resolve any
+// references to its classes and methods.
+func checkSystemServerOrder(ctx android.ModuleContext, libName string) {
+ config := dexpreopt.GetGlobalConfig(ctx)
+ jars := config.AllSystemServerClasspathJars(ctx)
+ jarIndex := config.AllSystemServerJars(ctx).IndexOfJar(libName)
+ ctx.WalkDeps(func(dep android.Module, parent android.Module) bool {
+ tag := ctx.OtherModuleDependencyTag(dep)
+ // Ideally this should only be walking relevant dependencies, but to maintain existing behavior
+ // for now just exclude any known irrelevant dependencies that would lead to incorrect errors.
+ if _, ok := tag.(bootclasspathDependencyTag); ok {
+ return false
+ }
+ depIndex := jars.IndexOfJar(dep.Name())
+ if jarIndex < depIndex && !config.BrokenSuboptimalOrderOfSystemServerJars {
+ jar := jars.Jar(jarIndex)
+ dep := jars.Jar(depIndex)
+ ctx.ModuleErrorf("non-optimal order of jars on the system server classpath:"+
+ " '%s' precedes its dependency '%s', so dexpreopt is unable to resolve any"+
+ " references from '%s' to '%s'.\n", jar, dep, jar, dep)
+ }
+ return true
+ })
+}
diff --git a/java/java.go b/java/java.go
index b9109ee94..b18c56130 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1172,6 +1172,16 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
buildComplianceMetadata(ctx)
j.createApiXmlFile(ctx)
+
+ if j.dexer.proguardDictionary.Valid() {
+ android.SetProvider(ctx, ProguardProvider, ProguardInfo{
+ ModuleName: ctx.ModuleName(),
+ Class: "JAVA_LIBRARIES",
+ ProguardDictionary: j.dexer.proguardDictionary.Path(),
+ ProguardUsageZip: j.dexer.proguardUsageZip.Path(),
+ ClassesJar: j.implementationAndResourcesJar,
+ })
+ }
}
func (j *Library) javaLibraryModuleInfoJSON(ctx android.ModuleContext) *android.ModuleInfoJSON {
@@ -1539,6 +1549,11 @@ type testProperties struct {
// host test.
Device_first_prefer32_data []string `android:"path_device_first_prefer32"`
+ // Same as data, but will add dependencies on modules using the host's os variation and
+ // the common arch variation. Useful for a device test that wants to depend on a host
+ // module, for example to include a custom Tradefed test runner.
+ Host_common_data []string `android:"path_host_common"`
+
// Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
// explicitly.
@@ -1837,6 +1852,7 @@ func (j *Test) generateAndroidBuildActionsWithConfig(ctx android.ModuleContext,
j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Device_common_data)...)
j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Device_first_data)...)
j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Device_first_prefer32_data)...)
+ j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Host_common_data)...)
j.extraTestConfigs = android.PathsForModuleSrc(ctx, j.testProperties.Test_options.Extra_test_configs)
diff --git a/java/java_test.go b/java/java_test.go
index 636a0c891..a6290a628 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -585,6 +585,29 @@ func TestTest(t *testing.T) {
}
}
+func TestHostCommonData(t *testing.T) {
+ t.Parallel()
+ ctx, _ := testJava(t, `
+ java_library_host {
+ name: "host",
+ srcs: ["a.java"],
+ }
+
+ java_test {
+ name: "foo",
+ srcs: ["a.java"],
+ host_common_data: [":host"],
+ }
+ `)
+
+ foo := ctx.ModuleForTests(t, "foo", "android_common").Module().(*Test)
+ host := ctx.ModuleForTests(t, "host", ctx.Config().BuildOSCommonTarget.String()).Module().(*Library)
+
+ if g, w := foo.data.RelativeToTop().Strings(), []string{host.outputFile.RelativeToTop().String()}; !slices.Equal(g, w) {
+ t.Errorf("expected test data %q, got %q\n", w, g)
+ }
+}
+
func TestHostBinaryNoJavaDebugInfoOverride(t *testing.T) {
t.Parallel()
bp := `
diff --git a/java/jdeps.go b/java/jdeps.go
index 927c1694d..07f8c4378 100644
--- a/java/jdeps.go
+++ b/java/jdeps.go
@@ -99,7 +99,7 @@ func (j *jdepsGeneratorSingleton) GenerateBuildActions(ctx android.SingletonCont
Rule: android.Touch,
Output: jfpath,
})
- ctx.DistForGoal("general-tests", j.outputPath)
+ ctx.DistForGoals([]string{"general-tests", "dist_files"}, j.outputPath)
}
func createJsonFile(moduleInfos map[string]android.IdeInfo, jfpath android.WritablePath) error {
diff --git a/java/robolectric.go b/java/robolectric.go
index 5dcc7dd81..be369f780 100644
--- a/java/robolectric.go
+++ b/java/robolectric.go
@@ -168,6 +168,7 @@ func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext)
r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Device_common_data)...)
r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Device_first_data)...)
r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Device_first_prefer32_data)...)
+ r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Host_common_data)...)
var ok bool
var instrumentedApp *JavaInfo