blob: cbb75c764f290361ec6e6f97ce8f172db04767bc [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 Willemsen99a75cd2017-08-04 16:04:04 -070018 "os"
Dan Willemsen1e704462016-08-21 15:17:17 -070019 "path/filepath"
Dan Willemsen99a75cd2017-08-04 16:04:04 -070020 "strconv"
21 "time"
22
23 "github.com/google/blueprint/microfactory"
Dan Willemsen1e704462016-08-21 15:17:17 -070024)
25
Dan Willemsen1e704462016-08-21 15:17:17 -070026func runSoong(ctx Context, config Config) {
Dan Willemsend9f6fa22016-08-21 15:17:17 -070027 ctx.BeginTrace("soong")
28 defer ctx.EndTrace()
29
Dan Willemsen99a75cd2017-08-04 16:04:04 -070030 func() {
31 ctx.BeginTrace("blueprint bootstrap")
32 defer ctx.EndTrace()
33
34 cmd := Command(ctx, config, "blueprint bootstrap", "build/blueprint/bootstrap.bash", "-t")
35 cmd.Environment.Set("BLUEPRINTDIR", "./build/blueprint")
36 cmd.Environment.Set("BOOTSTRAP", "./build/blueprint/bootstrap.bash")
37 cmd.Environment.Set("BUILDDIR", config.SoongOutDir())
Dan Willemsene7945d72018-01-23 22:15:15 -080038 cmd.Environment.Set("GOROOT", "./"+filepath.Join("prebuilts/go", config.HostPrebuiltTag()))
Jeff Gastond3e141d2017-08-08 17:46:01 -070039 cmd.Environment.Set("BLUEPRINT_LIST_FILE", filepath.Join(config.FileListDir(), "Android.bp.list"))
Dan Willemsen99a75cd2017-08-04 16:04:04 -070040 cmd.Environment.Set("NINJA_BUILDDIR", config.OutDir())
41 cmd.Environment.Set("SRCDIR", ".")
42 cmd.Environment.Set("TOPNAME", "Android.bp")
43 cmd.Sandbox = soongSandbox
44 cmd.Stdout = ctx.Stdout()
45 cmd.Stderr = ctx.Stderr()
46 cmd.RunOrFatal()
47 }()
48
49 func() {
50 ctx.BeginTrace("environment check")
51 defer ctx.EndTrace()
52
53 envFile := filepath.Join(config.SoongOutDir(), ".soong.environment")
54 envTool := filepath.Join(config.SoongOutDir(), ".bootstrap/bin/soong_env")
55 if _, err := os.Stat(envFile); err == nil {
56 if _, err := os.Stat(envTool); err == nil {
57 cmd := Command(ctx, config, "soong_env", envTool, envFile)
58 cmd.Sandbox = soongSandbox
59 cmd.Stdout = ctx.Stdout()
60 cmd.Stderr = ctx.Stderr()
61 if err := cmd.Run(); err != nil {
62 ctx.Verboseln("soong_env failed, forcing manifest regeneration")
63 os.Remove(envFile)
64 }
65 } else {
66 ctx.Verboseln("Missing soong_env tool, forcing manifest regeneration")
67 os.Remove(envFile)
68 }
69 } else if !os.IsNotExist(err) {
70 ctx.Fatalf("Failed to stat %f: %v", envFile, err)
71 }
72 }()
73
74 func() {
75 ctx.BeginTrace("minibp")
76 defer ctx.EndTrace()
77
78 var cfg microfactory.Config
79 cfg.Map("github.com/google/blueprint", "build/blueprint")
80
Dan Willemsend9e8f0a2017-10-30 13:42:06 -070081 cfg.TrimPath = absPath(ctx, ".")
Dan Willemsen99a75cd2017-08-04 16:04:04 -070082
83 minibp := filepath.Join(config.SoongOutDir(), ".minibootstrap/minibp")
84 if _, err := microfactory.Build(&cfg, minibp, "github.com/google/blueprint/bootstrap/minibp"); err != nil {
85 ctx.Fatalln("Failed to build minibp:", err)
86 }
87 }()
88
89 ninja := func(name, file string) {
90 ctx.BeginTrace(name)
91 defer ctx.EndTrace()
92
93 cmd := Command(ctx, config, "soong "+name,
94 config.PrebuiltBuildTool("ninja"),
95 "-d", "keepdepfile",
96 "-w", "dupbuild=err",
97 "-j", strconv.Itoa(config.Parallel()),
98 "-f", filepath.Join(config.SoongOutDir(), file))
99 if config.IsVerbose() {
100 cmd.Args = append(cmd.Args, "-v")
101 }
Dan Willemsen99a75cd2017-08-04 16:04:04 -0700102 cmd.Sandbox = soongSandbox
103 cmd.Stdin = ctx.Stdin()
104 cmd.Stdout = ctx.Stdout()
105 cmd.Stderr = ctx.Stderr()
106
107 defer ctx.ImportNinjaLog(filepath.Join(config.OutDir(), ".ninja_log"), time.Now())
108 cmd.RunOrFatal()
Dan Willemsen1e704462016-08-21 15:17:17 -0700109 }
Dan Willemsen99a75cd2017-08-04 16:04:04 -0700110
111 ninja("minibootstrap", ".minibootstrap/build.ninja")
112 ninja("bootstrap", ".bootstrap/build.ninja")
Dan Willemsen1e704462016-08-21 15:17:17 -0700113}