Merge "Create C-Suite config module"
diff --git a/Android.bp b/Android.bp
index 6389421..b15a875b 100644
--- a/Android.bp
+++ b/Android.bp
@@ -493,6 +493,7 @@
],
srcs: [
"sdk/sdk.go",
+ "sdk/update.go",
],
testSrcs: [
"sdk/sdk_test.go",
diff --git a/android/androidmk.go b/android/androidmk.go
index 9071347..b66fd18 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -199,19 +199,19 @@
switch amod.Os().Class {
case Host:
// Make cannot identify LOCAL_MODULE_HOST_ARCH:= common.
- if archStr != "common" {
+ if amod.Arch().ArchType != Common {
a.SetString("LOCAL_MODULE_HOST_ARCH", archStr)
}
host = true
case HostCross:
// Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common.
- if archStr != "common" {
+ if amod.Arch().ArchType != Common {
a.SetString("LOCAL_MODULE_HOST_CROSS_ARCH", archStr)
}
host = true
case Device:
// Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common.
- if archStr != "common" {
+ if amod.Arch().ArchType != Common {
if amod.Target().NativeBridge {
hostArchStr := amod.Target().NativeBridgeHostArchName
if hostArchStr != "" {
diff --git a/android/apex.go b/android/apex.go
index 557febf..5118a0a 100644
--- a/android/apex.go
+++ b/android/apex.go
@@ -19,7 +19,6 @@
"sync"
"github.com/google/blueprint"
- "github.com/google/blueprint/proptools"
)
// ApexModule is the interface that a module type is expected to implement if
@@ -76,18 +75,15 @@
// CreateApexVariations.
setApexName(apexName string)
- // Return the no_apex property
- NoApex() bool
-
// Tests if this module is available for the specified APEX or ":platform"
AvailableFor(what string) bool
+
+ // DepIsInSameApex tests if the other module 'dep' is installed to the same
+ // APEX as this module
+ DepIsInSameApex(ctx BaseModuleContext, dep Module) bool
}
type ApexProperties struct {
- // Whether this module should not be part of any APEX. Default is false.
- // TODO(b/128708192): remove this as this is equal to apex_available: [":platform"]
- No_apex *bool
-
// Availability of this module in APEXes. Only the listed APEXes can include this module.
// "//apex_available:anyapex" is a pseudo APEX name that matches to any APEX.
// "//apex_available:platform" refers to non-APEX partitions like "system.img".
@@ -143,23 +139,30 @@
return false
}
-func (m *ApexModuleBase) NoApex() bool {
- return proptools.Bool(m.ApexProperties.No_apex)
-}
-
const (
availableToPlatform = "//apex_available:platform"
availableToAnyApex = "//apex_available:anyapex"
)
-func (m *ApexModuleBase) AvailableFor(what string) bool {
- if len(m.ApexProperties.Apex_available) == 0 {
+func CheckAvailableForApex(what string, apex_available []string) bool {
+ if len(apex_available) == 0 {
// apex_available defaults to ["//apex_available:platform", "//apex_available:anyapex"],
// which means 'available to everybody'.
return true
}
- return InList(what, m.ApexProperties.Apex_available) ||
- (what != availableToPlatform && InList(availableToAnyApex, m.ApexProperties.Apex_available))
+ return InList(what, apex_available) ||
+ (what != availableToPlatform && InList(availableToAnyApex, apex_available))
+}
+
+func (m *ApexModuleBase) AvailableFor(what string) bool {
+ return CheckAvailableForApex(what, m.ApexProperties.Apex_available)
+}
+
+func (m *ApexModuleBase) DepIsInSameApex(ctx BaseModuleContext, dep Module) bool {
+ // By default, if there is a dependency from A to B, we try to include both in the same APEX,
+ // unless B is explicitly from outside of the APEX (i.e. a stubs lib). Thus, returning true.
+ // This is overridden by some module types like apex.ApexBundle, cc.Module, java.Module, etc.
+ return true
}
func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) {
@@ -167,7 +170,7 @@
if n == availableToPlatform || n == availableToAnyApex {
continue
}
- if !mctx.OtherModuleExists(n) {
+ if !mctx.OtherModuleExists(n) && !mctx.Config().AllowMissingDependencies() {
mctx.PropertyErrorf("apex_available", "%q is not a valid module name", n)
}
}
@@ -178,7 +181,7 @@
m.checkApexAvailableProperty(mctx)
sort.Strings(m.apexVariations)
variations := []string{}
- availableForPlatform := m.AvailableFor(availableToPlatform)
+ availableForPlatform := mctx.Module().(ApexModule).AvailableFor(availableToPlatform)
if availableForPlatform {
variations = append(variations, "") // Original variation for platform
}
diff --git a/android/arch.go b/android/arch.go
index 907c58b..0519e76 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -22,9 +22,12 @@
"strconv"
"strings"
+ "github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
+const COMMON_VARIANT = "common"
+
var (
archTypeList []ArchType
@@ -36,7 +39,7 @@
X86_64 = newArch("x86_64", "lib64")
Common = ArchType{
- Name: "common",
+ Name: COMMON_VARIANT,
}
)
@@ -527,7 +530,6 @@
CpuVariant string
Abi []string
ArchFeatures []string
- Native bool
}
func (a Arch) String() string {
@@ -703,11 +705,82 @@
}
func (target Target) String() string {
- variant := ""
+ return target.OsVariation() + "_" + target.ArchVariation()
+}
+
+func (target Target) OsVariation() string {
+ return target.Os.String()
+}
+
+func (target Target) ArchVariation() string {
+ var variation string
if target.NativeBridge {
- variant = "native_bridge_"
+ variation = "native_bridge_"
}
- return target.Os.String() + "_" + variant + target.Arch.String()
+ variation += target.Arch.String()
+
+ return variation
+}
+
+func (target Target) Variations() []blueprint.Variation {
+ return []blueprint.Variation{
+ {Mutator: "os", Variation: target.OsVariation()},
+ {Mutator: "arch", Variation: target.ArchVariation()},
+ }
+}
+
+func osMutator(mctx BottomUpMutatorContext) {
+ var module Module
+ var ok bool
+ if module, ok = mctx.Module().(Module); !ok {
+ return
+ }
+
+ base := module.base()
+
+ if !base.ArchSpecific() {
+ return
+ }
+
+ osClasses := base.OsClassSupported()
+
+ var moduleOSList []OsType
+
+ for _, os := range osTypeList {
+ supportedClass := false
+ for _, osClass := range osClasses {
+ if os.Class == osClass {
+ supportedClass = true
+ }
+ }
+ if !supportedClass {
+ continue
+ }
+
+ if len(mctx.Config().Targets[os]) == 0 {
+ continue
+ }
+
+ moduleOSList = append(moduleOSList, os)
+ }
+
+ if len(moduleOSList) == 0 {
+ base.commonProperties.Enabled = boolPtr(false)
+ return
+ }
+
+ osNames := make([]string, len(moduleOSList))
+
+ for i, os := range moduleOSList {
+ osNames[i] = os.String()
+ }
+
+ modules := mctx.CreateVariations(osNames...)
+ for i, m := range modules {
+ m.(Module).base().commonProperties.CompileOS = moduleOSList[i]
+ m.(Module).base().setOSProperties(mctx)
+ }
+
}
// archMutator splits a module into a variant for each Target requested by the module. Target selection
@@ -747,84 +820,63 @@
return
}
- var moduleTargets []Target
- moduleMultiTargets := make(map[int][]Target)
- primaryModules := make(map[int]bool)
- osClasses := base.OsClassSupported()
+ os := base.commonProperties.CompileOS
+ osTargets := mctx.Config().Targets[os]
- for _, os := range osTypeList {
- supportedClass := false
- for _, osClass := range osClasses {
- if os.Class == osClass {
- supportedClass = true
+ // Filter NativeBridge targets unless they are explicitly supported
+ if os == Android && !Bool(base.commonProperties.Native_bridge_supported) {
+ var targets []Target
+ for _, t := range osTargets {
+ if !t.NativeBridge {
+ targets = append(targets, t)
}
}
- if !supportedClass {
- continue
- }
- osTargets := mctx.Config().Targets[os]
- if len(osTargets) == 0 {
- continue
- }
+ osTargets = targets
+ }
- // Filter NativeBridge targets unless they are explicitly supported
- if os == Android && !Bool(base.commonProperties.Native_bridge_supported) {
- var targets []Target
- for _, t := range osTargets {
- if !t.NativeBridge {
- targets = append(targets, t)
- }
- }
+ // only the primary arch in the recovery partition
+ if os == Android && module.InstallInRecovery() {
+ osTargets = []Target{osTargets[0]}
+ }
- osTargets = targets
- }
+ prefer32 := false
+ if base.prefer32 != nil {
+ prefer32 = base.prefer32(mctx, base, os.Class)
+ }
- // only the primary arch in the recovery partition
- if os == Android && module.InstallInRecovery() {
- osTargets = []Target{osTargets[0]}
- }
+ multilib, extraMultilib := decodeMultilib(base, os.Class)
+ targets, err := decodeMultilibTargets(multilib, osTargets, prefer32)
+ if err != nil {
+ mctx.ModuleErrorf("%s", err.Error())
+ }
- prefer32 := false
- if base.prefer32 != nil {
- prefer32 = base.prefer32(mctx, base, os.Class)
- }
-
- multilib, extraMultilib := decodeMultilib(base, os.Class)
- targets, err := decodeMultilibTargets(multilib, osTargets, prefer32)
+ var multiTargets []Target
+ if extraMultilib != "" {
+ multiTargets, err = decodeMultilibTargets(extraMultilib, osTargets, prefer32)
if err != nil {
mctx.ModuleErrorf("%s", err.Error())
}
-
- var multiTargets []Target
- if extraMultilib != "" {
- multiTargets, err = decodeMultilibTargets(extraMultilib, osTargets, prefer32)
- if err != nil {
- mctx.ModuleErrorf("%s", err.Error())
- }
- }
-
- if len(targets) > 0 {
- primaryModules[len(moduleTargets)] = true
- moduleMultiTargets[len(moduleTargets)] = multiTargets
- moduleTargets = append(moduleTargets, targets...)
- }
}
- if len(moduleTargets) == 0 {
+ if len(targets) == 0 {
base.commonProperties.Enabled = boolPtr(false)
return
}
- targetNames := make([]string, len(moduleTargets))
+ targetNames := make([]string, len(targets))
- for i, target := range moduleTargets {
- targetNames[i] = target.String()
+ for i, target := range targets {
+ targetNames[i] = target.ArchVariation()
}
modules := mctx.CreateVariations(targetNames...)
for i, m := range modules {
- m.(Module).base().SetTarget(moduleTargets[i], moduleMultiTargets[i], primaryModules[i])
+ m.(Module).base().commonProperties.CompileTarget = targets[i]
+ m.(Module).base().commonProperties.CompileMultiTargets = multiTargets
+ if i == 0 {
+ m.(Module).base().commonProperties.CompilePrimary = true
+ }
m.(Module).base().setArchProperties(mctx)
}
}
@@ -855,149 +907,11 @@
}
}
-func filterArchStructFields(fields []reflect.StructField) (filteredFields []reflect.StructField, filtered bool) {
- for _, field := range fields {
- if !proptools.HasTag(field, "android", "arch_variant") {
- filtered = true
- continue
- }
-
- // The arch_variant field isn't necessary past this point
- // Instead of wasting space, just remove it. Go also has a
- // 16-bit limit on structure name length. The name is constructed
- // based on the Go source representation of the structure, so
- // the tag names count towards that length.
- //
- // TODO: handle the uncommon case of other tags being involved
- if field.Tag == `android:"arch_variant"` {
- field.Tag = ""
- }
-
- // Recurse into structs
- switch field.Type.Kind() {
- case reflect.Struct:
- var subFiltered bool
- field.Type, subFiltered = filterArchStruct(field.Type)
- filtered = filtered || subFiltered
- if field.Type == nil {
- continue
- }
- case reflect.Ptr:
- if field.Type.Elem().Kind() == reflect.Struct {
- nestedType, subFiltered := filterArchStruct(field.Type.Elem())
- filtered = filtered || subFiltered
- if nestedType == nil {
- continue
- }
- field.Type = reflect.PtrTo(nestedType)
- }
- case reflect.Interface:
- panic("Interfaces are not supported in arch_variant properties")
- }
-
- filteredFields = append(filteredFields, field)
- }
-
- return filteredFields, filtered
-}
-
-// filterArchStruct takes a reflect.Type that is either a sturct or a pointer to a struct, and returns a reflect.Type
-// that only contains the fields in the original type that have an `android:"arch_variant"` struct tag, and a bool
-// that is true if the new struct type has fewer fields than the original type. If there are no fields in the
-// original type with the struct tag it returns nil and true.
-func filterArchStruct(prop reflect.Type) (filteredProp reflect.Type, filtered bool) {
- var fields []reflect.StructField
-
- ptr := prop.Kind() == reflect.Ptr
- if ptr {
- prop = prop.Elem()
- }
-
- for i := 0; i < prop.NumField(); i++ {
- fields = append(fields, prop.Field(i))
- }
-
- filteredFields, filtered := filterArchStructFields(fields)
-
- if len(filteredFields) == 0 {
- return nil, true
- }
-
- if !filtered {
- if ptr {
- return reflect.PtrTo(prop), false
- }
- return prop, false
- }
-
- ret := reflect.StructOf(filteredFields)
- if ptr {
- ret = reflect.PtrTo(ret)
- }
-
- return ret, true
-}
-
-// filterArchStruct takes a reflect.Type that is either a sturct or a pointer to a struct, and returns a list of
-// reflect.Type that only contains the fields in the original type that have an `android:"arch_variant"` struct tag,
-// and a bool that is true if the new struct type has fewer fields than the original type. If there are no fields in
-// the original type with the struct tag it returns nil and true. Each returned struct type will have a maximum of
-// 10 top level fields in it to attempt to avoid hitting the reflect.StructOf name length limit, although the limit
-// can still be reached with a single struct field with many fields in it.
-func filterArchStructSharded(prop reflect.Type) (filteredProp []reflect.Type, filtered bool) {
- var fields []reflect.StructField
-
- ptr := prop.Kind() == reflect.Ptr
- if ptr {
- prop = prop.Elem()
- }
-
- for i := 0; i < prop.NumField(); i++ {
- fields = append(fields, prop.Field(i))
- }
-
- fields, filtered = filterArchStructFields(fields)
- if !filtered {
- if ptr {
- return []reflect.Type{reflect.PtrTo(prop)}, false
- }
- return []reflect.Type{prop}, false
- }
-
- if len(fields) == 0 {
- return nil, true
- }
-
- shards := shardFields(fields, 10)
-
- for _, shard := range shards {
- s := reflect.StructOf(shard)
- if ptr {
- s = reflect.PtrTo(s)
- }
- filteredProp = append(filteredProp, s)
- }
-
- return filteredProp, true
-}
-
-func shardFields(fields []reflect.StructField, shardSize int) [][]reflect.StructField {
- ret := make([][]reflect.StructField, 0, (len(fields)+shardSize-1)/shardSize)
- for len(fields) > shardSize {
- ret = append(ret, fields[0:shardSize])
- fields = fields[shardSize:]
- }
- if len(fields) > 0 {
- ret = append(ret, fields)
- }
- return ret
-}
-
// createArchType takes a reflect.Type that is either a struct or a pointer to a struct, and returns a list of
// reflect.Type that contains the arch-variant properties inside structs for each architecture, os, target, multilib,
// etc.
func createArchType(props reflect.Type) []reflect.Type {
- propShards, _ := filterArchStructSharded(props)
+ propShards, _ := proptools.FilterPropertyStructSharded(props, filterArchStruct)
if len(propShards) == 0 {
return nil
}
@@ -1096,6 +1010,23 @@
return ret
}
+func filterArchStruct(field reflect.StructField, prefix string) (bool, reflect.StructField) {
+ if proptools.HasTag(field, "android", "arch_variant") {
+ // The arch_variant field isn't necessary past this point
+ // Instead of wasting space, just remove it. Go also has a
+ // 16-bit limit on structure name length. The name is constructed
+ // based on the Go source representation of the structure, so
+ // the tag names count towards that length.
+ //
+ // TODO: handle the uncommon case of other tags being involved
+ if field.Tag == `android:"arch_variant"` {
+ field.Tag = ""
+ }
+ return true, field
+ }
+ return false, field
+}
+
var archPropTypeMap OncePer
func InitArchModule(m Module) {
@@ -1172,6 +1103,100 @@
return ret
}
+// Rewrite the module's properties structs to contain os-specific values.
+func (m *ModuleBase) setOSProperties(ctx BottomUpMutatorContext) {
+ os := m.commonProperties.CompileOS
+
+ for i := range m.generalProperties {
+ genProps := m.generalProperties[i]
+ if m.archProperties[i] == nil {
+ continue
+ }
+ for _, archProperties := range m.archProperties[i] {
+ archPropValues := reflect.ValueOf(archProperties).Elem()
+
+ targetProp := archPropValues.FieldByName("Target")
+
+ // Handle host-specific properties in the form:
+ // target: {
+ // host: {
+ // key: value,
+ // },
+ // },
+ if os.Class == Host || os.Class == HostCross {
+ field := "Host"
+ prefix := "target.host"
+ m.appendProperties(ctx, genProps, targetProp, field, prefix)
+ }
+
+ // Handle target OS generalities of the form:
+ // target: {
+ // bionic: {
+ // key: value,
+ // },
+ // }
+ if os.Linux() {
+ field := "Linux"
+ prefix := "target.linux"
+ m.appendProperties(ctx, genProps, targetProp, field, prefix)
+ }
+
+ if os.Bionic() {
+ field := "Bionic"
+ prefix := "target.bionic"
+ m.appendProperties(ctx, genProps, targetProp, field, prefix)
+ }
+
+ // Handle target OS properties in the form:
+ // target: {
+ // linux_glibc: {
+ // key: value,
+ // },
+ // not_windows: {
+ // key: value,
+ // },
+ // android {
+ // key: value,
+ // },
+ // },
+ field := os.Field
+ prefix := "target." + os.Name
+ m.appendProperties(ctx, genProps, targetProp, field, prefix)
+
+ if (os.Class == Host || os.Class == HostCross) && os != Windows {
+ field := "Not_windows"
+ prefix := "target.not_windows"
+ m.appendProperties(ctx, genProps, targetProp, field, prefix)
+ }
+
+ // Handle 64-bit device properties in the form:
+ // target {
+ // android64 {
+ // key: value,
+ // },
+ // android32 {
+ // key: value,
+ // },
+ // },
+ // WARNING: this is probably not what you want to use in your blueprints file, it selects
+ // options for all targets on a device that supports 64-bit binaries, not just the targets
+ // that are being compiled for 64-bit. Its expected use case is binaries like linker and
+ // debuggerd that need to know when they are a 32-bit process running on a 64-bit device
+ if os.Class == Device {
+ if ctx.Config().Android64() {
+ field := "Android64"
+ prefix := "target.android64"
+ m.appendProperties(ctx, genProps, targetProp, field, prefix)
+ } else {
+ field := "Android32"
+ prefix := "target.android32"
+ m.appendProperties(ctx, genProps, targetProp, field, prefix)
+ }
+ }
+ }
+ }
+}
+
// Rewrite the module's properties structs to contain arch-specific values.
func (m *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
arch := m.Arch()
@@ -1189,9 +1214,6 @@
multilibProp := archPropValues.FieldByName("Multilib")
targetProp := archPropValues.FieldByName("Target")
- var field string
- var prefix string
-
// Handle arch-specific properties in the form:
// arch: {
// arm64: {
@@ -1256,68 +1278,32 @@
m.appendProperties(ctx, genProps, multilibProp, field, prefix)
}
- // Handle host-specific properties in the form:
+ // Handle combined OS-feature and arch specific properties in the form:
// target: {
- // host: {
- // key: value,
- // },
- // },
- if os.Class == Host || os.Class == HostCross {
- field = "Host"
- prefix = "target.host"
- m.appendProperties(ctx, genProps, targetProp, field, prefix)
- }
-
- // Handle target OS generalities of the form:
- // target: {
- // bionic: {
- // key: value,
- // },
// bionic_x86: {
// key: value,
// },
// }
- if os.Linux() {
- field = "Linux"
- prefix = "target.linux"
+ if os.Linux() && arch.ArchType != Common {
+ field := "Linux_" + arch.ArchType.Name
+ prefix := "target.linux_" + arch.ArchType.Name
m.appendProperties(ctx, genProps, targetProp, field, prefix)
-
- if arch.ArchType != Common {
- field = "Linux_" + arch.ArchType.Name
- prefix = "target.linux_" + arch.ArchType.Name
- m.appendProperties(ctx, genProps, targetProp, field, prefix)
- }
}
- if os.Bionic() {
- field = "Bionic"
- prefix = "target.bionic"
+ if os.Bionic() && arch.ArchType != Common {
+ field := "Bionic_" + t.Name
+ prefix := "target.bionic_" + t.Name
m.appendProperties(ctx, genProps, targetProp, field, prefix)
-
- if arch.ArchType != Common {
- field = "Bionic_" + t.Name
- prefix = "target.bionic_" + t.Name
- m.appendProperties(ctx, genProps, targetProp, field, prefix)
- }
}
- // Handle target OS properties in the form:
+ // Handle combined OS and arch specific properties in the form:
// target: {
- // linux_glibc: {
- // key: value,
- // },
- // not_windows: {
- // key: value,
- // },
// linux_glibc_x86: {
// key: value,
// },
// linux_glibc_arm: {
// key: value,
// },
- // android {
- // key: value,
- // },
// android_arm {
// key: value,
// },
@@ -1325,46 +1311,23 @@
// key: value,
// },
// },
- field = os.Field
- prefix = "target." + os.Name
- m.appendProperties(ctx, genProps, targetProp, field, prefix)
-
if arch.ArchType != Common {
- field = os.Field + "_" + t.Name
- prefix = "target." + os.Name + "_" + t.Name
+ field := os.Field + "_" + t.Name
+ prefix := "target." + os.Name + "_" + t.Name
m.appendProperties(ctx, genProps, targetProp, field, prefix)
}
- if (os.Class == Host || os.Class == HostCross) && os != Windows {
- field := "Not_windows"
- prefix := "target.not_windows"
- m.appendProperties(ctx, genProps, targetProp, field, prefix)
- }
-
- // Handle 64-bit device properties in the form:
+ // Handle arm on x86 properties in the form:
// target {
- // android64 {
+ // arm_on_x86 {
// key: value,
// },
- // android32 {
+ // arm_on_x86_64 {
// key: value,
// },
// },
- // WARNING: this is probably not what you want to use in your blueprints file, it selects
- // options for all targets on a device that supports 64-bit binaries, not just the targets
- // that are being compiled for 64-bit. Its expected use case is binaries like linker and
- // debuggerd that need to know when they are a 32-bit process running on a 64-bit device
+ // TODO(ccross): is this still necessary with native bridge?
if os.Class == Device {
- if ctx.Config().Android64() {
- field := "Android64"
- prefix := "target.android64"
- m.appendProperties(ctx, genProps, targetProp, field, prefix)
- } else {
- field := "Android32"
- prefix := "target.android32"
- m.appendProperties(ctx, genProps, targetProp, field, prefix)
- }
-
if (arch.ArchType == X86 && (hasArmAbi(arch) ||
hasArmAndroidArch(ctx.Config().Targets[Android]))) ||
(arch.ArchType == Arm &&
@@ -1482,11 +1445,6 @@
addTarget(Android, *variables.DeviceSecondaryArch,
variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant,
variables.DeviceSecondaryAbi, NativeBridgeDisabled, nil, nil)
-
- deviceArches := targets[Android]
- if deviceArches[0].Arch.ArchType.Multilib == deviceArches[1].Arch.ArchType.Multilib {
- deviceArches[1].Arch.Native = false
- }
}
if variables.NativeBridgeArch != nil && *variables.NativeBridgeArch != "" {
@@ -1634,7 +1592,7 @@
if err != nil {
return nil, err
}
- arch.Native = false
+
ret = append(ret, Target{
Os: Android,
Arch: arch,
@@ -1663,7 +1621,6 @@
ArchVariant: stringPtr(archVariant),
CpuVariant: stringPtr(cpuVariant),
Abi: abi,
- Native: true,
}
if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" {
diff --git a/android/arch_test.go b/android/arch_test.go
index 0589e6c..52a6684 100644
--- a/android/arch_test.go
+++ b/android/arch_test.go
@@ -16,7 +16,10 @@
import (
"reflect"
+ "runtime"
"testing"
+
+ "github.com/google/blueprint/proptools"
)
type Named struct {
@@ -219,7 +222,7 @@
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- out, filtered := filterArchStruct(reflect.TypeOf(test.in))
+ out, filtered := proptools.FilterPropertyStruct(reflect.TypeOf(test.in), filterArchStruct)
if filtered != test.filtered {
t.Errorf("expected filtered %v, got %v", test.filtered, filtered)
}
@@ -230,3 +233,139 @@
})
}
}
+
+type archTestModule struct {
+ ModuleBase
+ props struct {
+ Deps []string
+ }
+}
+
+func (m *archTestModule) GenerateAndroidBuildActions(ctx ModuleContext) {
+}
+
+func (m *archTestModule) DepsMutator(ctx BottomUpMutatorContext) {
+ ctx.AddDependency(ctx.Module(), nil, m.props.Deps...)
+}
+
+func archTestModuleFactory() Module {
+ m := &archTestModule{}
+ m.AddProperties(&m.props)
+ InitAndroidArchModule(m, HostAndDeviceSupported, MultilibBoth)
+ return m
+}
+
+func TestArchMutator(t *testing.T) {
+ var buildOSVariants []string
+ var buildOS32Variants []string
+ switch runtime.GOOS {
+ case "linux":
+ buildOSVariants = []string{"linux_glibc_x86_64", "linux_glibc_x86"}
+ buildOS32Variants = []string{"linux_glibc_x86"}
+ case "darwin":
+ buildOSVariants = []string{"darwin_x86_64"}
+ buildOS32Variants = nil
+ }
+
+ bp := `
+ module {
+ name: "foo",
+ }
+
+ module {
+ name: "bar",
+ host_supported: true,
+ }
+
+ module {
+ name: "baz",
+ device_supported: false,
+ }
+
+ module {
+ name: "qux",
+ host_supported: true,
+ compile_multilib: "32",
+ }
+ `
+
+ mockFS := map[string][]byte{
+ "Android.bp": []byte(bp),
+ }
+
+ testCases := []struct {
+ name string
+ config func(Config)
+ fooVariants []string
+ barVariants []string
+ bazVariants []string
+ quxVariants []string
+ }{
+ {
+ name: "normal",
+ config: nil,
+ fooVariants: []string{"android_arm64_armv8-a", "android_arm_armv7-a-neon"},
+ barVariants: append(buildOSVariants, "android_arm64_armv8-a", "android_arm_armv7-a-neon"),
+ bazVariants: nil,
+ quxVariants: append(buildOS32Variants, "android_arm_armv7-a-neon"),
+ },
+ {
+ name: "host-only",
+ config: func(config Config) {
+ config.BuildOSTarget = Target{}
+ config.BuildOSCommonTarget = Target{}
+ config.Targets[Android] = nil
+ },
+ fooVariants: nil,
+ barVariants: buildOSVariants,
+ bazVariants: nil,
+ quxVariants: buildOS32Variants,
+ },
+ }
+
+ enabledVariants := func(ctx *TestContext, name string) []string {
+ var ret []string
+ variants := ctx.ModuleVariantsForTests(name)
+ for _, variant := range variants {
+ m := ctx.ModuleForTests(name, variant)
+ if m.Module().Enabled() {
+ ret = append(ret, variant)
+ }
+ }
+ return ret
+ }
+
+ for _, tt := range testCases {
+ t.Run(tt.name, func(t *testing.T) {
+ ctx := NewTestArchContext()
+ ctx.RegisterModuleType("module", ModuleFactoryAdaptor(archTestModuleFactory))
+ ctx.MockFileSystem(mockFS)
+ ctx.Register()
+ config := TestArchConfig(buildDir, nil)
+ if tt.config != nil {
+ tt.config(config)
+ }
+
+ _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
+ FailIfErrored(t, errs)
+ _, errs = ctx.PrepareBuildActions(config)
+ FailIfErrored(t, errs)
+
+ if g, w := enabledVariants(ctx, "foo"), tt.fooVariants; !reflect.DeepEqual(w, g) {
+ t.Errorf("want foo variants:\n%q\ngot:\n%q\n", w, g)
+ }
+
+ if g, w := enabledVariants(ctx, "bar"), tt.barVariants; !reflect.DeepEqual(w, g) {
+ t.Errorf("want bar variants:\n%q\ngot:\n%q\n", w, g)
+ }
+
+ if g, w := enabledVariants(ctx, "baz"), tt.bazVariants; !reflect.DeepEqual(w, g) {
+ t.Errorf("want baz variants:\n%q\ngot:\n%q\n", w, g)
+ }
+
+ if g, w := enabledVariants(ctx, "qux"), tt.quxVariants; !reflect.DeepEqual(w, g) {
+ t.Errorf("want qux variants:\n%q\ngot:\n%q\n", w, g)
+ }
+ })
+ }
+}
diff --git a/android/config.go b/android/config.go
index d03d38e..e208dcd 100644
--- a/android/config.go
+++ b/android/config.go
@@ -89,9 +89,14 @@
ConfigFileName string
ProductVariablesFileName string
- Targets map[OsType][]Target
- BuildOsVariant string
- BuildOsCommonVariant string
+ Targets map[OsType][]Target
+ BuildOSTarget Target // the Target for tools run on the build machine
+ BuildOSCommonTarget Target // the Target for common (java) tools run on the build machine
+ AndroidCommonTarget Target // the Target for common modules for the Android device
+
+ // multilibConflicts for an ArchType is true if there is earlier configured device architecture with the same
+ // multilib value.
+ multilibConflicts map[ArchType]bool
deviceConfig *deviceConfig
@@ -240,10 +245,10 @@
config := testConfig.config
config.Targets[Android] = []Target{
- {Android, Arch{ArchType: X86_64, ArchVariant: "silvermont", Native: true, Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", ""},
- {Android, Arch{ArchType: X86, ArchVariant: "silvermont", Native: true, Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", ""},
- {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Native: true, Abi: []string{"arm64-v8a"}}, NativeBridgeEnabled, "x86_64", "arm64"},
- {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Native: true, Abi: []string{"armeabi-v7a"}}, NativeBridgeEnabled, "x86", "arm"},
+ {Android, Arch{ArchType: X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", ""},
+ {Android, Arch{ArchType: X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", ""},
+ {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeEnabled, "x86_64", "arm64"},
+ {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeEnabled, "x86", "arm"},
}
return testConfig
@@ -255,7 +260,7 @@
config.Targets = map[OsType][]Target{
Fuchsia: []Target{
- {Fuchsia, Arch{ArchType: Arm64, ArchVariant: "", Native: true}, NativeBridgeDisabled, "", ""},
+ {Fuchsia, Arch{ArchType: Arm64, ArchVariant: ""}, NativeBridgeDisabled, "", ""},
},
BuildOs: []Target{
{BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", ""},
@@ -272,8 +277,8 @@
config.Targets = map[OsType][]Target{
Android: []Target{
- {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Native: true, Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", ""},
- {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Native: true, Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", ""},
+ {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", ""},
+ {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", ""},
},
BuildOs: []Target{
{BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", ""},
@@ -285,8 +290,9 @@
config.Targets[BuildOs] = config.Targets[BuildOs][:1]
}
- config.BuildOsVariant = config.Targets[BuildOs][0].String()
- config.BuildOsCommonVariant = getCommonTargets(config.Targets[BuildOs])[0].String()
+ config.BuildOSTarget = config.Targets[BuildOs][0]
+ config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0]
+ config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
config.TestProductVariables.DeviceArch = proptools.StringPtr("arm64")
config.TestProductVariables.DeviceArchVariant = proptools.StringPtr("armv8-a")
config.TestProductVariables.DeviceSecondaryArch = proptools.StringPtr("arm")
@@ -305,8 +311,9 @@
env: originalEnv,
- srcDir: srcDir,
- buildDir: buildDir,
+ srcDir: srcDir,
+ buildDir: buildDir,
+ multilibConflicts: make(map[ArchType]bool),
}
config.deviceConfig = &deviceConfig{
@@ -360,9 +367,20 @@
targets[Android] = androidTargets
}
+ multilib := make(map[string]bool)
+ for _, target := range targets[Android] {
+ if seen := multilib[target.Arch.ArchType.Multilib]; seen {
+ config.multilibConflicts[target.Arch.ArchType] = true
+ }
+ multilib[target.Arch.ArchType.Multilib] = true
+ }
+
config.Targets = targets
- config.BuildOsVariant = targets[BuildOs][0].String()
- config.BuildOsCommonVariant = getCommonTargets(targets[BuildOs])[0].String()
+ config.BuildOSTarget = config.Targets[BuildOs][0]
+ config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0]
+ if len(config.Targets[Android]) > 0 {
+ config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
+ }
if err := config.fromEnv(); err != nil {
return Config{}, err
@@ -373,13 +391,14 @@
func (c *config) fromEnv() error {
switch c.Getenv("EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9") {
- case "":
- // Nothing, this is the default
- case "true":
- // Use -source 9 -target 9
+ case "", "true":
+ // Use -source 9 -target 9. This is the default.
c.targetOpenJDK9 = true
+ case "false":
+ // Use -source 8 -target 8. This is the legacy behaviour.
+ c.targetOpenJDK9 = false
default:
- return fmt.Errorf(`Invalid value for EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9, should be "" or "true"`)
+ return fmt.Errorf(`Invalid value for EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9, should be "", "true", or "false"`)
}
return nil
@@ -852,6 +871,10 @@
return Bool(c.productVariables.VndkSnapshotBuildArtifacts)
}
+func (c *config) HasMultilibConflict(arch ArchType) bool {
+ return c.multilibConflicts[arch]
+}
+
func (c *deviceConfig) Arches() []Arch {
var arches []Arch
for _, target := range c.config.Targets[Android] {
@@ -1009,19 +1032,6 @@
return "", false
}
-// SecondArchIsTranslated returns true if the primary device arch is X86 or X86_64 and the device also has an arch
-// that is Arm or Arm64.
-func (c *config) SecondArchIsTranslated() bool {
- deviceTargets := c.Targets[Android]
- if len(deviceTargets) < 2 {
- return false
- }
-
- arch := deviceTargets[0].Arch
-
- return (arch.ArchType == X86 || arch.ArchType == X86_64) && hasArmAndroidArch(deviceTargets)
-}
-
func (c *config) IntegerOverflowDisabledForPath(path string) bool {
if c.productVariables.IntegerOverflowExcludePaths == nil {
return false
diff --git a/android/hooks.go b/android/hooks.go
index 64ffd52..604cb9c 100644
--- a/android/hooks.go
+++ b/android/hooks.go
@@ -30,7 +30,7 @@
BaseModuleContext
AppendProperties(...interface{})
PrependProperties(...interface{})
- CreateModule(ModuleFactory, ...interface{})
+ CreateModule(ModuleFactory, ...interface{}) Module
}
// Arch hooks are run after the module has been split into architecture variants, and can be used
@@ -75,7 +75,7 @@
type InstallHookContext interface {
ModuleContext
- Path() OutputPath
+ Path() InstallPath
Symlink() bool
}
@@ -89,11 +89,11 @@
type installHookContext struct {
ModuleContext
- path OutputPath
+ path InstallPath
symlink bool
}
-func (x *installHookContext) Path() OutputPath {
+func (x *installHookContext) Path() InstallPath {
return x.path
}
@@ -101,7 +101,7 @@
return x.symlink
}
-func (x *hooks) runInstallHooks(ctx ModuleContext, path OutputPath, symlink bool) {
+func (x *hooks) runInstallHooks(ctx ModuleContext, path InstallPath, symlink bool) {
if len(x.install) > 0 {
mctx := &installHookContext{
ModuleContext: ctx,
diff --git a/android/module.go b/android/module.go
index a1a01a5..70b602b 100644
--- a/android/module.go
+++ b/android/module.go
@@ -147,16 +147,17 @@
ExpandSource(srcFile, prop string) Path
ExpandOptionalSource(srcFile *string, prop string) OptionalPath
- InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
- InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
- InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath
- InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath
+ InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
+ InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
+ InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
+ InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
CheckbuildFile(srcPath Path)
InstallInData() bool
InstallInTestcases() bool
InstallInSanitizerDir() bool
InstallInRecovery() bool
+ InstallInRoot() bool
InstallBypassMake() bool
RequiredModuleNames() []string
@@ -196,6 +197,7 @@
InstallInTestcases() bool
InstallInSanitizerDir() bool
InstallInRecovery() bool
+ InstallInRoot() bool
InstallBypassMake() bool
SkipInstall()
ExportedToMake() bool
@@ -415,6 +417,7 @@
} `android:"arch_variant"`
// Set by TargetMutator
+ CompileOS OsType `blueprint:"mutated"`
CompileTarget Target `blueprint:"mutated"`
CompileMultiTargets []Target `blueprint:"mutated"`
CompilePrimary bool `blueprint:"mutated"`
@@ -512,8 +515,19 @@
m.AddProperties(
&base.nameProperties,
- &base.commonProperties,
- &base.variableProperties)
+ &base.commonProperties)
+
+ // Allow tests to override the default product variables
+ if base.variableProperties == nil {
+ base.variableProperties = zeroProductVariables
+ }
+
+ // Filter the product variables properties to the ones that exist on this module
+ base.variableProperties = createVariableProperties(m.GetProperties(), base.variableProperties)
+ if base.variableProperties != nil {
+ m.AddProperties(base.variableProperties)
+ }
+
base.generalProperties = m.GetProperties()
base.customizableProperties = m.GetProperties()
@@ -595,7 +609,7 @@
nameProperties nameProperties
commonProperties commonProperties
- variableProperties variableProperties
+ variableProperties interface{}
hostAndDeviceProperties hostAndDeviceProperties
generalProperties []interface{}
archProperties [][]interface{}
@@ -706,12 +720,6 @@
}
}
-func (m *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
- m.commonProperties.CompileTarget = target
- m.commonProperties.CompileMultiTargets = multiTargets
- m.commonProperties.CompilePrimary = primary
-}
-
func (m *ModuleBase) Target() Target {
return m.commonProperties.CompileTarget
}
@@ -846,6 +854,10 @@
return Bool(m.commonProperties.Recovery)
}
+func (m *ModuleBase) InstallInRoot() bool {
+ return false
+}
+
func (m *ModuleBase) InstallBypassMake() bool {
return false
}
@@ -1183,6 +1195,12 @@
func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
argNames ...string) blueprint.Rule {
+ if m.config.UseGoma() && params.Pool == nil {
+ // When USE_GOMA=true is set and the rule is not supported by goma, restrict jobs to the
+ // local parallelism value
+ params.Pool = localPool
+ }
+
rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
if m.config.captureBuild {
@@ -1522,11 +1540,15 @@
return m.module.InstallInRecovery()
}
+func (m *moduleContext) InstallInRoot() bool {
+ return m.module.InstallInRoot()
+}
+
func (m *moduleContext) InstallBypassMake() bool {
return m.module.InstallBypassMake()
}
-func (m *moduleContext) skipInstall(fullInstallPath OutputPath) bool {
+func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool {
if m.module.base().commonProperties.SkipInstall {
return true
}
@@ -1551,18 +1573,18 @@
return false
}
-func (m *moduleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
- deps ...Path) OutputPath {
+func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
+ deps ...Path) InstallPath {
return m.installFile(installPath, name, srcPath, Cp, deps)
}
-func (m *moduleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
- deps ...Path) OutputPath {
+func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
+ deps ...Path) InstallPath {
return m.installFile(installPath, name, srcPath, CpExecutable, deps)
}
-func (m *moduleContext) installFile(installPath OutputPath, name string, srcPath Path,
- rule blueprint.Rule, deps []Path) OutputPath {
+func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path,
+ rule blueprint.Rule, deps []Path) InstallPath {
fullInstallPath := installPath.Join(m, name)
m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
@@ -1597,7 +1619,7 @@
return fullInstallPath
}
-func (m *moduleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
+func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
fullInstallPath := installPath.Join(m, name)
m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
@@ -1626,7 +1648,7 @@
// installPath/name -> absPath where absPath might be a path that is available only at runtime
// (e.g. /apex/...)
-func (m *moduleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
+func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
fullInstallPath := installPath.Join(m, name)
m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
diff --git a/android/mutator.go b/android/mutator.go
index 7b7859c..4a5338f 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -15,6 +15,8 @@
package android
import (
+ "reflect"
+
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
@@ -84,6 +86,7 @@
}
func registerArchMutator(ctx RegisterMutatorsContext) {
+ ctx.BottomUp("os", osMutator).Parallel()
ctx.BottomUp("arch", archMutator).Parallel()
ctx.TopDown("arch_hooks", archHookMutator).Parallel()
}
@@ -121,7 +124,7 @@
Rename(name string)
- CreateModule(ModuleFactory, ...interface{})
+ CreateModule(ModuleFactory, ...interface{}) Module
}
type topDownMutatorContext struct {
@@ -243,9 +246,25 @@
t.Module().base().commonProperties.DebugName = name
}
-func (t *topDownMutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) {
- inherited := []interface{}{&t.Module().base().commonProperties, &t.Module().base().variableProperties}
- t.bp.CreateModule(ModuleFactoryAdaptor(factory), append(inherited, props...)...)
+func (t *topDownMutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
+ inherited := []interface{}{&t.Module().base().commonProperties}
+ module := t.bp.CreateModule(ModuleFactoryAdaptor(factory), append(inherited, props...)...).(Module)
+
+ if t.Module().base().variableProperties != nil && module.base().variableProperties != nil {
+ src := t.Module().base().variableProperties
+ dst := []interface{}{
+ module.base().variableProperties,
+ // Put an empty copy of the src properties into dst so that properties in src that are not in dst
+ // don't cause a "failed to find property to extend" error.
+ proptools.CloneEmptyProperties(reflect.ValueOf(src).Elem()).Interface(),
+ }
+ err := proptools.AppendMatchingProperties(dst, src, nil)
+ if err != nil {
+ panic(err)
+ }
+ }
+
+ return module
}
func (b *bottomUpMutatorContext) MutatorName() string {
diff --git a/android/notices.go b/android/notices.go
index 7b61d65..bf273b5 100644
--- a/android/notices.go
+++ b/android/notices.go
@@ -60,7 +60,7 @@
})
}
-func BuildNoticeOutput(ctx ModuleContext, installPath OutputPath, installFilename string,
+func BuildNoticeOutput(ctx ModuleContext, installPath InstallPath, installFilename string,
noticePaths []Path) NoticeOutputs {
// Merge all NOTICE files into one.
// TODO(jungjw): We should just produce a well-formatted NOTICE.html file in a single pass.
diff --git a/android/package_ctx.go b/android/package_ctx.go
index 00b99ff..548450e 100644
--- a/android/package_ctx.go
+++ b/android/package_ctx.go
@@ -104,7 +104,8 @@
}
// RuleFunc wraps blueprint.PackageContext.RuleFunc, converting the interface{} config
-// argument to a Context that supports Config().
+// argument to a Context that supports Config(), and provides a default Pool if none is
+// specified.
func (p PackageContext) RuleFunc(name string,
f func(PackageRuleContext) blueprint.RuleParams, argNames ...string) blueprint.Rule {
@@ -114,6 +115,11 @@
if len(ctx.errors) > 0 {
return params, ctx.errors[0]
}
+ if ctx.Config().UseGoma() && params.Pool == nil {
+ // When USE_GOMA=true is set and the rule is not supported by goma, restrict jobs to the
+ // local parallelism value
+ params.Pool = localPool
+ }
return params, nil
}, argNames...)
}
@@ -234,10 +240,16 @@
})
}
-// AndroidStaticRule wraps blueprint.StaticRule and provides a default Pool if none is specified
+// AndroidStaticRule is an alias for StaticRule.
func (p PackageContext) AndroidStaticRule(name string, params blueprint.RuleParams,
argNames ...string) blueprint.Rule {
- return p.AndroidRuleFunc(name, func(PackageRuleContext) blueprint.RuleParams {
+ return p.StaticRule(name, params, argNames...)
+}
+
+// StaticRule wraps blueprint.StaticRule and provides a default Pool if none is specified.
+func (p PackageContext) StaticRule(name string, params blueprint.RuleParams,
+ argNames ...string) blueprint.Rule {
+ return p.RuleFunc(name, func(PackageRuleContext) blueprint.RuleParams {
return params
}, argNames...)
}
@@ -245,18 +257,6 @@
// AndroidGomaStaticRule wraps blueprint.StaticRule but uses goma's parallelism if goma is enabled
func (p PackageContext) AndroidGomaStaticRule(name string, params blueprint.RuleParams,
argNames ...string) blueprint.Rule {
- return p.StaticRule(name, params, argNames...)
-}
-
-func (p PackageContext) AndroidRuleFunc(name string,
- f func(PackageRuleContext) blueprint.RuleParams, argNames ...string) blueprint.Rule {
- return p.RuleFunc(name, func(ctx PackageRuleContext) blueprint.RuleParams {
- params := f(ctx)
- if ctx.Config().UseGoma() && params.Pool == nil {
- // When USE_GOMA=true is set and the rule is not supported by goma, restrict jobs to the
- // local parallelism value
- params.Pool = localPool
- }
- return params
- }, argNames...)
+ // bypass android.PackageContext.StaticRule so that Pool does not get set to local_pool.
+ return p.PackageContext.StaticRule(name, params, argNames...)
}
diff --git a/android/paths.go b/android/paths.go
index 8bd2c61..8dbb086 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -47,6 +47,7 @@
InstallInTestcases() bool
InstallInSanitizerDir() bool
InstallInRecovery() bool
+ InstallInRoot() bool
InstallBypassMake() bool
}
@@ -792,7 +793,7 @@
return OptionalPathForPath(PathForSource(ctx, relPath))
}
-// OutputPath is a Path representing a file path rooted from the build directory
+// OutputPath is a Path representing an intermediates file path rooted from the build directory
type OutputPath struct {
basePath
}
@@ -820,17 +821,6 @@
return OutputPath{basePath{path, ctx.Config(), ""}}
}
-// pathForInstallInMakeDir is used by PathForModuleInstall when the module returns true
-// for InstallBypassMake to produce an OutputPath that installs to $OUT_DIR instead of
-// $OUT_DIR/soong.
-func pathForInstallInMakeDir(ctx PathContext, pathComponents ...string) OutputPath {
- path, err := validatePath(pathComponents...)
- if err != nil {
- reportPathError(ctx, err)
- }
- return OutputPath{basePath{"../" + path, ctx.Config(), ""}}
-}
-
// PathsForOutput returns Paths rooted from buildDir
func PathsForOutput(ctx PathContext, paths []string) WritablePaths {
ret := make(WritablePaths, len(paths))
@@ -846,10 +836,6 @@
return filepath.Join(p.config.buildDir, p.path)
}
-func (p OutputPath) RelPathString() string {
- return p.path
-}
-
// Join creates a new OutputPath with paths... joined with the current path. The
// provided paths... may not use '..' to escape from the current path.
func (p OutputPath) Join(ctx PathContext, paths ...string) OutputPath {
@@ -1118,9 +1104,44 @@
return ModuleResPath{PathForModuleOut(ctx, "res", p)}
}
+// InstallPath is a Path representing a installed file path rooted from the build directory
+type InstallPath struct {
+ basePath
+
+ baseDir string // "../" for Make paths to convert "out/soong" to "out", "" for Soong paths
+}
+
+func (p InstallPath) writablePath() {}
+
+func (p InstallPath) String() string {
+ return filepath.Join(p.config.buildDir, p.baseDir, p.path)
+}
+
+// Join creates a new InstallPath with paths... joined with the current path. The
+// provided paths... may not use '..' to escape from the current path.
+func (p InstallPath) Join(ctx PathContext, paths ...string) InstallPath {
+ path, err := validatePath(paths...)
+ if err != nil {
+ reportPathError(ctx, err)
+ }
+ return p.withRel(path)
+}
+
+func (p InstallPath) withRel(rel string) InstallPath {
+ p.basePath = p.basePath.withRel(rel)
+ return p
+}
+
+// ToMakePath returns a new InstallPath that points to Make's install directory instead of Soong's,
+// i.e. out/ instead of out/soong/.
+func (p InstallPath) ToMakePath() InstallPath {
+ p.baseDir = "../"
+ return p
+}
+
// PathForModuleInstall returns a Path representing the install path for the
// module appended with paths...
-func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string) OutputPath {
+func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string) InstallPath {
var outPaths []string
if ctx.Device() {
partition := modulePartition(ctx)
@@ -1140,13 +1161,30 @@
outPaths = append([]string{"debug"}, outPaths...)
}
outPaths = append(outPaths, pathComponents...)
- if ctx.InstallBypassMake() && ctx.Config().EmbeddedInMake() {
- return pathForInstallInMakeDir(ctx, outPaths...)
+
+ path, err := validatePath(outPaths...)
+ if err != nil {
+ reportPathError(ctx, err)
}
- return PathForOutput(ctx, outPaths...)
+
+ ret := InstallPath{basePath{path, ctx.Config(), ""}, ""}
+ if ctx.InstallBypassMake() && ctx.Config().EmbeddedInMake() {
+ ret = ret.ToMakePath()
+ }
+
+ return ret
}
-func InstallPathToOnDevicePath(ctx PathContext, path OutputPath) string {
+func PathForNdkInstall(ctx PathContext, paths ...string) InstallPath {
+ paths = append([]string{"ndk"}, paths...)
+ path, err := validatePath(paths...)
+ if err != nil {
+ reportPathError(ctx, err)
+ }
+ return InstallPath{basePath{path, ctx.Config(), ""}, ""}
+}
+
+func InstallPathToOnDevicePath(ctx PathContext, path InstallPath) string {
rel := Rel(ctx, PathForOutput(ctx, "target", "product", ctx.Config().DeviceName()).String(), path.String())
return "/" + rel
@@ -1159,8 +1197,12 @@
} else if ctx.InstallInTestcases() {
partition = "testcases"
} else if ctx.InstallInRecovery() {
- // the layout of recovery partion is the same as that of system partition
- partition = "recovery/root/system"
+ if ctx.InstallInRoot() {
+ partition = "recovery/root"
+ } else {
+ // the layout of recovery partion is the same as that of system partition
+ partition = "recovery/root/system"
+ }
} else if ctx.SocSpecific() {
partition = ctx.DeviceConfig().VendorPath()
} else if ctx.DeviceSpecific() {
@@ -1169,6 +1211,8 @@
partition = ctx.DeviceConfig().ProductPath()
} else if ctx.SystemExtSpecific() {
partition = ctx.DeviceConfig().SystemExtPath()
+ } else if ctx.InstallInRoot() {
+ partition = "root"
} else {
partition = "system"
}
diff --git a/android/paths_test.go b/android/paths_test.go
index b66eb1e..2e67272 100644
--- a/android/paths_test.go
+++ b/android/paths_test.go
@@ -204,6 +204,7 @@
inTestcases bool
inSanitizerDir bool
inRecovery bool
+ inRoot bool
}
func (moduleInstallPathContextImpl) Fs() pathtools.FileSystem {
@@ -232,6 +233,10 @@
return m.inRecovery
}
+func (m moduleInstallPathContextImpl) InstallInRoot() bool {
+ return m.inRoot
+}
+
func (m moduleInstallPathContextImpl) InstallBypassMake() bool {
return false
}
@@ -313,6 +318,40 @@
in: []string{"bin", "my_test"},
out: "target/product/test_device/system_ext/bin/my_test",
},
+ {
+ name: "root binary",
+ ctx: &moduleInstallPathContextImpl{
+ baseModuleContext: baseModuleContext{
+ target: deviceTarget,
+ },
+ inRoot: true,
+ },
+ in: []string{"my_test"},
+ out: "target/product/test_device/root/my_test",
+ },
+ {
+ name: "recovery binary",
+ ctx: &moduleInstallPathContextImpl{
+ baseModuleContext: baseModuleContext{
+ target: deviceTarget,
+ },
+ inRecovery: true,
+ },
+ in: []string{"bin/my_test"},
+ out: "target/product/test_device/recovery/root/system/bin/my_test",
+ },
+ {
+ name: "recovery root binary",
+ ctx: &moduleInstallPathContextImpl{
+ baseModuleContext: baseModuleContext{
+ target: deviceTarget,
+ },
+ inRecovery: true,
+ inRoot: true,
+ },
+ in: []string{"my_test"},
+ out: "target/product/test_device/recovery/root/my_test",
+ },
{
name: "system native test binary",
diff --git a/android/prebuilt_etc.go b/android/prebuilt_etc.go
index d29ed16..6c4813b 100644
--- a/android/prebuilt_etc.go
+++ b/android/prebuilt_etc.go
@@ -65,7 +65,7 @@
installDirBase string
// The base install location when soc_specific property is set to true, e.g. "firmware" for prebuilt_firmware.
socInstallDirBase string
- installDirPath OutputPath
+ installDirPath InstallPath
additionalDependencies *Paths
}
@@ -91,7 +91,7 @@
return PathForModuleSrc(ctx, String(p.properties.Src))
}
-func (p *PrebuiltEtc) InstallDirPath() OutputPath {
+func (p *PrebuiltEtc) InstallDirPath() InstallPath {
return p.installDirPath
}
@@ -158,7 +158,7 @@
ExtraEntries: []AndroidMkExtraEntriesFunc{
func(entries *AndroidMkEntries) {
entries.SetString("LOCAL_MODULE_TAGS", "optional")
- entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString())
+ entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String())
entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
entries.SetString("LOCAL_UNINSTALLABLE_MODULE", strconv.FormatBool(!p.Installable()))
if p.additionalDependencies != nil {
diff --git a/android/prebuilt_etc_test.go b/android/prebuilt_etc_test.go
index 0a2c7a4..f675ea3 100644
--- a/android/prebuilt_etc_test.go
+++ b/android/prebuilt_etc_test.go
@@ -182,9 +182,9 @@
`)
p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a_core").Module().(*PrebuiltEtc)
- expected := "target/product/test_device/system/usr/share/bar"
- if p.installDirPath.RelPathString() != expected {
- t.Errorf("expected %q, got %q", expected, p.installDirPath.RelPathString())
+ expected := buildDir + "/target/product/test_device/system/usr/share/bar"
+ if p.installDirPath.String() != expected {
+ t.Errorf("expected %q, got %q", expected, p.installDirPath.String())
}
}
@@ -199,9 +199,9 @@
buildOS := BuildOs.String()
p := ctx.ModuleForTests("foo.conf", buildOS+"_common").Module().(*PrebuiltEtc)
- expected := filepath.Join("host", config.PrebuiltOS(), "usr", "share", "bar")
- if p.installDirPath.RelPathString() != expected {
- t.Errorf("expected %q, got %q", expected, p.installDirPath.RelPathString())
+ expected := filepath.Join(buildDir, "host", config.PrebuiltOS(), "usr", "share", "bar")
+ if p.installDirPath.String() != expected {
+ t.Errorf("expected %q, got %q", expected, p.installDirPath.String())
}
}
@@ -214,14 +214,14 @@
`)
p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a_core").Module().(*PrebuiltEtc)
- expected := "target/product/test_device/system/fonts"
- if p.installDirPath.RelPathString() != expected {
- t.Errorf("expected %q, got %q", expected, p.installDirPath.RelPathString())
+ expected := buildDir + "/target/product/test_device/system/fonts"
+ if p.installDirPath.String() != expected {
+ t.Errorf("expected %q, got %q", expected, p.installDirPath.String())
}
}
func TestPrebuiltFirmwareDirPath(t *testing.T) {
- targetPath := "target/product/test_device"
+ targetPath := buildDir + "/target/product/test_device"
tests := []struct {
description string
config string
@@ -249,7 +249,7 @@
t.Run(tt.description, func(t *testing.T) {
ctx, _ := testPrebuiltEtc(t, tt.config)
p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a_core").Module().(*PrebuiltEtc)
- if p.installDirPath.RelPathString() != tt.expectedPath {
+ if p.installDirPath.String() != tt.expectedPath {
t.Errorf("expected %q, got %q", tt.expectedPath, p.installDirPath)
}
})
diff --git a/android/proto.go b/android/proto.go
index c8ade45..b712258 100644
--- a/android/proto.go
+++ b/android/proto.go
@@ -52,9 +52,8 @@
}
if plugin := String(p.Proto.Plugin); plugin != "" {
- ctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: ctx.Config().BuildOsVariant},
- }, ProtoPluginDepTag, "protoc-gen-"+plugin)
+ ctx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(),
+ ProtoPluginDepTag, "protoc-gen-"+plugin)
}
}
diff --git a/android/sdk.go b/android/sdk.go
index 52c392f..8e1e106 100644
--- a/android/sdk.go
+++ b/android/sdk.go
@@ -39,25 +39,28 @@
Version string
}
-const (
- // currentVersion refers to the in-development version of an SDK
- currentVersion = "current"
-)
-
-// IsCurrentVersion determines if the SdkRef is referencing to an in-development version of an SDK
-func (s SdkRef) IsCurrentVersion() bool {
- return s.Version == currentVersion
+// Unversioned determines if the SdkRef is referencing to the unversioned SDK module
+func (s SdkRef) Unversioned() bool {
+ return s.Version == ""
}
-// IsCurrentVersionOf determines if the SdkRef is referencing to an in-development version of the
-// specified SDK
-func (s SdkRef) IsCurrentVersionOf(name string) bool {
- return s.Name == name && s.IsCurrentVersion()
+// String returns string representation of this SdkRef for debugging purpose
+func (s SdkRef) String() string {
+ if s.Name == "" {
+ return "(No Sdk)"
+ }
+ if s.Unversioned() {
+ return s.Name
+ }
+ return s.Name + string(SdkVersionSeparator) + s.Version
}
-// ParseSdkRef parses a `name#version` style string into a corresponding SdkRef struct
+// SdkVersionSeparator is a character used to separate an sdk name and its version
+const SdkVersionSeparator = '@'
+
+// ParseSdkRef parses a `name@version` style string into a corresponding SdkRef struct
func ParseSdkRef(ctx BaseModuleContext, str string, property string) SdkRef {
- tokens := strings.Split(str, "#")
+ tokens := strings.Split(str, string(SdkVersionSeparator))
if len(tokens) < 1 || len(tokens) > 2 {
ctx.PropertyErrorf(property, "%q does not follow name#version syntax", str)
return SdkRef{Name: "invalid sdk name", Version: "invalid sdk version"}
@@ -65,7 +68,7 @@
name := tokens[0]
- version := currentVersion // If version is omitted, defaults to "current"
+ var version string
if len(tokens) == 2 {
version = tokens[1]
}
@@ -75,6 +78,7 @@
type SdkRefs []SdkRef
+// Contains tells if the given SdkRef is in this list of SdkRef's
func (refs SdkRefs) Contains(s SdkRef) bool {
for _, r := range refs {
if r == s {
@@ -105,7 +109,7 @@
return s
}
-// MakeMemberof sets this module to be a member of a specific SDK
+// MakeMemberOf sets this module to be a member of a specific SDK
func (s *SdkBase) MakeMemberOf(sdk SdkRef) {
s.properties.ContainingSdk = &sdk
}
@@ -120,10 +124,10 @@
if s.properties.ContainingSdk != nil {
return *s.properties.ContainingSdk
}
- return SdkRef{Name: "", Version: currentVersion}
+ return SdkRef{Name: "", Version: ""}
}
-// Membername returns the name of the module that this SDK member is overriding
+// MemberName returns the name of the module that this SDK member is overriding
func (s *SdkBase) MemberName() string {
return proptools.String(s.properties.Sdk_member_name)
}
diff --git a/android/sh_binary.go b/android/sh_binary.go
index ba0c8be..6db9892 100644
--- a/android/sh_binary.go
+++ b/android/sh_binary.go
@@ -48,6 +48,9 @@
// Whether this module is directly installable to one of the partitions. Default: true.
Installable *bool
+
+ // install symlinks to the binary
+ Symlinks []string `android:"arch_variant"`
}
type TestProperties struct {
@@ -103,6 +106,10 @@
return s.properties.Installable == nil || Bool(s.properties.Installable)
}
+func (s *ShBinary) Symlinks() []string {
+ return s.properties.Symlinks
+}
+
func (s *ShBinary) GenerateAndroidBuildActions(ctx ModuleContext) {
s.sourceFilePath = PathForModuleSrc(ctx, String(s.properties.Src))
filename := String(s.properties.Filename)
@@ -145,6 +152,9 @@
entries.SetString("LOCAL_MODULE_RELATIVE_PATH", String(s.properties.Sub_dir))
entries.SetString("LOCAL_MODULE_SUFFIX", "")
entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel())
+ if len(s.properties.Symlinks) > 0 {
+ entries.SetString("LOCAL_MODULE_SYMLINKS", strings.Join(s.properties.Symlinks, " "))
+ }
}
func (s *ShTest) GenerateAndroidBuildActions(ctx ModuleContext) {
diff --git a/android/singleton.go b/android/singleton.go
index a59d54a..33bc6d1 100644
--- a/android/singleton.go
+++ b/android/singleton.go
@@ -52,6 +52,10 @@
VisitAllModulesBlueprint(visit func(blueprint.Module))
VisitAllModules(visit func(Module))
VisitAllModulesIf(pred func(Module) bool, visit func(Module))
+
+ VisitDirectDeps(module Module, visit func(Module))
+ VisitDirectDepsIf(module Module, pred func(Module) bool, visit func(Module))
+
// Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
VisitDepsDepthFirst(module Module, visit func(Module))
// Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
@@ -127,6 +131,11 @@
}
func (s *singletonContextAdaptor) Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule {
+ if s.Config().UseGoma() && params.Pool == nil {
+ // When USE_GOMA=true is set and the rule is not supported by goma, restrict jobs to the
+ // local parallelism value
+ params.Pool = localPool
+ }
rule := s.SingletonContext.Rule(pctx.PackageContext, name, params, argNames...)
if s.Config().captureBuild {
s.ruleParams[rule] = params
@@ -187,6 +196,14 @@
s.SingletonContext.VisitAllModulesIf(predAdaptor(pred), visitAdaptor(visit))
}
+func (s *singletonContextAdaptor) VisitDirectDeps(module Module, visit func(Module)) {
+ s.SingletonContext.VisitDirectDeps(module, visitAdaptor(visit))
+}
+
+func (s *singletonContextAdaptor) VisitDirectDepsIf(module Module, pred func(Module) bool, visit func(Module)) {
+ s.SingletonContext.VisitDirectDepsIf(module, predAdaptor(pred), visitAdaptor(visit))
+}
+
func (s *singletonContextAdaptor) VisitDepsDepthFirst(module Module, visit func(Module)) {
s.SingletonContext.VisitDepsDepthFirst(module, visitAdaptor(visit))
}
diff --git a/android/variable.go b/android/variable.go
index 3f2b9e9..41943b0 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -122,7 +122,7 @@
} `android:"arch_variant"`
}
-var zeroProductVariables variableProperties
+var zeroProductVariables interface{} = variableProperties{}
type productVariables struct {
// Suffix to add to generated Makefiles
@@ -366,8 +366,13 @@
// TODO: depend on config variable, create variants, propagate variants up tree
a := module.base()
- variableValues := reflect.ValueOf(&a.variableProperties.Product_variables).Elem()
- zeroValues := reflect.ValueOf(zeroProductVariables.Product_variables)
+
+ if a.variableProperties == nil {
+ return
+ }
+
+ variableValues := reflect.ValueOf(a.variableProperties).Elem().FieldByName("Product_variables")
+ zeroValues := reflect.ValueOf(zeroProductVariables).FieldByName("Product_variables")
for i := 0; i < variableValues.NumField(); i++ {
variableValue := variableValues.Field(i)
@@ -496,3 +501,106 @@
return nil
}
+
+var variablePropTypeMap OncePer
+
+// sliceToTypeArray takes a slice of property structs and returns a reflection created array containing the
+// reflect.Types of each property struct. The result can be used as a key in a map.
+func sliceToTypeArray(s []interface{}) interface{} {
+ // Create an array using reflection whose length is the length of the input slice
+ ret := reflect.New(reflect.ArrayOf(len(s), reflect.TypeOf(reflect.TypeOf(0)))).Elem()
+ for i, e := range s {
+ ret.Index(i).Set(reflect.ValueOf(reflect.TypeOf(e)))
+ }
+ return ret.Interface()
+}
+
+// createVariableProperties takes the list of property structs for a module and returns a property struct that
+// contains the product variable properties that exist in the property structs, or nil if there are none. It
+// caches the result.
+func createVariableProperties(moduleTypeProps []interface{}, productVariables interface{}) interface{} {
+ // Convert the moduleTypeProps to an array of reflect.Types that can be used as a key in the OncePer.
+ key := sliceToTypeArray(moduleTypeProps)
+
+ // Use the variablePropTypeMap OncePer to cache the result for each set of property struct types.
+ typ, _ := variablePropTypeMap.Once(NewCustomOnceKey(key), func() interface{} {
+ // Compute the filtered property struct type.
+ return createVariablePropertiesType(moduleTypeProps, productVariables)
+ }).(reflect.Type)
+
+ if typ == nil {
+ return nil
+ }
+
+ // Create a new pointer to a filtered property struct.
+ return reflect.New(typ).Interface()
+}
+
+// createVariablePropertiesType creates a new type that contains only the product variable properties that exist in
+// a list of property structs.
+func createVariablePropertiesType(moduleTypeProps []interface{}, productVariables interface{}) reflect.Type {
+ typ, _ := proptools.FilterPropertyStruct(reflect.TypeOf(productVariables),
+ func(field reflect.StructField, prefix string) (bool, reflect.StructField) {
+ // Filter function, returns true if the field should be in the resulting struct
+ if prefix == "" {
+ // Keep the top level Product_variables field
+ return true, field
+ }
+ _, rest := splitPrefix(prefix)
+ if rest == "" {
+ // Keep the 2nd level field (i.e. Product_variables.Eng)
+ return true, field
+ }
+
+ // Strip off the first 2 levels of the prefix
+ _, prefix = splitPrefix(rest)
+
+ for _, p := range moduleTypeProps {
+ if fieldExistsByNameRecursive(reflect.TypeOf(p).Elem(), prefix, field.Name) {
+ // Keep any fields that exist in one of the property structs
+ return true, field
+ }
+ }
+
+ return false, field
+ })
+ return typ
+}
+
+func splitPrefix(prefix string) (first, rest string) {
+ index := strings.IndexByte(prefix, '.')
+ if index == -1 {
+ return prefix, ""
+ }
+ return prefix[:index], prefix[index+1:]
+}
+
+func fieldExistsByNameRecursive(t reflect.Type, prefix, name string) bool {
+ if t.Kind() != reflect.Struct {
+ panic(fmt.Errorf("fieldExistsByNameRecursive can only be called on a reflect.Struct"))
+ }
+
+ if prefix != "" {
+ split := strings.SplitN(prefix, ".", 2)
+ firstPrefix := split[0]
+ rest := ""
+ if len(split) > 1 {
+ rest = split[1]
+ }
+ f, exists := t.FieldByName(firstPrefix)
+ if !exists {
+ return false
+ }
+ ft := f.Type
+ if ft.Kind() == reflect.Ptr {
+ ft = ft.Elem()
+ }
+ if ft.Kind() != reflect.Struct {
+ panic(fmt.Errorf("field %q in %q is not a struct", firstPrefix, t))
+ }
+ return fieldExistsByNameRecursive(ft, rest, name)
+ } else {
+ _, exists := t.FieldByName(name)
+ return exists
+ }
+}
diff --git a/android/variable_test.go b/android/variable_test.go
index ce9ba54..c1910fe 100644
--- a/android/variable_test.go
+++ b/android/variable_test.go
@@ -16,7 +16,10 @@
import (
"reflect"
+ "strconv"
"testing"
+
+ "github.com/google/blueprint/proptools"
)
type printfIntoPropertyTestCase struct {
@@ -122,3 +125,111 @@
}
}
}
+
+type testProductVariableModule struct {
+ ModuleBase
+}
+
+func (m *testProductVariableModule) GenerateAndroidBuildActions(ctx ModuleContext) {
+}
+
+var testProductVariableProperties = struct {
+ Product_variables struct {
+ Eng struct {
+ Srcs []string
+ Cflags []string
+ }
+ }
+}{}
+
+func testProductVariableModuleFactoryFactory(props interface{}) func() Module {
+ return func() Module {
+ m := &testProductVariableModule{}
+ clonedProps := proptools.CloneProperties(reflect.ValueOf(props)).Interface()
+ m.AddProperties(clonedProps)
+
+ // Set a default variableProperties, this will be used as the input to the property struct filter
+ // for this test module.
+ m.variableProperties = testProductVariableProperties
+ InitAndroidModule(m)
+ return m
+ }
+}
+
+func TestProductVariables(t *testing.T) {
+ ctx := NewTestContext()
+ // A module type that has a srcs property but not a cflags property.
+ ctx.RegisterModuleType("module1", ModuleFactoryAdaptor(testProductVariableModuleFactoryFactory(struct {
+ Srcs []string
+ }{})))
+ // A module type that has a cflags property but not a srcs property.
+ ctx.RegisterModuleType("module2", ModuleFactoryAdaptor(testProductVariableModuleFactoryFactory(struct {
+ Cflags []string
+ }{})))
+ // A module type that does not have any properties that match product_variables.
+ ctx.RegisterModuleType("module3", ModuleFactoryAdaptor(testProductVariableModuleFactoryFactory(struct {
+ Foo []string
+ }{})))
+ ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
+ ctx.BottomUp("variable", variableMutator).Parallel()
+ })
+
+ // Test that a module can use one product variable even if it doesn't have all the properties
+ // supported by that product variable.
+ bp := `
+ module1 {
+ name: "foo",
+ product_variables: {
+ eng: {
+ srcs: ["foo.c"],
+ },
+ },
+ }
+ module2 {
+ name: "bar",
+ product_variables: {
+ eng: {
+ cflags: ["-DBAR"],
+ },
+ },
+ }
+
+ module3 {
+ name: "baz",
+ }
+ `
+
+ mockFS := map[string][]byte{
+ "Android.bp": []byte(bp),
+ }
+
+ ctx.MockFileSystem(mockFS)
+
+ ctx.Register()
+
+ config := TestConfig(buildDir, nil)
+ config.TestProductVariables.Eng = proptools.BoolPtr(true)
+
+ _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
+ FailIfErrored(t, errs)
+ _, errs = ctx.PrepareBuildActions(config)
+ FailIfErrored(t, errs)
+}
+
+func BenchmarkSliceToTypeArray(b *testing.B) {
+ for _, n := range []int{1, 2, 4, 8, 100} {
+ var propStructs []interface{}
+ for i := 0; i < n; i++ {
+ propStructs = append(propStructs, &struct {
+ A *string
+ B string
+ }{})
+
+ }
+ b.Run(strconv.Itoa(n), func(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ _ = sliceToTypeArray(propStructs)
+ }
+ })
+ }
+}
diff --git a/apex/apex.go b/apex/apex.go
index aff8d50..c9b989a 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -149,15 +149,6 @@
androidAppTag = dependencyTag{name: "androidApp"}
)
-var (
- whitelistNoApex = map[string][]string{
- "apex_test_build_features": []string{"libbinder"},
- "com.android.media.swcodec": []string{"libbinder"},
- "test_com.android.media.swcodec": []string{"libbinder"},
- "com.android.vndk": []string{"libbinder"},
- }
-)
-
func init() {
pctx.Import("android/soong/android")
pctx.Import("android/soong/java")
@@ -196,6 +187,12 @@
ctx.BottomUp("apex_vndk_add_deps", apexVndkAddDepsMutator).Parallel()
})
android.PostDepsMutators(RegisterPostDepsMutators)
+
+ android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
+ apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
+ sort.Strings(*apexFileContextsInfos)
+ ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
+ })
}
func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
@@ -222,12 +219,14 @@
if ab.IsNativeBridgeSupported() {
mctx.PropertyErrorf("native_bridge_supported", "%q doesn't support native bridge binary.", mctx.ModuleType())
}
- vndkVersion := proptools.StringDefault(ab.vndkProperties.Vndk_version, mctx.DeviceConfig().PlatformVndkVersion())
+
+ vndkVersion := proptools.String(ab.vndkProperties.Vndk_version)
+
vndkApexListMutex.Lock()
defer vndkApexListMutex.Unlock()
vndkApexList := vndkApexList(mctx.Config())
if other, ok := vndkApexList[vndkVersion]; ok {
- mctx.PropertyErrorf("vndk_version", "%v is already defined in %q", vndkVersion, other.Name())
+ mctx.PropertyErrorf("vndk_version", "%v is already defined in %q", vndkVersion, other.BaseModuleName())
}
vndkApexList[vndkVersion] = ab
}
@@ -280,14 +279,40 @@
func apexMutator(mctx android.BottomUpMutatorContext) {
if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
am.CreateApexVariations(mctx)
- } else if _, ok := mctx.Module().(*apexBundle); ok {
+ } else if a, ok := mctx.Module().(*apexBundle); ok {
// apex bundle itself is mutated so that it and its modules have same
// apex variant.
apexBundleName := mctx.ModuleName()
mctx.CreateVariations(apexBundleName)
+
+ // collects APEX list
+ if mctx.Device() && a.installable() {
+ addApexFileContextsInfos(mctx, a)
+ }
}
}
+var (
+ apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
+ apexFileContextsInfosMutex sync.Mutex
+)
+
+func apexFileContextsInfos(config android.Config) *[]string {
+ return config.Once(apexFileContextsInfosKey, func() interface{} {
+ return &[]string{}
+ }).(*[]string)
+}
+
+func addApexFileContextsInfos(ctx android.BaseModuleContext, a *apexBundle) {
+ apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName())
+ fileContextsName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
+
+ apexFileContextsInfosMutex.Lock()
+ defer apexFileContextsInfosMutex.Unlock()
+ apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
+ *apexFileContextsInfos = append(*apexFileContextsInfos, apexName+":"+fileContextsName)
+}
+
func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
if ab, ok := mctx.Module().(*apexBundle); ok {
if !mctx.Config().FlattenApex() || mctx.Config().UnbundledBuild() {
@@ -533,7 +558,14 @@
case nativeTest:
return "NATIVE_TESTS"
case app:
- return "APPS"
+ // b/142537672 Why isn't this APP? We want to have full control over
+ // the paths and file names of the apk file under the flattend APEX.
+ // If this is set to APP, then the paths and file names are modified
+ // by the Make build system. For example, it is installed to
+ // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
+ // /system/apex/<apexname>/app/<Appname> because the build system automatically
+ // appends module name (which is <apexname>.<Appname> to the path.
+ return "ETC"
default:
panic(fmt.Errorf("unknown class %d", class))
}
@@ -561,8 +593,8 @@
bundleModuleFile android.WritablePath
outputFiles map[apexPackaging]android.WritablePath
- flattenedOutput android.OutputPath
- installDir android.OutputPath
+ flattenedOutput android.InstallPath
+ installDir android.InstallPath
prebuiltFileToDelete string
@@ -587,28 +619,25 @@
func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
native_shared_libs []string, binaries []string, tests []string,
- arch string, imageVariation string) {
+ target android.Target, imageVariation string) {
// Use *FarVariation* to be able to depend on modules having
// conflicting variations with this module. This is required since
// arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
// for native shared libs.
- ctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: arch},
+ ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
{Mutator: "image", Variation: imageVariation},
{Mutator: "link", Variation: "shared"},
{Mutator: "version", Variation: ""}, // "" is the non-stub variant
- }, sharedLibTag, native_shared_libs...)
+ }...), sharedLibTag, native_shared_libs...)
- ctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: arch},
- {Mutator: "image", Variation: imageVariation},
- }, executableTag, binaries...)
+ ctx.AddFarVariationDependencies(append(target.Variations(),
+ blueprint.Variation{Mutator: "image", Variation: imageVariation}),
+ executableTag, binaries...)
- ctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: arch},
+ ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
{Mutator: "image", Variation: imageVariation},
{Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
- }, testTag, tests...)
+ }...), testTag, tests...)
}
func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
@@ -640,49 +669,45 @@
for i, target := range targets {
// When multilib.* is omitted for native_shared_libs, it implies
// multilib.both.
- ctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: target.String()},
+ ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
{Mutator: "image", Variation: a.getImageVariation(config)},
{Mutator: "link", Variation: "shared"},
- }, sharedLibTag, a.properties.Native_shared_libs...)
+ }...), sharedLibTag, a.properties.Native_shared_libs...)
// When multilib.* is omitted for tests, it implies
// multilib.both.
- ctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: target.String()},
+ ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
{Mutator: "image", Variation: a.getImageVariation(config)},
{Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
- }, testTag, a.properties.Tests...)
+ }...), testTag, a.properties.Tests...)
// Add native modules targetting both ABIs
addDependenciesForNativeModules(ctx,
a.properties.Multilib.Both.Native_shared_libs,
a.properties.Multilib.Both.Binaries,
a.properties.Multilib.Both.Tests,
- target.String(),
+ target,
a.getImageVariation(config))
isPrimaryAbi := i == 0
if isPrimaryAbi {
// When multilib.* is omitted for binaries, it implies
// multilib.first.
- ctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: target.String()},
- {Mutator: "image", Variation: a.getImageVariation(config)},
- }, executableTag, a.properties.Binaries...)
+ ctx.AddFarVariationDependencies(append(target.Variations(),
+ blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
+ executableTag, a.properties.Binaries...)
// Add native modules targetting the first ABI
addDependenciesForNativeModules(ctx,
a.properties.Multilib.First.Native_shared_libs,
a.properties.Multilib.First.Binaries,
a.properties.Multilib.First.Tests,
- target.String(),
+ target,
a.getImageVariation(config))
// When multilib.* is omitted for prebuilts, it implies multilib.first.
- ctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: target.String()},
- }, prebuiltTag, a.properties.Prebuilts...)
+ ctx.AddFarVariationDependencies(target.Variations(),
+ prebuiltTag, a.properties.Prebuilts...)
}
switch target.Arch.ArchType.Multilib {
@@ -692,14 +717,14 @@
a.properties.Multilib.Lib32.Native_shared_libs,
a.properties.Multilib.Lib32.Binaries,
a.properties.Multilib.Lib32.Tests,
- target.String(),
+ target,
a.getImageVariation(config))
addDependenciesForNativeModules(ctx,
a.properties.Multilib.Prefer32.Native_shared_libs,
a.properties.Multilib.Prefer32.Binaries,
a.properties.Multilib.Prefer32.Tests,
- target.String(),
+ target,
a.getImageVariation(config))
case "lib64":
// Add native modules targetting 64-bit ABI
@@ -707,7 +732,7 @@
a.properties.Multilib.Lib64.Native_shared_libs,
a.properties.Multilib.Lib64.Binaries,
a.properties.Multilib.Lib64.Tests,
- target.String(),
+ target,
a.getImageVariation(config))
if !has32BitTarget {
@@ -715,7 +740,7 @@
a.properties.Multilib.Prefer32.Native_shared_libs,
a.properties.Multilib.Prefer32.Binaries,
a.properties.Multilib.Prefer32.Tests,
- target.String(),
+ target,
a.getImageVariation(config))
}
@@ -724,7 +749,7 @@
if sanitizer == "hwaddress" {
addDependenciesForNativeModules(ctx,
[]string{"libclang_rt.hwasan-aarch64-android"},
- nil, nil, target.String(), a.getImageVariation(config))
+ nil, nil, target, a.getImageVariation(config))
break
}
}
@@ -733,13 +758,11 @@
}
- ctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: "android_common"},
- }, javaLibTag, a.properties.Java_libs...)
+ ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
+ javaLibTag, a.properties.Java_libs...)
- ctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: "android_common"},
- }, androidAppTag, a.properties.Apps...)
+ ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
+ androidAppTag, a.properties.Apps...)
if String(a.properties.Key) == "" {
ctx.ModuleErrorf("key is missing")
@@ -763,6 +786,11 @@
}
}
+func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
+ // direct deps of an APEX bundle are all part of the APEX bundle
+ return true
+}
+
func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
if overridden {
@@ -867,9 +895,7 @@
dirInApex = "lib64"
}
dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
- if !ccMod.Arch().Native {
- dirInApex = filepath.Join(dirInApex, ccMod.Arch().ArchType.String())
- } else if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
+ if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
}
if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), config) {
@@ -892,9 +918,7 @@
func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
- if !cc.Arch().Native {
- dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
- } else if cc.Target().NativeBridge == android.NativeBridgeEnabled {
+ if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
}
fileToCopy = cc.OutputFile().Path()
@@ -948,7 +972,11 @@
}
func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToCopy android.Path, dirInApex string) {
- dirInApex = filepath.Join("app", pkgName)
+ appDir := "app"
+ if app.Privileged() {
+ appDir = "priv-app"
+ }
+ dirInApex = filepath.Join(appDir, pkgName)
fileToCopy = app.OutputFile()
return
}
@@ -1035,7 +1063,7 @@
return true
} else if sh, ok := child.(*android.ShBinary); ok {
fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
- filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, nil})
+ filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, sh.Symlinks()})
} else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
@@ -1170,10 +1198,6 @@
}
} else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
- } else if depTag == android.DefaultsDepTag {
- return false
- } else if am.NoApex() && !android.InList(depName, whitelistNoApex[ctx.ModuleName()]) {
- ctx.ModuleErrorf("tries to include no_apex module %s", depName)
}
}
}
@@ -1205,22 +1229,14 @@
return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
})
- // check no_apex modules
- whitelist := whitelistNoApex[ctx.ModuleName()]
- for i := range filesInfo {
- if am, ok := filesInfo[i].module.(android.ApexModule); ok {
- if am.NoApex() && !android.InList(filesInfo[i].moduleName, whitelist) {
- ctx.ModuleErrorf("tries to include no_apex module %s", filesInfo[i].moduleName)
- }
- }
- }
-
// check apex_available requirements
- for _, fi := range filesInfo {
- if am, ok := fi.module.(android.ApexModule); ok {
- if !am.AvailableFor(ctx.ModuleName()) {
- ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name())
- return
+ if !ctx.Host() {
+ for _, fi := range filesInfo {
+ if am, ok := fi.module.(android.ApexModule); ok {
+ if !am.AvailableFor(ctx.ModuleName()) {
+ ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name())
+ return
+ }
}
}
}
@@ -1265,7 +1281,8 @@
// instead of `android.PathForOutput`) to return the correct path to the flattened
// APEX (as its contents is installed by Make, not Soong).
factx := flattenedApexContext{ctx}
- a.flattenedOutput = android.PathForModuleInstall(&factx, "apex", factx.ModuleName())
+ apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName())
+ a.flattenedOutput = android.PathForModuleInstall(&factx, "apex", apexName)
if a.apexTypes.zip() {
a.buildUnflattenedApex(ctx, zipApex)
@@ -1565,8 +1582,9 @@
a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, ctx.ModuleName() + ".apex_pubkey", ".", etc, nil, nil})
if ctx.Config().FlattenApex() {
+ apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName())
for _, fi := range a.filesInfo {
- dir := filepath.Join("apex", ctx.ModuleName(), fi.installDir)
+ dir := filepath.Join("apex", apexName, fi.installDir)
target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile)
for _, sym := range fi.symlinks {
ctx.InstallSymlink(android.PathForModuleInstall(ctx, dir), sym, target)
@@ -1597,7 +1615,7 @@
}}
}
-func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apexType apexPackaging) []string {
+func (a *apexBundle) androidMkForFiles(w io.Writer, apexName, moduleDir string, apexType apexPackaging) []string {
moduleNames := []string{}
for _, fi := range a.filesInfo {
@@ -1621,12 +1639,11 @@
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName+suffix)
// /apex/<apex_name>/{lib|framework|...}
- pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex",
- proptools.StringDefault(a.properties.Apex_name, name), fi.installDir)
+ pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", apexName, fi.installDir)
if a.properties.Flattened && apexType.image() {
// /system/apex/<name>/{lib|framework|...}
- fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)",
- a.installDir.RelPathString(), name, fi.installDir))
+ fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join(a.installDir.ToMakePath().String(),
+ apexName, fi.installDir))
if !a.isFlattenedVariant() {
fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
}
@@ -1647,17 +1664,17 @@
host := false
switch fi.module.Target().Os.Class {
case android.Host:
- if archStr != "common" {
+ if fi.module.Target().Arch.ArchType != android.Common {
fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
}
host = true
case android.HostCross:
- if archStr != "common" {
+ if fi.module.Target().Arch.ArchType != android.Common {
fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
}
host = true
case android.Device:
- if archStr != "common" {
+ if fi.module.Target().Arch.ArchType != android.Common {
fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
}
}
@@ -1706,7 +1723,8 @@
Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
moduleNames := []string{}
if a.installable() {
- moduleNames = a.androidMkForFiles(w, name, moduleDir, apexType)
+ apexName := proptools.StringDefault(a.properties.Apex_name, name)
+ moduleNames = a.androidMkForFiles(w, apexName, moduleDir, apexType)
}
if a.isFlattenedVariant() {
@@ -1735,7 +1753,7 @@
fmt.Fprintln(w, "LOCAL_MODULE :=", name)
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
- fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", a.installDir.RelPathString()))
+ fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.ToMakePath().String())
fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
if len(moduleNames) > 0 {
@@ -1746,7 +1764,7 @@
}
if a.prebuiltFileToDelete != "" {
fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+
- filepath.Join("$(OUT_DIR)", a.installDir.RelPathString(), a.prebuiltFileToDelete))
+ filepath.Join(a.installDir.ToMakePath().String(), a.prebuiltFileToDelete))
}
fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
@@ -1801,6 +1819,15 @@
}{
proptools.StringPtr("both"),
})
+
+ vndkVersion := proptools.StringDefault(bundle.vndkProperties.Vndk_version, "current")
+ if vndkVersion == "current" {
+ vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
+ bundle.vndkProperties.Vndk_version = proptools.StringPtr(vndkVersion)
+ }
+
+ // Ensure VNDK APEX mount point is formatted as com.android.vndk.v###
+ bundle.properties.Apex_name = proptools.StringPtr("com.android.vndk.v" + vndkVersion)
})
return bundle
}
@@ -1840,7 +1867,7 @@
properties PrebuiltProperties
inputApex android.Path
- installDir android.OutputPath
+ installDir android.InstallPath
installFilename string
outputApex android.WritablePath
}
@@ -1987,7 +2014,7 @@
Include: "$(BUILD_PREBUILT)",
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
func(entries *android.AndroidMkEntries) {
- entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString()))
+ entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
diff --git a/apex/apex_test.go b/apex/apex_test.go
index ecfa46f..7a51bb6 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -102,9 +102,6 @@
ctx.RegisterModuleType("apex_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
ctx.RegisterModuleType("prebuilt_apex", android.ModuleFactoryAdaptor(PrebuiltFactory))
- ctx.RegisterModuleType("cc_defaults", android.ModuleFactoryAdaptor(func() android.Module {
- return cc.DefaultsFactory()
- }))
ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory))
ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
@@ -1382,6 +1379,7 @@
vndk: {
enabled: true,
},
+ target_arch: "arm64",
srcs: ["libvndk27.so"],
}
`, withFiles(map[string][]byte{
@@ -1441,6 +1439,37 @@
}))
}
+func TestVndkApexNameRule(t *testing.T) {
+ ctx, _ := testApex(t, `
+ apex_vndk {
+ name: "myapex",
+ key: "myapex.key",
+ file_contexts: "myapex",
+ }
+ apex_vndk {
+ name: "myapex_v28",
+ key: "myapex.key",
+ file_contexts: "myapex",
+ vndk_version: "28",
+ }
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }`)
+
+ assertApexName := func(expected, moduleName string) {
+ bundle := ctx.ModuleForTests(moduleName, "android_common_"+moduleName).Module().(*apexBundle)
+ actual := proptools.String(bundle.properties.Apex_name)
+ if !reflect.DeepEqual(actual, expected) {
+ t.Errorf("Got '%v', expected '%v'", actual, expected)
+ }
+ }
+
+ assertApexName("com.android.vndk.vVER", "myapex")
+ assertApexName("com.android.vndk.v28", "myapex_v28")
+}
+
func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
ctx, _ := testApex(t, `
apex_vndk {
@@ -1469,10 +1498,10 @@
}
`, withTargets(map[android.OsType][]android.Target{
android.Android: []android.Target{
- {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Native: true, Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
- {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Native: true, Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
- {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Native: true, Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
- {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Native: true, Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
+ {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
+ {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
+ {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
+ {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
},
}))
@@ -1864,8 +1893,8 @@
`)
apex := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
- expected := "target/product/test_device/product/apex"
- actual := apex.installDir.RelPathString()
+ expected := buildDir + "/target/product/test_device/product/apex"
+ actual := apex.installDir.String()
if actual != expected {
t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
}
@@ -2151,200 +2180,6 @@
`)
}
-func TestApexUsesFailsIfUseNoApex(t *testing.T) {
- // 'no_apex' prevents a module to be included in an apex
- testApexError(t, `tries to include no_apex module mylib2`, `
- apex {
- name: "commonapex",
- key: "myapex.key",
- native_shared_libs: ["mylib"],
- }
-
- apex_key {
- name: "myapex.key",
- public_key: "testkey.avbpubkey",
- private_key: "testkey.pem",
- }
-
- cc_library {
- name: "mylib",
- srcs: ["mylib.cpp"],
- shared_libs: ["mylib2"],
- system_shared_libs: [],
- stl: "none",
- }
-
- cc_library {
- name: "mylib2",
- srcs: ["mylib.cpp"],
- system_shared_libs: [],
- stl: "none",
- no_apex: true,
- }
- `)
-
- // respect 'no_apex' even with static link
- testApexError(t, `tries to include no_apex module mylib2`, `
- apex {
- name: "commonapex",
- key: "myapex.key",
- native_shared_libs: ["mylib"],
- }
-
- apex_key {
- name: "myapex.key",
- public_key: "testkey.avbpubkey",
- private_key: "testkey.pem",
- }
-
- cc_library {
- name: "mylib",
- srcs: ["mylib.cpp"],
- static_libs: ["mylib2"],
- system_shared_libs: [],
- stl: "none",
- }
-
- cc_library {
- name: "mylib2",
- srcs: ["mylib.cpp"],
- system_shared_libs: [],
- stl: "none",
- no_apex: true,
- }
- `)
-
- // 'no_apex' can be applied via defaults
- testApexError(t, `tries to include no_apex module mylib2`, `
- apex {
- name: "commonapex",
- key: "myapex.key",
- native_shared_libs: ["mylib"],
- }
-
- apex_key {
- name: "myapex.key",
- public_key: "testkey.avbpubkey",
- private_key: "testkey.pem",
- }
-
- cc_library {
- name: "mylib",
- srcs: ["mylib.cpp"],
- static_libs: ["mylib2"],
- system_shared_libs: [],
- stl: "none",
- }
-
- cc_defaults {
- name: "mylib2_defaults",
- system_shared_libs: [],
- stl: "none",
- no_apex: true,
- }
-
- cc_library {
- name: "mylib2",
- srcs: ["mylib.cpp"],
- defaults: ["mylib2_defaults"],
- }
- `)
-}
-
-func TestNoApexWorksWithWhitelist(t *testing.T) {
-
- testApex(t, `
- apex {
- name: "myapex",
- key: "myapex.key",
- native_shared_libs: ["mylib"],
- }
-
- apex_key {
- name: "myapex.key",
- public_key: "testkey.avbpubkey",
- private_key: "testkey.pem",
- }
-
- cc_library {
- name: "mylib",
- srcs: ["mylib.cpp"],
- shared_libs: ["mylib2"],
- system_shared_libs: [],
- stl: "none",
- }
-
- cc_defaults {
- name: "mylib2_defaults",
- system_shared_libs: [],
- stl: "none",
- no_apex: true,
- }
-
- cc_library {
- name: "mylib2",
- srcs: ["mylib.cpp"],
- defaults: ["mylib2_defaults"],
- }
- `, func(fs map[string][]byte, config android.Config) {
- whitelistNoApex = map[string][]string{
- "myapex": []string{"mylib2"},
- }
- })
-}
-
-func TestNoApexCanBeDependedOnViaStubs(t *testing.T) {
- ctx, _ := testApex(t, `
- apex {
- name: "myapex",
- key: "myapex.key",
- native_shared_libs: ["mylib"],
- }
-
- apex_key {
- name: "myapex.key",
- public_key: "testkey.avbpubkey",
- private_key: "testkey.pem",
- }
-
- cc_library {
- name: "mylib",
- srcs: ["mylib.cpp"],
- shared_libs: ["mylib2"],
- system_shared_libs: [],
- stl: "none",
- }
-
- cc_library {
- name: "mylib2",
- srcs: ["mylib.cpp"],
- shared_libs: ["mylib3"],
- system_shared_libs: [],
- stl: "none",
- stubs: {
- versions: ["1", "2", "3"],
- },
- }
-
- // this won't be included in "myapex", so 'no_apex' is still valid in this case.
- cc_library {
- name: "mylib3",
- srcs: ["mylib.cpp"],
- system_shared_libs: [],
- stl: "none",
- no_apex: true,
- }
- `)
-
- module := ctx.ModuleForTests("myapex", "android_common_myapex")
- apexRule := module.Rule("apexRule")
- copyCmds := apexRule.Args["copy_commands"]
-
- ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
- ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
- ensureNotContains(t, copyCmds, "image.apex/lib64/mylib3.so")
-}
-
func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
apex {
@@ -2397,6 +2232,7 @@
key: "myapex.key",
apps: [
"AppFoo",
+ "AppFooPriv",
],
}
@@ -2412,6 +2248,14 @@
sdk_version: "none",
system_modules: "none",
}
+
+ android_app {
+ name: "AppFooPriv",
+ srcs: ["foo/bar/MyClass.java"],
+ sdk_version: "none",
+ system_modules: "none",
+ privileged: true,
+ }
`)
module := ctx.ModuleForTests("myapex", "android_common_myapex")
@@ -2419,6 +2263,7 @@
copyCmds := apexRule.Args["copy_commands"]
ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
+ ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
}
@@ -2572,6 +2417,36 @@
// check that libfoo is created only for the platform
ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
+
+ ctx, _ = testApex(t, `
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ native_shared_libs: ["libfoo"],
+ }
+
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+
+ cc_library {
+ name: "libfoo",
+ stl: "none",
+ system_shared_libs: [],
+ apex_available: ["myapex"],
+ static: {
+ apex_available: ["//apex_available:platform"],
+ },
+ }`)
+
+ // shared variant of libfoo is only available to myapex
+ ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
+ ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
+ // but the static variant is available to both myapex and the platform
+ ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_static_myapex")
+ ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_static")
}
func TestMain(m *testing.M) {
diff --git a/cc/androidmk.go b/cc/androidmk.go
index aab4edd..9a98b0e 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -308,15 +308,13 @@
var fuzzFiles []string
for _, d := range fuzz.corpus {
- rel := d.Rel()
- path := d.String()
- path = strings.TrimSuffix(path, rel)
- fuzzFiles = append(fuzzFiles, path+":corpus/"+d.Base())
+ fuzzFiles = append(fuzzFiles,
+ filepath.Dir(fuzz.corpusIntermediateDir.String())+":corpus/"+d.Base())
}
if fuzz.dictionary != nil {
- path := strings.TrimSuffix(fuzz.dictionary.String(), fuzz.dictionary.Rel())
- fuzzFiles = append(fuzzFiles, path+":"+fuzz.dictionary.Base())
+ fuzzFiles = append(fuzzFiles,
+ filepath.Dir(fuzz.dictionary.String())+":"+fuzz.dictionary.Base())
}
if len(fuzzFiles) > 0 {
@@ -350,11 +348,10 @@
}
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
- path := installer.path.RelPathString()
- dir, file := filepath.Split(path)
+ path, file := filepath.Split(installer.path.ToMakePath().String())
stem, suffix, _ := android.SplitFileExt(file)
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
- fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
+ fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path)
fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
})
}
@@ -395,12 +392,11 @@
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
c.libraryDecorator.androidMkWriteExportedFlags(w)
- path := c.path.RelPathString()
- dir, file := filepath.Split(path)
+ path, file := filepath.Split(c.path.ToMakePath().String())
stem, suffix, ext := android.SplitFileExt(file)
fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext)
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
- fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
+ fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path)
fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
})
}
diff --git a/cc/binary.go b/cc/binary.go
index 0d69405..9f18d6c 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -453,7 +453,7 @@
// Bionic binaries (e.g. linker) is installed to the bootstrap subdirectory.
// The original path becomes a symlink to the corresponding file in the
// runtime APEX.
- translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled || !ctx.Arch().Native
+ translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled
if InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !translatedArch && ctx.apexName() == "" && !ctx.inRecovery() {
if ctx.Device() && isBionic(ctx.baseModuleName()) {
binary.installSymlinkToRuntimeApex(ctx, file)
diff --git a/cc/builder.go b/cc/builder.go
index c4f65da..0760dd4 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -195,7 +195,7 @@
_ = pctx.SourcePathVariable("sAbiDiffer", "prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/header-abi-diff")
- sAbiDiff = pctx.AndroidRuleFunc("sAbiDiff",
+ sAbiDiff = pctx.RuleFunc("sAbiDiff",
func(ctx android.PackageRuleContext) blueprint.RuleParams {
// TODO(b/78139997): Add -check-all-apis back
commandStr := "($sAbiDiffer ${allowFlags} -lib ${libName} -arch ${arch} -o ${out} -new ${in} -old ${referenceDump})"
diff --git a/cc/cc.go b/cc/cc.go
index 744e0cb..806a6ed 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -552,8 +552,10 @@
}
})
android.InitAndroidArchModule(c, c.hod, c.multilib)
- android.InitApexModule(c)
+
android.InitDefaultableModule(c)
+
+ android.InitApexModule(c)
android.InitSdkAwareModule(c)
return c
@@ -1387,10 +1389,9 @@
depTag = headerExportDepTag
}
if buildStubs {
- actx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: ctx.Target().String()},
- {Mutator: "image", Variation: c.imageVariation()},
- }, depTag, lib)
+ actx.AddFarVariationDependencies(append(ctx.Target().Variations(),
+ blueprint.Variation{Mutator: "image", Variation: c.imageVariation()}),
+ depTag, lib)
} else {
actx.AddVariationDependencies(nil, depTag, lib)
}
@@ -1932,7 +1933,11 @@
if ptr != nil {
if !linkFile.Valid() {
- ctx.ModuleErrorf("module %q missing output file", depName)
+ if !ctx.Config().AllowMissingDependencies() {
+ ctx.ModuleErrorf("module %q missing output file", depName)
+ } else {
+ ctx.AddMissingDependencies([]string{depName})
+ }
return
}
*ptr = append(*ptr, linkFile.Path())
@@ -2150,6 +2155,16 @@
return false
}
+func (c *Module) AvailableFor(what string) bool {
+ if linker, ok := c.linker.(interface {
+ availableFor(string) bool
+ }); ok {
+ return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
+ } else {
+ return c.ApexModuleBase.AvailableFor(what)
+ }
+}
+
func (c *Module) installable() bool {
return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
}
@@ -2179,6 +2194,16 @@
}
}
+func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
+ if depTag, ok := ctx.OtherModuleDependencyTag(dep).(dependencyTag); ok {
+ if cc, ok := dep.(*Module); ok && cc.IsStubs() && depTag.shared {
+ // dynamic dep to a stubs lib crosses APEX boundary
+ return false
+ }
+ }
+ return true
+}
+
//
// Defaults
//
@@ -2208,6 +2233,8 @@
&BaseLinkerProperties{},
&ObjectLinkerProperties{},
&LibraryProperties{},
+ &StaticProperties{},
+ &SharedProperties{},
&FlagExporterProperties{},
&BinaryLinkerProperties{},
&TestProperties{},
@@ -2227,8 +2254,8 @@
&android.ProtoProperties{},
)
- android.InitApexModule(module)
android.InitDefaultsModule(module)
+ android.InitApexModule(module)
return module
}
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 6275822..689aacd 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -15,8 +15,6 @@
package cc
import (
- "android/soong/android"
-
"fmt"
"io/ioutil"
"os"
@@ -25,6 +23,8 @@
"sort"
"strings"
"testing"
+
+ "android/soong/android"
)
var buildDir string
@@ -53,6 +53,7 @@
}
func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.TestContext {
+ t.Helper()
return testCcWithConfigForOs(t, bp, config, android.Android)
}
@@ -2321,3 +2322,67 @@
}
}
}
+
+func TestDefaults(t *testing.T) {
+ ctx := testCc(t, `
+ cc_defaults {
+ name: "defaults",
+ srcs: ["foo.c"],
+ static: {
+ srcs: ["bar.c"],
+ },
+ shared: {
+ srcs: ["baz.c"],
+ },
+ }
+
+ cc_library_static {
+ name: "libstatic",
+ defaults: ["defaults"],
+ }
+
+ cc_library_shared {
+ name: "libshared",
+ defaults: ["defaults"],
+ }
+
+ cc_library {
+ name: "libboth",
+ defaults: ["defaults"],
+ }
+
+ cc_binary {
+ name: "binary",
+ defaults: ["defaults"],
+ }`)
+
+ pathsToBase := func(paths android.Paths) []string {
+ var ret []string
+ for _, p := range paths {
+ ret = append(ret, p.Base())
+ }
+ return ret
+ }
+
+ shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_core_shared").Rule("ld")
+ if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
+ t.Errorf("libshared ld rule wanted %q, got %q", w, g)
+ }
+ bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_core_shared").Rule("ld")
+ if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
+ t.Errorf("libboth ld rule wanted %q, got %q", w, g)
+ }
+ binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a_core").Rule("ld")
+ if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
+ t.Errorf("binary ld rule wanted %q, got %q", w, g)
+ }
+
+ static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_core_static").Rule("ar")
+ if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
+ t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
+ }
+ bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_core_static").Rule("ar")
+ if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
+ t.Errorf("libboth ar rule wanted %q, got %q", w, g)
+ }
+}
diff --git a/cc/compiler.go b/cc/compiler.go
index 85ff400..ffb6ad2 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -309,7 +309,6 @@
flags.SystemIncludeFlags = append(flags.SystemIncludeFlags,
"-isystem "+getCurrentIncludePath(ctx).String(),
"-isystem "+getCurrentIncludePath(ctx).Join(ctx, config.NDKTriple(tc)).String())
- flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_NDK__")
}
if ctx.useVndk() {
diff --git a/cc/config/vndk.go b/cc/config/vndk.go
index d7d8955..3e8abac 100644
--- a/cc/config/vndk.go
+++ b/cc/config/vndk.go
@@ -65,6 +65,7 @@
"android.hardware.neuralnetworks@1.0",
"android.hardware.neuralnetworks@1.1",
"android.hardware.neuralnetworks@1.2",
+ "android.hardware.neuralnetworks@1.3",
"android.hardware.nfc@1.0",
"android.hardware.nfc@1.1",
"android.hardware.nfc@1.2",
diff --git a/cc/config/x86_windows_host.go b/cc/config/x86_windows_host.go
index 0f500b6..43e8c85 100644
--- a/cc/config/x86_windows_host.go
+++ b/cc/config/x86_windows_host.go
@@ -73,6 +73,7 @@
"-m32",
"-Wl,--large-address-aware",
"-L${WindowsGccRoot}/${WindowsGccTriple}/lib32",
+ "-static-libgcc",
}
windowsX86ClangLdflags = append(ClangFilterUnknownCflags(windowsX86Ldflags), []string{
"-B${WindowsGccRoot}/${WindowsGccTriple}/bin",
@@ -86,6 +87,7 @@
"-m64",
"-L${WindowsGccRoot}/${WindowsGccTriple}/lib64",
"-Wl,--high-entropy-va",
+ "-static-libgcc",
}
windowsX8664ClangLdflags = append(ClangFilterUnknownCflags(windowsX8664Ldflags), []string{
"-B${WindowsGccRoot}/${WindowsGccTriple}/bin",
diff --git a/cc/fuzz.go b/cc/fuzz.go
index c19fdc5..a99b0bb 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -53,9 +53,10 @@
*binaryDecorator
*baseCompiler
- Properties FuzzProperties
- corpus android.Paths
- dictionary android.Path
+ Properties FuzzProperties
+ dictionary android.Path
+ corpus android.Paths
+ corpusIntermediateDir android.Path
}
func (fuzz *fuzzBinary) linkerProps() []interface{} {
@@ -103,6 +104,16 @@
fuzz.binaryDecorator.baseInstaller.install(ctx, file)
fuzz.corpus = android.PathsForModuleSrc(ctx, fuzz.Properties.Corpus)
+ builder := android.NewRuleBuilder()
+ intermediateDir := android.PathForModuleOut(ctx, "corpus")
+ for _, entry := range fuzz.corpus {
+ builder.Command().Text("cp").
+ Input(entry).
+ Output(intermediateDir.Join(ctx, entry.Base()))
+ }
+ builder.Build(pctx, ctx, "copy_corpus", "copy corpus")
+ fuzz.corpusIntermediateDir = intermediateDir
+
if fuzz.Properties.Dictionary != nil {
fuzz.dictionary = android.PathForModuleSrc(ctx, *fuzz.Properties.Dictionary)
if fuzz.dictionary.Ext() != ".dict" {
@@ -148,10 +159,14 @@
// include the STL.
android.AddLoadHook(module, func(ctx android.LoadHookContext) {
staticStlLinkage := struct {
- Stl *string
+ Target struct {
+ Linux_glibc struct {
+ Stl *string
+ }
+ }
}{}
- staticStlLinkage.Stl = proptools.StringPtr("libc++_static")
+ staticStlLinkage.Target.Linux_glibc.Stl = proptools.StringPtr("libc++_static")
ctx.AppendProperties(&staticStlLinkage)
})
@@ -211,7 +226,7 @@
// The corpora.
for _, corpusEntry := range fuzzModule.corpus {
archDirs[archDir] = append(archDirs[archDir],
- fileToZip{corpusEntry, ccModule.Name() + "/corpus/" + corpusEntry.Base()})
+ fileToZip{corpusEntry, ccModule.Name() + "/corpus"})
}
// The dictionary.
diff --git a/cc/installer.go b/cc/installer.go
index a52ccf1..9fdc88a 100644
--- a/cc/installer.go
+++ b/cc/installer.go
@@ -52,7 +52,7 @@
relative string
location installLocation
- path android.OutputPath
+ path android.InstallPath
}
var _ installer = (*baseInstaller)(nil)
@@ -61,16 +61,15 @@
return []interface{}{&installer.Properties}
}
-func (installer *baseInstaller) installDir(ctx ModuleContext) android.OutputPath {
+func (installer *baseInstaller) installDir(ctx ModuleContext) android.InstallPath {
dir := installer.dir
if ctx.toolchain().Is64Bit() && installer.dir64 != "" {
dir = installer.dir64
}
- if !ctx.Host() && !ctx.Arch().Native {
- dir = filepath.Join(dir, ctx.Arch().ArchType.String())
- }
if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
dir = filepath.Join(dir, ctx.Target().NativeBridgeRelativePath)
+ } else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
+ dir = filepath.Join(dir, ctx.Arch().ArchType.String())
}
if installer.location == InstallInData && ctx.useVndk() {
dir = filepath.Join(dir, "vendor")
diff --git a/cc/library.go b/cc/library.go
index 0f33611..80dc76c 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -31,24 +31,7 @@
"android/soong/genrule"
)
-type StaticSharedLibraryProperties struct {
- Srcs []string `android:"path,arch_variant"`
- Cflags []string `android:"arch_variant"`
-
- Enabled *bool `android:"arch_variant"`
- Whole_static_libs []string `android:"arch_variant"`
- Static_libs []string `android:"arch_variant"`
- Shared_libs []string `android:"arch_variant"`
- System_shared_libs []string `android:"arch_variant"`
-
- Export_shared_lib_headers []string `android:"arch_variant"`
- Export_static_lib_headers []string `android:"arch_variant"`
-}
-
type LibraryProperties struct {
- Static StaticSharedLibraryProperties `android:"arch_variant"`
- Shared StaticSharedLibraryProperties `android:"arch_variant"`
-
// local file name to pass to the linker as -unexported_symbols_list
Unexported_symbols_list *string `android:"path,arch_variant"`
// local file name to pass to the linker as -force_symbols_not_weak_list
@@ -128,6 +111,30 @@
Inject_bssl_hash *bool `android:"arch_variant"`
}
+type StaticProperties struct {
+ Static StaticOrSharedProperties `android:"arch_variant"`
+}
+
+type SharedProperties struct {
+ Shared StaticOrSharedProperties `android:"arch_variant"`
+}
+
+type StaticOrSharedProperties struct {
+ Srcs []string `android:"path,arch_variant"`
+ Cflags []string `android:"arch_variant"`
+
+ Enabled *bool `android:"arch_variant"`
+ Whole_static_libs []string `android:"arch_variant"`
+ Static_libs []string `android:"arch_variant"`
+ Shared_libs []string `android:"arch_variant"`
+ System_shared_libs []string `android:"arch_variant"`
+
+ Export_shared_lib_headers []string `android:"arch_variant"`
+ Export_static_lib_headers []string `android:"arch_variant"`
+
+ Apex_available []string `android:"arch_variant"`
+}
+
type LibraryMutatedProperties struct {
// Build a static variant
BuildStatic bool `blueprint:"mutated"`
@@ -295,6 +302,8 @@
// functionality: static vs. shared linkage, reusing object files for shared libraries
type libraryDecorator struct {
Properties LibraryProperties
+ StaticProperties StaticProperties
+ SharedProperties SharedProperties
MutatedProperties LibraryMutatedProperties
// For reusing static library objects for shared library
@@ -355,11 +364,20 @@
func (library *libraryDecorator) linkerProps() []interface{} {
var props []interface{}
props = append(props, library.baseLinker.linkerProps()...)
- return append(props,
+ props = append(props,
&library.Properties,
&library.MutatedProperties,
&library.flagExporter.Properties,
&library.stripper.StripProperties)
+
+ if library.MutatedProperties.BuildShared {
+ props = append(props, &library.SharedProperties)
+ }
+ if library.MutatedProperties.BuildStatic {
+ props = append(props, &library.StaticProperties)
+ }
+
+ return props
}
func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
@@ -373,9 +391,9 @@
}
if library.static() {
- flags.CFlags = append(flags.CFlags, library.Properties.Static.Cflags...)
+ flags.CFlags = append(flags.CFlags, library.StaticProperties.Static.Cflags...)
} else if library.shared() {
- flags.CFlags = append(flags.CFlags, library.Properties.Shared.Cflags...)
+ flags.CFlags = append(flags.CFlags, library.SharedProperties.Shared.Cflags...)
}
if library.shared() {
@@ -498,10 +516,10 @@
if len(library.baseCompiler.Properties.Srcs) > 0 {
ctx.PropertyErrorf("srcs", "cc_library_headers must not have any srcs")
}
- if len(library.Properties.Static.Srcs) > 0 {
+ if len(library.StaticProperties.Static.Srcs) > 0 {
ctx.PropertyErrorf("static.srcs", "cc_library_headers must not have any srcs")
}
- if len(library.Properties.Shared.Srcs) > 0 {
+ if len(library.SharedProperties.Shared.Srcs) > 0 {
ctx.PropertyErrorf("shared.srcs", "cc_library_headers must not have any srcs")
}
return Objects{}
@@ -516,8 +534,8 @@
SourceAbiFlags = append(SourceAbiFlags, "-I"+reexportedInclude)
}
flags.SAbiFlags = SourceAbiFlags
- total_length := len(library.baseCompiler.Properties.Srcs) + len(deps.GeneratedSources) + len(library.Properties.Shared.Srcs) +
- len(library.Properties.Static.Srcs)
+ total_length := len(library.baseCompiler.Properties.Srcs) + len(deps.GeneratedSources) +
+ len(library.SharedProperties.Shared.Srcs) + len(library.StaticProperties.Static.Srcs)
if total_length > 0 {
flags.SAbiDump = true
}
@@ -527,11 +545,11 @@
buildFlags := flagsToBuilderFlags(flags)
if library.static() {
- srcs := android.PathsForModuleSrc(ctx, library.Properties.Static.Srcs)
+ srcs := android.PathsForModuleSrc(ctx, library.StaticProperties.Static.Srcs)
objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceStaticLibrary,
srcs, library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps))
} else if library.shared() {
- srcs := android.PathsForModuleSrc(ctx, library.Properties.Shared.Srcs)
+ srcs := android.PathsForModuleSrc(ctx, library.SharedProperties.Shared.Srcs)
objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceSharedLibrary,
srcs, library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps))
}
@@ -557,6 +575,8 @@
// Write LOCAL_ADDITIONAL_DEPENDENCIES for ABI diff
androidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer)
+
+ availableFor(string) bool
}
func (library *libraryDecorator) getLibName(ctx BaseModuleContext) string {
@@ -625,12 +645,12 @@
func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
if library.static() {
- if library.Properties.Static.System_shared_libs != nil {
- library.baseLinker.Properties.System_shared_libs = library.Properties.Static.System_shared_libs
+ if library.StaticProperties.Static.System_shared_libs != nil {
+ library.baseLinker.Properties.System_shared_libs = library.StaticProperties.Static.System_shared_libs
}
} else if library.shared() {
- if library.Properties.Shared.System_shared_libs != nil {
- library.baseLinker.Properties.System_shared_libs = library.Properties.Shared.System_shared_libs
+ if library.SharedProperties.Shared.System_shared_libs != nil {
+ library.baseLinker.Properties.System_shared_libs = library.SharedProperties.Shared.System_shared_libs
}
}
@@ -638,12 +658,12 @@
if library.static() {
deps.WholeStaticLibs = append(deps.WholeStaticLibs,
- library.Properties.Static.Whole_static_libs...)
- deps.StaticLibs = append(deps.StaticLibs, library.Properties.Static.Static_libs...)
- deps.SharedLibs = append(deps.SharedLibs, library.Properties.Static.Shared_libs...)
+ library.StaticProperties.Static.Whole_static_libs...)
+ deps.StaticLibs = append(deps.StaticLibs, library.StaticProperties.Static.Static_libs...)
+ deps.SharedLibs = append(deps.SharedLibs, library.StaticProperties.Static.Shared_libs...)
- deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, library.Properties.Static.Export_shared_lib_headers...)
- deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, library.Properties.Static.Export_static_lib_headers...)
+ deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, library.StaticProperties.Static.Export_shared_lib_headers...)
+ deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, library.StaticProperties.Static.Export_static_lib_headers...)
} else if library.shared() {
if ctx.toolchain().Bionic() && !Bool(library.baseLinker.Properties.Nocrt) {
if !ctx.useSdk() {
@@ -662,12 +682,12 @@
deps.CrtEnd = "ndk_crtend_so." + version
}
}
- deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.Properties.Shared.Whole_static_libs...)
- deps.StaticLibs = append(deps.StaticLibs, library.Properties.Shared.Static_libs...)
- deps.SharedLibs = append(deps.SharedLibs, library.Properties.Shared.Shared_libs...)
+ deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.SharedProperties.Shared.Whole_static_libs...)
+ deps.StaticLibs = append(deps.StaticLibs, library.SharedProperties.Shared.Static_libs...)
+ deps.SharedLibs = append(deps.SharedLibs, library.SharedProperties.Shared.Shared_libs...)
- deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, library.Properties.Shared.Export_shared_lib_headers...)
- deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, library.Properties.Shared.Export_static_lib_headers...)
+ deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, library.SharedProperties.Shared.Export_shared_lib_headers...)
+ deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, library.SharedProperties.Shared.Export_static_lib_headers...)
}
if ctx.useVndk() {
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, library.baseLinker.Properties.Target.Vendor.Exclude_static_libs)
@@ -775,9 +795,7 @@
// Optimize out relinking against shared libraries whose interface hasn't changed by
// depending on a table of contents file instead of the library itself.
- tocPath := outputFile.RelPathString()
- tocPath = pathtools.ReplaceExtension(tocPath, flags.Toolchain.ShlibSuffix()[1:]+".toc")
- tocFile := android.PathForOutput(ctx, tocPath)
+ tocFile := outputFile.ReplaceExtension(ctx, flags.Toolchain.ShlibSuffix()[1:]+".toc")
library.tocFile = android.OptionalPathForPath(tocFile)
TransformSharedObjectToToc(ctx, outputFile, tocFile, builderFlags)
@@ -978,11 +996,13 @@
}
func (library *libraryDecorator) buildStatic() bool {
- return library.MutatedProperties.BuildStatic && BoolDefault(library.Properties.Static.Enabled, true)
+ return library.MutatedProperties.BuildStatic &&
+ BoolDefault(library.StaticProperties.Static.Enabled, true)
}
func (library *libraryDecorator) buildShared() bool {
- return library.MutatedProperties.BuildShared && BoolDefault(library.Properties.Shared.Enabled, true)
+ return library.MutatedProperties.BuildShared &&
+ BoolDefault(library.SharedProperties.Shared.Enabled, true)
}
func (library *libraryDecorator) getWholeStaticMissingDeps() []string {
@@ -1032,7 +1052,7 @@
// Bionic libraries (e.g. libc.so) is installed to the bootstrap subdirectory.
// The original path becomes a symlink to the corresponding file in the
// runtime APEX.
- translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled || !ctx.Arch().Native
+ translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled
if InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !library.buildStubs() && !translatedArch && !ctx.inRecovery() {
if ctx.Device() {
library.installSymlinkToRuntimeApex(ctx, file)
@@ -1118,6 +1138,19 @@
return library.MutatedProperties.StubsVersion
}
+func (library *libraryDecorator) availableFor(what string) bool {
+ var list []string
+ if library.static() {
+ list = library.StaticProperties.Static.Apex_available
+ } else if library.shared() {
+ list = library.SharedProperties.Shared.Apex_available
+ }
+ if len(list) == 0 {
+ return false
+ }
+ return android.CheckAvailableForApex(what, list)
+}
+
var versioningMacroNamesListKey = android.NewOnceKey("versioningMacroNamesList")
func versioningMacroNamesList(config android.Config) *map[string]string {
@@ -1166,16 +1199,16 @@
// Check libraries in addition to cflags, since libraries may be exporting different
// include directories.
- if len(staticCompiler.Properties.Static.Cflags) == 0 &&
- len(sharedCompiler.Properties.Shared.Cflags) == 0 &&
- len(staticCompiler.Properties.Static.Whole_static_libs) == 0 &&
- len(sharedCompiler.Properties.Shared.Whole_static_libs) == 0 &&
- len(staticCompiler.Properties.Static.Static_libs) == 0 &&
- len(sharedCompiler.Properties.Shared.Static_libs) == 0 &&
- len(staticCompiler.Properties.Static.Shared_libs) == 0 &&
- len(sharedCompiler.Properties.Shared.Shared_libs) == 0 &&
- staticCompiler.Properties.Static.System_shared_libs == nil &&
- sharedCompiler.Properties.Shared.System_shared_libs == nil {
+ if len(staticCompiler.StaticProperties.Static.Cflags) == 0 &&
+ len(sharedCompiler.SharedProperties.Shared.Cflags) == 0 &&
+ len(staticCompiler.StaticProperties.Static.Whole_static_libs) == 0 &&
+ len(sharedCompiler.SharedProperties.Shared.Whole_static_libs) == 0 &&
+ len(staticCompiler.StaticProperties.Static.Static_libs) == 0 &&
+ len(sharedCompiler.SharedProperties.Shared.Static_libs) == 0 &&
+ len(staticCompiler.StaticProperties.Static.Shared_libs) == 0 &&
+ len(sharedCompiler.SharedProperties.Shared.Shared_libs) == 0 &&
+ staticCompiler.StaticProperties.Static.System_shared_libs == nil &&
+ sharedCompiler.SharedProperties.Shared.System_shared_libs == nil {
mctx.AddInterVariantDependency(reuseObjTag, shared, static)
sharedCompiler.baseCompiler.Properties.OriginalSrcs =
diff --git a/cc/ndk_headers.go b/cc/ndk_headers.go
index 4065128..b8423be 100644
--- a/cc/ndk_headers.go
+++ b/cc/ndk_headers.go
@@ -48,7 +48,7 @@
}
// Returns the NDK base include path for use with sdk_version current. Usable with -I.
-func getCurrentIncludePath(ctx android.ModuleContext) android.OutputPath {
+func getCurrentIncludePath(ctx android.ModuleContext) android.InstallPath {
return getNdkSysrootBase(ctx).Join(ctx, "usr/include")
}
@@ -94,7 +94,7 @@
}
func getHeaderInstallDir(ctx android.ModuleContext, header android.Path, from string,
- to string) android.OutputPath {
+ to string) android.InstallPath {
// Output path is the sysroot base + "usr/include" + to directory + directory component
// of the file without the leading from directory stripped.
//
diff --git a/cc/ndk_sysroot.go b/cc/ndk_sysroot.go
index e39bae5..f6de4ef 100644
--- a/cc/ndk_sysroot.go
+++ b/cc/ndk_sysroot.go
@@ -66,12 +66,12 @@
pctx.Import("android/soong/android")
}
-func getNdkInstallBase(ctx android.PathContext) android.OutputPath {
- return android.PathForOutput(ctx, "ndk")
+func getNdkInstallBase(ctx android.PathContext) android.InstallPath {
+ return android.PathForNdkInstall(ctx)
}
// Returns the main install directory for the NDK sysroot. Usable with --sysroot.
-func getNdkSysrootBase(ctx android.PathContext) android.OutputPath {
+func getNdkSysrootBase(ctx android.PathContext) android.InstallPath {
return getNdkInstallBase(ctx).Join(ctx, "sysroot")
}
diff --git a/cc/object.go b/cc/object.go
index 1f1ac8e..31729a5 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -104,7 +104,7 @@
var outputFile android.Path
builderFlags := flagsToBuilderFlags(flags)
- if len(objs.objFiles) == 1 {
+ if len(objs.objFiles) == 1 && String(object.Properties.Linker_script) == "" {
outputFile = objs.objFiles[0]
if String(object.Properties.Prefix_symbols) != "" {
diff --git a/cc/sanitize.go b/cc/sanitize.go
index c0a7c63..5172fc8 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -465,7 +465,6 @@
if Bool(sanitize.Properties.Sanitize.Fuzzer) {
flags.CFlags = append(flags.CFlags, "-fsanitize=fuzzer-no-link")
- flags.LdFlags = append(flags.LdFlags, "-fsanitize=fuzzer-no-link")
// TODO(b/131771163): LTO and Fuzzer support is mutually incompatible.
_, flags.LdFlags = removeFromList("-flto", flags.LdFlags)
@@ -473,6 +472,12 @@
flags.LdFlags = append(flags.LdFlags, "-fno-lto")
flags.CFlags = append(flags.CFlags, "-fno-lto")
+ // TODO(b/142430592): Upstream linker scripts for sanitizer runtime libraries
+ // discard the sancov_lowest_stack symbol, because it's emulated TLS (and thus
+ // doesn't match the linker script due to the "__emutls_v." prefix).
+ flags.LdFlags = append(flags.LdFlags, "-fno-sanitize-coverage=stack-depth")
+ flags.CFlags = append(flags.CFlags, "-fno-sanitize-coverage=stack-depth")
+
// TODO(b/133876586): Experimental PM breaks sanitizer coverage.
_, flags.CFlags = removeFromList("-fexperimental-new-pass-manager", flags.CFlags)
flags.CFlags = append(flags.CFlags, "-fno-experimental-new-pass-manager")
@@ -860,7 +865,8 @@
} else {
runtimeLibrary = config.ScudoRuntimeLibrary(toolchain)
}
- } else if len(diagSanitizers) > 0 || c.sanitize.Properties.UbsanRuntimeDep {
+ } else if len(diagSanitizers) > 0 || c.sanitize.Properties.UbsanRuntimeDep ||
+ Bool(c.sanitize.Properties.Sanitize.Fuzzer) {
runtimeLibrary = config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain)
}
@@ -878,18 +884,16 @@
// added to libFlags and LOCAL_SHARED_LIBRARIES by cc.Module
if c.staticBinary() {
// static executable gets static runtime libs
- mctx.AddFarVariationDependencies([]blueprint.Variation{
+ mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{
{Mutator: "link", Variation: "static"},
{Mutator: "image", Variation: c.imageVariation()},
- {Mutator: "arch", Variation: mctx.Target().String()},
- }, staticDepTag, runtimeLibrary)
+ }...), staticDepTag, runtimeLibrary)
} else if !c.static() && !c.header() {
// dynamic executable and shared libs get shared runtime libs
- mctx.AddFarVariationDependencies([]blueprint.Variation{
+ mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{
{Mutator: "link", Variation: "shared"},
{Mutator: "image", Variation: c.imageVariation()},
- {Mutator: "arch", Variation: mctx.Target().String()},
- }, earlySharedDepTag, runtimeLibrary)
+ }...), earlySharedDepTag, runtimeLibrary)
}
// static lib does not have dependency to the runtime library. The
// dependency will be added to the executables or shared libs using
diff --git a/cc/stl.go b/cc/stl.go
index 458129c..aa34240 100644
--- a/cc/stl.go
+++ b/cc/stl.go
@@ -221,13 +221,13 @@
if !ctx.toolchain().Bionic() {
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
- flags.extraLibFlags = append(flags.extraLibFlags, "-nodefaultlibs")
- if ctx.staticBinary() {
- flags.extraLibFlags = append(flags.extraLibFlags, hostStaticGccLibs[ctx.Os()]...)
- } else {
- flags.extraLibFlags = append(flags.extraLibFlags, hostDynamicGccLibs[ctx.Os()]...)
- }
+ flags.extraLibFlags = append(flags.extraLibFlags, "-nostdlib++")
if ctx.Windows() {
+ if stl.Properties.SelectedStl == "libc++_static" {
+ // These are transitively needed by libc++_static.
+ flags.extraLibFlags = append(flags.extraLibFlags,
+ "-lmsvcrt", "-lucrt")
+ }
// Use SjLj exceptions for 32-bit. libgcc_eh implements SjLj
// exception model for 32-bit.
if ctx.Arch().ArchType == android.X86 {
@@ -260,12 +260,7 @@
// None or error.
if !ctx.toolchain().Bionic() {
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
- flags.extraLibFlags = append(flags.extraLibFlags, "-nodefaultlibs")
- if ctx.staticBinary() {
- flags.extraLibFlags = append(flags.extraLibFlags, hostStaticGccLibs[ctx.Os()]...)
- } else {
- flags.extraLibFlags = append(flags.extraLibFlags, hostDynamicGccLibs[ctx.Os()]...)
- }
+ flags.extraLibFlags = append(flags.extraLibFlags, "-nostdlib++")
}
default:
panic(fmt.Errorf("Unknown stl: %q", stl.Properties.SelectedStl))
@@ -273,22 +268,3 @@
return flags
}
-
-var hostDynamicGccLibs, hostStaticGccLibs map[android.OsType][]string
-
-func init() {
- hostDynamicGccLibs = map[android.OsType][]string{
- android.Fuchsia: []string{"-lc", "-lunwind"},
- android.Linux: []string{"-lgcc_s", "-lgcc", "-lc", "-lgcc_s", "-lgcc"},
- android.Darwin: []string{"-lc", "-lSystem"},
- android.Windows: []string{"-Wl,--start-group", "-lmingw32", "-lgcc", "-lgcc_eh",
- "-lmoldname", "-lmingwex", "-lmsvcrt", "-lucrt", "-lpthread",
- "-ladvapi32", "-lshell32", "-luser32", "-lkernel32", "-lpsapi",
- "-Wl,--end-group"},
- }
- hostStaticGccLibs = map[android.OsType][]string{
- android.Linux: []string{"-Wl,--start-group", "-lgcc", "-lgcc_eh", "-lc", "-Wl,--end-group"},
- android.Darwin: []string{"NO_STATIC_HOST_BINARIES_ON_DARWIN"},
- android.Windows: []string{"NO_STATIC_HOST_BINARIES_ON_WINDOWS"},
- }
-}
diff --git a/cc/testing.go b/cc/testing.go
index a0b1634..6fa6ea7 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -190,6 +190,7 @@
name: "crtbegin_so",
recovery_available: true,
vendor_available: true,
+ stl: "none",
}
cc_object {
@@ -208,6 +209,7 @@
name: "crtend_so",
recovery_available: true,
vendor_available: true,
+ stl: "none",
}
cc_object {
@@ -239,6 +241,7 @@
os android.OsType) *android.TestContext {
ctx := android.NewTestArchContext()
+ ctx.RegisterModuleType("cc_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(BinaryFactory))
ctx.RegisterModuleType("cc_binary_host", android.ModuleFactoryAdaptor(binaryHostFactory))
ctx.RegisterModuleType("cc_fuzz", android.ModuleFactoryAdaptor(FuzzFactory))
@@ -264,6 +267,7 @@
ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
})
+ ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
ctx.RegisterSingletonType("vndk-snapshot", android.SingletonFactoryAdaptor(VndkSnapshotSingleton))
// add some modules that are required by the compiler and/or linker
@@ -274,6 +278,7 @@
"foo.c": nil,
"foo.lds": nil,
"bar.c": nil,
+ "baz.c": nil,
"baz.o": nil,
"a.proto": nil,
"b.aidl": nil,
diff --git a/cc/vndk_prebuilt.go b/cc/vndk_prebuilt.go
index 8126e4a..2cebb6d 100644
--- a/cc/vndk_prebuilt.go
+++ b/cc/vndk_prebuilt.go
@@ -129,6 +129,18 @@
func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext,
flags Flags, deps PathDeps, objs Objects) android.Path {
+
+ arches := ctx.DeviceConfig().Arches()
+ if len(arches) == 0 || arches[0].ArchType.String() != p.arch() {
+ ctx.Module().SkipInstall()
+ return nil
+ }
+
+ if ctx.DeviceConfig().BinderBitness() != p.binderBit() {
+ ctx.Module().SkipInstall()
+ return nil
+ }
+
if len(p.properties.Srcs) > 0 && p.shared() {
p.libraryDecorator.exportIncludes(ctx)
p.libraryDecorator.reexportSystemDirs(p.properties.Export_system_include_dirs...)
@@ -136,6 +148,8 @@
// current VNDK prebuilts are only shared libs.
return p.singleSourcePath(ctx)
}
+
+ ctx.Module().SkipInstall()
return nil
}
diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go
index c378f09..511b840 100644
--- a/dexpreopt/dexpreopt.go
+++ b/dexpreopt/dexpreopt.go
@@ -248,7 +248,7 @@
odexPath := module.BuildPath.InSameDir(ctx, "oat", arch.String(), pathtools.ReplaceExtension(base, "odex"))
odexInstallPath := toOdexPath(module.DexLocation)
if odexOnSystemOther(module, global) {
- odexInstallPath = strings.Replace(odexInstallPath, SystemPartition, SystemOtherPartition, 1)
+ odexInstallPath = filepath.Join(SystemOtherPartition, odexInstallPath)
}
vdexPath := odexPath.ReplaceExtension(ctx, "vdex")
@@ -581,7 +581,8 @@
}
for _, f := range global.PatternsOnSystemOther {
- if makefileMatch(filepath.Join(SystemPartition, f), dexLocation) {
+ // See comment of SYSTEM_OTHER_ODEX_FILTER for details on the matching.
+ if makefileMatch("/"+f, dexLocation) || makefileMatch(filepath.Join(SystemPartition, f), dexLocation) {
return true
}
}
diff --git a/dexpreopt/dexpreopt_test.go b/dexpreopt/dexpreopt_test.go
index 7f1fe42..bf692fe 100644
--- a/dexpreopt/dexpreopt_test.go
+++ b/dexpreopt/dexpreopt_test.go
@@ -16,17 +16,30 @@
import (
"android/soong/android"
+ "fmt"
"reflect"
"strings"
"testing"
)
-func testModuleConfig(ctx android.PathContext) ModuleConfig {
+func testSystemModuleConfig(ctx android.PathContext, name string) ModuleConfig {
+ return testModuleConfig(ctx, name, "system")
+}
+
+func testSystemProductModuleConfig(ctx android.PathContext, name string) ModuleConfig {
+ return testModuleConfig(ctx, name, "system/product")
+}
+
+func testProductModuleConfig(ctx android.PathContext, name string) ModuleConfig {
+ return testModuleConfig(ctx, name, "product")
+}
+
+func testModuleConfig(ctx android.PathContext, name, partition string) ModuleConfig {
return ModuleConfig{
- Name: "test",
- DexLocation: "/system/app/test/test.apk",
- BuildPath: android.PathForOutput(ctx, "test/test.apk"),
- DexPath: android.PathForOutput(ctx, "test/dex/test.jar"),
+ Name: name,
+ DexLocation: fmt.Sprintf("/%s/app/test/%s.apk", partition, name),
+ BuildPath: android.PathForOutput(ctx, fmt.Sprintf("%s/%s.apk", name, name)),
+ DexPath: android.PathForOutput(ctx, fmt.Sprintf("%s/dex/%s.jar", name, name)),
UncompressedDex: false,
HasApkLibraries: false,
PreoptFlags: nil,
@@ -46,14 +59,14 @@
ForceCreateAppImage: false,
PresignedPrebuilt: false,
NoStripping: false,
- StripInputPath: android.PathForOutput(ctx, "unstripped/test.apk"),
- StripOutputPath: android.PathForOutput(ctx, "stripped/test.apk"),
+ StripInputPath: android.PathForOutput(ctx, fmt.Sprintf("unstripped/%s.apk", name)),
+ StripOutputPath: android.PathForOutput(ctx, fmt.Sprintf("stripped/%s.apk", name)),
}
}
func TestDexPreopt(t *testing.T) {
ctx := android.PathContextForTesting(android.TestConfig("out", nil), nil)
- global, module := GlobalConfigForTests(ctx), testModuleConfig(ctx)
+ global, module := GlobalConfigForTests(ctx), testSystemModuleConfig(ctx, "test")
rule, err := GenerateDexpreoptRule(ctx, global, module)
if err != nil {
@@ -73,7 +86,7 @@
func TestDexPreoptStrip(t *testing.T) {
// Test that we panic if we strip in a configuration where stripping is not allowed.
ctx := android.PathContextForTesting(android.TestConfig("out", nil), nil)
- global, module := GlobalConfigForTests(ctx), testModuleConfig(ctx)
+ global, module := GlobalConfigForTests(ctx), testSystemModuleConfig(ctx, "test")
global.NeverAllowStripping = true
module.NoStripping = false
@@ -86,29 +99,64 @@
func TestDexPreoptSystemOther(t *testing.T) {
ctx := android.PathContextForTesting(android.TestConfig("out", nil), nil)
- global, module := GlobalConfigForTests(ctx), testModuleConfig(ctx)
+ global := GlobalConfigForTests(ctx)
+ systemModule := testSystemModuleConfig(ctx, "Stest")
+ systemProductModule := testSystemProductModuleConfig(ctx, "SPtest")
+ productModule := testProductModuleConfig(ctx, "Ptest")
global.HasSystemOther = true
- global.PatternsOnSystemOther = []string{"app/%"}
- rule, err := GenerateDexpreoptRule(ctx, global, module)
- if err != nil {
- t.Fatal(err)
+ type moduleTest struct {
+ module ModuleConfig
+ expectedPartition string
+ }
+ tests := []struct {
+ patterns []string
+ moduleTests []moduleTest
+ }{
+ {
+ patterns: []string{"app/%"},
+ moduleTests: []moduleTest{
+ {module: systemModule, expectedPartition: "system_other/system"},
+ {module: systemProductModule, expectedPartition: "system/product"},
+ {module: productModule, expectedPartition: "product"},
+ },
+ },
+ {
+ patterns: []string{"app/%", "product/app/%"},
+ moduleTests: []moduleTest{
+ {module: systemModule, expectedPartition: "system_other/system"},
+ {module: systemProductModule, expectedPartition: "system_other/system/product"},
+ {module: productModule, expectedPartition: "system_other/product"},
+ },
+ },
}
- wantInstalls := android.RuleBuilderInstalls{
- {android.PathForOutput(ctx, "test/oat/arm/package.odex"), "/system_other/app/test/oat/arm/test.odex"},
- {android.PathForOutput(ctx, "test/oat/arm/package.vdex"), "/system_other/app/test/oat/arm/test.vdex"},
+ for _, test := range tests {
+ global.PatternsOnSystemOther = test.patterns
+ for _, mt := range test.moduleTests {
+ rule, err := GenerateDexpreoptRule(ctx, global, mt.module)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ name := mt.module.Name
+ wantInstalls := android.RuleBuilderInstalls{
+ {android.PathForOutput(ctx, name+"/oat/arm/package.odex"), fmt.Sprintf("/%s/app/test/oat/arm/%s.odex", mt.expectedPartition, name)},
+ {android.PathForOutput(ctx, name+"/oat/arm/package.vdex"), fmt.Sprintf("/%s/app/test/oat/arm/%s.vdex", mt.expectedPartition, name)},
+ }
+
+ if rule.Installs().String() != wantInstalls.String() {
+ t.Errorf("\npatterns: %v\nwant installs:\n %v\ngot:\n %v", test.patterns, wantInstalls, rule.Installs())
+ }
+ }
}
- if rule.Installs().String() != wantInstalls.String() {
- t.Errorf("\nwant installs:\n %v\ngot:\n %v", wantInstalls, rule.Installs())
- }
}
func TestDexPreoptProfile(t *testing.T) {
ctx := android.PathContextForTesting(android.TestConfig("out", nil), nil)
- global, module := GlobalConfigForTests(ctx), testModuleConfig(ctx)
+ global, module := GlobalConfigForTests(ctx), testSystemModuleConfig(ctx, "test")
module.ProfileClassListing = android.OptionalPathForPath(android.PathForTesting("profile"))
@@ -156,7 +204,7 @@
t.Run(test.name, func(t *testing.T) {
ctx := android.PathContextForTesting(android.TestConfig("out", nil), nil)
- global, module := GlobalConfigForTests(ctx), testModuleConfig(ctx)
+ global, module := GlobalConfigForTests(ctx), testSystemModuleConfig(ctx, "test")
test.setup(&global, &module)
diff --git a/genrule/genrule.go b/genrule/genrule.go
index b8b0e01..a7c5d65 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -17,6 +17,7 @@
import (
"fmt"
"io"
+ "strconv"
"strings"
"github.com/google/blueprint"
@@ -37,11 +38,21 @@
var (
pctx = android.NewPackageContext("android/soong/genrule")
+
+ gensrcsMerge = pctx.AndroidStaticRule("gensrcsMerge", blueprint.RuleParams{
+ Command: "${soongZip} -o ${tmpZip} @${tmpZip}.rsp && ${zipSync} -d ${genDir} ${tmpZip}",
+ CommandDeps: []string{"${soongZip}", "${zipSync}"},
+ Rspfile: "${tmpZip}.rsp",
+ RspfileContent: "${zipArgs}",
+ }, "tmpZip", "genDir", "zipArgs")
)
func init() {
pctx.Import("android/soong/android")
pctx.HostBinToolVariable("sboxCmd", "sbox")
+
+ pctx.HostBinToolVariable("soongZip", "soong_zip")
+ pctx.HostBinToolVariable("zipSync", "zipsync")
}
type SourceFileGenerator interface {
@@ -112,9 +123,9 @@
taskGenerator taskFunc
- deps android.Paths
- rule blueprint.Rule
- rawCommand string
+ deps android.Paths
+ rule blueprint.Rule
+ rawCommands []string
exportedIncludeDirs android.Paths
@@ -122,15 +133,20 @@
outputDeps android.Paths
subName string
+ subDir string
}
-type taskFunc func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) generateTask
+type taskFunc func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) []generateTask
type generateTask struct {
in android.Paths
out android.WritablePaths
+ copyTo android.WritablePaths
+ genDir android.WritablePath
sandboxOuts []string
cmd string
+ shard int
+ shards int
}
func (g *Module) GeneratedSourceFiles() android.Paths {
@@ -156,9 +172,7 @@
if m := android.SrcIsModule(tool); m != "" {
tool = m
}
- ctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: ctx.Config().BuildOsVariant},
- }, tag, tool)
+ ctx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), tag, tool)
}
}
}
@@ -169,10 +183,10 @@
if len(g.properties.Export_include_dirs) > 0 {
for _, dir := range g.properties.Export_include_dirs {
g.exportedIncludeDirs = append(g.exportedIncludeDirs,
- android.PathForModuleGen(ctx, ctx.ModuleDir(), dir))
+ android.PathForModuleGen(ctx, g.subDir, ctx.ModuleDir(), dir))
}
} else {
- g.exportedIncludeDirs = append(g.exportedIncludeDirs, android.PathForModuleGen(ctx, ""))
+ g.exportedIncludeDirs = append(g.exportedIncludeDirs, android.PathForModuleGen(ctx, g.subDir))
}
locationLabels := map[string][]string{}
@@ -277,120 +291,170 @@
}
}
- task := g.taskGenerator(ctx, String(g.properties.Cmd), srcFiles)
+ var copyFrom android.Paths
+ var outputFiles android.WritablePaths
+ var zipArgs strings.Builder
- for _, out := range task.out {
- addLocationLabel(out.Rel(), []string{filepath.Join("__SBOX_OUT_DIR__", out.Rel())})
- }
-
- referencedDepfile := false
-
- rawCommand, err := android.ExpandNinjaEscaped(task.cmd, func(name string) (string, bool, error) {
- // report the error directly without returning an error to android.Expand to catch multiple errors in a
- // single run
- reportError := func(fmt string, args ...interface{}) (string, bool, error) {
- ctx.PropertyErrorf("cmd", fmt, args...)
- return "SOONG_ERROR", false, nil
+ for _, task := range g.taskGenerator(ctx, String(g.properties.Cmd), srcFiles) {
+ for _, out := range task.out {
+ addLocationLabel(out.Rel(), []string{filepath.Join("__SBOX_OUT_DIR__", out.Rel())})
}
- switch name {
- case "location":
- if len(g.properties.Tools) == 0 && len(g.properties.Tool_files) == 0 {
- return reportError("at least one `tools` or `tool_files` is required if $(location) is used")
+ referencedDepfile := false
+
+ rawCommand, err := android.ExpandNinjaEscaped(task.cmd, func(name string) (string, bool, error) {
+ // report the error directly without returning an error to android.Expand to catch multiple errors in a
+ // single run
+ reportError := func(fmt string, args ...interface{}) (string, bool, error) {
+ ctx.PropertyErrorf("cmd", fmt, args...)
+ return "SOONG_ERROR", false, nil
}
- paths := locationLabels[firstLabel]
- if len(paths) == 0 {
- return reportError("default label %q has no files", firstLabel)
- } else if len(paths) > 1 {
- return reportError("default label %q has multiple files, use $(locations %s) to reference it",
- firstLabel, firstLabel)
- }
- return locationLabels[firstLabel][0], false, nil
- case "in":
- return "${in}", true, nil
- case "out":
- return "__SBOX_OUT_FILES__", false, nil
- case "depfile":
- referencedDepfile = true
- if !Bool(g.properties.Depfile) {
- return reportError("$(depfile) used without depfile property")
- }
- return "__SBOX_DEPFILE__", false, nil
- case "genDir":
- return "__SBOX_OUT_DIR__", false, nil
- default:
- if strings.HasPrefix(name, "location ") {
- label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
- if paths, ok := locationLabels[label]; ok {
- if len(paths) == 0 {
- return reportError("label %q has no files", label)
- } else if len(paths) > 1 {
- return reportError("label %q has multiple files, use $(locations %s) to reference it",
- label, label)
- }
- return paths[0], false, nil
- } else {
- return reportError("unknown location label %q", label)
+
+ switch name {
+ case "location":
+ if len(g.properties.Tools) == 0 && len(g.properties.Tool_files) == 0 {
+ return reportError("at least one `tools` or `tool_files` is required if $(location) is used")
}
- } else if strings.HasPrefix(name, "locations ") {
- label := strings.TrimSpace(strings.TrimPrefix(name, "locations "))
- if paths, ok := locationLabels[label]; ok {
- if len(paths) == 0 {
- return reportError("label %q has no files", label)
- }
- return strings.Join(paths, " "), false, nil
- } else {
- return reportError("unknown locations label %q", label)
+ paths := locationLabels[firstLabel]
+ if len(paths) == 0 {
+ return reportError("default label %q has no files", firstLabel)
+ } else if len(paths) > 1 {
+ return reportError("default label %q has multiple files, use $(locations %s) to reference it",
+ firstLabel, firstLabel)
}
- } else {
- return reportError("unknown variable '$(%s)'", name)
+ return locationLabels[firstLabel][0], false, nil
+ case "in":
+ return "${in}", true, nil
+ case "out":
+ return "__SBOX_OUT_FILES__", false, nil
+ case "depfile":
+ referencedDepfile = true
+ if !Bool(g.properties.Depfile) {
+ return reportError("$(depfile) used without depfile property")
+ }
+ return "__SBOX_DEPFILE__", false, nil
+ case "genDir":
+ return "__SBOX_OUT_DIR__", false, nil
+ default:
+ if strings.HasPrefix(name, "location ") {
+ label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
+ if paths, ok := locationLabels[label]; ok {
+ if len(paths) == 0 {
+ return reportError("label %q has no files", label)
+ } else if len(paths) > 1 {
+ return reportError("label %q has multiple files, use $(locations %s) to reference it",
+ label, label)
+ }
+ return paths[0], false, nil
+ } else {
+ return reportError("unknown location label %q", label)
+ }
+ } else if strings.HasPrefix(name, "locations ") {
+ label := strings.TrimSpace(strings.TrimPrefix(name, "locations "))
+ if paths, ok := locationLabels[label]; ok {
+ if len(paths) == 0 {
+ return reportError("label %q has no files", label)
+ }
+ return strings.Join(paths, " "), false, nil
+ } else {
+ return reportError("unknown locations label %q", label)
+ }
+ } else {
+ return reportError("unknown variable '$(%s)'", name)
+ }
}
+ })
+
+ if err != nil {
+ ctx.PropertyErrorf("cmd", "%s", err.Error())
+ return
}
- })
- if err != nil {
- ctx.PropertyErrorf("cmd", "%s", err.Error())
- return
+ if Bool(g.properties.Depfile) && !referencedDepfile {
+ ctx.PropertyErrorf("cmd", "specified depfile=true but did not include a reference to '${depfile}' in cmd")
+ return
+ }
+
+ // tell the sbox command which directory to use as its sandbox root
+ buildDir := android.PathForOutput(ctx).String()
+ sandboxPath := shared.TempDirForOutDir(buildDir)
+
+ // recall that Sprintf replaces percent sign expressions, whereas dollar signs expressions remain as written,
+ // to be replaced later by ninja_strings.go
+ depfilePlaceholder := ""
+ if Bool(g.properties.Depfile) {
+ depfilePlaceholder = "$depfileArgs"
+ }
+
+ // Escape the command for the shell
+ rawCommand = "'" + strings.Replace(rawCommand, "'", `'\''`, -1) + "'"
+ g.rawCommands = append(g.rawCommands, rawCommand)
+ sandboxCommand := fmt.Sprintf("rm -rf %s && $sboxCmd --sandbox-path %s --output-root %s -c %s %s $allouts",
+ task.genDir, sandboxPath, task.genDir, rawCommand, depfilePlaceholder)
+
+ ruleParams := blueprint.RuleParams{
+ Command: sandboxCommand,
+ CommandDeps: []string{"$sboxCmd"},
+ }
+ args := []string{"allouts"}
+ if Bool(g.properties.Depfile) {
+ ruleParams.Deps = blueprint.DepsGCC
+ args = append(args, "depfileArgs")
+ }
+ name := "generator"
+ if task.shards > 1 {
+ name += strconv.Itoa(task.shard)
+ }
+ rule := ctx.Rule(pctx, name, ruleParams, args...)
+
+ g.generateSourceFile(ctx, task, rule)
+
+ if len(task.copyTo) > 0 {
+ outputFiles = append(outputFiles, task.copyTo...)
+ copyFrom = append(copyFrom, task.out.Paths()...)
+ zipArgs.WriteString(" -C " + task.genDir.String())
+ zipArgs.WriteString(android.JoinWithPrefix(task.out.Strings(), " -f "))
+ } else {
+ outputFiles = append(outputFiles, task.out...)
+ }
}
- if Bool(g.properties.Depfile) && !referencedDepfile {
- ctx.PropertyErrorf("cmd", "specified depfile=true but did not include a reference to '${depfile}' in cmd")
+ if len(copyFrom) > 0 {
+ ctx.Build(pctx, android.BuildParams{
+ Rule: gensrcsMerge,
+ Implicits: copyFrom,
+ Outputs: outputFiles,
+ Args: map[string]string{
+ "zipArgs": zipArgs.String(),
+ "tmpZip": android.PathForModuleGen(ctx, g.subDir+".zip").String(),
+ "genDir": android.PathForModuleGen(ctx, g.subDir).String(),
+ },
+ })
}
- // tell the sbox command which directory to use as its sandbox root
- buildDir := android.PathForOutput(ctx).String()
- sandboxPath := shared.TempDirForOutDir(buildDir)
+ g.outputFiles = outputFiles.Paths()
- // recall that Sprintf replaces percent sign expressions, whereas dollar signs expressions remain as written,
- // to be replaced later by ninja_strings.go
- depfilePlaceholder := ""
- if Bool(g.properties.Depfile) {
- depfilePlaceholder = "$depfileArgs"
+ // For <= 6 outputs, just embed those directly in the users. Right now, that covers >90% of
+ // the genrules on AOSP. That will make things simpler to look at the graph in the common
+ // case. For larger sets of outputs, inject a phony target in between to limit ninja file
+ // growth.
+ if len(g.outputFiles) <= 6 {
+ g.outputDeps = g.outputFiles
+ } else {
+ phonyFile := android.PathForModuleGen(ctx, "genrule-phony")
+
+ ctx.Build(pctx, android.BuildParams{
+ Rule: blueprint.Phony,
+ Output: phonyFile,
+ Inputs: g.outputFiles,
+ })
+
+ g.outputDeps = android.Paths{phonyFile}
}
- genDir := android.PathForModuleGen(ctx)
- // Escape the command for the shell
- rawCommand = "'" + strings.Replace(rawCommand, "'", `'\''`, -1) + "'"
- g.rawCommand = rawCommand
- sandboxCommand := fmt.Sprintf("$sboxCmd --sandbox-path %s --output-root %s -c %s %s $allouts",
- sandboxPath, genDir, rawCommand, depfilePlaceholder)
-
- ruleParams := blueprint.RuleParams{
- Command: sandboxCommand,
- CommandDeps: []string{"$sboxCmd"},
- }
- args := []string{"allouts"}
- if Bool(g.properties.Depfile) {
- ruleParams.Deps = blueprint.DepsGCC
- args = append(args, "depfileArgs")
- }
- g.rule = ctx.Rule(pctx, "generator", ruleParams, args...)
-
- g.generateSourceFile(ctx, task)
-
}
-func (g *Module) generateSourceFile(ctx android.ModuleContext, task generateTask) {
+func (g *Module) generateSourceFile(ctx android.ModuleContext, task generateTask, rule blueprint.Rule) {
desc := "generate"
if len(task.out) == 0 {
ctx.ModuleErrorf("must have at least one output file")
@@ -405,9 +469,13 @@
depFile = android.PathForModuleGen(ctx, task.out[0].Rel()+".d")
}
+ if task.shards > 1 {
+ desc += " " + strconv.Itoa(task.shard)
+ }
+
params := android.BuildParams{
- Rule: g.rule,
- Description: "generate",
+ Rule: rule,
+ Description: desc,
Output: task.out[0],
ImplicitOutputs: task.out[1:],
Inputs: task.in,
@@ -422,28 +490,6 @@
}
ctx.Build(pctx, params)
-
- for _, outputFile := range task.out {
- g.outputFiles = append(g.outputFiles, outputFile)
- }
-
- // For <= 6 outputs, just embed those directly in the users. Right now, that covers >90% of
- // the genrules on AOSP. That will make things simpler to look at the graph in the common
- // case. For larger sets of outputs, inject a phony target in between to limit ninja file
- // growth.
- if len(task.out) <= 6 {
- g.outputDeps = g.outputFiles
- } else {
- phonyFile := android.PathForModuleGen(ctx, "genrule-phony")
-
- ctx.Build(pctx, android.BuildParams{
- Rule: blueprint.Phony,
- Output: phonyFile,
- Inputs: g.outputFiles,
- })
-
- g.outputDeps = android.Paths{phonyFile}
- }
}
// Collect information for opening IDE project files in java/jdeps.go.
@@ -465,7 +511,7 @@
SubName: g.subName,
Extra: []android.AndroidMkExtraFunc{
func(w io.Writer, outputFile android.Path) {
- fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES :=", strings.Join(g.outputFiles.Strings(), " "))
+ fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES :=", strings.Join(g.outputDeps.Strings(), " "))
},
},
Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
@@ -502,47 +548,80 @@
func NewGenSrcs() *Module {
properties := &genSrcsProperties{}
- taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) generateTask {
- commands := []string{}
- outFiles := android.WritablePaths{}
- genDir := android.PathForModuleGen(ctx)
- sandboxOuts := []string{}
- for _, in := range srcFiles {
- outFile := android.GenPathWithExt(ctx, "", in, String(properties.Output_extension))
- outFiles = append(outFiles, outFile)
+ taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) []generateTask {
+ genDir := android.PathForModuleGen(ctx, "gensrcs")
+ shardSize := defaultShardSize
+ if s := properties.Shard_size; s != nil {
+ shardSize = int(*s)
+ }
- sandboxOutfile := pathToSandboxOut(outFile, genDir)
- sandboxOuts = append(sandboxOuts, sandboxOutfile)
+ shards := android.ShardPaths(srcFiles, shardSize)
+ var generateTasks []generateTask
- command, err := android.Expand(rawCommand, func(name string) (string, error) {
- switch name {
- case "in":
- return in.String(), nil
- case "out":
- return sandboxOutfile, nil
- default:
- return "$(" + name + ")", nil
- }
- })
- if err != nil {
- ctx.PropertyErrorf("cmd", err.Error())
+ for i, shard := range shards {
+ var commands []string
+ var outFiles android.WritablePaths
+ var copyTo android.WritablePaths
+ var shardDir android.WritablePath
+ var sandboxOuts []string
+
+ if len(shards) > 1 {
+ shardDir = android.PathForModuleGen(ctx, strconv.Itoa(i))
+ } else {
+ shardDir = genDir
}
- // escape the command in case for example it contains '#', an odd number of '"', etc
- command = fmt.Sprintf("bash -c %v", proptools.ShellEscape(command))
- commands = append(commands, command)
- }
- fullCommand := strings.Join(commands, " && ")
+ for _, in := range shard {
+ outFile := android.GenPathWithExt(ctx, "gensrcs", in, String(properties.Output_extension))
+ sandboxOutfile := pathToSandboxOut(outFile, genDir)
- return generateTask{
- in: srcFiles,
- out: outFiles,
- sandboxOuts: sandboxOuts,
- cmd: fullCommand,
+ if len(shards) > 1 {
+ shardFile := android.GenPathWithExt(ctx, strconv.Itoa(i), in, String(properties.Output_extension))
+ copyTo = append(copyTo, outFile)
+ outFile = shardFile
+ }
+
+ outFiles = append(outFiles, outFile)
+ sandboxOuts = append(sandboxOuts, sandboxOutfile)
+
+ command, err := android.Expand(rawCommand, func(name string) (string, error) {
+ switch name {
+ case "in":
+ return in.String(), nil
+ case "out":
+ return sandboxOutfile, nil
+ default:
+ return "$(" + name + ")", nil
+ }
+ })
+ if err != nil {
+ ctx.PropertyErrorf("cmd", err.Error())
+ }
+
+ // escape the command in case for example it contains '#', an odd number of '"', etc
+ command = fmt.Sprintf("bash -c %v", proptools.ShellEscape(command))
+ commands = append(commands, command)
+ }
+ fullCommand := strings.Join(commands, " && ")
+
+ generateTasks = append(generateTasks, generateTask{
+ in: shard,
+ out: outFiles,
+ copyTo: copyTo,
+ genDir: shardDir,
+ sandboxOuts: sandboxOuts,
+ cmd: fullCommand,
+ shard: i,
+ shards: len(shards),
+ })
}
+
+ return generateTasks
}
- return generatorFactory(taskGenerator, properties)
+ g := generatorFactory(taskGenerator, properties)
+ g.subDir = "gensrcs"
+ return g
}
func GenSrcsFactory() android.Module {
@@ -554,12 +633,17 @@
type genSrcsProperties struct {
// extension that will be substituted for each output file
Output_extension *string
+
+ // maximum number of files that will be passed on a single command line.
+ Shard_size *int64
}
+const defaultShardSize = 100
+
func NewGenRule() *Module {
properties := &genRuleProperties{}
- taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) generateTask {
+ taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) []generateTask {
outs := make(android.WritablePaths, len(properties.Out))
sandboxOuts := make([]string, len(properties.Out))
genDir := android.PathForModuleGen(ctx)
@@ -567,12 +651,13 @@
outs[i] = android.PathForModuleGen(ctx, out)
sandboxOuts[i] = pathToSandboxOut(outs[i], genDir)
}
- return generateTask{
+ return []generateTask{{
in: srcFiles,
out: outs,
+ genDir: android.PathForModuleGen(ctx),
sandboxOuts: sandboxOuts,
cmd: rawCommand,
- }
+ }}
}
return generatorFactory(taskGenerator, properties)
diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go
index 0b6952f..5ac0e8c 100644
--- a/genrule/genrule_test.go
+++ b/genrule/genrule_test.go
@@ -57,6 +57,7 @@
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
ctx.RegisterModuleType("genrule", android.ModuleFactoryAdaptor(GenRuleFactory))
+ ctx.RegisterModuleType("gensrcs", android.ModuleFactoryAdaptor(GenSrcsFactory))
ctx.RegisterModuleType("genrule_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
ctx.RegisterModuleType("tool", android.ModuleFactoryAdaptor(toolFactory))
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
@@ -109,6 +110,9 @@
"tool_file2": nil,
"in1": nil,
"in2": nil,
+ "in1.txt": nil,
+ "in2.txt": nil,
+ "in3.txt": nil,
}
for k, v := range fs {
@@ -491,11 +495,102 @@
}
gen := ctx.ModuleForTests("gen", "").Module().(*Module)
- if g, w := gen.rawCommand, "'"+test.expect+"'"; w != g {
+ if g, w := gen.rawCommands[0], "'"+test.expect+"'"; w != g {
t.Errorf("want %q, got %q", w, g)
}
})
}
+}
+
+func TestGenSrcs(t *testing.T) {
+ testcases := []struct {
+ name string
+ prop string
+
+ allowMissingDependencies bool
+
+ err string
+ cmds []string
+ deps []string
+ files []string
+ }{
+ {
+ name: "gensrcs",
+ prop: `
+ tools: ["tool"],
+ srcs: ["in1.txt", "in2.txt"],
+ cmd: "$(location) $(in) > $(out)",
+ `,
+ cmds: []string{
+ "'bash -c '\\''out/tool in1.txt > __SBOX_OUT_DIR__/in1.h'\\'' && bash -c '\\''out/tool in2.txt > __SBOX_OUT_DIR__/in2.h'\\'''",
+ },
+ deps: []string{buildDir + "/.intermediates/gen/gen/gensrcs/in1.h", buildDir + "/.intermediates/gen/gen/gensrcs/in2.h"},
+ files: []string{buildDir + "/.intermediates/gen/gen/gensrcs/in1.h", buildDir + "/.intermediates/gen/gen/gensrcs/in2.h"},
+ },
+ {
+ name: "shards",
+ prop: `
+ tools: ["tool"],
+ srcs: ["in1.txt", "in2.txt", "in3.txt"],
+ cmd: "$(location) $(in) > $(out)",
+ shard_size: 2,
+ `,
+ cmds: []string{
+ "'bash -c '\\''out/tool in1.txt > __SBOX_OUT_DIR__/in1.h'\\'' && bash -c '\\''out/tool in2.txt > __SBOX_OUT_DIR__/in2.h'\\'''",
+ "'bash -c '\\''out/tool in3.txt > __SBOX_OUT_DIR__/in3.h'\\'''",
+ },
+ deps: []string{buildDir + "/.intermediates/gen/gen/gensrcs/in1.h", buildDir + "/.intermediates/gen/gen/gensrcs/in2.h", buildDir + "/.intermediates/gen/gen/gensrcs/in3.h"},
+ files: []string{buildDir + "/.intermediates/gen/gen/gensrcs/in1.h", buildDir + "/.intermediates/gen/gen/gensrcs/in2.h", buildDir + "/.intermediates/gen/gen/gensrcs/in3.h"},
+ },
+ }
+
+ for _, test := range testcases {
+ t.Run(test.name, func(t *testing.T) {
+ config := android.TestArchConfig(buildDir, nil)
+ bp := "gensrcs {\n"
+ bp += `name: "gen",` + "\n"
+ bp += `output_extension: "h",` + "\n"
+ bp += test.prop
+ bp += "}\n"
+
+ ctx := testContext(config, bp, nil)
+
+ _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
+ if errs == nil {
+ _, errs = ctx.PrepareBuildActions(config)
+ }
+ if errs == nil && test.err != "" {
+ t.Fatalf("want error %q, got no error", test.err)
+ } else if errs != nil && test.err == "" {
+ android.FailIfErrored(t, errs)
+ } else if test.err != "" {
+ if len(errs) != 1 {
+ t.Errorf("want 1 error, got %d errors:", len(errs))
+ for _, err := range errs {
+ t.Errorf(" %s", err.Error())
+ }
+ t.FailNow()
+ }
+ if !strings.Contains(errs[0].Error(), test.err) {
+ t.Fatalf("want %q, got %q", test.err, errs[0].Error())
+ }
+ return
+ }
+
+ gen := ctx.ModuleForTests("gen", "").Module().(*Module)
+ if g, w := gen.rawCommands, test.cmds; !reflect.DeepEqual(w, g) {
+ t.Errorf("want %q, got %q", w, g)
+ }
+
+ if g, w := gen.outputDeps.Strings(), test.deps; !reflect.DeepEqual(w, g) {
+ t.Errorf("want deps %q, got %q", w, g)
+ }
+
+ if g, w := gen.outputFiles.Strings(), test.files; !reflect.DeepEqual(w, g) {
+ t.Errorf("want files %q, got %q", w, g)
+ }
+ })
+ }
}
@@ -529,8 +624,8 @@
gen := ctx.ModuleForTests("gen", "").Module().(*Module)
expectedCmd := "'cp ${in} __SBOX_OUT_FILES__'"
- if gen.rawCommand != expectedCmd {
- t.Errorf("Expected cmd: %q, actual: %q", expectedCmd, gen.rawCommand)
+ if gen.rawCommands[0] != expectedCmd {
+ t.Errorf("Expected cmd: %q, actual: %q", expectedCmd, gen.rawCommands[0])
}
expectedSrcs := []string{"in1"}
diff --git a/go.mod b/go.mod
index cc328e0..1483a31 100644
--- a/go.mod
+++ b/go.mod
@@ -7,3 +7,5 @@
replace github.com/golang/protobuf v0.0.0 => ../../external/golang-protobuf
replace github.com/google/blueprint v0.0.0 => ../blueprint
+
+go 1.13
diff --git a/java/aar.go b/java/aar.go
index 6a883d3..6426ac3 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -520,6 +520,10 @@
return proptools.StringDefault(a.properties.Sdk_version, defaultSdkVersion(a))
}
+func (a *AARImport) systemModules() string {
+ return ""
+}
+
func (a *AARImport) minSdkVersion() string {
if a.properties.Min_sdk_version != nil {
return *a.properties.Min_sdk_version
diff --git a/java/androidmk.go b/java/androidmk.go
index bc61297..7927acf 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -145,7 +145,7 @@
}
func (prebuilt *Import) AndroidMkEntries() android.AndroidMkEntries {
- if !prebuilt.IsForPlatform() || !prebuilt.ContainingSdk().IsCurrentVersion() {
+ if !prebuilt.IsForPlatform() || !prebuilt.ContainingSdk().Unversioned() {
return android.AndroidMkEntries{
Disabled: true,
}
@@ -317,7 +317,7 @@
entries.SetPath("LOCAL_FULL_MANIFEST_FILE", app.manifestPath)
- entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", Bool(app.appProperties.Privileged))
+ entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", app.Privileged())
entries.SetPath("LOCAL_CERTIFICATE", app.certificate.Pem)
entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", app.getOverriddenPackages()...)
@@ -598,6 +598,18 @@
fmt.Fprintln(w, "droidcore: checkapi")
}
}
+ if dstubs.apiLintTimestamp != nil {
+ fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-api-lint")
+ fmt.Fprintln(w, dstubs.Name()+"-api-lint:",
+ dstubs.apiLintTimestamp.String())
+
+ fmt.Fprintln(w, ".PHONY: checkapi")
+ fmt.Fprintln(w, "checkapi:",
+ dstubs.apiLintTimestamp.String())
+
+ fmt.Fprintln(w, ".PHONY: droidcore")
+ fmt.Fprintln(w, "droidcore: checkapi")
+ }
if dstubs.checkNullabilityWarningsTimestamp != nil {
fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-nullability-warnings")
fmt.Fprintln(w, dstubs.Name()+"-check-nullability-warnings:",
@@ -618,7 +630,7 @@
Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
func(entries *android.AndroidMkEntries) {
- entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", Bool(a.properties.Privileged))
+ entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", a.Privileged())
if a.certificate != nil {
entries.SetPath("LOCAL_CERTIFICATE", a.certificate.Pem)
} else {
diff --git a/java/app.go b/java/app.go
index 3ee8b8d..3dbcbf4 100644
--- a/java/app.go
+++ b/java/app.go
@@ -126,7 +126,7 @@
// the install APK name is normally the same as the module name, but can be overridden with PRODUCT_PACKAGE_NAME_OVERRIDES.
installApkName string
- installDir android.OutputPath
+ installDir android.InstallPath
onDeviceDir string
@@ -167,10 +167,8 @@
embedJni := a.shouldEmbedJnis(ctx)
for _, jniTarget := range ctx.MultiTargets() {
- variation := []blueprint.Variation{
- {Mutator: "arch", Variation: jniTarget.String()},
- {Mutator: "link", Variation: "shared"},
- }
+ variation := append(jniTarget.Variations(),
+ blueprint.Variation{Mutator: "link", Variation: "shared"})
tag := &jniDependencyTag{
target: jniTarget,
}
@@ -230,7 +228,7 @@
// Uncompress dex in APKs of privileged apps (even for unbundled builds, they may
// be preinstalled as prebuilts).
- if ctx.Config().UncompressPrivAppDex() && Bool(a.appProperties.Privileged) {
+ if ctx.Config().UncompressPrivAppDex() && a.Privileged() {
return true
}
@@ -318,7 +316,7 @@
if ctx.ModuleName() == "framework-res" {
// framework-res.apk is installed as system/framework/framework-res.apk
installDir = "framework"
- } else if Bool(a.appProperties.Privileged) {
+ } else if a.Privileged() {
installDir = filepath.Join("priv-app", a.installApkName)
} else {
installDir = filepath.Join("app", a.installApkName)
@@ -444,7 +442,7 @@
if ctx.ModuleName() == "framework-res" {
// framework-res.apk is installed as system/framework/framework-res.apk
a.installDir = android.PathForModuleInstall(ctx, "framework")
- } else if Bool(a.appProperties.Privileged) {
+ } else if a.Privileged() {
a.installDir = android.PathForModuleInstall(ctx, "priv-app", a.installApkName)
} else if ctx.InstallInTestcases() {
a.installDir = android.PathForModuleInstall(ctx, a.installApkName)
@@ -557,6 +555,10 @@
return a.Library.OutputFiles(tag)
}
+func (a *AndroidApp) Privileged() bool {
+ return Bool(a.appProperties.Privileged)
+}
+
// android_app compiles sources and Android resources into an Android application package `.apk` file.
func AndroidAppFactory() android.Module {
module := &AndroidApp{}
@@ -773,7 +775,7 @@
usesLibrary usesLibrary
- installPath android.OutputPath
+ installPath android.InstallPath
}
type AndroidAppImportProperties struct {
@@ -874,7 +876,7 @@
}
// Uncompress dex in APKs of privileged apps
- if ctx.Config().UncompressPrivAppDex() && Bool(a.properties.Privileged) {
+ if ctx.Config().UncompressPrivAppDex() && a.Privileged() {
return true
}
@@ -1005,6 +1007,10 @@
a.AddProperties(a.archVariants)
}
+func (a *AndroidAppImport) Privileged() bool {
+ return Bool(a.properties.Privileged)
+}
+
func createVariantGroupType(variants []string, variantGroupName string) reflect.Type {
props := reflect.TypeOf((*AndroidAppImportProperties)(nil))
diff --git a/java/config/config.go b/java/config/config.go
index ce62b93..f418ee7 100644
--- a/java/config/config.go
+++ b/java/config/config.go
@@ -86,6 +86,14 @@
// This is set up and guaranteed by soong_ui
return ctx.Config().Getenv("ANDROID_JAVA_HOME")
})
+ pctx.VariableFunc("JlinkVersion", func(ctx android.PackageVarContext) string {
+ switch ctx.Config().Getenv("EXPERIMENTAL_USE_OPENJDK11_TOOLCHAIN") {
+ case "true":
+ return "11"
+ default:
+ return "9"
+ }
+ })
pctx.SourcePathVariable("JavaToolchain", "${JavaHome}/bin")
pctx.SourcePathVariableWithEnvOverride("JavacCmd",
diff --git a/java/config/makevars.go b/java/config/makevars.go
index c40f4fc..2fa6f89 100644
--- a/java/config/makevars.go
+++ b/java/config/makevars.go
@@ -38,6 +38,7 @@
ctx.Strict("ANDROID_JAVA_HOME", "${JavaHome}")
ctx.Strict("ANDROID_JAVA8_HOME", "prebuilts/jdk/jdk8/${hostPrebuiltTag}")
ctx.Strict("ANDROID_JAVA9_HOME", "prebuilts/jdk/jdk9/${hostPrebuiltTag}")
+ ctx.Strict("ANDROID_JAVA11_HOME", "prebuilts/jdk/jdk11/${hostPrebuiltTag}")
ctx.Strict("ANDROID_JAVA_TOOLCHAIN", "${JavaToolchain}")
ctx.Strict("JAVA", "${JavaCmd} ${JavaVmFlags}")
ctx.Strict("JAVAC", "${JavacCmd} ${JavacVmFlags}")
diff --git a/java/device_host_converter.go b/java/device_host_converter.go
index 030b010..14db521 100644
--- a/java/device_host_converter.go
+++ b/java/device_host_converter.go
@@ -18,8 +18,6 @@
"fmt"
"io"
- "github.com/google/blueprint"
-
"android/soong/android"
)
@@ -83,13 +81,13 @@
var deviceHostConverterDepTag = dependencyTag{name: "device_host_converter"}
func (d *DeviceForHost) DepsMutator(ctx android.BottomUpMutatorContext) {
- variation := []blueprint.Variation{{Mutator: "arch", Variation: "android_common"}}
- ctx.AddFarVariationDependencies(variation, deviceHostConverterDepTag, d.properties.Libs...)
+ ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
+ deviceHostConverterDepTag, d.properties.Libs...)
}
func (d *HostForDevice) DepsMutator(ctx android.BottomUpMutatorContext) {
- variation := []blueprint.Variation{{Mutator: "arch", Variation: ctx.Config().BuildOsCommonVariant}}
- ctx.AddFarVariationDependencies(variation, deviceHostConverterDepTag, d.properties.Libs...)
+ ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(),
+ deviceHostConverterDepTag, d.properties.Libs...)
}
func (d *DeviceHostConverter) GenerateAndroidBuildActions(ctx android.ModuleContext) {
diff --git a/java/device_host_converter_test.go b/java/device_host_converter_test.go
index 44aae9b..3c9a0f3 100644
--- a/java/device_host_converter_test.go
+++ b/java/device_host_converter_test.go
@@ -60,7 +60,7 @@
deviceImportModule := ctx.ModuleForTests("device_import_module", "android_common")
deviceImportCombined := deviceImportModule.Output("combined/device_import_module.jar")
- hostModule := ctx.ModuleForTests("host_module", config.BuildOsCommonVariant)
+ hostModule := ctx.ModuleForTests("host_module", config.BuildOSCommonTarget.String())
hostJavac := hostModule.Output("javac/host_module.jar")
hostRes := hostModule.Output("res/host_module.jar")
combined := hostModule.Output("combined/host_module.jar")
@@ -133,11 +133,11 @@
ctx, config := testJava(t, bp)
- hostModule := ctx.ModuleForTests("host_module", config.BuildOsCommonVariant)
+ hostModule := ctx.ModuleForTests("host_module", config.BuildOSCommonTarget.String())
hostJavac := hostModule.Output("javac/host_module.jar")
hostRes := hostModule.Output("res/host_module.jar")
- hostImportModule := ctx.ModuleForTests("host_import_module", config.BuildOsCommonVariant)
+ hostImportModule := ctx.ModuleForTests("host_import_module", config.BuildOSCommonTarget.String())
hostImportCombined := hostImportModule.Output("combined/host_import_module.jar")
deviceModule := ctx.ModuleForTests("device_module", "android_common")
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index 6214dac..b48871e 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -22,7 +22,7 @@
type dexpreopter struct {
dexpreoptProperties DexpreoptProperties
- installPath android.OutputPath
+ installPath android.InstallPath
uncompressedDex bool
isSDKLibrary bool
isTest bool
@@ -94,7 +94,7 @@
return false
}
-func odexOnSystemOther(ctx android.ModuleContext, installPath android.OutputPath) bool {
+func odexOnSystemOther(ctx android.ModuleContext, installPath android.InstallPath) bool {
return dexpreopt.OdexOnSystemOtherByName(ctx.ModuleName(), android.InstallPathToOnDevicePath(ctx, installPath), dexpreoptGlobalConfig(ctx))
}
@@ -126,10 +126,6 @@
archs = archs[:1]
}
}
- if ctx.Config().SecondArchIsTranslated() {
- // Only preopt primary arch for translated arch since there is only an image there.
- archs = archs[:1]
- }
var images android.Paths
var imagesDeps []android.Paths
diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go
index 8c699b8..043f9da 100644
--- a/java/dexpreopt_config.go
+++ b/java/dexpreopt_config.go
@@ -87,11 +87,7 @@
// supported through native bridge.
func dexpreoptTargets(ctx android.PathContext) []android.Target {
var targets []android.Target
- for i, target := range ctx.Config().Targets[android.Android] {
- if ctx.Config().SecondArchIsTranslated() && i > 0 {
- break
- }
-
+ for _, target := range ctx.Config().Targets[android.Android] {
if target.NativeBridge == android.NativeBridgeDisabled {
targets = append(targets, target)
}
diff --git a/java/droiddoc.go b/java/droiddoc.go
index 1d5331e..3b581cb 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -67,9 +67,15 @@
// If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Installable *bool
- // if not blank, set to the version of the sdk to compile against
+ // if not blank, set to the version of the sdk to compile against.
+ // Defaults to compiling against the current platform.
Sdk_version *string `android:"arch_variant"`
+ // When targeting 1.9 and above, override the modules to use with --system,
+ // otherwise provides defaults libraries to add to the bootclasspath.
+ // Defaults to "none"
+ System_modules *string
+
Aidl struct {
// Top level directories to pass to aidl tool
Include_dirs []string
@@ -238,6 +244,16 @@
// do not perform API check against Last_released, in the case that both two specified API
// files by Last_released are modules which don't exist.
Ignore_missing_latest_api *bool `blueprint:"mutated"`
+
+ Api_lint struct {
+ Enabled *bool
+
+ // If set, performs api_lint on any new APIs not found in the given signature file
+ New_since *string `android:"path"`
+
+ // If not blank, path to the baseline txt file for approved API lint violations.
+ Baseline_file *string `android:"path"`
+ }
}
// user can specify the version of previous released API file in order to do compatibility check.
@@ -391,6 +407,10 @@
return proptools.StringDefault(j.properties.Sdk_version, defaultSdkVersion(j))
}
+func (j *Javadoc) systemModules() string {
+ return proptools.String(j.properties.System_modules)
+}
+
func (j *Javadoc) minSdkVersion() string {
return j.sdkVersion()
}
@@ -417,6 +437,10 @@
}
ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
}
+ } else if sdkDep.systemModules != "" {
+ // Add the system modules to both the system modules and bootclasspath.
+ ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
+ ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.systemModules)
}
}
@@ -461,14 +485,14 @@
flags droiddocBuilderFlags) android.Paths {
outSrcFiles := make(android.Paths, 0, len(srcFiles))
+ var aidlSrcs android.Paths
aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
for _, srcFile := range srcFiles {
switch srcFile.Ext() {
case ".aidl":
- javaFile := genAidl(ctx, srcFile, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
- outSrcFiles = append(outSrcFiles, javaFile)
+ aidlSrcs = append(aidlSrcs, srcFile)
case ".logtags":
javaFile := genLogtags(ctx, srcFile)
outSrcFiles = append(outSrcFiles, javaFile)
@@ -477,6 +501,12 @@
}
}
+ // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
+ if len(aidlSrcs) > 0 {
+ srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
+ outSrcFiles = append(outSrcFiles, srcJarFiles...)
+ }
+
return outSrcFiles
}
@@ -498,6 +528,10 @@
case bootClasspathTag:
if dep, ok := module.(Dependency); ok {
deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
+ } else if sm, ok := module.(*SystemModules); ok {
+ // A system modules dependency has been added to the bootclasspath
+ // so add its libs to the bootclasspath.
+ deps.bootClasspath = append(deps.bootClasspath, sm.headerJars...)
} else {
panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
}
@@ -1148,6 +1182,7 @@
checkCurrentApiTimestamp android.WritablePath
updateCurrentApiTimestamp android.WritablePath
checkLastReleasedApiTimestamp android.WritablePath
+ apiLintTimestamp android.WritablePath
checkNullabilityWarningsTimestamp android.WritablePath
@@ -1484,6 +1519,57 @@
// Create rule for apicheck
+ if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().IsPdkBuild() {
+ rule := android.NewRuleBuilder()
+ rule.Command().Text("( true")
+
+ srcJarDir := android.PathForModuleOut(ctx, "api_lint", "srcjars")
+ srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
+
+ cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
+ deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
+
+ cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
+
+ newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
+ if newSince.Valid() {
+ cmd.FlagWithInput("--api-lint ", newSince.Path())
+ } else {
+ cmd.Flag("--api-lint")
+ }
+
+ d.inclusionAnnotationsFlags(ctx, cmd)
+ d.mergeAnnoDirFlags(ctx, cmd)
+
+ baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file)
+ updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt")
+ d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp")
+
+ if baselineFile.Valid() {
+ cmd.FlagWithInput("--baseline ", baselineFile.Path())
+ cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
+ }
+
+ zipSyncCleanupCmd(rule, srcJarDir)
+
+ msg := fmt.Sprintf(`\n******************************\n`+
+ `Your API changes are triggering API Lint warnings or errors.\n\n`+
+ `To make these errors go away, you have two choices:\n`+
+ ` 1. You can suppress the errors with @SuppressLint(\"<id>\").\n\n`+
+ ` 2. You can update the baseline by executing the following command:\n`+
+ ` cp \"$PWD/%s\" \"$PWD/%s\"\n\n`+
+ `******************************\n`, updatedBaselineOutput, baselineFile.Path())
+ rule.Command().
+ Text("touch").Output(d.apiLintTimestamp).
+ Text(") || (").
+ Text("echo").Flag("-e").Flag(`"` + msg + `"`).
+ Text("; exit 38").
+ Text(")")
+
+ rule.Build(pctx, ctx, "metalavaApiLint", "metalava API lint")
+
+ }
+
if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
!ctx.Config().IsPdkBuild() {
diff --git a/java/gen.go b/java/gen.go
index b840b60..d50a665 100644
--- a/java/gen.go
+++ b/java/gen.go
@@ -15,9 +15,11 @@
package java
import (
+ "strconv"
"strings"
"github.com/google/blueprint"
+ "github.com/google/blueprint/pathtools"
"android/soong/android"
)
@@ -29,13 +31,6 @@
}
var (
- aidl = pctx.AndroidStaticRule("aidl",
- blueprint.RuleParams{
- Command: "${config.AidlCmd} -d$depFile $aidlFlags $in $out",
- CommandDeps: []string{"${config.AidlCmd}"},
- },
- "depFile", "aidlFlags")
-
logtags = pctx.AndroidStaticRule("logtags",
blueprint.RuleParams{
Command: "$logtagsCmd -o $out $in",
@@ -49,23 +44,64 @@
})
)
-func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string, deps android.Paths) android.Path {
- javaFile := android.GenPathWithExt(ctx, "aidl", aidlFile, "java")
- depFile := javaFile.String() + ".d"
+func genAidl(ctx android.ModuleContext, aidlFiles android.Paths, aidlFlags string, deps android.Paths) android.Paths {
+ // Shard aidl files into groups of 50 to avoid having to recompile all of them if one changes and to avoid
+ // hitting command line length limits.
+ shards := android.ShardPaths(aidlFiles, 50)
- ctx.Build(pctx, android.BuildParams{
- Rule: aidl,
- Description: "aidl " + aidlFile.Rel(),
- Output: javaFile,
- Input: aidlFile,
- Implicits: deps,
- Args: map[string]string{
- "depFile": depFile,
- "aidlFlags": aidlFlags,
- },
- })
+ srcJarFiles := make(android.Paths, 0, len(shards))
- return javaFile
+ for i, shard := range shards {
+ srcJarFile := android.PathForModuleGen(ctx, "aidl", "aidl"+strconv.Itoa(i)+".srcjar")
+ srcJarFiles = append(srcJarFiles, srcJarFile)
+
+ outDir := srcJarFile.ReplaceExtension(ctx, "tmp")
+
+ rule := android.NewRuleBuilder()
+
+ rule.Command().Text("rm -rf").Flag(outDir.String())
+ rule.Command().Text("mkdir -p").Flag(outDir.String())
+ rule.Command().Text("FLAGS=' " + aidlFlags + "'")
+
+ for _, aidlFile := range shard {
+ depFile := srcJarFile.InSameDir(ctx, aidlFile.String()+".d")
+ javaFile := outDir.Join(ctx, pathtools.ReplaceExtension(aidlFile.String(), "java"))
+ rule.Command().
+ Tool(ctx.Config().HostToolPath(ctx, "aidl")).
+ FlagWithDepFile("-d", depFile).
+ Flag("$FLAGS").
+ Input(aidlFile).
+ Output(javaFile).
+ Implicits(deps)
+ rule.Temporary(javaFile)
+ }
+
+ rule.Command().
+ Tool(ctx.Config().HostToolPath(ctx, "soong_zip")).
+ // TODO(b/124333557): this can't use -srcjar for now, aidl on parcelables generates java files
+ // without a package statement, which causes -srcjar to put them in the top level of the zip file.
+ // Once aidl skips parcelables we can use -srcjar.
+ //Flag("-srcjar").
+ Flag("-write_if_changed").
+ FlagWithOutput("-o ", srcJarFile).
+ FlagWithArg("-C ", outDir.String()).
+ FlagWithArg("-D ", outDir.String())
+
+ rule.Command().Text("rm -rf").Flag(outDir.String())
+
+ rule.Restat()
+
+ ruleName := "aidl"
+ ruleDesc := "aidl"
+ if len(shards) > 1 {
+ ruleName += "_" + strconv.Itoa(i)
+ ruleDesc += " " + strconv.Itoa(i)
+ }
+
+ rule.Build(pctx, ctx, ruleName, ruleDesc)
+ }
+
+ return srcJarFiles
}
func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Path {
@@ -98,26 +134,38 @@
flags javaBuilderFlags) android.Paths {
outSrcFiles := make(android.Paths, 0, len(srcFiles))
+ var protoSrcs android.Paths
+ var aidlSrcs android.Paths
aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
for _, srcFile := range srcFiles {
switch srcFile.Ext() {
case ".aidl":
- javaFile := genAidl(ctx, srcFile, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
- outSrcFiles = append(outSrcFiles, javaFile)
+ aidlSrcs = append(aidlSrcs, srcFile)
case ".logtags":
j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
javaFile := genLogtags(ctx, srcFile)
outSrcFiles = append(outSrcFiles, javaFile)
case ".proto":
- srcJarFile := genProto(ctx, srcFile, flags.proto)
- outSrcFiles = append(outSrcFiles, srcJarFile)
+ protoSrcs = append(protoSrcs, srcFile)
default:
outSrcFiles = append(outSrcFiles, srcFile)
}
}
+ // Process all proto files together to support sharding them into one or more rules that produce srcjars.
+ if len(protoSrcs) > 0 {
+ srcJarFiles := genProto(ctx, protoSrcs, flags.proto)
+ outSrcFiles = append(outSrcFiles, srcJarFiles...)
+ }
+
+ // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
+ if len(aidlSrcs) > 0 {
+ srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
+ outSrcFiles = append(outSrcFiles, srcJarFiles...)
+ }
+
return outSrcFiles
}
diff --git a/java/java.go b/java/java.go
index f7b0f53..0aef69e 100644
--- a/java/java.go
+++ b/java/java.go
@@ -270,7 +270,8 @@
Proguard_flags_files []string `android:"path"`
}
- // When targeting 1.9, override the modules to use with --system
+ // When targeting 1.9 and above, override the modules to use with --system,
+ // otherwise provides defaults libraries to add to the bootclasspath.
System_modules *string
UncompressDex bool `blueprint:"mutated"`
@@ -347,8 +348,8 @@
// list of SDK lib names that this java moudule is exporting
exportedSdkLibs []string
- // list of source files, collected from compiledJavaSrcs and compiledSrcJars
- // filter out Exclude_srcs, will be used by android.IDEInfo struct
+ // list of source files, collected from srcFiles with uniqie java and all kt files,
+ // will be used by android.IDEInfo struct
expandIDEInfoCompiledSrcs []string
// expanded Jarjar_rules
@@ -457,7 +458,10 @@
type sdkDep struct {
useModule, useFiles, useDefaultLibs, invalidVersion bool
- modules []string
+ modules []string
+
+ // The default system modules to use. Will be an empty string if no system
+ // modules are to be used.
systemModules string
frameworkResModule string
@@ -496,6 +500,10 @@
return proptools.StringDefault(j.deviceProperties.Sdk_version, defaultSdkVersion(j))
}
+func (j *Module) systemModules() string {
+ return proptools.String(j.deviceProperties.System_modules)
+}
+
func (j *Module) minSdkVersion() string {
if j.deviceProperties.Min_sdk_version != nil {
return *j.deviceProperties.Min_sdk_version
@@ -528,13 +536,10 @@
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
}
}
- } else if j.deviceProperties.System_modules == nil {
- ctx.PropertyErrorf("sdk_version",
- `system_modules is required to be set when sdk_version is "none", did you mean "core_platform"`)
- } else if *j.deviceProperties.System_modules != "none" {
+ } else if sdkDep.systemModules != "" {
// Add the system modules to both the system modules and bootclasspath.
- ctx.AddVariationDependencies(nil, systemModulesTag, *j.deviceProperties.System_modules)
- ctx.AddVariationDependencies(nil, bootClasspathTag, *j.deviceProperties.System_modules)
+ ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
+ ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.systemModules)
}
if ctx.ModuleName() == "android_stubs_current" ||
ctx.ModuleName() == "android_system_stubs_current" ||
@@ -546,9 +551,7 @@
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
- ctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: ctx.Config().BuildOsCommonVariant},
- }, pluginTag, j.properties.Plugins...)
+ ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
android.ProtoDeps(ctx, &j.protoProperties)
if j.hasSrcExt(".proto") {
@@ -1032,9 +1035,6 @@
srcJars = append(srcJars, aaptSrcJar)
}
- // Collect source files and filter out Exclude_srcs that IDEInfo struct will use
- j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.Strings()...)
-
if j.properties.Jarjar_rules != nil {
j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
}
@@ -1051,6 +1051,9 @@
}
}
+ // Collect .java files for AIDEGen
+ j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, uniqueSrcFiles.Strings()...)
+
var kotlinJars android.Paths
if srcFiles.HasExt(".kt") {
@@ -1075,6 +1078,9 @@
kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
+ // Collect .kt files for AIDEGen
+ j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.FilterByExt(".kt").Strings()...)
+
flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
@@ -1559,6 +1565,12 @@
return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0
}
+func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
+ depTag := ctx.OtherModuleDependencyTag(dep)
+ // dependencies other than the static linkage are all considered crossing APEX boundary
+ return depTag == staticLibTag
+}
+
//
// Java libraries (.jar file)
//
@@ -1795,7 +1807,7 @@
isWrapperVariant bool
wrapperFile android.Path
- binaryFile android.OutputPath
+ binaryFile android.InstallPath
}
func (j *Binary) HostToolPath() android.OptionalPath {
diff --git a/java/java_test.go b/java/java_test.go
index a932319..a3499cc 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -18,6 +18,7 @@
"io/ioutil"
"os"
"path/filepath"
+ "reflect"
"strconv"
"strings"
"testing"
@@ -811,19 +812,22 @@
}
`)
- inputs := ctx.ModuleForTests("bar-doc", "android_common").Rule("javadoc").Inputs
+ barDoc := ctx.ModuleForTests("bar-doc", "android_common").Rule("javadoc")
var javaSrcs []string
- for _, i := range inputs {
+ for _, i := range barDoc.Inputs {
javaSrcs = append(javaSrcs, i.Base())
}
- if len(javaSrcs) != 3 || javaSrcs[0] != "a.java" || javaSrcs[1] != "IFoo.java" || javaSrcs[2] != "IBar.java" {
- t.Errorf("inputs of bar-doc must be []string{\"a.java\", \"IFoo.java\", \"IBar.java\", but was %#v.", javaSrcs)
+ if len(javaSrcs) != 1 || javaSrcs[0] != "a.java" {
+ t.Errorf("inputs of bar-doc must be []string{\"a.java\"}, but was %#v.", javaSrcs)
}
- aidlRule := ctx.ModuleForTests("bar-doc", "android_common").Output(inputs[2].String())
- aidlFlags := aidlRule.Args["aidlFlags"]
- if !strings.Contains(aidlFlags, "-Ibar-doc") {
- t.Errorf("aidl flags for IBar.aidl should contain \"-Ibar-doc\", but was %q", aidlFlags)
+ aidl := ctx.ModuleForTests("bar-doc", "android_common").Rule("aidl")
+ if g, w := barDoc.Implicits.Strings(), aidl.Output.String(); !inList(w, g) {
+ t.Errorf("implicits of bar-doc must contain %q, but was %q.", w, g)
+ }
+
+ if g, w := aidl.Implicits.Strings(), []string{"bar-doc/IBar.aidl", "bar-doc/IFoo.aidl"}; !reflect.DeepEqual(w, g) {
+ t.Errorf("aidl inputs must be %q, but was %q", w, g)
}
}
@@ -1091,8 +1095,10 @@
`
t.Run("Java language level 8", func(t *testing.T) {
- // Test default javac -source 1.8 -target 1.8
- ctx, _ := testJava(t, bp)
+ // Test with legacy javac -source 1.8 -target 1.8
+ config := testConfig(map[string]string{"EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9": "false"})
+ ctx := testContext(bp, nil)
+ run(t, ctx, config)
checkPatchModuleFlag(t, ctx, "foo", "")
checkPatchModuleFlag(t, ctx, "bar", "")
@@ -1100,10 +1106,8 @@
})
t.Run("Java language level 9", func(t *testing.T) {
- // Test again with javac -source 9 -target 9
- config := testConfig(map[string]string{"EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9": "true"})
- ctx := testContext(bp, nil)
- run(t, ctx, config)
+ // Test with default javac -source 9 -target 9
+ ctx, _ := testJava(t, bp)
checkPatchModuleFlag(t, ctx, "foo", "")
expected := "java.base=.:" + buildDir
diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go
index 3d46077..23ba2b0 100644
--- a/java/platform_compat_config.go
+++ b/java/platform_compat_config.go
@@ -30,7 +30,7 @@
android.ModuleBase
properties platformCompatConfigProperties
- installDirPath android.OutputPath
+ installDirPath android.InstallPath
configFile android.OutputPath
}
@@ -78,7 +78,7 @@
Include: "$(BUILD_PREBUILT)",
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
func(entries *android.AndroidMkEntries) {
- entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString())
+ entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String())
entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base())
},
},
diff --git a/java/proto.go b/java/proto.go
index f5c233c..e013bb4 100644
--- a/java/proto.go
+++ b/java/proto.go
@@ -15,36 +15,61 @@
package java
import (
+ "path/filepath"
+ "strconv"
+
"android/soong/android"
)
-func genProto(ctx android.ModuleContext, protoFile android.Path, flags android.ProtoFlags) android.Path {
- srcJarFile := android.GenPathWithExt(ctx, "proto", protoFile, "srcjar")
+func genProto(ctx android.ModuleContext, protoFiles android.Paths, flags android.ProtoFlags) android.Paths {
+ // Shard proto files into groups of 100 to avoid having to recompile all of them if one changes and to avoid
+ // hitting command line length limits.
+ shards := android.ShardPaths(protoFiles, 100)
- outDir := srcJarFile.ReplaceExtension(ctx, "tmp")
- depFile := srcJarFile.ReplaceExtension(ctx, "srcjar.d")
+ srcJarFiles := make(android.Paths, 0, len(shards))
- rule := android.NewRuleBuilder()
+ for i, shard := range shards {
+ srcJarFile := android.PathForModuleGen(ctx, "proto", "proto"+strconv.Itoa(i)+".srcjar")
+ srcJarFiles = append(srcJarFiles, srcJarFile)
- rule.Command().Text("rm -rf").Flag(outDir.String())
- rule.Command().Text("mkdir -p").Flag(outDir.String())
+ outDir := srcJarFile.ReplaceExtension(ctx, "tmp")
- android.ProtoRule(ctx, rule, protoFile, flags, flags.Deps, outDir, depFile, nil)
+ rule := android.NewRuleBuilder()
- // Proto generated java files have an unknown package name in the path, so package the entire output directory
- // into a srcjar.
- rule.Command().
- BuiltTool(ctx, "soong_zip").
- Flag("-jar").
- FlagWithOutput("-o ", srcJarFile).
- FlagWithArg("-C ", outDir.String()).
- FlagWithArg("-D ", outDir.String())
+ rule.Command().Text("rm -rf").Flag(outDir.String())
+ rule.Command().Text("mkdir -p").Flag(outDir.String())
- rule.Command().Text("rm -rf").Flag(outDir.String())
+ for _, protoFile := range shard {
+ depFile := srcJarFile.InSameDir(ctx, protoFile.String()+".d")
+ rule.Command().Text("mkdir -p").Flag(filepath.Dir(depFile.String()))
+ android.ProtoRule(ctx, rule, protoFile, flags, flags.Deps, outDir, depFile, nil)
+ }
- rule.Build(pctx, ctx, "protoc_"+protoFile.Rel(), "protoc "+protoFile.Rel())
+ // Proto generated java files have an unknown package name in the path, so package the entire output directory
+ // into a srcjar.
+ rule.Command().
+ BuiltTool(ctx, "soong_zip").
+ Flag("-jar").
+ Flag("-write_if_changed").
+ FlagWithOutput("-o ", srcJarFile).
+ FlagWithArg("-C ", outDir.String()).
+ FlagWithArg("-D ", outDir.String())
- return srcJarFile
+ rule.Command().Text("rm -rf").Flag(outDir.String())
+
+ rule.Restat()
+
+ ruleName := "protoc"
+ ruleDesc := "protoc"
+ if len(shards) > 1 {
+ ruleName += "_" + strconv.Itoa(i)
+ ruleDesc += " " + strconv.Itoa(i)
+ }
+
+ rule.Build(pctx, ctx, ruleName, ruleDesc)
+ }
+
+ return srcJarFiles
}
func protoDeps(ctx android.BottomUpMutatorContext, p *android.ProtoProperties) {
diff --git a/java/sdk.go b/java/sdk.go
index 3451774..c6a9a73 100644
--- a/java/sdk.go
+++ b/java/sdk.go
@@ -39,6 +39,8 @@
type sdkContext interface {
// sdkVersion returns the sdk_version property of the current module, or an empty string if it is not set.
sdkVersion() string
+ // systemModules returns the system_modules property of the current module, or an empty string if it is not set.
+ systemModules() string
// minSdkVersion returns the min_sdk_version property of the current module, or sdkVersion() if it is not set.
minSdkVersion() string
// targetSdkVersion returns the target_sdk_version property of the current module, or sdkVersion() if it is not set.
@@ -185,8 +187,18 @@
frameworkResModule: "framework-res",
}
case "none":
+ systemModules := sdkContext.systemModules()
+ if systemModules == "" {
+ ctx.PropertyErrorf("sdk_version",
+ `system_modules is required to be set to a non-empty value when sdk_version is "none", did you mean sdk_version: "core_platform"?`)
+ } else if systemModules == "none" {
+ // Normalize no system modules to an empty string.
+ systemModules = ""
+ }
+
return sdkDep{
noStandardLibs: true,
+ systemModules: systemModules,
}
case "core_platform":
return sdkDep{
diff --git a/java/sdk_test.go b/java/sdk_test.go
index 88e21d7..5e0e592 100644
--- a/java/sdk_test.go
+++ b/java/sdk_test.go
@@ -250,7 +250,10 @@
}
checkClasspath := func(t *testing.T, ctx *android.TestContext) {
- javac := ctx.ModuleForTests("foo", variant).Rule("javac")
+ foo := ctx.ModuleForTests("foo", variant)
+ javac := foo.Rule("javac")
+
+ aidl := foo.MaybeRule("aidl")
got := javac.Args["bootClasspath"]
if got != bc {
@@ -263,6 +266,9 @@
}
var deps []string
+ if aidl.Rule != nil {
+ deps = append(deps, aidl.Output.String())
+ }
if len(bootclasspath) > 0 && bootclasspath[0] != `""` {
deps = append(deps, bootclasspath...)
}
@@ -273,9 +279,9 @@
}
}
+ // Test with legacy javac -source 1.8 -target 1.8
t.Run("Java language level 8", func(t *testing.T) {
- // Test default javac -source 1.8 -target 1.8
- config := testConfig(nil)
+ config := testConfig(map[string]string{"EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9": "false"})
if testcase.unbundled {
config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
}
@@ -290,19 +296,15 @@
if testcase.host != android.Host {
aidl := ctx.ModuleForTests("foo", variant).Rule("aidl")
- aidlFlags := aidl.Args["aidlFlags"]
- // Trim trailing "-I." to avoid having to specify it in every test
- aidlFlags = strings.TrimSpace(strings.TrimSuffix(aidlFlags, "-I."))
-
- if g, w := aidlFlags, testcase.aidl; g != w {
- t.Errorf("want aidl flags %q, got %q", w, g)
+ if g, w := aidl.RuleParams.Command, testcase.aidl+" -I."; !strings.Contains(g, w) {
+ t.Errorf("want aidl command to contain %q, got %q", w, g)
}
}
})
- // Test again with javac -source 9 -target 9
+ // Test with default javac -source 9 -target 9
t.Run("Java language level 9", func(t *testing.T) {
- config := testConfig(map[string]string{"EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9": "true"})
+ config := testConfig(nil)
if testcase.unbundled {
config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
}
@@ -325,7 +327,8 @@
// Test again with PLATFORM_VERSION_CODENAME=REL
t.Run("REL", func(t *testing.T) {
- config := testConfig(nil)
+ // TODO(b/115604102): This test should be rewritten with language level 9
+ config := testConfig(map[string]string{"EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9": "false"})
config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("REL")
config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(true)
diff --git a/java/system_modules.go b/java/system_modules.go
index 43e4e11..b56a401 100644
--- a/java/system_modules.go
+++ b/java/system_modules.go
@@ -36,13 +36,15 @@
var (
jarsTosystemModules = pctx.AndroidStaticRule("jarsTosystemModules", blueprint.RuleParams{
Command: `rm -rf ${outDir} ${workDir} && mkdir -p ${workDir}/jmod && ` +
- `${moduleInfoJavaPath} ${moduleName} $in > ${workDir}/module-info.java && ` +
+ `${moduleInfoJavaPath} java.base $in > ${workDir}/module-info.java && ` +
`${config.JavacCmd} --system=none --patch-module=java.base=${classpath} ${workDir}/module-info.java && ` +
`${config.SoongZipCmd} -jar -o ${workDir}/classes.jar -C ${workDir} -f ${workDir}/module-info.class && ` +
`${config.MergeZipsCmd} -j ${workDir}/module.jar ${workDir}/classes.jar $in && ` +
- `${config.JmodCmd} create --module-version 9 --target-platform android ` +
- ` --class-path ${workDir}/module.jar ${workDir}/jmod/${moduleName}.jmod && ` +
- `${config.JlinkCmd} --module-path ${workDir}/jmod --add-modules ${moduleName} --output ${outDir} ` +
+ // Note: The version of the java.base module created must match the version
+ // of the jlink tool which consumes it.
+ `${config.JmodCmd} create --module-version ${config.JlinkVersion} --target-platform android ` +
+ ` --class-path ${workDir}/module.jar ${workDir}/jmod/java.base.jmod && ` +
+ `${config.JlinkCmd} --module-path ${workDir}/jmod --add-modules java.base --output ${outDir} ` +
// Note: The system-modules jlink plugin is disabled because (a) it is not
// useful on Android, and (b) it causes errors with later versions of jlink
// when the jdk.internal.module is absent from java.base (as it is here).
@@ -58,10 +60,10 @@
"${config.JrtFsJar}",
},
},
- "moduleName", "classpath", "outDir", "workDir")
+ "classpath", "outDir", "workDir")
)
-func TransformJarsToSystemModules(ctx android.ModuleContext, moduleName string, jars android.Paths) (android.Path, android.Paths) {
+func TransformJarsToSystemModules(ctx android.ModuleContext, jars android.Paths) (android.Path, android.Paths) {
outDir := android.PathForModuleOut(ctx, "system")
workDir := android.PathForModuleOut(ctx, "modules")
outputFile := android.PathForModuleOut(ctx, "system/lib/modules")
@@ -77,10 +79,9 @@
Outputs: outputs,
Inputs: jars,
Args: map[string]string{
- "moduleName": moduleName,
- "classpath": strings.Join(jars.Strings(), ":"),
- "workDir": workDir.String(),
- "outDir": outDir.String(),
+ "classpath": strings.Join(jars.Strings(), ":"),
+ "workDir": workDir.String(),
+ "outDir": outDir.String(),
},
})
@@ -123,7 +124,7 @@
system.headerJars = jars
- system.outputDir, system.outputDeps = TransformJarsToSystemModules(ctx, "java.base", jars)
+ system.outputDir, system.outputDeps = TransformJarsToSystemModules(ctx, jars)
}
func (system *SystemModules) DepsMutator(ctx android.BottomUpMutatorContext) {
diff --git a/makedeps/deps.go b/makedeps/deps.go
index e64e6f7..db49532 100644
--- a/makedeps/deps.go
+++ b/makedeps/deps.go
@@ -57,10 +57,12 @@
return nil, fmt.Errorf("%sunsupported variable expansion: %v", pos(node), x.Target.Dump())
}
outputs := x.Target.Words()
- if len(outputs) == 0 {
- return nil, fmt.Errorf("%smissing output: %v", pos(node), x)
+ if len(outputs) > 0 {
+ ret.Output = outputs[0].Value(nil)
+ } else {
+ // TODO(b/141372861): put this back
+ //return nil, fmt.Errorf("%smissing output: %v", pos(node), x)
}
- ret.Output = outputs[0].Value(nil)
if !x.Prerequisites.Const() {
return nil, fmt.Errorf("%sunsupported variable expansion: %v", pos(node), x.Prerequisites.Dump())
diff --git a/makedeps/deps_test.go b/makedeps/deps_test.go
index a32df65..ac2f699 100644
--- a/makedeps/deps_test.go
+++ b/makedeps/deps_test.go
@@ -147,6 +147,20 @@
},
},
},
+ {
+ // TODO(b/141372861): remove this
+ // AIDL produces a dep file with no output file for a parcelable (b/
+ name: "AIDL parcelable",
+ input: ` : \
+ frameworks/base/tests/net/integration/src/com/android/server/net/integrationtests/HttpResponse.aidl
+`,
+ output: Deps{
+ Output: "",
+ Inputs: []string{
+ "frameworks/base/tests/net/integration/src/com/android/server/net/integrationtests/HttpResponse.aidl",
+ },
+ },
+ },
}
for _, tc := range testCases {
diff --git a/python/androidmk.go b/python/androidmk.go
index 1e51e7b..aae7ced 100644
--- a/python/androidmk.go
+++ b/python/androidmk.go
@@ -89,12 +89,11 @@
ret.Required = append(ret.Required, "libc++")
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
- path := installer.path.RelPathString()
- dir, file := filepath.Split(path)
+ path, file := filepath.Split(installer.path.ToMakePath().String())
stem := strings.TrimSuffix(file, 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 := "+path)
fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(installer.androidMkSharedLibs, " "))
})
diff --git a/python/installer.go b/python/installer.go
index 62f36f4..396f036 100644
--- a/python/installer.go
+++ b/python/installer.go
@@ -33,7 +33,7 @@
dir64 string
relative string
- path android.OutputPath
+ path android.InstallPath
androidMkSharedLibs []string
}
@@ -47,12 +47,12 @@
var _ installer = (*pythonInstaller)(nil)
-func (installer *pythonInstaller) installDir(ctx android.ModuleContext) android.OutputPath {
+func (installer *pythonInstaller) installDir(ctx android.ModuleContext) android.InstallPath {
dir := installer.dir
if ctx.Arch().ArchType.Multilib == "lib64" && installer.dir64 != "" {
dir = installer.dir64
}
- if !ctx.Host() && !ctx.Arch().Native {
+ if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
dir = filepath.Join(dir, ctx.Arch().ArchType.String())
}
return android.PathForModuleInstall(ctx, dir, installer.relative)
diff --git a/python/python.go b/python/python.go
index ad08909..1b606cb 100644
--- a/python/python.go
+++ b/python/python.go
@@ -306,22 +306,17 @@
if p.bootstrapper.autorun() {
launcherModule = "py2-launcher-autorun"
}
- ctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: ctx.Target().String()},
- }, launcherTag, launcherModule)
+ ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherTag, launcherModule)
// Add py2-launcher shared lib dependencies. Ideally, these should be
// derived from the `shared_libs` property of "py2-launcher". However, we
// cannot read the property at this stage and it will be too late to add
// dependencies later.
- ctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: ctx.Target().String()},
- }, launcherSharedLibTag, "libsqlite")
+ ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherSharedLibTag, "libsqlite")
if ctx.Target().Os.Bionic() {
- ctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: ctx.Target().String()},
- }, launcherSharedLibTag, "libc", "libdl", "libm")
+ ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherSharedLibTag,
+ "libc", "libdl", "libm")
}
}
diff --git a/rust/androidmk.go b/rust/androidmk.go
index 107959f..a6208db 100644
--- a/rust/androidmk.go
+++ b/rust/androidmk.go
@@ -116,11 +116,10 @@
ret.OutputFile = android.OptionalPathForPath(compiler.path)
}
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
- path := compiler.path.RelPathString()
- dir, file := filepath.Split(path)
+ path, file := filepath.Split(compiler.path.ToMakePath().String())
stem, suffix, _ := android.SplitFileExt(file)
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
- fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
+ fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path)
fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
})
}
diff --git a/rust/compiler.go b/rust/compiler.go
index 3bfef76..3f02835 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -20,16 +20,22 @@
"android/soong/android"
"android/soong/rust/config"
+ "github.com/google/blueprint/proptools"
)
+func getEdition(compiler *baseCompiler) string {
+ return proptools.StringDefault(compiler.Properties.Edition, config.DefaultEdition)
+}
+
+func getDenyWarnings(compiler *baseCompiler) bool {
+ return BoolDefault(compiler.Properties.Deny_warnings, config.DefaultDenyWarnings)
+}
+
func NewBaseCompiler(dir, dir64 string) *baseCompiler {
return &baseCompiler{
- Properties: BaseCompilerProperties{
- Edition: &config.DefaultEdition,
- Deny_warnings: config.DefaultDenyWarnings,
- },
- dir: dir,
- dir64: dir64,
+ Properties: BaseCompilerProperties{},
+ dir: dir,
+ dir64: dir64,
}
}
@@ -94,7 +100,7 @@
dir64 string
subDir string
relative string
- path android.OutputPath
+ path android.InstallPath
}
var _ compiler = (*baseCompiler)(nil)
@@ -113,12 +119,12 @@
func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flags {
- if Bool(compiler.Properties.Deny_warnings) {
+ if getDenyWarnings(compiler) {
flags.RustFlags = append(flags.RustFlags, "-D warnings")
}
flags.RustFlags = append(flags.RustFlags, compiler.Properties.Flags...)
flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags(compiler.Properties.Features)...)
- flags.RustFlags = append(flags.RustFlags, "--edition="+*compiler.Properties.Edition)
+ flags.RustFlags = append(flags.RustFlags, "--edition="+getEdition(compiler))
flags.LinkFlags = append(flags.LinkFlags, compiler.Properties.Ld_flags...)
flags.GlobalRustFlags = append(flags.GlobalRustFlags, config.GlobalRustFlags...)
flags.GlobalRustFlags = append(flags.GlobalRustFlags, ctx.toolchain().ToolchainRustFlags())
@@ -173,12 +179,12 @@
return compiler.Properties.Crate_name
}
-func (compiler *baseCompiler) installDir(ctx ModuleContext) android.OutputPath {
+func (compiler *baseCompiler) installDir(ctx ModuleContext) android.InstallPath {
dir := compiler.dir
if ctx.toolchain().Is64Bit() && compiler.dir64 != "" {
dir = compiler.dir64
}
- if (!ctx.Host() && !ctx.Arch().Native) || ctx.Target().NativeBridge == android.NativeBridgeEnabled {
+ if !ctx.Host() || ctx.Target().NativeBridge == android.NativeBridgeEnabled {
dir = filepath.Join(dir, ctx.Arch().ArchType.String())
}
return android.PathForModuleInstall(ctx, dir, compiler.subDir,
diff --git a/rust/config/global.go b/rust/config/global.go
index ae50804..7846d21 100644
--- a/rust/config/global.go
+++ b/rust/config/global.go
@@ -17,8 +17,6 @@
import (
"strings"
- "github.com/google/blueprint/proptools"
-
"android/soong/android"
_ "android/soong/cc/config"
)
@@ -35,7 +33,7 @@
"libtest",
}
- DefaultDenyWarnings = proptools.BoolPtr(true)
+ DefaultDenyWarnings = true
GlobalRustFlags = []string{
"--remap-path-prefix $$(pwd)=",
diff --git a/rust/rust.go b/rust/rust.go
index 61b51e5..4f5e7fb 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -496,7 +496,7 @@
}
// proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
- actx.AddFarVariationDependencies([]blueprint.Variation{{Mutator: "arch", Variation: ctx.Config().BuildOsVariant}}, procMacroDepTag, deps.ProcMacros...)
+ actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
}
func (mod *Module) Name() string {
diff --git a/scripts/strip.sh b/scripts/strip.sh
index f987d98..40f0184 100755
--- a/scripts/strip.sh
+++ b/scripts/strip.sh
@@ -67,9 +67,9 @@
do_strip_keep_symbol_list() {
echo "${symbols_to_keep}" | tr ',' '\n' > "${outfile}.symbolList"
- KEEP_SYMBOLS="--strip-unneeded-symbol=.* --keep-symbols="
+ KEEP_SYMBOLS="--strip-unneeded-symbol=* --keep-symbols="
KEEP_SYMBOLS+="${outfile}.symbolList"
- "${CLANG_BIN}/llvm-objcopy" --regex "${infile}" "${outfile}.tmp" ${KEEP_SYMBOLS}
+ "${CROSS_COMPILE}objcopy" -w "${infile}" "${outfile}.tmp" ${KEEP_SYMBOLS}
}
do_strip_keep_mini_debug_info() {
diff --git a/sdk/sdk.go b/sdk/sdk.go
index fcb3fb7..d189043 100644
--- a/sdk/sdk.go
+++ b/sdk/sdk.go
@@ -15,6 +15,9 @@
package sdk
import (
+ "fmt"
+ "strconv"
+
"github.com/google/blueprint"
"android/soong/android"
@@ -25,6 +28,7 @@
func init() {
android.RegisterModuleType("sdk", ModuleFactory)
+ android.RegisterModuleType("sdk_snapshot", SnapshotModuleFactory)
android.PreDepsMutators(RegisterPreDepsMutators)
android.PostDepsMutators(RegisterPostDepsMutators)
}
@@ -34,12 +38,18 @@
android.DefaultableModuleBase
properties sdkProperties
+
+ updateScript android.OutputPath
+ freezeScript android.OutputPath
}
type sdkProperties struct {
- // The list of java_import modules that provide Java stubs for this SDK
- Java_libs []string
+ // The list of java libraries in this SDK
+ Java_libs []string
+ // The list of native libraries in this SDK
Native_shared_libs []string
+
+ Snapshot bool `blueprint:"mutated"`
}
// sdk defines an SDK which is a logical group of modules (e.g. native libs, headers, java libs, etc.)
@@ -52,8 +62,44 @@
return s
}
+// sdk_snapshot is a versioned snapshot of an SDK. This is an auto-generated module.
+func SnapshotModuleFactory() android.Module {
+ s := ModuleFactory()
+ s.(*sdk).properties.Snapshot = true
+ return s
+}
+
+func (s *sdk) snapshot() bool {
+ return s.properties.Snapshot
+}
+
+func (s *sdk) frozenVersions(ctx android.BaseModuleContext) []string {
+ if s.snapshot() {
+ panic(fmt.Errorf("frozenVersions() called for sdk_snapshot %q", ctx.ModuleName()))
+ }
+ versions := []string{}
+ ctx.WalkDeps(func(child android.Module, parent android.Module) bool {
+ depTag := ctx.OtherModuleDependencyTag(child)
+ if depTag == sdkMemberDepTag {
+ return true
+ }
+ if versionedDepTag, ok := depTag.(sdkMemberVesionedDepTag); ok {
+ v := versionedDepTag.version
+ if v != "current" && !android.InList(v, versions) {
+ versions = append(versions, versionedDepTag.version)
+ }
+ }
+ return false
+ })
+ return android.SortedUniqueStrings(versions)
+}
+
func (s *sdk) GenerateAndroidBuildActions(ctx android.ModuleContext) {
- // TODO(jiyong): add build rules for creating stubs from members of this SDK
+ s.buildSnapshotGenerationScripts(ctx)
+}
+
+func (s *sdk) AndroidMkEntries() android.AndroidMkEntries {
+ return s.androidMkEntriesForScript()
}
// RegisterPreDepsMutators registers pre-deps mutators to support modules implementing SdkAware
@@ -76,6 +122,7 @@
// should have been mutated for the apex before the SDK requirements are set.
ctx.TopDown("SdkDepsMutator", sdkDepsMutator).Parallel()
ctx.BottomUp("SdkDepsReplaceMutator", sdkDepsReplaceMutator).Parallel()
+ ctx.TopDown("SdkRequirementCheck", sdkRequirementsMutator).Parallel()
}
type dependencyTag struct {
@@ -101,19 +148,31 @@
targets := mctx.MultiTargets()
for _, target := range targets {
- mctx.AddFarVariationDependencies([]blueprint.Variation{
- {Mutator: "arch", Variation: target.String()},
+ mctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
{Mutator: "image", Variation: "core"},
{Mutator: "link", Variation: "shared"},
- }, sdkMemberDepTag, m.properties.Native_shared_libs...)
+ }...), sdkMemberDepTag, m.properties.Native_shared_libs...)
}
}
}
// Step 2: record that dependencies of SDK modules are members of the SDK modules
func memberDepsMutator(mctx android.TopDownMutatorContext) {
- if _, ok := mctx.Module().(*sdk); ok {
+ if s, ok := mctx.Module().(*sdk); ok {
mySdkRef := android.ParseSdkRef(mctx, mctx.ModuleName(), "name")
+ if s.snapshot() && mySdkRef.Unversioned() {
+ mctx.PropertyErrorf("name", "sdk_snapshot should be named as <name>@<version>. "+
+ "Did you manually modify Android.bp?")
+ }
+ if !s.snapshot() && !mySdkRef.Unversioned() {
+ mctx.PropertyErrorf("name", "sdk shouldn't be named as <name>@<version>.")
+ }
+ if mySdkRef.Version != "" && mySdkRef.Version != "current" {
+ if _, err := strconv.Atoi(mySdkRef.Version); err != nil {
+ mctx.PropertyErrorf("name", "version %q is neither a number nor \"current\"", mySdkRef.Version)
+ }
+ }
+
mctx.VisitDirectDeps(func(child android.Module) {
if member, ok := child.(android.SdkAware); ok {
member.MakeMemberOf(mySdkRef)
@@ -122,7 +181,7 @@
}
}
-// Step 3: create dependencies from the in-development version of an SDK member to frozen versions
+// Step 3: create dependencies from the unversioned SDK member to snapshot versions
// of the same member. By having these dependencies, they are mutated for multiple Mainline modules
// (apex and apk), each of which might want different sdks to be built with. For example, if both
// apex A and B are referencing libfoo which is a member of sdk 'mysdk', the two APEXes can be
@@ -130,7 +189,7 @@
// using.
func memberInterVersionMutator(mctx android.BottomUpMutatorContext) {
if m, ok := mctx.Module().(android.SdkAware); ok && m.IsInAnySdk() {
- if !m.ContainingSdk().IsCurrentVersion() {
+ if !m.ContainingSdk().Unversioned() {
memberName := m.MemberName()
tag := sdkMemberVesionedDepTag{member: memberName, version: m.ContainingSdk().Version}
mctx.AddReverseDependency(mctx.Module(), tag, memberName)
@@ -159,7 +218,7 @@
// versioned module is used instead of the un-versioned (in-development) module libfoo
func sdkDepsReplaceMutator(mctx android.BottomUpMutatorContext) {
if m, ok := mctx.Module().(android.SdkAware); ok && m.IsInAnySdk() {
- if sdk := m.ContainingSdk(); !sdk.IsCurrentVersion() {
+ if sdk := m.ContainingSdk(); !sdk.Unversioned() {
if m.RequiredSdks().Contains(sdk) {
// Note that this replacement is done only for the modules that have the same
// variations as the current module. Since current module is already mutated for
@@ -170,3 +229,31 @@
}
}
}
+
+// Step 6: ensure that the dependencies from outside of the APEX are all from the required SDKs
+func sdkRequirementsMutator(mctx android.TopDownMutatorContext) {
+ if m, ok := mctx.Module().(interface {
+ DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool
+ RequiredSdks() android.SdkRefs
+ }); ok {
+ requiredSdks := m.RequiredSdks()
+ if len(requiredSdks) == 0 {
+ return
+ }
+ mctx.VisitDirectDeps(func(dep android.Module) {
+ if mctx.OtherModuleDependencyTag(dep) == android.DefaultsDepTag {
+ // dependency to defaults is always okay
+ return
+ }
+
+ // If the dep is from outside of the APEX, but is not in any of the
+ // required SDKs, we know that the dep is a violation.
+ if sa, ok := dep.(android.SdkAware); ok {
+ if !m.DepIsInSameApex(mctx, dep) && !requiredSdks.Contains(sa.ContainingSdk()) {
+ mctx.ModuleErrorf("depends on %q (in SDK %q) that isn't part of the required SDKs: %v",
+ sa.Name(), sa.ContainingSdk(), requiredSdks)
+ }
+ }
+ })
+ }
+}
diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go
index 9eca72f..664bb7c 100644
--- a/sdk/sdk_test.go
+++ b/sdk/sdk_test.go
@@ -69,6 +69,7 @@
// from this package
ctx.RegisterModuleType("sdk", android.ModuleFactoryAdaptor(ModuleFactory))
+ ctx.RegisterModuleType("sdk_snapshot", android.ModuleFactoryAdaptor(SnapshotModuleFactory))
ctx.PreDepsMutators(RegisterPreDepsMutators)
ctx.PostDepsMutators(RegisterPostDepsMutators)
@@ -114,6 +115,23 @@
return ctx, config
}
+func testSdkError(t *testing.T, pattern, bp string) {
+ t.Helper()
+ ctx, config := testSdkContext(t, bp)
+ _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
+ if len(errs) > 0 {
+ android.FailIfNoMatchingErrors(t, pattern, errs)
+ return
+ }
+ _, errs = ctx.PrepareBuildActions(config)
+ if len(errs) > 0 {
+ android.FailIfNoMatchingErrors(t, pattern, errs)
+ return
+ }
+
+ t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
+}
+
// ensure that 'result' contains 'expected'
func ensureContains(t *testing.T, result string, expected string) {
t.Helper()
@@ -155,12 +173,17 @@
func TestBasicSdkWithJava(t *testing.T) {
ctx, _ := testSdk(t, `
sdk {
- name: "mysdk#1",
+ name: "mysdk",
+ java_libs: ["sdkmember"],
+ }
+
+ sdk_snapshot {
+ name: "mysdk@1",
java_libs: ["sdkmember_mysdk_1"],
}
- sdk {
- name: "mysdk#2",
+ sdk_snapshot {
+ name: "mysdk@2",
java_libs: ["sdkmember_mysdk_2"],
}
@@ -195,7 +218,7 @@
apex {
name: "myapex",
java_libs: ["myjavalib"],
- uses_sdks: ["mysdk#1"],
+ uses_sdks: ["mysdk@1"],
key: "myapex.key",
certificate: ":myapex.cert",
}
@@ -203,7 +226,7 @@
apex {
name: "myapex2",
java_libs: ["myjavalib"],
- uses_sdks: ["mysdk#2"],
+ uses_sdks: ["mysdk@2"],
key: "myapex.key",
certificate: ":myapex.cert",
}
@@ -223,12 +246,17 @@
func TestBasicSdkWithCc(t *testing.T) {
ctx, _ := testSdk(t, `
sdk {
- name: "mysdk#1",
+ name: "mysdk",
+ native_shared_libs: ["sdkmember"],
+ }
+
+ sdk_snapshot {
+ name: "mysdk@1",
native_shared_libs: ["sdkmember_mysdk_1"],
}
- sdk {
- name: "mysdk#2",
+ sdk_snapshot {
+ name: "mysdk@2",
native_shared_libs: ["sdkmember_mysdk_2"],
}
@@ -267,7 +295,7 @@
apex {
name: "myapex",
native_shared_libs: ["mycpplib"],
- uses_sdks: ["mysdk#1"],
+ uses_sdks: ["mysdk@1"],
key: "myapex.key",
certificate: ":myapex.cert",
}
@@ -275,7 +303,7 @@
apex {
name: "myapex2",
native_shared_libs: ["mycpplib"],
- uses_sdks: ["mysdk#2"],
+ uses_sdks: ["mysdk@2"],
key: "myapex.key",
certificate: ":myapex.cert",
}
@@ -292,6 +320,63 @@
ensureListContains(t, pathsToStrings(cpplibForMyApex2.Rule("ld").Implicits), sdkMemberV2.String())
}
+func TestDepNotInRequiredSdks(t *testing.T) {
+ testSdkError(t, `module "myjavalib".*depends on "otherlib".*that isn't part of the required SDKs:.*`, `
+ sdk {
+ name: "mysdk",
+ java_libs: ["sdkmember"],
+ }
+
+ sdk_snapshot {
+ name: "mysdk@1",
+ java_libs: ["sdkmember_mysdk_1"],
+ }
+
+ java_import {
+ name: "sdkmember",
+ prefer: false,
+ host_supported: true,
+ }
+
+ java_import {
+ name: "sdkmember_mysdk_1",
+ sdk_member_name: "sdkmember",
+ host_supported: true,
+ }
+
+ java_library {
+ name: "myjavalib",
+ srcs: ["Test.java"],
+ libs: [
+ "sdkmember",
+ "otherlib",
+ ],
+ system_modules: "none",
+ sdk_version: "none",
+ compile_dex: true,
+ host_supported: true,
+ }
+
+ // this lib is no in mysdk
+ java_library {
+ name: "otherlib",
+ srcs: ["Test.java"],
+ system_modules: "none",
+ sdk_version: "none",
+ compile_dex: true,
+ host_supported: true,
+ }
+
+ apex {
+ name: "myapex",
+ java_libs: ["myjavalib"],
+ uses_sdks: ["mysdk@1"],
+ key: "myapex.key",
+ certificate: ":myapex.cert",
+ }
+ `)
+}
+
var buildDir string
func setUp() {
diff --git a/sdk/update.go b/sdk/update.go
new file mode 100644
index 0000000..5235c9e
--- /dev/null
+++ b/sdk/update.go
@@ -0,0 +1,228 @@
+// Copyright (C) 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package sdk
+
+import (
+ "fmt"
+ "io"
+ "path/filepath"
+ "strconv"
+ "strings"
+
+ "github.com/google/blueprint/proptools"
+
+ "android/soong/android"
+ "android/soong/java"
+)
+
+var pctx = android.NewPackageContext("android/soong/sdk")
+
+// generatedFile abstracts operations for writing contents into a file and emit a build rule
+// for the file.
+type generatedFile struct {
+ path android.OutputPath
+ content strings.Builder
+}
+
+func newGeneratedFile(ctx android.ModuleContext, name string) *generatedFile {
+ return &generatedFile{
+ path: android.PathForModuleOut(ctx, name).OutputPath,
+ }
+}
+
+func (gf *generatedFile) printfln(format string, args ...interface{}) {
+ // ninja consumes newline characters in rspfile_content. Prevent it by
+ // escaping the backslash in the newline character. The extra backshash
+ // is removed when the rspfile is written to the actual script file
+ fmt.Fprintf(&(gf.content), format+"\\n", args...)
+}
+
+func (gf *generatedFile) build(pctx android.PackageContext, ctx android.BuilderContext, implicits android.Paths) {
+ rb := android.NewRuleBuilder()
+ // convert \\n to \n
+ rb.Command().
+ Implicits(implicits).
+ Text("echo").Text(proptools.ShellEscape(gf.content.String())).
+ Text("| sed 's/\\\\n/\\n/g' >").Output(gf.path)
+ rb.Command().
+ Text("chmod a+x").Output(gf.path)
+ rb.Build(pctx, ctx, gf.path.Base(), "Build "+gf.path.Base())
+}
+
+func (s *sdk) javaMemberNames(ctx android.ModuleContext) []string {
+ result := []string{}
+ ctx.VisitDirectDeps(func(m android.Module) {
+ if _, ok := m.(*java.Library); ok {
+ result = append(result, m.Name())
+ }
+ })
+ return result
+}
+
+// buildAndroidBp creates the blueprint file that defines prebuilt modules for each of
+// the SDK members, and the sdk_snapshot module for the specified version
+func (s *sdk) buildAndroidBp(ctx android.ModuleContext, version string) android.OutputPath {
+ bp := newGeneratedFile(ctx, "blueprint-"+version+".sh")
+
+ makePrebuiltName := func(name string) string {
+ return ctx.ModuleName() + "_" + name + string(android.SdkVersionSeparator) + version
+ }
+
+ javaLibs := s.javaMemberNames(ctx)
+ for _, name := range javaLibs {
+ prebuiltName := makePrebuiltName(name)
+ jar := filepath.Join("java", name, "stub.jar")
+
+ bp.printfln("java_import {")
+ bp.printfln(" name: %q,", prebuiltName)
+ bp.printfln(" jars: [%q],", jar)
+ bp.printfln(" sdk_member_name: %q,", name)
+ bp.printfln("}")
+ bp.printfln("")
+
+ // This module is for the case when the source tree for the unversioned module
+ // doesn't exist (i.e. building in an unbundled tree). "prefer:" is set to false
+ // so that this module does not eclipse the unversioned module if it exists.
+ bp.printfln("java_import {")
+ bp.printfln(" name: %q,", name)
+ bp.printfln(" jars: [%q],", jar)
+ bp.printfln(" prefer: false,")
+ bp.printfln("}")
+ bp.printfln("")
+
+ }
+
+ // TODO(jiyong): emit cc_prebuilt_library_shared for the native libs
+
+ bp.printfln("sdk_snapshot {")
+ bp.printfln(" name: %q,", ctx.ModuleName()+string(android.SdkVersionSeparator)+version)
+ bp.printfln(" java_libs: [")
+ for _, n := range javaLibs {
+ bp.printfln(" %q,", makePrebuiltName(n))
+ }
+ bp.printfln(" ],")
+ // TODO(jiyong): emit native_shared_libs
+ bp.printfln("}")
+ bp.printfln("")
+
+ bp.build(pctx, ctx, nil)
+ return bp.path
+}
+
+func (s *sdk) buildScript(ctx android.ModuleContext, version string) android.OutputPath {
+ sh := newGeneratedFile(ctx, "update_prebuilt-"+version+".sh")
+
+ snapshotRoot := filepath.Join(ctx.ModuleDir(), version)
+ aidlIncludeDir := filepath.Join(snapshotRoot, "aidl")
+ javaStubsDir := filepath.Join(snapshotRoot, "java")
+
+ sh.printfln("#!/bin/bash")
+ sh.printfln("echo Updating snapshot of %s in %s", ctx.ModuleName(), snapshotRoot)
+ sh.printfln("pushd $ANDROID_BUILD_TOP > /dev/null")
+ sh.printfln("rm -rf %s", snapshotRoot)
+ sh.printfln("mkdir -p %s", aidlIncludeDir)
+ sh.printfln("mkdir -p %s", javaStubsDir)
+ // TODO(jiyong): mkdir the 'native' dir
+
+ var implicits android.Paths
+ ctx.VisitDirectDeps(func(m android.Module) {
+ if javaLib, ok := m.(*java.Library); ok {
+ headerJars := javaLib.HeaderJars()
+ if len(headerJars) != 1 {
+ panic(fmt.Errorf("there must be only one header jar from %q", m.Name()))
+ }
+ implicits = append(implicits, headerJars...)
+
+ exportedAidlIncludeDirs := javaLib.AidlIncludeDirs()
+ for _, dir := range exportedAidlIncludeDirs {
+ // Using tar to copy with the directory structure
+ // TODO(jiyong): copy parcelable declarations only
+ sh.printfln("find %s -name \"*.aidl\" | tar cf - -T - | (cd %s; tar xf -)",
+ dir.String(), aidlIncludeDir)
+ }
+
+ copiedHeaderJar := filepath.Join(javaStubsDir, m.Name(), "stub.jar")
+ sh.printfln("mkdir -p $(dirname %s) && cp %s %s",
+ copiedHeaderJar, headerJars[0].String(), copiedHeaderJar)
+ }
+ // TODO(jiyong): emit the commands for copying the headers and stub libraries for native libs
+ })
+
+ bp := s.buildAndroidBp(ctx, version)
+ implicits = append(implicits, bp)
+ sh.printfln("cp %s %s", bp.String(), filepath.Join(snapshotRoot, "Android.bp"))
+
+ sh.printfln("popd > /dev/null")
+ sh.printfln("rm -- \"$0\"") // self deleting so that stale script is not used
+ sh.printfln("echo Done")
+
+ sh.build(pctx, ctx, implicits)
+ return sh.path
+}
+
+func (s *sdk) buildSnapshotGenerationScripts(ctx android.ModuleContext) {
+ if s.snapshot() {
+ // we don't need a script for sdk_snapshot.. as they are frozen
+ return
+ }
+
+ // script to update the 'current' snapshot
+ s.updateScript = s.buildScript(ctx, "current")
+
+ versions := s.frozenVersions(ctx)
+ newVersion := "1"
+ if len(versions) >= 1 {
+ lastVersion := versions[len(versions)-1]
+ lastVersionNum, err := strconv.Atoi(lastVersion)
+ if err != nil {
+ panic(err)
+ return
+ }
+ newVersion = strconv.Itoa(lastVersionNum + 1)
+ }
+ // script to create a new frozen version of snapshot
+ s.freezeScript = s.buildScript(ctx, newVersion)
+}
+
+func (s *sdk) androidMkEntriesForScript() android.AndroidMkEntries {
+ if s.snapshot() {
+ // we don't need a script for sdk_snapshot.. as they are frozen
+ return android.AndroidMkEntries{}
+ }
+
+ entries := android.AndroidMkEntries{
+ Class: "FAKE",
+ // TODO(jiyong): remove this? but androidmk.go expects OutputFile to be specified anyway
+ OutputFile: android.OptionalPathForPath(s.updateScript),
+ Include: "$(BUILD_SYSTEM)/base_rules.mk",
+ ExtraEntries: []android.AndroidMkExtraEntriesFunc{
+ func(entries *android.AndroidMkEntries) {
+ entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES",
+ s.updateScript.String(), s.freezeScript.String())
+ },
+ },
+ ExtraFooters: []android.AndroidMkExtraFootersFunc{
+ func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
+ fmt.Fprintln(w, "$(LOCAL_BUILT_MODULE): $(LOCAL_ADDITIONAL_DEPENDENCIES)")
+ fmt.Fprintln(w, " touch $@")
+ fmt.Fprintln(w, " echo ##################################################")
+ fmt.Fprintln(w, " echo To update current SDK: execute", s.updateScript.String())
+ fmt.Fprintln(w, " echo To freeze current SDK: execute", s.freezeScript.String())
+ fmt.Fprintln(w, " echo ##################################################")
+ },
+ },
+ }
+ return entries
+}
diff --git a/ui/build/cleanbuild.go b/ui/build/cleanbuild.go
index 0a2b510..1dbeb26 100644
--- a/ui/build/cleanbuild.go
+++ b/ui/build/cleanbuild.go
@@ -107,6 +107,8 @@
productOut("obj/NOTICE_FILES"),
productOut("obj/PACKAGING"),
productOut("ramdisk"),
+ productOut("debug_ramdisk"),
+ productOut("test_harness_ramdisk"),
productOut("recovery"),
productOut("root"),
productOut("system"),
diff --git a/ui/build/config.go b/ui/build/config.go
index def3345..919b9ce 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -214,10 +214,14 @@
// Configure Java-related variables, including adding it to $PATH
java8Home := filepath.Join("prebuilts/jdk/jdk8", ret.HostPrebuiltTag())
java9Home := filepath.Join("prebuilts/jdk/jdk9", ret.HostPrebuiltTag())
+ java11Home := filepath.Join("prebuilts/jdk/jdk11", ret.HostPrebuiltTag())
javaHome := func() string {
if override, ok := ret.environ.Get("OVERRIDE_ANDROID_JAVA_HOME"); ok {
return override
}
+ if toolchain11, ok := ret.environ.Get("EXPERIMENTAL_USE_OPENJDK11_TOOLCHAIN"); ok && toolchain11 == "true" {
+ return java11Home
+ }
return java9Home
}()
absJavaHome := absPath(ctx, javaHome)
@@ -228,11 +232,13 @@
if path, ok := ret.environ.Get("PATH"); ok && path != "" {
newPath = append(newPath, path)
}
+
ret.environ.Unset("OVERRIDE_ANDROID_JAVA_HOME")
ret.environ.Set("JAVA_HOME", absJavaHome)
ret.environ.Set("ANDROID_JAVA_HOME", javaHome)
ret.environ.Set("ANDROID_JAVA8_HOME", java8Home)
ret.environ.Set("ANDROID_JAVA9_HOME", java9Home)
+ ret.environ.Set("ANDROID_JAVA11_HOME", java11Home)
ret.environ.Set("PATH", strings.Join(newPath, string(filepath.ListSeparator)))
outDir := ret.OutDir()
diff --git a/ui/build/dumpvars.go b/ui/build/dumpvars.go
index 6b9eac1..4270bb1 100644
--- a/ui/build/dumpvars.go
+++ b/ui/build/dumpvars.go
@@ -17,6 +17,8 @@
import (
"bytes"
"fmt"
+ "io/ioutil"
+ "os"
"strings"
"android/soong/ui/metrics"
@@ -40,6 +42,7 @@
soongUiVars := map[string]func() string{
"OUT_DIR": func() string { return config.OutDir() },
"DIST_DIR": func() string { return config.DistDir() },
+ "TMPDIR": func() string { return absPath(ctx, config.TempDir()) },
}
makeVars := make([]string, 0, len(vars))
@@ -51,7 +54,17 @@
var ret map[string]string
if len(makeVars) > 0 {
- var err error
+ tmpDir, err := ioutil.TempDir("", "dumpvars")
+ if err != nil {
+ return nil, err
+ }
+ defer os.RemoveAll(tmpDir)
+
+ // It's not safe to use the same TMPDIR as the build, as that can be removed.
+ config.Environment().Set("TMPDIR", tmpDir)
+
+ SetupLitePath(ctx, config)
+
ret, err = dumpMakeVars(ctx, config, goals, makeVars, false)
if err != nil {
return ret, err
@@ -208,6 +221,8 @@
"DEFAULT_WARNING_BUILD_MODULE_TYPES",
"DEFAULT_ERROR_BUILD_MODULE_TYPES",
+ "BUILD_BROKEN_PREBUILT_ELF_FILES",
+ "BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW",
"BUILD_BROKEN_USES_BUILD_AUX_EXECUTABLE",
"BUILD_BROKEN_USES_BUILD_AUX_STATIC_LIBRARY",
"BUILD_BROKEN_USES_BUILD_COPY_HEADERS",
diff --git a/ui/build/path.go b/ui/build/path.go
index 0e1c02c..c34ba1b 100644
--- a/ui/build/path.go
+++ b/ui/build/path.go
@@ -18,6 +18,7 @@
"fmt"
"io/ioutil"
"os"
+ "os/exec"
"path/filepath"
"runtime"
"strings"
@@ -53,6 +54,51 @@
return ret
}
+// A "lite" version of SetupPath used for dumpvars, or other places that need
+// minimal overhead (but at the expense of logging).
+func SetupLitePath(ctx Context, config Config) {
+ if config.pathReplaced {
+ return
+ }
+
+ ctx.BeginTrace(metrics.RunSetupTool, "litepath")
+ defer ctx.EndTrace()
+
+ origPath, _ := config.Environment().Get("PATH")
+ myPath, _ := config.Environment().Get("TMPDIR")
+ myPath = filepath.Join(myPath, "path")
+ ensureEmptyDirectoriesExist(ctx, myPath)
+
+ os.Setenv("PATH", origPath)
+ for name, pathConfig := range paths.Configuration {
+ if !pathConfig.Symlink {
+ continue
+ }
+
+ origExec, err := exec.LookPath(name)
+ if err != nil {
+ continue
+ }
+ origExec, err = filepath.Abs(origExec)
+ if err != nil {
+ continue
+ }
+
+ err = os.Symlink(origExec, filepath.Join(myPath, name))
+ if err != nil {
+ ctx.Fatalln("Failed to create symlink:", err)
+ }
+ }
+
+ myPath, _ = filepath.Abs(myPath)
+
+ prebuiltsPath, _ := filepath.Abs("prebuilts/build-tools/path/" + runtime.GOOS + "-x86")
+ myPath = prebuiltsPath + string(os.PathListSeparator) + myPath
+
+ config.Environment().Set("PATH", myPath)
+ config.pathReplaced = true
+}
+
func SetupPath(ctx Context, config Config) {
if config.pathReplaced {
return
diff --git a/ui/build/paths/config.go b/ui/build/paths/config.go
index e44600e..1af816b 100644
--- a/ui/build/paths/config.go
+++ b/ui/build/paths/config.go
@@ -122,6 +122,9 @@
"pgrep": LinuxOnlyPrebuilt,
"pkill": LinuxOnlyPrebuilt,
"ps": LinuxOnlyPrebuilt,
+
+ // The toybox xargs is currently breaking the mac build.
+ "xargs": LinuxOnlyPrebuilt,
}
func init() {
diff --git a/vnames.json b/vnames.json
index 7b34c52..f9d3adc 100644
--- a/vnames.json
+++ b/vnames.json
@@ -2,7 +2,7 @@
{
"pattern": "out/(.*)",
"vname": {
- "corpus": "CORPUS",
+ "corpus": "android.googlesource.com/platform/superproject",
"root": "out",
"path": "@1@"
}
@@ -10,7 +10,7 @@
{
"pattern": "(.*)",
"vname": {
- "corpus": "CORPUS",
+ "corpus": "android.googlesource.com/platform/superproject",
"path": "@1@"
}
}
diff --git a/xml/xml_test.go b/xml/xml_test.go
index ae3e9fe..f2a440f 100644
--- a/xml/xml_test.go
+++ b/xml/xml_test.go
@@ -15,15 +15,40 @@
package xml
import (
- "android/soong/android"
"io/ioutil"
"os"
"testing"
+
+ "android/soong/android"
)
+var buildDir string
+
+func setUp() {
+ var err error
+ buildDir, err = ioutil.TempDir("", "soong_xml_test")
+ if err != nil {
+ panic(err)
+ }
+}
+
+func tearDown() {
+ os.RemoveAll(buildDir)
+}
+
+func TestMain(m *testing.M) {
+ run := func() int {
+ setUp()
+ defer tearDown()
+
+ return m.Run()
+ }
+
+ os.Exit(run())
+}
+
func testXml(t *testing.T, bp string) *android.TestContext {
- config, buildDir := setup(t)
- defer teardown(buildDir)
+ config := android.TestArchConfig(buildDir, nil)
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
ctx.RegisterModuleType("prebuilt_etc_xml", android.ModuleFactoryAdaptor(PrebuiltEtcXmlFactory))
@@ -45,21 +70,6 @@
return ctx
}
-func setup(t *testing.T) (config android.Config, buildDir string) {
- buildDir, err := ioutil.TempDir("", "soong_xml_test")
- if err != nil {
- t.Fatal(err)
- }
-
- config = android.TestArchConfig(buildDir, nil)
-
- return
-}
-
-func teardown(buildDir string) {
- os.RemoveAll(buildDir)
-}
-
func assertEqual(t *testing.T, name, expected, actual string) {
t.Helper()
if expected != actual {
@@ -103,5 +113,5 @@
}
m := ctx.ModuleForTests("foo.xml", "android_arm64_armv8-a").Module().(*prebuiltEtcXml)
- assertEqual(t, "installDir", "target/product/test_device/system/etc", m.InstallDirPath().RelPathString())
+ assertEqual(t, "installDir", buildDir+"/target/product/test_device/system/etc", m.InstallDirPath().String())
}