Merge changes Id9717132,I3e3b7251,I021c7971,I8a117a86,Ia5196f1f, ...

am: b8245ea839

Change-Id: I9cd28715891eb9bbd6e0d1a3e0a3e83da2d1d00f
This commit is contained in:
Colin Cross
2017-08-12 01:19:58 +00:00
committed by android-build-merger
16 changed files with 388 additions and 262 deletions

View File

@@ -33,7 +33,7 @@ func init() {
} }
type AndroidMkDataProvider interface { type AndroidMkDataProvider interface {
AndroidMk() (AndroidMkData, error) AndroidMk() AndroidMkData
BaseModuleName() string BaseModuleName() string
} }
@@ -43,11 +43,15 @@ type AndroidMkData struct {
OutputFile OptionalPath OutputFile OptionalPath
Disabled bool 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 { func AndroidMkSingleton() blueprint.Singleton {
return &androidMkSingleton{} return &androidMkSingleton{}
} }
@@ -157,58 +161,39 @@ func translateAndroidMkModule(ctx blueprint.SingletonContext, w io.Writer, mod b
return nil return nil
} }
data, err := provider.AndroidMk() data := provider.AndroidMk()
if err != nil {
return err
}
// Make does not understand LinuxBionic // Make does not understand LinuxBionic
if amod.Os() == LinuxBionic { if amod.Os() == LinuxBionic {
return nil return nil
} }
if data.SubName != "" { prefix := ""
name += data.SubName 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 { fmt.Fprintln(&data.preamble, "\ninclude $(CLEAR_VARS)")
return nil 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)
if !data.OutputFile.Valid() { fmt.Fprintln(&data.preamble, "LOCAL_PREBUILT_MODULE_FILE :=", data.OutputFile.String())
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())
if len(amod.commonProperties.Required) > 0 { 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() archStr := amod.Arch().ArchType.String()
@@ -217,51 +202,68 @@ func translateAndroidMkModule(ctx blueprint.SingletonContext, w io.Writer, mod b
case Host: case Host:
// Make cannot identify LOCAL_MODULE_HOST_ARCH:= common. // Make cannot identify LOCAL_MODULE_HOST_ARCH:= common.
if archStr != "common" { if archStr != "common" {
fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr) fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_ARCH :=", archStr)
} }
host = true host = true
case HostCross: case HostCross:
// Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common. // Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common.
if archStr != "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 host = true
case Device: case Device:
// Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common. // Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common.
if archStr != "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 { 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 { 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 { if amod.commonProperties.Proprietary {
fmt.Fprintln(w, "LOCAL_PROPRIETARY_MODULE := true") fmt.Fprintln(&data.preamble, "LOCAL_PROPRIETARY_MODULE := true")
} }
if amod.commonProperties.Vendor { if amod.commonProperties.Vendor {
fmt.Fprintln(w, "LOCAL_VENDOR_MODULE := true") fmt.Fprintln(&data.preamble, "LOCAL_VENDOR_MODULE := true")
} }
if amod.commonProperties.Owner != nil { 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 { if host {
fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", amod.Os().String()) fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_OS :=", amod.Os().String())
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") 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 { for _, extra := range data.Extra {
err = extra(w, data.OutputFile.Path()) extra(w, data.OutputFile.Path())
if err != nil {
return err
}
} }
fmt.Fprintln(w, "include $(BUILD_PREBUILT)") fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
return err
} }

View File

@@ -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 // 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 // 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 // package's initialization - either from the init() function or as part of a

View File

