Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0dd067d3 authored by Lukács T. Berki's avatar Lukács T. Berki Committed by Gerrit Code Review
Browse files

Merge changes from topics "remove-blueprint-main", "remove-some-minibp", "remove-srcdir"

* changes:
  Remove Srcdir() from BootstrapConfig.
  Define command line args in soong_build .
  Move bpglob to .bootstrap from .minibootstrap.
parents 860f42c1 f7e36d80
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -28,8 +28,6 @@ import (

	"android/soong/bazel/cquery"

	"github.com/google/blueprint/bootstrap"

	"android/soong/bazel"
	"android/soong/shared"
)
@@ -760,7 +758,7 @@ func (c *bazelSingleton) GenerateBuildActions(ctx SingletonContext) {

	// Add ninja file dependencies for files which all bazel invocations require.
	bazelBuildList := absolutePath(filepath.Join(
		filepath.Dir(bootstrap.CmdlineArgs.ModuleListFile), "bazel.list"))
		filepath.Dir(ctx.Config().moduleListFile), "bazel.list"))
	ctx.AddNinjaFileDeps(bazelBuildList)

	data, err := ioutil.ReadFile(bazelBuildList)
+4 −10
Original line number Diff line number Diff line
@@ -79,10 +79,6 @@ func (c Config) DebugCompilation() bool {
	return false // Never compile Go code in the main build for debugging
}

func (c Config) SrcDir() string {
	return c.srcDir
}

