Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package build |
| 16 | |
| 17 | import ( |
Dan Willemsen | d9f6fa2 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 18 | "path/filepath" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 19 | "strconv" |
| 20 | "strings" |
Dan Willemsen | d9f6fa2 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 21 | "time" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | func runNinja(ctx Context, config Config) { |
Dan Willemsen | d9f6fa2 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 25 | ctx.BeginTrace("ninja") |
| 26 | defer ctx.EndTrace() |
| 27 | |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 28 | executable := config.PrebuiltBuildTool("ninja") |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 29 | 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 Willemsen | 269a8c7 | 2017-05-03 17:15:47 -0700 | [diff] [blame^] | 53 | cmd := Command(ctx, config, "ninja", executable, args...) |
| 54 | cmd.Environment.AppendFromKati(config.KatiEnvFile()) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 55 | |
| 56 | // Allow both NINJA_ARGS and NINJA_EXTRA_ARGS, since both have been |
| 57 | // used in the past to specify extra ninja arguments. |
Dan Willemsen | 269a8c7 | 2017-05-03 17:15:47 -0700 | [diff] [blame^] | 58 | if extra, ok := cmd.Environment.Get("NINJA_ARGS"); ok { |
| 59 | cmd.Args = append(cmd.Args, strings.Fields(extra)...) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 60 | } |
Dan Willemsen | 269a8c7 | 2017-05-03 17:15:47 -0700 | [diff] [blame^] | 61 | if extra, ok := cmd.Environment.Get("NINJA_EXTRA_ARGS"); ok { |
| 62 | cmd.Args = append(cmd.Args, strings.Fields(extra)...) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Dan Willemsen | 269a8c7 | 2017-05-03 17:15:47 -0700 | [diff] [blame^] | 65 | if _, ok := cmd.Environment.Get("NINJA_STATUS"); !ok { |
| 66 | cmd.Environment.Set("NINJA_STATUS", "[%p %f/%t] ") |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 69 | cmd.Stdin = ctx.Stdin() |
| 70 | cmd.Stdout = ctx.Stdout() |
| 71 | cmd.Stderr = ctx.Stderr() |
Dan Willemsen | d9f6fa2 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 72 | startTime := time.Now() |
| 73 | defer ctx.ImportNinjaLog(filepath.Join(config.OutDir(), ".ninja_log"), startTime) |
Dan Willemsen | 269a8c7 | 2017-05-03 17:15:47 -0700 | [diff] [blame^] | 74 | cmd.RunOrFatal() |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 75 | } |