@@ -14,7 +14,11 @@
package android 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, // This file implements common functionality for handling modules that may exist as prebuilts,
// source, or both. // source, or both.
@@ -25,35 +29,43 @@ type prebuiltDependencyTag struct {
var prebuiltDepTag prebuiltDependencyTag var prebuiltDepTag prebuiltDependencyTag
type Prebuilt struct { type PrebuiltProperties struct {
Properties struct { // When prefer is set to true the prebuilt will be used instead of any source module with
Srcs []string `android:"arch_variant"` // a matching name.
// When prefer is set to true the prebuilt will be used instead of any source module with Prefer bool `android:"arch_variant"`
// a matching name.
Prefer bool `android:"arch_variant"`
SourceExists bool `blueprint:"mutated"` SourceExists bool `blueprint:"mutated"`
UsePrebuilt bool `blueprint:"mutated"` UsePrebuilt bool `blueprint:"mutated"`
} }
module Module
type Prebuilt struct {
properties PrebuiltProperties
module Module
srcs *[]string
} }
func (p *Prebuilt) Name(name string) string { func (p *Prebuilt) Name(name string) string {
return "prebuilt_" + name return "prebuilt_" + name
} }
func (p *Prebuilt) Path(ctx ModuleContext) Path { func (p *Prebuilt) SingleSourcePath(ctx ModuleContext) Path {
if len(p.Properties.Srcs) == 0 { if len(*p.srcs) == 0 {
ctx.PropertyErrorf("srcs", "missing prebuilt source file") ctx.PropertyErrorf("srcs", "missing prebuilt source file")
return nil return nil
} }
if len(p.Properties.Srcs) > 1 { if len(*p.srcs) > 1 {
ctx.PropertyErrorf("srcs", "multiple prebuilt source files") ctx.PropertyErrorf("srcs", "multiple prebuilt source files")
return nil 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 { type PrebuiltInterface interface {
@@ -78,7 +90,7 @@ func prebuiltMutator(ctx BottomUpMutatorContext) {
name := m.base().BaseModuleName() name := m.base().BaseModuleName()
if ctx.OtherModuleExists(name) { if ctx.OtherModuleExists(name) {
ctx.AddReverseDependency(ctx.Module(), prebuiltDepTag, name) ctx.AddReverseDependency(ctx.Module(), prebuiltDepTag, name)
p.Properties.SourceExists = true p.properties.SourceExists = true
} else { } else {
ctx.Rename(name) ctx.Rename(name)
} }
@@ -90,15 +102,18 @@ func prebuiltMutator(ctx BottomUpMutatorContext) {
func PrebuiltSelectModuleMutator(ctx TopDownMutatorContext) { func PrebuiltSelectModuleMutator(ctx TopDownMutatorContext) {
if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil { if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil {
p := m.Prebuilt() p := m.Prebuilt()
if !p.Properties.SourceExists { if p.srcs == nil {
p.Properties.UsePrebuilt = p.usePrebuilt(ctx, 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 { } else if s, ok := ctx.Module().(Module); ok {
ctx.VisitDirectDeps(func(m blueprint.Module) { ctx.VisitDirectDeps(func(m blueprint.Module) {
if ctx.OtherModuleDependencyTag(m) == prebuiltDepTag { if ctx.OtherModuleDependencyTag(m) == prebuiltDepTag {
p := m.(PrebuiltInterface).Prebuilt() p := m.(PrebuiltInterface).Prebuilt()
if p.usePrebuilt(ctx, s) { if p.usePrebuilt(ctx, s) {
p.Properties.UsePrebuilt = true p.properties.UsePrebuilt = true
s.SkipInstall() s.SkipInstall()
} }
} }
@@ -113,8 +128,8 @@ func PrebuiltReplaceMutator(ctx BottomUpMutatorContext) {
if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil { if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil {
p := m.Prebuilt() p := m.Prebuilt()
name := m.base().BaseModuleName() name := m.base().BaseModuleName()
if p.Properties.UsePrebuilt { if p.properties.UsePrebuilt {
if p.Properties.SourceExists { if p.properties.SourceExists {
ctx.ReplaceDependencies(name) ctx.ReplaceDependencies(name)
} }
} else { } 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 // 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. // will be used if it is marked "prefer" or if the source module is disabled.
func (p *Prebuilt) usePrebuilt(ctx TopDownMutatorContext, source Module) bool { func (p *Prebuilt) usePrebuilt(ctx TopDownMutatorContext, source Module) bool {
if len(p.Properties.Srcs) == 0 { if len(*p.srcs) == 0 {
return false return false
} }
// TODO: use p.Properties.Name and ctx.ModuleDir to override preference // TODO: use p.Properties.Name and ctx.ModuleDir to override preference
if p.Properties.Prefer { if p.properties.Prefer {
return true return true
} }

View File

@@ -151,7 +151,7 @@ func TestPrebuilts(t *testing.T) {
} }
if p, ok := m.(*prebuiltModule); ok { if p, ok := m.(*prebuiltModule); ok {
dependsOnPrebuiltModule = true dependsOnPrebuiltModule = true
if !p.Prebuilt().Properties.UsePrebuilt { if !p.Prebuilt().properties.UsePrebuilt {
t.Errorf("dependency on prebuilt module not marked used") t.Errorf("dependency on prebuilt module not marked used")
} }
} }
@@ -180,12 +180,16 @@ func TestPrebuilts(t *testing.T) {
type prebuiltModule struct { type prebuiltModule struct {
ModuleBase ModuleBase
prebuilt Prebuilt prebuilt Prebuilt
properties struct {
Srcs []string
}
} }
func newPrebuiltModule() Module { func newPrebuiltModule() Module {
m := &prebuiltModule{} m := &prebuiltModule{}
m.AddProperties(&m.prebuilt.Properties) m.AddProperties(&m.properties)
InitPrebuiltModule(m, &m.properties.Srcs)
InitAndroidModule(m) InitAndroidModule(m)
return m return m
} }

View File

@@ -49,30 +49,34 @@ func (c *Module) subAndroidMk(data *android.AndroidMkData, obj interface{}) {
} }
} }
func (c *Module) AndroidMk() (ret android.AndroidMkData, err error) { func (c *Module) AndroidMk() android.AndroidMkData {
if c.Properties.HideFromMake { if c.Properties.HideFromMake {
ret.Disabled = true return android.AndroidMkData{
return ret, nil Disabled: true,
}
} }
ret.OutputFile = c.outputFile ret := android.AndroidMkData{
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) (err error) { OutputFile: c.outputFile,
fmt.Fprintln(w, "LOCAL_SANITIZE := never") Extra: []android.AndroidMkExtraFunc{
if len(c.Properties.AndroidMkSharedLibs) > 0 { func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.Properties.AndroidMkSharedLibs, " ")) fmt.Fprintln(w, "LOCAL_SANITIZE := never")
} if len(c.Properties.AndroidMkSharedLibs) > 0 {
if c.Target().Os == android.Android && c.Properties.Sdk_version != "" && !c.vndk() { fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.Properties.AndroidMkSharedLibs, " "))
fmt.Fprintln(w, "LOCAL_SDK_VERSION := "+c.Properties.Sdk_version) }
fmt.Fprintln(w, "LOCAL_NDK_STL_VARIANT := none") if c.Target().Os == android.Android && c.Properties.Sdk_version != "" && !c.vndk() {
} else { fmt.Fprintln(w, "LOCAL_SDK_VERSION := "+c.Properties.Sdk_version)
// These are already included in LOCAL_SHARED_LIBRARIES fmt.Fprintln(w, "LOCAL_NDK_STL_VARIANT := none")
fmt.Fprintln(w, "LOCAL_CXX_STL := none") } else {
} // These are already included in LOCAL_SHARED_LIBRARIES
if c.vndk() { fmt.Fprintln(w, "LOCAL_CXX_STL := none")
fmt.Fprintln(w, "LOCAL_USE_VNDK := true") }
} if c.vndk() {
return nil fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
}) }
},
},
}
for _, feature := range c.features { for _, feature := range c.features {
c.subAndroidMk(&ret, feature) c.subAndroidMk(&ret, feature)
@@ -91,7 +95,7 @@ func (c *Module) AndroidMk() (ret android.AndroidMkData, err error) {
ret.SubName += vendorSuffix ret.SubName += vendorSuffix
} }
return ret, nil return ret
} }
func androidMkWriteTestData(data android.Paths, ctx AndroidMkContext, ret *android.AndroidMkData) { func androidMkWriteTestData(data android.Paths, ctx AndroidMkContext, ret *android.AndroidMkData) {
@@ -106,9 +110,8 @@ func androidMkWriteTestData(data android.Paths, ctx AndroidMkContext, ret *andro
testFiles = append(testFiles, path+":"+rel) testFiles = append(testFiles, path+":"+rel)
} }
if len(testFiles) > 0 { if len(testFiles) > 0 {
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_TEST_DATA := "+strings.Join(testFiles, " ")) fmt.Fprintln(w, "LOCAL_TEST_DATA := "+strings.Join(testFiles, " "))
return nil
}) })
} }
} }
@@ -133,10 +136,10 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An
ret.Class = "SHARED_LIBRARIES" ret.Class = "SHARED_LIBRARIES"
} else if library.header() { } else if library.header() {
ret.Custom = func(w io.Writer, name, prefix, moduleDir string) error { ret.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
fmt.Fprintln(w, "LOCAL_MODULE :=", name) fmt.Fprintln(w, "LOCAL_MODULE :=", name+data.SubName)
archStr := ctx.Target().Arch.ArchType.String() archStr := ctx.Target().Arch.ArchType.String()
var host bool var host bool
@@ -160,14 +163,12 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An
library.androidMkWriteExportedFlags(w) library.androidMkWriteExportedFlags(w)
fmt.Fprintln(w, "include $(BUILD_HEADER_LIBRARY)") fmt.Fprintln(w, "include $(BUILD_HEADER_LIBRARY)")
return nil
} }
return return
} }
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
library.androidMkWriteExportedFlags(w) library.androidMkWriteExportedFlags(w)
fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES := ") fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES := ")
if library.sAbiOutputFile.Valid() { if library.sAbiOutputFile.Valid() {
@@ -185,8 +186,6 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An
if library.coverageOutputFile.Valid() { if library.coverageOutputFile.Valid() {
fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", library.coverageOutputFile.String()) fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", library.coverageOutputFile.String())
} }
return nil
}) })
if library.shared() { if library.shared() {
@@ -195,13 +194,11 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An
} }
func (object *objectLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { func (object *objectLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
ret.Custom = func(w io.Writer, name, prefix, moduleDir string) error { ret.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
out := ret.OutputFile.Path() out := ret.OutputFile.Path()
fmt.Fprintln(w, "\n$("+prefix+"OUT_INTERMEDIATE_LIBRARIES)/"+name+objectExtension+":", out.String()) fmt.Fprintln(w, "\n$("+prefix+"OUT_INTERMEDIATE_LIBRARIES)/"+name+data.SubName+objectExtension+":", out.String())
fmt.Fprintln(w, "\t$(copy-file-to-target)") fmt.Fprintln(w, "\t$(copy-file-to-target)")
return nil
} }
} }
@@ -210,7 +207,7 @@ func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.Andr
ctx.subAndroidMk(ret, &binary.stripper) ctx.subAndroidMk(ret, &binary.stripper)
ret.Class = "EXECUTABLES" ret.Class = "EXECUTABLES"
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=") fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
if Bool(binary.Properties.Static_executable) { if Bool(binary.Properties.Static_executable) {
fmt.Fprintln(w, "LOCAL_FORCE_STATIC_EXECUTABLE := true") fmt.Fprintln(w, "LOCAL_FORCE_STATIC_EXECUTABLE := true")
@@ -223,19 +220,17 @@ func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.Andr
if binary.coverageOutputFile.Valid() { if binary.coverageOutputFile.Valid() {
fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", binary.coverageOutputFile.String()) fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", binary.coverageOutputFile.String())
} }
return nil
}) })
} }
func (benchmark *benchmarkDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { func (benchmark *benchmarkDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
ctx.subAndroidMk(ret, benchmark.binaryDecorator) ctx.subAndroidMk(ret, benchmark.binaryDecorator)
ret.Class = "NATIVE_TESTS" ret.Class = "NATIVE_TESTS"
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
if len(benchmark.Properties.Test_suites) > 0 { if len(benchmark.Properties.Test_suites) > 0 {
fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=", fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
strings.Join(benchmark.Properties.Test_suites, " ")) strings.Join(benchmark.Properties.Test_suites, " "))
} }
return nil
}) })
androidMkWriteTestData(benchmark.data, ctx, ret) androidMkWriteTestData(benchmark.data, ctx, ret)
@@ -248,12 +243,11 @@ func (test *testBinary) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkDa
ret.SubName = "_" + test.binaryDecorator.Properties.Stem ret.SubName = "_" + test.binaryDecorator.Properties.Stem
} }
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
if len(test.Properties.Test_suites) > 0 { if len(test.Properties.Test_suites) > 0 {
fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=", fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
strings.Join(test.Properties.Test_suites, " ")) strings.Join(test.Properties.Test_suites, " "))
} }
return nil
}) })
androidMkWriteTestData(test.data, ctx, ret) androidMkWriteTestData(test.data, ctx, ret)
@@ -265,11 +259,9 @@ func (test *testLibrary) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkD
func (library *toolchainLibraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { func (library *toolchainLibraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
ret.Class = "STATIC_LIBRARIES" ret.Class = "STATIC_LIBRARIES"
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext()) fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext())
fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=") fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
return nil
}) })
} }
@@ -279,7 +271,7 @@ func (stripper *stripper) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMk
return return
} }
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
if stripper.StripProperties.Strip.None { if stripper.StripProperties.Strip.None {
fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false") fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
} else if stripper.StripProperties.Strip.Keep_symbols { } else if stripper.StripProperties.Strip.Keep_symbols {
@@ -287,17 +279,14 @@ func (stripper *stripper) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMk
} else { } else {
fmt.Fprintln(w, "LOCAL_STRIP_MODULE := mini-debug-info") fmt.Fprintln(w, "LOCAL_STRIP_MODULE := mini-debug-info")
} }
return nil
}) })
} }
func (packer *relocationPacker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { func (packer *relocationPacker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
if packer.Properties.PackingRelocations { if packer.Properties.PackingRelocations {
fmt.Fprintln(w, "LOCAL_PACK_MODULE_RELOCATIONS := true") fmt.Fprintln(w, "LOCAL_PACK_MODULE_RELOCATIONS := true")
} }
return nil
}) })
} }
@@ -308,14 +297,13 @@ func (installer *baseInstaller) AndroidMk(ctx AndroidMkContext, ret *android.And
ret.OutputFile = android.OptionalPathForPath(installer.path) ret.OutputFile = android.OptionalPathForPath(installer.path)
} }
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
path := installer.path.RelPathString() path := installer.path.RelPathString()
dir, file := filepath.Split(path) dir, file := filepath.Split(path)
stem := strings.TrimSuffix(file, filepath.Ext(file)) stem := strings.TrimSuffix(file, filepath.Ext(file))
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+filepath.Ext(file)) fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+filepath.Ext(file))
fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir)) fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
return nil
}) })
} }
@@ -323,7 +311,7 @@ func (c *stubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkDa
ret.SubName = ndkLibrarySuffix + "." + c.properties.ApiLevel ret.SubName = ndkLibrarySuffix + "." + c.properties.ApiLevel
ret.Class = "SHARED_LIBRARIES" ret.Class = "SHARED_LIBRARIES"
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
path, file := filepath.Split(c.installPath) path, file := filepath.Split(c.installPath)
stem := strings.TrimSuffix(file, filepath.Ext(file)) stem := strings.TrimSuffix(file, filepath.Ext(file))
fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=") fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
@@ -336,7 +324,6 @@ func (c *stubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkDa
// dozens of libraries with the same name, they'll clobber each other // dozens of libraries with the same name, they'll clobber each other
// and the real versions of the libraries from the platform). // and the real versions of the libraries from the platform).
fmt.Fprintln(w, "LOCAL_COPY_TO_INTERMEDIATE_LIBRARIES := false") fmt.Fprintln(w, "LOCAL_COPY_TO_INTERMEDIATE_LIBRARIES := false")
return nil
}) })
} }
@@ -344,7 +331,7 @@ func (c *llndkStubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.Androi
ret.Class = "SHARED_LIBRARIES" ret.Class = "SHARED_LIBRARIES"
ret.SubName = ".vendor" ret.SubName = ".vendor"
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
c.libraryDecorator.androidMkWriteExportedFlags(w) c.libraryDecorator.androidMkWriteExportedFlags(w)
fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+outputFile.Ext()) fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+outputFile.Ext())
@@ -353,7 +340,5 @@ func (c *llndkStubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.Androi
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true") fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true") fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
fmt.Fprintln(w, "LOCAL_USE_VNDK := true") fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
return nil
}) })
} }