// 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
// may be multiple devices being built.
@@ -126,7 +122,6 @@ type config struct {

	deviceConfig *deviceConfig

	srcDir         string // the path of the root source directory
	buildDir       string // the path of the build output directory
	moduleListFile string // the path to the file which lists blueprint files to parse.

@@ -402,7 +397,7 @@ func TestArchConfig(buildDir string, env map[string]string, bp string, fs map[st
// multiple runs in the same program execution is carried over (such as Bazel
// context or environment deps).
func ConfigForAdditionalRun(c Config) (Config, error) {
	newConfig, err := NewConfig(c.srcDir, c.buildDir, c.moduleListFile, c.env)
	newConfig, err := NewConfig(c.buildDir, c.moduleListFile, c.env)
	if err != nil {
		return Config{}, err
	}
@@ -413,14 +408,13 @@ func ConfigForAdditionalRun(c Config) (Config, error) {

// 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.
func NewConfig(srcDir, buildDir string, moduleListFile string, availableEnv map[string]string) (Config, error) {
func NewConfig(buildDir string, moduleListFile string, availableEnv map[string]string) (Config, error) {
	// Make a config with default options.
	config := &config{
		ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName),

		env: availableEnv,

		srcDir:            srcDir,
		buildDir:          buildDir,
		multilibConflicts: make(map[ArchType]bool),

@@ -439,7 +433,7 @@ func NewConfig(srcDir, buildDir string, moduleListFile string, availableEnv map[
		return Config{}, err
	}

	absSrcDir, err := filepath.Abs(srcDir)
	absSrcDir, err := filepath.Abs(".")
	if err != nil {
		return Config{}, err
	}
@@ -597,7 +591,7 @@ func (c *config) PrebuiltOS() string {

// GoRoot returns the path to the root directory of the Go toolchain.
func (c *config) GoRoot() string {
	return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS())
	return fmt.Sprintf("prebuilts/go/%s", c.PrebuiltOS())
}

// PrebuiltBuildTool returns the path to a tool in the prebuilts directory containing
+4 −4
Original line number Diff line number Diff line
@@ -622,7 +622,7 @@ func expandOneSrcPath(ctx ModuleWithDepsPathContext, sPath string, expandedExclu
// It intended for use in globs that only list files that exist, so it allows '$' in
// filenames.
func pathsForModuleSrcFromFullPath(ctx EarlyModulePathContext, paths []string, incDirs bool) Paths {
	prefix := filepath.Join(ctx.Config().srcDir, ctx.ModuleDir()) + "/"
	prefix := ctx.ModuleDir() + "/"
	if prefix == "./" {
		prefix = ""
	}
@@ -658,7 +658,7 @@ func PathsWithOptionalDefaultForModuleSrc(ctx ModuleMissingDepsPathContext, inpu
	}
	// Use Glob so that if the default doesn't exist, a dependency is added so that when it
	// is created, we're run again.
	path := filepath.Join(ctx.Config().srcDir, ctx.ModuleDir(), def)
	path := filepath.Join(ctx.ModuleDir(), def)
	return Glob(ctx, path, nil)
}

@@ -986,7 +986,7 @@ func (p SourcePath) withRel(rel string) SourcePath {
// code that is embedding ninja variables in paths
func safePathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error) {
	p, err := validateSafePath(pathComponents...)
	ret := SourcePath{basePath{p, ""}, ctx.Config().srcDir}
	ret := SourcePath{basePath{p, ""}, "."}
	if err != nil {
		return ret, err
	}
@@ -1002,7 +1002,7 @@ func safePathForSource(ctx PathContext, pathComponents ...string) (SourcePath, e
// pathForSource creates a SourcePath from pathComponents, but does not check that it exists.
func pathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error) {
	p, err := validatePath(pathComponents...)
	ret := SourcePath{basePath{p, ""}, ctx.Config().srcDir}
	ret := SourcePath{basePath{p, ""}, "."}
	if err != nil {
		return ret, err
	}
+34 −19
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ var (
	docFile           string
	bazelQueryViewDir string
	bp2buildMarker    string

	cmdlineArgs bootstrap.Args
)

func init() {
@@ -61,6 +63,21 @@ func init() {
	flag.StringVar(&docFile, "soong_docs", "", "build documentation file to output")
	flag.StringVar(&bazelQueryViewDir, "bazel_queryview_dir", "", "path to the bazel queryview directory relative to --top")
	flag.StringVar(&bp2buildMarker, "bp2build_marker", "", "If set, run bp2build, touch the specified marker file then exit")

	flag.StringVar(&cmdlineArgs.OutFile, "o", "build.ninja", "the Ninja file to output")
	flag.StringVar(&cmdlineArgs.GlobFile, "globFile", "build-globs.ninja", "the Ninja file of globs to output")
	flag.StringVar(&cmdlineArgs.GlobListDir, "globListDir", "", "the directory containing the glob list files")
	flag.StringVar(&cmdlineArgs.BuildDir, "b", ".", "the build output directory")
	flag.StringVar(&cmdlineArgs.NinjaBuildDir, "n", "", "the ninja builddir directory")
	flag.StringVar(&cmdlineArgs.DepFile, "d", "", "the dependency file to output")
	flag.StringVar(&cmdlineArgs.Cpuprofile, "cpuprofile", "", "write cpu profile to file")
	flag.StringVar(&cmdlineArgs.TraceFile, "trace", "", "write trace to file")
	flag.StringVar(&cmdlineArgs.Memprofile, "memprofile", "", "write memory profile to file")
	flag.BoolVar(&cmdlineArgs.NoGC, "nogc", false, "turn off GC for debugging")
	flag.BoolVar(&cmdlineArgs.RunGoTests, "t", false, "build and run go tests during bootstrap")
	flag.BoolVar(&cmdlineArgs.UseValidations, "use-validations", false, "use validations to depend on go tests")
	flag.StringVar(&cmdlineArgs.ModuleListFile, "l", "", "file that lists filepaths to parse")
	flag.BoolVar(&cmdlineArgs.EmptyNinjaFile, "empty-ninja-file", false, "write out a 0-byte ninja file")
}

func newNameResolver(config android.Config) *android.NameResolver {
@@ -90,8 +107,8 @@ func newContext(configuration android.Config, prepareBuildActions bool) *android
	return ctx
}

func newConfig(srcDir, outDir string, availableEnv map[string]string) android.Config {
	configuration, err := android.NewConfig(srcDir, outDir, bootstrap.CmdlineArgs.ModuleListFile, availableEnv)
func newConfig(outDir string, availableEnv map[string]string) android.Config {
	configuration, err := android.NewConfig(outDir, cmdlineArgs.ModuleListFile, availableEnv)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s", err)
		os.Exit(1)
@@ -107,7 +124,7 @@ func newConfig(srcDir, outDir string, availableEnv map[string]string) android.Co
func runMixedModeBuild(configuration android.Config, firstCtx *android.Context, extraNinjaDeps []string) {
	var firstArgs, secondArgs bootstrap.Args

	firstArgs = bootstrap.CmdlineArgs
	firstArgs = cmdlineArgs
	configuration.SetStopBefore(bootstrap.StopBeforeWriteNinja)
	bootstrap.RunBlueprint(firstArgs, firstCtx.Context, configuration)

@@ -123,7 +140,7 @@ func runMixedModeBuild(configuration android.Config, firstCtx *android.Context,
		os.Exit(1)
	}
	secondCtx := newContext(secondConfig, true)
	secondArgs = bootstrap.CmdlineArgs
	secondArgs = cmdlineArgs
	ninjaDeps := bootstrap.RunBlueprint(secondArgs, secondCtx.Context, secondConfig)
	ninjaDeps = append(ninjaDeps, extraNinjaDeps...)
	err = deptools.WriteDepFile(shared.JoinPath(topDir, secondArgs.DepFile), secondArgs.OutFile, ninjaDeps)
@@ -145,7 +162,7 @@ func runQueryView(configuration android.Config, ctx *android.Context) {

func runSoongDocs(configuration android.Config) {
	ctx := newContext(configuration, false)
	soongDocsArgs := bootstrap.CmdlineArgs
	soongDocsArgs := cmdlineArgs
	bootstrap.RunBlueprint(soongDocsArgs, ctx.Context, configuration)
	if err := writeDocs(ctx, configuration, docFile); err != nil {
		fmt.Fprintf(os.Stderr, "%s", err)
@@ -183,7 +200,7 @@ func doChosenActivity(configuration android.Config, extraNinjaDeps []string) str
	generateQueryView := bazelQueryViewDir != ""
	jsonModuleFile := configuration.Getenv("SOONG_DUMP_JSON_MODULE_GRAPH")

	blueprintArgs := bootstrap.CmdlineArgs
	blueprintArgs := cmdlineArgs
	prepareBuildActions := !generateQueryView && jsonModuleFile == ""
	if bazelConversionRequested {
		// Run the alternate pipeline of bp2build mutators and singleton to convert
@@ -208,16 +225,16 @@ func doChosenActivity(configuration android.Config, extraNinjaDeps []string) str
	// Convert the Soong module graph into Bazel BUILD files.
	if generateQueryView {
		runQueryView(configuration, ctx)
		return bootstrap.CmdlineArgs.OutFile // TODO: This is a lie
		return cmdlineArgs.OutFile // TODO: This is a lie
	}

	if jsonModuleFile != "" {
		writeJsonModuleGraph(configuration, ctx, jsonModuleFile, extraNinjaDeps)
		return bootstrap.CmdlineArgs.OutFile // TODO: This is a lie
		return cmdlineArgs.OutFile // TODO: This is a lie
	}

	writeMetrics(configuration)
	return bootstrap.CmdlineArgs.OutFile
	return cmdlineArgs.OutFile
}

// soong_ui dumps the available environment variables to
@@ -256,9 +273,7 @@ func main() {

	availableEnv := parseAvailableEnv()

	// The top-level Blueprints file is passed as the first argument.
	srcDir := filepath.Dir(flag.Arg(0))
	configuration := newConfig(srcDir, outDir, availableEnv)
	configuration := newConfig(outDir, availableEnv)
	extraNinjaDeps := []string{
		configuration.ProductVariablesFileName,
		usedEnvFile,
@@ -420,7 +435,7 @@ func getTemporaryExcludes() []string {
// Read the bazel.list file that the Soong Finder already dumped earlier (hopefully)
// It contains the locations of BUILD files, BUILD.bazel files, etc. in the source dir
func getExistingBazelRelatedFiles(topDir string) ([]string, error) {
	bazelFinderFile := filepath.Join(filepath.Dir(bootstrap.CmdlineArgs.ModuleListFile), "bazel.list")
	bazelFinderFile := filepath.Join(filepath.Dir(cmdlineArgs.ModuleListFile), "bazel.list")
	if !filepath.IsAbs(bazelFinderFile) {
		// Assume this was a relative path under topDir
		bazelFinderFile = filepath.Join(topDir, bazelFinderFile)
@@ -451,8 +466,8 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) {
	// Android.bp files. It must not depend on the values of per-build product
	// configurations or variables, since those will generate different BUILD
	// files based on how the user has configured their tree.
	bp2buildCtx.SetModuleListFile(bootstrap.CmdlineArgs.ModuleListFile)
	modulePaths, err := bp2buildCtx.ListModulePaths(configuration.SrcDir())
	bp2buildCtx.SetModuleListFile(cmdlineArgs.ModuleListFile)
	modulePaths, err := bp2buildCtx.ListModulePaths(".")
	if err != nil {
		panic(err)
	}
@@ -465,7 +480,7 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) {
	// Run the loading and analysis pipeline to prepare the graph of regular
	// Modules parsed from Android.bp files, and the BazelTargetModules mapped
	// from the regular Modules.
	blueprintArgs := bootstrap.CmdlineArgs
	blueprintArgs := cmdlineArgs
	ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, bp2buildCtx.Context, configuration)
	ninjaDeps = append(ninjaDeps, extraNinjaDeps...)

@@ -493,8 +508,8 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) {
		"bazel-" + filepath.Base(topDir),
	}

	if bootstrap.CmdlineArgs.NinjaBuildDir[0] != '/' {
		excludes = append(excludes, bootstrap.CmdlineArgs.NinjaBuildDir)
	if cmdlineArgs.NinjaBuildDir[0] != '/' {
		excludes = append(excludes, cmdlineArgs.NinjaBuildDir)
	}

	existingBazelRelatedFiles, err := getExistingBazelRelatedFiles(topDir)
@@ -509,7 +524,7 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) {
	excludes = append(excludes, getTemporaryExcludes()...)

	symlinkForestDeps := bp2build.PlantSymlinkForest(
		topDir, workspaceRoot, generatedRoot, configuration.SrcDir(), excludes)
		topDir, workspaceRoot, generatedRoot, ".", excludes)

	// Only report metrics when in bp2build mode. The metrics aren't relevant
	// for queryview, since that's a total repo-wide conversion and there's a
+4 −12
Original line number Diff line number Diff line
@@ -71,16 +71,11 @@ 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
// probably be nicer to use a flag in bootstrap.Args instead.
type BlueprintConfig struct {
	srcDir           string
	buildDir         string
	ninjaBuildDir    string
	debugCompilation bool
}

func (c BlueprintConfig) SrcDir() string {
	return "."
}

func (c BlueprintConfig) BuildDir() string {
	return c.buildDir
}
@@ -194,7 +189,6 @@ func bootstrapBlueprint(ctx Context, config Config) {
	blueprintCtx := blueprint.NewContext()
	blueprintCtx.SetIgnoreUnknownModuleTypes(true)
	blueprintConfig := BlueprintConfig{
		srcDir:           os.Getenv("TOP"),
		buildDir:         config.SoongOutDir(),
		ninjaBuildDir:    config.OutDir(),
		debugCompilation: os.Getenv("SOONG_DELVE") != "",
@@ -227,12 +221,10 @@ func runSoong(ctx Context, config Config) {
	// unused variables were changed?
	envFile := filepath.Join(config.SoongOutDir(), availableEnvFile)

	for _, n := range []string{".bootstrap", ".minibootstrap"} {
		dir := filepath.Join(config.SoongOutDir(), n)
	dir := filepath.Join(config.SoongOutDir(), ".bootstrap")
	if err := os.MkdirAll(dir, 0755); err != nil {
		ctx.Fatalf("Cannot mkdir " + dir)
	}
	}

	buildMode := config.bazelBuildMode()
	integratedBp2Build := (buildMode == mixedBuild) || (buildMode == generateBuildFiles)
@@ -272,7 +264,7 @@ func runSoong(ctx Context, config Config) {
		}
	}()

	runMicrofactory(ctx, config, ".minibootstrap/bpglob", "github.com/google/blueprint/bootstrap/bpglob",
	runMicrofactory(ctx, config, ".bootstrap/bpglob", "github.com/google/blueprint/bootstrap/bpglob",
		map[string]string{"github.com/google/blueprint": "build/blueprint"})

	ninja := func(name, ninjaFile string, targets ...string) {
Loading