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 | db8457c | 2017-05-12 16:38:17 -0700 | [diff] [blame] | 18 | "io/ioutil" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 19 | "os" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 20 | "path/filepath" |
| 21 | "text/template" |
Colin Cross | 74cda72 | 2020-01-16 15:25:50 -0800 | [diff] [blame] | 22 | |
| 23 | "android/soong/ui/metrics" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 24 | ) |
| 25 | |
Jingwen Chen | cda22c9 | 2020-11-23 00:22:30 -0500 | [diff] [blame] | 26 | // SetupOutDir ensures the out directory exists, and has the proper files to |
| 27 | // prevent kati from recursing into it. |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 28 | func SetupOutDir(ctx Context, config Config) { |
| 29 | ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), "Android.mk")) |
| 30 | ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), "CleanSpec.mk")) |
Anton Hansson | 5e5c48b | 2020-11-27 12:35:20 +0000 | [diff] [blame] | 31 | if !config.SkipKati() { |
Jingwen Chen | cda22c9 | 2020-11-23 00:22:30 -0500 | [diff] [blame] | 32 | // Run soong_build with Kati for a hybrid build, e.g. running the |
| 33 | // AndroidMk singleton and postinstall commands. Communicate this to |
| 34 | // soong_build by writing an empty .soong.kati_enabled marker file in the |
| 35 | // soong_build output directory for the soong_build primary builder to |
| 36 | // know if the user wants to run Kati after. |
| 37 | // |
| 38 | // This does not preclude running Kati for *product configuration purposes*. |
| 39 | ensureEmptyFileExists(ctx, filepath.Join(config.SoongOutDir(), ".soong.kati_enabled")) |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 40 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 41 | // The ninja_build file is used by our buildbots to understand that the output |
| 42 | // can be parsed as ninja output. |
| 43 | ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), "ninja_build")) |
Jeff Gaston | b64fc1c | 2017-08-04 12:30:12 -0700 | [diff] [blame] | 44 | ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), ".out-dir")) |
Colin Cross | 28f527c | 2019-11-26 16:19:04 -0800 | [diff] [blame] | 45 | |
| 46 | if buildDateTimeFile, ok := config.environ.Get("BUILD_DATETIME_FILE"); ok { |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 47 | err := ioutil.WriteFile(buildDateTimeFile, []byte(config.buildDateTime), 0666) // a+rw |
Colin Cross | 28f527c | 2019-11-26 16:19:04 -0800 | [diff] [blame] | 48 | if err != nil { |
| 49 | ctx.Fatalln("Failed to write BUILD_DATETIME to file:", err) |
| 50 | } |
| 51 | } else { |
| 52 | ctx.Fatalln("Missing BUILD_DATETIME_FILE") |
| 53 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | var combinedBuildNinjaTemplate = template.Must(template.New("combined").Parse(` |
| 57 | builddir = {{.OutDir}} |
Colin Cross | 8b8bec3 | 2019-11-15 13:18:43 -0800 | [diff] [blame] | 58 | {{if .UseRemoteBuild }}pool local_pool |
Dan Willemsen | 2997123 | 2018-09-26 14:58:30 -0700 | [diff] [blame] | 59 | depth = {{.Parallel}} |
Colin Cross | 8b8bec3 | 2019-11-15 13:18:43 -0800 | [diff] [blame] | 60 | {{end -}} |
| 61 | pool highmem_pool |
| 62 | depth = {{.HighmemParallel}} |
Anton Hansson | 0b55bdb | 2021-06-04 10:08:08 +0100 | [diff] [blame^] | 63 | {{if and (not .SkipKatiNinja) .HasKatiSuffix}}subninja {{.KatiBuildNinjaFile}} |
Dan Willemsen | fb1271a | 2018-09-26 15:00:42 -0700 | [diff] [blame] | 64 | subninja {{.KatiPackageNinjaFile}} |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 65 | {{end -}} |
Dan Willemsen | fb1271a | 2018-09-26 15:00:42 -0700 | [diff] [blame] | 66 | subninja {{.SoongNinjaFile}} |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 67 | `)) |
| 68 | |
| 69 | func createCombinedBuildNinjaFile(ctx Context, config Config) { |
Anton Hansson | 0b55bdb | 2021-06-04 10:08:08 +0100 | [diff] [blame^] | 70 | // If we're in SkipKati mode but want to run kati ninja, skip creating this file if it already exists |
| 71 | if config.SkipKati() && !config.SkipKatiNinja() { |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 72 | if _, err := os.Stat(config.CombinedNinjaFile()); err == nil || !os.IsNotExist(err) { |
| 73 | return |
| 74 | } |
| 75 | } |
| 76 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 77 | file, err := os.Create(config.CombinedNinjaFile()) |
| 78 | if err != nil { |
| 79 | ctx.Fatalln("Failed to create combined ninja file:", err) |
| 80 | } |
| 81 | defer file.Close() |
| 82 | |
| 83 | if err := combinedBuildNinjaTemplate.Execute(file, config); err != nil { |
| 84 | ctx.Fatalln("Failed to write combined ninja file:", err) |
| 85 | } |
| 86 | } |
| 87 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 88 | // These are bitmasks which can be used to check whether various flags are set e.g. whether to use Bazel. |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 89 | const ( |
Anton Hansson | 5a7861a | 2021-06-04 10:09:01 +0100 | [diff] [blame] | 90 | _ = iota |
| 91 | // Whether to run the kati config step. |
| 92 | RunProductConfig = 1 << iota |
| 93 | // Whether to run soong to generate a ninja file. |
| 94 | RunSoong = 1 << iota |
| 95 | // Whether to run kati to generate a ninja file. |
| 96 | RunKati = 1 << iota |
Anton Hansson | 0b55bdb | 2021-06-04 10:08:08 +0100 | [diff] [blame^] | 97 | // Whether to include the kati-generated ninja file in the combined ninja. |
| 98 | RunKatiNinja = 1 << iota |
Anton Hansson | 5a7861a | 2021-06-04 10:09:01 +0100 | [diff] [blame] | 99 | // Whether to run ninja on the combined ninja. |
| 100 | RunNinja = 1 << iota |
| 101 | // Whether to run bazel on the combined ninja. |
| 102 | RunBazel = 1 << iota |
| 103 | RunBuildTests = 1 << iota |
Anton Hansson | 0b55bdb | 2021-06-04 10:08:08 +0100 | [diff] [blame^] | 104 | RunAll = RunProductConfig | RunSoong | RunKati | RunKatiNinja | RunNinja |
| 105 | RunAllWithBazel = RunProductConfig | RunSoong | RunKati | RunKatiNinja | RunBazel |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 106 | ) |
| 107 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 108 | // checkProblematicFiles fails the build if existing Android.mk or CleanSpec.mk files are found at the root of the tree. |
Anton Hansson | ecf0f10 | 2018-09-19 22:14:17 +0100 | [diff] [blame] | 109 | func checkProblematicFiles(ctx Context) { |
| 110 | files := []string{"Android.mk", "CleanSpec.mk"} |
| 111 | for _, file := range files { |
| 112 | if _, err := os.Stat(file); !os.IsNotExist(err) { |
| 113 | absolute := absPath(ctx, file) |
| 114 | ctx.Printf("Found %s in tree root. This file needs to be removed to build.\n", file) |
| 115 | ctx.Fatalf(" rm %s\n", absolute) |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 120 | // checkCaseSensitivity issues a warning if a case-insensitive file system is being used. |
Dan Willemsen | db8457c | 2017-05-12 16:38:17 -0700 | [diff] [blame] | 121 | func checkCaseSensitivity(ctx Context, config Config) { |
| 122 | outDir := config.OutDir() |
| 123 | lowerCase := filepath.Join(outDir, "casecheck.txt") |
| 124 | upperCase := filepath.Join(outDir, "CaseCheck.txt") |
| 125 | lowerData := "a" |
| 126 | upperData := "B" |
| 127 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 128 | if err := ioutil.WriteFile(lowerCase, []byte(lowerData), 0666); err != nil { // a+rw |
Dan Willemsen | db8457c | 2017-05-12 16:38:17 -0700 | [diff] [blame] | 129 | ctx.Fatalln("Failed to check case sensitivity:", err) |
| 130 | } |
| 131 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 132 | if err := ioutil.WriteFile(upperCase, []byte(upperData), 0666); err != nil { // a+rw |
Dan Willemsen | db8457c | 2017-05-12 16:38:17 -0700 | [diff] [blame] | 133 | ctx.Fatalln("Failed to check case sensitivity:", err) |
| 134 | } |
| 135 | |
| 136 | res, err := ioutil.ReadFile(lowerCase) |
| 137 | if err != nil { |
| 138 | ctx.Fatalln("Failed to check case sensitivity:", err) |
| 139 | } |
| 140 | |
| 141 | if string(res) != lowerData { |
| 142 | ctx.Println("************************************************************") |
| 143 | ctx.Println("You are building on a case-insensitive filesystem.") |
| 144 | ctx.Println("Please move your source tree to a case-sensitive filesystem.") |
| 145 | ctx.Println("************************************************************") |
| 146 | ctx.Fatalln("Case-insensitive filesystems not supported") |
| 147 | } |
| 148 | } |
| 149 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 150 | // help prints a help/usage message, via the build/make/help.sh script. |
| 151 | func help(ctx Context, config Config) { |
Jeff Gaston | df4a081 | 2017-05-30 20:11:20 -0700 | [diff] [blame] | 152 | cmd := Command(ctx, config, "help.sh", "build/make/help.sh") |
Dan Willemsen | b2e6c2e | 2017-07-13 17:24:44 -0700 | [diff] [blame] | 153 | cmd.Sandbox = dumpvarsSandbox |
Dan Willemsen | b82471a | 2018-05-17 16:37:09 -0700 | [diff] [blame] | 154 | cmd.RunAndPrintOrFatal() |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 157 | // checkRAM warns if there probably isn't enough RAM to complete a build. |
| 158 | func checkRAM(ctx Context, config Config) { |
Dan Willemsen | 570a292 | 2020-05-26 23:02:29 -0700 | [diff] [blame] | 159 | if totalRAM := config.TotalRAM(); totalRAM != 0 { |
| 160 | ram := float32(totalRAM) / (1024 * 1024 * 1024) |
| 161 | ctx.Verbosef("Total RAM: %.3vGB", ram) |
| 162 | |
| 163 | if ram <= 16 { |
| 164 | ctx.Println("************************************************************") |
| 165 | ctx.Printf("You are building on a machine with %.3vGB of RAM\n", ram) |
| 166 | ctx.Println("") |
| 167 | ctx.Println("The minimum required amount of free memory is around 16GB,") |
| 168 | ctx.Println("and even with that, some configurations may not work.") |
| 169 | ctx.Println("") |
| 170 | ctx.Println("If you run into segfaults or other errors, try reducing your") |
| 171 | ctx.Println("-j value.") |
| 172 | ctx.Println("************************************************************") |
| 173 | } else if ram <= float32(config.Parallel()) { |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 174 | // Want at least 1GB of RAM per job. |
Dan Willemsen | 570a292 | 2020-05-26 23:02:29 -0700 | [diff] [blame] | 175 | ctx.Printf("Warning: high -j%d count compared to %.3vGB of RAM", config.Parallel(), ram) |
| 176 | ctx.Println("If you run into segfaults or other errors, try a lower -j value") |
| 177 | } |
| 178 | } |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | // Build the tree. The 'what' argument can be used to chose which components of |
| 182 | // the build to run, via checking various bitmasks. |
Anton Hansson | 5a7861a | 2021-06-04 10:09:01 +0100 | [diff] [blame] | 183 | func Build(ctx Context, config Config) { |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 184 | ctx.Verboseln("Starting build with args:", config.Arguments()) |
| 185 | ctx.Verboseln("Environment:", config.Environment().Environ()) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 186 | |
Colin Cross | 74cda72 | 2020-01-16 15:25:50 -0800 | [diff] [blame] | 187 | ctx.BeginTrace(metrics.Total, "total") |
| 188 | defer ctx.EndTrace() |
| 189 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 190 | if inList("help", config.Arguments()) { |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 191 | help(ctx, config) |
Dan Willemsen | 0b73b4b | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 192 | return |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Jeff Gaston | 3615fe8 | 2017-05-24 13:14:34 -0700 | [diff] [blame] | 195 | // Make sure that no other Soong process is running with the same output directory |
| 196 | buildLock := BecomeSingletonOrFail(ctx, config) |
| 197 | defer buildLock.Unlock() |
| 198 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 199 | if inList("clean", config.Arguments()) || inList("clobber", config.Arguments()) { |
| 200 | clean(ctx, config) |
| 201 | return |
| 202 | } |
| 203 | |
| 204 | // checkProblematicFiles aborts the build if Android.mk or CleanSpec.mk are found at the root of the tree. |
Anton Hansson | ecf0f10 | 2018-09-19 22:14:17 +0100 | [diff] [blame] | 205 | checkProblematicFiles(ctx) |
| 206 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 207 | checkRAM(ctx, config) |
| 208 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 209 | SetupOutDir(ctx, config) |
| 210 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 211 | // checkCaseSensitivity issues a warning if a case-insensitive file system is being used. |
Dan Willemsen | db8457c | 2017-05-12 16:38:17 -0700 | [diff] [blame] | 212 | checkCaseSensitivity(ctx, config) |
| 213 | |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 214 | ensureEmptyDirectoriesExist(ctx, config.TempDir()) |
| 215 | |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 216 | SetupPath(ctx, config) |
| 217 | |
Anton Hansson | 5a7861a | 2021-06-04 10:09:01 +0100 | [diff] [blame] | 218 | what := RunAll |
| 219 | if config.UseBazel() { |
| 220 | what = RunAllWithBazel |
| 221 | } |
| 222 | if config.Checkbuild() { |
| 223 | what |= RunBuildTests |
| 224 | } |
Anton Hansson | 5e5c48b | 2020-11-27 12:35:20 +0000 | [diff] [blame] | 225 | if config.SkipConfig() { |
| 226 | ctx.Verboseln("Skipping Config as requested") |
Anton Hansson | 5a7861a | 2021-06-04 10:09:01 +0100 | [diff] [blame] | 227 | what = what &^ RunProductConfig |
Anton Hansson | 5e5c48b | 2020-11-27 12:35:20 +0000 | [diff] [blame] | 228 | } |
Anton Hansson | 5e5c48b | 2020-11-27 12:35:20 +0000 | [diff] [blame] | 229 | if config.SkipKati() { |
| 230 | ctx.Verboseln("Skipping Kati as requested") |
Anton Hansson | 5a7861a | 2021-06-04 10:09:01 +0100 | [diff] [blame] | 231 | what = what &^ RunKati |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 232 | } |
Anton Hansson | 0b55bdb | 2021-06-04 10:08:08 +0100 | [diff] [blame^] | 233 | if config.SkipKatiNinja() { |
| 234 | ctx.Verboseln("Skipping use of Kati ninja as requested") |
| 235 | what = what &^ RunKatiNinja |
| 236 | } |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 237 | if config.SkipNinja() { |
| 238 | ctx.Verboseln("Skipping Ninja as requested") |
Anton Hansson | 5a7861a | 2021-06-04 10:09:01 +0100 | [diff] [blame] | 239 | what = what &^ RunNinja |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 240 | } |
| 241 | |
Yoshisato Yanagisawa | 2cb0e5d | 2019-01-10 10:14:16 +0900 | [diff] [blame] | 242 | if config.StartGoma() { |
Yoshisato Yanagisawa | 2cb0e5d | 2019-01-10 10:14:16 +0900 | [diff] [blame] | 243 | startGoma(ctx, config) |
| 244 | } |
| 245 | |
Ramy Medhat | bbf2567 | 2019-07-17 12:30:04 +0000 | [diff] [blame] | 246 | if config.StartRBE() { |
Ramy Medhat | bbf2567 | 2019-07-17 12:30:04 +0000 | [diff] [blame] | 247 | startRBE(ctx, config) |
| 248 | } |
| 249 | |
Anton Hansson | 5a7861a | 2021-06-04 10:09:01 +0100 | [diff] [blame] | 250 | if what&RunProductConfig != 0 { |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 251 | runMakeProductConfig(ctx, config) |
| 252 | } |
| 253 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 254 | // Everything below here depends on product config. |
| 255 | |
Colin Cross | 806fd94 | 2019-05-03 13:35:58 -0700 | [diff] [blame] | 256 | if inList("installclean", config.Arguments()) || |
| 257 | inList("install-clean", config.Arguments()) { |
Rupert Shuttleworth | 1f304e6 | 2020-11-24 14:13:41 +0000 | [diff] [blame] | 258 | installClean(ctx, config) |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 259 | ctx.Println("Deleted images and staging directories.") |
| 260 | return |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | if inList("dataclean", config.Arguments()) || |
Colin Cross | 806fd94 | 2019-05-03 13:35:58 -0700 | [diff] [blame] | 264 | inList("data-clean", config.Arguments()) { |
Rupert Shuttleworth | 1f304e6 | 2020-11-24 14:13:41 +0000 | [diff] [blame] | 265 | dataClean(ctx, config) |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 266 | ctx.Println("Deleted data files.") |
| 267 | return |
| 268 | } |
| 269 | |
Anton Hansson | 5a7861a | 2021-06-04 10:09:01 +0100 | [diff] [blame] | 270 | if what&RunSoong != 0 { |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 271 | runSoong(ctx, config) |
Jingwen Chen | eb76c43 | 2021-01-28 08:22:12 -0500 | [diff] [blame] | 272 | |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 273 | if config.bazelBuildMode() == generateBuildFiles { |
| 274 | // Return early, if we're using Soong as solely the generator of BUILD files. |
Jingwen Chen | eb76c43 | 2021-01-28 08:22:12 -0500 | [diff] [blame] | 275 | return |
| 276 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Anton Hansson | 5a7861a | 2021-06-04 10:09:01 +0100 | [diff] [blame] | 279 | if what&RunKati != 0 { |
Dan Willemsen | 2997123 | 2018-09-26 14:58:30 -0700 | [diff] [blame] | 280 | genKatiSuffix(ctx, config) |
| 281 | runKatiCleanSpec(ctx, config) |
| 282 | runKatiBuild(ctx, config) |
Dan Willemsen | fb1271a | 2018-09-26 15:00:42 -0700 | [diff] [blame] | 283 | runKatiPackage(ctx, config) |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 284 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 285 | ioutil.WriteFile(config.LastKatiSuffixFile(), []byte(config.KatiSuffix()), 0666) // a+rw |
Anton Hansson | 0b55bdb | 2021-06-04 10:08:08 +0100 | [diff] [blame^] | 286 | } else if what&RunKatiNinja != 0 { |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 287 | // Load last Kati Suffix if it exists |
| 288 | if katiSuffix, err := ioutil.ReadFile(config.LastKatiSuffixFile()); err == nil { |
| 289 | ctx.Verboseln("Loaded previous kati config:", string(katiSuffix)) |
| 290 | config.SetKatiSuffix(string(katiSuffix)) |
| 291 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Colin Cross | 3719349 | 2017-11-16 17:55:00 -0800 | [diff] [blame] | 294 | // Write combined ninja file |
| 295 | createCombinedBuildNinjaFile(ctx, config) |
| 296 | |
Colin Cross | 8ba7d47 | 2020-06-25 11:27:52 -0700 | [diff] [blame] | 297 | distGzipFile(ctx, config, config.CombinedNinjaFile()) |
| 298 | |
Colin Cross | 3719349 | 2017-11-16 17:55:00 -0800 | [diff] [blame] | 299 | if what&RunBuildTests != 0 { |
| 300 | testForDanglingRules(ctx, config) |
| 301 | } |
| 302 | |
Anton Hansson | 5a7861a | 2021-06-04 10:09:01 +0100 | [diff] [blame] | 303 | if what&RunNinja != 0 { |
| 304 | if what&RunKati != 0 { |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 305 | installCleanIfNecessary(ctx, config) |
| 306 | } |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 307 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 308 | runNinjaForBuild(ctx, config) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 309 | } |
Rupert Shuttleworth | 680387b | 2020-10-25 12:31:27 +0000 | [diff] [blame] | 310 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 311 | // Currently, using Bazel requires Kati and Soong to run first, so check whether to run Bazel last. |
Anton Hansson | 5a7861a | 2021-06-04 10:09:01 +0100 | [diff] [blame] | 312 | if what&RunBazel != 0 { |
Rupert Shuttleworth | 680387b | 2020-10-25 12:31:27 +0000 | [diff] [blame] | 313 | runBazel(ctx, config) |
| 314 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 315 | } |
Colin Cross | 8ba7d47 | 2020-06-25 11:27:52 -0700 | [diff] [blame] | 316 | |
| 317 | // distGzipFile writes a compressed copy of src to the distDir if dist is enabled. Failures |
| 318 | // are printed but non-fatal. |
| 319 | func distGzipFile(ctx Context, config Config, src string, subDirs ...string) { |
| 320 | if !config.Dist() { |
| 321 | return |
| 322 | } |
| 323 | |
| 324 | subDir := filepath.Join(subDirs...) |
Rupert Shuttleworth | 3c9f5ac | 2020-12-10 11:32:38 +0000 | [diff] [blame] | 325 | destDir := filepath.Join(config.RealDistDir(), "soong_ui", subDir) |
Colin Cross | 8ba7d47 | 2020-06-25 11:27:52 -0700 | [diff] [blame] | 326 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 327 | if err := os.MkdirAll(destDir, 0777); err != nil { // a+rwx |
Colin Cross | 8ba7d47 | 2020-06-25 11:27:52 -0700 | [diff] [blame] | 328 | ctx.Printf("failed to mkdir %s: %s", destDir, err.Error()) |
Colin Cross | 8ba7d47 | 2020-06-25 11:27:52 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 331 | if err := gzipFileToDir(src, destDir); err != nil { |
Colin Cross | 8ba7d47 | 2020-06-25 11:27:52 -0700 | [diff] [blame] | 332 | ctx.Printf("failed to dist %s: %s", filepath.Base(src), err.Error()) |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | // distFile writes a copy of src to the distDir if dist is enabled. Failures are printed but |
| 337 | // non-fatal. |
| 338 | func distFile(ctx Context, config Config, src string, subDirs ...string) { |
| 339 | if !config.Dist() { |
| 340 | return |
| 341 | } |
| 342 | |
| 343 | subDir := filepath.Join(subDirs...) |
Rupert Shuttleworth | 3c9f5ac | 2020-12-10 11:32:38 +0000 | [diff] [blame] | 344 | destDir := filepath.Join(config.RealDistDir(), "soong_ui", subDir) |
Colin Cross | 8ba7d47 | 2020-06-25 11:27:52 -0700 | [diff] [blame] | 345 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 346 | if err := os.MkdirAll(destDir, 0777); err != nil { // a+rwx |
Colin Cross | 8ba7d47 | 2020-06-25 11:27:52 -0700 | [diff] [blame] | 347 | ctx.Printf("failed to mkdir %s: %s", destDir, err.Error()) |
Colin Cross | 8ba7d47 | 2020-06-25 11:27:52 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Rupert Shuttleworth | eeb5caa | 2020-11-25 07:13:54 +0000 | [diff] [blame] | 350 | if _, err := copyFile(src, filepath.Join(destDir, filepath.Base(src))); err != nil { |
Colin Cross | 8ba7d47 | 2020-06-25 11:27:52 -0700 | [diff] [blame] | 351 | ctx.Printf("failed to dist %s: %s", filepath.Base(src), err.Error()) |
| 352 | } |
| 353 | } |