Add bazel staging mode to soong build.

This is to use bazel to build targets that are being prepared for an
incipient release to the prod mode allowlist.

Bug: 254265047
Test: m nothing
Test: m nothing --bazel-mode-dev
Test: m nothing --bazel-mode-staging
Change-Id: Ic78a59cf51dba83ef1ac26483586560ea9b24aaf
This commit is contained in:
MarkDacek
2022-10-18 20:10:16 +00:00
parent bdb7495fe5
commit b78465de1d
8 changed files with 56 additions and 9 deletions

View File

@@ -1347,4 +1347,8 @@ var (
ProdMixedBuildsEnabledList = []string{ ProdMixedBuildsEnabledList = []string{
"com.android.adbd", "com.android.adbd",
} }
// Staging builds should be entirely prod, plus some near-ready ones. Add the
// new ones to the first argument as needed.
StagingMixedBuildsEnabledList = append([]string{}, ProdMixedBuildsEnabledList...)
) )

View File

@@ -386,6 +386,12 @@ func NewBazelContext(c *config) (BazelContext, error) {
for _, enabledProdModule := range allowlists.ProdMixedBuildsEnabledList { for _, enabledProdModule := range allowlists.ProdMixedBuildsEnabledList {
enabledModules[enabledProdModule] = true enabledModules[enabledProdModule] = true
} }
case BazelStagingMode:
modulesDefaultToBazel = false
for _, enabledStagingMode := range allowlists.StagingMixedBuildsEnabledList {
enabledModules[enabledStagingMode] = true
}
case BazelDevMode: case BazelDevMode:
modulesDefaultToBazel = true modulesDefaultToBazel = true

View File

@@ -97,6 +97,11 @@ const (
// allowlisted on an experimental basis. // allowlisted on an experimental basis.
BazelDevMode BazelDevMode
// Use bazel during analysis of a few allowlisted build modules. The allowlist
// is considered "staging, as these are modules being prepared to be released
// into prod mode shortly after.
BazelStagingMode
// Use bazel during analysis of build modules from an allowlist carefully // Use bazel during analysis of build modules from an allowlist carefully
// curated by the build team to be proven stable. // curated by the build team to be proven stable.
BazelProdMode BazelProdMode

View File

@@ -88,6 +88,7 @@ func init() {
flag.StringVar(&cmdlineArgs.OutFile, "o", "build.ninja", "the Ninja file to output") flag.StringVar(&cmdlineArgs.OutFile, "o", "build.ninja", "the Ninja file to output")
flag.BoolVar(&cmdlineArgs.EmptyNinjaFile, "empty-ninja-file", false, "write out a 0-byte ninja file") flag.BoolVar(&cmdlineArgs.EmptyNinjaFile, "empty-ninja-file", false, "write out a 0-byte ninja file")
flag.BoolVar(&cmdlineArgs.BazelMode, "bazel-mode", false, "use bazel for analysis of certain modules") flag.BoolVar(&cmdlineArgs.BazelMode, "bazel-mode", false, "use bazel for analysis of certain modules")
flag.BoolVar(&cmdlineArgs.BazelMode, "bazel-mode-staging", false, "use bazel for analysis of certain near-ready modules")
flag.BoolVar(&cmdlineArgs.BazelModeDev, "bazel-mode-dev", false, "use bazel for analysis of a large number of modules (less stable)") flag.BoolVar(&cmdlineArgs.BazelModeDev, "bazel-mode-dev", false, "use bazel for analysis of a large number of modules (less stable)")
// Flags that probably shouldn't be flags of soong_build but we haven't found // Flags that probably shouldn't be flags of soong_build but we haven't found
@@ -142,6 +143,8 @@ func newConfig(availableEnv map[string]string) android.Config {
buildMode = android.BazelDevMode buildMode = android.BazelDevMode
} else if cmdlineArgs.BazelMode { } else if cmdlineArgs.BazelMode {
buildMode = android.BazelProdMode buildMode = android.BazelProdMode
} else if cmdlineArgs.BazelModeStaging {
buildMode = android.BazelStagingMode
} else { } else {
buildMode = android.AnalysisNoBazel buildMode = android.AnalysisNoBazel
} }

View File

@@ -112,9 +112,19 @@ const (
// checkBazelMode fails the build if there are conflicting arguments for which bazel // checkBazelMode fails the build if there are conflicting arguments for which bazel
// build mode to use. // build mode to use.
func checkBazelMode(ctx Context, config Config) { func checkBazelMode(ctx Context, config Config) {
if config.bazelProdMode && config.bazelDevMode { count := 0
if config.bazelProdMode {
count++
}
if config.bazelDevMode {
count++
}
if config.bazelStagingMode {
count++
}
if count > 1 {
ctx.Fatalln("Conflicting bazel mode.\n" + ctx.Fatalln("Conflicting bazel mode.\n" +
"Do not specify both --bazel-mode and --bazel-mode-dev") "Do not specify more than one of --bazel-mode and --bazel-mode-dev and --bazel-mode-staging ")
} }
} }

View File

@@ -100,8 +100,9 @@ type configImpl struct {
pathReplaced bool pathReplaced bool
bazelProdMode bool bazelProdMode bool
bazelDevMode bool bazelDevMode bool
bazelStagingMode bool
// Set by multiproduct_kati // Set by multiproduct_kati
emptyNinjaFile bool emptyNinjaFile bool
@@ -721,6 +722,8 @@ func (c *configImpl) parseArgs(ctx Context, args []string) {
c.bazelProdMode = true c.bazelProdMode = true
} else if arg == "--bazel-mode-dev" { } else if arg == "--bazel-mode-dev" {
c.bazelDevMode = true c.bazelDevMode = true
} else if arg == "--bazel-mode-staging" {
c.bazelStagingMode = true
} else if len(arg) > 0 && arg[0] == '-' { } else if len(arg) > 0 && arg[0] == '-' {
parseArgNum := func(def int) int { parseArgNum := func(def int) int {
if len(arg) > 2 { if len(arg) > 2 {
@@ -1115,7 +1118,7 @@ func (c *configImpl) UseRBE() bool {
} }
func (c *configImpl) BazelBuildEnabled() bool { func (c *configImpl) BazelBuildEnabled() bool {
return c.bazelProdMode || c.bazelDevMode return c.bazelProdMode || c.bazelDevMode || c.bazelStagingMode
} }
func (c *configImpl) StartRBE() bool { func (c *configImpl) StartRBE() bool {

View File

@@ -1008,6 +1008,7 @@ func TestBuildConfig(t *testing.T) {
useBazel bool useBazel bool
bazelDevMode bool bazelDevMode bool
bazelProdMode bool bazelProdMode bool
bazelStagingMode bool
expectedBuildConfig *smpb.BuildConfig expectedBuildConfig *smpb.BuildConfig
}{ }{
{ {
@@ -1083,6 +1084,17 @@ func TestBuildConfig(t *testing.T) {
BazelMixedBuild: proto.Bool(true), BazelMixedBuild: proto.Bool(true),
}, },
}, },
{
name: "bazel mixed build from staging mode",
environ: Environment{},
bazelStagingMode: true,
expectedBuildConfig: &smpb.BuildConfig{
ForceUseGoma: proto.Bool(false),
UseGoma: proto.Bool(false),
UseRbe: proto.Bool(false),
BazelMixedBuild: proto.Bool(true),
},
},
{ {
name: "specified targets", name: "specified targets",
environ: Environment{}, environ: Environment{},
@@ -1118,10 +1130,11 @@ func TestBuildConfig(t *testing.T) {
for _, tc := range tests { for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
c := &configImpl{ c := &configImpl{
environ: &tc.environ, environ: &tc.environ,
bazelDevMode: tc.bazelDevMode, bazelDevMode: tc.bazelDevMode,
bazelProdMode: tc.bazelProdMode, bazelProdMode: tc.bazelProdMode,
arguments: tc.arguments, bazelStagingMode: tc.bazelStagingMode,
arguments: tc.arguments,
} }
config := Config{c} config := Config{c}
checkBazelMode(ctx, config) checkBazelMode(ctx, config)

View File

@@ -260,6 +260,9 @@ func bootstrapBlueprint(ctx Context, config Config) {
if config.bazelDevMode { if config.bazelDevMode {
mainSoongBuildExtraArgs = append(mainSoongBuildExtraArgs, "--bazel-mode-dev") mainSoongBuildExtraArgs = append(mainSoongBuildExtraArgs, "--bazel-mode-dev")
} }
if config.bazelStagingMode {
mainSoongBuildExtraArgs = append(mainSoongBuildExtraArgs, "--bazel-mode-staging")
}
mainSoongBuildInvocation := primaryBuilderInvocation( mainSoongBuildInvocation := primaryBuilderInvocation(
config, config,