diff --git a/android/androidmk.go b/android/androidmk.go index 72b6584ab..e9c63fb70 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -148,6 +148,14 @@ type AndroidMkEntries struct { // without worrying about the variables being mixed up in the actual mk file. // 3. Makes troubleshooting and spotting errors easier. entryOrder []string + + // Provides data typically stored by Context objects that are commonly needed by + //AndroidMkEntries objects. + entryContext AndroidMkEntriesContext +} + +type AndroidMkEntriesContext interface { + Config() Config } type AndroidMkExtraEntriesContext interface { @@ -408,10 +416,19 @@ func (a *AndroidMkEntries) getDistContributions(mod blueprint.Module) *distContr } } + ext := filepath.Ext(dest) + suffix := "" if dist.Suffix != nil { - ext := filepath.Ext(dest) - suffix := *dist.Suffix - dest = strings.TrimSuffix(dest, ext) + suffix + ext + suffix = *dist.Suffix + } + + productString := "" + if dist.Append_artifact_with_product != nil && *dist.Append_artifact_with_product { + productString = fmt.Sprintf("_%s", a.entryContext.Config().DeviceProduct()) + } + + if suffix != "" || productString != "" { + dest = strings.TrimSuffix(dest, ext) + suffix + productString + ext } if dist.Dir != nil { @@ -478,6 +495,7 @@ type fillInEntriesContext interface { } func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint.Module) { + a.entryContext = ctx a.EntryMap = make(map[string][]string) amod := mod.(Module) base := amod.base() diff --git a/android/androidmk_test.go b/android/androidmk_test.go index ecfb00825..caf11f10f 100644 --- a/android/androidmk_test.go +++ b/android/androidmk_test.go @@ -148,6 +148,9 @@ func buildContextAndCustomModuleFoo(t *testing.T, bp string) (*TestContext, *cus FixtureRegisterWithContext(func(ctx RegistrationContext) { ctx.RegisterModuleType("custom", customModuleFactory) }), + FixtureModifyProductVariables(func(variables FixtureProductVariables) { + variables.DeviceProduct = proptools.StringPtr("bar") + }), FixtureWithRootAndroidBp(bp), ).RunTest(t) @@ -400,6 +403,25 @@ func TestGetDistContributions(t *testing.T) { }, }) + testHelper(t, "append-artifact-with-product", ` + custom { + name: "foo", + dist: { + targets: ["my_goal"], + append_artifact_with_product: true, + } + } +`, &distContributions{ + copiesForGoals: []*copiesForGoals{ + { + goals: "my_goal", + copies: []distCopy{ + distCopyForTest("one.out", "one_bar.out"), + }, + }, + }, + }) + testHelper(t, "dists-with-tag", ` custom { name: "foo", diff --git a/android/config.go b/android/config.go index e8ca84c6f..5c41ee8bf 100644 --- a/android/config.go +++ b/android/config.go @@ -351,6 +351,7 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string config := &config{ productVariables: productVariables{ DeviceName: stringPtr("test_device"), + DeviceProduct: stringPtr("test_product"), Platform_sdk_version: intPtr(30), Platform_sdk_codename: stringPtr("S"), Platform_base_sdk_extension_version: intPtr(1), @@ -723,6 +724,15 @@ func (c *config) DeviceName() string { return *c.productVariables.DeviceName } +// DeviceProduct returns the current product target. There could be multiple of +// these per device type. +// +// NOTE: Do not base conditional logic on this value. It may break product +// inheritance. +func (c *config) DeviceProduct() string { + return *c.productVariables.DeviceProduct +} + func (c *config) DeviceResourceOverlays() []string { return c.productVariables.DeviceResourceOverlays } diff --git a/android/module.go b/android/module.go index 03d3f80bc..db06d880a 100644 --- a/android/module.go +++ b/android/module.go @@ -609,6 +609,12 @@ type Dist struct { // A suffix to add to the artifact file name (before any extension). Suffix *string `android:"arch_variant"` + // If true, then the artifact file will be appended with _. For + // example, if the product is coral and the module is an android_app module + // of name foo, then the artifact would be foo_coral.apk. If false, there is + // no change to the artifact file name. + Append_artifact_with_product *bool `android:"arch_variant"` + // A string tag to select the OutputFiles associated with the tag. // // If no tag is specified then it will select the default dist paths provided diff --git a/android/variable.go b/android/variable.go index 37037ebdb..4ed05070e 100644 --- a/android/variable.go +++ b/android/variable.go @@ -201,6 +201,7 @@ type productVariables struct { Platform_base_os *string `json:",omitempty"` DeviceName *string `json:",omitempty"` + DeviceProduct *string `json:",omitempty"` DeviceArch *string `json:",omitempty"` DeviceArchVariant *string `json:",omitempty"` DeviceCpuVariant *string `json:",omitempty"` @@ -467,6 +468,7 @@ func (v *productVariables) SetDefaultConfig() { HostArch: stringPtr("x86_64"), HostSecondaryArch: stringPtr("x86"), DeviceName: stringPtr("generic_arm64"), + DeviceProduct: stringPtr("aosp_arm-eng"), DeviceArch: stringPtr("arm64"), DeviceArchVariant: stringPtr("armv8-a"), DeviceCpuVariant: stringPtr("generic"),