Allow codename.fingerprint format for targetSdkVersion

Use codename.fingerprint format for targetSdkVersion if it is unset
in the manifest and UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT=true.

Test: manual
Bug: 130541924
Change-Id: I4e3b1274cc32038b00b292dc6d67559eb320e9e4
This commit is contained in:
Colin Cross 2019-04-18 14:27:12 -07:00
parent 3047fa23da
commit 109328714f
5 changed files with 85 additions and 15 deletions

View File

@ -622,7 +622,7 @@ func (c *config) UnbundledBuild() bool {
return Bool(c.productVariables.Unbundled_build)
}
func (c *config) UnbundledBuildPrebuiltSdks() bool {
func (c *config) UnbundledBuildUsePrebuiltSdks() bool {
return Bool(c.productVariables.Unbundled_build) && !Bool(c.productVariables.Unbundled_build_sdks_from_source)
}

View File

@ -511,7 +511,7 @@ func (a *AARImport) Name() string {
}
func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) {
if !ctx.Config().UnbundledBuildPrebuiltSdks() {
if !ctx.Config().UnbundledBuildUsePrebuiltSdks() {
sdkDep := decodeSdkDep(ctx, sdkContext(a))
if sdkDep.useModule && sdkDep.frameworkResModule != "" {
ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule)

View File

@ -68,15 +68,27 @@ func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext
args = append(args, "--use-embedded-dex=true")
}
var deps android.Paths
targetSdkVersion := sdkVersionOrDefault(ctx, sdkContext.targetSdkVersion())
if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&
ctx.Config().UnbundledBuild() &&
!ctx.Config().UnbundledBuildUsePrebuiltSdks() &&
ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") {
apiFingerprint := apiFingerprintPath(ctx)
targetSdkVersion += fmt.Sprintf(".$$(cat %s)", apiFingerprint.String())
deps = append(deps, apiFingerprint)
}
// Inject minSdkVersion into the manifest
fixedManifest := android.PathForModuleOut(ctx, "manifest_fixer", "AndroidManifest.xml")
ctx.Build(pctx, android.BuildParams{
Rule: manifestFixerRule,
Input: manifest,
Output: fixedManifest,
Rule: manifestFixerRule,
Input: manifest,
Implicits: deps,
Output: fixedManifest,
Args: map[string]string{
"minSdkVersion": sdkVersionOrDefault(ctx, sdkContext.minSdkVersion()),
"targetSdkVersion": sdkVersionOrDefault(ctx, sdkContext.targetSdkVersion()),
"targetSdkVersion": targetSdkVersion,
"args": strings.Join(args, " "),
},
})

View File

@ -19,6 +19,7 @@ import (
"android/soong/java/config"
"fmt"
"path/filepath"
"runtime"
"sort"
"strconv"
"strings"
@ -29,11 +30,12 @@ import (
func init() {
android.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory)
android.RegisterSingletonType("sdk", sdkSingletonFactory)
android.RegisterMakeVarsProvider(pctx, sdkFrameworkAidlMakeVars)
android.RegisterMakeVarsProvider(pctx, sdkMakeVars)
}
var sdkVersionsKey = android.NewOnceKey("sdkVersionsKey")
var sdkFrameworkAidlPathKey = android.NewOnceKey("sdkFrameworkAidlPathKey")
var apiFingerprintPathKey = android.NewOnceKey("apiFingerprintPathKey")
type sdkContext interface {
// sdkVersion eturns the sdk_version property of the current module, or an empty string if it is not set.
@ -171,7 +173,7 @@ func decodeSdkDep(ctx android.BaseContext, sdkContext sdkContext) sdkDep {
}
}
if ctx.Config().UnbundledBuildPrebuiltSdks() && v != "" {
if ctx.Config().UnbundledBuildUsePrebuiltSdks() && v != "" {
return toPrebuilt(v)
}
@ -230,12 +232,16 @@ func sdkSingletonFactory() android.Singleton {
type sdkSingleton struct{}
func (sdkSingleton) GenerateBuildActions(ctx android.SingletonContext) {
if ctx.Config().UnbundledBuildPrebuiltSdks() || ctx.Config().IsPdkBuild() {
if ctx.Config().UnbundledBuildUsePrebuiltSdks() || ctx.Config().IsPdkBuild() {
return
}
// Create framework.aidl by extracting anything that implements android.os.Parcelable from the SDK stubs modules.
createSdkFrameworkAidl(ctx)
createAPIFingerprint(ctx)
}
// Create framework.aidl by extracting anything that implements android.os.Parcelable from the SDK stubs modules.
func createSdkFrameworkAidl(ctx android.SingletonContext) {
stubsModules := []string{
"android_stubs_current",
"android_test_stubs_current",
@ -308,10 +314,62 @@ func sdkFrameworkAidlPath(ctx android.PathContext) android.OutputPath {
}).(android.OutputPath)
}
func sdkFrameworkAidlMakeVars(ctx android.MakeVarsContext) {
if ctx.Config().UnbundledBuildPrebuiltSdks() || ctx.Config().IsPdkBuild() {
// Create api_fingerprint.txt
func createAPIFingerprint(ctx android.SingletonContext) {
out := apiFingerprintPath(ctx)
rule := android.NewRuleBuilder()
rule.Command().
Text("rm -f").Output(out)
cmd := rule.Command()
if ctx.Config().PlatformSdkCodename() == "REL" {
cmd.Text("echo REL >").Output(out)
} else if ctx.Config().IsPdkBuild() {
// TODO: get this from the PDK artifacts?
cmd.Text("echo PDK >").Output(out)
} else if !ctx.Config().UnbundledBuildUsePrebuiltSdks() {
in, err := ctx.GlobWithDeps("frameworks/base/api/*current.txt", nil)
if err != nil {
ctx.Errorf("error globbing API files: %s", err)
}
cmd.Text("cat").
Inputs(android.PathsForSource(ctx, in)).
Text("|")
if runtime.GOOS == "darwin" {
cmd.Text("md5")
} else {
cmd.Text("md5sum")
}
cmd.Text("| cut -d' ' -f1 >").
Output(out)
} else {
// Unbundled build
// TODO: use a prebuilt api_fingerprint.txt from prebuilts/sdk/current.txt once we have one
cmd.Text("echo").
Flag(ctx.Config().PlatformPreviewSdkVersion()).
Text(">").
Output(out)
}
rule.Build(pctx, ctx, "api_fingerprint", "generate api_fingerprint.txt")
}
func apiFingerprintPath(ctx android.PathContext) android.OutputPath {
return ctx.Config().Once(apiFingerprintPathKey, func() interface{} {
return android.PathForOutput(ctx, "api_fingerprint.txt")
}).(android.OutputPath)
}
func sdkMakeVars(ctx android.MakeVarsContext) {
if ctx.Config().UnbundledBuildUsePrebuiltSdks() || ctx.Config().IsPdkBuild() {
return
}
ctx.Strict("FRAMEWORK_AIDL", sdkFrameworkAidlPath(ctx).String())
ctx.Strict("API_FINGERPRINT", apiFingerprintPath(ctx).String())
}

View File

@ -402,7 +402,7 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiSc
props.Sdk_version = proptools.StringPtr(module.sdkVersion(apiScope))
props.Libs = module.sdkLibraryProperties.Stub_only_libs
// Unbundled apps will use the prebult one from /prebuilts/sdk
if mctx.Config().UnbundledBuildPrebuiltSdks() {
if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
}
props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
@ -612,7 +612,7 @@ func (module *SdkLibrary) PrebuiltJars(ctx android.BaseContext, sdkVersion strin
// to satisfy SdkLibraryDependency interface
func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseContext, sdkVersion string) android.Paths {
// This module is just a wrapper for the stubs.
if ctx.Config().UnbundledBuildPrebuiltSdks() {
if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
return module.PrebuiltJars(ctx, sdkVersion)
} else {
if strings.HasPrefix(sdkVersion, "system_") {
@ -628,7 +628,7 @@ func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseContext, sdkVersion stri
// to satisfy SdkLibraryDependency interface
func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseContext, sdkVersion string) android.Paths {
// This module is just a wrapper for the stubs.
if ctx.Config().UnbundledBuildPrebuiltSdks() {
if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
return module.PrebuiltJars(ctx, sdkVersion)
} else {
if strings.HasPrefix(sdkVersion, "system_") {