Add skip-sdk-check to extract_apks

Add skip-sdk-check to skip checking the SDK version when extracting an
APK/APEX from an App Set Bundle. This can be used when the platform SDK
version is not defined and the APEXs/APKs use SHA based SDK versions.
This check should not be set to true for non Beta dessert releases

Bug: 274518686
Test: # Add SHA targeting modules to platform
m SOONG_SKIP_APPSET_SDK_CHECK=true  #Build Passes
m SOONG_SKIP_APPSET_SDK_CHECK=false #Build Fails
m #No config supplied, build fails

Change-Id: I1919437d3410f09c991e1de39031bd88e1f8246a
This commit is contained in:
Pranav Gupta 2023-03-20 16:19:53 -07:00
parent 94d107020a
commit 51645ff23e
5 changed files with 18 additions and 5 deletions

View file

@ -35,11 +35,12 @@ var (
blueprint.RuleParams{
Command: `rm -rf "$out" && ` +
`${extract_apks} -o "${out}" -allow-prereleased=${allow-prereleased} ` +
`-sdk-version=${sdk-version} -abis=${abis} -screen-densities=all -extract-single ` +
`-sdk-version=${sdk-version} -skip-sdk-check=${skip-sdk-check} -abis=${abis} ` +
`-screen-densities=all -extract-single ` +
`${in}`,
CommandDeps: []string{"${extract_apks}"},
},
"abis", "allow-prereleased", "sdk-version")
"abis", "allow-prereleased", "sdk-version", "skip-sdk-check")
)
type prebuilt interface {
@ -845,6 +846,7 @@ func (p *prebuiltApexExtractorModule) GenerateAndroidBuildActions(ctx android.Mo
"abis": strings.Join(abis, ","),
"allow-prereleased": strconv.FormatBool(proptools.BoolDefault(p.properties.Prerelease, defaultAllowPrerelease)),
"sdk-version": ctx.Config().PlatformSdkVersion().String(),
"skip-sdk-check": strconv.FormatBool(ctx.Config().IsEnvTrue("SOONG_SKIP_APPSET_SDK_CHECK")),
},
})
}

View file

@ -41,6 +41,7 @@ type TargetConfig struct {
abis map[android_bundle_proto.Abi_AbiAlias]int
allowPrereleased bool
stem string
skipSdkCheck bool
}
// An APK set is a zip archive. An entry 'toc.pb' describes its contents.
@ -322,6 +323,12 @@ type sdkVersionTargetingMatcher struct {
func (m sdkVersionTargetingMatcher) matches(config TargetConfig) bool {
const preReleaseVersion = 10000
// TODO (b274518686) This check should only be used while SHA based targeting is active
// Once we have switched to an SDK version, this can be changed to throw an error if
// it was accidentally set
if config.skipSdkCheck == true {
return true
}
if m.SdkVersionTargeting == nil {
return true
}
@ -572,7 +579,7 @@ func (s screenDensityFlagValue) Set(densityList string) error {
func processArgs() {
flag.Usage = func() {
fmt.Fprintln(os.Stderr, `usage: extract_apks -o <output-file> [-zip <output-zip-file>] `+
`-sdk-version value -abis value `+
`-sdk-version value -abis value [-skip-sdk-check]`+
`-screen-densities value {-stem value | -extract-single} [-allow-prereleased] `+
`[-apkcerts <apkcerts output file> -partition <partition>] <APK set>`)
flag.PrintDefaults()
@ -585,6 +592,7 @@ func processArgs() {
"'all' or comma-separated list of screen density names (NODPI LDPI MDPI TVDPI HDPI XHDPI XXHDPI XXXHDPI)")
flag.BoolVar(&targetConfig.allowPrereleased, "allow-prereleased", false,
"allow prereleased")
flag.BoolVar(&targetConfig.skipSdkCheck, "skip-sdk-check", false, "Skip the SDK version check")
flag.StringVar(&targetConfig.stem, "stem", "", "output entries base name in the output zip file")
flag.Parse()
if (*outputFile == "") || len(flag.Args()) != 1 || *version == 0 ||

View file

@ -142,6 +142,7 @@ func (as *AndroidAppSet) GenerateAndroidBuildActions(ctx android.ModuleContext)
"allow-prereleased": strconv.FormatBool(proptools.Bool(as.properties.Prerelease)),
"screen-densities": screenDensities,
"sdk-version": ctx.Config().PlatformSdkVersion().String(),
"skip-sdk-check": strconv.FormatBool(ctx.Config().IsEnvTrue("SOONG_SKIP_APPSET_SDK_CHECK")),
"stem": as.BaseModuleName(),
"apkcerts": as.apkcertsFile.String(),
"partition": as.PartitionTag(ctx.DeviceConfig()),

View file

@ -89,6 +89,7 @@ func TestAndroidAppSet_Variants(t *testing.T) {
"allow-prereleased": "false",
"screen-densities": "LDPI,XXHDPI",
"sdk-version": "29",
"skip-sdk-check": "false",
"stem": "foo",
},
},
@ -105,6 +106,7 @@ func TestAndroidAppSet_Variants(t *testing.T) {
"allow-prereleased": "false",
"screen-densities": "all",
"sdk-version": "30",
"skip-sdk-check": "false",
"stem": "foo",
},
},

View file

@ -131,13 +131,13 @@ var (
blueprint.RuleParams{
Command: `rm -rf "$out" && ` +
`${config.ExtractApksCmd} -o "${out}" -zip "${zip}" -allow-prereleased=${allow-prereleased} ` +
`-sdk-version=${sdk-version} -abis=${abis} ` +
`-sdk-version=${sdk-version} -skip-sdk-check=${skip-sdk-check} -abis=${abis} ` +
`--screen-densities=${screen-densities} --stem=${stem} ` +
`-apkcerts=${apkcerts} -partition=${partition} ` +
`${in}`,
CommandDeps: []string{"${config.ExtractApksCmd}"},
},
"abis", "allow-prereleased", "screen-densities", "sdk-version", "stem", "apkcerts", "partition", "zip")
"abis", "allow-prereleased", "screen-densities", "sdk-version", "skip-sdk-check", "stem", "apkcerts", "partition", "zip")
turbine, turbineRE = pctx.RemoteStaticRules("turbine",
blueprint.RuleParams{