blob: c5702c086c461edb166bd7474a6e6cd11c1753a2 [file] [log] [blame]
Rupert Shuttleworth680387b2020-10-25 12:31:27 +00001// Copyright 2020 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package build
16
17import (
18 "path/filepath"
19 "strings"
20)
21
22func runBazel(ctx Context, config Config) {
23 // "droid" is the default ninja target.
24 outputGroups := "droid"
25 if len(config.ninjaArgs) > 0 {
26 // At this stage, the residue slice of args passed to ninja
27 // are the ninja targets to build, which can correspond directly
28 // to ninja_build's output_groups.
29 outputGroups = strings.Join(config.ninjaArgs, ",")
30 }
31
32 bazelExecutable := filepath.Join("tools", "bazel")
33 args := []string{
34 "build",
35 "--verbose_failures",
36 "--show_progress_rate_limit=0.05",
37 "--color=yes",
38 "--curses=yes",
39 "--show_timestamps",
40 "--announce_rc",
41 "--output_groups=" + outputGroups,
42 "//:" + config.TargetProduct() + "-" + config.TargetBuildVariant(),
43 }
44
45 cmd := Command(ctx, config, "bazel", bazelExecutable, args...)
46
47 cmd.Environment.Set("DIST_DIR", config.DistDir())
48 cmd.Environment.Set("SHELL", "/bin/bash")
49
50 ctx.Println(cmd.Cmd)
51 cmd.Dir = filepath.Join(config.OutDir(), "..")
52 ctx.Status.Status("Starting Bazel..")
53 cmd.RunAndStreamOrFatal()
54}