blob: 5787a00f8da492d893ab767a24d0a6eeec7bc1b6 [file] [log] [blame]
Dan Willemsen1e704462016-08-21 15:17:17 -07001// Copyright 2017 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 (
Dan Willemsend9f6fa22016-08-21 15:17:17 -070018 "path/filepath"
Dan Willemsen1e704462016-08-21 15:17:17 -070019 "strconv"
20 "strings"
Dan Willemsend9f6fa22016-08-21 15:17:17 -070021 "time"
Dan Willemsen1e704462016-08-21 15:17:17 -070022)
23
24func runNinja(ctx Context, config Config) {
Dan Willemsend9f6fa22016-08-21 15:17:17 -070025 ctx.BeginTrace("ninja")
26 defer ctx.EndTrace()
27
Dan Willemsenf173d592017-04-27 14:28:00 -070028 executable := config.PrebuiltBuildTool("ninja")
Dan Willemsen1e704462016-08-21 15:17:17 -070029 args := []string{
30 "-d", "keepdepfile",
31 }
32
33 args = append(args, config.NinjaArgs()...)
34
35 var parallel int
36 if config.UseGoma() {
37 parallel = config.RemoteParallel()
38 } else {
39 parallel = config.Parallel()
40 }
41 args = append(args, "-j", strconv.Itoa(parallel))
42 if config.keepGoing != 1 {
43 args = append(args, "-k", strconv.Itoa(config.keepGoing))
44 }
45
46 args = append(args, "-f", config.CombinedNinjaFile())
47
48 if config.IsVerbose() {
49 args = append(args, "-v")
50 }
51 args = append(args, "-w", "dupbuild=err")
52
Dan Willemsen269a8c72017-05-03 17:15:47 -070053 cmd := Command(ctx, config, "ninja", executable, args...)
54 cmd.Environment.AppendFromKati(config.KatiEnvFile())
Dan Willemsen1e704462016-08-21 15:17:17 -070055
56 // Allow both NINJA_ARGS and NINJA_EXTRA_ARGS, since both have been
57 // used in the past to specify extra ninja arguments.
Dan Willemsen269a8c72017-05-03 17:15:47 -070058 if extra, ok := cmd.Environment.Get("NINJA_ARGS"); ok {
59 cmd.Args = append(cmd.Args, strings.Fields(extra)...)
Dan Willemsen1e704462016-08-21 15:17:17 -070060 }
Dan Willemsen269a8c72017-05-03 17:15:47 -070061 if extra, ok := cmd.Environment.Get("NINJA_EXTRA_ARGS"); ok {
62 cmd.Args = append(cmd.Args, strings.Fields(extra)...)
Dan Willemsen1e704462016-08-21 15:17:17 -070063 }
64
Dan Willemsen269a8c72017-05-03 17:15:47 -070065 if _, ok := cmd.Environment.Get("NINJA_STATUS"); !ok {
66 cmd.Environment.Set("NINJA_STATUS", "[%p %f/%t] ")
Dan Willemsen1e704462016-08-21 15:17:17 -070067 }
68
Dan Willemsen1e704462016-08-21 15:17:17 -070069 cmd.Stdin = ctx.Stdin()
70 cmd.Stdout = ctx.Stdout()
71 cmd.Stderr = ctx.Stderr()
Dan Willemsend9f6fa22016-08-21 15:17:17 -070072 startTime := time.Now()
73 defer ctx.ImportNinjaLog(filepath.Join(config.OutDir(), ".ninja_log"), startTime)
Dan Willemsen269a8c72017-05-03 17:15:47 -070074 cmd.RunOrFatal()
Dan Willemsen1e704462016-08-21 15:17:17 -070075}