Merge changes Id9717132,I3e3b7251,I021c7971,I8a117a86,Ia5196f1f, ...
am: b8245ea839
Change-Id: I9cd28715891eb9bbd6e0d1a3e0a3e83da2d1d00f
This commit is contained in:
@@ -33,7 +33,7 @@ func init() {
|
||||
}
|
||||
|
||||
type AndroidMkDataProvider interface {
|
||||
AndroidMk() (AndroidMkData, error)
|
||||
AndroidMk() AndroidMkData
|
||||
BaseModuleName() string
|
||||
}
|
||||
|
||||
@@ -43,11 +43,15 @@ type AndroidMkData struct {
|
||||
OutputFile OptionalPath
|
||||
Disabled bool
|
||||
|
||||
Custom func(w io.Writer, name, prefix, moduleDir string) error
|
||||
Custom func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData)
|
||||
|
||||
Extra []func(w io.Writer, outputFile Path) error
|
||||
Extra []AndroidMkExtraFunc
|
||||
|
||||
preamble bytes.Buffer
|
||||
}
|
||||
|
||||
type AndroidMkExtraFunc func(w io.Writer, outputFile Path)
|
||||
|
||||
func AndroidMkSingleton() blueprint.Singleton {
|
||||
return &androidMkSingleton{}
|
||||
}
|
||||
@@ -157,58 +161,39 @@ func translateAndroidMkModule(ctx blueprint.SingletonContext, w io.Writer, mod b
|
||||
return nil
|
||||
}
|
||||
|
||||
data, err := provider.AndroidMk()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data := provider.AndroidMk()
|
||||
|
||||
// Make does not understand LinuxBionic
|
||||
if amod.Os() == LinuxBionic {
|
||||
return nil
|
||||
}
|
||||
|
||||
if data.SubName != "" {
|
||||
name += data.SubName
|
||||
}
|
||||
prefix := ""
|
||||
if amod.ArchSpecific() {
|
||||
switch amod.Os().Class {
|
||||
case Host:
|
||||
prefix = "HOST_"
|
||||
case HostCross:
|
||||
prefix = "HOST_CROSS_"
|
||||
case Device:
|
||||
prefix = "TARGET_"
|
||||
|
||||
if data.Custom != nil {
|
||||
prefix := ""
|
||||
if amod.ArchSpecific() {
|
||||
switch amod.Os().Class {
|
||||
case Host:
|
||||
prefix = "HOST_"
|
||||
case HostCross:
|
||||
prefix = "HOST_CROSS_"
|
||||
case Device:
|
||||
prefix = "TARGET_"
|
||||
|
||||
}
|
||||
|
||||
config := ctx.Config().(Config)
|
||||
if amod.Arch().ArchType != config.Targets[amod.Os().Class][0].Arch.ArchType {
|
||||
prefix = "2ND_" + prefix
|
||||
}
|
||||
}
|
||||
|
||||
return data.Custom(w, name, prefix, filepath.Dir(ctx.BlueprintFile(mod)))
|
||||
config := ctx.Config().(Config)
|
||||
if amod.Arch().ArchType != config.Targets[amod.Os().Class][0].Arch.ArchType {
|
||||
prefix = "2ND_" + prefix
|
||||
}
|
||||
}
|
||||
|
||||
if data.Disabled {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !data.OutputFile.Valid() {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
|
||||
fmt.Fprintln(w, "LOCAL_PATH :=", filepath.Dir(ctx.BlueprintFile(mod)))
|
||||
fmt.Fprintln(w, "LOCAL_MODULE :=", name)
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", data.Class)
|
||||
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", data.OutputFile.String())
|
||||
fmt.Fprintln(&data.preamble, "\ninclude $(CLEAR_VARS)")
|
||||
fmt.Fprintln(&data.preamble, "LOCAL_PATH :=", filepath.Dir(ctx.BlueprintFile(mod)))
|
||||
fmt.Fprintln(&data.preamble, "LOCAL_MODULE :=", name+data.SubName)
|
||||
fmt.Fprintln(&data.preamble, "LOCAL_MODULE_CLASS :=", data.Class)
|
||||
fmt.Fprintln(&data.preamble, "LOCAL_PREBUILT_MODULE_FILE :=", data.OutputFile.String())
|
||||
|
||||
if len(amod.commonProperties.Required) > 0 {
|
||||
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(amod.commonProperties.Required, " "))
|
||||
fmt.Fprintln(&data.preamble, "LOCAL_REQUIRED_MODULES := "+strings.Join(amod.commonProperties.Required, " "))
|
||||
}
|
||||
|
||||
archStr := amod.Arch().ArchType.String()
|
||||
@@ -217,51 +202,68 @@ func translateAndroidMkModule(ctx blueprint.SingletonContext, w io.Writer, mod b
|
||||
case Host:
|
||||
// Make cannot identify LOCAL_MODULE_HOST_ARCH:= common.
|
||||
if archStr != "common" {
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
|
||||
fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_ARCH :=", archStr)
|
||||
}
|
||||
host = true
|
||||
case HostCross:
|
||||
// Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common.
|
||||
if archStr != "common" {
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
|
||||
fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
|
||||
}
|
||||
host = true
|
||||
case Device:
|
||||
// Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common.
|
||||
if archStr != "common" {
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
|
||||
fmt.Fprintln(&data.preamble, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
|
||||
}
|
||||
|
||||
if len(amod.commonProperties.Logtags) > 0 {
|
||||
fmt.Fprintln(w, "LOCAL_LOGTAGS_FILES := ", strings.Join(amod.commonProperties.Logtags, " "))
|
||||
fmt.Fprintln(&data.preamble, "LOCAL_LOGTAGS_FILES := ", strings.Join(amod.commonProperties.Logtags, " "))
|
||||
}
|
||||
if len(amod.commonProperties.Init_rc) > 0 {
|
||||
fmt.Fprintln(w, "LOCAL_INIT_RC := ", strings.Join(amod.commonProperties.Init_rc, " "))
|
||||
fmt.Fprintln(&data.preamble, "LOCAL_INIT_RC := ", strings.Join(amod.commonProperties.Init_rc, " "))
|
||||
}
|
||||
if amod.commonProperties.Proprietary {
|
||||
fmt.Fprintln(w, "LOCAL_PROPRIETARY_MODULE := true")
|
||||
fmt.Fprintln(&data.preamble, "LOCAL_PROPRIETARY_MODULE := true")
|
||||
}
|
||||
if amod.commonProperties.Vendor {
|
||||
fmt.Fprintln(w, "LOCAL_VENDOR_MODULE := true")
|
||||
fmt.Fprintln(&data.preamble, "LOCAL_VENDOR_MODULE := true")
|
||||
}
|
||||
if amod.commonProperties.Owner != nil {
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_OWNER :=", *amod.commonProperties.Owner)
|
||||
fmt.Fprintln(&data.preamble, "LOCAL_MODULE_OWNER :=", *amod.commonProperties.Owner)
|
||||
}
|
||||
}
|
||||
|
||||
if host {
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", amod.Os().String())
|
||||
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
|
||||
fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_OS :=", amod.Os().String())
|
||||
fmt.Fprintln(&data.preamble, "LOCAL_IS_HOST_MODULE := true")
|
||||
}
|
||||
|
||||
blueprintDir := filepath.Dir(ctx.BlueprintFile(mod))
|
||||
|
||||
if data.Custom != nil {
|
||||
data.Custom(w, name, prefix, blueprintDir, data)
|
||||
} else {
|
||||
WriteAndroidMkData(w, data)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func WriteAndroidMkData(w io.Writer, data AndroidMkData) {
|
||||
if data.Disabled {
|
||||
return
|
||||
}
|
||||
|
||||
if !data.OutputFile.Valid() {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(data.preamble.Bytes())
|
||||
|
||||
for _, extra := range data.Extra {
|
||||
err = extra(w, data.OutputFile.Path())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
extra(w, data.OutputFile.Path())
|
||||
}
|
||||
|
||||
fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
|
||||
|
||||
return err
|
||||
}
|
||||
|
@@ -75,6 +75,22 @@ func (p AndroidPackageContext) SourcePathVariable(name, path string) blueprint.V
|
||||
})
|
||||
}
|
||||
|
||||
// SourcePathVariableWithEnvOverride returns a Variable whose value is the source directory
|
||||
// appended with the supplied path, or the value of the given environment variable if it is set.
|
||||
// The environment variable is not required to point to a path inside the source tree.
|
||||
// It may only be called during a Go package's initialization - either from the init() function or
|
||||
// as part of a package-scoped variable's initialization.
|
||||
func (p AndroidPackageContext) SourcePathVariableWithEnvOverride(name, path, env string) blueprint.Variable {
|
||||
return p.VariableFunc(name, func(config interface{}) (string, error) {
|
||||
ctx := &configErrorWrapper{p, config.(Config), []error{}}
|
||||
p := safePathForSource(ctx, path)
|
||||
if len(ctx.errors) > 0 {
|
||||
return "", ctx.errors[0]
|
||||
}
|
||||
return config.(Config).GetenvWithDefault(env, p.String()), nil
|
||||
})
|
||||
}
|
||||
|
||||
// HostBinVariable returns a Variable whose value is the path to a host tool
|
||||
// in the bin directory for host targets. It may only be called during a Go
|
||||
// package's initialization - either from the init() function or as part of a
|
||||
|
@@ -14,7 +14,11 @@
|
||||
|
||||
package android
|
||||
|
||||
import "github.com/google/blueprint"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
|
||||
// This file implements common functionality for handling modules that may exist as prebuilts,
|
||||
// source, or both.
|
||||
@@ -25,35 +29,43 @@ type prebuiltDependencyTag struct {
|
||||
|
||||
var prebuiltDepTag prebuiltDependencyTag
|
||||
|
||||
type Prebuilt struct {
|
||||
Properties struct {
|
||||
Srcs []string `android:"arch_variant"`
|
||||
// When prefer is set to true the prebuilt will be used instead of any source module with
|
||||
// a matching name.
|
||||
Prefer bool `android:"arch_variant"`
|
||||
type PrebuiltProperties struct {
|
||||
// When prefer is set to true the prebuilt will be used instead of any source module with
|
||||
// a matching name.
|
||||
Prefer bool `android:"arch_variant"`
|
||||
|
||||
SourceExists bool `blueprint:"mutated"`
|
||||
UsePrebuilt bool `blueprint:"mutated"`
|
||||
}
|
||||
module Module
|
||||
SourceExists bool `blueprint:"mutated"`
|
||||
UsePrebuilt bool `blueprint:"mutated"`
|
||||
}
|
||||
|
||||
type Prebuilt struct {
|
||||
properties PrebuiltProperties
|
||||
module Module
|
||||
srcs *[]string
|
||||
}
|
||||
|
||||
func (p *Prebuilt) Name(name string) string {
|
||||
return "prebuilt_" + name
|
||||
}
|
||||
|
||||
func (p *Prebuilt) Path(ctx ModuleContext) Path {
|
||||
if len(p.Properties.Srcs) == 0 {
|
||||
func (p *Prebuilt) SingleSourcePath(ctx ModuleContext) Path {
|
||||
if len(*p.srcs) == 0 {
|
||||
ctx.PropertyErrorf("srcs", "missing prebuilt source file")
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(p.Properties.Srcs) > 1 {
|
||||
if len(*p.srcs) > 1 {
|
||||
ctx.PropertyErrorf("srcs", "multiple prebuilt source files")
|
||||
return nil
|
||||
}
|
||||
|
||||
return PathForModuleSrc(ctx, p.Properties.Srcs[0])
|
||||
return PathForModuleSrc(ctx, (*p.srcs)[0])
|
||||
}
|
||||
|
||||
func InitPrebuiltModule(module PrebuiltInterface, srcs *[]string) {
|
||||
p := module.Prebuilt()
|
||||
module.AddProperties(&p.properties)
|
||||
p.srcs = srcs
|
||||
}
|
||||
|
||||
type PrebuiltInterface interface {
|
||||
@@ -78,7 +90,7 @@ func prebuiltMutator(ctx BottomUpMutatorContext) {
|
||||
name := m.base().BaseModuleName()
|
||||
if ctx.OtherModuleExists(name) {
|
||||
ctx.AddReverseDependency(ctx.Module(), prebuiltDepTag, name)
|
||||
p.Properties.SourceExists = true
|
||||
p.properties.SourceExists = true
|
||||
} else {
|
||||
ctx.Rename(name)
|
||||
}
|
||||
@@ -90,15 +102,18 @@ func prebuiltMutator(ctx BottomUpMutatorContext) {
|
||||
func PrebuiltSelectModuleMutator(ctx TopDownMutatorContext) {
|
||||
if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil {
|
||||
p := m.Prebuilt()
|
||||
if !p.Properties.SourceExists {
|
||||
p.Properties.UsePrebuilt = p.usePrebuilt(ctx, nil)
|
||||
if p.srcs == nil {
|
||||
panic(fmt.Errorf("prebuilt module did not have InitPrebuiltModule called on it"))
|
||||
}
|
||||
if !p.properties.SourceExists {
|
||||
p.properties.UsePrebuilt = p.usePrebuilt(ctx, nil)
|
||||
}
|
||||
} else if s, ok := ctx.Module().(Module); ok {
|
||||
ctx.VisitDirectDeps(func(m blueprint.Module) {
|
||||
if ctx.OtherModuleDependencyTag(m) == prebuiltDepTag {
|
||||
p := m.(PrebuiltInterface).Prebuilt()
|
||||
if p.usePrebuilt(ctx, s) {
|
||||
p.Properties.UsePrebuilt = true
|
||||
p.properties.UsePrebuilt = true
|
||||
s.SkipInstall()
|
||||
}
|
||||
}
|
||||
@@ -113,8 +128,8 @@ func PrebuiltReplaceMutator(ctx BottomUpMutatorContext) {
|
||||
if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil {
|
||||
p := m.Prebuilt()
|
||||
name := m.base().BaseModuleName()
|
||||
if p.Properties.UsePrebuilt {
|
||||
if p.Properties.SourceExists {
|
||||
if p.properties.UsePrebuilt {
|
||||
if p.properties.SourceExists {
|
||||
ctx.ReplaceDependencies(name)
|
||||
}
|
||||
} else {
|
||||
@@ -126,12 +141,12 @@ func PrebuiltReplaceMutator(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.Properties.Srcs) == 0 {
|
||||
if len(*p.srcs) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
// TODO: use p.Properties.Name and ctx.ModuleDir to override preference
|
||||
if p.Properties.Prefer {
|
||||
if p.properties.Prefer {
|
||||
return true
|
||||
}
|
||||
|
||||
|
@@ -151,7 +151,7 @@ func TestPrebuilts(t *testing.T) {
|
||||
}
|
||||
if p, ok := m.(*prebuiltModule); ok {
|
||||
dependsOnPrebuiltModule = true
|
||||
if !p.Prebuilt().Properties.UsePrebuilt {
|
||||
if !p.Prebuilt().properties.UsePrebuilt {
|
||||
t.Errorf("dependency on prebuilt module not marked used")
|
||||
}
|
||||
}
|
||||
@@ -180,12 +180,16 @@ func TestPrebuilts(t *testing.T) {
|
||||
|
||||
type prebuiltModule struct {
|
||||
ModuleBase
|
||||
prebuilt Prebuilt
|
||||
prebuilt Prebuilt
|
||||
properties struct {
|
||||
Srcs []string
|
||||
}
|
||||
}
|
||||
|
||||
func newPrebuiltModule() Module {
|
||||
m := &prebuiltModule{}
|
||||
m.AddProperties(&m.prebuilt.Properties)
|
||||
m.AddProperties(&m.properties)
|
||||
InitPrebuiltModule(m, &m.properties.Srcs)
|
||||
InitAndroidModule(m)
|
||||
return m
|
||||
}
|
||||
|
Reference in New Issue
Block a user