Merge "Pass --non-updatable-system flag to aapt2 when versionCode is unspecified" into main
This commit is contained in:
commit
0ef709565e
3 changed files with 59 additions and 4 deletions
10
java/aar.go
10
java/aar.go
|
@ -107,6 +107,10 @@ type aaptProperties struct {
|
||||||
|
|
||||||
// Names of aconfig_declarations modules that specify aconfig flags that the module depends on.
|
// Names of aconfig_declarations modules that specify aconfig flags that the module depends on.
|
||||||
Flags_packages []string
|
Flags_packages []string
|
||||||
|
|
||||||
|
// If set, `--non-updatable-system` flag is not passed to aapt2 even when
|
||||||
|
// `--version-code` is not specified in the `aaptFlags` property list or in the manifest.
|
||||||
|
DisableNonUpdatableSystem bool `blueprint:"mutated"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type aapt struct {
|
type aapt struct {
|
||||||
|
@ -308,9 +312,9 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext android.SdkConte
|
||||||
// This behavior has been copied from Make.
|
// This behavior has been copied from Make.
|
||||||
linkFlags = append(linkFlags, "--target-sdk-version "+minSdkVersion)
|
linkFlags = append(linkFlags, "--target-sdk-version "+minSdkVersion)
|
||||||
|
|
||||||
// Version code
|
// Mark non updatable when the module does not specify a version code
|
||||||
if !hasVersionCode {
|
if !a.aaptProperties.DisableNonUpdatableSystem && !hasVersionCode {
|
||||||
linkFlags = append(linkFlags, "--version-code", ctx.Config().PlatformSdkVersion().String())
|
linkFlags = append(linkFlags, "--non-updatable-system")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !hasVersionName {
|
if !hasVersionName {
|
||||||
|
|
|
@ -1452,6 +1452,7 @@ func AndroidTestFactory() android.Module {
|
||||||
module.appProperties.AlwaysPackageNativeLibs = true
|
module.appProperties.AlwaysPackageNativeLibs = true
|
||||||
module.Module.dexpreopter.isTest = true
|
module.Module.dexpreopter.isTest = true
|
||||||
module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
|
module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
|
||||||
|
module.aaptProperties.DisableNonUpdatableSystem = true
|
||||||
|
|
||||||
module.addHostAndDeviceProperties()
|
module.addHostAndDeviceProperties()
|
||||||
module.AddProperties(
|
module.AddProperties(
|
||||||
|
@ -1508,6 +1509,7 @@ func AndroidTestHelperAppFactory() android.Module {
|
||||||
module.appProperties.AlwaysPackageNativeLibs = true
|
module.appProperties.AlwaysPackageNativeLibs = true
|
||||||
module.Module.dexpreopter.isTest = true
|
module.Module.dexpreopter.isTest = true
|
||||||
module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
|
module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
|
||||||
|
module.aaptProperties.DisableNonUpdatableSystem = true
|
||||||
|
|
||||||
module.addHostAndDeviceProperties()
|
module.addHostAndDeviceProperties()
|
||||||
module.AddProperties(
|
module.AddProperties(
|
||||||
|
|
|
@ -4477,5 +4477,54 @@ func TestAppMinSdkVersionOverride(t *testing.T) {
|
||||||
fooOverride.BuildParams.Args["args"],
|
fooOverride.BuildParams.Args["args"],
|
||||||
"--minSdkVersion 33",
|
"--minSdkVersion 33",
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNonUpdatableSystem(t *testing.T) {
|
||||||
|
ctx := testApp(t, `
|
||||||
|
android_app {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
sdk_version: "current",
|
||||||
|
aaptflags: [
|
||||||
|
"--version-code 1",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
android_app {
|
||||||
|
name: "bar",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
sdk_version: "current",
|
||||||
|
}
|
||||||
|
android_test {
|
||||||
|
name: "baz",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
sdk_version: "current",
|
||||||
|
}
|
||||||
|
android_test_helper_app {
|
||||||
|
name: "baz_helper",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
sdk_version: "current",
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
hasNonUpdatableSystemFlag := func(module android.TestingModule) bool {
|
||||||
|
moduleAapt2LinkRule := module.Rule("android/soong/java.aapt2Link")
|
||||||
|
linkFlags := moduleAapt2LinkRule.Args["flags"]
|
||||||
|
return strings.Contains(linkFlags, "--non-updatable-system")
|
||||||
|
}
|
||||||
|
|
||||||
|
foo := ctx.ModuleForTests("foo", "android_common")
|
||||||
|
android.AssertBoolEquals(t, "app should not pass `--non-updatable-flags` when --version-code is specified",
|
||||||
|
false, hasNonUpdatableSystemFlag(foo))
|
||||||
|
|
||||||
|
bar := ctx.ModuleForTests("bar", "android_common")
|
||||||
|
android.AssertBoolEquals(t, "app should pass `--non-updatable-flags` when --version-code is not specified",
|
||||||
|
true, hasNonUpdatableSystemFlag(bar))
|
||||||
|
|
||||||
|
baz := ctx.ModuleForTests("baz", "android_common")
|
||||||
|
android.AssertBoolEquals(t, "test should not pass `--non-updatable-flags` even if --version-code is not specified",
|
||||||
|
false, hasNonUpdatableSystemFlag(baz))
|
||||||
|
|
||||||
|
baz_helper := ctx.ModuleForTests("baz_helper", "android_common")
|
||||||
|
android.AssertBoolEquals(t, "test should not pass `--non-updatable-flags` even if --version-code is not specified",
|
||||||
|
false, hasNonUpdatableSystemFlag(baz_helper))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue