summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/Android.bp1
-rw-r--r--java/androidmk.go3
-rw-r--r--java/boot_image.go14
-rw-r--r--java/bootclasspath.go145
-rw-r--r--java/dexpreopt.go40
-rw-r--r--java/dexpreopt_config.go4
-rw-r--r--java/platform_bootclasspath.go110
7 files changed, 186 insertions, 131 deletions
diff --git a/java/Android.bp b/java/Android.bp
index 8e3e10d9d..e367a0073 100644
--- a/java/Android.bp
+++ b/java/Android.bp
@@ -31,6 +31,7 @@ bootstrap_go_package {
"base.go",
"boot_image.go",
"boot_jars.go",
+ "bootclasspath.go",
"builder.go",
"classpath_fragment.go",
"device_host_converter.go",
diff --git a/java/androidmk.go b/java/androidmk.go
index 4e594a2fa..015454464 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -398,6 +398,9 @@ func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries {
if len(app.dexpreopter.builtInstalled) > 0 {
entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", app.dexpreopter.builtInstalled)
}
+ if app.dexpreopter.configPath != nil {
+ entries.SetPath("LOCAL_SOONG_DEXPREOPT_CONFIG", app.dexpreopter.configPath)
+ }
for _, extra := range app.extraOutputFiles {
install := app.onDeviceDir + "/" + extra.Base()
entries.AddStrings("LOCAL_SOONG_BUILT_INSTALLED", extra.String()+":"+install)
diff --git a/java/boot_image.go b/java/boot_image.go
index d0862a961..6f50c27e6 100644
--- a/java/boot_image.go
+++ b/java/boot_image.go
@@ -124,8 +124,22 @@ func bootImageConsistencyCheck(ctx android.EarlyModuleContext, m *BootImageModul
if m.properties.Image_name != nil && len(contents) != 0 {
ctx.ModuleErrorf(`both of the "image_name" and "contents" properties have been supplied, please supply exactly one`)
}
+
imageName := proptools.String(m.properties.Image_name)
if imageName == "art" {
+ // TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
+ if m.MemberName() != "" {
+ // The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
+ // 1. There is no way to use this at the moment so ignoring it is safe.
+ // 2. Attempting to initialize the contents property from the configuration will end up having
+ // the versioned prebuilt depending on the unversioned prebuilt. That will cause problems
+ // as the unversioned prebuilt could end up with an APEX variant created for the source
+ // APEX which will prevent it from having an APEX variant for the prebuilt APEX which in
+ // turn will prevent it from accessing the dex implementation jar from that which will
+ // break hidden API processing, amongst others.
+ return
+ }
+
// Get the configuration for the art apex jars. Do not use getImageConfig(ctx) here as this is
// too early in the Soong processing for that to work.
global := dexpreopt.GetGlobalConfig(ctx)
diff --git a/java/bootclasspath.go b/java/bootclasspath.go
new file mode 100644
index 000000000..b140a3080
--- /dev/null
+++ b/java/bootclasspath.go
@@ -0,0 +1,145 @@
+// Copyright 2021 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package java
+
+import (
+ "fmt"
+
+ "android/soong/android"
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
+)
+
+// Contains code that is common to both platform_bootclasspath and bootclasspath_fragment.
+
+// addDependencyOntoApexVariants adds dependencies onto the appropriate apex specific variants of
+// the module as specified in the ApexVariantReference list.
+func addDependencyOntoApexVariants(ctx android.BottomUpMutatorContext, propertyName string, refs []ApexVariantReference, tag blueprint.DependencyTag) {
+ for i, ref := range refs {
+ apex := proptools.StringDefault(ref.Apex, "platform")
+
+ if ref.Module == nil {
+ ctx.PropertyErrorf(propertyName, "missing module name at position %d", i)
+ continue
+ }
+ name := proptools.String(ref.Module)
+
+ addDependencyOntoApexModulePair(ctx, apex, name, tag)
+ }
+}
+
+// addDependencyOntoApexModulePair adds a dependency onto the specified APEX specific variant or the
+// specified module.
+//
+// If apex="platform" then this adds a dependency onto the platform variant of the module. This adds
+// dependencies onto the prebuilt and source modules with the specified name, depending on which
+// ones are available. Visiting must use isActiveModule to select the preferred module when both
+// source and prebuilt modules are available.
+func addDependencyOntoApexModulePair(ctx android.BottomUpMutatorContext, apex string, name string, tag blueprint.DependencyTag) {
+ var variations []blueprint.Variation
+ if apex != "platform" {
+ // Pick the correct apex variant.
+ variations = []blueprint.Variation{
+ {Mutator: "apex", Variation: apex},
+ }
+ }
+
+ addedDep := false
+ if ctx.OtherModuleDependencyVariantExists(variations, name) {
+ ctx.AddFarVariationDependencies(variations, tag, name)
+ addedDep = true
+ }
+
+ // Add a dependency on the prebuilt module if it exists.
+ prebuiltName := android.PrebuiltNameFromSource(name)
+ if ctx.OtherModuleDependencyVariantExists(variations, prebuiltName) {
+ ctx.AddVariationDependencies(variations, tag, prebuiltName)
+ addedDep = true
+ }
+
+ // If no appropriate variant existing for this, so no dependency could be added, then it is an
+ // error, unless missing dependencies are allowed. The simplest way to handle that is to add a
+ // dependency that will not be satisfied and the default behavior will handle it.
+ if !addedDep {
+ // Add dependency on the unprefixed (i.e. source or renamed prebuilt) module which we know does
+ // not exist. The resulting error message will contain useful information about the available
+ // variants.
+ reportMissingVariationDependency(ctx, variations, name)
+
+ // Add dependency on the missing prefixed prebuilt variant too if a module with that name exists
+ // so that information about its available variants will be reported too.
+ if ctx.OtherModuleExists(prebuiltName) {
+ reportMissingVariationDependency(ctx, variations, prebuiltName)
+ }
+ }
+}
+
+// reportMissingVariationDependency intentionally adds a dependency on a missing variation in order
+// to generate an appropriate error message with information about the available variations.
+func reportMissingVariationDependency(ctx android.BottomUpMutatorContext, variations []blueprint.Variation, name string) {
+ modules := ctx.AddFarVariationDependencies(variations, nil, name)
+ if len(modules) != 1 {
+ panic(fmt.Errorf("Internal Error: expected one module, found %d", len(modules)))
+ return
+ }
+ if modules[0] != nil {
+ panic(fmt.Errorf("Internal Error: expected module to be missing but was found: %q", modules[0]))
+ return
+ }
+}
+
+// ApexVariantReference specifies a particular apex variant of a module.
+type ApexVariantReference struct {
+ // The name of the module apex variant, i.e. the apex containing the module variant.
+ //
+ // If this is not specified then it defaults to "platform" which will cause a dependency to be
+ // added to the module's platform variant.
+ Apex *string
+
+ // The name of the module.
+ Module *string
+}
+
+// BootclasspathFragmentsDepsProperties contains properties related to dependencies onto fragments.
+type BootclasspathFragmentsDepsProperties struct {
+ // The names of the bootclasspath_fragment modules that form part of this module.
+ Fragments []ApexVariantReference
+}
+
+// addDependenciesOntoFragments adds dependencies to the fragments specified in this properties
+// structure.
+func (p *BootclasspathFragmentsDepsProperties) addDependenciesOntoFragments(ctx android.BottomUpMutatorContext) {
+ addDependencyOntoApexVariants(ctx, "fragments", p.Fragments, bootclasspathFragmentDepTag)
+}
+
+// bootclasspathDependencyTag defines dependencies from/to bootclasspath_fragment,
+// prebuilt_bootclasspath_fragment and platform_bootclasspath onto either source or prebuilt
+// modules.
+type bootclasspathDependencyTag struct {
+ blueprint.BaseDependencyTag
+
+ name string
+}
+
+func (t bootclasspathDependencyTag) ExcludeFromVisibilityEnforcement() {
+}
+
+// Dependencies that use the bootclasspathDependencyTag instances are only added after all the
+// visibility checking has been done so this has no functional effect. However, it does make it
+// clear that visibility is not being enforced on these tags.
+var _ android.ExcludeFromVisibilityEnforcementTag = bootclasspathDependencyTag{}
+
+// The tag used for dependencies onto bootclasspath_fragments.
+var bootclasspathFragmentDepTag = bootclasspathDependencyTag{name: "fragment"}
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index 3571590db..d00d74b8c 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -41,9 +41,12 @@ type dexpreopter struct {
builtInstalled string
- // A path to a dexpreopt.config file generated by Soong for libraries that may be used as a
- // <uses-library> by Make modules. The path is passed to Make via LOCAL_SOONG_DEXPREOPT_CONFIG
- // variable. If the path is nil, no config is generated (which is the case for apps and tests).
+ // The config is used for two purposes:
+ // - Passing dexpreopt information about libraries from Soong to Make. This is needed when
+ // a <uses-library> is defined in Android.bp, but used in Android.mk (see dex_preopt_config_merger.py).
+ // Note that dexpreopt.config might be needed even if dexpreopt is disabled for the library itself.
+ // - Dexpreopt post-processing (using dexpreopt artifacts from a prebuilt system image to incrementally
+ // dexpreopt another partition).
configPath android.WritablePath
}
@@ -138,27 +141,13 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr
}
}
- if !d.isApp && !d.isTest {
- // Slim dexpreopt config is serialized to dexpreopt.config files and used by
- // dex_preopt_config_merger.py to get information about <uses-library> dependencies.
- // Note that it might be needed even if dexpreopt is disabled for this module.
- slimDexpreoptConfig := &dexpreopt.ModuleConfig{
- Name: ctx.ModuleName(),
- DexLocation: dexLocation,
- EnforceUsesLibraries: d.enforceUsesLibs,
- ProvidesUsesLibrary: providesUsesLib,
- ClassLoaderContexts: d.classLoaderContexts,
- // The rest of the fields are not needed.
- }
- d.configPath = android.PathForModuleOut(ctx, "dexpreopt", "dexpreopt.config")
- dexpreopt.WriteSlimModuleConfigForMake(ctx, slimDexpreoptConfig, d.configPath)
- }
-
- if d.dexpreoptDisabled(ctx) {
+ // If it is neither app nor test, make config files regardless of its dexpreopt setting.
+ // The config files are required for apps defined in make which depend on the lib.
+ // TODO(b/158843648): The config for apps should be generated as well regardless of setting.
+ if (d.isApp || d.isTest) && d.dexpreoptDisabled(ctx) {
return
}
- globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
global := dexpreopt.GetGlobalConfig(ctx)
isSystemServerJar := inList(ctx.ModuleName(), global.SystemServerJars)
@@ -251,6 +240,15 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr
PresignedPrebuilt: d.isPresignedPrebuilt,
}
+ d.configPath = android.PathForModuleOut(ctx, "dexpreopt", "dexpreopt.config")
+ dexpreopt.WriteModuleConfig(ctx, dexpreoptConfig, d.configPath)
+
+ if d.dexpreoptDisabled(ctx) {
+ return
+ }
+
+ globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
+
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(ctx, globalSoong, global, dexpreoptConfig)
if err != nil {
ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error())
diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go
index 656f5ef71..0ab650287 100644
--- a/java/dexpreopt_config.go
+++ b/java/dexpreopt_config.go
@@ -236,9 +236,5 @@ func init() {
}
func dexpreoptConfigMakevars(ctx android.MakeVarsContext) {
- ctx.Strict("PRODUCT_BOOTCLASSPATH", strings.Join(defaultBootclasspath(ctx), ":"))
- ctx.Strict("PRODUCT_DEX2OAT_BOOTCLASSPATH", strings.Join(defaultBootImageConfig(ctx).getAnyAndroidVariant().dexLocationsDeps, ":"))
- ctx.Strict("PRODUCT_SYSTEM_SERVER_CLASSPATH", strings.Join(systemServerClasspath(ctx), ":"))
-
ctx.Strict("DEXPREOPT_BOOT_JARS_MODULES", strings.Join(defaultBootImageConfig(ctx).modules.CopyOfApexJarPairs(), ":"))
}
diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go
index 568f5e406..38ce98525 100644
--- a/java/platform_bootclasspath.go
+++ b/java/platform_bootclasspath.go
@@ -19,8 +19,6 @@ import (
"android/soong/android"
"android/soong/dexpreopt"
- "github.com/google/blueprint"
- "github.com/google/blueprint/proptools"
)
func init() {
@@ -35,27 +33,8 @@ func registerPlatformBootclasspathBuildComponents(ctx android.RegistrationContex
})
}
-type platformBootclasspathDependencyTag struct {
- blueprint.BaseDependencyTag
-
- name string
-}
-
-// Avoid having to make platform bootclasspath content visible to the platform bootclasspath.
-//
-// This is a temporary workaround to make it easier to migrate to platform bootclasspath with proper
-// dependencies.
-// TODO(b/177892522): Remove this and add needed visibility.
-func (t platformBootclasspathDependencyTag) ExcludeFromVisibilityEnforcement() {
-}
-
// The tag used for the dependency between the platform bootclasspath and any configured boot jars.
-var platformBootclasspathModuleDepTag = platformBootclasspathDependencyTag{name: "module"}
-
-// The tag used for the dependency between the platform bootclasspath and bootclasspath_fragments.
-var platformBootclasspathFragmentDepTag = platformBootclasspathDependencyTag{name: "fragment"}
-
-var _ android.ExcludeFromVisibilityEnforcementTag = platformBootclasspathDependencyTag{}
+var platformBootclasspathModuleDepTag = bootclasspathDependencyTag{name: "module"}
type platformBootclasspathModule struct {
android.ModuleBase
@@ -83,22 +62,8 @@ type platformBootclasspathModule struct {
hiddenAPIMetadataCSV android.OutputPath
}
-// ApexVariantReference specifies a particular apex variant of a module.
-type ApexVariantReference struct {
- // The name of the module apex variant, i.e. the apex containing the module variant.
- //
- // If this is not specified then it defaults to "platform" which will cause a dependency to be
- // added to the module's platform variant.
- Apex *string
-
- // The name of the module.
- Module *string
-}
-
type platformBootclasspathProperties struct {
- // The names of the bootclasspath_fragment modules that form part of this
- // platform_bootclasspath.
- Fragments []ApexVariantReference
+ BootclasspathFragmentsDepsProperties
Hidden_api HiddenAPIFlagFileProperties
}
@@ -178,74 +143,7 @@ func platformBootclasspathDepsMutator(ctx android.BottomUpMutatorContext) {
addDependenciesOntoBootImageModules(ctx, updatableModules)
// Add dependencies on all the fragments.
- addDependencyOntoApexVariants(ctx, "fragments", p.properties.Fragments, platformBootclasspathFragmentDepTag)
- }
-}
-
-func addDependencyOntoApexVariants(ctx android.BottomUpMutatorContext, propertyName string, refs []ApexVariantReference, tag blueprint.DependencyTag) {
- for i, ref := range refs {
- apex := proptools.StringDefault(ref.Apex, "platform")
-
- if ref.Module == nil {
- ctx.PropertyErrorf(propertyName, "missing module name at position %d", i)
- continue
- }
- name := proptools.String(ref.Module)
-
- addDependencyOntoApexModulePair(ctx, apex, name, tag)
- }
-}
-
-func addDependencyOntoApexModulePair(ctx android.BottomUpMutatorContext, apex string, name string, tag blueprint.DependencyTag) {
- var variations []blueprint.Variation
- if apex != "platform" {
- // Pick the correct apex variant.
- variations = []blueprint.Variation{
- {Mutator: "apex", Variation: apex},
- }
- }
-
- addedDep := false
- if ctx.OtherModuleDependencyVariantExists(variations, name) {
- ctx.AddFarVariationDependencies(variations, tag, name)
- addedDep = true
- }
-
- // Add a dependency on the prebuilt module if it exists.
- prebuiltName := android.PrebuiltNameFromSource(name)
- if ctx.OtherModuleDependencyVariantExists(variations, prebuiltName) {
- ctx.AddVariationDependencies(variations, tag, prebuiltName)
- addedDep = true
- }
-
- // If no appropriate variant existing for this, so no dependency could be added, then it is an
- // error, unless missing dependencies are allowed. The simplest way to handle that is to add a
- // dependency that will not be satisfied and the default behavior will handle it.
- if !addedDep {
- // Add dependency on the unprefixed (i.e. source or renamed prebuilt) module which we know does
- // not exist. The resulting error message will contain useful information about the available
- // variants.
- reportMissingVariationDependency(ctx, variations, name)
-
- // Add dependency on the missing prefixed prebuilt variant too if a module with that name exists
- // so that information about its available variants will be reported too.
- if ctx.OtherModuleExists(prebuiltName) {
- reportMissingVariationDependency(ctx, variations, prebuiltName)
- }
- }
-}
-
-// reportMissingVariationDependency intentionally adds a dependency on a missing variation in order
-// to generate an appropriate error message with information about the available variations.
-func reportMissingVariationDependency(ctx android.BottomUpMutatorContext, variations []blueprint.Variation, name string) {
- modules := ctx.AddFarVariationDependencies(variations, nil, name)
- if len(modules) != 1 {
- panic(fmt.Errorf("Internal Error: expected one module, found %d", len(modules)))
- return
- }
- if modules[0] != nil {
- panic(fmt.Errorf("Internal Error: expected module to be missing but was found: %q", modules[0]))
- return
+ p.properties.BootclasspathFragmentsDepsProperties.addDependenciesOntoFragments(ctx)
}
}
@@ -265,7 +163,7 @@ func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.Mo
tag := ctx.OtherModuleDependencyTag(module)
if tag == platformBootclasspathModuleDepTag {
b.configuredModules = append(b.configuredModules, module)
- } else if tag == platformBootclasspathFragmentDepTag {
+ } else if tag == bootclasspathFragmentDepTag {
b.fragments = append(b.fragments, module)
}
})