Merge "Revert^3 "Upgrade to clang-r522817"" into main
diff --git a/android/all_teams.go b/android/all_teams.go
index 0c433a6..d4bf7d0 100644
--- a/android/all_teams.go
+++ b/android/all_teams.go
@@ -79,11 +79,6 @@
ctx.VisitAllModules(func(module Module) {
bpFile := ctx.BlueprintFile(module)
- testModInfo := TestModuleInformation{}
- if tmi, ok := SingletonModuleProvider(ctx, module, TestOnlyProviderKey); ok {
- testModInfo = tmi
- }
-
// Package Modules and Team Modules are stored in a map so we can look them up by name for
// modules without a team.
if pack, ok := module.(*packageModule); ok {
@@ -97,6 +92,23 @@
return
}
+ testModInfo := TestModuleInformation{}
+ if tmi, ok := SingletonModuleProvider(ctx, module, TestOnlyProviderKey); ok {
+ testModInfo = tmi
+ }
+
+ // Some modules, like java_test_host don't set the provider when the module isn't enabled:
+ // test_only, top_level
+ // AVFHostTestCases{os:linux_glibc,arch:common} {true true}
+ // AVFHostTestCases{os:windows,arch:common} {false false}
+ // Generally variant information of true override false or unset.
+ if testModInfo.TestOnly == false {
+ if prevValue, exists := t.teams_for_mods[module.Name()]; exists {
+ if prevValue.testOnly == true {
+ return
+ }
+ }
+ }
entry := moduleTeamAndTestInfo{
bpFile: bpFile,
testOnly: testModInfo.TestOnly,
diff --git a/android/all_teams_test.go b/android/all_teams_test.go
index 9c2b38e..96ed92f 100644
--- a/android/all_teams_test.go
+++ b/android/all_teams_test.go
@@ -25,6 +25,8 @@
t.Parallel()
ctx := GroupFixturePreparers(
prepareForTestWithTeamAndFakes,
+ // This adds two variants, one armv7-a-neon, one armv8-a
+ PrepareForTestWithArchMutator,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterParallelSingletonType("all_teams", AllTeamsFactory)
}),
@@ -52,10 +54,35 @@
name: "noteam",
test_only: true,
}
+ // write the test-only provider value once
fake {
- name: "test-and-team-and-top",
+ name: "test-and-team-and-top1",
test_only: true,
team: "team2",
+ arch: {arm: { skip: false},
+ arm64: { skip: true}},
+ }
+ // write the test-only provider once, but on the other arch
+ fake {
+ name: "test-and-team-and-top2",
+ test_only: true,
+ team: "team2",
+ arch: {arm: { skip: true},
+ arm64: { skip: false}},
+ }
+ // write the test-only provider value twice
+ fake {
+ name: "test-and-team-and-top3",
+ test_only: true,
+ team: "team2",
+ }
+ // Don't write the test-only provider value
+ fake {
+ name: "test-and-team-and-top4",
+ test_only: true,
+ team: "team2",
+ arch: {arm: { skip: true},
+ arm64: { skip: true}},
}
`)
@@ -63,12 +90,16 @@
teams = getTeamProtoOutput(t, ctx)
// map of module name -> trendy team name.
- actualTeams := make(map[string]*string)
+ actualTeams := make(map[string]string)
actualTests := []string{}
actualTopLevelTests := []string{}
for _, teamProto := range teams.Teams {
- actualTeams[teamProto.GetTargetName()] = teamProto.TrendyTeamId
+ if teamProto.TrendyTeamId != nil {
+ actualTeams[teamProto.GetTargetName()] = *teamProto.TrendyTeamId
+ } else {
+ actualTeams[teamProto.GetTargetName()] = ""
+ }
if teamProto.GetTestOnly() {
actualTests = append(actualTests, teamProto.GetTargetName())
}
@@ -76,16 +107,23 @@
actualTopLevelTests = append(actualTopLevelTests, teamProto.GetTargetName())
}
}
- expectedTeams := map[string]*string{
- "main_test": proto.String("cool_team"),
- "tool": proto.String("22222"),
- "test-and-team-and-top": proto.String("22222"),
- "noteam": nil,
+ expectedTeams := map[string]string{
+ "main_test": "cool_team",
+ "tool": "22222",
+ "test-and-team-and-top1": "22222",
+ "test-and-team-and-top2": "22222",
+ "test-and-team-and-top3": "22222",
+ "test-and-team-and-top4": "22222",
+ "noteam": "",
}
expectedTests := []string{
"noteam",
- "test-and-team-and-top",
+ "test-and-team-and-top1",
+ "test-and-team-and-top2",
+ "test-and-team-and-top3",
+ // There should be no test-and-team-top4 as we skip writing all variants
+ // test-only for all variants
}
AssertDeepEquals(t, "compare maps", expectedTeams, actualTeams)
AssertDeepEquals(t, "test matchup", expectedTests, actualTests)
@@ -230,12 +268,16 @@
ModuleBase
sourceProperties SourceProperties
+ props struct {
+ // If true, don't write test-only value in provider
+ Skip bool `android:"arch_variant"`
+ }
}
func fakeFactory() Module {
module := &fakeForTests{}
- module.AddProperties(&module.sourceProperties)
- InitAndroidModule(module)
+ module.AddProperties(&module.sourceProperties, &module.props)
+ InitAndroidArchModule(module, HostAndDeviceSupported, MultilibBoth)
return module
}
@@ -250,7 +292,7 @@
func (f *fakeForTests) GenerateAndroidBuildActions(ctx ModuleContext) {
if Bool(f.sourceProperties.Test_only) {
SetProvider(ctx, TestOnlyProviderKey, TestModuleInformation{
- TestOnly: Bool(f.sourceProperties.Test_only),
+ TestOnly: Bool(f.sourceProperties.Test_only) && !f.props.Skip,
TopLevelTarget: false,
})
}
diff --git a/android/apex.go b/android/apex.go
index c0acada..dc0aeed 100644
--- a/android/apex.go
+++ b/android/apex.go
@@ -90,7 +90,13 @@
TestApexes []string
}
-var ApexInfoProvider = blueprint.NewMutatorProvider[ApexInfo]("apex")
+// AllApexInfo holds the ApexInfo of all apexes that include this module.
+type AllApexInfo struct {
+ ApexInfos []ApexInfo
+}
+
+var ApexInfoProvider = blueprint.NewMutatorProvider[ApexInfo]("apex_mutate")
+var AllApexInfoProvider = blueprint.NewMutatorProvider[*AllApexInfo]("apex_info")
func (i ApexInfo) AddJSONData(d *map[string]interface{}) {
(*d)["Apex"] = map[string]interface{}{
@@ -586,75 +592,131 @@
return merged, aliases
}
-// CreateApexVariations mutates a given module into multiple apex variants each of which is for an
-// apexBundle (and/or the platform) where the module is part of.
-func CreateApexVariations(mctx BottomUpMutatorContext, module ApexModule) []Module {
+// IncomingApexTransition is called by apexTransitionMutator.IncomingTransition on modules that can be in apexes.
+// The incomingVariation can be either the name of an apex if the dependency is coming directly from an apex
+// module, or it can be the name of an apex variation (e.g. apex10000) if it is coming from another module that
+// is in the apex.
+func IncomingApexTransition(ctx IncomingTransitionContext, incomingVariation string) string {
+ module := ctx.Module().(ApexModule)
base := module.apexModuleBase()
+ var apexInfos []ApexInfo
+ if allApexInfos, ok := ModuleProvider(ctx, AllApexInfoProvider); ok {
+ apexInfos = allApexInfos.ApexInfos
+ }
+
+ // Dependencies from platform variations go to the platform variation.
+ if incomingVariation == "" {
+ return ""
+ }
+
+ // If this module has no apex variations the use the platform variation.
+ if len(apexInfos) == 0 {
+ return ""
+ }
+
+ // Convert the list of apex infos into from the AllApexInfoProvider into the merged list
+ // of apex variations and the aliases from apex names to apex variations.
+ var aliases [][2]string
+ if !module.UniqueApexVariations() && !base.ApexProperties.UniqueApexVariationsForDeps {
+ apexInfos, aliases = mergeApexVariations(apexInfos)
+ }
+
+ // Check if the incoming variation matches an apex name, and if so use the corresponding
+ // apex variation.
+ aliasIndex := slices.IndexFunc(aliases, func(alias [2]string) bool {
+ return alias[0] == incomingVariation
+ })
+ if aliasIndex >= 0 {
+ return aliases[aliasIndex][1]
+ }
+
+ // Check if the incoming variation matches an apex variation.
+ apexIndex := slices.IndexFunc(apexInfos, func(info ApexInfo) bool {
+ return info.ApexVariationName == incomingVariation
+ })
+ if apexIndex >= 0 {
+ return incomingVariation
+ }
+
+ return ""
+}
+
+func MutateApexTransition(ctx BaseModuleContext, variation string) {
+ module := ctx.Module().(ApexModule)
+ base := module.apexModuleBase()
+ platformVariation := variation == ""
+
+ var apexInfos []ApexInfo
+ if allApexInfos, ok := ModuleProvider(ctx, AllApexInfoProvider); ok {
+ apexInfos = allApexInfos.ApexInfos
+ }
+
// Shortcut
- if len(base.apexInfos) == 0 {
- return nil
+ if len(apexInfos) == 0 {
+ return
}
// Do some validity checks.
// TODO(jiyong): is this the right place?
- base.checkApexAvailableProperty(mctx)
+ base.checkApexAvailableProperty(ctx)
- apexInfos := base.apexInfos
- // base.apexInfos is only needed to propagate the list of apexes from apexInfoMutator to
- // apexMutator. It is no longer accurate after mergeApexVariations, and won't be copied to
- // all but the first created variant. Clear it so it doesn't accidentally get used later.
- base.apexInfos = nil
-
- slices.SortFunc(apexInfos, func(a, b ApexInfo) int {
- return strings.Compare(a.ApexVariationName, b.ApexVariationName)
- })
-
- var aliases [][2]string
- if !mctx.Module().(ApexModule).UniqueApexVariations() && !base.ApexProperties.UniqueApexVariationsForDeps {
- apexInfos, aliases = mergeApexVariations(apexInfos)
+ if !module.UniqueApexVariations() && !base.ApexProperties.UniqueApexVariationsForDeps {
+ apexInfos, _ = mergeApexVariations(apexInfos)
}
var inApex ApexMembership
for _, a := range apexInfos {
for _, apexContents := range a.ApexContents {
- inApex = inApex.merge(apexContents.contents[mctx.ModuleName()])
+ inApex = inApex.merge(apexContents.contents[ctx.ModuleName()])
}
}
base.ApexProperties.InAnyApex = true
base.ApexProperties.DirectlyInAnyApex = inApex == directlyInApex
- defaultVariation := ""
- mctx.SetDefaultDependencyVariation(&defaultVariation)
+ if platformVariation && !ctx.Host() && !module.AvailableFor(AvailableToPlatform) {
+ // Do not install the module for platform, but still allow it to output
+ // uninstallable AndroidMk entries in certain cases when they have side
+ // effects. TODO(jiyong): move this routine to somewhere else
+ module.MakeUninstallable()
+ }
+ if !platformVariation {
+ var thisApexInfo ApexInfo
- variations := []string{defaultVariation}
- testApexes := []string{}
+ apexIndex := slices.IndexFunc(apexInfos, func(info ApexInfo) bool {
+ return info.ApexVariationName == variation
+ })
+ if apexIndex >= 0 {
+ thisApexInfo = apexInfos[apexIndex]
+ } else {
+ panic(fmt.Errorf("failed to find apexInfo for incoming variation %q", variation))
+ }
+
+ SetProvider(ctx, ApexInfoProvider, thisApexInfo)
+ }
+
+ // Set the value of TestApexes in every single apex variant.
+ // This allows each apex variant to be aware of the test apexes in the user provided apex_available.
+ var testApexes []string
for _, a := range apexInfos {
- variations = append(variations, a.ApexVariationName)
testApexes = append(testApexes, a.TestApexes...)
}
- modules := mctx.CreateVariations(variations...)
- for i, mod := range modules {
- platformVariation := i == 0
- if platformVariation && !mctx.Host() && !mod.(ApexModule).AvailableFor(AvailableToPlatform) {
- // Do not install the module for platform, but still allow it to output
- // uninstallable AndroidMk entries in certain cases when they have side
- // effects. TODO(jiyong): move this routine to somewhere else
- mod.MakeUninstallable()
- }
- if !platformVariation {
- mctx.SetVariationProvider(mod, ApexInfoProvider, apexInfos[i-1])
- }
- // Set the value of TestApexes in every single apex variant.
- // This allows each apex variant to be aware of the test apexes in the user provided apex_available.
- mod.(ApexModule).apexModuleBase().ApexProperties.TestApexes = testApexes
- }
+ base.ApexProperties.TestApexes = testApexes
- for _, alias := range aliases {
- mctx.CreateAliasVariation(alias[0], alias[1])
- }
+}
- return modules
+func ApexInfoMutator(ctx TopDownMutatorContext, module ApexModule) {
+ base := module.apexModuleBase()
+ if len(base.apexInfos) > 0 {
+ apexInfos := slices.Clone(base.apexInfos)
+ slices.SortFunc(apexInfos, func(a, b ApexInfo) int {
+ return strings.Compare(a.ApexVariationName, b.ApexVariationName)
+ })
+ SetProvider(ctx, AllApexInfoProvider, &AllApexInfo{apexInfos})
+ // base.apexInfos is only needed to propagate the list of apexes from the apex module to its
+ // contents within apexInfoMutator. Clear it so it doesn't accidentally get used later.
+ base.apexInfos = nil
+ }
}
// UpdateUniqueApexVariationsForDeps sets UniqueApexVariationsForDeps if any dependencies that are
@@ -665,13 +727,16 @@
// InApexVariants list in common. It is used instead of DepIsInSameApex because it needs to
// determine if the dep is in the same APEX due to being directly included, not only if it
// is included _because_ it is a dependency.
- anyInSameApex := func(a, b []ApexInfo) bool {
- collectApexes := func(infos []ApexInfo) []string {
- var ret []string
- for _, info := range infos {
- ret = append(ret, info.InApexVariants...)
+ anyInSameApex := func(a, b ApexModule) bool {
+ collectApexes := func(m ApexModule) []string {
+ if allApexInfo, ok := OtherModuleProvider(mctx, m, AllApexInfoProvider); ok {
+ var ret []string
+ for _, info := range allApexInfo.ApexInfos {
+ ret = append(ret, info.InApexVariants...)
+ }
+ return ret
}
- return ret
+ return nil
}
aApexes := collectApexes(a)
@@ -689,7 +754,7 @@
// If any of the dependencies requires unique apex variations, so does this module.
mctx.VisitDirectDeps(func(dep Module) {
if depApexModule, ok := dep.(ApexModule); ok {
- if anyInSameApex(depApexModule.apexModuleBase().apexInfos, am.apexModuleBase().apexInfos) &&
+ if anyInSameApex(depApexModule, am) &&
(depApexModule.UniqueApexVariations() ||
depApexModule.apexModuleBase().ApexProperties.UniqueApexVariationsForDeps) {
am.apexModuleBase().ApexProperties.UniqueApexVariationsForDeps = true
diff --git a/android/arch.go b/android/arch.go
index 27ce4d4..3224c3a 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -16,16 +16,11 @@
import (
"encoding"
- "encoding/json"
"fmt"
"reflect"
"runtime"
- "sort"
"strings"
- "android/soong/bazel"
- "android/soong/starlark_fmt"
-
"github.com/google/blueprint"
"github.com/google/blueprint/bootstrap"
"github.com/google/blueprint/proptools"
@@ -1899,428 +1894,8 @@
return buildTargets, nil
}
-func (m *ModuleBase) getArchPropertySet(propertySet interface{}, archType ArchType) interface{} {
- archString := archType.Field
- for i := range m.archProperties {
- if m.archProperties[i] == nil {
- // Skip over nil properties
- continue
- }
-
- // Not archProperties are usable; this function looks for properties of a very specific
- // form, and ignores the rest.
- for _, archProperty := range m.archProperties[i] {
- // archPropValue is a property struct, we are looking for the form:
- // `arch: { arm: { key: value, ... }}`
- archPropValue := reflect.ValueOf(archProperty).Elem()
-
- // Unwrap src so that it should looks like a pointer to `arm: { key: value, ... }`
- src := archPropValue.FieldByName("Arch").Elem()
-
- // Step into non-nil pointers to structs in the src value.
- if src.Kind() == reflect.Ptr {
- if src.IsNil() {
- continue
- }
- src = src.Elem()
- }
-
- // Find the requested field (e.g. arm, x86) in the src struct.
- src = src.FieldByName(archString)
-
- // We only care about structs.
- if !src.IsValid() || src.Kind() != reflect.Struct {
- continue
- }
-
- // If the value of the field is a struct then step into the
- // BlueprintEmbed field. The special "BlueprintEmbed" name is
- // used by createArchPropTypeDesc to embed the arch properties
- // in the parent struct, so the src arch prop should be in this
- // field.
- //
- // See createArchPropTypeDesc for more details on how Arch-specific
- // module properties are processed from the nested props and written
- // into the module's archProperties.
- src = src.FieldByName("BlueprintEmbed")
-
- // Clone the destination prop, since we want a unique prop struct per arch.
- propertySetClone := reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface()
-
- // Copy the located property struct into the cloned destination property struct.
- err := proptools.ExtendMatchingProperties([]interface{}{propertySetClone}, src.Interface(), nil, proptools.OrderReplace)
- if err != nil {
- // This is fine, it just means the src struct doesn't match the type of propertySet.
- continue
- }
-
- return propertySetClone
- }
- }
- // No property set was found specific to the given arch, so return an empty
- // property set.
- return reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface()
-}
-
-// getMultilibPropertySet returns a property set struct matching the type of
-// `propertySet`, containing multilib-specific module properties for the given architecture.
-// If no multilib-specific properties exist for the given architecture, returns an empty property
-// set matching `propertySet`'s type.
-func (m *ModuleBase) getMultilibPropertySet(propertySet interface{}, archType ArchType) interface{} {
- // archType.Multilib is lowercase (for example, lib32) but property struct field is
- // capitalized, such as Lib32, so use strings.Title to capitalize it.
- multiLibString := strings.Title(archType.Multilib)
-
- for i := range m.archProperties {
- if m.archProperties[i] == nil {
- // Skip over nil properties
- continue
- }
-
- // Not archProperties are usable; this function looks for properties of a very specific
- // form, and ignores the rest.
- for _, archProperties := range m.archProperties[i] {
- // archPropValue is a property struct, we are looking for the form:
- // `multilib: { lib32: { key: value, ... }}`
- archPropValue := reflect.ValueOf(archProperties).Elem()
-
- // Unwrap src so that it should looks like a pointer to `lib32: { key: value, ... }`
- src := archPropValue.FieldByName("Multilib").Elem()
-
- // Step into non-nil pointers to structs in the src value.
- if src.Kind() == reflect.Ptr {
- if src.IsNil() {
- // Ignore nil pointers.
- continue
- }
- src = src.Elem()
- }
-
- // Find the requested field (e.g. lib32) in the src struct.
- src = src.FieldByName(multiLibString)
-
- // We only care about valid struct pointers.
- if !src.IsValid() || src.Kind() != reflect.Ptr || src.Elem().Kind() != reflect.Struct {
- continue
- }
-
- // Get the zero value for the requested property set.
- propertySetClone := reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface()
-
- // Copy the located property struct into the "zero" property set struct.
- err := proptools.ExtendMatchingProperties([]interface{}{propertySetClone}, src.Interface(), nil, proptools.OrderReplace)
-
- if err != nil {
- // This is fine, it just means the src struct doesn't match.
- continue
- }
-
- return propertySetClone
- }
- }
-
- // There were no multilib properties specifically matching the given archtype.
- // Return zeroed value.
- return reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface()
-}
-
// ArchVariantContext defines the limited context necessary to retrieve arch_variant properties.
type ArchVariantContext interface {
ModuleErrorf(fmt string, args ...interface{})
PropertyErrorf(property, fmt string, args ...interface{})
}
-
-// ArchVariantProperties represents a map of arch-variant config strings to a property interface{}.
-type ArchVariantProperties map[string]interface{}
-
-// ConfigurationAxisToArchVariantProperties represents a map of bazel.ConfigurationAxis to
-// ArchVariantProperties, such that each independent arch-variant axis maps to the
-// configs/properties for that axis.
-type ConfigurationAxisToArchVariantProperties map[bazel.ConfigurationAxis]ArchVariantProperties
-
-// GetArchVariantProperties returns a ConfigurationAxisToArchVariantProperties where the
-// arch-variant properties correspond to the values of the properties of the 'propertySet' struct
-// that are specific to that axis/configuration. Each axis is independent, containing
-// non-overlapping configs that correspond to the various "arch-variant" support, at this time:
-//
-// arches (including multilib)
-// oses
-// arch+os combinations
-//
-// For example, passing a struct { Foo bool, Bar string } will return an interface{} that can be
-// type asserted back into the same struct, containing the config-specific property value specified
-// by the module if defined.
-//
-// Arch-specific properties may come from an arch stanza or a multilib stanza; properties
-// in these stanzas are combined.
-// For example: `arch: { x86: { Foo: ["bar"] } }, multilib: { lib32: {` Foo: ["baz"] } }`
-// will result in `Foo: ["bar", "baz"]` being returned for architecture x86, if the given
-// propertyset contains `Foo []string`.
-func (m *ModuleBase) GetArchVariantProperties(ctx ArchVariantContext, propertySet interface{}) ConfigurationAxisToArchVariantProperties {
- // Return value of the arch types to the prop values for that arch.
- axisToProps := ConfigurationAxisToArchVariantProperties{}
-
- // Nothing to do for non-arch-specific modules.
- if !m.ArchSpecific() {
- return axisToProps
- }
-
- dstType := reflect.ValueOf(propertySet).Type()
- var archProperties []interface{}
-
- // First find the property set in the module that corresponds to the requested
- // one. m.archProperties[i] corresponds to m.GetProperties()[i].
- for i, generalProp := range m.GetProperties() {
- srcType := reflect.ValueOf(generalProp).Type()
- if srcType == dstType {
- archProperties = m.archProperties[i]
- axisToProps[bazel.NoConfigAxis] = ArchVariantProperties{"": generalProp}
- break
- }
- }
-
- if archProperties == nil {
- // This module does not have the property set requested
- return axisToProps
- }
-
- archToProp := ArchVariantProperties{}
- // For each arch type (x86, arm64, etc.)
- for _, arch := range ArchTypeList() {
- // Arch properties are sometimes sharded (see createArchPropTypeDesc() ).
- // Iterate over every shard and extract a struct with the same type as the
- // input one that contains the data specific to that arch.
- propertyStructs := make([]reflect.Value, 0)
- archFeaturePropertyStructs := make(map[string][]reflect.Value, 0)
- for _, archProperty := range archProperties {
- archTypeStruct, ok := getArchTypeStruct(ctx, archProperty, arch)
- if ok {
- propertyStructs = append(propertyStructs, archTypeStruct)
-
- // For each feature this arch supports (arm: neon, x86: ssse3, sse4, ...)
- for _, feature := range archFeatures[arch] {
- prefix := "arch." + arch.Name + "." + feature
- if featureProperties, ok := getChildPropertyStruct(ctx, archTypeStruct, feature, prefix); ok {
- archFeaturePropertyStructs[feature] = append(archFeaturePropertyStructs[feature], featureProperties)
- }
- }
- }
- multilibStruct, ok := getMultilibStruct(ctx, archProperty, arch)
- if ok {
- propertyStructs = append(propertyStructs, multilibStruct)
- }
- }
-
- archToProp[arch.Name] = mergeStructs(ctx, propertyStructs, propertySet)
-
- // In soong, if multiple features match the current configuration, they're
- // all used. In bazel, we have to have unambiguous select() statements, so
- // we can't have two features that are both active in the same select().
- // One alternative is to split out each feature into a separate select(),
- // but then it's difficult to support exclude_srcs, which may need to
- // exclude things from the regular arch select() statement if a certain
- // feature is active. Instead, keep the features in the same select
- // statement as the arches, but emit the power set of all possible
- // combinations of features, so that bazel can match the most precise one.
- allFeatures := make([]string, 0, len(archFeaturePropertyStructs))
- for feature := range archFeaturePropertyStructs {
- allFeatures = append(allFeatures, feature)
- }
- for _, features := range bazel.PowerSetWithoutEmptySet(allFeatures) {
- sort.Strings(features)
- propsForCurrentFeatureSet := make([]reflect.Value, 0)
- propsForCurrentFeatureSet = append(propsForCurrentFeatureSet, propertyStructs...)
- for _, feature := range features {
- propsForCurrentFeatureSet = append(propsForCurrentFeatureSet, archFeaturePropertyStructs[feature]...)
- }
- archToProp[arch.Name+"-"+strings.Join(features, "-")] =
- mergeStructs(ctx, propsForCurrentFeatureSet, propertySet)
- }
- }
- axisToProps[bazel.ArchConfigurationAxis] = archToProp
-
- osToProp := ArchVariantProperties{}
- archOsToProp := ArchVariantProperties{}
-
- linuxStructs := getTargetStructs(ctx, archProperties, "Linux")
- bionicStructs := getTargetStructs(ctx, archProperties, "Bionic")
- hostStructs := getTargetStructs(ctx, archProperties, "Host")
- hostLinuxStructs := getTargetStructs(ctx, archProperties, "Host_linux")
- hostNotWindowsStructs := getTargetStructs(ctx, archProperties, "Not_windows")
-
- // For android, linux, ...
- for _, os := range osTypeList {
- if os == CommonOS {
- // It looks like this OS value is not used in Blueprint files
- continue
- }
- osStructs := make([]reflect.Value, 0)
-
- osSpecificStructs := getTargetStructs(ctx, archProperties, os.Field)
- if os.Class == Host {
- osStructs = append(osStructs, hostStructs...)
- }
- if os.Linux() {
- osStructs = append(osStructs, linuxStructs...)
- }
- if os.Bionic() {
- osStructs = append(osStructs, bionicStructs...)
- }
- if os.Linux() && os.Class == Host {
- osStructs = append(osStructs, hostLinuxStructs...)
- }
-
- if os == LinuxMusl {
- osStructs = append(osStructs, getTargetStructs(ctx, archProperties, "Musl")...)
- }
- if os == Linux {
- osStructs = append(osStructs, getTargetStructs(ctx, archProperties, "Glibc")...)
- }
-
- osStructs = append(osStructs, osSpecificStructs...)
-
- if os.Class == Host && os != Windows {
- osStructs = append(osStructs, hostNotWindowsStructs...)
- }
- osToProp[os.Name] = mergeStructs(ctx, osStructs, propertySet)
-
- // For arm, x86, ...
- for _, arch := range osArchTypeMap[os] {
- osArchStructs := make([]reflect.Value, 0)
-
- // Auto-combine with Linux_ and Bionic_ targets. This potentially results in
- // repetition and select() bloat, but use of Linux_* and Bionic_* targets is rare.
- // TODO(b/201423152): Look into cleanup.
- if os.Linux() {
- targetField := "Linux_" + arch.Name
- targetStructs := getTargetStructs(ctx, archProperties, targetField)
- osArchStructs = append(osArchStructs, targetStructs...)
- }
- if os.Bionic() {
- targetField := "Bionic_" + arch.Name
- targetStructs := getTargetStructs(ctx, archProperties, targetField)
- osArchStructs = append(osArchStructs, targetStructs...)
- }
- if os == LinuxMusl {
- targetField := "Musl_" + arch.Name
- targetStructs := getTargetStructs(ctx, archProperties, targetField)
- osArchStructs = append(osArchStructs, targetStructs...)
- }
- if os == Linux {
- targetField := "Glibc_" + arch.Name
- targetStructs := getTargetStructs(ctx, archProperties, targetField)
- osArchStructs = append(osArchStructs, targetStructs...)
- }
-
- targetField := GetCompoundTargetField(os, arch)
- targetName := fmt.Sprintf("%s_%s", os.Name, arch.Name)
- targetStructs := getTargetStructs(ctx, archProperties, targetField)
- osArchStructs = append(osArchStructs, targetStructs...)
-
- archOsToProp[targetName] = mergeStructs(ctx, osArchStructs, propertySet)
- }
- }
-
- axisToProps[bazel.OsConfigurationAxis] = osToProp
- axisToProps[bazel.OsArchConfigurationAxis] = archOsToProp
- return axisToProps
-}
-
-// Returns a struct matching the propertySet interface, containing properties specific to the targetName
-// For example, given these arguments:
-//
-// propertySet = BaseCompilerProperties
-// targetName = "android_arm"
-//
-// And given this Android.bp fragment:
-//
-// target:
-// android_arm: {
-// srcs: ["foo.c"],
-// }
-// android_arm64: {
-// srcs: ["bar.c"],
-// }
-// }
-//
-// This would return a BaseCompilerProperties with BaseCompilerProperties.Srcs = ["foo.c"]
-func getTargetStructs(ctx ArchVariantContext, archProperties []interface{}, targetName string) []reflect.Value {
- var propertyStructs []reflect.Value
- for _, archProperty := range archProperties {
- archPropValues := reflect.ValueOf(archProperty).Elem()
- targetProp := archPropValues.FieldByName("Target").Elem()
- targetStruct, ok := getChildPropertyStruct(ctx, targetProp, targetName, targetName)
- if ok {
- propertyStructs = append(propertyStructs, targetStruct)
- } else {
- return []reflect.Value{}
- }
- }
-
- return propertyStructs
-}
-
-func mergeStructs(ctx ArchVariantContext, propertyStructs []reflect.Value, propertySet interface{}) interface{} {
- // Create a new instance of the requested property set
- value := reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface()
-
- // Merge all the structs together
- for _, propertyStruct := range propertyStructs {
- mergePropertyStruct(ctx, value, propertyStruct)
- }
-
- return value
-}
-
-func printArchTypeStarlarkDict(dict map[ArchType][]string) string {
- valDict := make(map[string]string, len(dict))
- for k, v := range dict {
- valDict[k.String()] = starlark_fmt.PrintStringList(v, 1)
- }
- return starlark_fmt.PrintDict(valDict, 0)
-}
-
-func printArchTypeNestedStarlarkDict(dict map[ArchType]map[string][]string) string {
- valDict := make(map[string]string, len(dict))
- for k, v := range dict {
- valDict[k.String()] = starlark_fmt.PrintStringListDict(v, 1)
- }
- return starlark_fmt.PrintDict(valDict, 0)
-}
-
-func printArchConfigList(arches []archConfig) string {
- jsonOut, err := json.MarshalIndent(arches, "", starlark_fmt.Indention(1))
- if err != nil {
- panic(fmt.Errorf("Error converting arch configs %#v to json: %q", arches, err))
- }
- return fmt.Sprintf("json.decode('''%s''')", string(jsonOut))
-}
-
-func StarlarkArchConfigurations() string {
- return fmt.Sprintf(`
-_arch_to_variants = %s
-
-_arch_to_cpu_variants = %s
-
-_arch_to_features = %s
-
-_android_arch_feature_for_arch_variant = %s
-
-_aml_arches = %s
-
-_ndk_arches = %s
-
-arch_to_variants = _arch_to_variants
-arch_to_cpu_variants = _arch_to_cpu_variants
-arch_to_features = _arch_to_features
-android_arch_feature_for_arch_variants = _android_arch_feature_for_arch_variant
-aml_arches = _aml_arches
-ndk_arches = _ndk_arches
-`, printArchTypeStarlarkDict(archVariants),
- printArchTypeStarlarkDict(cpuVariants),
- printArchTypeStarlarkDict(archFeatures),
- printArchTypeNestedStarlarkDict(androidArchFeatureMap),
- printArchConfigList(getAmlAbisConfig()),
- printArchConfigList(getNdkAbisConfig()),
- )
-}
diff --git a/android/module.go b/android/module.go
index 26261cc..5fe379c 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1042,12 +1042,12 @@
pv := ctx.Config().productVariables
fullManifest := pv.DeviceArch != nil && pv.DeviceName != nil
if fullManifest {
- m.addRequiredDeps(ctx)
+ addRequiredDeps(ctx)
}
}
// addRequiredDeps adds required, target_required, and host_required as dependencies.
-func (m *ModuleBase) addRequiredDeps(ctx BottomUpMutatorContext) {
+func addRequiredDeps(ctx BottomUpMutatorContext) {
addDep := func(target Target, depName string) {
if !ctx.OtherModuleExists(depName) {
if ctx.Config().AllowMissingDependencies() {
@@ -1060,9 +1060,9 @@
// in build/make/core/main.mk.
// TODO(jiyong): the Make-side does this only when the required module is a shared
// library or a native test.
- bothInAndroid := m.Device() && target.Os.Class == Device
- nativeArch := InList(m.Arch().ArchType.Multilib, []string{"lib32", "lib64"})
- sameBitness := m.Arch().ArchType.Multilib == target.Arch.ArchType.Multilib
+ bothInAndroid := ctx.Device() && target.Os.Class == Device
+ nativeArch := InList(ctx.Arch().ArchType.Multilib, []string{"lib32", "lib64"})
+ sameBitness := ctx.Arch().ArchType.Multilib == target.Arch.ArchType.Multilib
if bothInAndroid && nativeArch && !sameBitness {
return
}
@@ -1081,31 +1081,31 @@
hostTargets = append(hostTargets, ctx.Config().Targets[ctx.Config().BuildOS]...)
hostTargets = append(hostTargets, ctx.Config().BuildOSCommonTarget)
- if m.Device() {
- for _, depName := range m.RequiredModuleNames() {
+ if ctx.Device() {
+ for _, depName := range ctx.Module().RequiredModuleNames() {
for _, target := range deviceTargets {
addDep(target, depName)
}
}
- for _, depName := range m.HostRequiredModuleNames() {
+ for _, depName := range ctx.Module().HostRequiredModuleNames() {
for _, target := range hostTargets {
addDep(target, depName)
}
}
}
- if m.Host() {
- for _, depName := range m.RequiredModuleNames() {
+ if ctx.Host() {
+ for _, depName := range ctx.Module().RequiredModuleNames() {
for _, target := range hostTargets {
// When a host module requires another host module, don't make a
// dependency if they have different OSes (i.e. hostcross).
- if m.Target().HostCross != target.HostCross {
+ if ctx.Target().HostCross != target.HostCross {
continue
}
addDep(target, depName)
}
}
- for _, depName := range m.TargetRequiredModuleNames() {
+ for _, depName := range ctx.Module().TargetRequiredModuleNames() {
for _, target := range deviceTargets {
addDep(target, depName)
}
diff --git a/android/prebuilt.go b/android/prebuilt.go
index 91ba05b..2b7b55b 100644
--- a/android/prebuilt.go
+++ b/android/prebuilt.go
@@ -706,11 +706,6 @@
return true
}
- // If the use_source_config_var property is set then it overrides the prefer property setting.
- if configVar := p.properties.Use_source_config_var; configVar != nil {
- return !ctx.Config().VendorConfig(proptools.String(configVar.Config_namespace)).Bool(proptools.String(configVar.Var_name))
- }
-
// TODO: use p.Properties.Name and ctx.ModuleDir to override preference
return Bool(p.properties.Prefer)
}
diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go
index 2241b08..2574ed4 100644
--- a/android/prebuilt_test.go
+++ b/android/prebuilt_test.go
@@ -295,158 +295,6 @@
}`,
prebuilt: []OsType{Android, buildOS},
},
- {
- name: "prebuilt use_source_config_var={acme, use_source} - no var specified",
- modules: `
- source {
- name: "bar",
- }
-
- prebuilt {
- name: "bar",
- use_source_config_var: {config_namespace: "acme", var_name: "use_source"},
- srcs: ["prebuilt_file"],
- }`,
- // When use_source_env is specified then it will use the prebuilt by default if the environment
- // variable is not set.
- prebuilt: []OsType{Android, buildOS},
- },
- {
- name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=false",
- modules: `
- source {
- name: "bar",
- }
-
- prebuilt {
- name: "bar",
- use_source_config_var: {config_namespace: "acme", var_name: "use_source"},
- srcs: ["prebuilt_file"],
- }`,
- preparer: FixtureModifyProductVariables(func(variables FixtureProductVariables) {
- variables.VendorVars = map[string]map[string]string{
- "acme": {
- "use_source": "false",
- },
- }
- }),
- // Setting the environment variable named in use_source_env to false will cause the prebuilt to
- // be used.
- prebuilt: []OsType{Android, buildOS},
- },
- {
- name: "apex_contributions supersedes any source preferred via use_source_config_var",
- modules: `
- source {
- name: "bar",
- }
-
- prebuilt {
- name: "bar",
- use_source_config_var: {config_namespace: "acme", var_name: "use_source"},
- srcs: ["prebuilt_file"],
- }
- apex_contributions {
- name: "my_mainline_module_contribution",
- api_domain: "apexfoo",
- // this metadata module contains prebuilt
- contents: ["prebuilt_bar"],
- }
- all_apex_contributions {
- name: "all_apex_contributions",
- }
- `,
- preparer: FixtureModifyProductVariables(func(variables FixtureProductVariables) {
- variables.VendorVars = map[string]map[string]string{
- "acme": {
- "use_source": "true",
- },
- }
- variables.BuildFlags = map[string]string{
- "RELEASE_APEX_CONTRIBUTIONS_ADSERVICES": "my_mainline_module_contribution",
- }
- }),
- // use_source_config_var indicates that source should be used
- // but this is superseded by `my_mainline_module_contribution`
- prebuilt: []OsType{Android, buildOS},
- },
- {
- name: "apex_contributions supersedes any prebuilt preferred via use_source_config_var",
- modules: `
- source {
- name: "bar",
- }
-
- prebuilt {
- name: "bar",
- use_source_config_var: {config_namespace: "acme", var_name: "use_source"},
- srcs: ["prebuilt_file"],
- }
- apex_contributions {
- name: "my_mainline_module_contribution",
- api_domain: "apexfoo",
- // this metadata module contains source
- contents: ["bar"],
- }
- all_apex_contributions {
- name: "all_apex_contributions",
- }
- `,
- preparer: FixtureModifyProductVariables(func(variables FixtureProductVariables) {
- variables.VendorVars = map[string]map[string]string{
- "acme": {
- "use_source": "false",
- },
- }
- variables.BuildFlags = map[string]string{
- "RELEASE_APEX_CONTRIBUTIONS_ADSERVICES": "my_mainline_module_contribution",
- }
- }),
- // use_source_config_var indicates that prebuilt should be used
- // but this is superseded by `my_mainline_module_contribution`
- prebuilt: nil,
- },
- {
- name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=true",
- modules: `
- source {
- name: "bar",
- }
-
- prebuilt {
- name: "bar",
- use_source_config_var: {config_namespace: "acme", var_name: "use_source"},
- srcs: ["prebuilt_file"],
- }`,
- preparer: FixtureModifyProductVariables(func(variables FixtureProductVariables) {
- variables.VendorVars = map[string]map[string]string{
- "acme": {
- "use_source": "true",
- },
- }
- }),
- // Setting the environment variable named in use_source_env to true will cause the source to be
- // used.
- prebuilt: nil,
- },
- {
- name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=true, no source",
- modules: `
- prebuilt {
- name: "bar",
- use_source_config_var: {config_namespace: "acme", var_name: "use_source"},
- srcs: ["prebuilt_file"],
- }`,
- preparer: FixtureModifyProductVariables(func(variables FixtureProductVariables) {
- variables.VendorVars = map[string]map[string]string{
- "acme": {
- "use_source": "true",
- },
- }
- }),
- // Although the environment variable says to use source there is no source available.
- prebuilt: []OsType{Android, buildOS},
- },
}
fs := MockFS{
diff --git a/android/variable.go b/android/variable.go
index 0040d83..599f88e 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -20,8 +20,6 @@
"runtime"
"strings"
- "android/soong/bazel"
-
"github.com/google/blueprint/proptools"
)
@@ -492,10 +490,6 @@
CheckVendorSeappViolations *bool `json:",omitempty"`
- // PartitionVarsForBazelMigrationOnlyDoNotUse are extra variables that are used to define the
- // partition images. They should not be read from soong modules.
- PartitionVarsForBazelMigrationOnlyDoNotUse PartitionVariables `json:",omitempty"`
-
BuildFlags map[string]string `json:",omitempty"`
BuildFromSourceStub *bool `json:",omitempty"`
@@ -644,387 +638,6 @@
return val == "true"
}
-// ProductConfigContext requires the access to the Module to get product config properties.
-type ProductConfigContext interface {
- Module() Module
-}
-
-// 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
-
- arch string
-}
-
-func (p ProductConfigProperty) Name() string {
- return p.name
-}
-
-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 {
- 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 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
- }
-
- 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, 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
-// their property name and the product config variable they're set under.
-//
-// The outer map key is the name of the property, like "cflags".
-//
-// The inner map key is a ProductConfigProperty, which is a struct of product
-// variable name, namespace, and the "full configuration" of the product
-// variable.
-//
-// e.g. product variable name: board, namespace: acme, full config: vendor_chip_foo
-//
-// The value of the map is the interface{} representing the value of the
-// property, like ["-DDEFINES"] for cflags.
-type ProductConfigProperties map[string]map[ProductConfigOrSoongConfigProperty]interface{}
-
-func (p *ProductConfigProperties) AddProductConfigProperty(
- propertyName, productVariableName, arch string, propertyValue interface{}) {
-
- productConfigProp := ProductConfigProperty{
- name: productVariableName, // e.g. size, feature1, feature2, FEATURE3, board
- arch: arch, // e.g. "", x86, arm64
- }
-
- 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:
- src, ok := propertyValue.([]string)
- if !ok {
- panic("Conflicting types")
- }
- dst = append(dst, src...)
- (*p)[propertyName][key] = dst
- default:
- if existing != propertyValue {
- panic(fmt.Errorf("TODO: handle merging value %#v", existing))
- }
- }
- } else {
- (*p)[propertyName][key] = propertyValue
- }
-}
-
-// maybeExtractConfigVarProp attempts to read this value as a config var struct
-// wrapped by interfaces and ptrs. If it's not the right type, the second return
-// value is false.
-func maybeExtractConfigVarProp(v reflect.Value) (reflect.Value, bool) {
- if v.Kind() == reflect.Interface {
- // The conditions_default value can be either
- // 1) an ptr to an interface of a struct (bool config variables and product variables)
- // 2) an interface of 1) (config variables with nested structs, like string vars)
- v = v.Elem()
- }
- if v.Kind() != reflect.Ptr {
- return v, false
- }
- v = reflect.Indirect(v)
- if v.Kind() == reflect.Interface {
- // Extract the struct from the interface
- v = v.Elem()
- }
-
- if !v.IsValid() {
- return v, false
- }
-
- if v.Kind() != reflect.Struct {
- return v, false
- }
- return v, true
-}
-
-func (productConfigProperties *ProductConfigProperties) AddProductConfigProperties(variableValues reflect.Value, arch string) {
- // Example of product_variables:
- //
- // product_variables: {
- // malloc_not_svelte: {
- // shared_libs: ["malloc_not_svelte_shared_lib"],
- // whole_static_libs: ["malloc_not_svelte_whole_static_lib"],
- // exclude_static_libs: [
- // "malloc_not_svelte_static_lib_excludes",
- // "malloc_not_svelte_whole_static_lib_excludes",
- // ],
- // },
- // },
-
- for i := 0; i < variableValues.NumField(); i++ {
- // e.g. Platform_sdk_version, Unbundled_build, Malloc_not_svelte, etc.
- productVariableName := variableValues.Type().Field(i).Name
-
- variableValue := variableValues.Field(i)
- // Check if any properties were set for the module
- if variableValue.IsZero() {
- // e.g. feature1: {}, malloc_not_svelte: {}
- continue
- }
-
- for j := 0; j < variableValue.NumField(); j++ {
- property := variableValue.Field(j)
- // e.g. Asflags, Cflags, Enabled, etc.
- propertyName := variableValue.Type().Field(j).Name
- if property.Kind() != reflect.Interface {
- productConfigProperties.AddProductConfigProperty(propertyName, productVariableName, arch, property.Interface())
- }
- }
- }
-
-}
-
-func (productConfigProperties *ProductConfigProperties) AddSoongConfigProperties(namespace string, soongConfigVariablesStruct reflect.Value) error {
- //
- // 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
- } else if !v.IsValid() {
- // Skip invalid variables which may not used, else leads to panic
- continue
- }
-
- 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 propertyOrStruct.IsZero() {
- continue
- }
-
- if v, ok := maybeExtractConfigVarProp(propertyOrStruct); ok {
- // The field is a struct, which is used by:
- // 1) soong_config_string_variables
- //
- // soc_a: {
- // cflags: ...,
- // }
- //
- // soc_b: {
- // cflags: ...,
- // }
- //
- // 2) conditions_default structs for all soong config variable types.
- //
- // conditions_default: {
- // 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++ {
- // For product variables, zero values are irrelevant; however, for soong config variables,
- // empty values are relevant because there can also be a conditions default which is not
- // applied for empty variables.
- if field.Field(k).IsZero() && namespace == "" {
- continue
- }
-
- 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" {
- return fmt.Errorf("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 propertyOrStruct.Kind() != reflect.Interface {
- // If not an interface, then this is not a conditions_default or
- // 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" {
- return fmt.Errorf("Arch/Multilib are not currently supported in soong config variable structs")
- } else {
- productConfigProperties.AddSoongConfigProperty(propertyOrValueName, namespace, variableName, "", "", propertyOrStruct.Interface())
- }
- }
- }
- }
- return nil
-}
-
-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
-
- 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 if !archOrOsSpecificStruct.IsZero() {
- // 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) {
var module Module
var ok bool
diff --git a/apex/apex.go b/apex/apex.go
index cb8449c..ef57d7e 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -73,7 +73,7 @@
// Run mark_platform_availability before the apexMutator as the apexMutator needs to know whether
// it should create a platform variant.
ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
- ctx.BottomUp("apex", apexMutator).Parallel()
+ ctx.Transition("apex", &apexTransitionMutator{})
ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
ctx.BottomUp("apex_dcla_deps", apexDCLADepsMutator).Parallel()
// Register after apex_info mutator so that it can use ApexVariationName
@@ -1084,6 +1084,10 @@
if a, ok := mctx.Module().(ApexInfoMutator); ok {
a.ApexInfoMutator(mctx)
}
+
+ if am, ok := mctx.Module().(android.ApexModule); ok {
+ android.ApexInfoMutator(mctx, am)
+ }
enforceAppUpdatability(mctx)
}
@@ -1284,40 +1288,41 @@
}
}
-// apexMutator visits each module and creates apex variations if the module was marked in the
-// previous run of apexInfoMutator.
-func apexMutator(mctx android.BottomUpMutatorContext) {
- if !mctx.Module().Enabled() {
- return
- }
+type apexTransitionMutator struct{}
- // This is the usual path.
- if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
- android.CreateApexVariations(mctx, am)
- return
- }
-
+func (a *apexTransitionMutator) Split(ctx android.BaseModuleContext) []string {
// apexBundle itself is mutated so that it and its dependencies have the same apex variant.
- // Note that a default variation "" is also created as an alias, and the default dependency
- // variation is set to the default variation. This is to allow an apex to depend on another
- // module which is outside of the apex. This is because the dependent module is not mutated
- // for this apex variant.
- createApexVariation := func(apexBundleName string) {
- defaultVariation := ""
- mctx.SetDefaultDependencyVariation(&defaultVariation)
- mctx.CreateVariations(apexBundleName)
- mctx.CreateAliasVariation(defaultVariation, apexBundleName)
- }
-
- if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
- createApexVariation(ai.ApexVariationName())
- } else if o, ok := mctx.Module().(*OverrideApex); ok {
+ if ai, ok := ctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
+ return []string{ai.ApexVariationName()}
+ } else if o, ok := ctx.Module().(*OverrideApex); ok {
apexBundleName := o.GetOverriddenModuleName()
if apexBundleName == "" {
- mctx.ModuleErrorf("base property is not set")
- return
+ ctx.ModuleErrorf("base property is not set")
}
- createApexVariation(apexBundleName)
+ return []string{apexBundleName}
+ }
+ return []string{""}
+}
+
+func (a *apexTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string {
+ return sourceVariation
+}
+
+func (a *apexTransitionMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string {
+ if am, ok := ctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
+ return android.IncomingApexTransition(ctx, incomingVariation)
+ } else if ai, ok := ctx.Module().(ApexInfoMutator); ok {
+ return ai.ApexVariationName()
+ } else if o, ok := ctx.Module().(*OverrideApex); ok {
+ return o.GetOverriddenModuleName()
+ }
+
+ return ""
+}
+
+func (a *apexTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, variation string) {
+ if am, ok := ctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
+ android.MutateApexTransition(ctx, variation)
}
}
diff --git a/cmd/release_config/build_flag/Android.bp b/cmd/release_config/build_flag/Android.bp
new file mode 100644
index 0000000..0f10c91
--- /dev/null
+++ b/cmd/release_config/build_flag/Android.bp
@@ -0,0 +1,32 @@
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+blueprint_go_binary {
+ name: "build-flag",
+ deps: [
+ "golang-protobuf-encoding-prototext",
+ "golang-protobuf-reflect-protoreflect",
+ "golang-protobuf-runtime-protoimpl",
+ "soong-cmd-release_config-proto",
+ "soong-cmd-release_config-lib",
+ ],
+ srcs: [
+ "main.go",
+ ],
+}
+
+bootstrap_go_package {
+ name: "soong-cmd-release_config-build_flag",
+ pkgPath: "android/soong/cmd/release_config/build_flag",
+ deps: [
+ "golang-protobuf-encoding-prototext",
+ "golang-protobuf-reflect-protoreflect",
+ "golang-protobuf-runtime-protoimpl",
+ "soong-cmd-release_config-proto",
+ "soong-cmd-release_config-lib",
+ ],
+ srcs: [
+ "main.go",
+ ],
+}
diff --git a/cmd/release_config/build_flag/main.go b/cmd/release_config/build_flag/main.go
new file mode 100644
index 0000000..6f909af
--- /dev/null
+++ b/cmd/release_config/build_flag/main.go
@@ -0,0 +1,229 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+ "path/filepath"
+ "strings"
+
+ rc_lib "android/soong/cmd/release_config/release_config_lib"
+ rc_proto "android/soong/cmd/release_config/release_config_proto"
+
+ "google.golang.org/protobuf/proto"
+)
+
+type Flags struct {
+ // The path to the top of the workspace. Default: ".".
+ top string
+
+ // Pathlist of release config map textproto files.
+ // If not specified, then the value is (if present):
+ // - build/release/release_config_map.textproto
+ // - vendor/google_shared/build/release/release_config_map.textproto
+ // - vendor/google/release/release_config_map.textproto
+ //
+ // Additionally, any maps specified in the environment variable
+ // `PRODUCT_RELEASE_CONFIG_MAPS` are used.
+ maps rc_lib.StringList
+
+ // Output directory (relative to `top`).
+ outDir string
+
+ // Which $TARGET_RELEASE(s) should we use. Some commands will only
+ // accept one value, others also accept `--release --all`.
+ targetReleases rc_lib.StringList
+
+ // Disable warning messages
+ quiet bool
+}
+
+type CommandFunc func(*rc_lib.ReleaseConfigs, Flags, string, []string) error
+
+var commandMap map[string]CommandFunc = map[string]CommandFunc{
+ "get": GetCommand,
+ "set": SetCommand,
+ "trace": GetCommand, // Also handled by GetCommand
+}
+
+// Find the top of the release config contribution directory.
+// Returns the parent of the flag_declarations and flag_values directories.
+func GetMapDir(path string) (string, error) {
+ for p := path; p != "."; p = filepath.Dir(p) {
+ switch filepath.Base(p) {
+ case "flag_declarations":
+ return filepath.Dir(p), nil
+ case "flag_values":
+ return filepath.Dir(p), nil
+ }
+ }
+ return "", fmt.Errorf("Could not determine directory from %s", path)
+}
+
+func MarshalFlagValue(config *rc_lib.ReleaseConfig, name string) (ret string, err error) {
+ fa, ok := config.FlagArtifacts[name]
+ if !ok {
+ return "", fmt.Errorf("%s not found in %s", name, config.Name)
+ }
+ return rc_lib.MarshalValue(fa.Value), nil
+}
+
+func GetReleaseArgs(configs *rc_lib.ReleaseConfigs, commonFlags Flags) ([]*rc_lib.ReleaseConfig, error) {
+ var all bool
+ relFlags := flag.NewFlagSet("set", flag.ExitOnError)
+ relFlags.BoolVar(&all, "all", false, "Display all flags")
+ relFlags.Parse(commonFlags.targetReleases)
+ var ret []*rc_lib.ReleaseConfig
+ if all {
+ for _, config := range configs.ReleaseConfigs {
+ ret = append(ret, config)
+ }
+ return ret, nil
+ }
+ for _, arg := range relFlags.Args() {
+ config, err := configs.GetReleaseConfig(arg)
+ if err != nil {
+ return nil, err
+ }
+ ret = append(ret, config)
+ }
+ return ret, nil
+}
+
+func GetCommand(configs *rc_lib.ReleaseConfigs, commonFlags Flags, cmd string, args []string) error {
+ isTrace := cmd == "trace"
+ var all bool
+ getFlags := flag.NewFlagSet("set", flag.ExitOnError)
+ getFlags.BoolVar(&all, "all", false, "Display all flags")
+ getFlags.Parse(args)
+ args = getFlags.Args()
+
+ releaseConfigList, err := GetReleaseArgs(configs, commonFlags)
+ if err != nil {
+ return err
+ }
+ if isTrace && len(releaseConfigList) > 1 {
+ return fmt.Errorf("trace command only allows one --release argument. Got: %s", strings.Join(commonFlags.targetReleases, " "))
+ }
+
+ if all {
+ args = []string{}
+ for _, fa := range configs.FlagArtifacts {
+ args = append(args, *fa.FlagDeclaration.Name)
+ }
+ }
+
+ showName := len(releaseConfigList) > 1 || len(args) > 1
+ for _, config := range releaseConfigList {
+ var configName string
+ if len(releaseConfigList) > 1 {
+ configName = fmt.Sprintf("%s.", config.Name)
+ }
+ for _, arg := range args {
+ val, err := MarshalFlagValue(config, arg)
+ if err != nil {
+ return err
+ }
+ if showName {
+ fmt.Printf("%s%s=%s\n", configName, arg, val)
+ } else {
+ fmt.Printf("%s\n", val)
+ }
+ if isTrace {
+ for _, trace := range config.FlagArtifacts[arg].Traces {
+ fmt.Printf(" => \"%s\" in %s\n", rc_lib.MarshalValue(trace.Value), *trace.Source)
+ }
+ }
+ }
+ }
+ return nil
+}
+
+func SetCommand(configs *rc_lib.ReleaseConfigs, commonFlags Flags, cmd string, args []string) error {
+ var valueDir string
+ if len(commonFlags.targetReleases) > 1 {
+ return fmt.Errorf("set command only allows one --release argument. Got: %s", strings.Join(commonFlags.targetReleases, " "))
+ }
+ targetRelease := commonFlags.targetReleases[0]
+
+ setFlags := flag.NewFlagSet("set", flag.ExitOnError)
+ setFlags.StringVar(&valueDir, "dir", "", "Directory in which to place the value")
+ setFlags.Parse(args)
+ setArgs := setFlags.Args()
+ if len(setArgs) != 2 {
+ return fmt.Errorf("set command expected flag and value, got: %s", strings.Join(setArgs, " "))
+ }
+ name := setArgs[0]
+ value := setArgs[1]
+ release, err := configs.GetReleaseConfig(targetRelease)
+ targetRelease = release.Name
+ if err != nil {
+ return err
+ }
+ flagArtifact, ok := release.FlagArtifacts[name]
+ if !ok {
+ return fmt.Errorf("Unknown build flag %s", name)
+ }
+ if valueDir == "" {
+ mapDir, err := GetMapDir(*flagArtifact.Traces[len(flagArtifact.Traces)-1].Source)
+ if err != nil {
+ return err
+ }
+ valueDir = mapDir
+ }
+
+ flagValue := &rc_proto.FlagValue{
+ Name: proto.String(name),
+ Value: rc_lib.UnmarshalValue(value),
+ }
+ flagPath := filepath.Join(valueDir, "flag_values", targetRelease, fmt.Sprintf("%s.textproto", name))
+ return rc_lib.WriteMessage(flagPath, flagValue)
+}
+
+func main() {
+ var err error
+ var commonFlags Flags
+ var configs *rc_lib.ReleaseConfigs
+
+ outEnv := os.Getenv("OUT_DIR")
+ if outEnv == "" {
+ outEnv = "out"
+ }
+ // Handle the common arguments
+ flag.StringVar(&commonFlags.top, "top", ".", "path to top of workspace")
+ flag.BoolVar(&commonFlags.quiet, "quiet", false, "disable warning messages")
+ flag.Var(&commonFlags.maps, "map", "path to a release_config_map.textproto. may be repeated")
+ flag.StringVar(&commonFlags.outDir, "out_dir", rc_lib.GetDefaultOutDir(), "basepath for the output. Multiple formats are created")
+ flag.Var(&commonFlags.targetReleases, "release", "TARGET_RELEASE for this build")
+ flag.Parse()
+
+ if commonFlags.quiet {
+ rc_lib.DisableWarnings()
+ }
+
+ if len(commonFlags.targetReleases) == 0 {
+ commonFlags.targetReleases = rc_lib.StringList{"trunk_staging"}
+ }
+
+ if err = os.Chdir(commonFlags.top); err != nil {
+ panic(err)
+ }
+
+ // Get the current state of flagging.
+ relName := commonFlags.targetReleases[0]
+ if relName == "--all" || relName == "-all" {
+ // If the users said `--release --all`, grab trunk staging for simplicity.
+ relName = "trunk_staging"
+ }
+ configs, err = rc_lib.ReadReleaseConfigMaps(commonFlags.maps, relName)
+ if err != nil {
+ panic(err)
+ }
+
+ if cmd, ok := commandMap[flag.Arg(0)]; ok {
+ args := flag.Args()
+ if err = cmd(configs, commonFlags, args[0], args[1:]); err != nil {
+ panic(err)
+ }
+ }
+}
diff --git a/cmd/release_config/crunch_flags/Android.bp b/cmd/release_config/crunch_flags/Android.bp
new file mode 100644
index 0000000..89c9591
--- /dev/null
+++ b/cmd/release_config/crunch_flags/Android.bp
@@ -0,0 +1,32 @@
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+blueprint_go_binary {
+ name: "crunch-flags",
+ deps: [
+ "golang-protobuf-encoding-prototext",
+ "golang-protobuf-reflect-protoreflect",
+ "golang-protobuf-runtime-protoimpl",
+ "soong-cmd-release_config-lib",
+ "soong-cmd-release_config-proto",
+ ],
+ srcs: [
+ "main.go",
+ ],
+}
+
+bootstrap_go_package {
+ name: "soong-cmd-release_config-crunch_flags",
+ pkgPath: "android/soong/cmd/release_config/crunch_flags",
+ deps: [
+ "golang-protobuf-encoding-prototext",
+ "golang-protobuf-reflect-protoreflect",
+ "golang-protobuf-runtime-protoimpl",
+ "soong-cmd-release_config-lib",
+ "soong-cmd-release_config-proto",
+ ],
+ srcs: [
+ "main.go",
+ ],
+}
diff --git a/cmd/release_config/crunch_flags/main.go b/cmd/release_config/crunch_flags/main.go
new file mode 100644
index 0000000..616674b
--- /dev/null
+++ b/cmd/release_config/crunch_flags/main.go
@@ -0,0 +1,359 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "io/fs"
+ "os"
+ "path/filepath"
+ "regexp"
+ "strings"
+
+ rc_lib "android/soong/cmd/release_config/release_config_lib"
+ rc_proto "android/soong/cmd/release_config/release_config_proto"
+ "google.golang.org/protobuf/encoding/prototext"
+ "google.golang.org/protobuf/proto"
+)
+
+// When a flag declaration has an initial value that is a string, the default workflow is PREBUILT.
+// If the flag name starts with any of prefixes in manualFlagNamePrefixes, it is MANUAL.
+var manualFlagNamePrefixes []string = []string{
+ "RELEASE_ACONFIG_",
+ "RELEASE_PLATFORM_",
+}
+
+var defaultFlagNamespace string = "android_UNKNOWN"
+
+func RenameNext(name string) string {
+ if name == "next" {
+ return "ap3a"
+ }
+ return name
+}
+
+func WriteFile(path string, message proto.Message) error {
+ data, err := prototext.MarshalOptions{Multiline: true}.Marshal(message)
+ if err != nil {
+ return err
+ }
+
+ err = os.MkdirAll(filepath.Dir(path), 0775)
+ if err != nil {
+ return err
+ }
+ return os.WriteFile(path, data, 0644)
+}
+
+func WalkValueFiles(dir string, Func fs.WalkDirFunc) error {
+ valPath := filepath.Join(dir, "build_config")
+ if _, err := os.Stat(valPath); err != nil {
+ fmt.Printf("%s not found, ignoring.\n", valPath)
+ return nil
+ }
+
+ return filepath.WalkDir(valPath, func(path string, d fs.DirEntry, err error) error {
+ if err != nil {
+ return err
+ }
+ if strings.HasSuffix(d.Name(), ".scl") && d.Type().IsRegular() {
+ return Func(path, d, err)
+ }
+ return nil
+ })
+}
+
+func ProcessBuildFlags(dir string, namespaceMap map[string]string) error {
+ var rootAconfigModule string
+
+ path := filepath.Join(dir, "build_flags.scl")
+ if _, err := os.Stat(path); err != nil {
+ fmt.Printf("%s not found, ignoring.\n", path)
+ return nil
+ } else {
+ fmt.Printf("Processing %s\n", path)
+ }
+ commentRegexp, err := regexp.Compile("^[[:space:]]*#(?<comment>.+)")
+ if err != nil {
+ return err
+ }
+ declRegexp, err := regexp.Compile("^[[:space:]]*flag.\"(?<name>[A-Z_0-9]+)\",[[:space:]]*(?<container>[_A-Z]*),[[:space:]]*(?<value>(\"[^\"]*\"|[^\",)]*))")
+ if err != nil {
+ return err
+ }
+ declIn, err := os.ReadFile(path)
+ if err != nil {
+ return err
+ }
+ lines := strings.Split(string(declIn), "\n")
+ var description string
+ for _, line := range lines {
+ if comment := commentRegexp.FindStringSubmatch(commentRegexp.FindString(line)); comment != nil {
+ // Description is the text from any contiguous series of lines before a `flag()` call.
+ description += fmt.Sprintf(" %s", strings.TrimSpace(comment[commentRegexp.SubexpIndex("comment")]))
+ continue
+ }
+ matches := declRegexp.FindStringSubmatch(declRegexp.FindString(line))
+ if matches == nil {
+ // The line is neither a comment nor a `flag()` call.
+ // Discard any description we have gathered and process the next line.
+ description = ""
+ continue
+ }
+ declValue := matches[declRegexp.SubexpIndex("value")]
+ declName := matches[declRegexp.SubexpIndex("name")]
+ container := rc_proto.Container(rc_proto.Container_value[matches[declRegexp.SubexpIndex("container")]])
+ description = strings.TrimSpace(description)
+ var namespace string
+ var ok bool
+ if namespace, ok = namespaceMap[declName]; !ok {
+ namespace = defaultFlagNamespace
+ }
+ flagDeclaration := &rc_proto.FlagDeclaration{
+ Name: proto.String(declName),
+ Namespace: proto.String(namespace),
+ Description: proto.String(description),
+ Container: &container,
+ }
+ description = ""
+ // Most build flags are `workflow: PREBUILT`.
+ workflow := rc_proto.Workflow(rc_proto.Workflow_PREBUILT)
+ switch {
+ case declName == "RELEASE_ACONFIG_VALUE_SETS":
+ rootAconfigModule = declValue[1 : len(declValue)-1]
+ continue
+ case strings.HasPrefix(declValue, "\""):
+ // String values mean that the flag workflow is (most likely) either MANUAL or PREBUILT.
+ declValue = declValue[1 : len(declValue)-1]
+ flagDeclaration.Value = &rc_proto.Value{Val: &rc_proto.Value_StringValue{declValue}}
+ for _, prefix := range manualFlagNamePrefixes {
+ if strings.HasPrefix(declName, prefix) {
+ workflow = rc_proto.Workflow(rc_proto.Workflow_MANUAL)
+ break
+ }
+ }
+ case declValue == "False" || declValue == "True":
+ // Boolean values are LAUNCH flags.
+ flagDeclaration.Value = &rc_proto.Value{Val: &rc_proto.Value_BoolValue{declValue == "True"}}
+ workflow = rc_proto.Workflow(rc_proto.Workflow_LAUNCH)
+ case declValue == "None":
+ // Use PREBUILT workflow with no initial value.
+ default:
+ fmt.Printf("%s: Unexpected value %s=%s\n", path, declName, declValue)
+ }
+ flagDeclaration.Workflow = &workflow
+ if flagDeclaration != nil {
+ declPath := filepath.Join(dir, "flag_declarations", fmt.Sprintf("%s.textproto", declName))
+ err := WriteFile(declPath, flagDeclaration)
+ if err != nil {
+ return err
+ }
+ }
+ }
+ if rootAconfigModule != "" {
+ rootProto := &rc_proto.ReleaseConfig{
+ Name: proto.String("root"),
+ AconfigValueSets: []string{rootAconfigModule},
+ }
+ return WriteFile(filepath.Join(dir, "release_configs", "root.textproto"), rootProto)
+ }
+ return nil
+}
+
+func ProcessBuildConfigs(dir, name string, paths []string, releaseProto *rc_proto.ReleaseConfig) error {
+ valRegexp, err := regexp.Compile("[[:space:]]+value.\"(?<name>[A-Z_0-9]+)\",[[:space:]]*(?<value>[^,)]*)")
+ if err != nil {
+ return err
+ }
+ for _, path := range paths {
+ fmt.Printf("Processing %s\n", path)
+ valIn, err := os.ReadFile(path)
+ if err != nil {
+ fmt.Printf("%s: error: %v\n", path, err)
+ return err
+ }
+ vals := valRegexp.FindAllString(string(valIn), -1)
+ for _, val := range vals {
+ matches := valRegexp.FindStringSubmatch(val)
+ valValue := matches[valRegexp.SubexpIndex("value")]
+ valName := matches[valRegexp.SubexpIndex("name")]
+ flagValue := &rc_proto.FlagValue{
+ Name: proto.String(valName),
+ }
+ switch {
+ case valName == "RELEASE_ACONFIG_VALUE_SETS":
+ flagValue = nil
+ if releaseProto.AconfigValueSets == nil {
+ releaseProto.AconfigValueSets = []string{}
+ }
+ releaseProto.AconfigValueSets = append(releaseProto.AconfigValueSets, valValue[1:len(valValue)-1])
+ case strings.HasPrefix(valValue, "\""):
+ valValue = valValue[1 : len(valValue)-1]
+ flagValue.Value = &rc_proto.Value{Val: &rc_proto.Value_StringValue{valValue}}
+ case valValue == "None":
+ // nothing to do here.
+ case valValue == "True":
+ flagValue.Value = &rc_proto.Value{Val: &rc_proto.Value_BoolValue{true}}
+ case valValue == "False":
+ flagValue.Value = &rc_proto.Value{Val: &rc_proto.Value_BoolValue{false}}
+ default:
+ fmt.Printf("%s: Unexpected value %s=%s\n", path, valName, valValue)
+ }
+ if flagValue != nil {
+ valPath := filepath.Join(dir, "flag_values", RenameNext(name), fmt.Sprintf("%s.textproto", valName))
+ err := WriteFile(valPath, flagValue)
+ if err != nil {
+ return err
+ }
+ }
+ }
+ }
+ return err
+}
+
+func ProcessReleaseConfigMap(dir string, descriptionMap map[string]string) error {
+ path := filepath.Join(dir, "release_config_map.mk")
+ if _, err := os.Stat(path); err != nil {
+ fmt.Printf("%s not found, ignoring.\n", path)
+ return nil
+ } else {
+ fmt.Printf("Processing %s\n", path)
+ }
+ configRegexp, err := regexp.Compile("^..call[[:space:]]+declare-release-config,[[:space:]]+(?<name>[_a-z0-0A-Z]+),[[:space:]]+(?<files>[^,]*)(,[[:space:]]*(?<inherits>.*)|[[:space:]]*)[)]$")
+ if err != nil {
+ return err
+ }
+ aliasRegexp, err := regexp.Compile("^..call[[:space:]]+alias-release-config,[[:space:]]+(?<name>[_a-z0-9A-Z]+),[[:space:]]+(?<target>[_a-z0-9A-Z]+)")
+ if err != nil {
+ return err
+ }
+
+ mapIn, err := os.ReadFile(path)
+ if err != nil {
+ return err
+ }
+ cleanDir := strings.TrimLeft(dir, "../")
+ var defaultContainer rc_proto.Container
+ switch {
+ case strings.HasPrefix(cleanDir, "build/") || cleanDir == "vendor/google_shared/build":
+ defaultContainer = rc_proto.Container(rc_proto.Container_ALL)
+ case cleanDir == "vendor/google/release":
+ defaultContainer = rc_proto.Container(rc_proto.Container_ALL)
+ default:
+ defaultContainer = rc_proto.Container(rc_proto.Container_VENDOR)
+ }
+ releaseConfigMap := &rc_proto.ReleaseConfigMap{DefaultContainer: &defaultContainer}
+ // If we find a description for the directory, include it.
+ if description, ok := descriptionMap[cleanDir]; ok {
+ releaseConfigMap.Description = proto.String(description)
+ }
+ lines := strings.Split(string(mapIn), "\n")
+ for _, line := range lines {
+ alias := aliasRegexp.FindStringSubmatch(aliasRegexp.FindString(line))
+ if alias != nil {
+ fmt.Printf("processing alias %s\n", line)
+ name := alias[aliasRegexp.SubexpIndex("name")]
+ target := alias[aliasRegexp.SubexpIndex("target")]
+ if target == "next" {
+ if RenameNext(target) != name {
+ return fmt.Errorf("Unexpected name for next (%s)", RenameNext(target))
+ }
+ target, name = name, target
+ }
+ releaseConfigMap.Aliases = append(releaseConfigMap.Aliases,
+ &rc_proto.ReleaseAlias{
+ Name: proto.String(name),
+ Target: proto.String(target),
+ })
+ }
+ config := configRegexp.FindStringSubmatch(configRegexp.FindString(line))
+ if config == nil {
+ continue
+ }
+ name := config[configRegexp.SubexpIndex("name")]
+ releaseConfig := &rc_proto.ReleaseConfig{
+ Name: proto.String(RenameNext(name)),
+ }
+ configFiles := config[configRegexp.SubexpIndex("files")]
+ files := strings.Split(strings.ReplaceAll(configFiles, "$(local_dir)", dir+"/"), " ")
+ configInherits := config[configRegexp.SubexpIndex("inherits")]
+ if len(configInherits) > 0 {
+ releaseConfig.Inherits = strings.Split(configInherits, " ")
+ }
+ err := ProcessBuildConfigs(dir, name, files, releaseConfig)
+ if err != nil {
+ return err
+ }
+
+ releasePath := filepath.Join(dir, "release_configs", fmt.Sprintf("%s.textproto", RenameNext(name)))
+ err = WriteFile(releasePath, releaseConfig)
+ if err != nil {
+ return err
+ }
+ }
+ return WriteFile(filepath.Join(dir, "release_config_map.textproto"), releaseConfigMap)
+}
+
+func main() {
+ var err error
+ var top string
+ var dirs rc_lib.StringList
+ var namespacesFile string
+ var descriptionsFile string
+
+ flag.StringVar(&top, "top", ".", "path to top of workspace")
+ flag.Var(&dirs, "dir", "directory to process, relative to the top of the workspace")
+ flag.StringVar(&namespacesFile, "namespaces", "", "location of file with 'flag_name namespace' information")
+ flag.StringVar(&descriptionsFile, "descriptions", "", "location of file with 'directory description' information")
+ flag.Parse()
+
+ if err = os.Chdir(top); err != nil {
+ panic(err)
+ }
+ if len(dirs) == 0 {
+ dirs = rc_lib.StringList{"build/release", "vendor/google_shared/build/release", "vendor/google/release"}
+ }
+
+ namespaceMap := make(map[string]string)
+ if namespacesFile != "" {
+ data, err := os.ReadFile(namespacesFile)
+ if err != nil {
+ panic(err)
+ }
+ for idx, line := range strings.Split(string(data), "\n") {
+ fields := strings.Split(line, " ")
+ if len(fields) > 2 {
+ panic(fmt.Errorf("line %d: too many fields: %s", idx, line))
+ }
+ namespaceMap[fields[0]] = fields[1]
+ }
+
+ }
+
+ descriptionMap := make(map[string]string)
+ descriptionMap["build/release"] = "Published open-source flags and declarations"
+ if descriptionsFile != "" {
+ data, err := os.ReadFile(descriptionsFile)
+ if err != nil {
+ panic(err)
+ }
+ for _, line := range strings.Split(string(data), "\n") {
+ if strings.TrimSpace(line) != "" {
+ fields := strings.SplitN(line, " ", 2)
+ descriptionMap[fields[0]] = fields[1]
+ }
+ }
+
+ }
+
+ for _, dir := range dirs {
+ err = ProcessBuildFlags(dir, namespaceMap)
+ if err != nil {
+ panic(err)
+ }
+
+ err = ProcessReleaseConfigMap(dir, descriptionMap)
+ if err != nil {
+ panic(err)
+ }
+ }
+}
diff --git a/cmd/release_config/release_config/main.go b/cmd/release_config/release_config/main.go
index 076abfa..a43fdcc 100644
--- a/cmd/release_config/release_config/main.go
+++ b/cmd/release_config/release_config/main.go
@@ -16,25 +16,44 @@
import (
"flag"
+ "fmt"
"os"
+ "path/filepath"
rc_lib "android/soong/cmd/release_config/release_config_lib"
)
func main() {
var top string
+ var quiet bool
var releaseConfigMapPaths rc_lib.StringList
var targetRelease string
var outputDir string
var err error
var configs *rc_lib.ReleaseConfigs
+ var json, pb, textproto bool
+ var product string
+
+ defaultRelease := os.Getenv("TARGET_RELEASE")
+ if defaultRelease == "" {
+ defaultRelease = "trunk_staging"
+ }
flag.StringVar(&top, "top", ".", "path to top of workspace")
+ flag.StringVar(&product, "product", os.Getenv("TARGET_PRODUCT"), "TARGET_PRODUCT for the build")
+ flag.BoolVar(&quiet, "quiet", false, "disable warning messages")
flag.Var(&releaseConfigMapPaths, "map", "path to a release_config_map.textproto. may be repeated")
- flag.StringVar(&targetRelease, "release", "trunk_staging", "TARGET_RELEASE for this build")
+ flag.StringVar(&targetRelease, "release", defaultRelease, "TARGET_RELEASE for this build")
flag.StringVar(&outputDir, "out_dir", rc_lib.GetDefaultOutDir(), "basepath for the output. Multiple formats are created")
+ flag.BoolVar(&textproto, "textproto", true, "write artifacts as text protobuf")
+ flag.BoolVar(&json, "json", true, "write artifacts as json")
+ flag.BoolVar(&pb, "pb", true, "write artifacts as binary protobuf")
flag.Parse()
+ if quiet {
+ rc_lib.DisableWarnings()
+ }
+
if err = os.Chdir(top); err != nil {
panic(err)
}
@@ -42,16 +61,36 @@
if err != nil {
panic(err)
}
+ config, err := configs.GetReleaseConfig(targetRelease)
+ if err != nil {
+ panic(err)
+ }
+ releaseName := config.Name
err = os.MkdirAll(outputDir, 0775)
if err != nil {
panic(err)
}
- err = configs.DumpMakefile(outputDir, targetRelease)
+ makefilePath := filepath.Join(outputDir, fmt.Sprintf("release_config-%s-%s.mk", product, releaseName))
+ err = configs.WriteMakefile(makefilePath, targetRelease)
if err != nil {
panic(err)
}
- err = configs.DumpArtifact(outputDir)
- if err != nil {
- panic(err)
+ if json {
+ err = configs.WriteArtifact(outputDir, product, "json")
+ if err != nil {
+ panic(err)
+ }
+ }
+ if pb {
+ err = configs.WriteArtifact(outputDir, product, "pb")
+ if err != nil {
+ panic(err)
+ }
+ }
+ if textproto {
+ err = configs.WriteArtifact(outputDir, product, "textproto")
+ if err != nil {
+ panic(err)
+ }
}
}
diff --git a/cmd/release_config/release_config_lib/Android.bp b/cmd/release_config/release_config_lib/Android.bp
index 601194c..0c67e11 100644
--- a/cmd/release_config/release_config_lib/Android.bp
+++ b/cmd/release_config/release_config_lib/Android.bp
@@ -18,7 +18,7 @@
bootstrap_go_package {
name: "soong-cmd-release_config-lib",
- pkgPath: "android/soong/release_config/release_config_lib",
+ pkgPath: "android/soong/cmd/release_config/release_config_lib",
deps: [
"golang-protobuf-encoding-prototext",
"golang-protobuf-reflect-protoreflect",
diff --git a/cmd/release_config/release_config_lib/flag_artifact.go b/cmd/release_config/release_config_lib/flag_artifact.go
index 51673a5..4446655 100644
--- a/cmd/release_config/release_config_lib/flag_artifact.go
+++ b/cmd/release_config/release_config_lib/flag_artifact.go
@@ -17,29 +17,37 @@
import (
"fmt"
- "android/soong/cmd/release_config/release_config_proto"
+ rc_proto "android/soong/cmd/release_config/release_config_proto"
"google.golang.org/protobuf/proto"
)
+// A flag artifact, with its final value and declaration/override history.
type FlagArtifact struct {
- FlagDeclaration *release_config_proto.FlagDeclaration
+ // The flag_declaration message.
+ FlagDeclaration *rc_proto.FlagDeclaration
// The index of the config directory where this flag was declared.
// Flag values cannot be set in a location with a lower index.
DeclarationIndex int
- Traces []*release_config_proto.Tracepoint
+ // A history of value assignments and overrides.
+ Traces []*rc_proto.Tracepoint
- // Assigned value
- Value *release_config_proto.Value
+ // The value of the flag.
+ Value *rc_proto.Value
}
// Key is flag name.
type FlagArtifacts map[string]*FlagArtifact
+// Create a clone of the flag artifact.
+//
+// Returns:
+//
+// *FlagArtifact: the copy of the artifact.
func (src *FlagArtifact) Clone() *FlagArtifact {
- value := &release_config_proto.Value{}
+ value := &rc_proto.Value{}
proto.Merge(value, src.Value)
return &FlagArtifact{
FlagDeclaration: src.FlagDeclaration,
@@ -48,6 +56,11 @@
}
}
+// Clone FlagArtifacts.
+//
+// Returns:
+//
+// FlagArtifacts: a copy of the source FlagArtifacts.
func (src FlagArtifacts) Clone() (dst FlagArtifacts) {
if dst == nil {
dst = make(FlagArtifacts)
@@ -58,30 +71,47 @@
return
}
+// Update the value of a flag.
+//
+// This appends to flagArtifact.Traces, and updates flagArtifact.Value.
+//
+// Args:
+//
+// flagValue FlagValue: the value to assign
+//
+// Returns:
+//
+// error: any error encountered
func (fa *FlagArtifact) UpdateValue(flagValue FlagValue) error {
name := *flagValue.proto.Name
- fa.Traces = append(fa.Traces, &release_config_proto.Tracepoint{Source: proto.String(flagValue.path), Value: flagValue.proto.Value})
+ fa.Traces = append(fa.Traces, &rc_proto.Tracepoint{Source: proto.String(flagValue.path), Value: flagValue.proto.Value})
if fa.Value.GetObsolete() {
return fmt.Errorf("Attempting to set obsolete flag %s. Trace=%v", name, fa.Traces)
}
+ var newValue *rc_proto.Value
switch val := flagValue.proto.Value.Val.(type) {
- case *release_config_proto.Value_StringValue:
- fa.Value = &release_config_proto.Value{Val: &release_config_proto.Value_StringValue{val.StringValue}}
- case *release_config_proto.Value_BoolValue:
- fa.Value = &release_config_proto.Value{Val: &release_config_proto.Value_BoolValue{val.BoolValue}}
- case *release_config_proto.Value_Obsolete:
+ case *rc_proto.Value_StringValue:
+ newValue = &rc_proto.Value{Val: &rc_proto.Value_StringValue{val.StringValue}}
+ case *rc_proto.Value_BoolValue:
+ newValue = &rc_proto.Value{Val: &rc_proto.Value_BoolValue{val.BoolValue}}
+ case *rc_proto.Value_Obsolete:
if !val.Obsolete {
return fmt.Errorf("%s: Cannot set obsolete=false. Trace=%v", name, fa.Traces)
}
- fa.Value = &release_config_proto.Value{Val: &release_config_proto.Value_Obsolete{true}}
+ newValue = &rc_proto.Value{Val: &rc_proto.Value_Obsolete{true}}
default:
return fmt.Errorf("Invalid type for flag_value: %T. Trace=%v", val, fa.Traces)
}
+ if proto.Equal(newValue, fa.Value) {
+ warnf("%s: redundant override (set in %s)\n", flagValue.path, *fa.Traces[len(fa.Traces)-2].Source)
+ }
+ fa.Value = newValue
return nil
}
-func (fa *FlagArtifact) Marshal() (*release_config_proto.FlagArtifact, error) {
- return &release_config_proto.FlagArtifact{
+// Marshal the FlagArtifact into a flag_artifact message.
+func (fa *FlagArtifact) Marshal() (*rc_proto.FlagArtifact, error) {
+ return &rc_proto.FlagArtifact{
FlagDeclaration: fa.FlagDeclaration,
Value: fa.Value,
Traces: fa.Traces,
diff --git a/cmd/release_config/release_config_lib/flag_declaration.go b/cmd/release_config/release_config_lib/flag_declaration.go
index d5cc418..97d4d4c 100644
--- a/cmd/release_config/release_config_lib/flag_declaration.go
+++ b/cmd/release_config/release_config_lib/flag_declaration.go
@@ -15,13 +15,13 @@
package release_config_lib
import (
- "android/soong/cmd/release_config/release_config_proto"
+ rc_proto "android/soong/cmd/release_config/release_config_proto"
)
-func FlagDeclarationFactory(protoPath string) (fd *release_config_proto.FlagDeclaration) {
- fd = &release_config_proto.FlagDeclaration{}
+func FlagDeclarationFactory(protoPath string) (fd *rc_proto.FlagDeclaration) {
+ fd = &rc_proto.FlagDeclaration{}
if protoPath != "" {
- LoadTextproto(protoPath, fd)
+ LoadMessage(protoPath, fd)
}
return fd
}
diff --git a/cmd/release_config/release_config_lib/flag_value.go b/cmd/release_config/release_config_lib/flag_value.go
index 138e8f8..e155e77 100644
--- a/cmd/release_config/release_config_lib/flag_value.go
+++ b/cmd/release_config/release_config_lib/flag_value.go
@@ -15,7 +15,9 @@
package release_config_lib
import (
- "android/soong/cmd/release_config/release_config_proto"
+ "strings"
+
+ rc_proto "android/soong/cmd/release_config/release_config_proto"
)
type FlagValue struct {
@@ -23,31 +25,46 @@
path string
// Protobuf
- proto release_config_proto.FlagValue
+ proto rc_proto.FlagValue
}
func FlagValueFactory(protoPath string) (fv *FlagValue) {
fv = &FlagValue{path: protoPath}
if protoPath != "" {
- LoadTextproto(protoPath, &fv.proto)
+ LoadMessage(protoPath, &fv.proto)
}
return fv
}
-func MarshalValue(value *release_config_proto.Value) string {
+func UnmarshalValue(str string) *rc_proto.Value {
+ ret := &rc_proto.Value{}
+ switch v := strings.ToLower(str); v {
+ case "true":
+ ret = &rc_proto.Value{Val: &rc_proto.Value_BoolValue{true}}
+ case "false":
+ ret = &rc_proto.Value{Val: &rc_proto.Value_BoolValue{false}}
+ case "##obsolete":
+ ret = &rc_proto.Value{Val: &rc_proto.Value_Obsolete{true}}
+ default:
+ ret = &rc_proto.Value{Val: &rc_proto.Value_StringValue{str}}
+ }
+ return ret
+}
+
+func MarshalValue(value *rc_proto.Value) string {
switch val := value.Val.(type) {
- case *release_config_proto.Value_UnspecifiedValue:
+ case *rc_proto.Value_UnspecifiedValue:
// Value was never set.
return ""
- case *release_config_proto.Value_StringValue:
+ case *rc_proto.Value_StringValue:
return val.StringValue
- case *release_config_proto.Value_BoolValue:
+ case *rc_proto.Value_BoolValue:
if val.BoolValue {
return "true"
}
// False ==> empty string
return ""
- case *release_config_proto.Value_Obsolete:
+ case *rc_proto.Value_Obsolete:
return " #OBSOLETE"
default:
// Flagged as error elsewhere, so return empty string here.
diff --git a/cmd/release_config/release_config_lib/release_config.go b/cmd/release_config/release_config_lib/release_config.go
index 3110dae..c67cee5 100644
--- a/cmd/release_config/release_config_lib/release_config.go
+++ b/cmd/release_config/release_config_lib/release_config.go
@@ -16,8 +16,9 @@
import (
"fmt"
+ "strings"
- "android/soong/cmd/release_config/release_config_proto"
+ rc_proto "android/soong/cmd/release_config/release_config_proto"
"google.golang.org/protobuf/proto"
)
@@ -33,7 +34,7 @@
DeclarationIndex int
// Protobufs relevant to the config.
- proto release_config_proto.ReleaseConfig
+ proto rc_proto.ReleaseConfig
FlagValues []*FlagValue
}
@@ -61,7 +62,7 @@
FlagArtifacts FlagArtifacts
// Generated release config
- ReleaseConfigArtifact *release_config_proto.ReleaseConfigArtifact
+ ReleaseConfigArtifact *rc_proto.ReleaseConfigArtifact
// We have begun compiling this release config.
compileInProgress bool
@@ -79,12 +80,18 @@
return fmt.Errorf("Loop detected for release config %s", config.Name)
}
config.compileInProgress = true
+ isRoot := config.Name == "root"
// Generate any configs we need to inherit. This will detect loops in
// the config.
contributionsToApply := []*ReleaseConfigContribution{}
myInherits := []string{}
myInheritsSet := make(map[string]bool)
+ // If there is a "root" release config, it is the start of every inheritance chain.
+ _, err := configs.GetReleaseConfig("root")
+ if err == nil && !isRoot {
+ config.InheritNames = append([]string{"root"}, config.InheritNames...)
+ }
for _, inherit := range config.InheritNames {
if _, ok := myInheritsSet[inherit]; ok {
continue
@@ -101,10 +108,46 @@
contributionsToApply = append(contributionsToApply, config.Contributions...)
myAconfigValueSets := []string{}
+ myAconfigValueSetsMap := map[string]bool{}
myFlags := configs.FlagArtifacts.Clone()
+ workflowManual := rc_proto.Workflow(rc_proto.Workflow_MANUAL)
+ container := rc_proto.Container(rc_proto.Container_ALL)
+ releaseAconfigValueSets := FlagArtifact{
+ FlagDeclaration: &rc_proto.FlagDeclaration{
+ Name: proto.String("RELEASE_ACONFIG_VALUE_SETS"),
+ Namespace: proto.String("android_UNKNOWN"),
+ Description: proto.String("Aconfig value sets assembled by release-config"),
+ Workflow: &workflowManual,
+ Container: &container,
+ Value: &rc_proto.Value{Val: &rc_proto.Value_StringValue{""}},
+ },
+ DeclarationIndex: -1,
+ Traces: []*rc_proto.Tracepoint{
+ &rc_proto.Tracepoint{
+ Source: proto.String("$release-config"),
+ Value: &rc_proto.Value{Val: &rc_proto.Value_StringValue{""}},
+ },
+ },
+ }
+ myFlags["RELEASE_ACONFIG_VALUE_SETS"] = &releaseAconfigValueSets
myDirsMap := make(map[int]bool)
for _, contrib := range contributionsToApply {
- myAconfigValueSets = append(myAconfigValueSets, contrib.proto.AconfigValueSets...)
+ if len(contrib.proto.AconfigValueSets) > 0 {
+ contribAconfigValueSets := []string{}
+ for _, v := range contrib.proto.AconfigValueSets {
+ if _, ok := myAconfigValueSetsMap[v]; !ok {
+ contribAconfigValueSets = append(contribAconfigValueSets, v)
+ myAconfigValueSetsMap[v] = true
+ }
+ }
+ myAconfigValueSets = append(myAconfigValueSets, contribAconfigValueSets...)
+ releaseAconfigValueSets.Traces = append(
+ releaseAconfigValueSets.Traces,
+ &rc_proto.Tracepoint{
+ Source: proto.String(contrib.path),
+ Value: &rc_proto.Value{Val: &rc_proto.Value_StringValue{strings.Join(contribAconfigValueSets, " ")}},
+ })
+ }
myDirsMap[contrib.DeclarationIndex] = true
for _, value := range contrib.FlagValues {
fa, ok := myFlags[*value.proto.Name]
@@ -116,27 +159,32 @@
// Setting location is to the left of declaration.
return fmt.Errorf("Setting value for flag %s not allowed in %s\n", *value.proto.Name, value.path)
}
+ if isRoot && *fa.FlagDeclaration.Workflow != workflowManual {
+ // The "root" release config can only contain workflow: MANUAL flags.
+ return fmt.Errorf("Setting value for non-MANUAL flag %s is not allowed in %s", *value.proto.Name, value.path)
+ }
if err := fa.UpdateValue(*value); err != nil {
return err
}
}
}
+ releaseAconfigValueSets.Value = &rc_proto.Value{Val: &rc_proto.Value_StringValue{strings.Join(myAconfigValueSets, " ")}}
directories := []string{}
- for idx, confDir := range configs.ConfigDirs {
+ for idx, confDir := range configs.configDirs {
if _, ok := myDirsMap[idx]; ok {
directories = append(directories, confDir)
}
}
config.FlagArtifacts = myFlags
- config.ReleaseConfigArtifact = &release_config_proto.ReleaseConfigArtifact{
+ config.ReleaseConfigArtifact = &rc_proto.ReleaseConfigArtifact{
Name: proto.String(config.Name),
OtherNames: config.OtherNames,
- FlagArtifacts: func() []*release_config_proto.FlagArtifact {
- ret := []*release_config_proto.FlagArtifact{}
+ FlagArtifacts: func() []*rc_proto.FlagArtifact {
+ ret := []*rc_proto.FlagArtifact{}
for _, flag := range myFlags {
- ret = append(ret, &release_config_proto.FlagArtifact{
+ ret = append(ret, &rc_proto.FlagArtifact{
FlagDeclaration: flag.FlagDeclaration,
Traces: flag.Traces,
Value: flag.Value,
diff --git a/cmd/release_config/release_config_lib/release_configs.go b/cmd/release_config/release_config_lib/release_configs.go
index 74fdc00..6efdb2f 100644
--- a/cmd/release_config/release_config_lib/release_configs.go
+++ b/cmd/release_config/release_config_lib/release_configs.go
@@ -16,7 +16,6 @@
import (
"cmp"
- "encoding/json"
"fmt"
"io/fs"
"os"
@@ -24,9 +23,8 @@
"slices"
"strings"
- "android/soong/cmd/release_config/release_config_proto"
+ rc_proto "android/soong/cmd/release_config/release_config_proto"
- "google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
)
@@ -37,10 +35,13 @@
path string
// Data received
- proto release_config_proto.ReleaseConfigMap
+ proto rc_proto.ReleaseConfigMap
+ // Map of name:contribution for release config contributions.
ReleaseConfigContributions map[string]*ReleaseConfigContribution
- FlagDeclarations []release_config_proto.FlagDeclaration
+
+ // Flags declared this directory's flag_declarations/*.textproto
+ FlagDeclarations []rc_proto.FlagDeclaration
}
type ReleaseConfigDirMap map[string]int
@@ -56,50 +57,51 @@
// Dictionary of flag_name:FlagDeclaration, with no overrides applied.
FlagArtifacts FlagArtifacts
+ // Generated release configs artifact
+ Artifact rc_proto.ReleaseConfigsArtifact
+
// Dictionary of name:ReleaseConfig
+ // Use `GetReleaseConfigs(name)` to get a release config.
ReleaseConfigs map[string]*ReleaseConfig
- // Generated release configs
- Artifact release_config_proto.ReleaseConfigsArtifact
+ // Map of directory to *ReleaseConfigMap
+ releaseConfigMapsMap map[string]*ReleaseConfigMap
// The list of config directories used.
- ConfigDirs []string
+ configDirs []string
// A map from the config directory to its order in the list of config
// directories.
- ConfigDirIndexes ReleaseConfigDirMap
+ configDirIndexes ReleaseConfigDirMap
}
-func (configs *ReleaseConfigs) DumpArtifact(outDir string) error {
- message := &configs.Artifact
- basePath := filepath.Join(outDir, "all_release_configs")
- writer := func(suffix string, marshal func() ([]byte, error)) error {
- data, err := marshal()
- if err != nil {
- return err
- }
- return os.WriteFile(fmt.Sprintf("%s.%s", basePath, suffix), data, 0644)
- }
- err := writer("textproto", func() ([]byte, error) { return prototext.MarshalOptions{Multiline: true}.Marshal(message) })
- if err != nil {
- return err
- }
-
- err = writer("pb", func() ([]byte, error) { return proto.Marshal(message) })
- if err != nil {
- return err
- }
-
- return writer("json", func() ([]byte, error) { return json.MarshalIndent(message, "", " ") })
+// Write the "all_release_configs" artifact.
+//
+// The file will be in "{outDir}/all_release_configs-{product}.{format}"
+//
+// Args:
+//
+// outDir string: directory path. Will be created if not present.
+// product string: TARGET_PRODUCT for the release_configs.
+// format string: one of "json", "pb", or "textproto"
+//
+// Returns:
+//
+// error: Any error encountered.
+func (configs *ReleaseConfigs) WriteArtifact(outDir, product, format string) error {
+ return WriteMessage(
+ filepath.Join(outDir, fmt.Sprintf("all_release_configs-%s.%s", product, format)),
+ &configs.Artifact)
}
func ReleaseConfigsFactory() (c *ReleaseConfigs) {
return &ReleaseConfigs{
- Aliases: make(map[string]*string),
- FlagArtifacts: make(map[string]*FlagArtifact),
- ReleaseConfigs: make(map[string]*ReleaseConfig),
- ConfigDirs: []string{},
- ConfigDirIndexes: make(ReleaseConfigDirMap),
+ Aliases: make(map[string]*string),
+ FlagArtifacts: make(map[string]*FlagArtifact),
+ ReleaseConfigs: make(map[string]*ReleaseConfig),
+ releaseConfigMapsMap: make(map[string]*ReleaseConfigMap),
+ configDirs: []string{},
+ configDirIndexes: make(ReleaseConfigDirMap),
}
}
@@ -109,7 +111,7 @@
ReleaseConfigContributions: make(map[string]*ReleaseConfigContribution),
}
if protoPath != "" {
- LoadTextproto(protoPath, &m.proto)
+ LoadMessage(protoPath, &m.proto)
}
return m
}
@@ -145,7 +147,7 @@
}
// If the input didn't specify a value, create one (== UnspecifiedValue).
if flagDeclaration.Value == nil {
- flagDeclaration.Value = &release_config_proto.Value{Val: &release_config_proto.Value_UnspecifiedValue{false}}
+ flagDeclaration.Value = &rc_proto.Value{Val: &rc_proto.Value_UnspecifiedValue{false}}
}
m.FlagDeclarations = append(m.FlagDeclarations, *flagDeclaration)
name := *flagDeclaration.Name
@@ -156,7 +158,7 @@
}
// Set the initial value in the flag artifact.
configs.FlagArtifacts[name].UpdateValue(
- FlagValue{path: path, proto: release_config_proto.FlagValue{
+ FlagValue{path: path, proto: rc_proto.FlagValue{
Name: proto.String(name), Value: flagDeclaration.Value}})
return nil
})
@@ -166,7 +168,7 @@
err = WalkTextprotoFiles(dir, "release_configs", func(path string, d fs.DirEntry, err error) error {
releaseConfigContribution := &ReleaseConfigContribution{path: path, DeclarationIndex: ConfigDirIndex}
- LoadTextproto(path, &releaseConfigContribution.proto)
+ LoadMessage(path, &releaseConfigContribution.proto)
name := *releaseConfigContribution.proto.Name
if fmt.Sprintf("%s.textproto", name) != filepath.Base(path) {
return fmt.Errorf("%s incorrectly declares release config %s", path, name)
@@ -197,6 +199,7 @@
return err
}
configs.ReleaseConfigMaps = append(configs.ReleaseConfigMaps, m)
+ configs.releaseConfigMapsMap[dir] = m
return nil
}
@@ -212,16 +215,23 @@
return nil, fmt.Errorf("Missing config %s. Trace=%v", name, trace)
}
-func (configs *ReleaseConfigs) DumpMakefile(outDir, targetRelease string) error {
- outFile := filepath.Join(outDir, "release_config.mk")
+// Write the makefile for this targetRelease.
+func (configs *ReleaseConfigs) WriteMakefile(outFile, targetRelease string) error {
makeVars := make(map[string]string)
+ var allReleaseNames []string
+ for _, v := range configs.ReleaseConfigs {
+ allReleaseNames = append(allReleaseNames, v.Name)
+ allReleaseNames = append(allReleaseNames, v.OtherNames...)
+ }
config, err := configs.GetReleaseConfig(targetRelease)
if err != nil {
return err
}
+
+ myFlagArtifacts := config.FlagArtifacts.Clone()
// Sort the flags by name first.
names := []string{}
- for k, _ := range config.FlagArtifacts {
+ for k, _ := range myFlagArtifacts {
names = append(names, k)
}
slices.SortFunc(names, func(a, b string) int {
@@ -237,12 +247,12 @@
}
for _, name := range names {
- flag := config.FlagArtifacts[name]
+ flag := myFlagArtifacts[name]
decl := flag.FlagDeclaration
- // cName := strings.ToLower(release_config_proto.Container_name[decl.GetContainer()])
+ // cName := strings.ToLower(rc_proto.Container_name[decl.GetContainer()])
cName := strings.ToLower(decl.Container.String())
- if cName == strings.ToLower(release_config_proto.Container_ALL.String()) {
+ if cName == strings.ToLower(rc_proto.Container_ALL.String()) {
partitions["product"] = append(partitions["product"], name)
partitions["system"] = append(partitions["system"], name)
partitions["system_ext"] = append(partitions["system_ext"], name)
@@ -277,7 +287,13 @@
// _ALL_RELEASE_FLAGS.PARTITIONS.*
// all _ALL_RELEASE_FLAGS.*, sorted by name
// Final flag values, sorted by name.
- data := fmt.Sprintf("_ALL_RELEASE_FLAGS :=$= %s\n", strings.Join(names, " "))
+ data := fmt.Sprintf("# TARGET_RELEASE=%s\n", config.Name)
+ if targetRelease != config.Name {
+ data += fmt.Sprintf("# User specified TARGET_RELEASE=%s\n", targetRelease)
+ }
+ // The variable _all_release_configs will get deleted during processing, so do not mark it read-only.
+ data += fmt.Sprintf("_all_release_configs := %s\n", strings.Join(allReleaseNames, " "))
+ data += fmt.Sprintf("_ALL_RELEASE_FLAGS :=$= %s\n", strings.Join(names, " "))
for _, pName := range pNames {
data += fmt.Sprintf("_ALL_RELEASE_FLAGS.PARTITIONS.%s :=$= %s\n", pName, strings.Join(partitions[pName], " "))
}
@@ -285,8 +301,6 @@
data += fmt.Sprintf("%s :=$= %s\n", vName, makeVars[vName])
}
data += "\n\n# Values for all build flags\n"
- data += fmt.Sprintf("RELEASE_ACONFIG_VALUE_SETS :=$= %s\n",
- strings.Join(config.ReleaseConfigArtifact.AconfigValueSets, " "))
for _, name := range names {
data += fmt.Sprintf("%s :=$= %s\n", name, makeVars[name])
}
@@ -321,10 +335,10 @@
if err != nil {
return err
}
- configs.Artifact = release_config_proto.ReleaseConfigsArtifact{
+ configs.Artifact = rc_proto.ReleaseConfigsArtifact{
ReleaseConfig: releaseConfig.ReleaseConfigArtifact,
- OtherReleaseConfigs: func() []*release_config_proto.ReleaseConfigArtifact {
- orc := []*release_config_proto.ReleaseConfigArtifact{}
+ OtherReleaseConfigs: func() []*rc_proto.ReleaseConfigArtifact {
+ orc := []*rc_proto.ReleaseConfigArtifact{}
for name, config := range configs.ReleaseConfigs {
if name != releaseConfig.Name {
orc = append(orc, config.ReleaseConfigArtifact)
@@ -332,6 +346,13 @@
}
return orc
}(),
+ ReleaseConfigMapsMap: func() map[string]*rc_proto.ReleaseConfigMap {
+ ret := make(map[string]*rc_proto.ReleaseConfigMap)
+ for k, v := range configs.releaseConfigMapsMap {
+ ret[k] = &v.proto
+ }
+ return ret
+ }(),
}
return nil
}
@@ -351,8 +372,8 @@
for idx, releaseConfigMapPath := range releaseConfigMapPaths {
// Maintain an ordered list of release config directories.
configDir := filepath.Dir(releaseConfigMapPath)
- configs.ConfigDirIndexes[configDir] = idx
- configs.ConfigDirs = append(configs.ConfigDirs, configDir)
+ configs.configDirIndexes[configDir] = idx
+ configs.configDirs = append(configs.configDirs, configDir)
err = configs.LoadReleaseConfigMap(releaseConfigMapPath, idx)
if err != nil {
return nil, err
diff --git a/cmd/release_config/release_config_lib/util.go b/cmd/release_config/release_config_lib/util.go
index c59deb3..86940da 100644
--- a/cmd/release_config/release_config_lib/util.go
+++ b/cmd/release_config/release_config_lib/util.go
@@ -15,6 +15,7 @@
package release_config_lib
import (
+ "encoding/json"
"fmt"
"io/fs"
"os"
@@ -25,6 +26,8 @@
"google.golang.org/protobuf/proto"
)
+var disableWarnings bool
+
type StringList []string
func (l *StringList) Set(v string) error {
@@ -36,15 +39,66 @@
return fmt.Sprintf("%v", *l)
}
-func LoadTextproto(path string, message proto.Message) error {
+// Write a marshalled message to a file.
+//
+// Marshal the message based on the extension of the path we are writing it to.
+//
+// Args:
+//
+// path string: the path of the file to write to. Directories are not created.
+// Supported extensions are: ".json", ".pb", and ".textproto".
+// message proto.Message: the message to write.
+//
+// Returns:
+//
+// error: any error encountered.
+func WriteMessage(path string, message proto.Message) (err error) {
+ var data []byte
+ switch filepath.Ext(path) {
+ case ".json":
+ data, err = json.MarshalIndent(message, "", " ")
+ case ".pb":
+ data, err = proto.Marshal(message)
+ case ".textproto":
+ data, err = prototext.MarshalOptions{Multiline: true}.Marshal(message)
+ default:
+ return fmt.Errorf("Unknown message format for %s", path)
+ }
+ if err != nil {
+ return err
+ }
+ return os.WriteFile(path, data, 0644)
+}
+
+// Read a message from a file.
+//
+// The message is unmarshalled based on the extension of the file read.
+//
+// Args:
+//
+// path string: the path of the file to read.
+// message proto.Message: the message to unmarshal the message into.
+//
+// Returns:
+//
+// error: any error encountered.
+func LoadMessage(path string, message proto.Message) error {
data, err := os.ReadFile(path)
if err != nil {
return err
}
- ret := prototext.Unmarshal(data, message)
- return ret
+ switch filepath.Ext(path) {
+ case ".json":
+ return json.Unmarshal(data, message)
+ case ".pb":
+ return proto.Unmarshal(data, message)
+ case ".textproto":
+ return prototext.Unmarshal(data, message)
+ }
+ return fmt.Errorf("Unknown message format for %s", path)
}
+// Call Func for any textproto files found in {root}/{subdir}.
func WalkTextprotoFiles(root string, subdir string, Func fs.WalkDirFunc) error {
path := filepath.Join(root, subdir)
if _, err := os.Stat(path); err != nil {
@@ -62,6 +116,19 @@
})
}
+// Turn off all warning output
+func DisableWarnings() {
+ disableWarnings = true
+}
+
+func warnf(format string, args ...any) (n int, err error) {
+ if !disableWarnings {
+ return fmt.Printf(format, args...)
+ }
+ return 0, nil
+}
+
+// Returns the default value for release config artifacts.
func GetDefaultOutDir() string {
outEnv := os.Getenv("OUT_DIR")
if outEnv == "" {
@@ -70,6 +137,7 @@
return filepath.Join(outEnv, "soong", "release-config")
}
+// Return the default list of map files to use.
func GetDefaultMapPaths() StringList {
var defaultMapPaths StringList
defaultLocations := StringList{
diff --git a/cmd/release_config/release_config_proto/Android.bp b/cmd/release_config/release_config_proto/Android.bp
index 5a6aeab..8c47f2a 100644
--- a/cmd/release_config/release_config_proto/Android.bp
+++ b/cmd/release_config/release_config_proto/Android.bp
@@ -18,7 +18,7 @@
bootstrap_go_package {
name: "soong-cmd-release_config-proto",
- pkgPath: "android/soong/release_config/release_config_proto",
+ pkgPath: "android/soong/cmd/release_config/release_config_proto",
deps: [
"golang-protobuf-reflect-protoreflect",
"golang-protobuf-runtime-protoimpl",
diff --git a/cmd/release_config/release_config_proto/build_flags_out.pb.go b/cmd/release_config/release_config_proto/build_flags_out.pb.go
index adc1ea4..0372d63 100644
--- a/cmd/release_config/release_config_proto/build_flags_out.pb.go
+++ b/cmd/release_config/release_config_proto/build_flags_out.pb.go
@@ -259,6 +259,8 @@
ReleaseConfig *ReleaseConfigArtifact `protobuf:"bytes,1,opt,name=release_config,json=releaseConfig" json:"release_config,omitempty"`
// All other release configs defined for this TARGET_PRODUCT.
OtherReleaseConfigs []*ReleaseConfigArtifact `protobuf:"bytes,2,rep,name=other_release_configs,json=otherReleaseConfigs" json:"other_release_configs,omitempty"`
+ // Map of release_config_artifact.directories to release_config_map message.
+ ReleaseConfigMapsMap map[string]*ReleaseConfigMap `protobuf:"bytes,3,rep,name=release_config_maps_map,json=releaseConfigMapsMap" json:"release_config_maps_map,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
}
func (x *ReleaseConfigsArtifact) Reset() {
@@ -307,6 +309,13 @@
return nil
}
+func (x *ReleaseConfigsArtifact) GetReleaseConfigMapsMap() map[string]*ReleaseConfigMap {
+ if x != nil {
+ return x.ReleaseConfigMapsMap
+ }
+ return nil
+}
+
var File_build_flags_out_proto protoreflect.FileDescriptor
var file_build_flags_out_proto_rawDesc = []byte{
@@ -352,7 +361,7 @@
0x69, 0x6e, 0x68, 0x65, 0x72, 0x69, 0x74, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08,
0x69, 0x6e, 0x68, 0x65, 0x72, 0x69, 0x74, 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x69, 0x72, 0x65,
0x63, 0x74, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x64,
- 0x69, 0x72, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x22, 0xe3, 0x01, 0x0a, 0x18, 0x72,
+ 0x69, 0x72, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x22, 0xe8, 0x03, 0x0a, 0x18, 0x72,
0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x73, 0x5f, 0x61,
0x72, 0x74, 0x69, 0x66, 0x61, 0x63, 0x74, 0x12, 0x5c, 0x0a, 0x0e, 0x72, 0x65, 0x6c, 0x65, 0x61,
0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
@@ -367,10 +376,26 @@
0x6f, 0x74, 0x6f, 0x2e, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66,
0x69, 0x67, 0x5f, 0x61, 0x72, 0x74, 0x69, 0x66, 0x61, 0x63, 0x74, 0x52, 0x13, 0x6f, 0x74, 0x68,
0x65, 0x72, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x73,
- 0x42, 0x33, 0x5a, 0x31, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2f, 0x73, 0x6f, 0x6f, 0x6e,
- 0x67, 0x2f, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67,
- 0x2f, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f,
- 0x70, 0x72, 0x6f, 0x74, 0x6f,
+ 0x12, 0x87, 0x01, 0x0a, 0x17, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e,
+ 0x66, 0x69, 0x67, 0x5f, 0x6d, 0x61, 0x70, 0x73, 0x5f, 0x6d, 0x61, 0x70, 0x18, 0x03, 0x20, 0x03,
+ 0x28, 0x0b, 0x32, 0x50, 0x2e, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2e, 0x72, 0x65, 0x6c,
+ 0x65, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f, 0x70, 0x72, 0x6f, 0x74,
+ 0x6f, 0x2e, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67,
+ 0x73, 0x5f, 0x61, 0x72, 0x74, 0x69, 0x66, 0x61, 0x63, 0x74, 0x2e, 0x52, 0x65, 0x6c, 0x65, 0x61,
+ 0x73, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4d, 0x61, 0x70, 0x73, 0x4d, 0x61, 0x70, 0x45,
+ 0x6e, 0x74, 0x72, 0x79, 0x52, 0x14, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x43, 0x6f, 0x6e,
+ 0x66, 0x69, 0x67, 0x4d, 0x61, 0x70, 0x73, 0x4d, 0x61, 0x70, 0x1a, 0x79, 0x0a, 0x19, 0x52, 0x65,
+ 0x6c, 0x65, 0x61, 0x73, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4d, 0x61, 0x70, 0x73, 0x4d,
+ 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01,
+ 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x46, 0x0a, 0x05, 0x76, 0x61, 0x6c,
+ 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x30, 0x2e, 0x61, 0x6e, 0x64, 0x72, 0x6f,
+ 0x69, 0x64, 0x2e, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69,
+ 0x67, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f,
+ 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f, 0x6d, 0x61, 0x70, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75,
+ 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x33, 0x5a, 0x31, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64,
+ 0x2f, 0x73, 0x6f, 0x6f, 0x6e, 0x67, 0x2f, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x63,
+ 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f,
+ 0x6e, 0x66, 0x69, 0x67, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
}
var (
@@ -385,28 +410,32 @@
return file_build_flags_out_proto_rawDescData
}
-var file_build_flags_out_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
+var file_build_flags_out_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_build_flags_out_proto_goTypes = []interface{}{
(*Tracepoint)(nil), // 0: android.release_config_proto.tracepoint
(*FlagArtifact)(nil), // 1: android.release_config_proto.flag_artifact
(*ReleaseConfigArtifact)(nil), // 2: android.release_config_proto.release_config_artifact
(*ReleaseConfigsArtifact)(nil), // 3: android.release_config_proto.release_configs_artifact
- (*Value)(nil), // 4: android.release_config_proto.value
- (*FlagDeclaration)(nil), // 5: android.release_config_proto.flag_declaration
+ nil, // 4: android.release_config_proto.release_configs_artifact.ReleaseConfigMapsMapEntry
+ (*Value)(nil), // 5: android.release_config_proto.value
+ (*FlagDeclaration)(nil), // 6: android.release_config_proto.flag_declaration
+ (*ReleaseConfigMap)(nil), // 7: android.release_config_proto.release_config_map
}
var file_build_flags_out_proto_depIdxs = []int32{
- 4, // 0: android.release_config_proto.tracepoint.value:type_name -> android.release_config_proto.value
- 5, // 1: android.release_config_proto.flag_artifact.flag_declaration:type_name -> android.release_config_proto.flag_declaration
- 4, // 2: android.release_config_proto.flag_artifact.value:type_name -> android.release_config_proto.value
+ 5, // 0: android.release_config_proto.tracepoint.value:type_name -> android.release_config_proto.value
+ 6, // 1: android.release_config_proto.flag_artifact.flag_declaration:type_name -> android.release_config_proto.flag_declaration
+ 5, // 2: android.release_config_proto.flag_artifact.value:type_name -> android.release_config_proto.value
0, // 3: android.release_config_proto.flag_artifact.traces:type_name -> android.release_config_proto.tracepoint
1, // 4: android.release_config_proto.release_config_artifact.flag_artifacts:type_name -> android.release_config_proto.flag_artifact
2, // 5: android.release_config_proto.release_configs_artifact.release_config:type_name -> android.release_config_proto.release_config_artifact
2, // 6: android.release_config_proto.release_configs_artifact.other_release_configs:type_name -> android.release_config_proto.release_config_artifact
- 7, // [7:7] is the sub-list for method output_type
- 7, // [7:7] is the sub-list for method input_type
- 7, // [7:7] is the sub-list for extension type_name
- 7, // [7:7] is the sub-list for extension extendee
- 0, // [0:7] is the sub-list for field type_name
+ 4, // 7: android.release_config_proto.release_configs_artifact.release_config_maps_map:type_name -> android.release_config_proto.release_configs_artifact.ReleaseConfigMapsMapEntry
+ 7, // 8: android.release_config_proto.release_configs_artifact.ReleaseConfigMapsMapEntry.value:type_name -> android.release_config_proto.release_config_map
+ 9, // [9:9] is the sub-list for method output_type
+ 9, // [9:9] is the sub-list for method input_type
+ 9, // [9:9] is the sub-list for extension type_name
+ 9, // [9:9] is the sub-list for extension extendee
+ 0, // [0:9] is the sub-list for field type_name
}
func init() { file_build_flags_out_proto_init() }
@@ -471,7 +500,7 @@
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_build_flags_out_proto_rawDesc,
NumEnums: 0,
- NumMessages: 4,
+ NumMessages: 5,
NumExtensions: 0,
NumServices: 0,
},
diff --git a/cmd/release_config/release_config_proto/build_flags_out.proto b/cmd/release_config/release_config_proto/build_flags_out.proto
index fd8487b..05e770f 100644
--- a/cmd/release_config/release_config_proto/build_flags_out.proto
+++ b/cmd/release_config/release_config_proto/build_flags_out.proto
@@ -82,5 +82,8 @@
// All other release configs defined for this TARGET_PRODUCT.
repeated release_config_artifact other_release_configs = 2;
+
+ // Map of release_config_artifact.directories to release_config_map message.
+ map<string, release_config_map> release_config_maps_map = 3;
}
diff --git a/cmd/release_config/release_config_proto/build_flags_src.pb.go b/cmd/release_config/release_config_proto/build_flags_src.pb.go
index ccf3b3f..d0c924d 100644
--- a/cmd/release_config/release_config_proto/build_flags_src.pb.go
+++ b/cmd/release_config/release_config_proto/build_flags_src.pb.go
@@ -568,6 +568,8 @@
// Any aliases.
Aliases []*ReleaseAlias `protobuf:"bytes,1,rep,name=aliases" json:"aliases,omitempty"`
+ // Description of this map and its intended use.
+ Description *string `protobuf:"bytes,2,opt,name=description" json:"description,omitempty"`
// The default container for flags declared here.
DefaultContainer *Container `protobuf:"varint,3,opt,name=default_container,json=defaultContainer,enum=android.release_config_proto.Container" json:"default_container,omitempty"`
}
@@ -611,6 +613,13 @@
return nil
}
+func (x *ReleaseConfigMap) GetDescription() string {
+ if x != nil && x.Description != nil {
+ return *x.Description
+ }
+ return ""
+}
+
func (x *ReleaseConfigMap) GetDefaultContainer() Container {
if x != nil && x.DefaultContainer != nil {
return *x.DefaultContainer
@@ -671,33 +680,35 @@
0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x12, 0x12, 0x0a, 0x04,
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,
0x12, 0x16, 0x0a, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
- 0x52, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x22, 0xb1, 0x01, 0x0a, 0x12, 0x72, 0x65, 0x6c,
+ 0x52, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x22, 0xd3, 0x01, 0x0a, 0x12, 0x72, 0x65, 0x6c,
0x65, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f, 0x6d, 0x61, 0x70, 0x12,
0x45, 0x0a, 0x07, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b,
0x32, 0x2b, 0x2e, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2e, 0x72, 0x65, 0x6c, 0x65, 0x61,
0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x52, 0x07, 0x61,
- 0x6c, 0x69, 0x61, 0x73, 0x65, 0x73, 0x12, 0x54, 0x0a, 0x11, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c,
- 0x74, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28,
- 0x0e, 0x32, 0x27, 0x2e, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2e, 0x72, 0x65, 0x6c, 0x65,
- 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
- 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x52, 0x10, 0x64, 0x65, 0x66, 0x61,
- 0x75, 0x6c, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2a, 0x4a, 0x0a, 0x08,
- 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x12, 0x18, 0x0a, 0x14, 0x55, 0x4e, 0x53, 0x50,
- 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x5f, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77,
- 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x4c, 0x41, 0x55, 0x4e, 0x43, 0x48, 0x10, 0x01, 0x12, 0x0c,
- 0x0a, 0x08, 0x50, 0x52, 0x45, 0x42, 0x55, 0x49, 0x4c, 0x54, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06,
- 0x4d, 0x41, 0x4e, 0x55, 0x41, 0x4c, 0x10, 0x03, 0x2a, 0x64, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x74,
- 0x61, 0x69, 0x6e, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x15, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49,
- 0x46, 0x49, 0x45, 0x44, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x10, 0x00,
- 0x12, 0x07, 0x0a, 0x03, 0x41, 0x4c, 0x4c, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x52, 0x4f,
- 0x44, 0x55, 0x43, 0x54, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4d,
- 0x10, 0x03, 0x12, 0x0e, 0x0a, 0x0a, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4d, 0x5f, 0x45, 0x58, 0x54,
- 0x10, 0x04, 0x12, 0x0a, 0x0a, 0x06, 0x56, 0x45, 0x4e, 0x44, 0x4f, 0x52, 0x10, 0x05, 0x42, 0x33,
- 0x5a, 0x31, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2f, 0x73, 0x6f, 0x6f, 0x6e, 0x67, 0x2f,
- 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, 0x72,
- 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f, 0x70, 0x72,
- 0x6f, 0x74, 0x6f,
+ 0x6c, 0x69, 0x61, 0x73, 0x65, 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69,
+ 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73,
+ 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x54, 0x0a, 0x11, 0x64, 0x65, 0x66, 0x61,
+ 0x75, 0x6c, 0x74, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x18, 0x03, 0x20,
+ 0x01, 0x28, 0x0e, 0x32, 0x27, 0x2e, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2e, 0x72, 0x65,
+ 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f, 0x70, 0x72, 0x6f,
+ 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x52, 0x10, 0x64, 0x65,
+ 0x66, 0x61, 0x75, 0x6c, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2a, 0x4a,
+ 0x0a, 0x08, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x12, 0x18, 0x0a, 0x14, 0x55, 0x4e,
+ 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x5f, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c,
+ 0x6f, 0x77, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x4c, 0x41, 0x55, 0x4e, 0x43, 0x48, 0x10, 0x01,
+ 0x12, 0x0c, 0x0a, 0x08, 0x50, 0x52, 0x45, 0x42, 0x55, 0x49, 0x4c, 0x54, 0x10, 0x02, 0x12, 0x0a,
+ 0x0a, 0x06, 0x4d, 0x41, 0x4e, 0x55, 0x41, 0x4c, 0x10, 0x03, 0x2a, 0x64, 0x0a, 0x09, 0x63, 0x6f,
+ 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x15, 0x55, 0x4e, 0x53, 0x50, 0x45,
+ 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72,
+ 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x4c, 0x4c, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x50,
+ 0x52, 0x4f, 0x44, 0x55, 0x43, 0x54, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x53, 0x59, 0x53, 0x54,
+ 0x45, 0x4d, 0x10, 0x03, 0x12, 0x0e, 0x0a, 0x0a, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4d, 0x5f, 0x45,
+ 0x58, 0x54, 0x10, 0x04, 0x12, 0x0a, 0x0a, 0x06, 0x56, 0x45, 0x4e, 0x44, 0x4f, 0x52, 0x10, 0x05,
+ 0x42, 0x33, 0x5a, 0x31, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2f, 0x73, 0x6f, 0x6f, 0x6e,
+ 0x67, 0x2f, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67,
+ 0x2f, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f,
+ 0x70, 0x72, 0x6f, 0x74, 0x6f,
}
var (
diff --git a/cmd/release_config/release_config_proto/build_flags_src.proto b/cmd/release_config/release_config_proto/build_flags_src.proto
index 8501524..c077f5c 100644
--- a/cmd/release_config/release_config_proto/build_flags_src.proto
+++ b/cmd/release_config/release_config_proto/build_flags_src.proto
@@ -144,6 +144,9 @@
// Any aliases.
repeated release_alias aliases = 1;
+ // Description of this map and its intended use.
+ optional string description = 2;
+
// The default container for flags declared here.
optional container default_container = 3;
diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go
index 04bc61d..93351f1 100644
--- a/dexpreopt/dexpreopt.go
+++ b/dexpreopt/dexpreopt.go
@@ -52,7 +52,7 @@
// GenerateDexpreoptRule generates a set of commands that will preopt a module based on a GlobalConfig and a
// ModuleConfig. The produced files and their install locations will be available through rule.Installs().
func GenerateDexpreoptRule(ctx android.BuilderContext, globalSoong *GlobalSoongConfig,
- global *GlobalConfig, module *ModuleConfig, productPackages android.Path) (
+ global *GlobalConfig, module *ModuleConfig, productPackages android.Path, copyApexSystemServerJarDex bool) (
rule *android.RuleBuilder, err error) {
defer func() {
@@ -94,7 +94,7 @@
for archIdx, _ := range module.Archs {
dexpreoptCommand(ctx, globalSoong, global, module, rule, archIdx, profile, appImage,
- generateDM, productPackages)
+ generateDM, productPackages, copyApexSystemServerJarDex)
}
}
}
@@ -231,7 +231,7 @@
func dexpreoptCommand(ctx android.BuilderContext, globalSoong *GlobalSoongConfig,
global *GlobalConfig, module *ModuleConfig, rule *android.RuleBuilder, archIdx int,
- profile android.WritablePath, appImage bool, generateDM bool, productPackages android.Path) {
+ profile android.WritablePath, appImage bool, generateDM bool, productPackages android.Path, copyApexSystemServerJarDex bool) {
arch := module.Archs[archIdx]
@@ -277,7 +277,7 @@
clcTarget = append(clcTarget, GetSystemServerDexLocation(ctx, global, lib))
}
- if DexpreoptRunningInSoong {
+ if DexpreoptRunningInSoong && copyApexSystemServerJarDex {
// Copy the system server jar to a predefined location where dex2oat will find it.
dexPathHost := SystemServerDexJarHostPath(ctx, module.Name)
rule.Command().Text("mkdir -p").Flag(filepath.Dir(dexPathHost.String()))
diff --git a/dexpreopt/dexpreopt_gen/dexpreopt_gen.go b/dexpreopt/dexpreopt_gen/dexpreopt_gen.go
index 8033b48..7512005 100644
--- a/dexpreopt/dexpreopt_gen/dexpreopt_gen.go
+++ b/dexpreopt/dexpreopt_gen/dexpreopt_gen.go
@@ -205,8 +205,9 @@
panic(err)
}
}
+ cpApexSscpServerJar := false // dexpreopt_gen operates on make modules, and since sscp libraries are in soong, this should be a noop
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(
- ctx, globalSoong, global, module, android.PathForTesting(productPackagesPath))
+ ctx, globalSoong, global, module, android.PathForTesting(productPackagesPath), cpApexSscpServerJar)
if err != nil {
panic(err)
}
diff --git a/dexpreopt/dexpreopt_test.go b/dexpreopt/dexpreopt_test.go
index 7071f3e..eff2416 100644
--- a/dexpreopt/dexpreopt_test.go
+++ b/dexpreopt/dexpreopt_test.go
@@ -101,7 +101,7 @@
module := testSystemModuleConfig(ctx, "test")
productPackages := android.PathForTesting("product_packages.txt")
- rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages)
+ rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
if err != nil {
t.Fatal(err)
}
@@ -161,7 +161,7 @@
for _, test := range tests {
global.PatternsOnSystemOther = test.patterns
for _, mt := range test.moduleTests {
- rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, mt.module, productPackages)
+ rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, mt.module, productPackages, true)
if err != nil {
t.Fatal(err)
}
@@ -181,6 +181,11 @@
}
func TestDexPreoptApexSystemServerJars(t *testing.T) {
+ // modify the global variable for test
+ var oldDexpreoptRunningInSoong = DexpreoptRunningInSoong
+ DexpreoptRunningInSoong = true
+
+ // test begin
config := android.TestConfig("out", nil, "", nil)
ctx := android.BuilderContextForTesting(config)
globalSoong := globalSoongConfigForTests(ctx)
@@ -191,7 +196,7 @@
global.ApexSystemServerJars = android.CreateTestConfiguredJarList(
[]string{"com.android.apex1:service-A"})
- rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages)
+ rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
if err != nil {
t.Fatal(err)
}
@@ -202,6 +207,18 @@
}
android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String())
+
+ android.AssertStringListContains(t, "apex sscp jar copy", rule.Outputs().Strings(), "out/soong/system_server_dexjars/service-A.jar")
+
+ // rule with apex sscp cp as false
+ rule, err = GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, false)
+ if err != nil {
+ t.Fatal(err)
+ }
+ android.AssertStringListDoesNotContain(t, "apex sscp jar copy", rule.Outputs().Strings(), "out/soong/system_server_dexjars/service-A.jar")
+
+ // cleanup the global variable for test
+ DexpreoptRunningInSoong = oldDexpreoptRunningInSoong
}
func TestDexPreoptStandaloneSystemServerJars(t *testing.T) {
@@ -215,7 +232,7 @@
global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList(
[]string{"platform:service-A"})
- rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages)
+ rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
if err != nil {
t.Fatal(err)
}
@@ -239,7 +256,7 @@
global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList(
[]string{"system_ext:service-A"})
- rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages)
+ rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
if err != nil {
t.Fatal(err)
}
@@ -263,7 +280,7 @@
global.ApexStandaloneSystemServerJars = android.CreateTestConfiguredJarList(
[]string{"com.android.apex1:service-A"})
- rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages)
+ rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
if err != nil {
t.Fatal(err)
}
@@ -286,7 +303,7 @@
module.ProfileClassListing = android.OptionalPathForPath(android.PathForTesting("profile"))
- rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages)
+ rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
if err != nil {
t.Fatal(err)
}
diff --git a/filesystem/filesystem_test.go b/filesystem/filesystem_test.go
index f4ecad4..3a5071d 100644
--- a/filesystem/filesystem_test.go
+++ b/filesystem/filesystem_test.go
@@ -84,12 +84,21 @@
cc_library {
name: "libbar",
required: ["libbaz"],
+ target: {
+ platform: {
+ required: ["lib_platform_only"],
+ },
+ },
}
cc_library {
name: "libbaz",
}
+ cc_library {
+ name: "lib_platform_only",
+ }
+
phony {
name: "phony",
required: [
@@ -120,6 +129,7 @@
"lib64/libbar.so",
"lib64/libbaz.so",
"lib64/libquz.so",
+ "lib64/lib_platform_only.so",
"etc/bpf/bpf.o",
}
for _, e := range expected {
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index 38ed856..25e95db 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -243,10 +243,6 @@
return true
}
- if disableSourceApexVariant(ctx) {
- return true
- }
-
if _, isApex := android.ModuleProvider(ctx, android.ApexBundleInfoProvider); isApex {
// dexpreopt rules for system server jars can be generated in the ModuleCtx of prebuilt apexes
return false
@@ -501,8 +497,12 @@
Output(appProductPackages)
productPackagesRule.Restat().Build("product_packages."+dexJarStem, "dexpreopt product_packages")
+ // Prebuilts are active, do not copy the dexpreopt'd source javalib to out/soong/system_server_dexjars
+ // The javalib from the deapexed prebuilt will be copied to this location.
+ // TODO (b/331665856): Implement a principled solution for this.
+ copyApexSystemServerJarDex := !disableSourceApexVariant(ctx)
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(
- ctx, globalSoong, global, dexpreoptConfig, appProductPackages)
+ ctx, globalSoong, global, dexpreoptConfig, appProductPackages, copyApexSystemServerJarDex)
if err != nil {
ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error())
return
diff --git a/java/droidstubs.go b/java/droidstubs.go
index 02b81a4..870c643 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -532,8 +532,8 @@
cmd.Flag(config.MetalavaAnnotationsFlags)
if params.migratingNullability {
- previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
- cmd.FlagWithInput("--migrate-nullness ", previousApi)
+ previousApiFiles := android.PathsForModuleSrc(ctx, []string{String(d.properties.Previous_api)})
+ cmd.FlagForEachInput("--migrate-nullness ", previousApiFiles)
}
if s := String(d.properties.Validate_nullability_from_list); s != "" {
@@ -692,11 +692,11 @@
ctx.PropertyErrorf("out", "out property may not be combined with check_api")
}
- apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
- removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
+ apiFiles := android.PathsForModuleSrc(ctx, []string{String(d.properties.Check_api.Last_released.Api_file)})
+ removedApiFiles := android.PathsForModuleSrc(ctx, []string{String(d.properties.Check_api.Last_released.Removed_api_file)})
- cmd.FlagWithInput("--check-compatibility:api:released ", apiFile)
- cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
+ cmd.FlagForEachInput("--check-compatibility:api:released ", apiFiles)
+ cmd.FlagForEachInput("--check-compatibility:removed:released ", removedApiFiles)
baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
if baselineFile.Valid() {
@@ -950,9 +950,12 @@
// Add API lint options.
if doApiLint {
- newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
- if newSince.Valid() {
- cmd.FlagWithInput("--api-lint ", newSince.Path())
+ var newSince android.Paths
+ if d.properties.Check_api.Api_lint.New_since != nil {
+ newSince = android.PathsForModuleSrc(ctx, []string{proptools.String(d.properties.Check_api.Api_lint.New_since)})
+ }
+ if len(newSince) > 0 {
+ cmd.FlagForEachInput("--api-lint ", newSince)
} else {
cmd.Flag("--api-lint")
}
diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go
index e4beb5e..ae587ea 100644
--- a/java/hiddenapi_modular.go
+++ b/java/hiddenapi_modular.go
@@ -1478,13 +1478,3 @@
}
return bootDexJar.Path()
}
-
-// extractEncodedDexJarsFromModules extracts the encoded dex jars from the supplied modules.
-func extractEncodedDexJarsFromModules(ctx android.ModuleContext, contents []android.Module) bootDexJarByModule {
- encodedDexJarsByModuleName := bootDexJarByModule{}
- for _, module := range contents {
- path := retrieveEncodedBootDexJarFromModule(ctx, module)
- encodedDexJarsByModuleName.addPath(module, path)
- }
- return encodedDexJarsByModuleName
-}
diff --git a/java/java.go b/java/java.go
index fb35a9a..725e25a 100644
--- a/java/java.go
+++ b/java/java.go
@@ -587,6 +587,7 @@
JAVA_VERSION_9 = 9
JAVA_VERSION_11 = 11
JAVA_VERSION_17 = 17
+ JAVA_VERSION_21 = 21
)
func (v javaVersion) String() string {
@@ -605,6 +606,8 @@
return "11"
case JAVA_VERSION_17:
return "17"
+ case JAVA_VERSION_21:
+ return "21"
default:
return "unsupported"
}
@@ -647,6 +650,8 @@
return JAVA_VERSION_11
case "17":
return JAVA_VERSION_17
+ case "21":
+ return JAVA_VERSION_21
case "10", "12", "13", "14", "15", "16":
ctx.PropertyErrorf("java_version", "Java language level %s is not supported", javaVersion)
return JAVA_VERSION_UNSUPPORTED
@@ -886,6 +891,12 @@
}
func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ if disableSourceApexVariant(ctx) {
+ // Prebuilts are active, do not create the installation rules for the source javalib.
+ // Even though the source javalib is not used, we need to hide it to prevent duplicate installation rules.
+ // TODO (b/331665856): Implement a principled solution for this.
+ j.HideFromMake()
+ }
j.provideHiddenAPIPropertyInfo(ctx)
j.sdkVersion = j.SdkVersion(ctx)
diff --git a/java/prebuilt_apis.go b/java/prebuilt_apis.go
index 6a79e58..00613ee 100644
--- a/java/prebuilt_apis.go
+++ b/java/prebuilt_apis.go
@@ -367,10 +367,23 @@
info := latest[k]
name := PrebuiltApiCombinedModuleName(info.module, info.scope, "latest")
+ // Iterate until the currentApiScope does not extend any other api scopes
+ // i.e. is not a superset of any other api scopes
+ // the relationship between the api scopes is defined in java/sdk_library.go
var srcs []string
currentApiScope := scopeByName[info.scope]
- srcs = append(srcs, PrebuiltApiModuleName(info.module, currentApiScope.name, "latest"))
+ for currentApiScope != nil {
+ if _, ok := latest[fmt.Sprintf("%s.%s", info.module, currentApiScope.name)]; ok {
+ srcs = append(srcs, PrebuiltApiModuleName(info.module, currentApiScope.name, "latest"))
+ }
+ currentApiScope = currentApiScope.extends
+ }
+ // srcs is currently listed in the order from the widest api scope to the narrowest api scopes
+ // e.g. module lib -> system -> public
+ // In order to pass the files in metalava from the narrowest api scope to the widest api scope,
+ // the list has to be reversed.
+ android.ReverseSliceInPlace(srcs)
createCombinedApiFilegroupModule(mctx, name, srcs)
}
}
diff --git a/java/sdk_library.go b/java/sdk_library.go
index e7e53a2..bb5730d 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -705,10 +705,10 @@
annotationsZip android.OptionalPath
// The path to the latest API file.
- latestApiPath android.OptionalPath
+ latestApiPaths android.Paths
// The path to the latest removed API file.
- latestRemovedApiPath android.OptionalPath
+ latestRemovedApiPaths android.Paths
}
func (paths *scopePaths) extractStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error {
@@ -829,28 +829,25 @@
})
}
-func extractSingleOptionalOutputPath(dep android.Module) (android.OptionalPath, error) {
+func extractOutputPaths(dep android.Module) (android.Paths, error) {
var paths android.Paths
if sourceFileProducer, ok := dep.(android.SourceFileProducer); ok {
paths = sourceFileProducer.Srcs()
+ return paths, nil
} else {
- return android.OptionalPath{}, fmt.Errorf("module %q does not produce source files", dep)
+ return nil, fmt.Errorf("module %q does not produce source files", dep)
}
- if len(paths) != 1 {
- return android.OptionalPath{}, fmt.Errorf("expected one path from %q, got %q", dep, paths)
- }
- return android.OptionalPathForPath(paths[0]), nil
}
func (paths *scopePaths) extractLatestApiPath(ctx android.ModuleContext, dep android.Module) error {
- outputPath, err := extractSingleOptionalOutputPath(dep)
- paths.latestApiPath = outputPath
+ outputPaths, err := extractOutputPaths(dep)
+ paths.latestApiPaths = outputPaths
return err
}
func (paths *scopePaths) extractLatestRemovedApiPath(ctx android.ModuleContext, dep android.Module) error {
- outputPath, err := extractSingleOptionalOutputPath(dep)
- paths.latestRemovedApiPath = outputPath
+ outputPaths, err := extractOutputPaths(dep)
+ paths.latestRemovedApiPaths = outputPaths
return err
}
@@ -1562,6 +1559,12 @@
}
func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ if disableSourceApexVariant(ctx) {
+ // Prebuilts are active, do not create the installation rules for the source javalib.
+ // Even though the source javalib is not used, we need to hide it to prevent duplicate installation rules.
+ // TODO (b/331665856): Implement a principled solution for this.
+ module.HideFromMake()
+ }
if proptools.String(module.deviceProperties.Min_sdk_version) != "" {
module.CheckMinSdkVersion(ctx)
}
@@ -1619,11 +1622,15 @@
scopes[scope.name] = scopeInfo
scopeInfo["current_api"] = scope.snapshotRelativeCurrentApiTxtPath(baseModuleName)
scopeInfo["removed_api"] = scope.snapshotRelativeRemovedApiTxtPath(baseModuleName)
- if p := scopePaths.latestApiPath; p.Valid() {
- scopeInfo["latest_api"] = p.Path().String()
+ if p := scopePaths.latestApiPaths; len(p) > 0 {
+ // The last path in the list is the one that applies to this scope, the
+ // preceding ones, if any, are for the scope(s) that it extends.
+ scopeInfo["latest_api"] = p[len(p)-1].String()
}
- if p := scopePaths.latestRemovedApiPath; p.Valid() {
- scopeInfo["latest_removed_api"] = p.Path().String()
+ if p := scopePaths.latestRemovedApiPaths; len(p) > 0 {
+ // The last path in the list is the one that applies to this scope, the
+ // preceding ones, if any, are for the scope(s) that it extends.
+ scopeInfo["latest_removed_api"] = p[len(p)-1].String()
}
}
android.SetProvider(ctx, android.AdditionalSdkInfoProvider, android.AdditionalSdkInfo{additionalSdkInfo})
diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go
index 5fac255..0f163e6 100644
--- a/java/sdk_library_test.go
+++ b/java/sdk_library_test.go
@@ -1085,18 +1085,6 @@
t.Run("prefer", func(t *testing.T) {
testJavaSdkLibraryImport_Preferred(t, "prefer: true,", android.NullFixturePreparer)
})
-
- t.Run("use_source_config_var", func(t *testing.T) {
- testJavaSdkLibraryImport_Preferred(t,
- "use_source_config_var: {config_namespace: \"acme\", var_name: \"use_source\"},",
- android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
- variables.VendorVars = map[string]map[string]string{
- "acme": {
- "use_source": "false",
- },
- }
- }))
- })
}
// If a module is listed in `mainline_module_contributions, it should be used
diff --git a/java/testing.go b/java/testing.go
index 631d516..5ae326d 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -711,7 +711,7 @@
func registerFakeApexMutator(ctx android.RegistrationContext) {
ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
- ctx.BottomUp("apex", fakeApexMutator).Parallel()
+ ctx.Transition("apex", &fakeApexMutator{})
})
}
@@ -726,16 +726,30 @@
// `apex_available`. It helps us avoid a dependency on the real mutator defined in "soong-apex",
// which will cause a cyclic dependency, and it provides an easy way to create an APEX variant for
// testing without dealing with all the complexities in the real mutator.
-func fakeApexMutator(mctx android.BottomUpMutatorContext) {
- switch mctx.Module().(type) {
+type fakeApexMutator struct{}
+
+func (f *fakeApexMutator) Split(ctx android.BaseModuleContext) []string {
+ switch ctx.Module().(type) {
case *Library, *SdkLibrary:
- if len(mctx.Module().(apexModuleBase).ApexAvailable()) > 0 {
- modules := mctx.CreateVariations("", "apex1000")
- apexInfo := android.ApexInfo{
- ApexVariationName: "apex1000",
- }
- mctx.SetVariationProvider(modules[1], android.ApexInfoProvider, apexInfo)
+ return []string{"", "apex1000"}
+ }
+ return []string{""}
+}
+
+func (f *fakeApexMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string {
+ return sourceVariation
+}
+
+func (f *fakeApexMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string {
+ return incomingVariation
+}
+
+func (f *fakeApexMutator) Mutate(ctx android.BottomUpMutatorContext, variation string) {
+ if variation != "" {
+ apexInfo := android.ApexInfo{
+ ApexVariationName: "apex1000",
}
+ android.SetProvider(ctx, android.ApexInfoProvider, apexInfo)
}
}
diff --git a/python/binary.go b/python/binary.go
index d6750c6..c84eeee 100644
--- a/python/binary.go
+++ b/python/binary.go
@@ -203,7 +203,7 @@
}
func (p *PythonBinaryModule) isEmbeddedLauncherEnabled() bool {
- return Bool(p.properties.Embedded_launcher)
+ return BoolDefault(p.properties.Embedded_launcher, true)
}
func (b *PythonBinaryModule) autorun() bool {
diff --git a/python/python.go b/python/python.go
index 2b1974e..e14fdf3 100644
--- a/python/python.go
+++ b/python/python.go
@@ -59,7 +59,7 @@
// list of the Python libraries used only for this Python version.
Libs []string `android:"arch_variant"`
- // whether the binary is required to be built with embedded launcher for this version, defaults to false.
+ // whether the binary is required to be built with embedded launcher for this version, defaults to true.
Embedded_launcher *bool // TODO(b/174041232): Remove this property
}
@@ -151,6 +151,8 @@
// The zip file containing the current module's source/data files, with the
// source files precompiled.
precompiledSrcsZip android.Path
+
+ sourceProperties android.SourceProperties
}
// newModule generates new Python base module
@@ -203,7 +205,7 @@
var _ pythonDependency = (*PythonLibraryModule)(nil)
func (p *PythonLibraryModule) init() android.Module {
- p.AddProperties(&p.properties, &p.protoProperties)
+ p.AddProperties(&p.properties, &p.protoProperties, &p.sourceProperties)
android.InitAndroidArchModule(p, p.hod, p.multilib)
android.InitDefaultableModule(p)
return p
@@ -421,6 +423,11 @@
func (p *PythonLibraryModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
expandedSrcs := android.PathsForModuleSrcExcludes(ctx, p.properties.Srcs, p.properties.Exclude_srcs)
android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: expandedSrcs.Strings()})
+ // Keep before any early returns.
+ android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{
+ TestOnly: Bool(p.sourceProperties.Test_only),
+ TopLevelTarget: p.sourceProperties.Top_level_test_target,
+ })
// expand data files from "data" property.
expandedData := android.PathsForModuleSrc(ctx, p.properties.Data)
diff --git a/python/python_test.go b/python/python_test.go
index 75a6a89..c0b7295 100644
--- a/python/python_test.go
+++ b/python/python_test.go
@@ -18,10 +18,13 @@
"fmt"
"os"
"path/filepath"
+ "strings"
"testing"
"android/soong/android"
"android/soong/cc"
+
+ "github.com/google/blueprint"
)
type pyModule struct {
@@ -360,6 +363,76 @@
}
}
+func TestTestOnlyProvider(t *testing.T) {
+ t.Parallel()
+ ctx := android.GroupFixturePreparers(
+ PrepareForTestWithPythonBuildComponents,
+ android.PrepareForTestWithAllowMissingDependencies,
+ ).RunTestWithBp(t, `
+ // These should be test-only
+ python_library { name: "py-lib-test", test_only: true }
+ python_library { name: "py-lib-test-host", test_only: true, host_supported: true }
+ python_test { name: "py-test", srcs: ["py-test.py"] }
+ python_test_host { name: "py-test-host", srcs: ["py-test-host.py"] }
+ python_binary_host { name: "py-bin-test", srcs: ["py-bin-test.py"] }
+
+ // These should not be.
+ python_library { name: "py-lib" }
+ python_binary_host { name: "py-bin", srcs: ["py-bin.py"] }
+ `)
+
+ // Visit all modules and ensure only the ones that should
+ // marked as test-only are marked as test-only.
+
+ actualTestOnly := []string{}
+ ctx.VisitAllModules(func(m blueprint.Module) {
+ if provider, ok := android.OtherModuleProvider(ctx.TestContext.OtherModuleProviderAdaptor(), m, android.TestOnlyProviderKey); ok {
+ if provider.TestOnly {
+ actualTestOnly = append(actualTestOnly, m.Name())
+ }
+ }
+ })
+ expectedTestOnlyModules := []string{
+ "py-lib-test",
+ "py-lib-test-host",
+ "py-test",
+ "py-test-host",
+ }
+
+ notEqual, left, right := android.ListSetDifference(expectedTestOnlyModules, actualTestOnly)
+ if notEqual {
+ t.Errorf("test-only: Expected but not found: %v, Found but not expected: %v", left, right)
+ }
+}
+
+// Don't allow setting test-only on things that are always tests or never tests.
+func TestInvalidTestOnlyTargets(t *testing.T) {
+ testCases := []string{
+ ` python_test { name: "py-test", test_only: true, srcs: ["py-test.py"] } `,
+ ` python_test_host { name: "py-test-host", test_only: true, srcs: ["py-test-host.py"] } `,
+ ` python_defaults { name: "py-defaults", test_only: true, srcs: ["foo.py"] } `,
+ }
+
+ for i, bp := range testCases {
+ ctx := android.GroupFixturePreparers(
+ PrepareForTestWithPythonBuildComponents,
+ android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
+
+ ctx.RegisterModuleType("python_defaults", DefaultsFactory)
+ }),
+ android.PrepareForTestWithAllowMissingDependencies).
+ ExtendWithErrorHandler(android.FixtureIgnoreErrors).
+ RunTestWithBp(t, bp)
+ if len(ctx.Errs) != 1 {
+ t.Errorf("Expected err setting test_only in testcase #%d: %d errs", i, len(ctx.Errs))
+ continue
+ }
+ if !strings.Contains(ctx.Errs[0].Error(), "unrecognized property \"test_only\"") {
+ t.Errorf("ERR: %s bad bp: %s", ctx.Errs[0], bp)
+ }
+ }
+}
+
func expectModule(t *testing.T, ctx *android.TestContext, name, variant, expectedSrcsZip string, expectedPyRunfiles []string) {
module := ctx.ModuleForTests(name, variant)
diff --git a/python/test.go b/python/test.go
index 826f353..2b939e7 100644
--- a/python/test.go
+++ b/python/test.go
@@ -36,7 +36,9 @@
}
func NewTest(hod android.HostOrDeviceSupported) *PythonTestModule {
- return &PythonTestModule{PythonBinaryModule: *NewBinary(hod)}
+ p := &PythonTestModule{PythonBinaryModule: *NewBinary(hod)}
+ p.sourceProperties = android.SourceProperties{Test_only: proptools.BoolPtr(true), Top_level_test_target: true}
+ return p
}
func PythonTestHostFactory() android.Module {
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index 275860f..0a5483b 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -688,6 +688,12 @@
public: {
enabled: true,
},
+ system: {
+ enabled: true,
+ },
+ module_lib: {
+ enabled: true,
+ },
}
java_system_modules {
@@ -752,6 +758,20 @@
removed_api: "sdk_library/public/myjavalib-removed.txt",
sdk_version: "current",
},
+ system: {
+ jars: ["sdk_library/system/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/system/myjavalib_stub_sources"],
+ current_api: "sdk_library/system/myjavalib.txt",
+ removed_api: "sdk_library/system/myjavalib-removed.txt",
+ sdk_version: "system_current",
+ },
+ module_lib: {
+ jars: ["sdk_library/module-lib/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/module-lib/myjavalib_stub_sources"],
+ current_api: "sdk_library/module-lib/myjavalib.txt",
+ removed_api: "sdk_library/module-lib/myjavalib-removed.txt",
+ sdk_version: "module_current",
+ },
}
java_system_modules_import {
@@ -771,6 +791,12 @@
.intermediates/myjavalib.stubs.exportable/android_common/combined/myjavalib.stubs.exportable.jar -> sdk_library/public/myjavalib-stubs.jar
.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt
+.intermediates/myjavalib.stubs.exportable.system/android_common/combined/myjavalib.stubs.exportable.system.jar -> sdk_library/system/myjavalib-stubs.jar
+.intermediates/myjavalib.stubs.source.system/android_common/exportable/myjavalib.stubs.source.system_api.txt -> sdk_library/system/myjavalib.txt
+.intermediates/myjavalib.stubs.source.system/android_common/exportable/myjavalib.stubs.source.system_removed.txt -> sdk_library/system/myjavalib-removed.txt
+.intermediates/myjavalib.stubs.exportable.module_lib/android_common/combined/myjavalib.stubs.exportable.module_lib.jar -> sdk_library/module-lib/myjavalib-stubs.jar
+.intermediates/myjavalib.stubs.source.module_lib/android_common/exportable/myjavalib.stubs.source.module_lib_api.txt -> sdk_library/module-lib/myjavalib.txt
+.intermediates/myjavalib.stubs.source.module_lib/android_common/exportable/myjavalib.stubs.source.module_lib_removed.txt -> sdk_library/module-lib/myjavalib-removed.txt
`),
checkInfoContents(result.Config, `
[
@@ -805,11 +831,23 @@
"@name": "myjavalib",
"dist_stem": "myjavalib",
"scopes": {
+ "module-lib": {
+ "current_api": "sdk_library/module-lib/myjavalib.txt",
+ "latest_api": "out/soong/.intermediates/prebuilts/sdk/myjavalib.api.module-lib.latest/gen/myjavalib.api.module-lib.latest",
+ "latest_removed_api": "out/soong/.intermediates/prebuilts/sdk/myjavalib-removed.api.module-lib.latest/gen/myjavalib-removed.api.module-lib.latest",
+ "removed_api": "sdk_library/module-lib/myjavalib-removed.txt"
+ },
"public": {
"current_api": "sdk_library/public/myjavalib.txt",
"latest_api": "out/soong/.intermediates/prebuilts/sdk/myjavalib.api.public.latest/gen/myjavalib.api.public.latest",
"latest_removed_api": "out/soong/.intermediates/prebuilts/sdk/myjavalib-removed.api.public.latest/gen/myjavalib-removed.api.public.latest",
"removed_api": "sdk_library/public/myjavalib-removed.txt"
+ },
+ "system": {
+ "current_api": "sdk_library/system/myjavalib.txt",
+ "latest_api": "out/soong/.intermediates/prebuilts/sdk/myjavalib.api.system.latest/gen/myjavalib.api.system.latest",
+ "latest_removed_api": "out/soong/.intermediates/prebuilts/sdk/myjavalib-removed.api.system.latest/gen/myjavalib-removed.api.system.latest",
+ "removed_api": "sdk_library/system/myjavalib-removed.txt"
}
}
},
diff --git a/soong_ui.bash b/soong_ui.bash
index 8e7cd19..7737880 100755
--- a/soong_ui.bash
+++ b/soong_ui.bash
@@ -35,6 +35,7 @@
soong_build_go soong_ui android/soong/cmd/soong_ui
soong_build_go mk2rbc android/soong/mk2rbc/mk2rbc
soong_build_go rbcrun rbcrun/rbcrun
+soong_build_go release-config android/soong/cmd/release_config/release_config
cd ${TOP}
exec "$(getoutdir)/soong_ui" "$@"
diff --git a/tradefed_modules/test_module_config.go b/tradefed_modules/test_module_config.go
index 6867537..9127f67 100644
--- a/tradefed_modules/test_module_config.go
+++ b/tradefed_modules/test_module_config.go
@@ -297,10 +297,16 @@
// 1. manifest file to testcases dir
// 2. New Module.config / AndroidTest.xml file with our options.
func (m *testModuleConfigModule) generateManifestAndConfig(ctx android.ModuleContext) {
+ // Keep before early returns.
+ android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{
+ TestOnly: true,
+ TopLevelTarget: true,
+ })
+
if !m.validateTestSuites(ctx) {
return
}
- // Ensure the provider is accurate
+ // Ensure the base provider is accurate
if m.provider.TestConfig == nil {
return
}
diff --git a/tradefed_modules/test_module_config_test.go b/tradefed_modules/test_module_config_test.go
index 41dd3d4..6997228 100644
--- a/tradefed_modules/test_module_config_test.go
+++ b/tradefed_modules/test_module_config_test.go
@@ -19,6 +19,8 @@
"strconv"
"strings"
"testing"
+
+ "github.com/google/blueprint"
)
const bp = `
@@ -347,6 +349,67 @@
RunTestWithBp(t, badBp)
}
+func TestTestOnlyProvider(t *testing.T) {
+ t.Parallel()
+ ctx := android.GroupFixturePreparers(
+ java.PrepareForTestWithJavaDefaultModules,
+ android.FixtureRegisterWithContext(RegisterTestModuleConfigBuildComponents),
+ ).RunTestWithBp(t, `
+ // These should be test-only
+ test_module_config_host {
+ name: "host-derived-test",
+ base: "host-base",
+ exclude_filters: ["android.test.example.devcodelab.DevCodelabTest#testHelloFail"],
+ include_annotations: ["android.platform.test.annotations.LargeTest"],
+ test_suites: ["general-tests"],
+ }
+
+ test_module_config {
+ name: "derived-test",
+ base: "base",
+ exclude_filters: ["android.test.example.devcodelab.DevCodelabTest#testHelloFail"],
+ include_annotations: ["android.platform.test.annotations.LargeTest"],
+ test_suites: ["general-tests"],
+ }
+
+ android_test {
+ name: "base",
+ sdk_version: "current",
+ data: ["data/testfile"],
+ }
+
+ java_test_host {
+ name: "host-base",
+ srcs: ["a.java"],
+ test_suites: ["general-tests"],
+ }`,
+ )
+
+ // Visit all modules and ensure only the ones that should
+ // marked as test-only are marked as test-only.
+
+ actualTestOnly := []string{}
+ ctx.VisitAllModules(func(m blueprint.Module) {
+ if provider, ok := android.OtherModuleProvider(ctx.TestContext.OtherModuleProviderAdaptor(), m, android.TestOnlyProviderKey); ok {
+ if provider.TestOnly {
+ actualTestOnly = append(actualTestOnly, m.Name())
+ }
+ }
+ })
+ expectedTestOnlyModules := []string{
+ "host-derived-test",
+ "derived-test",
+ // android_test and java_test_host are tests too.
+ "host-base",
+ "base",
+ }
+
+ notEqual, left, right := android.ListSetDifference(expectedTestOnlyModules, actualTestOnly)
+ if notEqual {
+ t.Errorf("test-only: Expected but not found: %v, Found but not expected: %v", left, right)
+ }
+}
+
// Use for situations where the entries map contains pairs: [srcPath:installedPath1, srcPath2:installedPath2]
// and we want to compare the RHS of the pairs, i.e. installedPath1, installedPath2
func assertEntryPairValues(t *testing.T, actual []string, expected []string) {