View File

@@ -31,12 +31,19 @@ type prebuiltLinkerInterface interface {
type prebuiltLinker struct { type prebuiltLinker struct {
android.Prebuilt android.Prebuilt
properties struct {
Srcs []string `android:"arch_variant"`
}
} }
func (p *prebuiltLinker) prebuilt() *android.Prebuilt { func (p *prebuiltLinker) prebuilt() *android.Prebuilt {
return &p.Prebuilt return &p.Prebuilt
} }
func (p *prebuiltLinker) PrebuiltSrcs() []string {
return p.properties.Srcs
}
type prebuiltLibraryLinker struct { type prebuiltLibraryLinker struct {
*libraryDecorator *libraryDecorator
prebuiltLinker prebuiltLinker
@@ -44,20 +51,15 @@ type prebuiltLibraryLinker struct {
var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil) var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil)
func (p *prebuiltLibraryLinker) linkerProps() []interface{} {
props := p.libraryDecorator.linkerProps()
return append(props, &p.Prebuilt.Properties)
}
func (p *prebuiltLibraryLinker) link(ctx ModuleContext, func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
flags Flags, deps PathDeps, objs Objects) android.Path { flags Flags, deps PathDeps, objs Objects) android.Path {
// TODO(ccross): verify shared library dependencies // TODO(ccross): verify shared library dependencies
if len(p.Prebuilt.Properties.Srcs) > 0 { if len(p.properties.Srcs) > 0 {
p.libraryDecorator.exportIncludes(ctx, "-I") p.libraryDecorator.exportIncludes(ctx, "-I")
p.libraryDecorator.reexportFlags(deps.ReexportedFlags) p.libraryDecorator.reexportFlags(deps.ReexportedFlags)
p.libraryDecorator.reexportDeps(deps.ReexportedFlagsDeps) p.libraryDecorator.reexportDeps(deps.ReexportedFlagsDeps)
// TODO(ccross): .toc optimization, stripping, packing // TODO(ccross): .toc optimization, stripping, packing
return p.Prebuilt.Path(ctx) return p.Prebuilt.SingleSourcePath(ctx)
} }
return nil return nil
@@ -78,6 +80,9 @@ func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libr
} }
module.linker = prebuilt module.linker = prebuilt
module.AddProperties(&prebuilt.properties)
android.InitPrebuiltModule(module, &prebuilt.properties.Srcs)
return module, library return module, library
} }
@@ -96,6 +101,9 @@ func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libr
} }
module.linker = prebuilt module.linker = prebuilt
module.AddProperties(&prebuilt.properties)
android.InitPrebuiltModule(module, &prebuilt.properties.Srcs)
return module, library return module, library
} }
@@ -106,15 +114,10 @@ type prebuiltBinaryLinker struct {
var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil) var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil)
func (p *prebuiltBinaryLinker) linkerProps() []interface{} {
props := p.binaryDecorator.linkerProps()
return append(props, &p.Prebuilt.Properties)
}
func (p *prebuiltBinaryLinker) link(ctx ModuleContext, func (p *prebuiltBinaryLinker) link(ctx ModuleContext,
flags Flags, deps PathDeps, objs Objects) android.Path { flags Flags, deps PathDeps, objs Objects) android.Path {
// TODO(ccross): verify shared library dependencies // TODO(ccross): verify shared library dependencies
if len(p.Prebuilt.Properties.Srcs) > 0 { if len(p.properties.Srcs) > 0 {
// TODO(ccross): .toc optimization, stripping, packing // TODO(ccross): .toc optimization, stripping, packing
// Copy binaries to a name matching the final installed name // Copy binaries to a name matching the final installed name
@@ -125,7 +128,7 @@ func (p *prebuiltBinaryLinker) link(ctx ModuleContext,
Rule: android.Cp, Rule: android.Cp,
Description: "prebuilt", Description: "prebuilt",
Output: outputFile, Output: outputFile,
Input: p.Prebuilt.Path(ctx), Input: p.Prebuilt.SingleSourcePath(ctx),
}) })
return outputFile return outputFile
@@ -148,5 +151,8 @@ func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecor
} }
module.linker = prebuilt module.linker = prebuilt
module.AddProperties(&prebuilt.properties)
android.InitPrebuiltModule(module, &prebuilt.properties.Srcs)
return module, binary return module, binary
} }

