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 ( 18 "os/exec" 19 "path/filepath" 20 ) 21 22 func runSoongBootstrap(ctx Context, config Config) { 23 ctx.BeginTrace("bootstrap soong") 24 defer ctx.EndTrace() 25 26 cmd := exec.CommandContext(ctx.Context, "./bootstrap.bash") 27 env := config.Environment().Copy() 28 env.Set("BUILDDIR", config.SoongOutDir()) 29 cmd.Env = env.Environ() 30 cmd.Stdout = ctx.Stdout() 31 cmd.Stderr = ctx.Stderr() 32 ctx.Verboseln(cmd.Path, cmd.Args) 33 if err := cmd.Run(); err != nil { 34 if e, ok := err.(*exec.ExitError); ok { 35 ctx.Fatalln("soong bootstrap failed with:", e.ProcessState.String()) 36 } else { 37 ctx.Fatalln("Failed to run soong bootstrap:", err) 38 } 39 } 40 } 41 42 func runSoong(ctx Context, config Config) { 43 ctx.BeginTrace("soong") 44 defer ctx.EndTrace() 45 46 cmd := exec.CommandContext(ctx.Context, filepath.Join(config.SoongOutDir(), "soong"), "-w", "dupbuild=err") 47 if config.IsVerbose() { 48 cmd.Args = append(cmd.Args, "-v") 49 } 50 env := config.Environment().Copy() 51 env.Set("SKIP_NINJA", "true") 52 cmd.Env = env.Environ() 53 cmd.Stdin = ctx.Stdin() 54 cmd.Stdout = ctx.Stdout() 55 cmd.Stderr = ctx.Stderr() 56 ctx.Verboseln(cmd.Path, cmd.Args) 57 if err := cmd.Run(); err != nil { 58 if e, ok := err.(*exec.ExitError); ok { 59 ctx.Fatalln("soong bootstrap failed with:", e.ProcessState.String()) 60 } else { 61 ctx.Fatalln("Failed to run soong bootstrap:", err) 62 } 63 } 64 } 65