diff options
author | Dan Willemsen <dwillemsen@google.com> | 2017-05-12 19:28:13 -0700 |
---|---|---|
committer | Dan Willemsen <dwillemsen@google.com> | 2017-05-15 16:26:21 -0700 |
commit | 02781d59bb336827b3cf732278eeac121442034d (patch) | |
tree | e54ab052536054e3f425e3ebc202b9fb60cc66e7 /ui | |
parent | db8457cfecde2940690b577852528c5da01e3f5b (diff) | |
download | build_soong-02781d59bb336827b3cf732278eeac121442034d.tar.gz build_soong-02781d59bb336827b3cf732278eeac121442034d.tar.bz2 build_soong-02781d59bb336827b3cf732278eeac121442034d.zip |
Move auto installclean to soong_ui
This way kati won't need to be run as often (either initially, or when
switching products with the same device).
Bug: 35970961
Test: m clean; m -j blueprint_tools; m -j blueprint_tools; m -j blueprint_tools
Test: lunch aosp_arm-eng; m -j blueprint_tools; lunch full-eng; m -j blueprint_tools; <repeat>
Change-Id: Ie9fca3c8f1dd412459ea47c7090c7c5fdb0bcf6e
Diffstat (limited to 'ui')
-rw-r--r-- | ui/build/build.go | 59 | ||||
-rw-r--r-- | ui/build/config.go | 42 | ||||
-rw-r--r-- | ui/build/make.go | 5 |
3 files changed, 103 insertions, 3 deletions
diff --git a/ui/build/build.go b/ui/build/build.go index b84dd7d7..598e342d 100644 --- a/ui/build/build.go +++ b/ui/build/build.go @@ -18,6 +18,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" "text/template" ) @@ -91,6 +92,62 @@ func checkCaseSensitivity(ctx Context, config Config) { } } +// Since products and build variants (unfortunately) shared the same +// PRODUCT_OUT staging directory, things can get out of sync if different +// build configurations are built in the same tree. This function will +// notice when the configuration has changed and call installclean to +// remove the files necessary to keep things consistent. +func installcleanIfNecessary(ctx Context, config Config) { + if inList("installclean", config.Arguments()) { + return + } + + configFile := config.DevicePreviousProductConfig() + prefix := "PREVIOUS_BUILD_CONFIG := " + suffix := "\n" + currentProduct := prefix + config.TargetProduct() + "-" + config.TargetBuildVariant() + suffix + + writeConfig := func() { + err := ioutil.WriteFile(configFile, []byte(currentProduct), 0777) + if err != nil { + ctx.Fatalln("Failed to write product config:", err) + } + } + + prev, err := ioutil.ReadFile(configFile) + if err != nil { + if os.IsNotExist(err) { + writeConfig() + return + } else { + ctx.Fatalln("Failed to read previous product config:", err) + } + } else if string(prev) == currentProduct { + return + } + + if disable, _ := config.Environment().Get("DISABLE_AUTO_INSTALLCLEAN"); disable == "true" { + ctx.Println("DISABLE_AUTO_INSTALLCLEAN is set; skipping auto-clean. Your tree may be in an inconsistent state.") + return + } + + ctx.BeginTrace("installclean") + defer ctx.EndTrace() + + prevConfig := strings.TrimPrefix(strings.TrimSuffix(string(prev), suffix), prefix) + currentConfig := strings.TrimPrefix(strings.TrimSuffix(currentProduct, suffix), prefix) + + ctx.Printf("Build configuration changed: %q -> %q, forcing installclean\n", prevConfig, currentConfig) + + cleanConfig := CopyConfig(ctx, config, "installclean") + cleanConfig.SetKatiArgs([]string{"installclean"}) + cleanConfig.SetNinjaArgs([]string{"installclean"}) + + Build(ctx, cleanConfig, BuildKati|BuildNinja) + + writeConfig() +} + // Build the tree. The 'what' argument can be used to chose which components of // the build to run. func Build(ctx Context, config Config, what int) { @@ -145,6 +202,8 @@ func Build(ctx Context, config Config, what int) { } if what&BuildNinja != 0 { + installcleanIfNecessary(ctx, config) + // Write combined ninja file createCombinedBuildNinjaFile(ctx, config) diff --git a/ui/build/config.go b/ui/build/config.go index 0d299243..51cff506 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -38,9 +38,10 @@ type configImpl struct { dist bool // From the product config - katiArgs []string - ninjaArgs []string - katiSuffix string + katiArgs []string + ninjaArgs []string + katiSuffix string + targetDevice string } const srcDirFileCheck = "build/soong/root.bp" @@ -166,6 +167,22 @@ func NewConfig(ctx Context, args ...string) Config { return Config{ret} } +// CopyConfig copies the configuration from an existing configuration, but replaces +// the Arguments() list with a new set. Useful if you need to run a different build +// with the same state as an existing build config. +func CopyConfig(ctx Context, config Config, args ...string) Config { + return Config{&configImpl{ + arguments: args, + goma: config.goma, + environ: config.environ.Copy(), + + parallel: config.parallel, + keepGoing: config.keepGoing, + verbose: config.verbose, + dist: config.dist, + }} +} + // Lunch configures the environment for a specific product similarly to the // `lunch` bash function. func (c *configImpl) Lunch(ctx Context, product, variant string) { @@ -271,6 +288,21 @@ func (c *configImpl) TargetProduct() string { panic("TARGET_PRODUCT is not defined") } +func (c *configImpl) TargetDevice() string { + return c.targetDevice +} + +func (c *configImpl) SetTargetDevice(device string) { + c.targetDevice = device +} + +func (c *configImpl) TargetBuildVariant() string { + if v, ok := c.environ.Get("TARGET_BUILD_VARIANT"); ok { + return v + } + panic("TARGET_BUILD_VARIANT is not defined") +} + func (c *configImpl) KatiArgs() []string { return c.katiArgs } @@ -337,6 +369,10 @@ func (c *configImpl) SoongMakeVarsMk() string { return filepath.Join(c.SoongOutDir(), "make_vars-"+c.TargetProduct()+".mk") } +func (c *configImpl) DevicePreviousProductConfig() string { + return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice(), "previous_build_config.mk") +} + func (c *configImpl) HostPrebuiltTag() string { if runtime.GOOS == "linux" { return "linux-x86" diff --git a/ui/build/make.go b/ui/build/make.go index 32dc17b5..2b399263 100644 --- a/ui/build/make.go +++ b/ui/build/make.go @@ -83,6 +83,7 @@ func runMakeProductConfig(ctx Context, config Config) { // So that we can use the correct TARGET_PRODUCT if it's been // modified by PRODUCT-* arguments "TARGET_PRODUCT", + "TARGET_BUILD_VARIANT", // compiler wrappers set up by make "CC_WRAPPER", @@ -129,6 +130,9 @@ func runMakeProductConfig(ctx Context, config Config) { // Used to execute Kati and Ninja "NINJA_GOALS", "KATI_GOALS", + + // To find target/product/<DEVICE> + "TARGET_DEVICE", }, exportEnvVars...), bannerVars...) make_vars, err := DumpMakeVars(ctx, config, config.Arguments(), []string{ @@ -159,4 +163,5 @@ func runMakeProductConfig(ctx Context, config Config) { config.SetKatiArgs(strings.Fields(make_vars["KATI_GOALS"])) config.SetNinjaArgs(strings.Fields(make_vars["NINJA_GOALS"])) + config.SetTargetDevice(make_vars["TARGET_DEVICE"]) } |