View File

@@ -444,12 +444,10 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
} }
func (sanitize *sanitize) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { func (sanitize *sanitize) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
if sanitize.androidMkRuntimeLibrary != "" { if sanitize.androidMkRuntimeLibrary != "" {
fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES += "+sanitize.androidMkRuntimeLibrary) fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES += "+sanitize.androidMkRuntimeLibrary)
} }
return nil
}) })
} }

View File

@@ -15,17 +15,32 @@
package java package java
import ( import (
"fmt"
"io"
"android/soong/android" "android/soong/android"
) )
func (library *Library) AndroidMk() (ret android.AndroidMkData, err error) { func (library *Library) AndroidMk() android.AndroidMkData {
ret.Class = "JAVA_LIBRARIES" return android.AndroidMkData{
ret.OutputFile = android.OptionalPathForPath(library.outputFile) Class: "JAVA_LIBRARIES",
return OutputFile: android.OptionalPathForPath(library.outputFile),
Extra: []android.AndroidMkExtraFunc{
func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := .jar")
},
},
}
} }
func (prebuilt *Prebuilt) AndroidMk() (ret android.AndroidMkData, err error) { func (prebuilt *Import) AndroidMk() android.AndroidMkData {
ret.Class = "JAVA_LIBRARIES" return android.AndroidMkData{
ret.OutputFile = android.OptionalPathForPath(prebuilt.classpathFile) Class: "JAVA_LIBRARIES",
return OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
Extra: []android.AndroidMkExtraFunc{
func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := .jar")
},
},
}
} }

