Make the "apk" property configurable
On android_app_import and android_test_import.
Unfortunately I had to add a mutator because you can't evaluate
configurable properties during defaultable hooks.
Bug: 373414956
Test: m nothing --no-skip-soong-tests
Change-Id: Ic42d558e4f2222091aac250b9513d867fb8d6984
diff --git a/android/prebuilt.go b/android/prebuilt.go
index 19f12f0..5d75b62 100644
--- a/android/prebuilt.go
+++ b/android/prebuilt.go
@@ -272,6 +272,25 @@
InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, "srcs")
}
+// InitConfigurablePrebuiltModuleString is the same as InitPrebuiltModule, but uses a
+// Configurable string property instead of a regular list of strings. It only produces a single
+// source file.
+func InitConfigurablePrebuiltModuleString(module PrebuiltInterface, srcs *proptools.Configurable[string], propertyName string) {
+ if srcs == nil {
+ panic(fmt.Errorf("%s must not be nil", propertyName))
+ }
+
+ srcsSupplier := func(ctx BaseModuleContext, _ Module) []string {
+ src := srcs.GetOrDefault(ctx, "")
+ if src == "" {
+ return nil
+ }
+ return []string{src}
+ }
+
+ InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, propertyName)
+}
+
func InitSingleSourcePrebuiltModule(module PrebuiltInterface, srcProps interface{}, srcField string) {
srcPropsValue := reflect.ValueOf(srcProps).Elem()
srcStructField, _ := srcPropsValue.Type().FieldByName(srcField)