diff options
author | 2025-02-13 10:10:18 -0800 | |
---|---|---|
committer | 2025-02-13 10:10:18 -0800 | |
commit | cc5cf314dde14d579d8b347f09ca485be4c40d80 (patch) | |
tree | e4091daddff1da87489d41ac36ff289192a74d27 | |
parent | e9be6473d5178e395e50859b650b29365dafe738 (diff) | |
parent | 6d8fc1058d81e2e989c82b8e1e0c53278a3fb8f1 (diff) |
Merge changes from topic "partial-compile-clean" into main
* changes:
config: make partialCompileFlags visible
Add partialcompileclean phony
Add PhonyOutput to BuildParams
-rw-r--r-- | android/config.go | 12 | ||||
-rw-r--r-- | android/config_test.go | 4 | ||||
-rw-r--r-- | android/module.go | 3 | ||||
-rw-r--r-- | android/module_context.go | 3 | ||||
-rw-r--r-- | ui/build/build.go | 1 | ||||
-rw-r--r-- | ui/build/cleanbuild.go | 46 | ||||
-rw-r--r-- | ui/build/config.go | 4 | ||||
-rw-r--r-- | ui/build/ninja.go | 12 |
8 files changed, 75 insertions, 10 deletions
diff --git a/android/config.go b/android/config.go index eda8e718a..acaad60ad 100644 --- a/android/config.go +++ b/android/config.go @@ -386,10 +386,10 @@ type config struct { type partialCompileFlags struct { // Is partial compilation enabled at all? - enabled bool + Enabled bool // Whether to use d8 instead of r8 - use_d8 bool + Use_d8 bool // Add others as needed. } @@ -429,7 +429,7 @@ type jsonConfigurable interface { // switch statement below. var defaultPartialCompileFlags = partialCompileFlags{ // Set any opt-out flags here. Opt-in flags are off by default. - enabled: false, + Enabled: false, } func (c *config) parsePartialCompileFlags(isEngBuild bool) (partialCompileFlags, error) { @@ -473,14 +473,14 @@ func (c *config) parsePartialCompileFlags(isEngBuild bool) (partialCompileFlags, switch tok { case "true": ret = defaultPartialCompileFlags - ret.enabled = true + ret.Enabled = true case "false": // Set everything to false. ret = partialCompileFlags{} case "enabled": - ret.enabled = makeVal(state, defaultPartialCompileFlags.enabled) + ret.Enabled = makeVal(state, defaultPartialCompileFlags.Enabled) case "use_d8": - ret.use_d8 = makeVal(state, defaultPartialCompileFlags.use_d8) + ret.Use_d8 = makeVal(state, defaultPartialCompileFlags.Use_d8) default: return partialCompileFlags{}, fmt.Errorf("Unknown SOONG_PARTIAL_COMPILE value: %v", tok) } diff --git a/android/config_test.go b/android/config_test.go index 4fdcc9ca4..4bdf05f0e 100644 --- a/android/config_test.go +++ b/android/config_test.go @@ -214,12 +214,12 @@ func TestConfiguredJarList(t *testing.T) { } func (p partialCompileFlags) updateEnabled(value bool) partialCompileFlags { - p.enabled = value + p.Enabled = value return p } func (p partialCompileFlags) updateUseD8(value bool) partialCompileFlags { - p.use_d8 = value + p.Use_d8 = value return p } diff --git a/android/module.go b/android/module.go index 3295e93be..578e1889c 100644 --- a/android/module.go +++ b/android/module.go @@ -3001,6 +3001,9 @@ func AddAncestors(ctx SingletonContext, dirMap map[string]Paths, mmName func(str func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) { var checkbuildDeps Paths + // Create a top level partialcompileclean target for modules to add dependencies to. + ctx.Phony("partialcompileclean") + mmTarget := func(dir string) string { return "MODULES-IN-" + strings.Replace(filepath.Clean(dir), "/", "-", -1) } diff --git a/android/module_context.go b/android/module_context.go index 45a8e5c7a..fe9429c9d 100644 --- a/android/module_context.go +++ b/android/module_context.go @@ -81,6 +81,8 @@ type BuildParams struct { Default bool // Args is a key value mapping for replacements of variables within the Rule Args map[string]string + // PhonyOutput marks this build as `phony_output = true` + PhonyOutput bool } type ModuleBuildParams BuildParams @@ -369,6 +371,7 @@ func convertBuildParams(params BuildParams) blueprint.BuildParams { Validations: params.Validations.Strings(), Args: params.Args, Default: params.Default, + PhonyOutput: params.PhonyOutput, } if params.Depfile != nil { diff --git a/ui/build/build.go b/ui/build/build.go index 95d7831d2..781ca182f 100644 --- a/ui/build/build.go +++ b/ui/build/build.go @@ -401,6 +401,7 @@ func Build(ctx Context, config Config) { if what&RunKati != 0 { installCleanIfNecessary(ctx, config) } + partialCompileCleanIfNecessary(ctx, config) runNinjaForBuild(ctx, config) updateBuildIdDir(ctx, config) } diff --git a/ui/build/cleanbuild.go b/ui/build/cleanbuild.go index 41cb5ab6d..723d90fa3 100644 --- a/ui/build/cleanbuild.go +++ b/ui/build/cleanbuild.go @@ -218,6 +218,52 @@ func installCleanIfNecessary(ctx Context, config Config) { writeConfig() } +// When SOONG_USE_PARTIAL_COMPILE transitions from on to off, we need to remove +// all files which were potentially built with partial compile, so that they +// get rebuilt with that turned off. +func partialCompileCleanIfNecessary(ctx Context, config Config) { + configFile := config.DevicePreviousUsePartialCompile() + currentValue, _ := config.Environment().Get("SOONG_USE_PARTIAL_COMPILE") + + ensureDirectoriesExist(ctx, filepath.Dir(configFile)) + + writeValue := func() { + err := ioutil.WriteFile(configFile, []byte(currentValue), 0666) // a+rw + if err != nil { + ctx.Fatalln("Failed to write use partial compile config:", err) + } + } + + previousValueBytes, err := ioutil.ReadFile(configFile) + if err != nil { + if os.IsNotExist(err) { + // Just write the new config file, no old config file to worry about. + writeValue() + return + } else { + ctx.Fatalln("Failed to read previous use partial compile config:", err) + } + } + + previousValue := string(previousValueBytes) + switch previousValue { + case currentValue: + // Same value as before - nothing left to do here. + return + case "true": + // Transitioning from on to off. Build (phony) target: partialcompileclean. + ctx.BeginTrace(metrics.PrimaryNinja, "partialcompileclean") + defer ctx.EndTrace() + + ctx.Printf("SOONG_USE_PARTIAL_COMPILE turned off, forcing partialcompileclean\n") + + runNinja(ctx, config, []string{"partialcompileclean"}) + default: + // Transitioning from off to on. Nothing to do in this case. + } + writeValue() +} + // cleanOldFiles takes an input file (with all paths relative to basePath), and removes files from // the filesystem if they were removed from the input file since the last execution. func cleanOldFiles(ctx Context, basePath, newFile string) { diff --git a/ui/build/config.go b/ui/build/config.go index 2a00c4124..a4f778d74 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -1685,6 +1685,10 @@ func (c *configImpl) DevicePreviousProductConfig() string { return filepath.Join(c.ProductOut(), "previous_build_config.mk") } +func (c *configImpl) DevicePreviousUsePartialCompile() string { + return filepath.Join(c.ProductOut(), "previous_use_partial_compile.txt") +} + func (c *configImpl) KatiPackageMkDir() string { return filepath.Join(c.SoongOutDir(), "kati_packaging"+c.KatiSuffix()) } diff --git a/ui/build/ninja.go b/ui/build/ninja.go index 1d4285f2c..e2a568fad 100644 --- a/ui/build/ninja.go +++ b/ui/build/ninja.go @@ -36,10 +36,16 @@ const ( ninjaWeightListFileName = ".ninja_weight_list" ) +// Runs ninja with the arguments from the command line, as found in +// config.NinjaArgs(). +func runNinjaForBuild(ctx Context, config Config) { + runNinja(ctx, config, config.NinjaArgs()) +} + // Constructs and runs the Ninja command line with a restricted set of // environment variables. It's important to restrict the environment Ninja runs // for hermeticity reasons, and to avoid spurious rebuilds. -func runNinjaForBuild(ctx Context, config Config) { +func runNinja(ctx Context, config Config, ninjaArgs []string) { ctx.BeginTrace(metrics.PrimaryNinja, "ninja") defer ctx.EndTrace() @@ -88,7 +94,7 @@ func runNinjaForBuild(ctx Context, config Config) { "-w", "missingdepfile=err", } } - args = append(args, config.NinjaArgs()...) + args = append(args, ninjaArgs...) var parallel int if config.UseRemoteBuild() { @@ -244,6 +250,8 @@ func runNinjaForBuild(ctx Context, config Config) { "RUST_LOG", // SOONG_USE_PARTIAL_COMPILE only determines which half of the rule we execute. + // When it transitions true => false, we build phony target "partialcompileclean", + // which removes all files that could have been created while it was true. "SOONG_USE_PARTIAL_COMPILE", // Directory for ExecutionMetrics |