Merge "Allow the user to explicitly set the java Uncompress_dex property."
This commit is contained in:
@@ -55,6 +55,7 @@ func init() {
|
|||||||
AddNeverAllowRules(createMediaRules()...)
|
AddNeverAllowRules(createMediaRules()...)
|
||||||
AddNeverAllowRules(createJavaDeviceForHostRules()...)
|
AddNeverAllowRules(createJavaDeviceForHostRules()...)
|
||||||
AddNeverAllowRules(createCcSdkVariantRules()...)
|
AddNeverAllowRules(createCcSdkVariantRules()...)
|
||||||
|
AddNeverAllowRules(createUncompressDexRules()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a NeverAllow rule to the set of rules to apply.
|
// Add a NeverAllow rule to the set of rules to apply.
|
||||||
@@ -210,6 +211,15 @@ func createCcSdkVariantRules() []Rule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createUncompressDexRules() []Rule {
|
||||||
|
return []Rule{
|
||||||
|
NeverAllow().
|
||||||
|
NotIn("art").
|
||||||
|
WithMatcher("uncompress_dex", isSetMatcherInstance).
|
||||||
|
Because("uncompress_dex is only allowed for certain jars for test in art."),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func neverallowMutator(ctx BottomUpMutatorContext) {
|
func neverallowMutator(ctx BottomUpMutatorContext) {
|
||||||
m, ok := ctx.Module().(Module)
|
m, ok := ctx.Module().(Module)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@@ -303,6 +303,29 @@ var neverallowTests = []struct {
|
|||||||
`module "outside_whitelist": violates neverallow`,
|
`module "outside_whitelist": violates neverallow`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "uncompress_dex inside art",
|
||||||
|
fs: map[string][]byte{
|
||||||
|
"art/Android.bp": []byte(`
|
||||||
|
java_library {
|
||||||
|
name: "inside_art_libraries",
|
||||||
|
uncompress_dex: true,
|
||||||
|
}`),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "uncompress_dex outside art",
|
||||||
|
fs: map[string][]byte{
|
||||||
|
"other/Android.bp": []byte(`
|
||||||
|
java_library {
|
||||||
|
name: "outside_art_libraries",
|
||||||
|
uncompress_dex: true,
|
||||||
|
}`),
|
||||||
|
},
|
||||||
|
expectedErrors: []string{
|
||||||
|
"module \"outside_art_libraries\": violates neverallow",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNeverallow(t *testing.T) {
|
func TestNeverallow(t *testing.T) {
|
||||||
@@ -396,8 +419,9 @@ func (p *mockCcLibraryModule) GenerateAndroidBuildActions(ModuleContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type mockJavaLibraryProperties struct {
|
type mockJavaLibraryProperties struct {
|
||||||
Libs []string
|
Libs []string
|
||||||
Sdk_version *string
|
Sdk_version *string
|
||||||
|
Uncompress_dex *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockJavaLibraryModule struct {
|
type mockJavaLibraryModule struct {
|
||||||
|
@@ -568,16 +568,17 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path {
|
|||||||
installDir = filepath.Join("app", a.installApkName)
|
installDir = filepath.Join("app", a.installApkName)
|
||||||
}
|
}
|
||||||
a.dexpreopter.installPath = android.PathForModuleInstall(ctx, installDir, a.installApkName+".apk")
|
a.dexpreopter.installPath = android.PathForModuleInstall(ctx, installDir, a.installApkName+".apk")
|
||||||
a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx)
|
if a.deviceProperties.Uncompress_dex == nil {
|
||||||
|
// If the value was not force-set by the user, use reasonable default based on the module.
|
||||||
|
a.deviceProperties.Uncompress_dex = proptools.BoolPtr(a.shouldUncompressDex(ctx))
|
||||||
|
}
|
||||||
|
a.dexpreopter.uncompressedDex = *a.deviceProperties.Uncompress_dex
|
||||||
a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries()
|
a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries()
|
||||||
a.dexpreopter.usesLibs = a.usesLibrary.usesLibraryProperties.Uses_libs
|
a.dexpreopter.usesLibs = a.usesLibrary.usesLibraryProperties.Uses_libs
|
||||||
a.dexpreopter.optionalUsesLibs = a.usesLibrary.presentOptionalUsesLibs(ctx)
|
a.dexpreopter.optionalUsesLibs = a.usesLibrary.presentOptionalUsesLibs(ctx)
|
||||||
a.dexpreopter.libraryPaths = a.usesLibrary.usesLibraryPaths(ctx)
|
a.dexpreopter.libraryPaths = a.usesLibrary.usesLibraryPaths(ctx)
|
||||||
a.dexpreopter.manifestFile = a.mergedManifestFile
|
a.dexpreopter.manifestFile = a.mergedManifestFile
|
||||||
|
|
||||||
a.deviceProperties.UncompressDex = a.dexpreopter.uncompressedDex
|
|
||||||
|
|
||||||
if ctx.ModuleName() != "framework-res" {
|
if ctx.ModuleName() != "framework-res" {
|
||||||
a.Module.compile(ctx, a.aaptSrcJar)
|
a.Module.compile(ctx, a.aaptSrcJar)
|
||||||
}
|
}
|
||||||
|
@@ -2806,6 +2806,32 @@ func TestUncompressDex(t *testing.T) {
|
|||||||
uncompressedPlatform: true,
|
uncompressedPlatform: true,
|
||||||
uncompressedUnbundled: true,
|
uncompressedUnbundled: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "normal_uncompress_dex_true",
|
||||||
|
bp: `
|
||||||
|
android_app {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
sdk_version: "current",
|
||||||
|
uncompress_dex: true,
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
uncompressedPlatform: true,
|
||||||
|
uncompressedUnbundled: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "normal_uncompress_dex_false",
|
||||||
|
bp: `
|
||||||
|
android_app {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
sdk_version: "current",
|
||||||
|
uncompress_dex: false,
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
uncompressedPlatform: false,
|
||||||
|
uncompressedUnbundled: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
test := func(t *testing.T, bp string, want bool, unbundled bool) {
|
test := func(t *testing.T, bp string, want bool, unbundled bool) {
|
||||||
|
@@ -18,6 +18,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
|
"github.com/google/blueprint/proptools"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
"android/soong/remoteexec"
|
"android/soong/remoteexec"
|
||||||
@@ -188,7 +189,7 @@ func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags,
|
|||||||
outDir := android.PathForModuleOut(ctx, "dex")
|
outDir := android.PathForModuleOut(ctx, "dex")
|
||||||
|
|
||||||
zipFlags := "--ignore_missing_files"
|
zipFlags := "--ignore_missing_files"
|
||||||
if j.deviceProperties.UncompressDex {
|
if proptools.Bool(j.deviceProperties.Uncompress_dex) {
|
||||||
zipFlags += " -L 0"
|
zipFlags += " -L 0"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +236,7 @@ func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags,
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if j.deviceProperties.UncompressDex {
|
if proptools.Bool(j.deviceProperties.Uncompress_dex) {
|
||||||
alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", jarName)
|
alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", jarName)
|
||||||
TransformZipAlign(ctx, alignedJavalibJar, javalibJar)
|
TransformZipAlign(ctx, alignedJavalibJar, javalibJar)
|
||||||
javalibJar = alignedJavalibJar
|
javalibJar = alignedJavalibJar
|
||||||
|
20
java/java.go
20
java/java.go
@@ -342,8 +342,13 @@ type CompilerDeviceProperties struct {
|
|||||||
// set the name of the output
|
// set the name of the output
|
||||||
Stem *string
|
Stem *string
|
||||||
|
|
||||||
UncompressDex bool `blueprint:"mutated"`
|
// Keep the data uncompressed. We always need uncompressed dex for execution,
|
||||||
IsSDKLibrary bool `blueprint:"mutated"`
|
// so this might actually save space by avoiding storing the same data twice.
|
||||||
|
// This defaults to reasonable value based on module and should not be set.
|
||||||
|
// It exists only to support ART tests.
|
||||||
|
Uncompress_dex *bool
|
||||||
|
|
||||||
|
IsSDKLibrary bool `blueprint:"mutated"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool {
|
func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool {
|
||||||
@@ -1570,7 +1575,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
|||||||
|
|
||||||
// Hidden API CSV generation and dex encoding
|
// Hidden API CSV generation and dex encoding
|
||||||
dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
|
dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
|
||||||
j.deviceProperties.UncompressDex)
|
proptools.Bool(j.deviceProperties.Uncompress_dex))
|
||||||
|
|
||||||
// merge dex jar with resources if necessary
|
// merge dex jar with resources if necessary
|
||||||
if j.resourceJar != nil {
|
if j.resourceJar != nil {
|
||||||
@@ -1578,7 +1583,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
|||||||
combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
|
combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
|
||||||
TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
|
TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
|
||||||
false, nil, nil)
|
false, nil, nil)
|
||||||
if j.deviceProperties.UncompressDex {
|
if *j.deviceProperties.Uncompress_dex {
|
||||||
combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
|
combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
|
||||||
TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
|
TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
|
||||||
dexOutputFile = combinedAlignedJar
|
dexOutputFile = combinedAlignedJar
|
||||||
@@ -1856,8 +1861,11 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
j.checkSdkVersions(ctx)
|
j.checkSdkVersions(ctx)
|
||||||
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
|
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
|
||||||
j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
|
j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
|
||||||
j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
|
if j.deviceProperties.Uncompress_dex == nil {
|
||||||
j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex
|
// If the value was not force-set by the user, use reasonable default based on the module.
|
||||||
|
j.deviceProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter))
|
||||||
|
}
|
||||||
|
j.dexpreopter.uncompressedDex = *j.deviceProperties.Uncompress_dex
|
||||||
j.compile(ctx, nil)
|
j.compile(ctx, nil)
|
||||||
|
|
||||||
// Collect the module directory for IDE info in java/jdeps.go.
|
// Collect the module directory for IDE info in java/jdeps.go.
|
||||||
|
Reference in New Issue
Block a user