diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2019-03-29 07:36:53 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-03-29 07:36:53 +0000 |
commit | 083bd3e971414839a6a4ce9917bfb1b59dbc341c (patch) | |
tree | 293f8ab25f63c2269181730a4e85c1e6dc4352a6 /android | |
parent | 2e03bb7296c434e8d22d86556ea76bc759404110 (diff) | |
parent | 939ebd5f332b243f2921d26f16922cfa8750d862 (diff) | |
download | soong-083bd3e971414839a6a4ce9917bfb1b59dbc341c.tar.gz |
Merge "Add prebuilt_apex."
Diffstat (limited to 'android')
-rw-r--r-- | android/prebuilt.go | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/android/prebuilt.go b/android/prebuilt.go index 5bd0e2dad..df25a89fa 100644 --- a/android/prebuilt.go +++ b/android/prebuilt.go @@ -18,6 +18,7 @@ import ( "fmt" "github.com/google/blueprint" + "github.com/google/blueprint/proptools" ) // This file implements common functionality for handling modules that may exist as prebuilts, @@ -42,6 +43,7 @@ type Prebuilt struct { properties PrebuiltProperties module Module srcs *[]string + src *string } func (p *Prebuilt) Name(name string) string { @@ -49,19 +51,27 @@ func (p *Prebuilt) Name(name string) string { } func (p *Prebuilt) SingleSourcePath(ctx ModuleContext) Path { - if len(*p.srcs) == 0 { - ctx.PropertyErrorf("srcs", "missing prebuilt source file") - return nil - } + if p.srcs != nil { + if len(*p.srcs) == 0 { + ctx.PropertyErrorf("srcs", "missing prebuilt source file") + return nil + } - if len(*p.srcs) > 1 { - ctx.PropertyErrorf("srcs", "multiple prebuilt source files") - return nil - } + if len(*p.srcs) > 1 { + ctx.PropertyErrorf("srcs", "multiple prebuilt source files") + return nil + } - // Return the singleton source after expanding any filegroup in the - // sources. - return PathForModuleSrc(ctx, (*p.srcs)[0]) + // Return the singleton source after expanding any filegroup in the + // sources. + return PathForModuleSrc(ctx, (*p.srcs)[0]) + } else { + if proptools.String(p.src) == "" { + ctx.PropertyErrorf("src", "missing prebuilt source file") + return nil + } + return PathForModuleSrc(ctx, *p.src) + } } func InitPrebuiltModule(module PrebuiltInterface, srcs *[]string) { @@ -70,13 +80,19 @@ func InitPrebuiltModule(module PrebuiltInterface, srcs *[]string) { p.srcs = srcs } +func InitSingleSourcePrebuiltModule(module PrebuiltInterface, src *string) { + p := module.Prebuilt() + module.AddProperties(&p.properties) + p.src = src +} + type PrebuiltInterface interface { Module Prebuilt() *Prebuilt } func RegisterPrebuiltsPreArchMutators(ctx RegisterMutatorsContext) { - ctx.BottomUp("prebuilts", prebuiltMutator).Parallel() + ctx.BottomUp("prebuilts", PrebuiltMutator).Parallel() } func RegisterPrebuiltsPostDepsMutators(ctx RegisterMutatorsContext) { @@ -84,9 +100,9 @@ func RegisterPrebuiltsPostDepsMutators(ctx RegisterMutatorsContext) { ctx.BottomUp("prebuilt_postdeps", PrebuiltPostDepsMutator).Parallel() } -// prebuiltMutator ensures that there is always a module with an undecorated name, and marks +// PrebuiltMutator ensures that there is always a module with an undecorated name, and marks // prebuilt modules that have both a prebuilt and a source module. -func prebuiltMutator(ctx BottomUpMutatorContext) { +func PrebuiltMutator(ctx BottomUpMutatorContext) { if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil { p := m.Prebuilt() name := m.base().BaseModuleName() @@ -104,7 +120,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 { + if p.srcs == nil && p.src == nil { panic(fmt.Errorf("prebuilt module did not have InitPrebuiltModule called on it")) } if !p.properties.SourceExists { @@ -143,7 +159,11 @@ func PrebuiltPostDepsMutator(ctx BottomUpMutatorContext) { // usePrebuilt returns true if a prebuilt should be used instead of the source module. The prebuilt // will be used if it is marked "prefer" or if the source module is disabled. func (p *Prebuilt) usePrebuilt(ctx TopDownMutatorContext, source Module) bool { - if len(*p.srcs) == 0 { + if p.srcs != nil && len(*p.srcs) == 0 { + return false + } + + if p.src != nil && *p.src == "" { return false } |