Merge "Add runtime_resource_overlay." am: 84f71af41c am: 51e926c45d

Change-Id: I628c969aeed58f65aacdc16521a35c8a2831ff93
This commit is contained in:
Automerger Merge Worker 2020-01-24 00:44:02 +00:00
commit 8f84cbc441
5 changed files with 150 additions and 3 deletions

View file

@ -15,11 +15,12 @@
package java
import (
"android/soong/android"
"fmt"
"path/filepath"
"strings"
"android/soong/android"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)

View file

@ -695,3 +695,16 @@ func androidMkWriteTestData(data android.Paths, entries *android.AndroidMkEntrie
}
entries.AddStrings("LOCAL_COMPATIBILITY_SUPPORT_FILES", testFiles...)
}
func (r *RuntimeResourceOverlay) AndroidMkEntries() []android.AndroidMkEntries {
return []android.AndroidMkEntries{android.AndroidMkEntries{
Class: "ETC",
OutputFile: android.OptionalPathForPath(r.outputFile),
Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
func(entries *android.AndroidMkEntries) {
entries.SetPath("LOCAL_MODULE_PATH", r.installDir.ToMakePath())
},
},
}}
}

View file

@ -47,6 +47,7 @@ func RegisterAppBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("override_android_test", OverrideAndroidTestModuleFactory)
ctx.RegisterModuleType("android_app_import", AndroidAppImportFactory)
ctx.RegisterModuleType("android_test_import", AndroidTestImportFactory)
ctx.RegisterModuleType("runtime_resource_overlay", RuntimeResourceOverlayFactory)
}
// AndroidManifest.xml merging
@ -1212,6 +1213,95 @@ func AndroidTestImportFactory() android.Module {
return module
}
type RuntimeResourceOverlay struct {
android.ModuleBase
android.DefaultableModuleBase
aapt
properties RuntimeResourceOverlayProperties
outputFile android.Path
installDir android.InstallPath
}
type RuntimeResourceOverlayProperties struct {
// the name of a certificate in the default certificate directory or an android_app_certificate
// module name in the form ":module".
Certificate *string
// optional theme name. If specified, the overlay package will be applied
// only when the ro.boot.vendor.overlay.theme system property is set to the same value.
Theme *string
// if not blank, set to the version of the sdk to compile against.
// Defaults to compiling against the current platform.
Sdk_version *string
// if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
// Defaults to sdk_version if not set.
Min_sdk_version *string
}
func (r *RuntimeResourceOverlay) DepsMutator(ctx android.BottomUpMutatorContext) {
sdkDep := decodeSdkDep(ctx, sdkContext(r))
if sdkDep.hasFrameworkLibs() {
r.aapt.deps(ctx, sdkDep)
}
cert := android.SrcIsModule(String(r.properties.Certificate))
if cert != "" {
ctx.AddDependency(ctx.Module(), certificateTag, cert)
}
}
func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// Compile and link resources
r.aapt.hasNoCode = true
r.aapt.buildActions(ctx, r)
// Sign the built package
_, certificates := collectAppDeps(ctx, false)
certificates = processMainCert(r.ModuleBase, String(r.properties.Certificate), certificates, ctx)
signed := android.PathForModuleOut(ctx, "signed", r.Name()+".apk")
SignAppPackage(ctx, signed, r.aapt.exportPackage, certificates)
r.outputFile = signed
r.installDir = android.PathForModuleInstall(ctx, "overlay", String(r.properties.Theme))
ctx.InstallFile(r.installDir, r.outputFile.Base(), r.outputFile)
}
func (r *RuntimeResourceOverlay) sdkVersion() string {
return String(r.properties.Sdk_version)
}
func (r *RuntimeResourceOverlay) systemModules() string {
return ""
}
func (r *RuntimeResourceOverlay) minSdkVersion() string {
if r.properties.Min_sdk_version != nil {
return *r.properties.Min_sdk_version
}
return r.sdkVersion()
}
func (r *RuntimeResourceOverlay) targetSdkVersion() string {
return r.sdkVersion()
}
// runtime_resource_overlay generates a resource-only apk file that can overlay application and
// system resources at run time.
func RuntimeResourceOverlayFactory() android.Module {
module := &RuntimeResourceOverlay{}
module.AddProperties(
&module.properties,
&module.aaptProperties)
InitJavaModule(module, android.DeviceSupported)
return module
}
type UsesLibraryProperties struct {
// A list of shared library modules that will be listed in uses-library tags in the AndroidManifest.xml file.
Uses_libs []string

View file

@ -2207,3 +2207,45 @@ func checkAapt2LinkFlag(t *testing.T, aapt2Flags, flagName, expectedValue string
}
}
}
func TestRuntimeResourceOverlay(t *testing.T) {
ctx, config := testJava(t, `
runtime_resource_overlay {
name: "foo",
certificate: "platform",
product_specific: true,
}
runtime_resource_overlay {
name: "foo_themed",
certificate: "platform",
product_specific: true,
theme: "faza",
}
`)
m := ctx.ModuleForTests("foo", "android_common")
// Check cert signing flag.
signedApk := m.Output("signed/foo.apk")
signingFlag := signedApk.Args["certificates"]
expected := "build/make/target/product/security/platform.x509.pem build/make/target/product/security/platform.pk8"
if expected != signingFlag {
t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag)
}
// Check device location.
path := android.AndroidMkEntriesForTest(t, config, "", m.Module())[0].EntryMap["LOCAL_MODULE_PATH"]
expectedPath := []string{"/tmp/target/product/test_device/product/overlay"}
if !reflect.DeepEqual(path, expectedPath) {
t.Errorf("Unexpected LOCAL_MODULE_PATH value: %v, expected: %v", path, expectedPath)
}
// A themed module has a different device location
m = ctx.ModuleForTests("foo_themed", "android_common")
path = android.AndroidMkEntriesForTest(t, config, "", m.Module())[0].EntryMap["LOCAL_MODULE_PATH"]
expectedPath = []string{"/tmp/target/product/test_device/product/overlay/faza"}
if !reflect.DeepEqual(path, expectedPath) {
t.Errorf("Unexpected LOCAL_MODULE_PATH value: %v, expected: %v", path, expectedPath)
}
}

View file

@ -15,14 +15,15 @@
package java
import (
"android/soong/android"
"android/soong/java/config"
"fmt"
"path/filepath"
"sort"
"strconv"
"strings"
"android/soong/android"
"android/soong/java/config"
"github.com/google/blueprint/pathtools"
)