Merge changes from topic "dex2oat-soong-dep-2" am: c9f9ab89a9 am: d0b12394bc am: 004ad89cdb

Change-Id: Ia96b651b0eb456a970a9fe065babe4d9460a46aa
This commit is contained in:
Treehugger Robot
2020-02-13 22:58:51 +00:00
13 changed files with 388 additions and 167 deletions

View File

@@ -142,6 +142,10 @@ type AndroidApp struct {
noticeOutputs android.NoticeOutputs
}
func (a *AndroidApp) IsInstallable() bool {
return Bool(a.properties.Installable)
}
func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths {
return nil
}
@@ -338,7 +342,6 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path {
installDir = filepath.Join("app", a.installApkName)
}
a.dexpreopter.installPath = android.PathForModuleInstall(ctx, installDir, a.installApkName+".apk")
a.dexpreopter.isInstallable = Bool(a.properties.Installable)
a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx)
a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries()
@@ -922,6 +925,10 @@ type AndroidAppImportProperties struct {
Filename *string
}
func (a *AndroidAppImport) IsInstallable() bool {
return true
}
// Updates properties with variant-specific values.
func (a *AndroidAppImport) processVariants(ctx android.LoadHookContext) {
config := ctx.Config()
@@ -1064,7 +1071,6 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext
}
a.dexpreopter.installPath = installDir.Join(ctx, a.BaseModuleName()+".apk")
a.dexpreopter.isInstallable = true
a.dexpreopter.isPresignedPrebuilt = Bool(a.properties.Presigned)
a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx)

View File

