aboutsummaryrefslogtreecommitdiffstats
path: root/android
diff options
context:
space:
mode:
authorJaewoong Jung <jungjw@google.com>2019-06-11 12:25:34 -0700
committerMichael Bestas <mkbestas@lineageos.org>2019-12-11 19:03:32 +0200
commitcdfe4845abb5c1609127207a6b98199dd561cbd3 (patch)
treeef665d90ab809874da257e7f41d60c2d74f5836b /android
parent5e4874fa2710ff14bf3a2d65649e756ad42f252e (diff)
downloadbuild_soong-cdfe4845abb5c1609127207a6b98199dd561cbd3.tar.gz
build_soong-cdfe4845abb5c1609127207a6b98199dd561cbd3.tar.bz2
build_soong-cdfe4845abb5c1609127207a6b98199dd561cbd3.zip
Improve android_app_import.dpi_variants handling.
Instead of circumventing the limitation of Prebuilt implementation by picking a source path itself, it now uses the same mechanism as archMutator and replaces the source path in advance so that Prebuilt always sees the corrent source path. Because this requires the Apk field to be a string pointer, the single source prebuilt implementation is being updated to be reflection-based. Test: Soong unit tests, m soong_docs, TreeHugger Change-Id: I2304f15e32d632f74f95f0d9e9bf1f75ff3e2225
Diffstat (limited to 'android')
-rw-r--r--android/prebuilt.go48
1 files changed, 40 insertions, 8 deletions
diff --git a/android/prebuilt.go b/android/prebuilt.go
index 3d9804ce..48d3b68b 100644
--- a/android/prebuilt.go
+++ b/android/prebuilt.go
@@ -16,6 +16,7 @@ package android
import (
"fmt"
+ "reflect"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -43,7 +44,10 @@ type Prebuilt struct {
properties PrebuiltProperties
module Module
srcs *[]string
- src *string
+
+ // Metadata for single source Prebuilt modules.
+ srcProps reflect.Value
+ srcField reflect.StructField
}
func (p *Prebuilt) Name(name string) string {
@@ -71,11 +75,16 @@ func (p *Prebuilt) SingleSourcePath(ctx ModuleContext) Path {
// sources.
return PathForModuleSrc(ctx, (*p.srcs)[0])
} else {
- if proptools.String(p.src) == "" {
- ctx.PropertyErrorf("src", "missing prebuilt source file")
+ if !p.srcProps.IsValid() {
+ ctx.ModuleErrorf("prebuilt source was not set")
+ }
+ src := p.getSingleSourceFieldValue()
+ if src == "" {
+ ctx.PropertyErrorf(proptools.FieldNameForProperty(p.srcField.Name),
+ "missing prebuilt source file")
return nil
}
- return PathForModuleSrc(ctx, *p.src)
+ return PathForModuleSrc(ctx, src)
}
}
@@ -89,10 +98,12 @@ func InitPrebuiltModule(module PrebuiltInterface, srcs *[]string) {
p.srcs = srcs
}
-func InitSingleSourcePrebuiltModule(module PrebuiltInterface, src *string) {
+func InitSingleSourcePrebuiltModule(module PrebuiltInterface, srcProps interface{}, srcField string) {
p := module.Prebuilt()
module.AddProperties(&p.properties)
- p.src = src
+ p.srcProps = reflect.ValueOf(srcProps).Elem()
+ p.srcField, _ = p.srcProps.Type().FieldByName(srcField)
+ p.checkSingleSourceProperties()
}
type PrebuiltInterface interface {
@@ -129,7 +140,7 @@ func PrebuiltMutator(ctx BottomUpMutatorContext) {
func PrebuiltSelectModuleMutator(ctx TopDownMutatorContext) {
if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil {
p := m.Prebuilt()
- if p.srcs == nil && p.src == nil {
+ if p.srcs == nil && !p.srcProps.IsValid() {
panic(fmt.Errorf("prebuilt module did not have InitPrebuiltModule called on it"))
}
if !p.properties.SourceExists {
@@ -172,7 +183,7 @@ func (p *Prebuilt) usePrebuilt(ctx TopDownMutatorContext, source Module) bool {
return false
}
- if p.src != nil && *p.src == "" {
+ if p.srcProps.IsValid() && p.getSingleSourceFieldValue() == "" {
return false
}
@@ -187,3 +198,24 @@ func (p *Prebuilt) usePrebuilt(ctx TopDownMutatorContext, source Module) bool {
func (p *Prebuilt) SourceExists() bool {
return p.properties.SourceExists
}
+
+func (p *Prebuilt) checkSingleSourceProperties() {
+ if !p.srcProps.IsValid() || p.srcField.Name == "" {
+ panic(fmt.Errorf("invalid single source prebuilt %+v", p))
+ }
+
+ if p.srcProps.Kind() != reflect.Struct && p.srcProps.Kind() != reflect.Interface {
+ panic(fmt.Errorf("invalid single source prebuilt %+v", p.srcProps))
+ }
+}
+
+func (p *Prebuilt) getSingleSourceFieldValue() string {
+ value := p.srcProps.FieldByIndex(p.srcField.Index)
+ if value.Kind() == reflect.Ptr {
+ value = value.Elem()
+ }
+ if value.Kind() != reflect.String {
+ panic(fmt.Errorf("prebuilt src field %q should be a string or a pointer to one", p.srcField.Name))
+ }
+ return value.String()
+}