Remove the bootstrap.Config class.

It was confusing because bootstrapping uses two configurations: the
"global" config and the special-cased bootstrap one.

This change merges them.

Test: Presubmits.
Change-Id: I82b482cbe28a343ab6991374b2a28667e1a06b48
This commit is contained in:
Lukacs T. Berki
2021-09-02 09:58:09 +02:00
parent 7686708a43
commit ea1a31c07f
3 changed files with 64 additions and 19 deletions

View File

@@ -75,10 +75,26 @@ func (c Config) OutDir() string {
return c.soongOutDir return c.soongOutDir
} }
func (c Config) RunGoTests() bool {
return c.runGoTests
}
func (c Config) UseValidationsForGoTests() bool {
return c.useValidationsForGoTests
}
func (c Config) DebugCompilation() bool { func (c Config) DebugCompilation() bool {
return false // Never compile Go code in the main build for debugging return false // Never compile Go code in the main build for debugging
} }
func (c Config) Subninjas() []string {
return []string{}
}
func (c Config) PrimaryBuilderInvocations() []bootstrap.PrimaryBuilderInvocation {
return []bootstrap.PrimaryBuilderInvocation{}
}
// A DeviceConfig object represents the configuration for a particular device // A DeviceConfig object represents the configuration for a particular device
// being built. For now there will only be one of these, but in the future there // being built. For now there will only be one of these, but in the future there
// may be multiple devices being built. // may be multiple devices being built.
@@ -125,6 +141,9 @@ type config struct {
soongOutDir string // the path of the build output directory soongOutDir string // the path of the build output directory
moduleListFile string // the path to the file which lists blueprint files to parse. moduleListFile string // the path to the file which lists blueprint files to parse.
runGoTests bool
useValidationsForGoTests bool
env map[string]string env map[string]string
envLock sync.Mutex envLock sync.Mutex
envDeps map[string]string envDeps map[string]string
@@ -396,8 +415,8 @@ func TestArchConfig(buildDir string, env map[string]string, bp string, fs map[st
// bootstrap run. Only per-run data is reset. Data which needs to persist across // bootstrap run. Only per-run data is reset. Data which needs to persist across
// multiple runs in the same program execution is carried over (such as Bazel // multiple runs in the same program execution is carried over (such as Bazel
// context or environment deps). // context or environment deps).
func ConfigForAdditionalRun(c Config) (Config, error) { func ConfigForAdditionalRun(cmdlineArgs bootstrap.Args, c Config) (Config, error) {
newConfig, err := NewConfig(c.soongOutDir, c.moduleListFile, c.env) newConfig, err := NewConfig(cmdlineArgs, c.soongOutDir, c.env)
if err != nil { if err != nil {
return Config{}, err return Config{}, err
} }
@@ -408,17 +427,19 @@ func ConfigForAdditionalRun(c Config) (Config, error) {
// NewConfig creates a new Config object. The srcDir argument specifies the path // NewConfig creates a new Config object. The srcDir argument specifies the path
// to the root source directory. It also loads the config file, if found. // to the root source directory. It also loads the config file, if found.
func NewConfig(soongOutDir string, moduleListFile string, availableEnv map[string]string) (Config, error) { func NewConfig(cmdlineArgs bootstrap.Args, soongOutDir string, availableEnv map[string]string) (Config, error) {
// Make a config with default options. // Make a config with default options.
config := &config{ config := &config{
ProductVariablesFileName: filepath.Join(soongOutDir, productVariablesFileName), ProductVariablesFileName: filepath.Join(soongOutDir, productVariablesFileName),
env: availableEnv, env: availableEnv,
soongOutDir: soongOutDir, soongOutDir: soongOutDir,
multilibConflicts: make(map[ArchType]bool), runGoTests: cmdlineArgs.RunGoTests,
useValidationsForGoTests: cmdlineArgs.UseValidations,
multilibConflicts: make(map[ArchType]bool),
moduleListFile: moduleListFile, moduleListFile: cmdlineArgs.ModuleListFile,
fs: pathtools.NewOsFs(absSrcDir), fs: pathtools.NewOsFs(absSrcDir),
} }

View File

@@ -113,8 +113,8 @@ func newContext(configuration android.Config, prepareBuildActions bool) *android
return ctx return ctx
} }
func newConfig(outDir string, availableEnv map[string]string) android.Config { func newConfig(cmdlineArgs bootstrap.Args, outDir string, availableEnv map[string]string) android.Config {
configuration, err := android.NewConfig(outDir, cmdlineArgs.ModuleListFile, availableEnv) configuration, err := android.NewConfig(cmdlineArgs, outDir, availableEnv)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "%s", err) fmt.Fprintf(os.Stderr, "%s", err)
os.Exit(1) os.Exit(1)
@@ -140,13 +140,13 @@ func runMixedModeBuild(configuration android.Config, firstCtx *android.Context,
os.Exit(1) os.Exit(1)
} }
// Second pass: Full analysis, using the bazel command results. Output ninja file. // Second pass: Full analysis, using the bazel command results. Output ninja file.
secondConfig, err := android.ConfigForAdditionalRun(configuration) secondArgs = cmdlineArgs
secondConfig, err := android.ConfigForAdditionalRun(secondArgs, configuration)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "%s", err) fmt.Fprintf(os.Stderr, "%s", err)
os.Exit(1) os.Exit(1)
} }
secondCtx := newContext(secondConfig, true) secondCtx := newContext(secondConfig, true)
secondArgs = cmdlineArgs
ninjaDeps := bootstrap.RunBlueprint(secondArgs, secondCtx.Context, secondConfig) ninjaDeps := bootstrap.RunBlueprint(secondArgs, secondCtx.Context, secondConfig)
ninjaDeps = append(ninjaDeps, extraNinjaDeps...) ninjaDeps = append(ninjaDeps, extraNinjaDeps...)
@@ -298,7 +298,7 @@ func main() {
availableEnv := parseAvailableEnv() availableEnv := parseAvailableEnv()
configuration := newConfig(outDir, availableEnv) configuration := newConfig(cmdlineArgs, outDir, availableEnv)
extraNinjaDeps := []string{ extraNinjaDeps := []string{
configuration.ProductVariablesFileName, configuration.ProductVariablesFileName,
usedEnvFile, usedEnvFile,

View File

@@ -71,10 +71,14 @@ func writeEnvironmentFile(ctx Context, envFile string, envDeps map[string]string
// A tiny struct used to tell Blueprint that it's in bootstrap mode. It would // A tiny struct used to tell Blueprint that it's in bootstrap mode. It would
// probably be nicer to use a flag in bootstrap.Args instead. // probably be nicer to use a flag in bootstrap.Args instead.
type BlueprintConfig struct { type BlueprintConfig struct {
toolDir string toolDir string
soongOutDir string soongOutDir string
outDir string outDir string
debugCompilation bool runGoTests bool
useValidations bool
debugCompilation bool
subninjas []string
primaryBuilderInvocations []bootstrap.PrimaryBuilderInvocation
} }
func (c BlueprintConfig) HostToolDir() string { func (c BlueprintConfig) HostToolDir() string {
@@ -89,10 +93,26 @@ func (c BlueprintConfig) OutDir() string {
return c.outDir return c.outDir
} }
func (c BlueprintConfig) RunGoTests() bool {
return c.runGoTests
}
func (c BlueprintConfig) UseValidationsForGoTests() bool {
return c.useValidations
}
func (c BlueprintConfig) DebugCompilation() bool { func (c BlueprintConfig) DebugCompilation() bool {
return c.debugCompilation return c.debugCompilation
} }
func (c BlueprintConfig) Subninjas() []string {
return c.subninjas
}
func (c BlueprintConfig) PrimaryBuilderInvocations() []bootstrap.PrimaryBuilderInvocation {
return c.primaryBuilderInvocations
}
func environmentArgs(config Config, suffix string) []string { func environmentArgs(config Config, suffix string) []string {
return []string{ return []string{
"--available_env", shared.JoinPath(config.SoongOutDir(), availableEnvFile), "--available_env", shared.JoinPath(config.SoongOutDir(), availableEnvFile),
@@ -211,10 +231,14 @@ func bootstrapBlueprint(ctx Context, config Config) {
blueprintCtx := blueprint.NewContext() blueprintCtx := blueprint.NewContext()
blueprintCtx.SetIgnoreUnknownModuleTypes(true) blueprintCtx.SetIgnoreUnknownModuleTypes(true)
blueprintConfig := BlueprintConfig{ blueprintConfig := BlueprintConfig{
soongOutDir: config.SoongOutDir(), soongOutDir: config.SoongOutDir(),
toolDir: config.HostToolDir(), toolDir: config.HostToolDir(),
outDir: config.OutDir(), outDir: config.OutDir(),
debugCompilation: os.Getenv("SOONG_DELVE") != "", runGoTests: !config.skipSoongTests,
useValidations: true,
debugCompilation: os.Getenv("SOONG_DELVE") != "",
subninjas: args.Subninjas,
primaryBuilderInvocations: args.PrimaryBuilderInvocations,
} }
args.EmptyNinjaFile = false args.EmptyNinjaFile = false