View File

@@ -231,18 +231,19 @@ func (a *AndroidApp) aaptFlags(ctx android.ModuleContext) ([]string, android.Pat
aaptFlags = append(aaptFlags, android.JoinWithPrefix(resourceDirs.Strings(), "-S ")) aaptFlags = append(aaptFlags, android.JoinWithPrefix(resourceDirs.Strings(), "-S "))
ctx.VisitDirectDeps(func(module blueprint.Module) { ctx.VisitDirectDeps(func(module blueprint.Module) {
var depFile android.OptionalPath var depFiles android.Paths
if sdkDep, ok := module.(sdkDependency); ok { if sdkDep, ok := module.(sdkDependency); ok {
depFile = android.OptionalPathForPath(sdkDep.ClasspathFile()) depFiles = sdkDep.ClasspathFiles()
} else if javaDep, ok := module.(Dependency); ok { } else if javaDep, ok := module.(Dependency); ok {
if ctx.OtherModuleName(module) == "framework-res" { if ctx.OtherModuleName(module) == "framework-res" {
depFile = android.OptionalPathForPath(javaDep.(*AndroidApp).exportPackage) depFiles = android.Paths{javaDep.(*AndroidApp).exportPackage}
} }
} }
if depFile.Valid() {
aaptFlags = append(aaptFlags, "-I "+depFile.String()) for _, dep := range depFiles {
aaptDeps = append(aaptDeps, depFile.Path()) aaptFlags = append(aaptFlags, "-I "+dep.String())
} }
aaptDeps = append(aaptDeps, depFiles...)
}) })
sdkVersion := a.deviceProperties.Sdk_version sdkVersion := a.deviceProperties.Sdk_version

View File

@@ -19,13 +19,11 @@ package java
// functions. // functions.
import ( import (
"path/filepath"
"strings" "strings"
"android/soong/android" "android/soong/android"
"github.com/google/blueprint" "github.com/google/blueprint"
_ "github.com/google/blueprint/bootstrap"
) )
var ( var (
@@ -39,36 +37,37 @@ var (
// read from directly using @<listfile>) // read from directly using @<listfile>)
javac = pctx.AndroidGomaStaticRule("javac", javac = pctx.AndroidGomaStaticRule("javac",
blueprint.RuleParams{ blueprint.RuleParams{
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + Command: `rm -rf "$outDir" "$annoDir" && mkdir -p "$outDir" "$annoDir" && ` +
`${JavacWrapper}$javacCmd ` + `${config.JavacWrapper}${config.JavacCmd} ${config.CommonJdkFlags} ` +
`-encoding UTF-8 $javacFlags $bootClasspath $classpath ` + `$javacFlags $bootClasspath $classpath ` +
`-extdirs "" -d $outDir @$out.rsp || ( rm -rf "$outDir"; exit 41 ) && ` + `-source $javaVersion -target $javaVersion ` +
`-d $outDir -s $annoDir @$out.rsp || ( rm -rf "$outDir"; exit 41 ) && ` +
`find $outDir -name "*.class" > $out`, `find $outDir -name "*.class" > $out`,
Rspfile: "$out.rsp", Rspfile: "$out.rsp",
RspfileContent: "$in", RspfileContent: "$in",
}, },
"javacCmd", "javacFlags", "bootClasspath", "classpath", "outDir") "javacFlags", "bootClasspath", "classpath", "outDir", "annoDir", "javaVersion")
jar = pctx.AndroidStaticRule("jar", jar = pctx.AndroidStaticRule("jar",
blueprint.RuleParams{ blueprint.RuleParams{
Command: `$jarCmd -o $out $jarArgs`, Command: `${config.SoongZipCmd} -o $out -d $jarArgs`,
CommandDeps: []string{"$jarCmd"}, CommandDeps: []string{"${config.SoongZipCmd}"},
}, },
"jarCmd", "jarArgs") "jarCmd", "jarArgs")
dx = pctx.AndroidStaticRule("dx", dx = pctx.AndroidStaticRule("dx",
blueprint.RuleParams{ blueprint.RuleParams{
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
`$dxCmd --dex --output=$outDir $dxFlags $in || ( rm -rf "$outDir"; exit 41 ) && ` + `${config.DxCmd} --dex --output=$outDir $dxFlags $in || ( rm -rf "$outDir"; exit 41 ) && ` +
`find "$outDir" -name "classes*.dex" > $out`, `find "$outDir" -name "classes*.dex" | sort > $out`,
CommandDeps: []string{"$dxCmd"}, CommandDeps: []string{"${config.DxCmd}"},
}, },
"outDir", "dxFlags") "outDir", "dxFlags")
jarjar = pctx.AndroidStaticRule("jarjar", jarjar = pctx.AndroidStaticRule("jarjar",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "java -jar $jarjarCmd process $rulesFile $in $out", Command: "${config.JavaCmd} -jar ${config.JarjarCmd} process $rulesFile $in $out",
CommandDeps: []string{"$jarjarCmd", "$rulesFile"}, CommandDeps: []string{"${config.JavaCmd}", "${config.JarjarCmd}", "$rulesFile"},
}, },
"rulesFile") "rulesFile")
@@ -83,19 +82,7 @@ var (
) )
func init() { func init() {
pctx.Import("github.com/google/blueprint/bootstrap") pctx.Import("android/soong/java/config")
pctx.StaticVariable("commonJdkFlags", "-source 1.7 -target 1.7 -Xmaxerrs 9999999")
pctx.StaticVariable("javacCmd", "javac -J-Xmx1024M $commonJdkFlags")
pctx.StaticVariable("jarCmd", filepath.Join("${bootstrap.ToolDir}", "soong_zip"))
pctx.HostBinToolVariable("dxCmd", "dx")
pctx.HostJavaToolVariable("jarjarCmd", "jarjar.jar")
pctx.VariableFunc("JavacWrapper", func(config interface{}) (string, error) {
if override := config.(android.Config).Getenv("JAVAC_WRAPPER"); override != "" {
return override + " ", nil
}
return "", nil
})
} }
type javaBuilderFlags struct { type javaBuilderFlags struct {
@@ -104,6 +91,7 @@ type javaBuilderFlags struct {
bootClasspath string bootClasspath string
classpath string classpath string
aidlFlags string aidlFlags string
javaVersion string
} }
type jarSpec struct { type jarSpec struct {
@@ -118,6 +106,7 @@ func TransformJavaToClasses(ctx android.ModuleContext, srcFiles android.Paths, s
flags javaBuilderFlags, deps android.Paths) jarSpec { flags javaBuilderFlags, deps android.Paths) jarSpec {
classDir := android.PathForModuleOut(ctx, "classes") classDir := android.PathForModuleOut(ctx, "classes")
annoDir := android.PathForModuleOut(ctx, "anno")
classFileList := android.PathForModuleOut(ctx, "classes.list") classFileList := android.PathForModuleOut(ctx, "classes.list")
javacFlags := flags.javacFlags + android.JoinWithPrefix(srcFileLists.Strings(), "@") javacFlags := flags.javacFlags + android.JoinWithPrefix(srcFileLists.Strings(), "@")
@@ -135,6 +124,8 @@ func TransformJavaToClasses(ctx android.ModuleContext, srcFiles android.Paths, s
"bootClasspath": flags.bootClasspath, "bootClasspath": flags.bootClasspath,
"classpath": flags.classpath, "classpath": flags.classpath,
"outDir": classDir.String(), "outDir": classDir.String(),
"annoDir": annoDir.String(),
"javaVersion": flags.javaVersion,
}, },
}) })
@@ -237,11 +228,11 @@ func TransformJarJar(ctx android.ModuleContext, classesJar android.Path, rulesFi
} }
func TransformPrebuiltJarToClasses(ctx android.ModuleContext, func TransformPrebuiltJarToClasses(ctx android.ModuleContext,
prebuilt android.Path) (classJarSpec, resourceJarSpec jarSpec) { subdir string, prebuilt android.Path) (classJarSpec, resourceJarSpec jarSpec) {
classDir := android.PathForModuleOut(ctx, "extracted/classes") classDir := android.PathForModuleOut(ctx, subdir, "classes")
classFileList := android.PathForModuleOut(ctx, "extracted/classes.list") classFileList := android.PathForModuleOut(ctx, subdir, "classes.list")
resourceFileList := android.PathForModuleOut(ctx, "extracted/resources.list") resourceFileList := android.PathForModuleOut(ctx, subdir, "resources.list")
ctx.ModuleBuild(pctx, android.ModuleBuildParams{ ctx.ModuleBuild(pctx, android.ModuleBuildParams{
Rule: extractPrebuilt, Rule: extractPrebuilt,

View File

@@ -14,10 +14,53 @@
package config package config
import "android/soong/android" import (
"path/filepath"
"strings"
_ "github.com/google/blueprint/bootstrap"
"android/soong/android"
)
var ( var (
pctx = android.NewPackageContext("android/soong/java/config")
DefaultLibraries = []string{"core-oj", "core-libart", "ext", "framework", "okhttp"} DefaultLibraries = []string{"core-oj", "core-libart", "ext", "framework", "okhttp"}
) )
var pctx = android.NewPackageContext("android/soong/java/config") func init() {
pctx.Import("github.com/google/blueprint/bootstrap")
pctx.StaticVariable("CommonJdkFlags", strings.Join([]string{
`-J-Xmx2048M`,
`-Xmaxerrs 9999999`,
`-encoding UTF-8`,
`-sourcepath ""`,
`-g`,
}, " "))
pctx.StaticVariable("DefaultJavaVersion", "1.8")
pctx.VariableConfigMethod("hostPrebuiltTag", android.Config.PrebuiltOS)
pctx.SourcePathVariableWithEnvOverride("JavaHome",
"prebuilts/jdk/jdk8/${hostPrebuiltTag}", "OVERRIDE_ANDROID_JAVA_HOME")
pctx.SourcePathVariable("JavaToolchain", "${JavaHome}/bin")
pctx.SourcePathVariableWithEnvOverride("JavacCmd",
"${JavaToolchain}/javac", "ALTERNATE_JAVAC")
pctx.SourcePathVariable("JavaCmd", "${JavaToolchain}/java")
pctx.SourcePathVariable("JarCmd", "${JavaToolchain}/jar")
pctx.SourcePathVariable("JavadocCmd", "${JavaToolchain}/javadoc")
pctx.StaticVariable("SoongZipCmd", filepath.Join("${bootstrap.ToolDir}", "soong_zip"))
pctx.HostBinToolVariable("DxCmd", "dx")
pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar")
pctx.VariableFunc("JavacWrapper", func(config interface{}) (string, error) {
if override := config.(android.Config).Getenv("JAVAC_WRAPPER"); override != "" {
return override + " ", nil
}
return "", nil
})
}

View File

@@ -26,4 +26,14 @@ func init() {
func makeVarsProvider(ctx android.MakeVarsContext) { func makeVarsProvider(ctx android.MakeVarsContext) {
ctx.Strict("TARGET_DEFAULT_JAVA_LIBRARIES", strings.Join(DefaultLibraries, " ")) ctx.Strict("TARGET_DEFAULT_JAVA_LIBRARIES", strings.Join(DefaultLibraries, " "))
ctx.Strict("DEFAULT_JAVA_LANGUAGE_VERSION", "${DefaultJavaVersion}")
ctx.Strict("ANDROID_JAVA_HOME", "${JavaHome}")
ctx.Strict("ANDROID_JAVA_TOOLCHAIN", "${JavaToolchain}")
ctx.Strict("JAVA", "${JavaCmd}")
ctx.Strict("JAVAC", "${JavacCmd}")
ctx.Strict("JAR", "${JarCmd}")
ctx.Strict("JAVADOC", "${JavadocCmd}")
ctx.Strict("COMMON_JDK_FLAGS", "${CommonJdkFlags}")
} }

View File

@@ -20,6 +20,7 @@ package java
import ( import (
"fmt" "fmt"
"strconv"
"strings" "strings"
"github.com/google/blueprint" "github.com/google/blueprint"
@@ -37,7 +38,8 @@ func init() {
android.RegisterModuleType("java_library_host", LibraryHostFactory) android.RegisterModuleType("java_library_host", LibraryHostFactory)
android.RegisterModuleType("java_binary", BinaryFactory) android.RegisterModuleType("java_binary", BinaryFactory)
android.RegisterModuleType("java_binary_host", BinaryHostFactory) android.RegisterModuleType("java_binary_host", BinaryHostFactory)
android.RegisterModuleType("java_prebuilt_library", PrebuiltFactory) android.RegisterModuleType("java_import", ImportFactory)
android.RegisterModuleType("java_import_host", ImportFactoryHost)
android.RegisterModuleType("android_prebuilt_sdk", SdkPrebuiltFactory) android.RegisterModuleType("android_prebuilt_sdk", SdkPrebuiltFactory)
android.RegisterModuleType("android_app", AndroidAppFactory) android.RegisterModuleType("android_app", AndroidAppFactory)
@@ -90,6 +92,9 @@ type CompilerProperties struct {
// if not blank, run jarjar using the specified rules file // if not blank, run jarjar using the specified rules file
Jarjar_rules *string Jarjar_rules *string
// If not blank, set the java version passed to javac as -source and -target
Java_version *string
} }
type CompilerDeviceProperties struct { type CompilerDeviceProperties struct {
@@ -144,7 +149,7 @@ type Module struct {
} }
type Dependency interface { type Dependency interface {
ClasspathFile() android.Path ClasspathFiles() android.Paths
ClassJarSpecs() []jarSpec ClassJarSpecs() []jarSpec
ResourceJarSpecs() []jarSpec ResourceJarSpecs() []jarSpec
AidlIncludeDirs() android.Paths AidlIncludeDirs() android.Paths
@@ -220,7 +225,7 @@ func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.Opt
} }
func (j *Module) collectDeps(ctx android.ModuleContext) (classpath android.Paths, func (j *Module) collectDeps(ctx android.ModuleContext) (classpath android.Paths,
bootClasspath android.OptionalPath, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess android.OptionalPath, bootClasspath android.Paths, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess android.OptionalPath,
aidlIncludeDirs android.Paths, srcFileLists android.Paths) { aidlIncludeDirs android.Paths, srcFileLists android.Paths) {
ctx.VisitDirectDeps(func(module blueprint.Module) { ctx.VisitDirectDeps(func(module blueprint.Module) {
@@ -239,11 +244,11 @@ func (j *Module) collectDeps(ctx android.ModuleContext) (classpath android.Paths
switch tag { switch tag {
case bootClasspathTag: case bootClasspathTag:
bootClasspath = android.OptionalPathForPath(dep.ClasspathFile()) bootClasspath = append(bootClasspath, dep.ClasspathFiles()...)
case libTag: case libTag:
classpath = append(classpath, dep.ClasspathFile()) classpath = append(classpath, dep.ClasspathFiles()...)
case staticLibTag: case staticLibTag:
classpath = append(classpath, dep.ClasspathFile()) classpath = append(classpath, dep.ClasspathFiles()...)
classJarSpecs = append(classJarSpecs, dep.ClassJarSpecs()...) classJarSpecs = append(classJarSpecs, dep.ClassJarSpecs()...)
resourceJarSpecs = append(resourceJarSpecs, dep.ResourceJarSpecs()...) resourceJarSpecs = append(resourceJarSpecs, dep.ResourceJarSpecs()...)
case frameworkResTag: case frameworkResTag:
@@ -283,6 +288,13 @@ func (j *Module) compile(ctx android.ModuleContext) {
var flags javaBuilderFlags var flags javaBuilderFlags
javacFlags := j.properties.Javacflags javacFlags := j.properties.Javacflags
if j.properties.Java_version != nil {
flags.javaVersion = *j.properties.Java_version
} else {
flags.javaVersion = "${config.DefaultJavaVersion}"
}
if len(javacFlags) > 0 { if len(javacFlags) > 0 {
ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " ")) ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
flags.javacFlags = "$javacFlags" flags.javacFlags = "$javacFlags"
@@ -296,9 +308,9 @@ func (j *Module) compile(ctx android.ModuleContext) {
var deps android.Paths var deps android.Paths
if bootClasspath.Valid() { if len(bootClasspath) > 0 {
flags.bootClasspath = "-bootclasspath " + bootClasspath.String() flags.bootClasspath = "-bootclasspath " + strings.Join(bootClasspath.Strings(), ":")
deps = append(deps, bootClasspath.Path()) deps = append(deps, bootClasspath...)
} }
if len(classpath) > 0 { if len(classpath) > 0 {
@@ -350,7 +362,7 @@ func (j *Module) compile(ctx android.ModuleContext) {
return return
} }
classes, _ := TransformPrebuiltJarToClasses(ctx, outputFile) classes, _ := TransformPrebuiltJarToClasses(ctx, "jarjar_extracted", outputFile)
classJarSpecs = []jarSpec{classes} classJarSpecs = []jarSpec{classes}
} }
@@ -399,8 +411,8 @@ func (j *Module) compile(ctx android.ModuleContext) {
var _ Dependency = (*Library)(nil) var _ Dependency = (*Library)(nil)
func (j *Module) ClasspathFile() android.Path { func (j *Module) ClasspathFiles() android.Paths {
return j.classpathFile return android.Paths{j.classpathFile}
} }
func (j *Module) ClassJarSpecs() []jarSpec { func (j *Module) ClassJarSpecs() []jarSpec {
@@ -519,63 +531,92 @@ func BinaryHostFactory() android.Module {
// Java prebuilts // Java prebuilts
// //
type Prebuilt struct { type ImportProperties struct {
Jars []string
}
type Import struct {
android.ModuleBase android.ModuleBase
prebuilt android.Prebuilt prebuilt android.Prebuilt
classpathFile android.Path properties ImportProperties
classpathFiles android.Paths
combinedClasspathFile android.Path
classJarSpecs, resourceJarSpecs []jarSpec classJarSpecs, resourceJarSpecs []jarSpec
} }
func (j *Prebuilt) Prebuilt() *android.Prebuilt { func (j *Import) Prebuilt() *android.Prebuilt {
return &j.prebuilt return &j.prebuilt
} }
func (j *Prebuilt) Name() string { func (j *Import) PrebuiltSrcs() []string {
return j.properties.Jars
}
func (j *Import) Name() string {
return j.prebuilt.Name(j.ModuleBase.Name()) return j.prebuilt.Name(j.ModuleBase.Name())
} }
func (j *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) { func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
} }
func (j *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
prebuilt := j.prebuilt.Path(ctx) j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, prebuilt) for i, prebuilt := range j.classpathFiles {
subdir := "extracted" + strconv.Itoa(i)
classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, subdir, prebuilt)
j.classJarSpecs = append(j.classJarSpecs, classJarSpec)
j.resourceJarSpecs = append(j.resourceJarSpecs, resourceJarSpec)
}
j.classpathFile = prebuilt j.combinedClasspathFile = TransformClassesToJar(ctx, j.classJarSpecs, android.OptionalPath{})
j.classJarSpecs = []jarSpec{classJarSpec}
j.resourceJarSpecs = []jarSpec{resourceJarSpec} ctx.InstallFileName(android.PathForModuleInstall(ctx, "framework"),
ctx.InstallFileName(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".jar", j.classpathFile) ctx.ModuleName()+".jar", j.combinedClasspathFile)
} }
var _ Dependency = (*Prebuilt)(nil) var _ Dependency = (*Import)(nil)
func (j *Prebuilt) ClasspathFile() android.Path { func (j *Import) ClasspathFiles() android.Paths {
return j.classpathFile return j.classpathFiles
} }
func (j *Prebuilt) ClassJarSpecs() []jarSpec { func (j *Import) ClassJarSpecs() []jarSpec {
return j.classJarSpecs return j.classJarSpecs
} }
func (j *Prebuilt) ResourceJarSpecs() []jarSpec { func (j *Import) ResourceJarSpecs() []jarSpec {
return j.resourceJarSpecs return j.resourceJarSpecs
} }
func (j *Prebuilt) AidlIncludeDirs() android.Paths { func (j *Import) AidlIncludeDirs() android.Paths {
return nil return nil
} }
func PrebuiltFactory() android.Module { var _ android.PrebuiltInterface = (*Import)(nil)
module := &Prebuilt{}
module.AddProperties(&module.prebuilt.Properties) func ImportFactory() android.Module {
module := &Import{}
module.AddProperties(&module.properties)
android.InitPrebuiltModule(module, &module.properties.Jars)
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
return module return module
} }
func ImportFactoryHost() android.Module {
module := &Import{}
module.AddProperties(&module.properties)
android.InitPrebuiltModule(module, &module.properties.Jars)
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
return module
}
// //
// SDK java prebuilts (.jar containing resources plus framework.aidl) // SDK java prebuilts (.jar containing resources plus framework.aidl)
// //
@@ -592,7 +633,7 @@ type sdkPrebuiltProperties struct {
} }
type sdkPrebuilt struct { type sdkPrebuilt struct {
Prebuilt Import
sdkProperties sdkPrebuiltProperties sdkProperties sdkPrebuiltProperties
@@ -600,7 +641,7 @@ type sdkPrebuilt struct {
} }
func (j *sdkPrebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (j *sdkPrebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.Prebuilt.GenerateAndroidBuildActions(ctx) j.Import.GenerateAndroidBuildActions(ctx)
j.aidlPreprocessed = android.OptionalPathForModuleSrc(ctx, j.sdkProperties.Aidl_preprocessed) j.aidlPreprocessed = android.OptionalPathForModuleSrc(ctx, j.sdkProperties.Aidl_preprocessed)
} }
@@ -612,10 +653,9 @@ func (j *sdkPrebuilt) AidlPreprocessed() android.OptionalPath {
func SdkPrebuiltFactory() android.Module { func SdkPrebuiltFactory() android.Module {
module := &sdkPrebuilt{} module := &sdkPrebuilt{}
module.AddProperties( module.AddProperties(&module.sdkProperties)
&module.prebuilt.Properties,
&module.sdkProperties)
android.InitPrebuiltModule(module, &module.properties.Jars)
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
return module return module
} }

View File

@@ -55,7 +55,7 @@ func testJava(t *testing.T, bp string) *android.TestContext {
ctx := android.NewTestContext() ctx := android.NewTestContext()
ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(AndroidAppFactory)) ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(AndroidAppFactory))
ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(LibraryFactory)) ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(LibraryFactory))
ctx.RegisterModuleType("java_prebuilt_library", android.ModuleFactoryAdaptor(PrebuiltFactory)) ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(ImportFactory))
ctx.RegisterModuleType("java_defaults", android.ModuleFactoryAdaptor(defaultsFactory)) ctx.RegisterModuleType("java_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators) ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators) ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
@@ -209,14 +209,14 @@ func TestPrebuilts(t *testing.T) {
static_libs: ["baz"], static_libs: ["baz"],
} }
java_prebuilt_library { java_import {
name: "bar", name: "bar",
srcs: ["a.jar"], jars: ["a.jar"],
} }
java_prebuilt_library { java_import {
name: "baz", name: "baz",
srcs: ["b.jar"], jars: ["b.jar"],
} }
`) `)
@@ -228,7 +228,7 @@ func TestPrebuilts(t *testing.T) {
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar) t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
} }
baz := filepath.Join(buildDir, ".intermediates", "baz", "extracted", "classes.list") baz := filepath.Join(buildDir, ".intermediates", "baz", "extracted0", "classes.list")
if !strings.Contains(jar.Args["jarArgs"], baz) { if !strings.Contains(jar.Args["jarArgs"], baz) {
t.Errorf("foo jarArgs %v does not contain %q", jar.Args["jarArgs"], baz) t.Errorf("foo jarArgs %v does not contain %q", jar.Args["jarArgs"], baz)
} }

View File

@@ -48,15 +48,14 @@ func (p *phony) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} }
} }
func (p *phony) AndroidMk() (ret android.AndroidMkData, err error) { func (p *phony) AndroidMk() android.AndroidMkData {
ret.Custom = func(w io.Writer, name, prefix, moduleDir string) error { return android.AndroidMkData{
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
fmt.Fprintln(w, "LOCAL_MODULE :=", name) fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(p.requiredModuleNames, " ")) fmt.Fprintln(w, "LOCAL_MODULE :=", name)
fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(p.requiredModuleNames, " "))
fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
return nil },
} }
return
} }

View File

@@ -38,10 +38,12 @@ func (p *pythonBaseModule) subAndroidMk(data *android.AndroidMkData, obj interfa
} }
} }
func (p *pythonBaseModule) AndroidMk() (ret android.AndroidMkData, err error) { func (p *pythonBaseModule) AndroidMk() android.AndroidMkData {
ret := android.AndroidMkData{}
p.subAndroidMk(&ret, p.installer) p.subAndroidMk(&ret, p.installer)
return ret, nil return ret
} }
func (p *pythonBinaryHostDecorator) AndroidMk(base *pythonBaseModule, ret *android.AndroidMkData) { func (p *pythonBinaryHostDecorator) AndroidMk(base *pythonBaseModule, ret *android.AndroidMkData) {
@@ -61,7 +63,7 @@ func (installer *pythonInstaller) AndroidMk(base *pythonBaseModule, ret *android
ret.OutputFile = android.OptionalPathForPath(installer.path) ret.OutputFile = android.OptionalPathForPath(installer.path)
} }
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
path := installer.path.RelPathString() path := installer.path.RelPathString()
dir, file := filepath.Split(path) dir, file := filepath.Split(path)
stem := strings.TrimSuffix(file, filepath.Ext(file)) stem := strings.TrimSuffix(file, filepath.Ext(file))
@@ -69,6 +71,5 @@ func (installer *pythonInstaller) AndroidMk(base *pythonBaseModule, ret *android
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+filepath.Ext(file)) fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+filepath.Ext(file))
fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir)) fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
return nil
}) })
} }