@@ -19,6 +19,11 @@ import (
"android/soong/dexpreopt"
)
type dexpreopterInterface interface {
IsInstallable() bool // Structs that embed dexpreopter must implement this.
dexpreoptDisabled(ctx android.BaseModuleContext) bool
}
type dexpreopter struct {
dexpreoptProperties DexpreoptProperties
@@ -26,7 +31,6 @@ type dexpreopter struct {
uncompressedDex bool
isSDKLibrary bool
isTest bool
isInstallable bool
isPresignedPrebuilt bool
manifestFile android.Path
@@ -58,8 +62,8 @@ type DexpreoptProperties struct {
}
}
func (d *dexpreopter) dexpreoptDisabled(ctx android.ModuleContext) bool {
global := dexpreoptGlobalConfig(ctx)
func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool {
global := dexpreopt.GetGlobalConfig(ctx)
if global.DisablePreopt {
return true
@@ -81,7 +85,11 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.ModuleContext) bool {
return true
}
if !d.isInstallable {
if !ctx.Module().(dexpreopterInterface).IsInstallable() {
return true
}
if ctx.Host() {
return true
}
@@ -95,16 +103,28 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.ModuleContext) bool {
return false
}
func dexpreoptToolDepsMutator(ctx android.BottomUpMutatorContext) {
if d, ok := ctx.Module().(dexpreopterInterface); !ok || d.dexpreoptDisabled(ctx) {
return
}
dexpreopt.RegisterToolDeps(ctx)
}
func odexOnSystemOther(ctx android.ModuleContext, installPath android.InstallPath) bool {
return dexpreopt.OdexOnSystemOtherByName(ctx.ModuleName(), android.InstallPathToOnDevicePath(ctx, installPath), dexpreoptGlobalConfig(ctx))
return dexpreopt.OdexOnSystemOtherByName(ctx.ModuleName(), android.InstallPathToOnDevicePath(ctx, installPath), dexpreopt.GetGlobalConfig(ctx))
}
func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.ModuleOutPath) android.ModuleOutPath {
if d.dexpreoptDisabled(ctx) {
// TODO(b/148690468): The check on d.installPath is to bail out in cases where
// the dexpreopter struct hasn't been fully initialized before we're called,
// e.g. in aar.go. This keeps the behaviour that dexpreopting is effectively
// disabled, even if installable is true.
if d.dexpreoptDisabled(ctx) || d.installPath.Base() == "." {
return dexJarFile
}
global := dexpreoptGlobalConfig(ctx)
globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
global := dexpreopt.GetGlobalConfig(ctx)
bootImage := defaultBootImageConfig(ctx)
dexFiles := bootImage.dexPathsDeps.Paths()
dexLocations := bootImage.dexLocationsDeps
@@ -156,7 +176,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo
}
}
dexpreoptConfig := dexpreopt.ModuleConfig{
dexpreoptConfig := &dexpreopt.ModuleConfig{
Name: ctx.ModuleName(),
DexLocation: dexLocation,
BuildPath: android.PathForModuleOut(ctx, "dexpreopt", ctx.ModuleName()+".jar").OutputPath,
@@ -191,7 +211,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo
PresignedPrebuilt: d.isPresignedPrebuilt,
}
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(ctx, global, dexpreoptConfig)
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(ctx, globalSoong, global, dexpreoptConfig)
if err != nil {
ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error())
return dexJarFile

View File

@@ -165,7 +165,7 @@ func dexpreoptBootJarsFactory() android.Singleton {
}
func skipDexpreoptBootJars(ctx android.PathContext) bool {
if dexpreoptGlobalConfig(ctx).DisablePreopt {
if dexpreopt.GetGlobalConfig(ctx).DisablePreopt {
return true
}
@@ -205,11 +205,15 @@ func (d *dexpreoptBootJars) GenerateBuildActions(ctx android.SingletonContext) {
if skipDexpreoptBootJars(ctx) {
return
}
if dexpreopt.GetCachedGlobalSoongConfig(ctx) == nil {
// No module has enabled dexpreopting, so we assume there will be no boot image to make.
return
}
d.dexpreoptConfigForMake = android.PathForOutput(ctx, ctx.Config().DeviceName(), "dexpreopt.config")
writeGlobalConfigForMake(ctx, d.dexpreoptConfigForMake)
global := dexpreoptGlobalConfig(ctx)
global := dexpreopt.GetGlobalConfig(ctx)
// Skip recompiling the boot image for the second sanitization phase. We'll get separate paths
// and invalidate first-stage artifacts which are crucial to SANITIZE_LITE builds.
@@ -295,7 +299,8 @@ func buildBootImage(ctx android.SingletonContext, config bootImageConfig) *bootI
func buildBootImageRuleForArch(ctx android.SingletonContext, image *bootImage,
arch android.ArchType, profile android.Path, missingDeps []string) android.WritablePaths {
global := dexpreoptGlobalConfig(ctx)
globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
global := dexpreopt.GetGlobalConfig(ctx)
symbolsDir := image.symbolsDir.Join(ctx, image.installSubdir, arch.String())
symbolsFile := symbolsDir.Join(ctx, image.stem+".oat")
@@ -330,7 +335,7 @@ func buildBootImageRuleForArch(ctx android.SingletonContext, image *bootImage,
invocationPath := outputPath.ReplaceExtension(ctx, "invocation")
cmd.Tool(global.SoongConfig.Dex2oat).
cmd.Tool(globalSoong.Dex2oat).
Flag("--avoid-storing-invocation").
FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath).
Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatImageXms).
@@ -433,7 +438,8 @@ It is likely that the boot classpath is inconsistent.
Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS="--runtime-arg -verbose:verifier" to see verification errors.`
func bootImageProfileRule(ctx android.SingletonContext, image *bootImage, missingDeps []string) android.WritablePath {
global := dexpreoptGlobalConfig(ctx)
globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
global := dexpreopt.GetGlobalConfig(ctx)
if global.DisableGenerateProfile || ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() {
return nil
@@ -464,7 +470,7 @@ func bootImageProfileRule(ctx android.SingletonContext, image *bootImage, missin
rule.Command().
Text(`ANDROID_LOG_TAGS="*:e"`).
Tool(global.SoongConfig.Profman).
Tool(globalSoong.Profman).
FlagWithInput("--create-profile-from=", bootImageProfile).
FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
FlagForEachArg("--dex-location=", image.dexLocationsDeps).
@@ -487,7 +493,8 @@ func bootImageProfileRule(ctx android.SingletonContext, image *bootImage, missin
var bootImageProfileRuleKey = android.NewOnceKey("bootImageProfileRule")
func bootFrameworkProfileRule(ctx android.SingletonContext, image *bootImage, missingDeps []string) android.WritablePath {
global := dexpreoptGlobalConfig(ctx)
globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
global := dexpreopt.GetGlobalConfig(ctx)
if global.DisableGenerateProfile || ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() {
return nil
@@ -513,7 +520,7 @@ func bootFrameworkProfileRule(ctx android.SingletonContext, image *bootImage, mi
rule.Command().
Text(`ANDROID_LOG_TAGS="*:e"`).
Tool(global.SoongConfig.Profman).
Tool(globalSoong.Profman).
Flag("--generate-boot-profile").
FlagWithInput("--create-profile-from=", bootFrameworkProfile).
FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
@@ -575,7 +582,7 @@ func dumpOatRules(ctx android.SingletonContext, image *bootImage) {
}
func writeGlobalConfigForMake(ctx android.SingletonContext, path android.WritablePath) {
data := dexpreoptGlobalConfigRaw(ctx).data
data := dexpreopt.GetGlobalConfigRawData(ctx)
ctx.Build(pctx, android.BuildParams{
Rule: android.WriteFile,

View File

@@ -49,7 +49,7 @@ func TestDexpreoptBootJars(t *testing.T) {
pathCtx := android.PathContextForTesting(config)
dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
dexpreoptConfig.BootJars = []string{"foo", "bar", "baz"}
setDexpreoptTestGlobalConfig(config, dexpreoptConfig)
dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
ctx := testContext()

View File

@@ -22,57 +22,12 @@ import (
"android/soong/dexpreopt"
)
// dexpreoptGlobalConfig returns the global dexpreopt.config. It is loaded once the first time it is called for any
// ctx.Config(), and returns the same data for all future calls with the same ctx.Config(). A value can be inserted
// for tests using setDexpreoptTestGlobalConfig.
func dexpreoptGlobalConfig(ctx android.PathContext) dexpreopt.GlobalConfig {
return dexpreoptGlobalConfigRaw(ctx).global
}
type globalConfigAndRaw struct {
global dexpreopt.GlobalConfig
data []byte
}
func dexpreoptGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw {
return ctx.Config().Once(dexpreoptGlobalConfigKey, func() interface{} {
if data, err := ctx.Config().DexpreoptGlobalConfig(ctx); err != nil {
panic(err)
} else if data != nil {
soongConfig := dexpreopt.CreateGlobalSoongConfig(ctx)
globalConfig, err := dexpreopt.LoadGlobalConfig(ctx, data, soongConfig)
if err != nil {
panic(err)
}
return globalConfigAndRaw{globalConfig, data}
}
// No global config filename set, see if there is a test config set
return ctx.Config().Once(dexpreoptTestGlobalConfigKey, func() interface{} {
// Nope, return a config with preopting disabled
return globalConfigAndRaw{dexpreopt.GlobalConfig{
DisablePreopt: true,
DisableGenerateProfile: true,
}, nil}
})
}).(globalConfigAndRaw)
}
// setDexpreoptTestGlobalConfig sets a GlobalConfig that future calls to dexpreoptGlobalConfig will return. It must
// be called before the first call to dexpreoptGlobalConfig for the config.
func setDexpreoptTestGlobalConfig(config android.Config, globalConfig dexpreopt.GlobalConfig) {
config.Once(dexpreoptTestGlobalConfigKey, func() interface{} { return globalConfigAndRaw{globalConfig, nil} })
}
var dexpreoptGlobalConfigKey = android.NewOnceKey("DexpreoptGlobalConfig")
var dexpreoptTestGlobalConfigKey = android.NewOnceKey("TestDexpreoptGlobalConfig")
// systemServerClasspath returns the on-device locations of the modules in the system server classpath. It is computed
// once the first time it is called for any ctx.Config(), and returns the same slice for all future calls with the same
// ctx.Config().
func systemServerClasspath(ctx android.MakeVarsContext) []string {
return ctx.Config().OnceStringSlice(systemServerClasspathKey, func() []string {
global := dexpreoptGlobalConfig(ctx)
global := dexpreopt.GetGlobalConfig(ctx)
var systemServerClasspathLocations []string
for _, m := range *DexpreoptedSystemServerJars(ctx.Config()) {
systemServerClasspathLocations = append(systemServerClasspathLocations,
@@ -121,7 +76,7 @@ var (
func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig {
return ctx.Config().Once(bootImageConfigKey, func() interface{} {
global := dexpreoptGlobalConfig(ctx)
global := dexpreopt.GetGlobalConfig(ctx)
targets := dexpreoptTargets(ctx)
deviceDir := android.PathForOutput(ctx, ctx.Config().DeviceName())
@@ -227,7 +182,7 @@ func defaultBootImageConfig(ctx android.PathContext) bootImageConfig {
func defaultBootclasspath(ctx android.PathContext) []string {
return ctx.Config().OnceStringSlice(defaultBootclasspathKey, func() []string {
global := dexpreoptGlobalConfig(ctx)
global := dexpreopt.GetGlobalConfig(ctx)
image := defaultBootImageConfig(ctx)
updatableBootclasspath := make([]string, len(global.UpdatableBootJars))

View File

@@ -76,6 +76,10 @@ func RegisterJavaBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("java_host_for_device", HostForDeviceFactory)
ctx.RegisterModuleType("dex_import", DexImportFactory)
ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator).Parallel()
})
ctx.RegisterSingletonType("logtags", LogtagsSingleton)
ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
}
@@ -105,7 +109,7 @@ func DexpreoptedSystemServerJars(config android.Config) *[]string {
// order (which is partial and non-deterministic). This pass adds additional dependencies between
// jars, making the order total and deterministic. It also constructs a global ordered list.
func systemServerJarsDepsMutator(ctx android.BottomUpMutatorContext) {
jars := dexpreopt.NonUpdatableSystemServerJars(ctx, dexpreoptGlobalConfig(ctx))
jars := dexpreopt.NonUpdatableSystemServerJars(ctx, dexpreopt.GetGlobalConfig(ctx))
name := ctx.ModuleName()
if android.InList(name, jars) {
dexpreoptedSystemServerJarsLock.Lock()
@@ -1781,6 +1785,10 @@ func (j *Module) JacocoReportClassesFile() android.Path {
return j.jacocoReportClassesFile
}
func (j *Module) IsInstallable() bool {
return Bool(j.properties.Installable)
}
//
// Java libraries (.jar file)
//
@@ -1818,7 +1826,6 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.checkSdkVersion(ctx)
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
j.dexpreopter.isInstallable = Bool(j.properties.Installable)
j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex
j.compile(ctx, nil)
@@ -2575,13 +2582,16 @@ func (j *DexImport) Stem() string {
return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
}
func (j *DexImport) IsInstallable() bool {
return true
}
func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if len(j.properties.Jars) != 1 {
ctx.PropertyErrorf("jars", "exactly one jar must be provided")
}
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
j.dexpreopter.isInstallable = true
j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars")

View File

@@ -57,7 +57,15 @@ func TestMain(m *testing.M) {
}
func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
return TestConfig(buildDir, env, bp, fs)
bp += dexpreopt.BpToolModulesForTest()
config := TestConfig(buildDir, env, bp, fs)
// Set up the global Once cache used for dexpreopt.GlobalSoongConfig, so that
// it doesn't create a real one, which would fail.
_ = dexpreopt.GlobalSoongConfigForTests(config)
return config
}
func testContext() *android.TestContext {
@@ -86,6 +94,8 @@ func testContext() *android.TestContext {
cc.RegisterRequiredBuildComponentsForTest(ctx)
ctx.RegisterModuleType("ndk_prebuilt_shared_stl", cc.NdkPrebuiltSharedStlFactory)
dexpreopt.RegisterToolModulesForTest(ctx)
return ctx
}
@@ -93,7 +103,7 @@ func run(t *testing.T, ctx *android.TestContext, config android.Config) {
t.Helper()
pathCtx := android.PathContextForTesting(config)
setDexpreoptTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx))
dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx))
ctx.Register(config)
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
@@ -112,7 +122,7 @@ func testJavaErrorWithConfig(t *testing.T, pattern string, config android.Config
ctx := testContext()
pathCtx := android.PathContextForTesting(config)
setDexpreoptTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx))
dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx))
ctx.Register(config)
_, errs := ctx.ParseBlueprintsFiles("Android.bp")