Add overrides property to prebuilt_apex

Bug: 137218697
Test: apex_test.go
Change-Id: I55a42e1e4af60d6d7185515a380c786312b8b29b
This commit is contained in:
Jaewoong Jung 2019-07-16 18:25:41 -07:00
parent 63f4b57a7f
commit 22f7d18a5d
2 changed files with 58 additions and 31 deletions

View file

@ -1430,6 +1430,13 @@ type PrebuiltProperties struct {
// Optional name for the installed apex. If unspecified, name of the
// module is used as the file name
Filename *string
// Names of modules to be overridden. Listed modules can only be other binaries
// (in Make or Soong).
// This does not completely prevent installation of the overridden binaries, but if both
// binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
// from PRODUCT_PACKAGES.
Overrides []string
}
func (p *Prebuilt) installable() bool {
@ -1525,17 +1532,16 @@ func (p *Prebuilt) Name() string {
return p.prebuilt.Name(p.ModuleBase.Name())
}
func (p *Prebuilt) AndroidMk() android.AndroidMkData {
return android.AndroidMkData{
func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries {
return android.AndroidMkEntries{
Class: "ETC",
OutputFile: android.OptionalPathForPath(p.inputApex),
Include: "$(BUILD_PREBUILT)",
Extra: []android.AndroidMkExtraFunc{
func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString()))
fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", p.installFilename)
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !p.installable())
},
AddCustomEntries: func(name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString()))
entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
},
}
}

View file

@ -17,6 +17,7 @@ package apex
import (
"io/ioutil"
"os"
"reflect"
"strings"
"testing"
@ -45,13 +46,13 @@ func testApexError(t *testing.T, pattern, bp string) {
t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
}
func testApex(t *testing.T, bp string) *android.TestContext {
func testApex(t *testing.T, bp string) (*android.TestContext, android.Config) {
ctx, config := testApexContext(t, bp)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
android.FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
android.FailIfErrored(t, errs)
return ctx
return ctx, config
}
func testApexContext(t *testing.T, bp string) (*android.TestContext, android.Config) {
@ -264,7 +265,7 @@ func ensureListNotContains(t *testing.T, result []string, notExpected string) {
// Minimal test
func TestBasicApex(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex_defaults {
name: "myapex-defaults",
manifest: ":myapex.manifest",
@ -388,7 +389,7 @@ func TestBasicApex(t *testing.T) {
}
func TestBasicZipApex(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
@ -436,7 +437,7 @@ func TestBasicZipApex(t *testing.T) {
}
func TestApexWithStubs(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
@ -520,7 +521,7 @@ func TestApexWithStubs(t *testing.T) {
}
func TestApexWithExplicitStubsDependency(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
@ -587,7 +588,7 @@ func TestApexWithExplicitStubsDependency(t *testing.T) {
}
func TestApexWithSystemLibsStubs(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
@ -708,7 +709,7 @@ func TestApexWithSystemLibsStubs(t *testing.T) {
}
func TestFilesInSubDir(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
@ -768,7 +769,7 @@ func TestFilesInSubDir(t *testing.T) {
}
func TestUseVendor(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
@ -842,7 +843,7 @@ func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
}
func TestStaticLinking(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
@ -882,7 +883,7 @@ func TestStaticLinking(t *testing.T) {
}
func TestKeys(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex {
name: "myapex_keytest",
key: "myapex.key",
@ -936,7 +937,7 @@ func TestKeys(t *testing.T) {
}
func TestMacro(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
@ -980,7 +981,7 @@ func TestMacro(t *testing.T) {
}
func TestHeaderLibsDependency(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
@ -1028,7 +1029,7 @@ func TestHeaderLibsDependency(t *testing.T) {
}
func TestNonTestApex(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
@ -1079,7 +1080,7 @@ func TestTestApex(t *testing.T) {
if android.InAnyApex("mylib_common_test") {
t.Fatal("mylib_common_test must not be used in any other tests since this checks that global state is not updated in an illegal way!")
}
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex_test {
name: "myapex",
key: "myapex.key",
@ -1127,7 +1128,7 @@ func TestTestApex(t *testing.T) {
}
func TestApexWithTarget(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
@ -1207,7 +1208,7 @@ func TestApexWithTarget(t *testing.T) {
}
func TestApexWithShBinary(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
@ -1235,7 +1236,7 @@ func TestApexWithShBinary(t *testing.T) {
}
func TestApexInProductPartition(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
@ -1267,7 +1268,7 @@ func TestApexInProductPartition(t *testing.T) {
}
func TestApexKeyFromOtherModule(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex_key {
name: "myapex.key",
public_key: ":my.avbpubkey",
@ -1300,7 +1301,7 @@ func TestApexKeyFromOtherModule(t *testing.T) {
}
func TestPrebuilt(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
prebuilt_apex {
name: "myapex",
arch: {
@ -1323,7 +1324,7 @@ func TestPrebuilt(t *testing.T) {
}
func TestPrebuiltFilenameOverride(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
prebuilt_apex {
name: "myapex",
src: "myapex-arm.apex",
@ -1339,8 +1340,28 @@ func TestPrebuiltFilenameOverride(t *testing.T) {
}
}
func TestPrebuiltOverrides(t *testing.T) {
ctx, config := testApex(t, `
prebuilt_apex {
name: "myapex.prebuilt",
src: "myapex-arm.apex",
overrides: [
"myapex",
],
}
`)
p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
expected := []string{"myapex"}
actual := android.AndroidMkEntriesForTest(t, config, "", p).EntryMap["LOCAL_OVERRIDES_PACKAGES"]
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Incorrect LOCAL_OVERRIDES_PACKAGES value '%s', expected '%s'", actual, expected)
}
}
func TestApexWithTests(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex_test {
name: "myapex",
key: "myapex.key",
@ -1374,7 +1395,7 @@ func TestApexWithTests(t *testing.T) {
}
func TestApexUsesOtherApex(t *testing.T) {
ctx := testApex(t, `
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",