Merge "Delete kotlin/rules.bzl file"
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index 67f3132..71281a6 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -313,6 +313,7 @@
"prebuilts/clang/host/linux-x86": Bp2BuildDefaultTrueRecursively,
"prebuilts/gradle-plugin": Bp2BuildDefaultTrueRecursively,
"prebuilts/runtime/mainline/platform/sdk": Bp2BuildDefaultTrueRecursively,
+ "prebuilts/sdk": Bp2BuildDefaultTrue,
"prebuilts/sdk/current/androidx": Bp2BuildDefaultTrue,
"prebuilts/sdk/current/androidx-legacy": Bp2BuildDefaultTrue,
"prebuilts/sdk/current/extras/constraint-layout-x": Bp2BuildDefaultTrue,
@@ -1557,9 +1558,6 @@
"com.android.media.swcodec",
"test_com.android.media.swcodec",
"libstagefright_foundation",
- "libcodec2_hidl@1.0",
- "libcodec2_hidl@1.1",
- "libcodec2_hidl@1.2",
}
// These should be the libs that are included by the apexes in the ProdMixedBuildsEnabledList
diff --git a/android/bazel.go b/android/bazel.go
index 3fe063c..114b1f5 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -71,7 +71,7 @@
MissingDeps []string `blueprint:"mutated"`
}
-type bazelModuleProperties struct {
+type BazelModuleProperties struct {
// The label of the Bazel target replacing this Soong module. When run in conversion mode, this
// will import the handcrafted build target into the autogenerated file. Note: this may result in
// a conflict due to duplicate targets if bp2build_available is also set.
@@ -96,7 +96,7 @@
type properties struct {
// In "Bazel mixed build" mode, this represents the Bazel target replacing
// this Soong module.
- Bazel_module bazelModuleProperties
+ Bazel_module BazelModuleProperties
}
// namespacedVariableProperties is a map from a string representing a Soong
diff --git a/android/bazel_test.go b/android/bazel_test.go
index 87b2c8f..77e2515 100644
--- a/android/bazel_test.go
+++ b/android/bazel_test.go
@@ -218,7 +218,7 @@
var bazelableBazelModuleBase = BazelModuleBase{
bazelProperties: properties{
- Bazel_module: bazelModuleProperties{
+ Bazel_module: BazelModuleProperties{
CanConvertToBazel: true,
},
},
@@ -344,7 +344,7 @@
},
BazelModuleBase: BazelModuleBase{
bazelProperties: properties{
- Bazel_module: bazelModuleProperties{
+ Bazel_module: BazelModuleProperties{
CanConvertToBazel: true,
Bp2build_available: proptools.BoolPtr(true),
},
diff --git a/android/filegroup.go b/android/filegroup.go
index 0ca5dc5..f30ee51 100644
--- a/android/filegroup.go
+++ b/android/filegroup.go
@@ -75,7 +75,8 @@
// https://docs.bazel.build/versions/master/be/general.html#filegroup
type bazelFilegroupAttributes struct {
- Srcs bazel.LabelListAttribute
+ Srcs bazel.LabelListAttribute
+ Applicable_licenses bazel.LabelListAttribute
}
type bazelAidlLibraryAttributes struct {
diff --git a/android/override_module.go b/android/override_module.go
index 9e95c0f..a4b7431 100644
--- a/android/override_module.go
+++ b/android/override_module.go
@@ -46,8 +46,8 @@
// Internal funcs to handle interoperability between override modules and prebuilts.
// i.e. cases where an overriding module, too, is overridden by a prebuilt module.
- setOverriddenByPrebuilt(overridden bool)
- getOverriddenByPrebuilt() bool
+ setOverriddenByPrebuilt(prebuilt Module)
+ getOverriddenByPrebuilt() Module
// Directory containing the Blueprint definition of the overriding module
setModuleDir(string)
@@ -60,7 +60,7 @@
overridingProperties []interface{}
- overriddenByPrebuilt bool
+ overriddenByPrebuilt Module
moduleDir string
}
@@ -96,11 +96,11 @@
return proptools.String(o.moduleProperties.Base)
}
-func (o *OverrideModuleBase) setOverriddenByPrebuilt(overridden bool) {
- o.overriddenByPrebuilt = overridden
+func (o *OverrideModuleBase) setOverriddenByPrebuilt(prebuilt Module) {
+ o.overriddenByPrebuilt = prebuilt
}
-func (o *OverrideModuleBase) getOverriddenByPrebuilt() bool {
+func (o *OverrideModuleBase) getOverriddenByPrebuilt() Module {
return o.overriddenByPrebuilt
}
@@ -281,7 +281,7 @@
panic("PrebuiltDepTag leads to a non-prebuilt module " + dep.Name())
}
if prebuilt.UsePrebuilt() {
- module.setOverriddenByPrebuilt(true)
+ module.setOverriddenByPrebuilt(dep)
return
}
})
@@ -314,8 +314,10 @@
ctx.AliasVariation(variants[0])
for i, o := range overrides {
mods[i+1].(OverridableModule).override(ctx, mods[i+1], o)
- if o.getOverriddenByPrebuilt() {
+ if prebuilt := o.getOverriddenByPrebuilt(); prebuilt != nil {
// The overriding module itself, too, is overridden by a prebuilt.
+ // Perform the same check for replacement
+ checkInvariantsForSourceAndPrebuilt(ctx, mods[i+1], prebuilt)
// Copy the flag and hide it in make
mods[i+1].ReplacedByPrebuilt()
}
diff --git a/android/package.go b/android/package.go
index 2bf6521..7fbc700 100644
--- a/android/package.go
+++ b/android/package.go
@@ -15,6 +15,8 @@
package android
import (
+ "path/filepath"
+
"android/soong/bazel"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -39,8 +41,8 @@
}
type bazelPackageAttributes struct {
- Default_visibility []string
- Default_applicable_licenses bazel.LabelListAttribute
+ Default_visibility []string
+ Default_package_metadata bazel.LabelListAttribute
}
type packageModule struct {
@@ -53,13 +55,32 @@
var _ Bazelable = &packageModule{}
func (p *packageModule) ConvertWithBp2build(ctx TopDownMutatorContext) {
+ defaultPackageMetadata := bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, p.properties.Default_applicable_licenses))
+ // If METADATA file exists in the package, add it to package(default_package_metadata=) using a
+ // filegroup(name="default_metadata_file") which can be accessed later on each module in Bazel
+ // using attribute "applicable_licenses".
+ // Attribute applicable_licenses of filegroup "default_metadata_file" has to be set to [],
+ // otherwise Bazel reports cyclic reference error.
+ if existed, _, _ := ctx.Config().fs.Exists(filepath.Join(ctx.ModuleDir(), "METADATA")); existed {
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "filegroup",
+ },
+ CommonAttributes{Name: "default_metadata_file"},
+ &bazelFilegroupAttributes{
+ Srcs: bazel.MakeLabelListAttribute(BazelLabelForModuleSrc(ctx, []string{"METADATA"})),
+ Applicable_licenses: bazel.LabelListAttribute{Value: bazel.LabelList{Includes: []bazel.Label{}}, EmitEmptyList: true},
+ })
+ defaultPackageMetadata.Value.Add(&bazel.Label{Label: ":default_metadata_file"})
+ }
+
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "package",
},
CommonAttributes{},
&bazelPackageAttributes{
- Default_applicable_licenses: bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, p.properties.Default_applicable_licenses)),
+ Default_package_metadata: defaultPackageMetadata,
// FIXME(asmundak): once b/221436821 is resolved
Default_visibility: []string{"//visibility:public"},
})
diff --git a/android/prebuilt.go b/android/prebuilt.go
index 9b5c0e9..95b772d 100644
--- a/android/prebuilt.go
+++ b/android/prebuilt.go
@@ -419,6 +419,20 @@
}
}
+// checkInvariantsForSourceAndPrebuilt checks if invariants are kept when replacing
+// source with prebuilt. Note that the current module for the context is the source module.
+func checkInvariantsForSourceAndPrebuilt(ctx BaseModuleContext, s, p Module) {
+ if _, ok := s.(OverrideModule); ok {
+ // skip the check when the source module is `override_X` because it's only a placeholder
+ // for the actual source module. The check will be invoked for the actual module.
+ return
+ }
+ if sourcePartition, prebuiltPartition := s.PartitionTag(ctx.DeviceConfig()), p.PartitionTag(ctx.DeviceConfig()); sourcePartition != prebuiltPartition {
+ ctx.OtherModuleErrorf(p, "partition is different: %s(%s) != %s(%s)",
+ sourcePartition, ctx.ModuleName(), prebuiltPartition, ctx.OtherModuleName(p))
+ }
+}
+
// PrebuiltSelectModuleMutator marks prebuilts that are used, either overriding source modules or
// because the source module doesn't exist. It also disables installing overridden source modules.
func PrebuiltSelectModuleMutator(ctx TopDownMutatorContext) {
@@ -434,6 +448,8 @@
ctx.VisitDirectDepsWithTag(PrebuiltDepTag, func(prebuiltModule Module) {
p := GetEmbeddedPrebuilt(prebuiltModule)
if p.usePrebuilt(ctx, s, prebuiltModule) {
+ checkInvariantsForSourceAndPrebuilt(ctx, s, prebuiltModule)
+
p.properties.UsePrebuilt = true
s.ReplacedByPrebuilt()
}
diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go
index fa40d1f..fc47cfd 100644
--- a/android/prebuilt_test.go
+++ b/android/prebuilt_test.go
@@ -497,6 +497,52 @@
}
}
+func testPrebuiltError(t *testing.T, expectedError, bp string) {
+ t.Helper()
+ fs := MockFS{
+ "prebuilt_file": nil,
+ }
+ GroupFixturePreparers(
+ PrepareForTestWithArchMutator,
+ PrepareForTestWithPrebuilts,
+ PrepareForTestWithOverrides,
+ fs.AddToFixture(),
+ FixtureRegisterWithContext(registerTestPrebuiltModules),
+ ).
+ ExtendWithErrorHandler(FixtureExpectsAtLeastOneErrorMatchingPattern(expectedError)).
+ RunTestWithBp(t, bp)
+}
+
+func TestPrebuiltShouldNotChangePartition(t *testing.T) {
+ testPrebuiltError(t, `partition is different`, `
+ source {
+ name: "foo",
+ vendor: true,
+ }
+ prebuilt {
+ name: "foo",
+ prefer: true,
+ srcs: ["prebuilt_file"],
+ }`)
+}
+
+func TestPrebuiltShouldNotChangePartition_WithOverride(t *testing.T) {
+ testPrebuiltError(t, `partition is different`, `
+ source {
+ name: "foo",
+ vendor: true,
+ }
+ override_source {
+ name: "bar",
+ base: "foo",
+ }
+ prebuilt {
+ name: "bar",
+ prefer: true,
+ srcs: ["prebuilt_file"],
+ }`)
+}
+
func registerTestPrebuiltBuildComponents(ctx RegistrationContext) {
registerTestPrebuiltModules(ctx)
diff --git a/android/testing.go b/android/testing.go
index fc39a9c..2a9c658 100644
--- a/android/testing.go
+++ b/android/testing.go
@@ -813,6 +813,20 @@
return path.RelativeToTop()
}
+func allOutputs(p BuildParams) []string {
+ outputs := append(WritablePaths(nil), p.Outputs...)
+ outputs = append(outputs, p.ImplicitOutputs...)
+ if p.Output != nil {
+ outputs = append(outputs, p.Output)
+ }
+ return outputs.Strings()
+}
+
+// AllOutputs returns all 'BuildParams.Output's and 'BuildParams.Outputs's in their full path string forms.
+func (p TestingBuildParams) AllOutputs() []string {
+ return allOutputs(p.BuildParams)
+}
+
// baseTestingComponent provides functionality common to both TestingModule and TestingSingleton.
type baseTestingComponent struct {
config Config
@@ -954,12 +968,7 @@
func (b baseTestingComponent) allOutputs() []string {
var outputFullPaths []string
for _, p := range b.provider.BuildParamsForTests() {
- outputs := append(WritablePaths(nil), p.Outputs...)
- outputs = append(outputs, p.ImplicitOutputs...)
- if p.Output != nil {
- outputs = append(outputs, p.Output)
- }
- outputFullPaths = append(outputFullPaths, outputs.Strings()...)
+ outputFullPaths = append(outputFullPaths, allOutputs(p)...)
}
return outputFullPaths
}
diff --git a/android/variable.go b/android/variable.go
index 496f523..bf66135 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -469,6 +469,10 @@
SourceRootDirs []string `json:",omitempty"`
AfdoProfiles []string `json:",omitempty"`
+
+ ProductManufacturer string `json:",omitempty"`
+ ProductBrand string `json:",omitempty"`
+ BuildVersionTags []string `json:",omitempty"`
}
func boolPtr(v bool) *bool {
@@ -537,124 +541,102 @@
Module() Module
}
-// ProductConfigProperty contains the information for a single property (may be a struct) paired
-// with the appropriate ProductConfigVariable.
+// ProductConfigOrSoongConfigProperty represents either a soong config variable + its value
+// or a product config variable. You can get both a ConfigurationAxis and a SelectKey from it
+// for use in bazel attributes. ProductVariableProperties() will return a map from properties ->
+// this interface -> property structs for use in bp2build converters
+type ProductConfigOrSoongConfigProperty interface {
+ // Name of the product variable or soong config variable
+ Name() string
+ // AlwaysEmit returns true for soong config variables but false for product variables. This
+ // is intended to indicate if we need to always emit empty lists in the select statements.
+ AlwaysEmit() bool
+ // ConfigurationAxis returns the bazel.ConfigurationAxis that represents this variable. The
+ // configuration axis will change depending on the variable and whether it's arch/os variant
+ // as well.
+ ConfigurationAxis() bazel.ConfigurationAxis
+ // SelectKey returns a string that represents the key of a select branch, however, it is not
+ // actually the real label written out to the build file.
+ // this.ConfigurationAxis().SelectKey(this.SelectKey()) will give the actual label.
+ SelectKey() string
+}
+
+// ProductConfigProperty represents a product config variable, and if it is arch-variant or not.
type ProductConfigProperty struct {
// The name of the product variable, e.g. "safestack", "malloc_not_svelte",
// "board"
- Name string
+ name string
- // Namespace of the variable, if this is a soong_config_module_type variable
- // e.g. "acme", "ANDROID", "vendor_name"
- Namespace string
-
- // Unique configuration to identify this product config property (i.e. a
- // primary key), as just using the product variable name is not sufficient.
- //
- // For product variables, this is the product variable name + optional
- // archvariant information. e.g.
- //
- // product_variables: {
- // foo: {
- // cflags: ["-Dfoo"],
- // },
- // },
- //
- // FullConfig would be "foo".
- //
- // target: {
- // android: {
- // product_variables: {
- // foo: {
- // cflags: ["-Dfoo-android"],
- // },
- // },
- // },
- // },
- //
- // FullConfig would be "foo-android".
- //
- // For soong config variables, this is the namespace + product variable name
- // + value of the variable, if applicable. The value can also be
- // conditions_default.
- //
- // e.g.
- //
- // soong_config_variables: {
- // feature1: {
- // conditions_default: {
- // cflags: ["-DDEFAULT1"],
- // },
- // cflags: ["-DFEATURE1"],
- // },
- // }
- //
- // where feature1 is created in the "acme" namespace, so FullConfig would be
- // "acme__feature1" and "acme__feature1__conditions_default".
- //
- // e.g.
- //
- // soong_config_variables: {
- // board: {
- // soc_a: {
- // cflags: ["-DSOC_A"],
- // },
- // soc_b: {
- // cflags: ["-DSOC_B"],
- // },
- // soc_c: {},
- // conditions_default: {
- // cflags: ["-DSOC_DEFAULT"]
- // },
- // },
- // }
- //
- // where board is created in the "acme" namespace, so FullConfig would be
- // "acme__board__soc_a", "acme__board__soc_b", and
- // "acme__board__conditions_default"
- FullConfig string
-
- // keeps track of whether this product variable is nested under an arch variant
- OuterAxis bazel.ConfigurationAxis
+ arch string
}
-func (p *ProductConfigProperty) AlwaysEmit() bool {
- return p.Namespace != ""
+func (p ProductConfigProperty) Name() string {
+ return p.name
}
-func (p *ProductConfigProperty) ConfigurationAxis() bazel.ConfigurationAxis {
- if p.Namespace == "" {
- return bazel.ProductVariableConfigurationAxis(p.FullConfig, p.OuterAxis)
+func (p ProductConfigProperty) AlwaysEmit() bool {
+ return false
+}
+
+func (p ProductConfigProperty) ConfigurationAxis() bazel.ConfigurationAxis {
+ return bazel.ProductVariableConfigurationAxis(p.arch != "", p.name+"__"+p.arch)
+}
+
+func (p ProductConfigProperty) SelectKey() string {
+ if p.arch == "" {
+ return strings.ToLower(p.name)
} else {
- // Soong config variables can be uniquely identified by the namespace
- // (e.g. acme, android) and the product variable name (e.g. board, size)
- return bazel.ProductVariableConfigurationAxis(p.Namespace+"__"+p.Name, bazel.NoConfigAxis)
+ return strings.ToLower(p.name + "-" + p.arch)
}
}
+// SoongConfigProperty represents a soong config variable, its value if it's a string variable,
+// and if it's dependent on the OS or not
+type SoongConfigProperty struct {
+ name string
+ namespace string
+ // Can be an empty string for bool/value soong config variables
+ value string
+ // If there is a target: field inside a soong config property struct, the os that it selects
+ // on will be represented here.
+ os string
+}
+
+func (p SoongConfigProperty) Name() string {
+ return p.name
+}
+
+func (p SoongConfigProperty) AlwaysEmit() bool {
+ return true
+}
+
+func (p SoongConfigProperty) ConfigurationAxis() bazel.ConfigurationAxis {
+ return bazel.ProductVariableConfigurationAxis(false, p.namespace+"__"+p.name+"__"+p.os)
+}
+
// SelectKey returns the literal string that represents this variable in a BUILD
// select statement.
-func (p *ProductConfigProperty) SelectKey() string {
- if p.Namespace == "" {
- return strings.ToLower(p.FullConfig)
- }
-
- if p.FullConfig == bazel.ConditionsDefaultConfigKey {
+func (p SoongConfigProperty) SelectKey() string {
+ // p.value being conditions_default can happen with or without a desired os. When not using
+ // an os, we want to emit literally just //conditions:default in the select statement, but
+ // when using an os, we want to emit namespace__name__conditions_default__os, so that
+ // the branch is only taken if the variable is not set, and we're on the desired os.
+ // ConfigurationAxis#SelectKey will map the conditions_default result of this function to
+ // //conditions:default.
+ if p.value == bazel.ConditionsDefaultConfigKey && p.os == "" {
return bazel.ConditionsDefaultConfigKey
}
- value := p.FullConfig
- if value == p.Name {
- value = ""
+ parts := []string{p.namespace, p.name}
+ if p.value != "" && p.value != bazel.ConditionsDefaultSelectKey {
+ parts = append(parts, p.value)
+ }
+ if p.os != "" {
+ parts = append(parts, p.os)
}
- // e.g. acme__feature1, android__board__soc_a
- selectKey := strings.ToLower(strings.Join([]string{p.Namespace, p.Name}, "__"))
- if value != "" {
- selectKey = strings.ToLower(strings.Join([]string{selectKey, value}, "__"))
- }
-
- return selectKey
+ // e.g. acme__feature1, android__board__soc_a, my_namespace__my_variables__my_value__my_os
+ return strings.ToLower(strings.Join(parts, "__"))
}
// ProductConfigProperties is a map of maps to group property values according
@@ -670,7 +652,7 @@
//
// The value of the map is the interface{} representing the value of the
// property, like ["-DDEFINES"] for cflags.
-type ProductConfigProperties map[string]map[ProductConfigProperty]interface{}
+type ProductConfigProperties map[string]map[ProductConfigOrSoongConfigProperty]interface{}
// ProductVariableProperties returns a ProductConfigProperties containing only the properties which
// have been set for the given module.
@@ -681,26 +663,10 @@
if moduleBase.variableProperties != nil {
productVariablesProperty := proptools.FieldNameForProperty("product_variables")
- productVariableValues(
- productVariablesProperty,
- moduleBase.variableProperties,
- "",
- "",
- &productConfigProperties,
- bazel.ConfigurationAxis{},
- )
-
- for axis, configToProps := range moduleBase.GetArchVariantProperties(ctx, moduleBase.variableProperties) {
+ for /* axis */ _, configToProps := range moduleBase.GetArchVariantProperties(ctx, moduleBase.variableProperties) {
for config, props := range configToProps {
- // GetArchVariantProperties is creating an instance of the requested type
- // and productVariablesValues expects an interface, so no need to cast
- productVariableValues(
- productVariablesProperty,
- props,
- "",
- config,
- &productConfigProperties,
- axis)
+ variableValues := reflect.ValueOf(props).Elem().FieldByName(productVariablesProperty)
+ productConfigProperties.AddProductConfigProperties(variableValues, config)
}
}
}
@@ -708,13 +674,8 @@
if m, ok := module.(Bazelable); ok && m.namespacedVariableProps() != nil {
for namespace, namespacedVariableProps := range m.namespacedVariableProps() {
for _, namespacedVariableProp := range namespacedVariableProps {
- productVariableValues(
- soongconfig.SoongConfigProperty,
- namespacedVariableProp,
- namespace,
- "",
- &productConfigProperties,
- bazel.NoConfigAxis)
+ variableValues := reflect.ValueOf(namespacedVariableProp).Elem().FieldByName(soongconfig.SoongConfigProperty)
+ productConfigProperties.AddSoongConfigProperties(namespace, variableValues)
}
}
}
@@ -723,30 +684,49 @@
}
func (p *ProductConfigProperties) AddProductConfigProperty(
- propertyName, namespace, productVariableName, config string, property interface{}, outerAxis bazel.ConfigurationAxis) {
- if (*p)[propertyName] == nil {
- (*p)[propertyName] = make(map[ProductConfigProperty]interface{})
- }
+ propertyName, productVariableName, arch string, propertyValue interface{}) {
productConfigProp := ProductConfigProperty{
- Namespace: namespace, // e.g. acme, android
- Name: productVariableName, // e.g. size, feature1, feature2, FEATURE3, board
- FullConfig: config, // e.g. size, feature1-x86, size__conditions_default
- OuterAxis: outerAxis,
+ name: productVariableName, // e.g. size, feature1, feature2, FEATURE3, board
+ arch: arch, // e.g. "", x86, arm64
}
- if existing, ok := (*p)[propertyName][productConfigProp]; ok && namespace != "" {
+ p.AddEitherProperty(propertyName, productConfigProp, propertyValue)
+}
+
+func (p *ProductConfigProperties) AddSoongConfigProperty(
+ propertyName, namespace, variableName, value, os string, propertyValue interface{}) {
+
+ soongConfigProp := SoongConfigProperty{
+ namespace: namespace,
+ name: variableName, // e.g. size, feature1, feature2, FEATURE3, board
+ value: value,
+ os: os, // e.g. android, linux_x86
+ }
+
+ p.AddEitherProperty(propertyName, soongConfigProp, propertyValue)
+}
+
+func (p *ProductConfigProperties) AddEitherProperty(
+ propertyName string, key ProductConfigOrSoongConfigProperty, propertyValue interface{}) {
+ if (*p)[propertyName] == nil {
+ (*p)[propertyName] = make(map[ProductConfigOrSoongConfigProperty]interface{})
+ }
+
+ if existing, ok := (*p)[propertyName][key]; ok {
switch dst := existing.(type) {
case []string:
- if src, ok := property.([]string); ok {
- dst = append(dst, src...)
- (*p)[propertyName][productConfigProp] = dst
+ src, ok := propertyValue.([]string)
+ if !ok {
+ panic("Conflicting types")
}
+ dst = append(dst, src...)
+ (*p)[propertyName][key] = dst
default:
- panic(fmt.Errorf("TODO: handle merging value %s", existing))
+ panic(fmt.Errorf("TODO: handle merging value %#v", existing))
}
} else {
- (*p)[propertyName][productConfigProp] = property
+ (*p)[propertyName][key] = propertyValue
}
}
@@ -783,10 +763,7 @@
return v, true
}
-func (productConfigProperties *ProductConfigProperties) AddProductConfigProperties(namespace, suffix string, variableValues reflect.Value, outerAxis bazel.ConfigurationAxis) {
- // variableValues can either be a product_variables or
- // soong_config_variables struct.
- //
+func (productConfigProperties *ProductConfigProperties) AddProductConfigProperties(variableValues reflect.Value, arch string) {
// Example of product_variables:
//
// product_variables: {
@@ -799,35 +776,7 @@
// ],
// },
// },
- //
- // Example of soong_config_variables:
- //
- // soong_config_variables: {
- // feature1: {
- // conditions_default: {
- // ...
- // },
- // cflags: ...
- // },
- // feature2: {
- // cflags: ...
- // conditions_default: {
- // ...
- // },
- // },
- // board: {
- // soc_a: {
- // ...
- // },
- // soc_a: {
- // ...
- // },
- // soc_c: {},
- // conditions_default: {
- // ...
- // },
- // },
- // }
+
for i := 0; i < variableValues.NumField(); i++ {
// e.g. Platform_sdk_version, Unbundled_build, Malloc_not_svelte, etc.
productVariableName := variableValues.Type().Field(i).Name
@@ -839,25 +788,78 @@
continue
}
- // Unlike product variables, config variables require a few more
- // indirections to extract the struct from the reflect.Value.
- if v, ok := maybeExtractConfigVarProp(variableValue); ok {
- variableValue = v
- }
-
for j := 0; j < variableValue.NumField(); j++ {
property := variableValue.Field(j)
// e.g. Asflags, Cflags, Enabled, etc.
propertyName := variableValue.Type().Field(j).Name
- // config can also be "conditions_default".
- config := proptools.PropertyNameForField(propertyName)
+ if property.Kind() != reflect.Interface {
+ productConfigProperties.AddProductConfigProperty(propertyName, productVariableName, arch, property.Interface())
+ }
+ }
+ }
+
+}
+
+func (productConfigProperties *ProductConfigProperties) AddSoongConfigProperties(namespace string, soongConfigVariablesStruct reflect.Value) {
+ //
+ // Example of soong_config_variables:
+ //
+ // soong_config_variables: {
+ // feature1: {
+ // conditions_default: {
+ // ...
+ // },
+ // cflags: ...
+ // },
+ // feature2: {
+ // cflags: ...
+ // conditions_default: {
+ // ...
+ // },
+ // },
+ // board: {
+ // soc_a: {
+ // ...
+ // },
+ // soc_b: {
+ // ...
+ // },
+ // soc_c: {},
+ // conditions_default: {
+ // ...
+ // },
+ // },
+ // }
+ for i := 0; i < soongConfigVariablesStruct.NumField(); i++ {
+ // e.g. feature1, feature2, board
+ variableName := soongConfigVariablesStruct.Type().Field(i).Name
+ variableStruct := soongConfigVariablesStruct.Field(i)
+ // Check if any properties were set for the module
+ if variableStruct.IsZero() {
+ // e.g. feature1: {}
+ continue
+ }
+
+ // Unlike product variables, config variables require a few more
+ // indirections to extract the struct from the reflect.Value.
+ if v, ok := maybeExtractConfigVarProp(variableStruct); ok {
+ variableStruct = v
+ }
+
+ for j := 0; j < variableStruct.NumField(); j++ {
+ propertyOrStruct := variableStruct.Field(j)
+ // propertyOrValueName can either be:
+ // - A property, like: Asflags, Cflags, Enabled, etc.
+ // - A soong config string variable's value, like soc_a, soc_b, soc_c in the example above
+ // - "conditions_default"
+ propertyOrValueName := variableStruct.Type().Field(j).Name
// If the property wasn't set, no need to pass it along
- if property.IsZero() {
+ if propertyOrStruct.IsZero() {
continue
}
- if v, ok := maybeExtractConfigVarProp(property); ok {
+ if v, ok := maybeExtractConfigVarProp(propertyOrStruct); ok {
// The field is a struct, which is used by:
// 1) soong_config_string_variables
//
@@ -875,6 +877,9 @@
// cflags: ...,
// static_libs: ...
// }
+ //
+ // This means that propertyOrValueName is either conditions_default, or a soong
+ // config string variable's value.
field := v
// Iterate over fields of this struct prop.
for k := 0; k < field.NumField(); k++ {
@@ -884,47 +889,59 @@
if field.Field(k).IsZero() && namespace == "" {
continue
}
- actualPropertyName := field.Type().Field(k).Name
- productConfigProperties.AddProductConfigProperty(
- actualPropertyName, // e.g. cflags, static_libs
- namespace, // e.g. acme, android
- productVariableName, // e.g. size, feature1, FEATURE2, board
- config,
- field.Field(k).Interface(), // e.g. ["-DDEFAULT"], ["foo", "bar"],
- outerAxis,
- )
+ propertyName := field.Type().Field(k).Name
+ if propertyName == "Target" {
+ productConfigProperties.AddSoongConfigPropertiesFromTargetStruct(namespace, variableName, proptools.PropertyNameForField(propertyOrValueName), field.Field(k))
+ } else if propertyName == "Arch" || propertyName == "Multilib" {
+ panic("Arch/Multilib are not currently supported in soong config variable structs")
+ } else {
+ productConfigProperties.AddSoongConfigProperty(propertyName, namespace, variableName, proptools.PropertyNameForField(propertyOrValueName), "", field.Field(k).Interface())
+ }
}
- } else if property.Kind() != reflect.Interface {
+ } else if propertyOrStruct.Kind() != reflect.Interface {
// If not an interface, then this is not a conditions_default or
- // a struct prop. That is, this is a regular product variable,
- // or a bool/value config variable.
- config := productVariableName + suffix
- productConfigProperties.AddProductConfigProperty(
- propertyName,
- namespace,
- productVariableName,
- config,
- property.Interface(),
- outerAxis,
- )
+ // a struct prop. That is, this is a bool/value config variable.
+ if propertyOrValueName == "Target" {
+ productConfigProperties.AddSoongConfigPropertiesFromTargetStruct(namespace, variableName, "", propertyOrStruct)
+ } else if propertyOrValueName == "Arch" || propertyOrValueName == "Multilib" {
+ panic("Arch/Multilib are not currently supported in soong config variable structs")
+ } else {
+ productConfigProperties.AddSoongConfigProperty(propertyOrValueName, namespace, variableName, "", "", propertyOrStruct.Interface())
+ }
}
}
}
}
-// productVariableValues uses reflection to convert a property struct for
-// product_variables and soong_config_variables to structs that can be generated
-// as select statements.
-func productVariableValues(
- fieldName string, variableProps interface{}, namespace, suffix string, productConfigProperties *ProductConfigProperties, outerAxis bazel.ConfigurationAxis) {
- if suffix != "" {
- suffix = "-" + suffix
- }
+func (productConfigProperties *ProductConfigProperties) AddSoongConfigPropertiesFromTargetStruct(namespace, soongConfigVariableName string, soongConfigVariableValue string, targetStruct reflect.Value) {
+ // targetStruct will be a struct with fields like "android", "host", "arm", "x86",
+ // "android_arm", etc. The values of each of those fields will be a regular property struct.
+ for i := 0; i < targetStruct.NumField(); i++ {
+ targetFieldName := targetStruct.Type().Field(i).Name
+ archOrOsSpecificStruct := targetStruct.Field(i)
+ for j := 0; j < archOrOsSpecificStruct.NumField(); j++ {
+ property := archOrOsSpecificStruct.Field(j)
+ // e.g. Asflags, Cflags, Enabled, etc.
+ propertyName := archOrOsSpecificStruct.Type().Field(j).Name
- // variableValues represent the product_variables or soong_config_variables struct.
- variableValues := reflect.ValueOf(variableProps).Elem().FieldByName(fieldName)
- productConfigProperties.AddProductConfigProperties(namespace, suffix, variableValues, outerAxis)
+ if targetFieldName == "Android" {
+ productConfigProperties.AddSoongConfigProperty(propertyName, namespace, soongConfigVariableName, soongConfigVariableValue, "android", property.Interface())
+ } else if targetFieldName == "Host" {
+ for _, os := range osTypeList {
+ if os.Class == Host {
+ productConfigProperties.AddSoongConfigProperty(propertyName, namespace, soongConfigVariableName, soongConfigVariableValue, os.Name, property.Interface())
+ }
+ }
+ } else {
+ // One problem with supporting additional fields is that if multiple branches of
+ // "target" overlap, we don't want them to be in the same select statement (aka
+ // configuration axis). "android" and "host" are disjoint, so it's ok that we only
+ // have 2 axes right now. (soongConfigVariables and soongConfigVariablesPlusOs)
+ panic("TODO: support other target types in soong config variable structs: " + targetFieldName)
+ }
+ }
+ }
}
func VariableMutator(mctx BottomUpMutatorContext) {
diff --git a/apex/apex.go b/apex/apex.go
index af9afb1..33ed111 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -2681,7 +2681,7 @@
}
pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex()
- if pathInApex != "" && !java.SkipDexpreoptBootJars(ctx) {
+ if pathInApex != "" {
pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
@@ -3432,15 +3432,6 @@
// Module separator
//
m[android.AvailableToAnyApex] = []string{
- // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
- "androidx",
- "androidx-constraintlayout_constraintlayout",
- "androidx-constraintlayout_constraintlayout-nodeps",
- "androidx-constraintlayout_constraintlayout-solver",
- "androidx-constraintlayout_constraintlayout-solver-nodeps",
- "com.google.android.material_material",
- "com.google.android.material_material-nodeps",
-
"libclang_rt",
"libprofile-clang-extras",
"libprofile-clang-extras_ndk",
@@ -3709,6 +3700,8 @@
commonAttrs := android.CommonAttributes{}
if a.testApex {
commonAttrs.Testonly = proptools.BoolPtr(true)
+ // Set the api_domain of the test apex
+ attrs.Base_apex_name = proptools.StringPtr(cc.GetApiDomain(a.Name()))
}
return attrs, props, commonAttrs
diff --git a/apex/apex_test.go b/apex/apex_test.go
index e4b0323..bf9c71b 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -4187,6 +4187,174 @@
})
}
+func TestVendorApexWithVndkPrebuilts(t *testing.T) {
+ ctx := testApex(t, "",
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.DeviceVndkVersion = proptools.StringPtr("27")
+ }),
+ android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
+ cc.RegisterVendorSnapshotModules(ctx)
+ }),
+ withFiles(map[string][]byte{
+ "vendor/foo/Android.bp": []byte(`
+ apex {
+ name: "myapex",
+ binaries: ["foo"],
+ key: "myapex.key",
+ min_sdk_version: "27",
+ vendor: true,
+ }
+
+ cc_binary {
+ name: "foo",
+ vendor: true,
+ srcs: ["abc.cpp"],
+ shared_libs: [
+ "libllndk",
+ "libvndk",
+ ],
+ nocrt: true,
+ system_shared_libs: [],
+ min_sdk_version: "27",
+ }
+
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+ `),
+ // Simulate VNDK prebuilts with vendor_snapshot
+ "prebuilts/vndk/Android.bp": []byte(`
+ vndk_prebuilt_shared {
+ name: "libllndk",
+ version: "27",
+ vendor_available: true,
+ product_available: true,
+ target_arch: "arm64",
+ arch: {
+ arm64: {
+ srcs: ["libllndk.so"],
+ },
+ },
+ }
+
+ vndk_prebuilt_shared {
+ name: "libvndk",
+ version: "27",
+ vendor_available: true,
+ product_available: true,
+ target_arch: "arm64",
+ arch: {
+ arm64: {
+ srcs: ["libvndk.so"],
+ },
+ },
+ vndk: {
+ enabled: true,
+ },
+ min_sdk_version: "27",
+ }
+
+ vndk_prebuilt_shared {
+ name: "libc++",
+ version: "27",
+ target_arch: "arm64",
+ vendor_available: true,
+ product_available: true,
+ vndk: {
+ enabled: true,
+ support_system_process: true,
+ },
+ arch: {
+ arm64: {
+ srcs: ["libc++.so"],
+ },
+ },
+ min_sdk_version: "apex_inherit",
+ }
+
+ vendor_snapshot {
+ name: "vendor_snapshot",
+ version: "27",
+ arch: {
+ arm64: {
+ vndk_libs: [
+ "libc++",
+ "libllndk",
+ "libvndk",
+ ],
+ static_libs: [
+ "libc++demangle",
+ "libclang_rt.builtins",
+ "libunwind",
+ ],
+ },
+ }
+ }
+
+ vendor_snapshot_static {
+ name: "libclang_rt.builtins",
+ version: "27",
+ target_arch: "arm64",
+ vendor: true,
+ arch: {
+ arm64: {
+ src: "libclang_rt.builtins-aarch64-android.a",
+ },
+ },
+ }
+
+ vendor_snapshot_static {
+ name: "libc++demangle",
+ version: "27",
+ target_arch: "arm64",
+ compile_multilib: "64",
+ vendor: true,
+ arch: {
+ arm64: {
+ src: "libc++demangle.a",
+ },
+ },
+ min_sdk_version: "apex_inherit",
+ }
+
+ vendor_snapshot_static {
+ name: "libunwind",
+ version: "27",
+ target_arch: "arm64",
+ compile_multilib: "64",
+ vendor: true,
+ arch: {
+ arm64: {
+ src: "libunwind.a",
+ },
+ },
+ min_sdk_version: "apex_inherit",
+ }
+ `),
+ }))
+
+ // Should embed the prebuilt VNDK libraries in the apex
+ ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
+ "bin/foo",
+ "prebuilts/vndk/libc++.so:lib64/libc++.so",
+ "prebuilts/vndk/libvndk.so:lib64/libvndk.so",
+ })
+
+ // Should link foo with prebuilt libraries (shared/static)
+ ldRule := ctx.ModuleForTests("foo", "android_vendor.27_arm64_armv8-a_myapex").Rule("ld")
+ android.AssertStringDoesContain(t, "should link to prebuilt llndk", ldRule.Args["libFlags"], "prebuilts/vndk/libllndk.so")
+ android.AssertStringDoesContain(t, "should link to prebuilt vndk", ldRule.Args["libFlags"], "prebuilts/vndk/libvndk.so")
+ android.AssertStringDoesContain(t, "should link to prebuilt libc++demangle", ldRule.Args["libFlags"], "prebuilts/vndk/libc++demangle.a")
+ android.AssertStringDoesContain(t, "should link to prebuilt libunwind", ldRule.Args["libFlags"], "prebuilts/vndk/libunwind.a")
+
+ // Should declare the LLNDK library as a "required" external dependency
+ manifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
+ requireNativeLibs := names(manifestRule.Args["requireNativeLibs"])
+ ensureListContains(t, requireNativeLibs, "libllndk.so")
+}
+
func TestDependenciesInApexManifest(t *testing.T) {
ctx := testApex(t, `
apex {
diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go
index d784818..3e55ccc 100644
--- a/apex/bootclasspath_fragment_test.go
+++ b/apex/bootclasspath_fragment_test.go
@@ -497,6 +497,26 @@
})
})
+ t.Run("generate boot image profile even if dexpreopt is disabled", func(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ commonPreparer,
+
+ // Configure some libraries in the art bootclasspath_fragment that match the source
+ // bootclasspath_fragment's contents property.
+ java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
+ addSource("foo", "bar"),
+ java.FixtureSetBootImageInstallDirOnDevice("art", "system/framework"),
+ dexpreopt.FixtureDisableDexpreoptBootImages(true),
+ ).RunTest(t)
+
+ ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
+ "etc/boot-image.prof",
+ "etc/classpaths/bootclasspath.pb",
+ "javalib/bar.jar",
+ "javalib/foo.jar",
+ })
+ })
+
t.Run("boot image disable generate profile", func(t *testing.T) {
result := android.GroupFixturePreparers(
commonPreparer,
diff --git a/bazel/configurability.go b/bazel/configurability.go
index d01877d..d042fe8 100644
--- a/bazel/configurability.go
+++ b/bazel/configurability.go
@@ -69,8 +69,8 @@
productVariableBazelPackage = "//build/bazel/product_variables"
- AndroidAndInApex = "android-in_apex"
- AndroidAndNonApex = "android-non_apex"
+ AndroidAndInApex = "android-in_apex"
+ AndroidPlatform = "system"
InApex = "in_apex"
NonApex = "non_apex"
@@ -202,7 +202,7 @@
osAndInApexMap = map[string]string{
AndroidAndInApex: "//build/bazel/rules/apex:android-in_apex",
- AndroidAndNonApex: "//build/bazel/rules/apex:android-non_apex",
+ AndroidPlatform: "//build/bazel/rules/apex:system",
osDarwin: "//build/bazel/platforms/os:darwin",
osLinux: "//build/bazel/platforms/os:linux_glibc",
osLinuxMusl: "//build/bazel/platforms/os:linux_musl",
@@ -292,8 +292,7 @@
case osArch:
return platformOsArchMap[config]
case productVariables:
- if strings.HasSuffix(config, ConditionsDefaultConfigKey) {
- // e.g. "acme__feature1__conditions_default" or "android__board__conditions_default"
+ if config == ConditionsDefaultConfigKey {
return ConditionsDefaultSelectKey
}
return fmt.Sprintf("%s:%s", productVariableBazelPackage, config)
@@ -325,11 +324,11 @@
)
// ProductVariableConfigurationAxis returns an axis for the given product variable
-func ProductVariableConfigurationAxis(variable string, outerAxis ConfigurationAxis) ConfigurationAxis {
+func ProductVariableConfigurationAxis(archVariant bool, variable string) ConfigurationAxis {
return ConfigurationAxis{
configurationType: productVariables,
subType: variable,
- outerAxisType: outerAxis.configurationType,
+ archVariant: archVariant,
}
}
@@ -340,8 +339,8 @@
// some configuration types (e.g. productVariables) have multiple independent axes, subType helps
// distinguish between them without needing to list all 17 product variables.
subType string
- // used to keep track of which product variables are arch variant
- outerAxisType configurationType
+
+ archVariant bool
}
func (ca *ConfigurationAxis) less(other ConfigurationAxis) bool {
diff --git a/bazel/properties.go b/bazel/properties.go
index 1757bad..e22f4db 100644
--- a/bazel/properties.go
+++ b/bazel/properties.go
@@ -334,7 +334,7 @@
if containsArch {
allProductVariablesAreArchVariant := true
for k := range la.ConfigurableValues {
- if k.configurationType == productVariables && k.outerAxisType != arch {
+ if k.configurationType == productVariables && !k.archVariant {
allProductVariablesAreArchVariant = false
}
}
@@ -1434,4 +1434,6 @@
type ConfigSettingAttributes struct {
// Each key in Flag_values is a label to a custom string_setting
Flag_values StringMapAttribute
+ // Each element in Constraint_values is a label to a constraint_value
+ Constraint_values LabelListAttribute
}
diff --git a/bazel/properties_test.go b/bazel/properties_test.go
index cf03eb5..c56d11f 100644
--- a/bazel/properties_test.go
+++ b/bazel/properties_test.go
@@ -248,13 +248,13 @@
OsArchConfigurationAxis: labelListSelectValues{
"linux_x86": makeLabelList([]string{"linux_x86_include"}, []string{}),
},
- ProductVariableConfigurationAxis("product_with_defaults", NoConfigAxis): labelListSelectValues{
+ ProductVariableConfigurationAxis(false, "product_with_defaults"): labelListSelectValues{
"a": makeLabelList([]string{}, []string{"not_in_value"}),
"b": makeLabelList([]string{"b_val"}, []string{}),
"c": makeLabelList([]string{"c_val"}, []string{}),
ConditionsDefaultConfigKey: makeLabelList([]string{"c_val", "default", "default2", "all_exclude"}, []string{}),
},
- ProductVariableConfigurationAxis("product_only_with_excludes", NoConfigAxis): labelListSelectValues{
+ ProductVariableConfigurationAxis(false, "product_only_with_excludes"): labelListSelectValues{
"a": makeLabelList([]string{}, []string{"product_config_exclude"}),
},
},
@@ -282,13 +282,13 @@
"linux_x86": makeLabels("linux_x86_include"),
ConditionsDefaultConfigKey: nilLabels,
},
- ProductVariableConfigurationAxis("product_with_defaults", NoConfigAxis): {
+ ProductVariableConfigurationAxis(false, "product_with_defaults"): {
"a": nilLabels,
"b": makeLabels("b_val"),
"c": makeLabels("c_val"),
ConditionsDefaultConfigKey: makeLabels("c_val", "default", "default2"),
},
- ProductVariableConfigurationAxis("product_only_with_excludes", NoConfigAxis): {
+ ProductVariableConfigurationAxis(false, "product_only_with_excludes"): {
"a": nilLabels,
ConditionsDefaultConfigKey: makeLabels("product_config_exclude"),
},
@@ -679,7 +679,7 @@
OsArchConfigurationAxis: stringListSelectValues{
"linux_x86": {"linux_x86_include"},
},
- ProductVariableConfigurationAxis("a", NoConfigAxis): stringListSelectValues{
+ ProductVariableConfigurationAxis(false, "a"): stringListSelectValues{
"a": []string{"not_in_value"},
},
},
@@ -704,7 +704,7 @@
"linux": []string{"linux_include"},
},
OsArchConfigurationAxis: stringListSelectValues{},
- ProductVariableConfigurationAxis("a", NoConfigAxis): stringListSelectValues{
+ ProductVariableConfigurationAxis(false, "a"): stringListSelectValues{
"a": []string{"not_in_value"},
},
}
diff --git a/bp2build/android_app_conversion_test.go b/bp2build/android_app_conversion_test.go
index 928a1f2..7f7aa6a 100644
--- a/bp2build/android_app_conversion_test.go
+++ b/bp2build/android_app_conversion_test.go
@@ -80,6 +80,7 @@
static_libs: ["static_lib_dep"],
java_version: "7",
certificate: "foocert",
+ required: ["static_lib_dep"],
}
`,
ExpectedBazelTargets: []string{
diff --git a/bp2build/apex_conversion_test.go b/bp2build/apex_conversion_test.go
index 1cc3f22..390cabe 100644
--- a/bp2build/apex_conversion_test.go
+++ b/bp2build/apex_conversion_test.go
@@ -1475,10 +1475,11 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "test_com.android.apogee", AttrNameToString{
- "file_contexts": `"file_contexts_file"`,
- "manifest": `"apex_manifest.json"`,
- "testonly": `True`,
- "tests": `[":cc_test_1"]`,
+ "file_contexts": `"file_contexts_file"`,
+ "base_apex_name": `"com.android.apogee"`,
+ "manifest": `"apex_manifest.json"`,
+ "testonly": `True`,
+ "tests": `[":cc_test_1"]`,
}),
}})
}
diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go
index 1b64055..e127fd5 100644
--- a/bp2build/build_conversion_test.go
+++ b/bp2build/build_conversion_test.go
@@ -21,6 +21,7 @@
"android/soong/android"
"android/soong/android/allowlists"
+ "android/soong/bazel"
"android/soong/python"
)
@@ -1931,3 +1932,17 @@
Description: "Generating API contribution Bazel targets for custom module",
})
}
+
+// If values of all keys in an axis are equal to //conditions:default, drop the axis and print the common value
+func TestPrettyPrintSelectMapEqualValues(t *testing.T) {
+ lla := bazel.LabelListAttribute{
+ Value: bazel.LabelList{},
+ }
+ libFooImplLabel := bazel.Label{
+ Label: ":libfoo.impl",
+ }
+ lla.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidPlatform, bazel.MakeLabelList([]bazel.Label{libFooImplLabel}))
+ lla.SetSelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, bazel.MakeLabelList([]bazel.Label{libFooImplLabel}))
+ actual, _ := prettyPrintAttribute(lla, 0)
+ android.AssertStringEquals(t, "Print the common value if all keys in an axis have the same value", `[":libfoo.impl"]`, actual)
+}
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 776129f..1b681ef 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -3042,7 +3042,8 @@
}`,
ExpectedBazelTargets: makeCcLibraryTargets("foolib", AttrNameToString{
"implementation_dynamic_deps": `select({
- "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:barlib"],
+ "//build/bazel/rules/apex:foo": ["@api_surfaces//module-libapi/current:barlib"],
+ "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:barlib"],
"//conditions:default": [":barlib"],
})`,
"local_includes": `["."]`,
@@ -3096,7 +3097,11 @@
"//build/bazel/platforms/os:linux_glibc": [":quxlib"],
"//build/bazel/platforms/os:linux_musl": [":quxlib"],
"//build/bazel/platforms/os:windows": [":quxlib"],
- "//build/bazel/rules/apex:android-in_apex": [
+ "//build/bazel/rules/apex:foo": [
+ "@api_surfaces//module-libapi/current:barlib",
+ "@api_surfaces//module-libapi/current:quxlib",
+ ],
+ "//build/bazel/rules/apex:system": [
"@api_surfaces//module-libapi/current:barlib",
"@api_surfaces//module-libapi/current:quxlib",
],
@@ -4139,44 +4144,34 @@
name: "barlib",
stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] },
bazel_module: { bp2build_available: false },
+ apex_available: ["//apex_available:platform",],
}
cc_library {
name: "bazlib",
stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] },
bazel_module: { bp2build_available: false },
+ apex_available: ["//apex_available:platform",],
}
cc_library {
name: "foo",
shared_libs: ["barlib", "bazlib"],
export_shared_lib_headers: ["bazlib"],
apex_available: [
- "apex_available:platform",
+ "//apex_available:platform",
],
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
- "implementation_dynamic_deps": `select({
- "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:barlib"],
- "//conditions:default": [":barlib"],
- })`,
- "dynamic_deps": `select({
- "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:bazlib"],
- "//conditions:default": [":bazlib"],
- })`,
- "local_includes": `["."]`,
- "tags": `["apex_available=apex_available:platform"]`,
+ "implementation_dynamic_deps": `[":barlib"]`,
+ "dynamic_deps": `[":bazlib"]`,
+ "local_includes": `["."]`,
+ "tags": `["apex_available=//apex_available:platform"]`,
}),
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "implementation_dynamic_deps": `select({
- "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:barlib"],
- "//conditions:default": [":barlib"],
- })`,
- "dynamic_deps": `select({
- "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:bazlib"],
- "//conditions:default": [":bazlib"],
- })`,
- "local_includes": `["."]`,
- "tags": `["apex_available=apex_available:platform"]`,
+ "implementation_dynamic_deps": `[":barlib"]`,
+ "dynamic_deps": `[":bazlib"]`,
+ "local_includes": `["."]`,
+ "tags": `["apex_available=//apex_available:platform"]`,
}),
},
})
@@ -4473,11 +4468,12 @@
ExpectedBazelTargets: []string{
MakeBazelTargetNoRestrictions(
"config_setting",
- "android-in_myapex",
+ "myapex",
AttrNameToString{
"flag_values": `{
- "//build/bazel/rules/apex:apex_name": "myapex",
+ "//build/bazel/rules/apex:api_domain": "myapex",
}`,
+ "constraint_values": `["//build/bazel/platforms/os:android"]`,
},
),
},
diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go
index 47dff8a..2ee9c99 100644
--- a/bp2build/cc_library_shared_conversion_test.go
+++ b/bp2build/cc_library_shared_conversion_test.go
@@ -609,7 +609,8 @@
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
"implementation_dynamic_deps": `select({
- "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:a"],
+ "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
+ "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
"//conditions:default": [":a"],
})`,
"tags": `["apex_available=apex_b"]`,
@@ -618,6 +619,64 @@
})
}
+// Tests that library in apexfoo links against stubs of platform_lib and otherapex_lib
+func TestCcLibrarySharedStubs_UseStubsFromMultipleApiDomains(t *testing.T) {
+ runCcLibrarySharedTestCase(t, Bp2buildTestCase{
+ Description: "cc_library_shared stubs",
+ ModuleTypeUnderTest: "cc_library_shared",
+ ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
+ Blueprint: soongCcLibrarySharedPreamble + `
+cc_library_shared {
+ name: "libplatform_stable",
+ stubs: { symbol_file: "libplatform_stable.map.txt", versions: ["28", "29", "current"] },
+ apex_available: ["//apex_available:platform"],
+ bazel_module: { bp2build_available: false },
+ include_build_directory: false,
+}
+cc_library_shared {
+ name: "libapexfoo_stable",
+ stubs: { symbol_file: "libapexfoo_stable.map.txt", versions: ["28", "29", "current"] },
+ apex_available: ["apexfoo"],
+ bazel_module: { bp2build_available: false },
+ include_build_directory: false,
+}
+cc_library_shared {
+ name: "libutils",
+ shared_libs: ["libplatform_stable", "libapexfoo_stable",],
+ apex_available: ["//apex_available:platform", "apexfoo", "apexbar"],
+ include_build_directory: false,
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_library_shared", "libutils", AttrNameToString{
+ "implementation_dynamic_deps": `select({
+ "//build/bazel/rules/apex:apexbar": [
+ "@api_surfaces//module-libapi/current:libplatform_stable",
+ "@api_surfaces//module-libapi/current:libapexfoo_stable",
+ ],
+ "//build/bazel/rules/apex:apexfoo": [
+ "@api_surfaces//module-libapi/current:libplatform_stable",
+ ":libapexfoo_stable",
+ ],
+ "//build/bazel/rules/apex:system": [
+ "@api_surfaces//module-libapi/current:libplatform_stable",
+ "@api_surfaces//module-libapi/current:libapexfoo_stable",
+ ],
+ "//conditions:default": [
+ ":libplatform_stable",
+ ":libapexfoo_stable",
+ ],
+ })`,
+ "tags": `[
+ "apex_available=//apex_available:platform",
+ "apex_available=apexfoo",
+ "apex_available=apexbar",
+ ]`,
+ }),
+ },
+ })
+}
+
func TestCcLibrarySharedStubs_IgnorePlatformAvailable(t *testing.T) {
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
Description: "cc_library_shared stubs",
@@ -641,7 +700,8 @@
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
"implementation_dynamic_deps": `select({
- "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:a"],
+ "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
+ "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
"//conditions:default": [":a"],
})`,
"tags": `[
@@ -653,6 +713,34 @@
})
}
+func TestCcLibraryDoesNotDropStubDepIfNoVariationAcrossAxis(t *testing.T) {
+ runCcLibrarySharedTestCase(t, Bp2buildTestCase{
+ Description: "cc_library depeends on impl for all configurations",
+ ModuleTypeUnderTest: "cc_library_shared",
+ ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
+ Blueprint: soongCcLibrarySharedPreamble + `
+cc_library_shared {
+ name: "a",
+ stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
+ bazel_module: { bp2build_available: false },
+ apex_available: ["//apex_available:platform"],
+}
+cc_library_shared {
+ name: "b",
+ shared_libs: [":a"],
+ include_build_directory: false,
+ apex_available: ["//apex_available:platform"],
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
+ "implementation_dynamic_deps": `[":a"]`,
+ "tags": `["apex_available=//apex_available:platform"]`,
+ }),
+ },
+ })
+}
+
func TestCcLibrarySharedStubs_MultipleApexAvailable(t *testing.T) {
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
ModuleTypeUnderTest: "cc_library_shared",
@@ -682,7 +770,7 @@
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
"implementation_dynamic_deps": `select({
- "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:a"],
+ "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
"//conditions:default": [":a"],
})`,
"tags": `[
diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go
index 9488014..2705aaf 100644
--- a/bp2build/cc_library_static_conversion_test.go
+++ b/bp2build/cc_library_static_conversion_test.go
@@ -1504,6 +1504,7 @@
versions: ["current"],
},
bazel_module: { bp2build_available: false },
+ apex_available: ["com.android.runtime"],
}
cc_library_static {
@@ -1561,7 +1562,8 @@
}),
MakeBazelTarget("cc_library_static", "keep_with_stubs", AttrNameToString{
"implementation_dynamic_deps": `select({
- "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:libm"],
+ "//build/bazel/rules/apex:foo": ["@api_surfaces//module-libapi/current:libm"],
+ "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:libm"],
"//conditions:default": [":libm"],
})`,
"system_dynamic_deps": `[]`,
diff --git a/bp2build/configurability.go b/bp2build/configurability.go
index 8e17103..3d9f0a2 100644
--- a/bp2build/configurability.go
+++ b/bp2build/configurability.go
@@ -279,6 +279,10 @@
}
if len(selects) == 0 {
+ // If there is a default value, and there are no selects for this axis, print that without any selects.
+ if val, exists := selectMap[bazel.ConditionsDefaultSelectKey]; exists {
+ return prettyPrint(val, indent, emitZeroValues)
+ }
// No conditions (or all values are empty lists), so no need for a map.
return "", nil
}
diff --git a/bp2build/java_binary_host_conversion_test.go b/bp2build/java_binary_host_conversion_test.go
index c821f59..e51f608 100644
--- a/bp2build/java_binary_host_conversion_test.go
+++ b/bp2build/java_binary_host_conversion_test.go
@@ -259,17 +259,20 @@
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
Description: "java_binary_host with srcs, libs, resources.",
Filesystem: map[string]string{
- "test.mf": "Main-Class: com.android.test.MainClass",
- "res/a.res": "",
- "res/b.res": "",
- },
- Blueprint: `java_binary_host {
+ "adir/test.mf": "Main-Class: com.android.test.MainClass",
+ "adir/res/a.res": "",
+ "adir/res/b.res": "",
+ "adir/Android.bp": `java_binary_host {
name: "java-binary-host",
manifest: "test.mf",
srcs: ["a.java", "b.kt"],
java_resources: ["res/a.res", "res/b.res"],
+ bazel_module: { bp2build_available: true },
}
`,
+ },
+ Dir: "adir",
+ Blueprint: "",
ExpectedBazelTargets: []string{
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
"srcs": `[
@@ -280,6 +283,7 @@
"res/a.res",
"res/b.res",
]`,
+ "resource_strip_prefix": `"adir"`,
"target_compatible_with": `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
diff --git a/bp2build/java_library_conversion_test.go b/bp2build/java_library_conversion_test.go
index 24b763b..60766f4 100644
--- a/bp2build/java_library_conversion_test.go
+++ b/bp2build/java_library_conversion_test.go
@@ -283,21 +283,25 @@
func TestJavaLibraryResources(t *testing.T) {
runJavaLibraryTestCase(t, Bp2buildTestCase{
+ Dir: "adir",
Filesystem: map[string]string{
- "res/a.res": "",
- "res/b.res": "",
- "res/dir1/b.res": "",
- },
- Blueprint: `java_library {
+ "adir/res/a.res": "",
+ "adir/res/b.res": "",
+ "adir/res/dir1/b.res": "",
+ "adir/Android.bp": `java_library {
name: "java-lib-1",
- java_resources: ["res/a.res", "res/b.res"],
+ java_resources: ["res/a.res", "res/b.res"],
+ bazel_module: { bp2build_available: true },
}`,
+ },
+ Blueprint: "",
ExpectedBazelTargets: []string{
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
"resources": `[
"res/a.res",
"res/b.res",
]`,
+ "resource_strip_prefix": `"adir"`,
}),
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
},
diff --git a/bp2build/package_conversion_test.go b/bp2build/package_conversion_test.go
index 3704b2d..ce848e4 100644
--- a/bp2build/package_conversion_test.go
+++ b/bp2build/package_conversion_test.go
@@ -15,9 +15,10 @@
package bp2build
import (
+ "testing"
+
"android/soong/android"
"android/soong/genrule"
- "testing"
)
func registerDependentModules(ctx android.RegistrationContext) {
@@ -29,6 +30,7 @@
tests := []struct {
description string
modules string
+ fs map[string]string
expected []ExpectedRuleTarget
}{
{
@@ -50,8 +52,8 @@
"package",
"",
AttrNameToString{
- "default_applicable_licenses": `[":my_license"]`,
- "default_visibility": `["//visibility:public"]`,
+ "default_package_metadata": `[":my_license"]`,
+ "default_visibility": `["//visibility:public"]`,
},
android.HostAndDeviceDefault,
},
@@ -67,6 +69,57 @@
},
},
},
+ {
+ description: "package has METADATA file",
+ fs: map[string]string{
+ "METADATA": ``,
+ },
+ modules: `
+license {
+ name: "my_license",
+ visibility: [":__subpackages__"],
+ license_kinds: ["SPDX-license-identifier-Apache-2.0"],
+ license_text: ["NOTICE"],
+}
+
+package {
+ default_applicable_licenses: ["my_license"],
+}
+`,
+ expected: []ExpectedRuleTarget{
+ {
+ "package",
+ "",
+ AttrNameToString{
+ "default_package_metadata": `[
+ ":my_license",
+ ":default_metadata_file",
+ ]`,
+ "default_visibility": `["//visibility:public"]`,
+ },
+ android.HostAndDeviceDefault,
+ },
+ {
+ "android_license",
+ "my_license",
+ AttrNameToString{
+ "license_kinds": `["SPDX-license-identifier-Apache-2.0"]`,
+ "license_text": `"NOTICE"`,
+ "visibility": `[":__subpackages__"]`,
+ },
+ android.HostAndDeviceDefault,
+ },
+ {
+ "filegroup",
+ "default_metadata_file",
+ AttrNameToString{
+ "applicable_licenses": `[]`,
+ "srcs": `["METADATA"]`,
+ },
+ android.HostAndDeviceDefault,
+ },
+ },
+ },
}
for _, test := range tests {
expected := make([]string, 0, len(test.expected))
@@ -80,6 +133,7 @@
ModuleTypeUnderTestFactory: android.PackageFactory,
Blueprint: test.modules,
ExpectedBazelTargets: expected,
+ Filesystem: test.fs,
})
}
}
diff --git a/bp2build/soong_config_module_type_conversion_test.go b/bp2build/soong_config_module_type_conversion_test.go
index ba42f34..ad07f68 100644
--- a/bp2build/soong_config_module_type_conversion_test.go
+++ b/bp2build/soong_config_module_type_conversion_test.go
@@ -1251,3 +1251,111 @@
srcs = ["main.cc"],
)`}})
}
+
+func TestSoongConfigModuleType_CombinedWithArchVariantProperties(t *testing.T) {
+ bp := `
+soong_config_bool_variable {
+ name: "my_bool_variable",
+}
+
+soong_config_string_variable {
+ name: "my_string_variable",
+ values: [
+ "value1",
+ "value2",
+ ],
+}
+
+soong_config_module_type {
+ name: "special_build_cc_defaults",
+ module_type: "cc_defaults",
+ config_namespace: "my_namespace",
+ bool_variables: ["my_bool_variable"],
+ variables: ["my_string_variable"],
+ properties: ["target.android.cflags", "cflags"],
+}
+
+special_build_cc_defaults {
+ name: "sample_cc_defaults",
+ target: {
+ android: {
+ cflags: ["-DFOO"],
+ },
+ },
+ soong_config_variables: {
+ my_bool_variable: {
+ target: {
+ android: {
+ cflags: ["-DBAR"],
+ },
+ },
+ conditions_default: {
+ target: {
+ android: {
+ cflags: ["-DBAZ"],
+ },
+ },
+ },
+ },
+ my_string_variable: {
+ value1: {
+ cflags: ["-DVALUE1_NOT_ANDROID"],
+ target: {
+ android: {
+ cflags: ["-DVALUE1"],
+ },
+ },
+ },
+ value2: {
+ target: {
+ android: {
+ cflags: ["-DVALUE2"],
+ },
+ },
+ },
+ conditions_default: {
+ target: {
+ android: {
+ cflags: ["-DSTRING_VAR_CONDITIONS_DEFAULT"],
+ },
+ },
+ },
+ },
+ },
+}
+
+cc_binary {
+ name: "my_binary",
+ srcs: ["main.cc"],
+ defaults: ["sample_cc_defaults"],
+}`
+
+ runSoongConfigModuleTypeTest(t, Bp2buildTestCase{
+ Description: "soong config variables - generates selects for library_linking_strategy",
+ ModuleTypeUnderTest: "cc_binary",
+ ModuleTypeUnderTestFactory: cc.BinaryFactory,
+ Blueprint: bp,
+ Filesystem: map[string]string{},
+ ExpectedBazelTargets: []string{`cc_binary(
+ name = "my_binary",
+ copts = select({
+ "//build/bazel/platforms/os:android": ["-DFOO"],
+ "//conditions:default": [],
+ }) + select({
+ "//build/bazel/product_variables:my_namespace__my_bool_variable__android": ["-DBAR"],
+ "//build/bazel/product_variables:my_namespace__my_bool_variable__conditions_default__android": ["-DBAZ"],
+ "//conditions:default": [],
+ }) + select({
+ "//build/bazel/product_variables:my_namespace__my_string_variable__value1": ["-DVALUE1_NOT_ANDROID"],
+ "//conditions:default": [],
+ }) + select({
+ "//build/bazel/product_variables:my_namespace__my_string_variable__conditions_default__android": ["-DSTRING_VAR_CONDITIONS_DEFAULT"],
+ "//build/bazel/product_variables:my_namespace__my_string_variable__value1__android": ["-DVALUE1"],
+ "//build/bazel/product_variables:my_namespace__my_string_variable__value2__android": ["-DVALUE2"],
+ "//conditions:default": [],
+ }),
+ local_includes = ["."],
+ srcs = ["main.cc"],
+ target_compatible_with = ["//build/bazel/platforms/os:android"],
+)`}})
+}
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 749fce5..cf5f74d 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -537,7 +537,7 @@
if !ok {
ctx.ModuleErrorf("Could not convert product variable %s property", proptools.PropertyNameForField(propName))
}
- newFlags, _ := bazel.TryVariableSubstitutions(flags, productConfigProp.Name)
+ newFlags, _ := bazel.TryVariableSubstitutions(flags, productConfigProp.Name())
attr.SetSelectValue(productConfigProp.ConfigurationAxis(), productConfigProp.SelectKey(), newFlags)
}
}
@@ -1194,16 +1194,34 @@
}
var (
- apexConfigSettingKey = android.NewOnceKey("apexConfigSetting")
- apexConfigSettingLock sync.Mutex
+ apiDomainConfigSettingKey = android.NewOnceKey("apiDomainConfigSettingKey")
+ apiDomainConfigSettingLock sync.Mutex
)
-func getApexConfigSettingMap(config android.Config) *map[string]bool {
- return config.Once(apexConfigSettingKey, func() interface{} {
+func getApiDomainConfigSettingMap(config android.Config) *map[string]bool {
+ return config.Once(apiDomainConfigSettingKey, func() interface{} {
return &map[string]bool{}
}).(*map[string]bool)
}
+var (
+ testApexNameToApiDomain = map[string]string{
+ "test_broken_com.android.art": "com.android.art",
+ }
+)
+
+// GetApiDomain returns the canonical name of the apex. This is synonymous to the apex_name definition.
+// https://cs.android.com/android/_/android/platform/build/soong/+/e3f0281b8897da1fe23b2f4f3a05f1dc87bcc902:apex/prebuilt.go;l=81-83;drc=2dc7244af985a6ad701b22f1271e606cabba527f;bpv=1;bpt=0
+// For test apexes, it uses a naming convention heuristic to determine the api domain.
+// TODO (b/281548611): Move this build/soong/android
+func GetApiDomain(apexName string) string {
+ if apiDomain, exists := testApexNameToApiDomain[apexName]; exists {
+ return apiDomain
+ }
+ // Remove `test_` prefix
+ return strings.TrimPrefix(apexName, "test_")
+}
+
// Create a config setting for this apex in build/bazel/rules/apex
// The use case for this is stub/impl selection in cc libraries
// Long term, these config_setting(s) should be colocated with the respective apex definitions.
@@ -1215,23 +1233,32 @@
// These correspond to android-non_apex and android-in_apex
return
}
- apexConfigSettingLock.Lock()
- defer apexConfigSettingLock.Unlock()
+ apiDomainConfigSettingLock.Lock()
+ defer apiDomainConfigSettingLock.Unlock()
// Return if a config_setting has already been created
- acsm := getApexConfigSettingMap(ctx.Config())
- if _, exists := (*acsm)[apexName]; exists {
+ apiDomain := GetApiDomain(apexName)
+ acsm := getApiDomainConfigSettingMap(ctx.Config())
+ if _, exists := (*acsm)[apiDomain]; exists {
return
}
- (*acsm)[apexName] = true
+ (*acsm)[apiDomain] = true
csa := bazel.ConfigSettingAttributes{
Flag_values: bazel.StringMapAttribute{
- "//build/bazel/rules/apex:apex_name": apexName,
+ "//build/bazel/rules/apex:api_domain": apiDomain,
},
+ // Constraint this to android
+ Constraint_values: bazel.MakeLabelListAttribute(
+ bazel.MakeLabelList(
+ []bazel.Label{
+ bazel.Label{Label: "//build/bazel/platforms/os:android"},
+ },
+ ),
+ ),
}
ca := android.CommonAttributes{
- Name: "android-in_" + apexName,
+ Name: apiDomain,
}
ctx.CreateBazelConfigSetting(
csa,
@@ -1242,66 +1269,111 @@
func inApexConfigSetting(apexAvailable string) string {
if apexAvailable == android.AvailableToPlatform {
- return bazel.AndroidAndNonApex
+ return bazel.AndroidPlatform
}
if apexAvailable == android.AvailableToAnyApex {
return bazel.AndroidAndInApex
}
- return "//build/bazel/rules/apex:android-in_" + apexAvailable
+ apiDomain := GetApiDomain(apexAvailable)
+ return "//build/bazel/rules/apex:" + apiDomain
+}
+
+// Inputs to stub vs impl selection.
+type stubSelectionInfo struct {
+ // Label of the implementation library (e.g. //bionic/libc:libc)
+ impl bazel.Label
+ // Axis containing the implementation library
+ axis bazel.ConfigurationAxis
+ // Axis key containing the implementation library
+ config string
+ // API domain of the apex
+ // For test apexes (test_com.android.foo), this will be the source apex (com.android.foo)
+ apiDomain string
+ // List of dep labels
+ dynamicDeps *bazel.LabelListAttribute
+ // Boolean value for determining if the dep is in the same api domain
+ // If false, the label will be rewritten to to the stub label
+ sameApiDomain bool
+}
+
+func useStubOrImplInApexWithName(ssi stubSelectionInfo) {
+ lib := ssi.impl
+ if !ssi.sameApiDomain {
+ lib = bazel.Label{
+ Label: apiSurfaceModuleLibCurrentPackage + strings.TrimPrefix(lib.OriginalModuleName, ":"),
+ }
+ }
+ // Create a select statement specific to this apex
+ inApexSelectValue := ssi.dynamicDeps.SelectValue(bazel.OsAndInApexAxis, inApexConfigSetting(ssi.apiDomain))
+ (&inApexSelectValue).Append(bazel.MakeLabelList([]bazel.Label{lib}))
+ ssi.dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, inApexConfigSetting(ssi.apiDomain), bazel.FirstUniqueBazelLabelList(inApexSelectValue))
+ // Delete the library from the common config for this apex
+ implDynamicDeps := ssi.dynamicDeps.SelectValue(ssi.axis, ssi.config)
+ implDynamicDeps = bazel.SubtractBazelLabelList(implDynamicDeps, bazel.MakeLabelList([]bazel.Label{ssi.impl}))
+ ssi.dynamicDeps.SetSelectValue(ssi.axis, ssi.config, implDynamicDeps)
+ if ssi.axis == bazel.NoConfigAxis {
+ // Set defaults. Defaults (i.e. host) should use impl and not stubs.
+ defaultSelectValue := ssi.dynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey)
+ (&defaultSelectValue).Append(bazel.MakeLabelList([]bazel.Label{ssi.impl}))
+ ssi.dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, bazel.FirstUniqueBazelLabelList(defaultSelectValue))
+ }
}
func setStubsForDynamicDeps(ctx android.BazelConversionPathContext, axis bazel.ConfigurationAxis,
config string, apexAvailable []string, dynamicLibs bazel.LabelList, dynamicDeps *bazel.LabelListAttribute, ind int, buildNonApexWithStubs bool) {
- depsWithStubs := []bazel.Label{}
- for _, l := range dynamicLibs.Includes {
- dep, _ := ctx.ModuleFromName(l.OriginalModuleName)
- if d, ok := dep.(*Module); ok && d.HasStubsVariants() {
- depApexAvailable := d.ApexAvailable()
- if !availableToSameApexes(apexAvailable, depApexAvailable) {
- depsWithStubs = append(depsWithStubs, l)
- }
- }
- }
- if len(depsWithStubs) > 0 {
- implDynamicDeps := bazel.SubtractBazelLabelList(dynamicLibs, bazel.MakeLabelList(depsWithStubs))
- dynamicDeps.SetSelectValue(axis, config, implDynamicDeps)
-
- stubLibLabels := []bazel.Label{}
- for _, l := range depsWithStubs {
- stubLabelInApiSurfaces := bazel.Label{
- Label: apiSurfaceModuleLibCurrentPackage + strings.TrimPrefix(l.OriginalModuleName, ":"),
- }
- stubLibLabels = append(stubLibLabels, stubLabelInApiSurfaces)
- }
- inApexSelectValue := dynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex)
- nonApexSelectValue := dynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex)
- defaultSelectValue := dynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey)
- nonApexDeps := depsWithStubs
- if buildNonApexWithStubs {
- nonApexDeps = stubLibLabels
- }
- if axis == bazel.NoConfigAxis {
- (&inApexSelectValue).Append(bazel.MakeLabelList(stubLibLabels))
- (&nonApexSelectValue).Append(bazel.MakeLabelList(nonApexDeps))
- (&defaultSelectValue).Append(bazel.MakeLabelList(depsWithStubs))
- dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, bazel.FirstUniqueBazelLabelList(inApexSelectValue))
- dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, bazel.FirstUniqueBazelLabelList(nonApexSelectValue))
- dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, bazel.FirstUniqueBazelLabelList(defaultSelectValue))
- } else if config == bazel.OsAndroid {
- (&inApexSelectValue).Append(bazel.MakeLabelList(stubLibLabels))
- (&nonApexSelectValue).Append(bazel.MakeLabelList(nonApexDeps))
- dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, bazel.FirstUniqueBazelLabelList(inApexSelectValue))
- dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, bazel.FirstUniqueBazelLabelList(nonApexSelectValue))
- }
- }
-
// Create a config_setting for each apex_available.
// This will be used to select impl of a dep if dep is available to the same apex.
for _, aa := range apexAvailable {
createInApexConfigSetting(ctx.(android.TopDownMutatorContext), aa)
}
+ apiDomainForSelects := []string{}
+ for _, apex := range apexAvailable {
+ apiDomainForSelects = append(apiDomainForSelects, GetApiDomain(apex))
+ }
+ // Always emit a select statement for the platform variant.
+ // This ensures that b build //foo --config=android works
+ // Soong always creates a platform variant even when the library might not be available to platform.
+ if !android.InList(android.AvailableToPlatform, apiDomainForSelects) {
+ apiDomainForSelects = append(apiDomainForSelects, android.AvailableToPlatform)
+ }
+ apiDomainForSelects = android.SortedUniqueStrings(apiDomainForSelects)
+
+ // Create a select for each apex this library could be included in.
+ for _, l := range dynamicLibs.Includes {
+ dep, _ := ctx.ModuleFromName(l.OriginalModuleName)
+ if c, ok := dep.(*Module); !ok || !c.HasStubsVariants() {
+ continue
+ }
+ // TODO (b/280339069): Decrease the verbosity of the generated BUILD files
+ for _, apiDomain := range apiDomainForSelects {
+ var sameApiDomain bool
+ if apiDomain == android.AvailableToPlatform {
+ // Platform variants in Soong use equality of apex_available for stub/impl selection.
+ // https://cs.android.com/android/_/android/platform/build/soong/+/316b0158fe57ee7764235923e7c6f3d530da39c6:cc/cc.go;l=3393-3404;drc=176271a426496fa2688efe2b40d5c74340c63375;bpv=1;bpt=0
+ // One of the factors behind this design choice is cc_test
+ // Tests only have a platform variant, and using equality of apex_available ensures
+ // that tests of an apex library gets its implementation and not stubs.
+ // TODO (b/280343104): Discuss if we can drop this special handling for platform variants.
+ sameApiDomain = availableToSameApexes(apexAvailable, dep.(*Module).ApexAvailable())
+ if linkable, ok := ctx.Module().(LinkableInterface); ok && linkable.Bootstrap() {
+ sameApiDomain = true
+ }
+ } else {
+ sameApiDomain = android.InList(apiDomain, dep.(*Module).ApexAvailable())
+ }
+ ssi := stubSelectionInfo{
+ impl: l,
+ axis: axis,
+ config: config,
+ apiDomain: apiDomain,
+ dynamicDeps: dynamicDeps,
+ sameApiDomain: sameApiDomain,
+ }
+ useStubOrImplInApexWithName(ssi)
+ }
+ }
}
func (la *linkerAttributes) convertStripProps(ctx android.BazelConversionPathContext, module *Module) {
@@ -1350,7 +1422,7 @@
// Collect all the configurations that an include or exclude property exists for.
// We want to iterate all configurations rather than either the include or exclude because, for a
// particular configuration, we may have either only an include or an exclude to handle.
- productConfigProps := make(map[android.ProductConfigProperty]bool, len(props)+len(excludeProps))
+ productConfigProps := make(map[android.ProductConfigOrSoongConfigProperty]bool, len(props)+len(excludeProps))
for p := range props {
productConfigProps[p] = true
}
@@ -1396,7 +1468,6 @@
la.implementationDynamicDeps.Exclude(bazel.OsConfigurationAxis, "linux_bionic", toRemove)
la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, toRemove)
- la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, toRemove)
stubsToRemove := make([]bazel.Label, 0, len(la.usedSystemDynamicDepAsDynamicDep))
for _, lib := range toRemove.Includes {
stubLabelInApiSurfaces := bazel.Label{
@@ -1404,7 +1475,12 @@
}
stubsToRemove = append(stubsToRemove, stubLabelInApiSurfaces)
}
- la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, bazel.MakeLabelList(stubsToRemove))
+ // system libraries (e.g. libc, libm, libdl) belong the com.android.runtime api domain
+ // dedupe the stubs of these libraries from the other api domains (platform, other_apexes...)
+ for _, aa := range ctx.Module().(*Module).ApexAvailable() {
+ la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, inApexConfigSetting(aa), bazel.MakeLabelList(stubsToRemove))
+ }
+ la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.AndroidPlatform, bazel.MakeLabelList(stubsToRemove))
}
la.deps.ResolveExcludes()
diff --git a/cc/cc.go b/cc/cc.go
index 3fbefcd..7237686 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1086,7 +1086,7 @@
panic(fmt.Errorf("FuzzPackagedModule called on non-fuzz module: %q", c.BaseModuleName()))
}
-func (c *Module) FuzzSharedLibraries() android.Paths {
+func (c *Module) FuzzSharedLibraries() android.RuleBuilderInstalls {
if fuzzer, ok := c.compiler.(*fuzzBinary); ok {
return fuzzer.sharedLibraries
}
diff --git a/cc/fuzz.go b/cc/fuzz.go
index 7aa8b91..dfefc11 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -103,7 +103,7 @@
*baseCompiler
fuzzPackagedModule fuzz.FuzzPackagedModule
installedSharedDeps []string
- sharedLibraries android.Paths
+ sharedLibraries android.RuleBuilderInstalls
}
func (fuzz *fuzzBinary) fuzzBinary() bool {
@@ -213,19 +213,19 @@
}
func SharedLibraryInstallLocation(
- libraryPath android.Path, isHost bool, fuzzDir string, archString string) string {
+ libraryBase string, isHost bool, fuzzDir string, archString string) string {
installLocation := "$(PRODUCT_OUT)/data"
if isHost {
installLocation = "$(HOST_OUT)"
}
installLocation = filepath.Join(
- installLocation, fuzzDir, archString, "lib", libraryPath.Base())
+ installLocation, fuzzDir, archString, "lib", libraryBase)
return installLocation
}
// Get the device-only shared library symbols install directory.
-func SharedLibrarySymbolsInstallLocation(libraryPath android.Path, fuzzDir string, archString string) string {
- return filepath.Join("$(PRODUCT_OUT)/symbols/data/", fuzzDir, archString, "/lib/", libraryPath.Base())
+func SharedLibrarySymbolsInstallLocation(libraryBase string, fuzzDir string, archString string) string {
+ return filepath.Join("$(PRODUCT_OUT)/symbols/data/", fuzzDir, archString, "/lib/", libraryBase)
}
func (fuzzBin *fuzzBinary) install(ctx ModuleContext, file android.Path) {
@@ -242,15 +242,16 @@
// Grab the list of required shared libraries.
fuzzBin.sharedLibraries, _ = CollectAllSharedDependencies(ctx)
- for _, lib := range fuzzBin.sharedLibraries {
+ for _, ruleBuilderInstall := range fuzzBin.sharedLibraries {
+ install := ruleBuilderInstall.To
fuzzBin.installedSharedDeps = append(fuzzBin.installedSharedDeps,
SharedLibraryInstallLocation(
- lib, ctx.Host(), installBase, ctx.Arch().ArchType.String()))
+ install, ctx.Host(), installBase, ctx.Arch().ArchType.String()))
// Also add the dependency on the shared library symbols dir.
if !ctx.Host() {
fuzzBin.installedSharedDeps = append(fuzzBin.installedSharedDeps,
- SharedLibrarySymbolsInstallLocation(lib, installBase, ctx.Arch().ArchType.String()))
+ SharedLibrarySymbolsInstallLocation(install, installBase, ctx.Arch().ArchType.String()))
}
}
}
@@ -422,7 +423,7 @@
files = append(files, GetSharedLibsToZip(ccModule.FuzzSharedLibraries(), ccModule, &s.FuzzPackager, archString, sharedLibsInstallDirPrefix, &sharedLibraryInstalled)...)
// The executable.
- files = append(files, fuzz.FileToZip{android.OutputFileForModule(ctx, ccModule, "unstripped"), ""})
+ files = append(files, fuzz.FileToZip{SourceFilePath: android.OutputFileForModule(ctx, ccModule, "unstripped")})
archDirs[archOs], ok = s.BuildZipFile(ctx, module, fpm, files, builder, archDir, archString, hostOrTargetString, archOs, archDirs)
if !ok {
@@ -453,19 +454,25 @@
// GetSharedLibsToZip finds and marks all the transiently-dependent shared libraries for
// packaging.
-func GetSharedLibsToZip(sharedLibraries android.Paths, module LinkableInterface, s *fuzz.FuzzPackager, archString string, destinationPathPrefix string, sharedLibraryInstalled *map[string]bool) []fuzz.FileToZip {
+func GetSharedLibsToZip(sharedLibraries android.RuleBuilderInstalls, module LinkableInterface, s *fuzz.FuzzPackager, archString string, destinationPathPrefix string, sharedLibraryInstalled *map[string]bool) []fuzz.FileToZip {
var files []fuzz.FileToZip
fuzzDir := "fuzz"
- for _, library := range sharedLibraries {
- files = append(files, fuzz.FileToZip{library, destinationPathPrefix})
+ for _, ruleBuilderInstall := range sharedLibraries {
+ library := ruleBuilderInstall.From
+ install := ruleBuilderInstall.To
+ files = append(files, fuzz.FileToZip{
+ SourceFilePath: library,
+ DestinationPathPrefix: destinationPathPrefix,
+ DestinationPath: install,
+ })
// For each architecture-specific shared library dependency, we need to
// install it to the output directory. Setup the install destination here,
// which will be used by $(copy-many-files) in the Make backend.
installDestination := SharedLibraryInstallLocation(
- library, module.Host(), fuzzDir, archString)
+ install, module.Host(), fuzzDir, archString)
if (*sharedLibraryInstalled)[installDestination] {
continue
}
@@ -483,7 +490,7 @@
// we want symbolization tools (like `stack`) to be able to find the symbols
// in $ANDROID_PRODUCT_OUT/symbols automagically.
if !module.Host() {
- symbolsInstallDestination := SharedLibrarySymbolsInstallLocation(library, fuzzDir, archString)
+ symbolsInstallDestination := SharedLibrarySymbolsInstallLocation(install, fuzzDir, archString)
symbolsInstallDestination = strings.ReplaceAll(symbolsInstallDestination, "$", "$$")
s.SharedLibInstallStrings = append(s.SharedLibInstallStrings,
library.String()+":"+symbolsInstallDestination)
@@ -497,12 +504,12 @@
// VisitDirectDeps is used first to avoid incorrectly using the core libraries (sanitizer
// runtimes, libc, libdl, etc.) from a dependency. This may cause issues when dependencies
// have explicit sanitizer tags, as we may get a dependency on an unsanitized libc, etc.
-func CollectAllSharedDependencies(ctx android.ModuleContext) (android.Paths, []android.Module) {
+func CollectAllSharedDependencies(ctx android.ModuleContext) (android.RuleBuilderInstalls, []android.Module) {
seen := make(map[string]bool)
recursed := make(map[string]bool)
deps := []android.Module{}
- var sharedLibraries android.Paths
+ var sharedLibraries android.RuleBuilderInstalls
// Enumerate the first level of dependencies, as we discard all non-library
// modules in the BFS loop below.
@@ -510,22 +517,36 @@
if !IsValidSharedDependency(dep) {
return
}
+ if !ctx.OtherModuleHasProvider(dep, SharedLibraryInfoProvider) {
+ return
+ }
if seen[ctx.OtherModuleName(dep)] {
return
}
seen[ctx.OtherModuleName(dep)] = true
deps = append(deps, dep)
- sharedLibraries = append(sharedLibraries, android.OutputFileForModule(ctx, dep, "unstripped"))
+
+ sharedLibraryInfo := ctx.OtherModuleProvider(dep, SharedLibraryInfoProvider).(SharedLibraryInfo)
+ installDestination := sharedLibraryInfo.SharedLibrary.Base()
+ ruleBuilderInstall := android.RuleBuilderInstall{android.OutputFileForModule(ctx, dep, "unstripped"), installDestination}
+ sharedLibraries = append(sharedLibraries, ruleBuilderInstall)
})
ctx.WalkDeps(func(child, parent android.Module) bool {
if !IsValidSharedDependency(child) {
return false
}
+ if !ctx.OtherModuleHasProvider(child, SharedLibraryInfoProvider) {
+ return false
+ }
if !seen[ctx.OtherModuleName(child)] {
seen[ctx.OtherModuleName(child)] = true
deps = append(deps, child)
- sharedLibraries = append(sharedLibraries, android.OutputFileForModule(ctx, child, "unstripped"))
+
+ sharedLibraryInfo := ctx.OtherModuleProvider(child, SharedLibraryInfoProvider).(SharedLibraryInfo)
+ installDestination := sharedLibraryInfo.SharedLibrary.Base()
+ ruleBuilderInstall := android.RuleBuilderInstall{android.OutputFileForModule(ctx, child, "unstripped"), installDestination}
+ sharedLibraries = append(sharedLibraries, ruleBuilderInstall)
}
if recursed[ctx.OtherModuleName(child)] {
diff --git a/cc/linkable.go b/cc/linkable.go
index 9578807..557f5d2 100644
--- a/cc/linkable.go
+++ b/cc/linkable.go
@@ -130,7 +130,7 @@
// FuzzSharedLibraries returns the shared library dependencies for this module.
// Expects that IsFuzzModule returns true.
- FuzzSharedLibraries() android.Paths
+ FuzzSharedLibraries() android.RuleBuilderInstalls
Device() bool
Host() bool
diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go
index 51f23c5..d2531c0 100644
--- a/cc/vendor_snapshot.go
+++ b/cc/vendor_snapshot.go
@@ -250,7 +250,11 @@
for _, path := range m.VintfFragments() {
prop.VintfFragments = append(prop.VintfFragments, filepath.Join("configs", path.Base()))
}
- prop.MinSdkVersion = m.MinSdkVersion()
+ if m.IsPrebuilt() {
+ prop.MinSdkVersion = "apex_inherit"
+ } else {
+ prop.MinSdkVersion = m.MinSdkVersion()
+ }
// install config files. ignores any duplicates.
for _, path := range append(m.InitRc(), m.VintfFragments()...) {
diff --git a/cc/vendor_snapshot_test.go b/cc/vendor_snapshot_test.go
index 5b69a10..c5431b3 100644
--- a/cc/vendor_snapshot_test.go
+++ b/cc/vendor_snapshot_test.go
@@ -23,6 +23,17 @@
"testing"
)
+func checkJsonContents(t *testing.T, ctx android.TestingSingleton, jsonPath string, key string, value string) {
+ jsonOut := ctx.MaybeOutput(jsonPath)
+ if jsonOut.Rule == nil {
+ t.Errorf("%q expected but not found", jsonPath)
+ return
+ }
+ if !strings.Contains(jsonOut.Args["content"], fmt.Sprintf("%q:%q", key, value)) {
+ t.Errorf("%q must include %q:%q but it only has %v", jsonPath, key, value, jsonOut.Args["content"])
+ }
+}
+
func TestVendorSnapshotCapture(t *testing.T) {
bp := `
cc_library {
@@ -52,6 +63,7 @@
name: "libvendor_available",
vendor_available: true,
nocrt: true,
+ min_sdk_version: "29",
}
cc_library_headers {
@@ -155,6 +167,9 @@
filepath.Join(staticDir, "libvendor_available.a.json"),
filepath.Join(staticDir, "libvendor_available.cfi.a.json"))
+ checkJsonContents(t, snapshotSingleton, filepath.Join(staticDir, "libb.a.json"), "MinSdkVersion", "apex_inherit")
+ checkJsonContents(t, snapshotSingleton, filepath.Join(staticDir, "libvendor_available.a.json"), "MinSdkVersion", "29")
+
// For binary executables, all vendor:true and vendor_available modules are captured.
if archType == "arm64" {
binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
diff --git a/cc/vndk.go b/cc/vndk.go
index 30bfdd8..9b70004 100644
--- a/cc/vndk.go
+++ b/cc/vndk.go
@@ -241,7 +241,7 @@
func vndkModuleLister(predicate func(*Module) bool) moduleListerFunc {
return func(ctx android.SingletonContext) (moduleNames, fileNames []string) {
ctx.VisitAllModules(func(m android.Module) {
- if c, ok := m.(*Module); ok && predicate(c) {
+ if c, ok := m.(*Module); ok && predicate(c) && !c.IsVndkPrebuiltLibrary() {
filename, err := getVndkFileName(c)
if err != nil {
ctx.ModuleErrorf(m, "%s", err)
@@ -402,6 +402,11 @@
m.VendorProperties.IsVNDKPrivate = Bool(prebuiltLib.Properties.Llndk.Private)
}
+ if m.IsVndkPrebuiltLibrary() && !m.IsVndk() {
+ m.VendorProperties.IsLLNDK = true
+ // TODO(b/280697209): copy "llndk.private" flag to vndk_prebuilt_shared
+ }
+
if (isLib && lib.buildShared()) || (isPrebuiltLib && prebuiltLib.buildShared()) {
if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
processVndkLibrary(mctx, m)
diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go
index 301246a..1c6aaad 100644
--- a/cmd/soong_ui/main.go
+++ b/cmd/soong_ui/main.go
@@ -94,12 +94,12 @@
}, {
flag: "--upload-metrics-only",
description: "upload metrics without building anything",
- config: uploadOnlyConfig,
+ config: build.UploadOnlyConfig,
stdio: stdio,
// Upload-only mode mostly skips to the metrics-uploading phase of soong_ui.
// However, this invocation marks the true "end of the build", and thus we
// need to update the total runtime of the build to include this upload step.
- run: updateTotalRealTime,
+ run: finalizeBazelMetrics,
},
}
@@ -203,8 +203,6 @@
bazelMetricsFile := filepath.Join(logsDir, c.logsPrefix+"bazel_metrics.pb")
soongBuildMetricsFile := filepath.Join(logsDir, c.logsPrefix+"soong_build_metrics.pb")
- //the profile file generated by Bazel"
- bazelProfileFile := filepath.Join(logsDir, c.logsPrefix+"analyzed_bazel_profile.txt")
metricsFiles := []string{
buildErrorFile, // build error strings
rbeMetricsFile, // high level metrics related to remote build execution.
@@ -226,7 +224,7 @@
criticalPath.WriteToMetrics(met)
met.Dump(soongMetricsFile)
if !config.SkipMetricsUpload() {
- build.UploadMetrics(buildCtx, config, c.simpleOutput, buildStarted, bazelProfileFile, bazelMetricsFile, metricsFiles...)
+ build.UploadMetrics(buildCtx, config, c.simpleOutput, buildStarted, metricsFiles...)
}
}()
c.run(buildCtx, config, args)
@@ -451,14 +449,6 @@
return build.NewConfig(ctx)
}
-// uploadOnlyConfig explicitly requires no arguments.
-func uploadOnlyConfig(ctx build.Context, args ...string) build.Config {
- if len(args) > 0 {
- fmt.Printf("--upload-only does not require arguments.")
- }
- return build.UploadOnlyConfig(ctx)
-}
-
func buildActionConfig(ctx build.Context, args ...string) build.Config {
flags := flag.NewFlagSet("build-mode", flag.ContinueOnError)
flags.SetOutput(ctx.Writer)
@@ -700,6 +690,15 @@
}
}
+func finalizeBazelMetrics(ctx build.Context, config build.Config, args []string) {
+ updateTotalRealTime(ctx, config, args)
+
+ logsDir := config.LogsDir()
+ logsPrefix := config.GetLogsPrefix()
+ bazelMetricsFile := filepath.Join(logsDir, logsPrefix+"bazel_metrics.pb")
+ bazelProfileFile := filepath.Join(logsDir, logsPrefix+"analyzed_bazel_profile.txt")
+ build.ProcessBazelMetrics(bazelProfileFile, bazelMetricsFile, ctx, config)
+}
func updateTotalRealTime(ctx build.Context, config build.Config, args []string) {
soongMetricsFile := filepath.Join(config.LogsDir(), "soong_metrics")
@@ -710,7 +709,7 @@
}
met := ctx.ContextImpl.Metrics
- err = met.UpdateTotalRealTime(data)
+ err = met.UpdateTotalRealTimeAndNonZeroExit(data, config.BazelExitCode())
if err != nil {
ctx.Fatal(err)
}
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index 609a29c..0cc3bd6 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -475,7 +475,16 @@
ctx.AddFarVariationDependencies(v, Dex2oatDepTag, dex2oatBin)
}
+func IsDex2oatNeeded(ctx android.PathContext) bool {
+ global := GetGlobalConfig(ctx)
+ return !global.DisablePreopt || !global.DisablePreoptBootImages
+}
+
func dex2oatPathFromDep(ctx android.ModuleContext) android.Path {
+ if !IsDex2oatNeeded(ctx) {
+ return nil
+ }
+
dex2oatBin := dex2oatModuleName(ctx.Config())
// Find the right dex2oat module, trying to follow PrebuiltDepTag from source
diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go
index a590c72..2b38793 100644
--- a/dexpreopt/dexpreopt.go
+++ b/dexpreopt/dexpreopt.go
@@ -100,11 +100,19 @@
return rule, nil
}
+// If dexpreopt is applicable to the module, returns whether dexpreopt is disabled. Otherwise, the
+// behavior is undefined.
+// When it returns true, dexpreopt artifacts will not be generated, but profile will still be
+// generated if profile-guided compilation is requested.
func dexpreoptDisabled(ctx android.PathContext, global *GlobalConfig, module *ModuleConfig) bool {
if ctx.Config().UnbundledBuild() {
return true
}
+ if global.DisablePreopt {
+ return true
+ }
+
if contains(global.DisablePreoptModules, module.Name) {
return true
}
diff --git a/dexpreopt/testing.go b/dexpreopt/testing.go
index 47ae494..6ed0736 100644
--- a/dexpreopt/testing.go
+++ b/dexpreopt/testing.go
@@ -174,3 +174,17 @@
dexpreoptConfig.DisableGenerateProfile = disable
})
}
+
+// FixtureDisableDexpreoptBootImages sets the DisablePreoptBootImages property in the global config.
+func FixtureDisableDexpreoptBootImages(disable bool) android.FixturePreparer {
+ return FixtureModifyGlobalConfig(func(_ android.PathContext, dexpreoptConfig *GlobalConfig) {
+ dexpreoptConfig.DisablePreoptBootImages = disable
+ })
+}
+
+// FixtureDisableDexpreopt sets the DisablePreopt property in the global config.
+func FixtureDisableDexpreopt(disable bool) android.FixturePreparer {
+ return FixtureModifyGlobalConfig(func(_ android.PathContext, dexpreoptConfig *GlobalConfig) {
+ dexpreoptConfig.DisablePreopt = disable
+ })
+}
diff --git a/fuzz/fuzz_common.go b/fuzz/fuzz_common.go
index f76529d..2a1b404 100644
--- a/fuzz/fuzz_common.go
+++ b/fuzz/fuzz_common.go
@@ -61,6 +61,7 @@
type FileToZip struct {
SourceFilePath android.Path
DestinationPathPrefix string
+ DestinationPath string
}
type ArchOs struct {
@@ -443,7 +444,7 @@
FlagWithOutput("-o ", corpusZip)
rspFile := corpusZip.ReplaceExtension(ctx, "rsp")
command.FlagWithRspFileInputList("-r ", rspFile, fuzzModule.Corpus)
- files = append(files, FileToZip{corpusZip, ""})
+ files = append(files, FileToZip{SourceFilePath: corpusZip})
}
// Package the data into a zipfile.
@@ -456,17 +457,17 @@
command.FlagWithArg("-C ", intermediateDir)
command.FlagWithInput("-f ", f)
}
- files = append(files, FileToZip{dataZip, ""})
+ files = append(files, FileToZip{SourceFilePath: dataZip})
}
// The dictionary.
if fuzzModule.Dictionary != nil {
- files = append(files, FileToZip{fuzzModule.Dictionary, ""})
+ files = append(files, FileToZip{SourceFilePath: fuzzModule.Dictionary})
}
// Additional fuzz config.
if fuzzModule.Config != nil && IsValidConfig(fuzzModule, module.Name()) {
- files = append(files, FileToZip{fuzzModule.Config, ""})
+ files = append(files, FileToZip{SourceFilePath: fuzzModule.Config})
}
return files
@@ -485,6 +486,9 @@
} else {
command.Flag("-P ''")
}
+ if file.DestinationPath != "" {
+ command.FlagWithArg("-e ", file.DestinationPath)
+ }
command.FlagWithInput("-f ", file.SourceFilePath)
}
@@ -502,7 +506,7 @@
}
s.FuzzTargets[module.Name()] = true
- archDirs[archOs] = append(archDirs[archOs], FileToZip{fuzzZip, ""})
+ archDirs[archOs] = append(archDirs[archOs], FileToZip{SourceFilePath: fuzzZip})
return archDirs[archOs], true
}
diff --git a/java/app.go b/java/app.go
index da9c6f3..4656cae 100755
--- a/java/app.go
+++ b/java/app.go
@@ -1622,7 +1622,7 @@
ctx.CreateBazelTargetModule(
props,
- android.CommonAttributes{Name: a.Name()},
+ android.CommonAttributes{Name: a.Name(), SkipData: proptools.BoolPtr(true)},
appAttrs,
)
diff --git a/java/app_import.go b/java/app_import.go
index 52ae024..9c01960 100644
--- a/java/app_import.go
+++ b/java/app_import.go
@@ -335,12 +335,11 @@
if proptools.Bool(a.properties.Preprocessed) {
output := srcApk
- // TODO(b/185811447) Uncomment this after all existing failing apks set skip_preprocessed_apk_checks: true
- //if !proptools.Bool(a.properties.Skip_preprocessed_apk_checks) {
- // writableOutput := android.PathForModuleOut(ctx, "validated-prebuilt", apkFilename)
- // a.validatePreprocessedApk(ctx, srcApk, writableOutput)
- // output = writableOutput
- //}
+ if !proptools.Bool(a.properties.Skip_preprocessed_apk_checks) {
+ writableOutput := android.PathForModuleOut(ctx, "validated-prebuilt", apkFilename)
+ a.validatePreprocessedApk(ctx, srcApk, writableOutput)
+ output = writableOutput
+ }
a.outputFile = output
a.certificate = PresignedCertificate
} else if !Bool(a.properties.Presigned) {
diff --git a/java/app_import_test.go b/java/app_import_test.go
index 845a962..bb8fab9 100644
--- a/java/app_import_test.go
+++ b/java/app_import_test.go
@@ -657,29 +657,28 @@
}
}
-// TODO(b/185811447) Uncomment this after all existing failing apks set skip_preprocessed_apk_checks: true
-//func TestAndroidAppImport_Preprocessed(t *testing.T) {
-// ctx, _ := testJava(t, `
-// android_app_import {
-// name: "foo",
-// apk: "prebuilts/apk/app.apk",
-// presigned: true,
-// preprocessed: true,
-// }
-// `)
-//
-// apkName := "foo.apk"
-// variant := ctx.ModuleForTests("foo", "android_common")
-// outputBuildParams := variant.Output("validated-prebuilt/" + apkName).BuildParams
-// if outputBuildParams.Rule.String() != android.Cp.String() {
-// t.Errorf("Unexpected prebuilt android_app_import rule: " + outputBuildParams.Rule.String())
-// }
-//
-// // Make sure compression and aligning were validated.
-// if len(outputBuildParams.Validations) != 2 {
-// t.Errorf("Expected compression/alignment validation rules, found %d validations", len(outputBuildParams.Validations))
-// }
-//}
+func TestAndroidAppImport_Preprocessed(t *testing.T) {
+ ctx, _ := testJava(t, `
+ android_app_import {
+ name: "foo",
+ apk: "prebuilts/apk/app.apk",
+ presigned: true,
+ preprocessed: true,
+ }
+ `)
+
+ apkName := "foo.apk"
+ variant := ctx.ModuleForTests("foo", "android_common")
+ outputBuildParams := variant.Output("validated-prebuilt/" + apkName).BuildParams
+ if outputBuildParams.Rule.String() != android.Cp.String() {
+ t.Errorf("Unexpected prebuilt android_app_import rule: " + outputBuildParams.Rule.String())
+ }
+
+ // Make sure compression and aligning were validated.
+ if len(outputBuildParams.Validations) != 2 {
+ t.Errorf("Expected compression/alignment validation rules, found %d validations", len(outputBuildParams.Validations))
+ }
+}
func TestAndroidTestImport_UncompressDex(t *testing.T) {
testCases := []struct {
diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go
index f692563..6ccf5a3 100644
--- a/java/bootclasspath_fragment.go
+++ b/java/bootclasspath_fragment.go
@@ -506,7 +506,7 @@
}
}
- if SkipDexpreoptBootJars(ctx) {
+ if !dexpreopt.IsDex2oatNeeded(ctx) {
return
}
@@ -901,10 +901,6 @@
// produceBootImageFiles builds the boot image files from the source if it is required.
func (b *BootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageOutputs {
- if SkipDexpreoptBootJars(ctx) {
- return bootImageOutputs{}
- }
-
// Only generate the boot image if the configuration does not skip it.
return b.generateBootImageBuildActions(ctx, imageConfig)
}
@@ -929,6 +925,13 @@
// Build a profile for the image config and then use that to build the boot image.
profile := bootImageProfileRule(ctx, imageConfig)
+ // If dexpreopt of boot image jars should be skipped, generate only a profile.
+ if SkipDexpreoptBootJars(ctx) {
+ return bootImageOutputs{
+ profile: profile,
+ }
+ }
+
// Build boot image files for the host variants.
buildBootImageVariantsForBuildOs(ctx, imageConfig, profile)
diff --git a/java/dex.go b/java/dex.go
index 4d6aa34..f7c1361 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -140,7 +140,7 @@
`$r8Template${config.R8Cmd} ${config.R8Flags} -injars $tmpJar --output $outDir ` +
`--no-data-resources ` +
`-printmapping ${outDict} ` +
- `--pg-conf-output ${outConfig} ` +
+ `-printconfiguration ${outConfig} ` +
`-printusage ${outUsage} ` +
`--deps-file ${out}.d ` +
`$r8Flags && ` +
diff --git a/java/dex_test.go b/java/dex_test.go
index 97fc3d0..2ba3831 100644
--- a/java/dex_test.go
+++ b/java/dex_test.go
@@ -23,7 +23,7 @@
)
func TestR8(t *testing.T) {
- result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, `
+ result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, `
android_app {
name: "app",
srcs: ["foo.java"],
@@ -191,7 +191,7 @@
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
- fixturePreparer := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd
+ fixturePreparer := PrepareForTestWithJavaDefaultModules
if tc.unbundled {
fixturePreparer = android.GroupFixturePreparers(
fixturePreparer,
@@ -258,7 +258,7 @@
}
func TestR8Flags(t *testing.T) {
- result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, `
+ result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, `
android_app {
name: "app",
srcs: ["foo.java"],
@@ -287,7 +287,7 @@
}
func TestD8(t *testing.T) {
- result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, `
+ result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, `
java_library {
name: "foo",
srcs: ["foo.java"],
@@ -328,7 +328,7 @@
}
func TestProguardFlagsInheritance(t *testing.T) {
- result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, `
+ result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, `
android_app {
name: "app",
static_libs: [
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index 0ffedf6..a96b312 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -180,6 +180,8 @@
return android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName())
}
+// Returns whether dexpreopt is applicable to the module.
+// When it returns true, neither profile nor dexpreopt artifacts will be generated.
func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool {
if !ctx.Device() {
return true
@@ -205,14 +207,6 @@
global := dexpreopt.GetGlobalConfig(ctx)
- if global.DisablePreopt {
- return true
- }
-
- if inList(moduleName(ctx), global.DisablePreoptModules) {
- return true
- }
-
isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx))
if isApexVariant(ctx) {
// Don't preopt APEX variant module unless the module is an APEX system server jar.
@@ -232,7 +226,7 @@
}
func dexpreoptToolDepsMutator(ctx android.BottomUpMutatorContext) {
- if d, ok := ctx.Module().(DexpreopterInterface); !ok || d.dexpreoptDisabled(ctx) {
+ if d, ok := ctx.Module().(DexpreopterInterface); !ok || d.dexpreoptDisabled(ctx) || !dexpreopt.IsDex2oatNeeded(ctx) {
return
}
dexpreopt.RegisterToolDeps(ctx)
diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go
index f4c0935..8e79674 100644
--- a/java/dexpreopt_bootjars.go
+++ b/java/dexpreopt_bootjars.go
@@ -500,9 +500,6 @@
// Generate build rules for boot images.
func (d *dexpreoptBootJars) GenerateSingletonBuildActions(ctx android.SingletonContext) {
- if SkipDexpreoptBootJars(ctx) {
- return
- }
if dexpreopt.GetCachedGlobalSoongConfig(ctx) == nil {
// No module has enabled dexpreopting, so we assume there will be no boot image to make.
return
@@ -1002,7 +999,7 @@
// (make/core/dex_preopt_libart.mk) to generate install rules that copy boot image files to the
// correct output directories.
func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) {
- if d.dexpreoptConfigForMake != nil {
+ if d.dexpreoptConfigForMake != nil && !SkipDexpreoptBootJars(ctx) {
ctx.Strict("DEX_PREOPT_CONFIG_FOR_MAKE", d.dexpreoptConfigForMake.String())
ctx.Strict("DEX_PREOPT_SOONG_CONFIG_FOR_MAKE", android.PathForOutput(ctx, "dexpreopt_soong.config").String())
}
@@ -1014,6 +1011,10 @@
ctx.Strict("DEXPREOPT_IMAGE_PROFILE_LICENSE_METADATA", image.profileLicenseMetadataFile.String())
}
+ if SkipDexpreoptBootJars(ctx) {
+ return
+ }
+
global := dexpreopt.GetGlobalConfig(ctx)
dexPaths, dexLocations := bcpForDexpreopt(ctx, global.PreoptWithUpdatableBcp)
ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_FILES", strings.Join(dexPaths.Strings(), " "))
diff --git a/java/dexpreopt_test.go b/java/dexpreopt_test.go
index 3d2c5c3..f91ac5c 100644
--- a/java/dexpreopt_test.go
+++ b/java/dexpreopt_test.go
@@ -438,3 +438,28 @@
android.AssertIntEquals(t, "entries count", 0, len(entriesList))
}
+
+func TestGenerateProfileEvenIfDexpreoptIsDisabled(t *testing.T) {
+ preparers := android.GroupFixturePreparers(
+ PrepareForTestWithJavaDefaultModules,
+ PrepareForTestWithFakeApexMutator,
+ dexpreopt.FixtureDisableDexpreopt(true),
+ )
+
+ result := preparers.RunTestWithBp(t, `
+ java_library {
+ name: "foo",
+ installable: true,
+ dex_preopt: {
+ profile: "art-profile",
+ },
+ srcs: ["a.java"],
+ }`)
+
+ ctx := result.TestContext
+ dexpreopt := ctx.ModuleForTests("foo", "android_common").MaybeRule("dexpreopt")
+
+ expected := []string{"out/soong/.intermediates/foo/android_common/dexpreopt/profile.prof"}
+
+ android.AssertArrayString(t, "outputs", expected, dexpreopt.AllOutputs())
+}
diff --git a/java/fuzz.go b/java/fuzz.go
index 1d6b913..9a0c908 100644
--- a/java/fuzz.go
+++ b/java/fuzz.go
@@ -250,11 +250,11 @@
files = s.PackageArtifacts(ctx, module, javaFuzzModule.fuzzPackagedModule, archDir, builder)
// Add .jar
- files = append(files, fuzz.FileToZip{javaFuzzModule.implementationJarFile, ""})
+ files = append(files, fuzz.FileToZip{SourceFilePath: javaFuzzModule.implementationJarFile})
// Add jni .so files
for _, fPath := range javaFuzzModule.jniFilePaths {
- files = append(files, fuzz.FileToZip{fPath, ""})
+ files = append(files, fuzz.FileToZip{SourceFilePath: fPath})
}
archDirs[archOs], ok = s.BuildZipFile(ctx, module, javaFuzzModule.fuzzPackagedModule, files, builder, archDir, archString, hostOrTargetString, archOs, archDirs)
diff --git a/java/java.go b/java/java.go
index 16d9ee7..a98762c 100644
--- a/java/java.go
+++ b/java/java.go
@@ -2710,8 +2710,13 @@
var resources bazel.LabelList
var resourceStripPrefix *string
+ if m.properties.Java_resources != nil && len(m.properties.Java_resource_dirs) > 0 {
+ ctx.ModuleErrorf("bp2build doesn't support both java_resources and java_resource_dirs being set on the same module.")
+ }
+
if m.properties.Java_resources != nil {
resources.Append(android.BazelLabelForModuleSrc(ctx, m.properties.Java_resources))
+ resourceStripPrefix = proptools.StringPtr(ctx.ModuleDir())
}
//TODO(b/179889880) handle case where glob includes files outside package
@@ -2975,7 +2980,7 @@
func javaLibraryBazelTargetModuleProperties() bazel.BazelTargetModuleProperties {
return bazel.BazelTargetModuleProperties{
Rule_class: "java_library",
- Bzl_load_location: "//build/bazel/rules/java:rules.bzl",
+ Bzl_load_location: "//build/bazel/rules/java:library.bzl",
}
}
@@ -3084,7 +3089,7 @@
props := bazel.BazelTargetModuleProperties{
Rule_class: "java_binary",
- Bzl_load_location: "//build/bazel/rules/java:rules.bzl",
+ Bzl_load_location: "@rules_java//java:defs.bzl",
}
binAttrs := &javaBinaryHostAttributes{
Runtime_deps: runtimeDeps,
@@ -3140,7 +3145,7 @@
}
props := bazel.BazelTargetModuleProperties{
Rule_class: "java_import",
- Bzl_load_location: "//build/bazel/rules/java:rules.bzl",
+ Bzl_load_location: "//build/bazel/rules/java:import.bzl",
}
name := android.RemoveOptionalPrebuiltPrefix(i.Name())
diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go
index 0ea3609..d5779f7 100644
--- a/java/platform_bootclasspath.go
+++ b/java/platform_bootclasspath.go
@@ -103,7 +103,7 @@
func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorContext) {
b.hiddenAPIDepsMutator(ctx)
- if SkipDexpreoptBootJars(ctx) {
+ if !dexpreopt.IsDex2oatNeeded(ctx) {
return
}
@@ -187,11 +187,6 @@
bootDexJarByModule := b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments)
buildRuleForBootJarsPackageCheck(ctx, bootDexJarByModule)
- // Nothing to do if skipping the dexpreopt of boot image jars.
- if SkipDexpreoptBootJars(ctx) {
- return
- }
-
b.generateBootImageBuildActions(ctx, platformModules, apexModules)
}
@@ -429,6 +424,12 @@
// Build a profile for the image config and then use that to build the boot image.
profile := bootImageProfileRule(ctx, imageConfig)
+ // If dexpreopt of boot image jars should be skipped, generate only a profile.
+ global := dexpreopt.GetGlobalConfig(ctx)
+ if global.DisablePreoptBootImages {
+ return
+ }
+
// Build boot image files for the android variants.
androidBootImageFiles := buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile)
diff --git a/java/prebuilt_apis.go b/java/prebuilt_apis.go
index 206d995..044802e 100644
--- a/java/prebuilt_apis.go
+++ b/java/prebuilt_apis.go
@@ -104,20 +104,51 @@
return fmt.Sprintf("%s_%s_%s_%s", mctx.ModuleName(), scope, version, module)
}
+func hasBazelPrebuilt(module string) bool {
+ return module == "android" || module == "core-for-system-modules"
+}
+
+func bazelPrebuiltApiModuleName(module, scope, version string) string {
+ bazelModule := module
+ switch module {
+ case "android":
+ bazelModule = "android_jar"
+ case "core-for-system-modules":
+ bazelModule = "core_jar"
+ }
+ bazelVersion := version
+ if version == "current" {
+ bazelVersion = strconv.Itoa(android.FutureApiLevelInt)
+ }
+ bazelScope := scope
+ switch scope {
+ case "module-lib":
+ bazelScope = "module"
+ case "system-server":
+ bazelScope = "system_server"
+ }
+ return fmt.Sprintf("//prebuilts/sdk:%s_%s_%s", bazelScope, bazelVersion, bazelModule)
+}
+
func createImport(mctx android.LoadHookContext, module, scope, version, path, sdkVersion string, compileDex bool) {
props := struct {
- Name *string
- Jars []string
- Sdk_version *string
- Installable *bool
- Compile_dex *bool
- }{}
- props.Name = proptools.StringPtr(prebuiltApiModuleName(mctx, module, scope, version))
- props.Jars = append(props.Jars, path)
- props.Sdk_version = proptools.StringPtr(sdkVersion)
- props.Installable = proptools.BoolPtr(false)
- props.Compile_dex = proptools.BoolPtr(compileDex)
-
+ Name *string
+ Jars []string
+ Sdk_version *string
+ Installable *bool
+ Compile_dex *bool
+ Bazel_module android.BazelModuleProperties
+ }{
+ Name: proptools.StringPtr(prebuiltApiModuleName(mctx, module, scope, version)),
+ Jars: []string{path},
+ Sdk_version: proptools.StringPtr(sdkVersion),
+ Installable: proptools.BoolPtr(false),
+ Compile_dex: proptools.BoolPtr(compileDex),
+ }
+ if hasBazelPrebuilt(module) {
+ props.Bazel_module = android.BazelModuleProperties{
+ Label: proptools.StringPtr(bazelPrebuiltApiModuleName(module, scope, version))}
+ }
mctx.CreateModule(ImportFactory, &props)
}
@@ -135,6 +166,19 @@
mctx.CreateModule(genrule.GenRuleFactory, &genruleProps)
}
+func createLatestApiModuleExtensionVersionFile(mctx android.LoadHookContext, name string, version string) {
+ genruleProps := struct {
+ Name *string
+ Srcs []string
+ Out []string
+ Cmd *string
+ }{}
+ genruleProps.Name = proptools.StringPtr(name)
+ genruleProps.Out = []string{name}
+ genruleProps.Cmd = proptools.StringPtr("echo " + version + " > $(out)")
+ mctx.CreateModule(genrule.GenRuleFactory, &genruleProps)
+}
+
func createEmptyFile(mctx android.LoadHookContext, name string) {
props := struct {
Name *string
@@ -233,9 +277,10 @@
type latestApiInfo struct {
module, scope, path string
version int
+ isExtensionApiFile bool
}
- getLatest := func(files []string) map[string]latestApiInfo {
+ getLatest := func(files []string, isExtensionApiFile bool) map[string]latestApiInfo {
m := make(map[string]latestApiInfo)
for _, f := range files {
module, version, scope := parseFinalizedPrebuiltPath(mctx, f)
@@ -245,16 +290,16 @@
key := module + "." + scope
info, exists := m[key]
if !exists || version > info.version {
- m[key] = latestApiInfo{module, scope, f, version}
+ m[key] = latestApiInfo{module, scope, f, version, isExtensionApiFile}
}
}
return m
}
- latest := getLatest(apiLevelFiles)
+ latest := getLatest(apiLevelFiles, false)
if p.properties.Extensions_dir != nil {
extensionApiFiles := globExtensionDirs(mctx, p, "api/*.txt")
- for k, v := range getLatest(extensionApiFiles) {
+ for k, v := range getLatest(extensionApiFiles, true) {
if _, exists := latest[k]; !exists {
mctx.ModuleErrorf("Module %v finalized for extension %d but never during an API level; likely error", v.module, v.version)
}
@@ -267,6 +312,12 @@
for _, k := range android.SortedKeys(latest) {
info := latest[k]
name := PrebuiltApiModuleName(info.module, info.scope, "latest")
+ latestExtensionVersionModuleName := PrebuiltApiModuleName(info.module, info.scope, "latest.extension_version")
+ if info.isExtensionApiFile {
+ createLatestApiModuleExtensionVersionFile(mctx, latestExtensionVersionModuleName, strconv.Itoa(info.version))
+ } else {
+ createLatestApiModuleExtensionVersionFile(mctx, latestExtensionVersionModuleName, "-1")
+ }
createApiModule(mctx, name, info.path)
}
diff --git a/python/python.go b/python/python.go
index 1a12973..8fde638 100644
--- a/python/python.go
+++ b/python/python.go
@@ -265,7 +265,6 @@
}
if proptools.BoolDefault(props.Version.Py2.Enabled, false) {
if !mctx.DeviceConfig().BuildBrokenUsesSoongPython2Modules() &&
- mctx.ModuleName() != "par_test" &&
mctx.ModuleName() != "py2-cmd" &&
mctx.ModuleName() != "py2-stdlib" {
mctx.PropertyErrorf("version.py2.enabled", "Python 2 is no longer supported, please convert to python 3. This error can be temporarily overridden by setting BUILD_BROKEN_USES_SOONG_PYTHON2_MODULES := true in the product configuration")
diff --git a/python/tests/Android.bp b/python/tests/Android.bp
index a656859..e5569ba 100644
--- a/python/tests/Android.bp
+++ b/python/tests/Android.bp
@@ -28,29 +28,6 @@
unit_test: false,
},
version: {
- py2: {
- enabled: true,
- embedded_launcher: true,
- },
- py3: {
- enabled: false,
- embedded_launcher: true,
- },
- },
-}
-
-python_test_host {
- name: "par_test3",
- main: "par_test.py",
- srcs: [
- "par_test.py",
- "testpkg/par_test.py",
- ],
- // Is not implemented as a python unittest
- test_options: {
- unit_test: false,
- },
- version: {
py3: {
embedded_launcher: true,
},
diff --git a/python/tests/py-cmd_test.py b/python/tests/py-cmd_test.py
index acda2d7..c7ba0ab 100644
--- a/python/tests/py-cmd_test.py
+++ b/python/tests/py-cmd_test.py
@@ -57,7 +57,7 @@
if sys.version_info[0] == 2:
assert_equal("len(sys.path)", len(sys.path), 4)
- assert_equal("sys.path[0]", sys.path[0], os.path.dirname(__file__))
+ assert_equal("sys.path[0]", sys.path[0], os.path.abspath(os.path.dirname(__file__)))
assert_equal("sys.path[1]", sys.path[1], "/extra")
assert_equal("sys.path[2]", sys.path[2], os.path.join(sys.executable, "internal"))
assert_equal("sys.path[3]", sys.path[3], os.path.join(sys.executable, "internal", "stdlib"))
diff --git a/python/tests/runtest.sh b/python/tests/runtest.sh
index 35941dc..f4abae5 100755
--- a/python/tests/runtest.sh
+++ b/python/tests/runtest.sh
@@ -24,10 +24,9 @@
fi
if [[ ( ! -f $ANDROID_HOST_OUT/nativetest64/par_test/par_test ) ||
- ( ! -f $ANDROID_HOST_OUT/nativetest64/par_test3/par_test3 ) ||
( ! -f $ANDROID_HOST_OUT/bin/py2-cmd ) ||
( ! -f $ANDROID_HOST_OUT/bin/py3-cmd )]]; then
- echo "Run 'm par_test par_test3 py2-cmd py3-cmd' first"
+ echo "Run 'm par_test py2-cmd py3-cmd' first"
exit 1
fi
@@ -41,12 +40,6 @@
ARGTEST=true $ANDROID_HOST_OUT/nativetest64/par_test/par_test --arg1 arg2
-PYTHONHOME= PYTHONPATH= $ANDROID_HOST_OUT/nativetest64/par_test3/par_test3
-PYTHONHOME=/usr $ANDROID_HOST_OUT/nativetest64/par_test3/par_test3
-PYTHONPATH=/usr $ANDROID_HOST_OUT/nativetest64/par_test3/par_test3
-
-ARGTEST=true $ANDROID_HOST_OUT/nativetest64/par_test3/par_test3 --arg1 arg2
-
cd $(dirname ${BASH_SOURCE[0]})
PYTHONPATH=/extra $ANDROID_HOST_OUT/bin/py2-cmd py-cmd_test.py
diff --git a/python/tests/testpkg/par_test.py b/python/tests/testpkg/par_test.py
index b513409..e12c527 100644
--- a/python/tests/testpkg/par_test.py
+++ b/python/tests/testpkg/par_test.py
@@ -33,11 +33,7 @@
fileName = fileName[:-1]
assert_equal("__file__", fileName, os.path.join(archive, "testpkg/par_test.py"))
-# Python3 is returning None here for me, and I haven't found any problems caused by this.
-if sys.version_info[0] == 2:
- assert_equal("__package__", __package__, "testpkg")
-else:
- assert_equal("__package__", __package__, None)
+assert_equal("__package__", __package__, "testpkg")
assert_equal("__loader__.archive", __loader__.archive, archive)
assert_equal("__loader__.prefix", __loader__.prefix, "testpkg/")
diff --git a/rust/config/global.go b/rust/config/global.go
index 2d1f0c1..748bb3d 100644
--- a/rust/config/global.go
+++ b/rust/config/global.go
@@ -24,7 +24,7 @@
var pctx = android.NewPackageContext("android/soong/rust/config")
var (
- RustDefaultVersion = "1.68.0"
+ RustDefaultVersion = "1.69.0"
RustDefaultBase = "prebuilts/rust/"
DefaultEdition = "2021"
Stdlibs = []string{
diff --git a/rust/fuzz.go b/rust/fuzz.go
index d7e7ddf..c2b9405 100644
--- a/rust/fuzz.go
+++ b/rust/fuzz.go
@@ -31,7 +31,7 @@
*binaryDecorator
fuzzPackagedModule fuzz.FuzzPackagedModule
- sharedLibraries android.Paths
+ sharedLibraries android.RuleBuilderInstalls
installedSharedDeps []string
}
@@ -119,15 +119,17 @@
// Grab the list of required shared libraries.
fuzz.sharedLibraries, _ = cc.CollectAllSharedDependencies(ctx)
- for _, lib := range fuzz.sharedLibraries {
+ for _, ruleBuilderInstall := range fuzz.sharedLibraries {
+ install := ruleBuilderInstall.To
+
fuzz.installedSharedDeps = append(fuzz.installedSharedDeps,
cc.SharedLibraryInstallLocation(
- lib, ctx.Host(), installBase, ctx.Arch().ArchType.String()))
+ install, ctx.Host(), installBase, ctx.Arch().ArchType.String()))
// Also add the dependency on the shared library symbols dir.
if !ctx.Host() {
fuzz.installedSharedDeps = append(fuzz.installedSharedDeps,
- cc.SharedLibrarySymbolsInstallLocation(lib, installBase, ctx.Arch().ArchType.String()))
+ cc.SharedLibrarySymbolsInstallLocation(install, installBase, ctx.Arch().ArchType.String()))
}
}
}
diff --git a/rust/rust.go b/rust/rust.go
index 7b520cd..dc53cc0 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -649,7 +649,7 @@
panic(fmt.Errorf("FuzzPackagedModule called on non-fuzz module: %q", mod.BaseModuleName()))
}
-func (mod *Module) FuzzSharedLibraries() android.Paths {
+func (mod *Module) FuzzSharedLibraries() android.RuleBuilderInstalls {
if fuzzer, ok := mod.compiler.(*fuzzDecorator); ok {
return fuzzer.sharedLibraries
}
diff --git a/scripts/rbc-run b/scripts/rbc-run
deleted file mode 100755
index 8d93f0e..0000000
--- a/scripts/rbc-run
+++ /dev/null
@@ -1,18 +0,0 @@
-#! /bin/bash
-# Convert and run one configuration
-# Args: a product/board makefile optionally followed by additional arguments
-# that will be passed to rbcrun.
-[[ $# -gt 1 && -f "$1" && -f "$2" ]] || { echo "Usage: ${0##*/} product.mk input_variables.mk [Additional rbcrun arguments]" >&2; exit 1; }
-set -eu
-
-declare -r output_root="${OUT_DIR:-out}"
-declare -r runner="${output_root}/rbcrun"
-declare -r converter="${output_root}/mk2rbc"
-declare -r launcher="${output_root}/rbc/launcher.rbc"
-declare -r makefile_list="${output_root}/.module_paths/configuration.list"
-declare -r makefile="$1"
-declare -r input_variables="$2"
-shift 2
-"${converter}" -mode=write -r --outdir "${output_root}/rbc" --input_variables "${input_variables}" --launcher="${launcher}" --makefile_list="${makefile_list}" "${makefile}"
-"${runner}" RBC_OUT="make,global" RBC_DEBUG="${RBC_DEBUG:-}" $@ "${launcher}"
-
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index 3a2ecc0..6159ea9 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -19,12 +19,14 @@
"testing"
"android/soong/android"
+ "android/soong/dexpreopt"
"android/soong/java"
)
var prepareForSdkTestWithJava = android.GroupFixturePreparers(
java.PrepareForTestWithJavaBuildComponents,
PrepareForTestWithSdkBuildComponents,
+ dexpreopt.PrepareForTestWithFakeDex2oatd,
// Ensure that all source paths are provided. This helps ensure that the snapshot generation is
// consistent and all files referenced from the snapshot's Android.bp file have actually been
diff --git a/ui/build/Android.bp b/ui/build/Android.bp
index b79754c..959ae4c 100644
--- a/ui/build/Android.bp
+++ b/ui/build/Android.bp
@@ -46,6 +46,7 @@
"soong-ui-tracer",
],
srcs: [
+ "bazel_metrics.go",
"build.go",
"cleanbuild.go",
"config.go",
diff --git a/ui/build/bazel_metrics.go b/ui/build/bazel_metrics.go
new file mode 100644
index 0000000..c0690c1
--- /dev/null
+++ b/ui/build/bazel_metrics.go
@@ -0,0 +1,135 @@
+// Copyright 2023 Google Inc. All rights reserved.
+//
+// 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 build
+
+// This file contains functionality to parse bazel profile data into
+// a bazel_metrics proto, defined in build/soong/ui/metrics/bazel_metrics_proto
+// These metrics are later uploaded in upload.go
+
+import (
+ "bufio"
+ "os"
+ "strconv"
+ "strings"
+
+ "android/soong/shared"
+ "google.golang.org/protobuf/proto"
+
+ bazel_metrics_proto "android/soong/ui/metrics/bazel_metrics_proto"
+)
+
+func parseTimingToNanos(str string) int64 {
+ millisString := removeDecimalPoint(str)
+ timingMillis, _ := strconv.ParseInt(millisString, 10, 64)
+ return timingMillis * 1000000
+}
+
+func parsePercentageToTenThousandths(str string) int32 {
+ percentageString := removeDecimalPoint(str)
+ //remove the % at the end of the string
+ percentage := strings.ReplaceAll(percentageString, "%", "")
+ percentagePortion, _ := strconv.ParseInt(percentage, 10, 32)
+ return int32(percentagePortion)
+}
+
+func removeDecimalPoint(numString string) string {
+ // The format is always 0.425 or 10.425
+ return strings.ReplaceAll(numString, ".", "")
+}
+
+func parseTotal(line string) int64 {
+ words := strings.Fields(line)
+ timing := words[3]
+ return parseTimingToNanos(timing)
+}
+
+func parsePhaseTiming(line string) bazel_metrics_proto.PhaseTiming {
+ words := strings.Fields(line)
+ getPhaseNameAndTimingAndPercentage := func([]string) (string, int64, int32) {
+ // Sample lines include:
+ // Total launch phase time 0.011 s 2.59%
+ // Total target pattern evaluation phase time 0.011 s 2.59%
+ var beginning int
+ var end int
+ for ind, word := range words {
+ if word == "Total" {
+ beginning = ind + 1
+ } else if beginning > 0 && word == "phase" {
+ end = ind
+ break
+ }
+ }
+ phaseName := strings.Join(words[beginning:end], " ")
+
+ // end is now "phase" - advance by 2 for timing and 4 for percentage
+ percentageString := words[end+4]
+ timingString := words[end+2]
+ timing := parseTimingToNanos(timingString)
+ percentagePortion := parsePercentageToTenThousandths(percentageString)
+ return phaseName, timing, percentagePortion
+ }
+
+ phaseName, timing, portion := getPhaseNameAndTimingAndPercentage(words)
+ phaseTiming := bazel_metrics_proto.PhaseTiming{}
+ phaseTiming.DurationNanos = &timing
+ phaseTiming.PortionOfBuildTime = &portion
+
+ phaseTiming.PhaseName = &phaseName
+ return phaseTiming
+}
+
+// This method takes a file created by bazel's --analyze-profile mode and
+// writes bazel metrics data to the provided filepath.
+func ProcessBazelMetrics(bazelProfileFile string, bazelMetricsFile string, ctx Context, config Config) {
+ if bazelProfileFile == "" {
+ return
+ }
+
+ readBazelProto := func(filepath string) bazel_metrics_proto.BazelMetrics {
+ //serialize the proto, write it
+ bazelMetrics := bazel_metrics_proto.BazelMetrics{}
+
+ file, err := os.ReadFile(filepath)
+ if err != nil {
+ ctx.Fatalln("Error reading metrics file\n", err)
+ }
+
+ scanner := bufio.NewScanner(strings.NewReader(string(file)))
+ scanner.Split(bufio.ScanLines)
+
+ var phaseTimings []*bazel_metrics_proto.PhaseTiming
+ for scanner.Scan() {
+ line := scanner.Text()
+ if strings.HasPrefix(line, "Total run time") {
+ total := parseTotal(line)
+ bazelMetrics.Total = &total
+ } else if strings.HasPrefix(line, "Total") {
+ phaseTiming := parsePhaseTiming(line)
+ phaseTimings = append(phaseTimings, &phaseTiming)
+ }
+ }
+ bazelMetrics.PhaseTimings = phaseTimings
+
+ return bazelMetrics
+ }
+
+ if _, err := os.Stat(bazelProfileFile); err != nil {
+ // We can assume bazel didn't run if the profile doesn't exist
+ return
+ }
+ bazelProto := readBazelProto(bazelProfileFile)
+ bazelProto.ExitCode = proto.Int32(config.bazelExitCode)
+ shared.Save(&bazelProto, bazelMetricsFile)
+}
diff --git a/ui/build/config.go b/ui/build/config.go
index 2dda52a..8ec9680 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -89,7 +89,8 @@
skipMetricsUpload bool
buildStartedTime int64 // For metrics-upload-only - manually specify a build-started time
buildFromTextStub bool
- ensureAllowlistIntegrity bool // For CI builds - make sure modules are mixed-built
+ ensureAllowlistIntegrity bool // For CI builds - make sure modules are mixed-built
+ bazelExitCode int32 // For b-runs - necessary for updating NonZeroExit
// From the product config
katiArgs []string
@@ -298,11 +299,12 @@
return true
}
-func UploadOnlyConfig(ctx Context, _ ...string) Config {
+func UploadOnlyConfig(ctx Context, args ...string) Config {
ret := &configImpl{
environ: OsEnvironment(),
sandboxConfig: &SandboxConfig{},
}
+ ret.parseArgs(ctx, args)
srcDir := absPath(ctx, ".")
bc := os.Getenv("ANDROID_BUILD_ENVIRONMENT_CONFIG")
if err := loadEnvConfig(ctx, ret, bc); err != nil {
@@ -883,6 +885,14 @@
}
} else if arg == "--ensure-allowlist-integrity" {
c.ensureAllowlistIntegrity = true
+ } else if strings.HasPrefix(arg, "--bazel-exit-code=") {
+ bazelExitCodeStr := strings.TrimPrefix(arg, "--bazel-exit-code=")
+ val, err := strconv.Atoi(bazelExitCodeStr)
+ if err == nil {
+ c.bazelExitCode = int32(val)
+ } else {
+ ctx.Fatalf("Error parsing bazel-exit-code", err)
+ }
} else if len(arg) > 0 && arg[0] == '-' {
parseArgNum := func(def int) int {
if len(arg) > 2 {
@@ -1723,6 +1733,10 @@
return time.UnixMilli(c.buildStartedTime)
}
+func (c *configImpl) BazelExitCode() int32 {
+ return c.bazelExitCode
+}
+
func GetMetricsUploader(topDir string, env *Environment) string {
if p, ok := env.Get("METRICS_UPLOADER"); ok {
metricsUploader := filepath.Join(topDir, p)
diff --git a/ui/build/dumpvars.go b/ui/build/dumpvars.go
index efe7478..b83b5cb 100644
--- a/ui/build/dumpvars.go
+++ b/ui/build/dumpvars.go
@@ -150,6 +150,7 @@
"PRODUCT_INCLUDE_TAGS",
"PRODUCT_SOURCE_ROOT_DIRS",
"TARGET_PRODUCT",
+ "TARGET_RELEASE",
"TARGET_BUILD_VARIANT",
"TARGET_BUILD_APPS",
"TARGET_BUILD_UNBUNDLED",
diff --git a/ui/build/finder.go b/ui/build/finder.go
index 3f628cf..62079fe 100644
--- a/ui/build/finder.go
+++ b/ui/build/finder.go
@@ -87,6 +87,8 @@
"TEST_MAPPING",
// Bazel top-level file to mark a directory as a Bazel workspace.
"WORKSPACE",
+ // METADATA file of packages
+ "METADATA",
},
// Bazel Starlark configuration files and all .mk files for product/board configuration.
IncludeSuffixes: []string{".bzl", ".mk"},
@@ -189,6 +191,13 @@
ctx.Fatalf("Could not find OWNERS: %v", err)
}
+ // Recursively look for all METADATA files.
+ metadataFiles := f.FindNamedAt(".", "METADATA")
+ err = dumpListToFile(ctx, config, metadataFiles, filepath.Join(dumpDir, "METADATA.list"))
+ if err != nil {
+ ctx.Fatalf("Could not find METADATA: %v", err)
+ }
+
// Recursively look for all TEST_MAPPING files.
testMappings := f.FindNamedAt(".", "TEST_MAPPING")
err = dumpListToFile(ctx, config, testMappings, filepath.Join(dumpDir, "TEST_MAPPING.list"))
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 563199b..18bf3b9 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -400,6 +400,8 @@
pbi.Inputs = append(pbi.Inputs,
config.Bp2BuildFilesMarkerFile(),
filepath.Join(config.FileListDir(), "bazel.list"))
+ case bp2buildFilesTag:
+ pbi.Inputs = append(pbi.Inputs, filepath.Join(config.FileListDir(), "METADATA.list"))
}
invocations = append(invocations, pbi)
}
diff --git a/ui/build/upload.go b/ui/build/upload.go
index 1e6d94a..9f14bdd 100644
--- a/ui/build/upload.go
+++ b/ui/build/upload.go
@@ -18,21 +18,16 @@
// another.
import (
- "bufio"
"fmt"
"io/ioutil"
"os"
"path/filepath"
- "strconv"
- "strings"
"time"
- "android/soong/shared"
"android/soong/ui/metrics"
"google.golang.org/protobuf/proto"
- bazel_metrics_proto "android/soong/ui/metrics/bazel_metrics_proto"
upload_proto "android/soong/ui/metrics/upload_proto"
)
@@ -78,122 +73,16 @@
return metricsFiles
}
-func parseTimingToNanos(str string) int64 {
- millisString := removeDecimalPoint(str)
- timingMillis, _ := strconv.ParseInt(millisString, 10, 64)
- return timingMillis * 1000000
-}
-
-func parsePercentageToTenThousandths(str string) int32 {
- percentageString := removeDecimalPoint(str)
- //remove the % at the end of the string
- percentage := strings.ReplaceAll(percentageString, "%", "")
- percentagePortion, _ := strconv.ParseInt(percentage, 10, 32)
- return int32(percentagePortion)
-}
-
-func removeDecimalPoint(numString string) string {
- // The format is always 0.425 or 10.425
- return strings.ReplaceAll(numString, ".", "")
-}
-
-func parseTotal(line string) int64 {
- words := strings.Fields(line)
- timing := words[3]
- return parseTimingToNanos(timing)
-}
-
-func parsePhaseTiming(line string) bazel_metrics_proto.PhaseTiming {
- words := strings.Fields(line)
- getPhaseNameAndTimingAndPercentage := func([]string) (string, int64, int32) {
- // Sample lines include:
- // Total launch phase time 0.011 s 2.59%
- // Total target pattern evaluation phase time 0.011 s 2.59%
- var beginning int
- var end int
- for ind, word := range words {
- if word == "Total" {
- beginning = ind + 1
- } else if beginning > 0 && word == "phase" {
- end = ind
- break
- }
- }
- phaseName := strings.Join(words[beginning:end], " ")
-
- // end is now "phase" - advance by 2 for timing and 4 for percentage
- percentageString := words[end+4]
- timingString := words[end+2]
- timing := parseTimingToNanos(timingString)
- percentagePortion := parsePercentageToTenThousandths(percentageString)
- return phaseName, timing, percentagePortion
- }
-
- phaseName, timing, portion := getPhaseNameAndTimingAndPercentage(words)
- phaseTiming := bazel_metrics_proto.PhaseTiming{}
- phaseTiming.DurationNanos = &timing
- phaseTiming.PortionOfBuildTime = &portion
-
- phaseTiming.PhaseName = &phaseName
- return phaseTiming
-}
-
-// This method takes a file created by bazel's --analyze-profile mode and
-// writes bazel metrics data to the provided filepath.
-// TODO(b/279987768) - move this outside of upload.go
-func processBazelMetrics(bazelProfileFile string, bazelMetricsFile string, ctx Context) {
- if bazelProfileFile == "" {
- return
- }
-
- readBazelProto := func(filepath string) bazel_metrics_proto.BazelMetrics {
- //serialize the proto, write it
- bazelMetrics := bazel_metrics_proto.BazelMetrics{}
-
- file, err := os.ReadFile(filepath)
- if err != nil {
- ctx.Fatalln("Error reading metrics file\n", err)
- }
-
- scanner := bufio.NewScanner(strings.NewReader(string(file)))
- scanner.Split(bufio.ScanLines)
-
- var phaseTimings []*bazel_metrics_proto.PhaseTiming
- for scanner.Scan() {
- line := scanner.Text()
- if strings.HasPrefix(line, "Total run time") {
- total := parseTotal(line)
- bazelMetrics.Total = &total
- } else if strings.HasPrefix(line, "Total") {
- phaseTiming := parsePhaseTiming(line)
- phaseTimings = append(phaseTimings, &phaseTiming)
- }
- }
- bazelMetrics.PhaseTimings = phaseTimings
-
- return bazelMetrics
- }
-
- if _, err := os.Stat(bazelProfileFile); err != nil {
- // We can assume bazel didn't run if the profile doesn't exist
- return
- }
- bazelProto := readBazelProto(bazelProfileFile)
- shared.Save(&bazelProto, bazelMetricsFile)
-}
-
// UploadMetrics uploads a set of metrics files to a server for analysis.
// The metrics files are first copied to a temporary directory
// and the uploader is then executed in the background to allow the user/system
// to continue working. Soong communicates to the uploader through the
// upload_proto raw protobuf file.
-func UploadMetrics(ctx Context, config Config, simpleOutput bool, buildStarted time.Time, bazelProfileFile string, bazelMetricsFile string, paths ...string) {
+func UploadMetrics(ctx Context, config Config, simpleOutput bool, buildStarted time.Time, paths ...string) {
ctx.BeginTrace(metrics.RunSetupTool, "upload_metrics")
defer ctx.EndTrace()
uploader := config.MetricsUploaderApp()
- processBazelMetrics(bazelProfileFile, bazelMetricsFile, ctx)
-
if uploader == "" {
// If the uploader path was not specified, no metrics shall be uploaded.
return
diff --git a/ui/build/upload_test.go b/ui/build/upload_test.go
index 58d9237..1fcded9 100644
--- a/ui/build/upload_test.go
+++ b/ui/build/upload_test.go
@@ -166,7 +166,7 @@
metricsUploader: tt.uploader,
}}
- UploadMetrics(ctx, config, false, time.Now(), "out/bazel_metrics.txt", "out/bazel_metrics.pb", metricsFiles...)
+ UploadMetrics(ctx, config, false, time.Now(), metricsFiles...)
})
}
}
@@ -221,7 +221,7 @@
metricsUploader: "echo",
}}
- UploadMetrics(ctx, config, true, time.Now(), "", "", metricsFile)
+ UploadMetrics(ctx, config, true, time.Now(), metricsFile)
t.Errorf("got nil, expecting %q as a failure", tt.expectedErr)
})
}
diff --git a/ui/metrics/metrics.go b/ui/metrics/metrics.go
index 82d11ed..a282e20 100644
--- a/ui/metrics/metrics.go
+++ b/ui/metrics/metrics.go
@@ -228,7 +228,7 @@
m.metrics.BuildDateTimestamp = proto.Int64(buildTimestamp.UnixNano() / int64(time.Second))
}
-func (m *Metrics) UpdateTotalRealTime(data []byte) error {
+func (m *Metrics) UpdateTotalRealTimeAndNonZeroExit(data []byte, bazelExitCode int32) error {
if err := proto.Unmarshal(data, &m.metrics); err != nil {
return fmt.Errorf("Failed to unmarshal proto", err)
}
@@ -236,6 +236,9 @@
endTime := uint64(time.Now().UnixNano())
*m.metrics.Total.RealTime = *proto.Uint64(endTime - startTime)
+
+ bazelError := bazelExitCode != 0
+ m.metrics.NonZeroExit = proto.Bool(bazelError)
return nil
}
diff --git a/zip/cmd/main.go b/zip/cmd/main.go
index def76aa..a2ccc20 100644
--- a/zip/cmd/main.go
+++ b/zip/cmd/main.go
@@ -78,6 +78,15 @@
return nil
}
+type explicitFile struct{}
+
+func (explicitFile) String() string { return `""` }
+
+func (explicitFile) Set(s string) error {
+ fileArgsBuilder.ExplicitPathInZip(s)
+ return nil
+}
+
type dir struct{}
func (dir) String() string { return `""` }
@@ -173,6 +182,7 @@
flags.Var(&nonDeflatedFiles, "s", "file path to be stored within the zip without compression")
flags.Var(&relativeRoot{}, "C", "path to use as relative root of files in following -f, -l, or -D arguments")
flags.Var(&junkPaths{}, "j", "junk paths, zip files without directory names")
+ flags.Var(&explicitFile{}, "e", "filename to use in the zip file for the next -f argument")
flags.Parse(expandedArgs[1:])
diff --git a/zip/zip.go b/zip/zip.go
index 6f1a8ad..5e1a104 100644
--- a/zip/zip.go
+++ b/zip/zip.go
@@ -80,6 +80,7 @@
type FileArg struct {
PathPrefixInZip, SourcePrefixToStrip string
+ ExplicitPathInZip string
SourceFiles []string
JunkPaths bool
GlobDir string
@@ -124,6 +125,10 @@
arg := b.state
arg.SourceFiles = []string{name}
b.fileArgs = append(b.fileArgs, arg)
+
+ if b.state.ExplicitPathInZip != "" {
+ b.state.ExplicitPathInZip = ""
+ }
return b
}
@@ -189,6 +194,12 @@
return b
}
+// ExplicitPathInZip sets the path in the zip file for the next File call.
+func (b *FileArgsBuilder) ExplicitPathInZip(s string) *FileArgsBuilder {
+ b.state.ExplicitPathInZip = s
+ return b
+}
+
func (b *FileArgsBuilder) Error() error {
if b == nil {
return nil
@@ -425,7 +436,9 @@
var dest string
- if fa.JunkPaths {
+ if fa.ExplicitPathInZip != "" {
+ dest = fa.ExplicitPathInZip
+ } else if fa.JunkPaths {
dest = filepath.Base(src)
} else {
var err error
diff --git a/zip/zip_test.go b/zip/zip_test.go
index e7fdea8..c64c3f4 100644
--- a/zip/zip_test.go
+++ b/zip/zip_test.go
@@ -454,6 +454,60 @@
fhWithSHA256("c", fileC, zip.Deflate, sha256FileC),
},
},
+ {
+ name: "explicit path",
+ args: fileArgsBuilder().
+ ExplicitPathInZip("foo").
+ File("a/a/a").
+ File("a/a/b"),
+ compressionLevel: 9,
+
+ files: []zip.FileHeader{
+ fh("foo", fileA, zip.Deflate),
+ fh("a/a/b", fileB, zip.Deflate),
+ },
+ },
+ {
+ name: "explicit path with prefix",
+ args: fileArgsBuilder().
+ PathPrefixInZip("prefix").
+ ExplicitPathInZip("foo").
+ File("a/a/a").
+ File("a/a/b"),
+ compressionLevel: 9,
+
+ files: []zip.FileHeader{
+ fh("prefix/foo", fileA, zip.Deflate),
+ fh("prefix/a/a/b", fileB, zip.Deflate),
+ },
+ },
+ {
+ name: "explicit path with glob",
+ args: fileArgsBuilder().
+ ExplicitPathInZip("foo").
+ File("a/a/a*").
+ File("a/a/b"),
+ compressionLevel: 9,
+
+ files: []zip.FileHeader{
+ fh("foo", fileA, zip.Deflate),
+ fh("a/a/b", fileB, zip.Deflate),
+ },
+ },
+ {
+ name: "explicit path with junk paths",
+ args: fileArgsBuilder().
+ JunkPaths(true).
+ ExplicitPathInZip("foo/bar").
+ File("a/a/a*").
+ File("a/a/b"),
+ compressionLevel: 9,
+
+ files: []zip.FileHeader{
+ fh("foo/bar", fileA, zip.Deflate),
+ fh("b", fileB, zip.Deflate),
+ },
+ },
// errors
{
@@ -490,6 +544,22 @@
File("d/a/a"),
err: ConflictingFileError{},
},
+ {
+ name: "error explicit path conflicting",
+ args: fileArgsBuilder().
+ ExplicitPathInZip("foo").
+ File("a/a/a").
+ ExplicitPathInZip("foo").
+ File("a/a/b"),
+ err: ConflictingFileError{},
+ },
+ {
+ name: "error explicit path conflicting glob",
+ args: fileArgsBuilder().
+ ExplicitPathInZip("foo").
+ File("a/a/*"),
+ err: ConflictingFileError{},
+ },
}
for _, test := range testCases {