diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/build/cleanbuild.go | 1 | ||||
-rw-r--r-- | ui/build/config.go | 34 | ||||
-rw-r--r-- | ui/build/ninja.go | 44 | ||||
-rw-r--r-- | ui/build/paths/config.go | 44 | ||||
-rw-r--r-- | ui/build/soong.go | 2 | ||||
-rw-r--r-- | ui/metrics/BUILD.bazel | 1 |
6 files changed, 58 insertions, 68 deletions
diff --git a/ui/build/cleanbuild.go b/ui/build/cleanbuild.go index ee5332735..41cb5ab6d 100644 --- a/ui/build/cleanbuild.go +++ b/ui/build/cleanbuild.go @@ -135,6 +135,7 @@ func installClean(ctx Context, config Config) { productOut("obj/NOTICE_FILES"), productOut("obj/PACKAGING"), productOut("ramdisk"), + productOut("ramdisk_16k"), productOut("debug_ramdisk"), productOut("vendor_ramdisk"), productOut("vendor_debug_ramdisk"), diff --git a/ui/build/config.go b/ui/build/config.go index 1698e63b4..bc0ab33d9 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -17,6 +17,7 @@ package build import ( "context" "encoding/json" + "errors" "fmt" "io/ioutil" "math/rand" @@ -140,6 +141,9 @@ const ( EXTERNAL_FILE // ninja uses a prioritized module list from Soong HINT_FROM_SOONG + // If ninja log exists, use NINJA_LOG, if not, use HINT_FROM_SOONG instead. + // We can assume it is an incremental build if ninja log exists. + DEFAULT ) const srcDirFileCheck = "build/soong/root.bp" @@ -316,8 +320,9 @@ func UploadOnlyConfig(ctx Context, args ...string) Config { func NewConfig(ctx Context, args ...string) Config { ret := &configImpl{ - environ: OsEnvironment(), - sandboxConfig: &SandboxConfig{}, + environ: OsEnvironment(), + sandboxConfig: &SandboxConfig{}, + ninjaWeightListSource: DEFAULT, } // Default matching ninja @@ -328,8 +333,21 @@ func NewConfig(ctx Context, args ...string) Config { ret.parseArgs(ctx, args) if ret.ninjaWeightListSource == HINT_FROM_SOONG { - ret.environ.Set("SOONG_GENERATES_NINJA_HINT", "true") + ret.environ.Set("SOONG_GENERATES_NINJA_HINT", "always") + } else if ret.ninjaWeightListSource == DEFAULT { + defaultNinjaWeightListSource := NINJA_LOG + if _, err := os.Stat(filepath.Join(ret.OutDir(), ninjaLogFileName)); errors.Is(err, os.ErrNotExist) { + ctx.Verboseln("$OUT/.ninja_log doesn't exist, use HINT_FROM_SOONG instead") + defaultNinjaWeightListSource = HINT_FROM_SOONG + } else { + ctx.Verboseln("$OUT/.ninja_log exist, use NINJA_LOG") + } + ret.ninjaWeightListSource = defaultNinjaWeightListSource + // soong_build generates ninja hint depending on ninja log existence. + // Set it "depend" to avoid soong re-run due to env variable change. + ret.environ.Set("SOONG_GENERATES_NINJA_HINT", "depend") } + // Make sure OUT_DIR is set appropriately if outDir, ok := ret.environ.Get("OUT_DIR"); ok { ret.environ.Set("OUT_DIR", filepath.Clean(outDir)) @@ -1729,6 +1747,16 @@ func (c *configImpl) IsPersistentBazelEnabled() bool { return c.Environment().IsEnvTrue("USE_PERSISTENT_BAZEL") } +// GetBazeliskBazelVersion returns the Bazel version to use for this build, +// or the empty string if the current canonical prod Bazel should be used. +// This environment variable should only be set to debug the build system. +// The Bazel version, if set, will be passed to Bazelisk, and Bazelisk will +// handle downloading and invoking the correct Bazel binary. +func (c *configImpl) GetBazeliskBazelVersion() string { + value, _ := c.Environment().Get("USE_BAZEL_VERSION") + return value +} + func (c *configImpl) BazelModulesForceEnabledByFlag() string { return c.bazelForceEnabledModules } diff --git a/ui/build/ninja.go b/ui/build/ninja.go index 5d56531b2..61aaad86b 100644 --- a/ui/build/ninja.go +++ b/ui/build/ninja.go @@ -35,48 +35,6 @@ const ( ninjaWeightListFileName = ".ninja_weight_list" ) -func useNinjaBuildLog(ctx Context, config Config, cmd *Cmd) { - ninjaLogFile := filepath.Join(config.OutDir(), ninjaLogFileName) - data, err := os.ReadFile(ninjaLogFile) - var outputBuilder strings.Builder - if err == nil { - lines := strings.Split(strings.TrimSpace(string(data)), "\n") - // ninja log: <start> <end> <restat> <name> <cmdhash> - // ninja weight list: <name>,<end-start+1> - for _, line := range lines { - if strings.HasPrefix(line, "#") { - continue - } - fields := strings.Split(line, "\t") - path := fields[3] - start, err := strconv.Atoi(fields[0]) - if err != nil { - continue - } - end, err := strconv.Atoi(fields[1]) - if err != nil { - continue - } - outputBuilder.WriteString(path) - outputBuilder.WriteString(",") - outputBuilder.WriteString(strconv.Itoa(end-start+1) + "\n") - } - } else { - // If there is no ninja log file, just pass empty ninja weight list. - // Because it is still efficient with critical path calculation logic even without weight. - ctx.Verbosef("There is an error during reading ninja log, so ninja will use empty weight list: %s", err) - } - - weightListFile := filepath.Join(config.OutDir(), ninjaWeightListFileName) - - err = os.WriteFile(weightListFile, []byte(outputBuilder.String()), 0644) - if err == nil { - cmd.Args = append(cmd.Args, "-o", "usesweightlist="+weightListFile) - } else { - ctx.Panicf("Could not write ninja weight list file %s", err) - } -} - // 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. @@ -131,7 +89,7 @@ func runNinjaForBuild(ctx Context, config Config) { switch config.NinjaWeightListSource() { case NINJA_LOG: - useNinjaBuildLog(ctx, config, cmd) + 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). cmd.Args = append(cmd.Args, "-o", "usesweightlist=/dev/null") diff --git a/ui/build/paths/config.go b/ui/build/paths/config.go index b3092eaf1..b3e871fc7 100644 --- a/ui/build/paths/config.go +++ b/ui/build/paths/config.go @@ -86,27 +86,29 @@ func GetConfig(name string) PathConfig { // This list specifies whether a particular binary from $PATH is allowed to be // run during the build. For more documentation, see path_interposer.go . var Configuration = map[string]PathConfig{ - "bash": Allowed, - "dd": Allowed, - "diff": Allowed, - "dlv": Allowed, - "expr": Allowed, - "fuser": Allowed, - "getopt": Allowed, - "git": Allowed, - "hexdump": Allowed, - "jar": Allowed, - "java": Allowed, - "javap": Allowed, - "lsof": Allowed, - "openssl": Allowed, - "pstree": Allowed, - "rsync": Allowed, - "sh": Allowed, - "stubby": Allowed, - "tr": Allowed, - "unzip": Allowed, - "zip": Allowed, + "bash": Allowed, + "dd": Allowed, + "diff": Allowed, + "dlv": Allowed, + "expr": Allowed, + "fuser": Allowed, + "gcert": Allowed, + "getopt": Allowed, + "git": Allowed, + "hexdump": Allowed, + "jar": Allowed, + "java": Allowed, + "javap": Allowed, + "lsof": Allowed, + "openssl": Allowed, + "prodcertstatus": Allowed, + "pstree": Allowed, + "rsync": Allowed, + "sh": Allowed, + "stubby": Allowed, + "tr": Allowed, + "unzip": Allowed, + "zip": Allowed, // Host toolchain is removed. In-tree toolchain should be used instead. // GCC also can't find cc1 with this implementation. diff --git a/ui/build/soong.go b/ui/build/soong.go index e24abddd1..b14208eb4 100644 --- a/ui/build/soong.go +++ b/ui/build/soong.go @@ -537,7 +537,7 @@ func runSoong(ctx Context, config Config) { defer ctx.EndTrace() if config.IsPersistentBazelEnabled() { - bazelProxy := bazel.NewProxyServer(ctx.Logger, config.OutDir(), filepath.Join(config.SoongOutDir(), "workspace")) + bazelProxy := bazel.NewProxyServer(ctx.Logger, config.OutDir(), filepath.Join(config.SoongOutDir(), "workspace"), config.GetBazeliskBazelVersion()) bazelProxy.Start() defer bazelProxy.Close() } diff --git a/ui/metrics/BUILD.bazel b/ui/metrics/BUILD.bazel index 2dc1ab633..ca39c59b1 100644 --- a/ui/metrics/BUILD.bazel +++ b/ui/metrics/BUILD.bazel @@ -23,6 +23,7 @@ py_proto_library( proto_library( name = "metrics-proto", srcs = [ + "bazel_metrics_proto/bazel_metrics.proto", "bp2build_metrics_proto/bp2build_metrics.proto", "metrics_proto/metrics.proto", ], |