From 5a7861a27295b7df1b2040f6df0bdf176da8088d Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Fri, 4 Jun 2021 10:09:01 +0100 Subject: [PATCH 1/2] Various cleanup in soong_ui to aid new feature - Rename the "BuildX" variables to "RunX" - Remove redundant comments - Inline all the "what to do" based on config in build.go - Inline some constants only used in one place Bug: 189187214 Test: m nothing Test: build/soong/build_test.bash Change-Id: I111a69e642212d7938d4971283545e0d9acbb01a Merged-In: I111a69e642212d7938d4971283545e0d9acbb01a (cherry picked from commit d274ea91968b95ef7a2edd2d604afbc237e84ff9) --- cmd/multiproduct_kati/main.go | 12 +++++--- cmd/soong_ui/main.go | 14 ++------- cuj/cuj.go | 2 +- ui/build/build.go | 58 +++++++++++++++++++---------------- ui/build/config.go | 7 +++-- 5 files changed, 46 insertions(+), 47 deletions(-) diff --git a/cmd/multiproduct_kati/main.go b/cmd/multiproduct_kati/main.go index 20f146ae3..55a5470e3 100644 --- a/cmd/multiproduct_kati/main.go +++ b/cmd/multiproduct_kati/main.go @@ -460,19 +460,21 @@ func buildProduct(mpctx *mpContext, product string) { } }() - buildWhat := build.BuildProductConfig + config.SetSkipNinja(true) + + buildWhat := build.RunProductConfig if !*onlyConfig { - buildWhat |= build.BuildSoong + buildWhat |= build.RunSoong if !*onlySoong { - buildWhat |= build.BuildKati + buildWhat |= build.RunKati } } before := time.Now() - build.Build(ctx, config, buildWhat) + build.Build(ctx, config) // Save std_full.log if Kati re-read the makefiles - if buildWhat&build.BuildKati != 0 { + if buildWhat&build.RunKati != 0 { if after, err := os.Stat(config.KatiBuildNinjaFile()); err == nil && after.ModTime().After(before) { err := copyFile(stdLog, filepath.Join(filepath.Dir(stdLog), "std_full.log")) if err != nil { diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go index 390a9ecdf..22922c0e5 100644 --- a/cmd/soong_ui/main.go +++ b/cmd/soong_ui/main.go @@ -59,12 +59,10 @@ type command struct { run func(ctx build.Context, config build.Config, args []string, logsDir string) } -const makeModeFlagName = "--make-mode" - // list of supported commands (flags) supported by soong ui var commands []command = []command{ { - flag: makeModeFlagName, + flag: "--make-mode", description: "build the modules by the target name (i.e. soong_docs)", config: func(ctx build.Context, args ...string) build.Config { return build.NewConfig(ctx, args...) @@ -506,15 +504,7 @@ func runMake(ctx build.Context, config build.Config, _ []string, logsDir string) ctx.Fatal("done") } - toBuild := build.BuildAll - if config.UseBazel() { - toBuild = build.BuildAllWithBazel - } - - if config.Checkbuild() { - toBuild |= build.RunBuildTests - } - build.Build(ctx, config, toBuild) + build.Build(ctx, config) } // getCommand finds the appropriate command based on args[1] flag. args[0] diff --git a/cuj/cuj.go b/cuj/cuj.go index 333301268..b4ae9a263 100644 --- a/cuj/cuj.go +++ b/cuj/cuj.go @@ -115,7 +115,7 @@ func (t *Test) Run(logsDir string) { defer f.Shutdown() build.FindSources(buildCtx, config, f) - build.Build(buildCtx, config, build.BuildAll) + build.Build(buildCtx, config) t.results.metrics = met } diff --git a/ui/build/build.go b/ui/build/build.go index c2ad0570b..da44b6568 100644 --- a/ui/build/build.go +++ b/ui/build/build.go @@ -87,15 +87,20 @@ func createCombinedBuildNinjaFile(ctx Context, config Config) { // These are bitmasks which can be used to check whether various flags are set e.g. whether to use Bazel. const ( - BuildNone = iota - BuildProductConfig = 1 << iota - BuildSoong = 1 << iota - BuildKati = 1 << iota - BuildNinja = 1 << iota - BuildBazel = 1 << iota - RunBuildTests = 1 << iota - BuildAll = BuildProductConfig | BuildSoong | BuildKati | BuildNinja - BuildAllWithBazel = BuildProductConfig | BuildSoong | BuildKati | BuildBazel + _ = iota + // Whether to run the kati config step. + RunProductConfig = 1 << iota + // Whether to run soong to generate a ninja file. + RunSoong = 1 << iota + // Whether to run kati to generate a ninja file. + RunKati = 1 << iota + // Whether to run ninja on the combined ninja. + RunNinja = 1 << iota + // Whether to run bazel on the combined ninja. + RunBazel = 1 << iota + RunBuildTests = 1 << iota + RunAll = RunProductConfig | RunSoong | RunKati | RunNinja + RunAllWithBazel = RunProductConfig | RunSoong | RunKati | RunBazel ) // checkProblematicFiles fails the build if existing Android.mk or CleanSpec.mk files are found at the root of the tree. @@ -173,7 +178,7 @@ func checkRAM(ctx Context, config Config) { // Build the tree. The 'what' argument can be used to chose which components of // the build to run, via checking various bitmasks. -func Build(ctx Context, config Config, what int) { +func Build(ctx Context, config Config) { ctx.Verboseln("Starting build with args:", config.Arguments()) ctx.Verboseln("Environment:", config.Environment().Environ()) @@ -208,33 +213,35 @@ func Build(ctx Context, config Config, what int) { SetupPath(ctx, config) + what := RunAll + if config.UseBazel() { + what = RunAllWithBazel + } + if config.Checkbuild() { + what |= RunBuildTests + } if config.SkipConfig() { ctx.Verboseln("Skipping Config as requested") - what = what &^ BuildProductConfig + what = what &^ RunProductConfig } - if config.SkipKati() { ctx.Verboseln("Skipping Kati as requested") - what = what &^ BuildKati + what = what &^ RunKati } - if config.SkipNinja() { ctx.Verboseln("Skipping Ninja as requested") - what = what &^ BuildNinja + what = what &^ RunNinja } if config.StartGoma() { - // Ensure start Goma compiler_proxy startGoma(ctx, config) } if config.StartRBE() { - // Ensure RBE proxy is started startRBE(ctx, config) } - if what&BuildProductConfig != 0 { - // Run make for product config + if what&RunProductConfig != 0 { runMakeProductConfig(ctx, config) } @@ -254,8 +261,7 @@ func Build(ctx Context, config Config, what int) { return } - if what&BuildSoong != 0 { - // Run Soong + if what&RunSoong != 0 { runSoong(ctx, config) if config.bazelBuildMode() == generateBuildFiles { @@ -264,8 +270,7 @@ func Build(ctx Context, config Config, what int) { } } - if what&BuildKati != 0 { - // Run ckati + if what&RunKati != 0 { genKatiSuffix(ctx, config) runKatiCleanSpec(ctx, config) runKatiBuild(ctx, config) @@ -289,17 +294,16 @@ func Build(ctx Context, config Config, what int) { testForDanglingRules(ctx, config) } - if what&BuildNinja != 0 { - if what&BuildKati != 0 { + if what&RunNinja != 0 { + if what&RunKati != 0 { installCleanIfNecessary(ctx, config) } - // Run ninja runNinjaForBuild(ctx, config) } // Currently, using Bazel requires Kati and Soong to run first, so check whether to run Bazel last. - if what&BuildBazel != 0 { + if what&RunBazel != 0 { runBazel(ctx, config) } } diff --git a/ui/build/config.go b/ui/build/config.go index f1f59895e..3a445a330 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -567,8 +567,7 @@ func getTargetsFromDirs(ctx Context, relDir string, dirs []string, targetNamePre func (c *configImpl) parseArgs(ctx Context, args []string) { for i := 0; i < len(args); i++ { arg := strings.TrimSpace(args[i]) - if arg == "--make-mode" { - } else if arg == "showcommands" { + if arg == "showcommands" { c.verbose = true } else if arg == "--skip-ninja" { c.skipNinja = true @@ -796,6 +795,10 @@ func (c *configImpl) SkipNinja() bool { return c.skipNinja } +func (c *configImpl) SetSkipNinja(v bool) { + c.skipNinja = v +} + func (c *configImpl) SkipConfig() bool { return c.skipConfig } From 0b55bdb7af7ab2a039fefc88086f0ee41c00ac69 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Fri, 4 Jun 2021 10:08:08 +0100 Subject: [PATCH 2/2] Add a soong-only mode to soong-ui The previous --skip-kati flag could be interpreted as "do not run kati to re-generate ninja file". Add a more specific flag for the "soong only" build use-case, where we do not load the kati-generated ninja files at all. Bug: 189187214 Test: build/soong/soong_ui.bash \ --make-mode \ --soong-only --skip-soong-tests \ TARGET_PRODUCT=mainline_sdk \ SOONG_ALLOW_MISSING_DEPENDENCIES=true \ SOONG_SDK_SNAPSHOT_VERSION=unversioned \ SOONG_SDK_SNAPSHOT_USE_SRCJAR=true \ out/soong/mainline-sdks/art-module-sdk.zip Change-Id: I91abbd28af517d4b550ebc6d88fd64947caf9545 Merged-In: I91abbd28af517d4b550ebc6d88fd64947caf9545 (cherry picked from commit 546de4a1f3de92a2f920daa6311a1c317aedf877) --- ui/build/build.go | 18 ++++++++++++------ ui/build/config.go | 9 +++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ui/build/build.go b/ui/build/build.go index da44b6568..8f050d9be 100644 --- a/ui/build/build.go +++ b/ui/build/build.go @@ -60,15 +60,15 @@ builddir = {{.OutDir}} {{end -}} pool highmem_pool depth = {{.HighmemParallel}} -{{if .HasKatiSuffix}}subninja {{.KatiBuildNinjaFile}} +{{if and (not .SkipKatiNinja) .HasKatiSuffix}}subninja {{.KatiBuildNinjaFile}} subninja {{.KatiPackageNinjaFile}} {{end -}} subninja {{.SoongNinjaFile}} `)) func createCombinedBuildNinjaFile(ctx Context, config Config) { - // If we're in SkipKati mode, skip creating this file if it already exists - if config.SkipKati() { + // If we're in SkipKati mode but want to run kati ninja, skip creating this file if it already exists + if config.SkipKati() && !config.SkipKatiNinja() { if _, err := os.Stat(config.CombinedNinjaFile()); err == nil || !os.IsNotExist(err) { return } @@ -94,13 +94,15 @@ const ( RunSoong = 1 << iota // Whether to run kati to generate a ninja file. RunKati = 1 << iota + // Whether to include the kati-generated ninja file in the combined ninja. + RunKatiNinja = 1 << iota // Whether to run ninja on the combined ninja. RunNinja = 1 << iota // Whether to run bazel on the combined ninja. RunBazel = 1 << iota RunBuildTests = 1 << iota - RunAll = RunProductConfig | RunSoong | RunKati | RunNinja - RunAllWithBazel = RunProductConfig | RunSoong | RunKati | RunBazel + RunAll = RunProductConfig | RunSoong | RunKati | RunKatiNinja | RunNinja + RunAllWithBazel = RunProductConfig | RunSoong | RunKati | RunKatiNinja | RunBazel ) // checkProblematicFiles fails the build if existing Android.mk or CleanSpec.mk files are found at the root of the tree. @@ -228,6 +230,10 @@ func Build(ctx Context, config Config) { ctx.Verboseln("Skipping Kati as requested") what = what &^ RunKati } + if config.SkipKatiNinja() { + ctx.Verboseln("Skipping use of Kati ninja as requested") + what = what &^ RunKatiNinja + } if config.SkipNinja() { ctx.Verboseln("Skipping Ninja as requested") what = what &^ RunNinja @@ -277,7 +283,7 @@ func Build(ctx Context, config Config) { runKatiPackage(ctx, config) ioutil.WriteFile(config.LastKatiSuffixFile(), []byte(config.KatiSuffix()), 0666) // a+rw - } else { + } else if what&RunKatiNinja != 0 { // Load last Kati Suffix if it exists if katiSuffix, err := ioutil.ReadFile(config.LastKatiSuffixFile()); err == nil { ctx.Verboseln("Loaded previous kati config:", string(katiSuffix)) diff --git a/ui/build/config.go b/ui/build/config.go index 3a445a330..220e734f0 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -48,6 +48,7 @@ type configImpl struct { dist bool skipConfig bool skipKati bool + skipKatiNinja bool skipNinja bool skipSoongTests bool @@ -575,7 +576,11 @@ func (c *configImpl) parseArgs(ctx Context, args []string) { c.skipConfig = true c.skipKati = true } else if arg == "--skip-kati" { + // TODO: remove --skip-kati once module builds have been migrated to --song-only c.skipKati = true + } else if arg == "--soong-only" { + c.skipKati = true + c.skipKatiNinja = true } else if arg == "--skip-soong-tests" { c.skipSoongTests = true } else if len(arg) > 0 && arg[0] == '-' { @@ -791,6 +796,10 @@ func (c *configImpl) SkipKati() bool { return c.skipKati } +func (c *configImpl) SkipKatiNinja() bool { + return c.skipKatiNinja +} + func (c *configImpl) SkipNinja() bool { return c.skipNinja }