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

Commit 1ff11b51 authored by LaMont Jones's avatar LaMont Jones Committed by Gerrit Code Review
Browse files

Merge "Allow n2 as a replacement for ninja in builds" into main

parents 9e47dcc5 bee030d3
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -121,6 +121,10 @@ type configImpl struct {
	// There's quite a bit of overlap with module-info.json and soong module graph. We
	// could consider merging them.
	moduleDebugFile string

	// Whether to use n2 instead of ninja.  This is controlled with the
	// environment variable SOONG_USE_N2
	useN2 bool
}

type NinjaWeightListSource uint
@@ -283,6 +287,10 @@ func NewConfig(ctx Context, args ...string) Config {
		ret.moduleDebugFile, _ = filepath.Abs(shared.JoinPath(ret.SoongOutDir(), "soong-debug-info.json"))
	}

	if os.Getenv("SOONG_USE_N2") == "true" {
		ret.useN2 = true
	}

	ret.environ.Unset(
		// We're already using it
		"USE_SOONG_UI",
@@ -339,6 +347,9 @@ func NewConfig(ctx Context, args ...string) Config {

		// We read it here already, don't let others share in the fun
		"GENERATE_SOONG_DEBUG",

		// Use config.useN2 instead.
		"SOONG_USE_N2",
	)

	if ret.UseGoma() || ret.ForceUseGoma() {
+37 −11
Original line number Diff line number Diff line
@@ -56,6 +56,17 @@ func runNinjaForBuild(ctx Context, config Config) {
		"-d", "stats",
		"--frontend_file", fifo,
	}
	if config.useN2 {
		executable = config.PrebuiltBuildTool("n2")
		args = []string{
			"-d", "trace",
			// TODO: implement these features, or remove them.
			//"-d", "keepdepfile",
			//"-d", "keeprsp",
			//"-d", "stats",
			"--frontend-file", fifo,
		}
	}

	args = append(args, config.NinjaArgs()...)

@@ -72,18 +83,22 @@ func runNinjaForBuild(ctx Context, config Config) {

	args = append(args, "-f", config.CombinedNinjaFile())

	if !config.useN2 {
		args = append(args,
			"-o", "usesphonyoutputs=yes",
			"-w", "dupbuild=err",
			"-w", "missingdepfile=err")
	}

	if !config.BuildBrokenMissingOutputs() {
		// Missing outputs will be treated as errors.
		// BUILD_BROKEN_MISSING_OUTPUTS can be used to bypass this check.
		if !config.useN2 {
			args = append(args,
				"-w", "missingoutfile=err",
			)
		}
	}

	cmd := Command(ctx, config, "ninja", executable, args...)

@@ -97,17 +112,23 @@ func runNinjaForBuild(ctx Context, config Config) {

	switch config.NinjaWeightListSource() {
	case NINJA_LOG:
		if !config.useN2 {
			cmd.Args = append(cmd.Args, "-o", "usesninjalogasweightlist=yes")
		}
	case EVENLY_DISTRIBUTED:
		// pass empty weight list means ninja considers every tasks's weight as 1(default value).
		if !config.useN2 {
			cmd.Args = append(cmd.Args, "-o", "usesweightlist=/dev/null")
		}
	case EXTERNAL_FILE:
		fallthrough
	case HINT_FROM_SOONG:
		// The weight list is already copied/generated.
		if !config.useN2 {
			ninjaWeightListPath := filepath.Join(config.OutDir(), ninjaWeightListFileName)
			cmd.Args = append(cmd.Args, "-o", "usesweightlist="+ninjaWeightListPath)
		}
	}

	// Allow both NINJA_ARGS and NINJA_EXTRA_ARGS, since both have been
	// used in the past to specify extra ninja arguments.
@@ -206,11 +227,16 @@ func runNinjaForBuild(ctx Context, config Config) {
			// We don't want this build broken flag to cause reanalysis, so allow it through to the
			// actions.
			"BUILD_BROKEN_INCORRECT_PARTITION_IMAGES",
			"SOONG_USE_N2",
			"RUST_BACKTRACE",
		}, config.BuildBrokenNinjaUsesEnvVars()...)...)
	}

	cmd.Environment.Set("DIST_DIR", config.DistDir())
	cmd.Environment.Set("SHELL", "/bin/bash")
	if config.useN2 {
		cmd.Environment.Set("RUST_BACKTRACE", "1")
	}

	// Print the environment variables that Ninja is operating in.
	ctx.Verboseln("Ninja environment: ")
+22 −1
Original line number Diff line number Diff line
@@ -638,6 +638,22 @@ func runSoong(ctx Context, config Config) {
			"--frontend_file", fifo,
			"-f", filepath.Join(config.SoongOutDir(), "bootstrap.ninja"),
		}
		if config.useN2 {
			ninjaArgs = []string{
				// TODO: implement these features, or remove them.
				//"-d", "keepdepfile",
				//"-d", "stats",
				//"-o", "usesphonyoutputs=yes",
				//"-o", "preremoveoutputs=yes",
				//"-w", "dupbuild=err",
				//"-w", "outputdir=err",
				//"-w", "missingoutfile=err",
				"-v",
				"-j", strconv.Itoa(config.Parallel()),
				"--frontend-file", fifo,
				"-f", filepath.Join(config.SoongOutDir(), "bootstrap.ninja"),
			}
		}

		if extra, ok := config.Environment().Get("SOONG_UI_NINJA_ARGS"); ok {
			ctx.Printf(`CAUTION: arguments in $SOONG_UI_NINJA_ARGS=%q, e.g. "-n", can make soong_build FAIL or INCORRECT`, extra)
@@ -645,8 +661,13 @@ func runSoong(ctx Context, config Config) {
		}

		ninjaArgs = append(ninjaArgs, targets...)
		ninjaCmd := config.PrebuiltBuildTool("ninja")
		if config.useN2 {
			ninjaCmd = config.PrebuiltBuildTool("n2")
		}

		cmd := Command(ctx, config, "soong bootstrap",
			config.PrebuiltBuildTool("ninja"), ninjaArgs...)
			ninjaCmd, ninjaArgs...)

		var ninjaEnv Environment