Merge "Add filename property to android_app_import"

This commit is contained in:
Jaewoong Jung
2019-08-15 17:29:55 +00:00
committed by Gerrit Code Review
3 changed files with 69 additions and 21 deletions

View File

@@ -609,28 +609,23 @@ func (dstubs *Droidstubs) AndroidMk() android.AndroidMkData {
} }
} }
func (app *AndroidAppImport) AndroidMk() android.AndroidMkData { func (a *AndroidAppImport) AndroidMkEntries() android.AndroidMkEntries {
return android.AndroidMkData{ return android.AndroidMkEntries{
Class: "APPS", Class: "APPS",
OutputFile: android.OptionalPathForPath(app.outputFile), OutputFile: android.OptionalPathForPath(a.outputFile),
Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk", Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
Extra: []android.AndroidMkExtraFunc{ AddCustomEntries: func(name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
func(w io.Writer, outputFile android.Path) { entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", Bool(a.properties.Privileged))
if Bool(app.properties.Privileged) { if a.certificate != nil {
fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true") entries.SetString("LOCAL_CERTIFICATE", a.certificate.Pem.String())
}
if app.certificate != nil {
fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.Pem.String())
} else { } else {
fmt.Fprintln(w, "LOCAL_CERTIFICATE := PRESIGNED") entries.SetString("LOCAL_CERTIFICATE", "PRESIGNED")
} }
if len(app.properties.Overrides) > 0 { entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", a.properties.Overrides...)
fmt.Fprintln(w, "LOCAL_OVERRIDES_PACKAGES :=", strings.Join(app.properties.Overrides, " ")) if len(a.dexpreopter.builtInstalled) > 0 {
entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", a.dexpreopter.builtInstalled)
} }
if len(app.dexpreopter.builtInstalled) > 0 { entries.AddStrings("LOCAL_INSTALLED_MODULE_STEM", a.installPath.Rel())
fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", app.dexpreopter.builtInstalled)
}
},
}, },
} }
} }

View File

@@ -740,6 +740,8 @@ type AndroidAppImport struct {
dexpreopter dexpreopter
usesLibrary usesLibrary usesLibrary usesLibrary
installPath android.OutputPath
} }
type AndroidAppImportProperties struct { type AndroidAppImportProperties struct {
@@ -765,6 +767,9 @@ type AndroidAppImportProperties struct {
// binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
// from PRODUCT_PACKAGES. // from PRODUCT_PACKAGES.
Overrides []string Overrides []string
// Optional name for the installed app. If unspecified, it is derived from the module name.
Filename *string
} }
// Chooses a source APK path to use based on the module and product specs. // Chooses a source APK path to use based on the module and product specs.
@@ -917,7 +922,8 @@ func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext
// TODO: Optionally compress the output apk. // TODO: Optionally compress the output apk.
ctx.InstallFile(installDir, a.BaseModuleName()+".apk", a.outputFile) a.installPath = ctx.InstallFile(installDir,
proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+".apk"), a.outputFile)
// TODO: androidmk converter jni libs // TODO: androidmk converter jni libs
} }

View File

@@ -1242,6 +1242,53 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) {
} }
} }
func TestAndroidAppImport_Filename(t *testing.T) {
ctx, config := testJava(t, `
android_app_import {
name: "foo",
apk: "prebuilts/apk/app.apk",
presigned: true,
}
android_app_import {
name: "bar",
apk: "prebuilts/apk/app.apk",
presigned: true,
filename: "bar_sample.apk"
}
`)
testCases := []struct {
name string
expected string
}{
{
name: "foo",
expected: "foo.apk",
},
{
name: "bar",
expected: "bar_sample.apk",
},
}
for _, test := range testCases {
variant := ctx.ModuleForTests(test.name, "android_common")
if variant.MaybeOutput(test.expected).Rule == nil {
t.Errorf("can't find output named %q - all outputs: %v", test.expected, variant.AllOutputs())
}
a := variant.Module().(*AndroidAppImport)
expectedValues := []string{test.expected}
actualValues := android.AndroidMkEntriesForTest(
t, config, "", a).EntryMap["LOCAL_INSTALLED_MODULE_STEM"]
if !reflect.DeepEqual(actualValues, expectedValues) {
t.Errorf("Incorrect LOCAL_INSTALLED_MODULE_STEM value '%s', expected '%s'",
actualValues, expectedValues)
}
}
}
func TestStl(t *testing.T) { func TestStl(t *testing.T) {
ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
cc_library { cc_library {