blob: 04c91295d457834cac6057b5cbaa4d65e334bead [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// Copyright 2015 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
Colin Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
Jingwen Chenc711fec2020-11-22 23:52:50 -050017// This is the primary location to write and read all configuration values and
18// product variables necessary for soong_build's operation.
19
Colin Cross3f40fa42015-01-30 17:27:36 -080020import (
Colin Cross3f40fa42015-01-30 17:27:36 -080021 "encoding/json"
22 "fmt"
Colin Crossd8f20142016-11-03 09:43:26 -070023 "io/ioutil"
Colin Cross3f40fa42015-01-30 17:27:36 -080024 "os"
Colin Cross35cec122015-04-02 14:37:16 -070025 "path/filepath"
Colin Cross3f40fa42015-01-30 17:27:36 -080026 "runtime"
Dan Willemsen34cc69e2015-09-23 15:26:20 -070027 "strings"
Colin Crossc1e86a32015-04-15 12:33:28 -070028 "sync"
Colin Cross6ff51382015-12-17 16:39:19 -080029
Colin Cross98be1bb2019-12-13 20:41:13 -080030 "github.com/google/blueprint"
Colin Crosse87040b2017-12-11 15:52:26 -080031 "github.com/google/blueprint/bootstrap"
Colin Cross98be1bb2019-12-13 20:41:13 -080032 "github.com/google/blueprint/pathtools"
Colin Cross6ff51382015-12-17 16:39:19 -080033 "github.com/google/blueprint/proptools"
Colin Cross9d34f352019-11-22 16:03:51 -080034
35 "android/soong/android/soongconfig"
Colin Cross3f40fa42015-01-30 17:27:36 -080036)
37
Jingwen Chenc711fec2020-11-22 23:52:50 -050038// Bool re-exports proptools.Bool for the android package.
Colin Cross6ff51382015-12-17 16:39:19 -080039var Bool = proptools.Bool
Jingwen Chenc711fec2020-11-22 23:52:50 -050040
41// String re-exports proptools.String for the android package.
Jack He8cc71432016-12-08 15:45:07 -080042var String = proptools.String
Jingwen Chenc711fec2020-11-22 23:52:50 -050043
44// StringDefault re-exports proptools.StringDefault for the android package.
Jeongik Cha219141c2020-08-06 23:00:37 +090045var StringDefault = proptools.StringDefault
Jiyong Park6a927c42020-01-21 02:03:43 +090046
Jingwen Chenc711fec2020-11-22 23:52:50 -050047// FutureApiLevelInt is a placeholder constant for unreleased API levels.
Dan Albert0b176c82020-07-23 16:43:25 -070048const FutureApiLevelInt = 10000
49
Jingwen Chenc711fec2020-11-22 23:52:50 -050050// FutureApiLevel represents unreleased API levels.
Dan Albert0b176c82020-07-23 16:43:25 -070051var FutureApiLevel = ApiLevel{
52 value: "current",
53 number: FutureApiLevelInt,
54 isPreview: true,
55}
Colin Cross6ff51382015-12-17 16:39:19 -080056
Jingwen Chenc711fec2020-11-22 23:52:50 -050057// configFileName is the name the file containing FileConfigurableOptions from
58// soong_ui for the soong_build primary builder.
Dan Willemsen87b17d12015-07-14 00:39:06 -070059const configFileName = "soong.config"
Jingwen Chenc711fec2020-11-22 23:52:50 -050060
61// productVariablesFileName contain the product configuration variables from soong_ui for the
62// soong_build primary builder and Kati.
Dan Willemsen87b17d12015-07-14 00:39:06 -070063const productVariablesFileName = "soong.variables"
Colin Cross3f40fa42015-01-30 17:27:36 -080064
65// A FileConfigurableOptions contains options which can be configured by the
66// config file. These will be included in the config struct.
67type FileConfigurableOptions struct {
Jiyong Park22101982020-09-17 19:09:58 +090068 Mega_device *bool `json:",omitempty"`
69 Host_bionic *bool `json:",omitempty"`
70 Host_bionic_arm64 *bool `json:",omitempty"`
Colin Cross3f40fa42015-01-30 17:27:36 -080071}
72
Jingwen Chenc711fec2020-11-22 23:52:50 -050073// SetDefaultConfig resets the receiving FileConfigurableOptions to default
74// values.
Colin Cross27385972015-09-18 10:57:10 -070075func (f *FileConfigurableOptions) SetDefaultConfig() {
76 *f = FileConfigurableOptions{}
Colin Cross3f40fa42015-01-30 17:27:36 -080077}
78
Colin Cross9272ade2016-08-17 15:24:12 -070079// A Config object represents the entire build configuration for Android.
Colin Crossc3c0a492015-04-10 15:43:55 -070080type Config struct {
81 *config
82}
83
Jingwen Chenc711fec2020-11-22 23:52:50 -050084// BuildDir returns the build output directory for the configuration.
Jeff Gastonefc1b412017-03-29 17:29:06 -070085func (c Config) BuildDir() string {
86 return c.buildDir
87}
88
Jingwen Chenc711fec2020-11-22 23:52:50 -050089// A DeviceConfig object represents the configuration for a particular device
90// being built. For now there will only be one of these, but in the future there
91// may be multiple devices being built.
Colin Cross9272ade2016-08-17 15:24:12 -070092type DeviceConfig struct {
93 *deviceConfig
94}
95
Jingwen Chenc711fec2020-11-22 23:52:50 -050096// VendorConfig represents the configuration for vendor-specific behavior.
Colin Cross9d34f352019-11-22 16:03:51 -080097type VendorConfig soongconfig.SoongConfig
Dan Willemsen0fe78662018-03-26 12:41:18 -070098
Jingwen Chenc711fec2020-11-22 23:52:50 -050099// Definition of general build configuration for soong_build. Some of these
100// configuration values are generated from soong_ui for soong_build,
101// communicated over JSON files like soong.config or soong.variables.
Colin Cross1332b002015-04-07 17:11:30 -0700102type config struct {
Jingwen Chenc711fec2020-11-22 23:52:50 -0500103 // Options configurable with soong.confg
Colin Cross3f40fa42015-01-30 17:27:36 -0800104 FileConfigurableOptions
Jingwen Chenc711fec2020-11-22 23:52:50 -0500105
106 // Options configurable with soong.variables
Dan Willemsen45133ac2018-03-09 21:22:06 -0800107 productVariables productVariables
Colin Cross3f40fa42015-01-30 17:27:36 -0800108
Dan Willemsen674dc7f2018-03-12 18:06:05 -0700109 // Only available on configs created by TestConfig
110 TestProductVariables *productVariables
111
Jingwen Chenc711fec2020-11-22 23:52:50 -0500112 // A specialized context object for Bazel/Soong mixed builds and migration
113 // purposes.
Chris Parsonsf3c96ef2020-09-29 02:23:17 -0400114 BazelContext BazelContext
115
Dan Willemsen87b17d12015-07-14 00:39:06 -0700116 ConfigFileName string
117 ProductVariablesFileName string
118
Jaewoong Jung642916f2020-10-09 17:25:15 -0700119 Targets map[OsType][]Target
120 BuildOSTarget Target // the Target for tools run on the build machine
121 BuildOSCommonTarget Target // the Target for common (java) tools run on the build machine
122 AndroidCommonTarget Target // the Target for common modules for the Android device
123 AndroidFirstDeviceTarget Target // the first Target for modules for the Android device
Dan Willemsen218f6562015-07-08 18:13:11 -0700124
Jingwen Chenc711fec2020-11-22 23:52:50 -0500125 // multilibConflicts for an ArchType is true if there is earlier configured
126 // device architecture with the same multilib value.
Colin Cross3b19f5d2019-09-17 14:45:31 -0700127 multilibConflicts map[ArchType]bool
128
Colin Cross9272ade2016-08-17 15:24:12 -0700129 deviceConfig *deviceConfig
130
Chris Parsons8f232a22020-06-23 17:37:05 -0400131 srcDir string // the path of the root source directory
132 buildDir string // the path of the build output directory
133 moduleListFile string // the path to the file which lists blueprint files to parse.
Colin Crossc1e86a32015-04-15 12:33:28 -0700134
Colin Cross6ccbc912017-10-10 23:07:38 -0700135 env map[string]string
Dan Willemsene7680ba2015-09-11 17:06:19 -0700136 envLock sync.Mutex
137 envDeps map[string]string
138 envFrozen bool
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800139
Jingwen Chencda22c92020-11-23 00:22:30 -0500140 // Changes behavior based on whether Kati runs after soong_build, or if soong_build
141 // runs standalone.
142 katiEnabled bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700143
Colin Cross32616ed2017-09-05 21:56:44 -0700144 captureBuild bool // true for tests, saves build parameters for each module
145 ignoreEnvironment bool // true for tests, returns empty from all Getenv calls
Colin Crosscec81712017-07-13 14:43:27 -0700146
Colin Crosse87040b2017-12-11 15:52:26 -0800147 stopBefore bootstrap.StopBefore
148
Colin Cross98be1bb2019-12-13 20:41:13 -0800149 fs pathtools.FileSystem
150 mockBpList string
151
Colin Cross5e6a7972020-06-07 16:56:32 -0700152 // If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error
153 // in tests when a path doesn't exist.
154 testAllowNonExistentPaths bool
155
Jingwen Chenc711fec2020-11-22 23:52:50 -0500156 // The list of files that when changed, must invalidate soong_build to
157 // regenerate build.ninja.
Colin Cross12129292020-10-29 18:23:58 -0700158 ninjaFileDepsSet sync.Map
159
Colin Cross9272ade2016-08-17 15:24:12 -0700160 OncePer
161}
162
163type deviceConfig struct {
Dan Willemsen00269f22017-07-06 16:59:48 -0700164 config *config
Colin Cross9272ade2016-08-17 15:24:12 -0700165 OncePer
Colin Cross3f40fa42015-01-30 17:27:36 -0800166}
167
Colin Cross485e5722015-08-27 13:28:01 -0700168type jsonConfigurable interface {
Colin Cross27385972015-09-18 10:57:10 -0700169 SetDefaultConfig()
Colin Cross485e5722015-08-27 13:28:01 -0700170}
Colin Cross3f40fa42015-01-30 17:27:36 -0800171
Colin Cross485e5722015-08-27 13:28:01 -0700172func loadConfig(config *config) error {
Colin Cross988414c2020-01-11 01:11:46 +0000173 err := loadFromConfigFile(&config.FileConfigurableOptions, absolutePath(config.ConfigFileName))
Colin Cross485e5722015-08-27 13:28:01 -0700174 if err != nil {
175 return err
176 }
177
Colin Cross988414c2020-01-11 01:11:46 +0000178 return loadFromConfigFile(&config.productVariables, absolutePath(config.ProductVariablesFileName))
Colin Cross485e5722015-08-27 13:28:01 -0700179}
180
Jingwen Chenc711fec2020-11-22 23:52:50 -0500181// loadFromConfigFile loads and decodes configuration options from a JSON file
182// in the current working directory.
Colin Cross485e5722015-08-27 13:28:01 -0700183func loadFromConfigFile(configurable jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800184 // Try to open the file
Colin Cross485e5722015-08-27 13:28:01 -0700185 configFileReader, err := os.Open(filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800186 defer configFileReader.Close()
187 if os.IsNotExist(err) {
188 // Need to create a file, so that blueprint & ninja don't get in
189 // a dependency tracking loop.
190 // Make a file-configurable-options with defaults, write it out using
191 // a json writer.
Colin Cross27385972015-09-18 10:57:10 -0700192 configurable.SetDefaultConfig()
193 err = saveToConfigFile(configurable, filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800194 if err != nil {
195 return err
196 }
Colin Cross15cd21a2018-02-27 11:26:02 -0800197 } else if err != nil {
198 return fmt.Errorf("config file: could not open %s: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800199 } else {
200 // Make a decoder for it
201 jsonDecoder := json.NewDecoder(configFileReader)
Colin Cross485e5722015-08-27 13:28:01 -0700202 err = jsonDecoder.Decode(configurable)
Colin Cross3f40fa42015-01-30 17:27:36 -0800203 if err != nil {
Colin Cross15cd21a2018-02-27 11:26:02 -0800204 return fmt.Errorf("config file: %s did not parse correctly: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800205 }
206 }
207
Colin Cross3f40fa42015-01-30 17:27:36 -0800208 // No error
209 return nil
210}
211
Colin Crossd8f20142016-11-03 09:43:26 -0700212// atomically writes the config file in case two copies of soong_build are running simultaneously
213// (for example, docs generation and ninja manifest generation)
Colin Cross485e5722015-08-27 13:28:01 -0700214func saveToConfigFile(config jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800215 data, err := json.MarshalIndent(&config, "", " ")
216 if err != nil {
217 return fmt.Errorf("cannot marshal config data: %s", err.Error())
218 }
219
Colin Crossd8f20142016-11-03 09:43:26 -0700220 f, err := ioutil.TempFile(filepath.Dir(filename), "config")
Colin Cross3f40fa42015-01-30 17:27:36 -0800221 if err != nil {
Jingwen Chenc711fec2020-11-22 23:52:50 -0500222 return fmt.Errorf("cannot create empty config file %s: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800223 }
Colin Crossd8f20142016-11-03 09:43:26 -0700224 defer os.Remove(f.Name())
225 defer f.Close()
Colin Cross3f40fa42015-01-30 17:27:36 -0800226
Colin Crossd8f20142016-11-03 09:43:26 -0700227 _, err = f.Write(data)
Colin Cross3f40fa42015-01-30 17:27:36 -0800228 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700229 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
230 }
231
Colin Crossd8f20142016-11-03 09:43:26 -0700232 _, err = f.WriteString("\n")
Colin Cross485e5722015-08-27 13:28:01 -0700233 if err != nil {
234 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800235 }
236
Colin Crossd8f20142016-11-03 09:43:26 -0700237 f.Close()
238 os.Rename(f.Name(), filename)
239
Colin Cross3f40fa42015-01-30 17:27:36 -0800240 return nil
241}
242
Colin Cross988414c2020-01-11 01:11:46 +0000243// NullConfig returns a mostly empty Config for use by standalone tools like dexpreopt_gen that
244// use the android package.
245func NullConfig(buildDir string) Config {
246 return Config{
247 config: &config{
248 buildDir: buildDir,
249 fs: pathtools.OsFs,
250 },
251 }
252}
253
Jingwen Chenc711fec2020-11-22 23:52:50 -0500254// TestConfig returns a Config object for testing.
Colin Cross98be1bb2019-12-13 20:41:13 -0800255func TestConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
Colin Cross9c6241f2019-04-22 15:51:26 -0700256 envCopy := make(map[string]string)
257 for k, v := range env {
258 envCopy[k] = v
259 }
260
Jingwen Chen2838c812020-11-23 01:06:40 -0500261 // Copy the real PATH value to the test environment, it's needed by
262 // NonHermeticHostSystemTool() used in x86_darwin_host.go
Colin Cross9c6241f2019-04-22 15:51:26 -0700263 envCopy["PATH"] = originalEnv["PATH"]
264
Dan Willemsen00269f22017-07-06 16:59:48 -0700265 config := &config{
Dan Willemsen45133ac2018-03-09 21:22:06 -0800266 productVariables: productVariables{
Dan Albert4f378d72020-07-23 17:32:15 -0700267 DeviceName: stringPtr("test_device"),
268 Platform_sdk_version: intPtr(30),
269 Platform_sdk_codename: stringPtr("S"),
270 Platform_version_active_codenames: []string{"S"},
271 DeviceSystemSdkVersions: []string{"14", "15"},
272 Platform_systemsdk_versions: []string{"29", "30"},
273 AAPTConfig: []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"},
274 AAPTPreferredConfig: stringPtr("xhdpi"),
275 AAPTCharacteristics: stringPtr("nosdcard"),
276 AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"},
277 UncompressPrivAppDex: boolPtr(true),
Dan Willemsen00269f22017-07-06 16:59:48 -0700278 },
279
Colin Cross6ccbc912017-10-10 23:07:38 -0700280 buildDir: buildDir,
281 captureBuild: true,
Colin Cross9c6241f2019-04-22 15:51:26 -0700282 env: envCopy,
Colin Cross5e6a7972020-06-07 16:56:32 -0700283
284 // Set testAllowNonExistentPaths so that test contexts don't need to specify every path
285 // passed to PathForSource or PathForModuleSrc.
286 testAllowNonExistentPaths: true,
Chris Parsonsf3c96ef2020-09-29 02:23:17 -0400287
288 BazelContext: noopBazelContext{},
Dan Willemsen00269f22017-07-06 16:59:48 -0700289 }
290 config.deviceConfig = &deviceConfig{
291 config: config,
292 }
Dan Willemsen45133ac2018-03-09 21:22:06 -0800293 config.TestProductVariables = &config.productVariables
Dan Willemsen00269f22017-07-06 16:59:48 -0700294
Colin Cross98be1bb2019-12-13 20:41:13 -0800295 config.mockFileSystem(bp, fs)
296
Dan Willemsen00269f22017-07-06 16:59:48 -0700297 return Config{config}
Colin Crossce75d2c2016-10-06 16:12:58 -0700298}
299
Jingwen Chenc711fec2020-11-22 23:52:50 -0500300// TestArchConfigNativeBridge returns a Config object suitable for using
301// for tests that need to run the arch mutator for native bridge supported
302// archs.
Colin Cross98be1bb2019-12-13 20:41:13 -0800303func TestArchConfigNativeBridge(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
304 testConfig := TestArchConfig(buildDir, env, bp, fs)
dimitry1f33e402019-03-26 12:39:31 +0100305 config := testConfig.config
306
Colin Cross0d99f7c2019-05-14 16:01:24 -0700307 config.Targets[Android] = []Target{
Jiyong Park1613e552020-09-14 19:43:17 +0900308 {Android, Arch{ArchType: X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false},
309 {Android, Arch{ArchType: X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", "", false},
310 {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeEnabled, "x86_64", "arm64", false},
311 {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeEnabled, "x86", "arm", false},
dimitry1f33e402019-03-26 12:39:31 +0100312 }
313
314 return testConfig
315}
316
Jingwen Chenc711fec2020-11-22 23:52:50 -0500317// TestArchConfigFuchsia returns a Config object suitable for using for
318// tests that need to run the arch mutator for the Fuchsia arch.
Colin Cross98be1bb2019-12-13 20:41:13 -0800319func TestArchConfigFuchsia(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
320 testConfig := TestConfig(buildDir, env, bp, fs)
Doug Hornc32c6b02019-01-17 14:44:05 -0800321 config := testConfig.config
322
323 config.Targets = map[OsType][]Target{
324 Fuchsia: []Target{
Jiyong Park1613e552020-09-14 19:43:17 +0900325 {Fuchsia, Arch{ArchType: Arm64, ArchVariant: "", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false},
Doug Hornc32c6b02019-01-17 14:44:05 -0800326 },
327 BuildOs: []Target{
Jiyong Park1613e552020-09-14 19:43:17 +0900328 {BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", false},
Doug Hornc32c6b02019-01-17 14:44:05 -0800329 },
330 }
331
332 return testConfig
333}
334
Jingwen Chenc711fec2020-11-22 23:52:50 -0500335// TestArchConfig returns a Config object suitable for using for tests that
336// need to run the arch mutator.
Colin Cross98be1bb2019-12-13 20:41:13 -0800337func TestArchConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
338 testConfig := TestConfig(buildDir, env, bp, fs)
Colin Crossae4c6182017-09-15 17:33:55 -0700339 config := testConfig.config
340
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700341 config.Targets = map[OsType][]Target{
342 Android: []Target{
Jiyong Park1613e552020-09-14 19:43:17 +0900343 {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false},
344 {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", "", false},
Colin Crossae4c6182017-09-15 17:33:55 -0700345 },
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700346 BuildOs: []Target{
Jiyong Park1613e552020-09-14 19:43:17 +0900347 {BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", false},
348 {BuildOs, Arch{ArchType: X86}, NativeBridgeDisabled, "", "", false},
Colin Crossae4c6182017-09-15 17:33:55 -0700349 },
350 }
351
Colin Cross0d99f7c2019-05-14 16:01:24 -0700352 if runtime.GOOS == "darwin" {
353 config.Targets[BuildOs] = config.Targets[BuildOs][:1]
354 }
355
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700356 config.BuildOSTarget = config.Targets[BuildOs][0]
357 config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0]
358 config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
Jaewoong Jung642916f2020-10-09 17:25:15 -0700359 config.AndroidFirstDeviceTarget = firstTarget(config.Targets[Android], "lib64", "lib32")[0]
Inseob Kim1f086e22019-05-09 13:29:15 +0900360 config.TestProductVariables.DeviceArch = proptools.StringPtr("arm64")
361 config.TestProductVariables.DeviceArchVariant = proptools.StringPtr("armv8-a")
362 config.TestProductVariables.DeviceSecondaryArch = proptools.StringPtr("arm")
363 config.TestProductVariables.DeviceSecondaryArchVariant = proptools.StringPtr("armv7-a-neon")
Colin Cross2a076922018-10-04 23:28:25 -0700364
Colin Crossae4c6182017-09-15 17:33:55 -0700365 return testConfig
366}
367
Jingwen Chenc711fec2020-11-22 23:52:50 -0500368// ConfigForAdditionalRun is a config object which is "reset" for another
369// bootstrap run. Only per-run data is reset. Data which needs to persist across
370// multiple runs in the same program execution is carried over (such as Bazel
371// context or environment deps).
Chris Parsonsf3c96ef2020-09-29 02:23:17 -0400372func ConfigForAdditionalRun(c Config) (Config, error) {
373 newConfig, err := NewConfig(c.srcDir, c.buildDir, c.moduleListFile)
374 if err != nil {
375 return Config{}, err
376 }
377 newConfig.BazelContext = c.BazelContext
378 newConfig.envDeps = c.envDeps
379 return newConfig, nil
380}
381
Jingwen Chenc711fec2020-11-22 23:52:50 -0500382// NewConfig creates a new Config object. The srcDir argument specifies the path
383// to the root source directory. It also loads the config file, if found.
Chris Parsons8f232a22020-06-23 17:37:05 -0400384func NewConfig(srcDir, buildDir string, moduleListFile string) (Config, error) {
Jingwen Chenc711fec2020-11-22 23:52:50 -0500385 // Make a config with default options.
Colin Cross9272ade2016-08-17 15:24:12 -0700386 config := &config{
387 ConfigFileName: filepath.Join(buildDir, configFileName),
388 ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName),
Dan Willemsen87b17d12015-07-14 00:39:06 -0700389
Colin Cross6ccbc912017-10-10 23:07:38 -0700390 env: originalEnv,
391
Colin Cross3b19f5d2019-09-17 14:45:31 -0700392 srcDir: srcDir,
393 buildDir: buildDir,
394 multilibConflicts: make(map[ArchType]bool),
Colin Cross98be1bb2019-12-13 20:41:13 -0800395
Chris Parsons8f232a22020-06-23 17:37:05 -0400396 moduleListFile: moduleListFile,
397 fs: pathtools.NewOsFs(absSrcDir),
Colin Cross68f55102015-03-25 14:43:57 -0700398 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800399
Dan Willemsen00269f22017-07-06 16:59:48 -0700400 config.deviceConfig = &deviceConfig{
Colin Cross9272ade2016-08-17 15:24:12 -0700401 config: config,
402 }
403
Liz Kammer7941b302020-07-28 13:27:34 -0700404 // Soundness check of the build and source directories. This won't catch strange
405 // configurations with symlinks, but at least checks the obvious case.
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700406 absBuildDir, err := filepath.Abs(buildDir)
407 if err != nil {
408 return Config{}, err
409 }
410
411 absSrcDir, err := filepath.Abs(srcDir)
412 if err != nil {
413 return Config{}, err
414 }
415
416 if strings.HasPrefix(absSrcDir, absBuildDir) {
417 return Config{}, fmt.Errorf("Build dir must not contain source directory")
418 }
419
Colin Cross3f40fa42015-01-30 17:27:36 -0800420 // Load any configurable options from the configuration file
Colin Cross9272ade2016-08-17 15:24:12 -0700421 err = loadConfig(config)
Colin Cross3f40fa42015-01-30 17:27:36 -0800422 if err != nil {
Colin Crossc3c0a492015-04-10 15:43:55 -0700423 return Config{}, err
Colin Cross3f40fa42015-01-30 17:27:36 -0800424 }
425
Jingwen Chencda22c92020-11-23 00:22:30 -0500426 KatiEnabledMarkerFile := filepath.Join(buildDir, ".soong.kati_enabled")
427 if _, err := os.Stat(absolutePath(KatiEnabledMarkerFile)); err == nil {
428 config.katiEnabled = true
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800429 }
430
Jingwen Chenc711fec2020-11-22 23:52:50 -0500431 // Sets up the map of target OSes to the finer grained compilation targets
432 // that are configured from the product variables.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700433 targets, err := decodeTargetProductVariables(config)
Dan Willemsen218f6562015-07-08 18:13:11 -0700434 if err != nil {
435 return Config{}, err
436 }
437
Paul Duffin1356d8c2020-02-25 19:26:33 +0000438 // Make the CommonOS OsType available for all products.
439 targets[CommonOS] = []Target{commonTargetMap[CommonOS.Name]}
440
Dan Albert4098deb2016-10-19 14:04:41 -0700441 var archConfig []archConfig
Dan Willemsen322acaf2016-01-12 23:07:05 -0800442 if Bool(config.Mega_device) {
Dan Albert4098deb2016-10-19 14:04:41 -0700443 archConfig = getMegaDeviceConfig()
Colin Cross395f2cf2018-10-24 16:10:32 -0700444 } else if config.NdkAbis() {
Dan Albert4098deb2016-10-19 14:04:41 -0700445 archConfig = getNdkAbisConfig()
Martin Stjernholmc1ecc432019-11-15 15:00:31 +0000446 } else if config.AmlAbis() {
447 archConfig = getAmlAbisConfig()
Dan Albert4098deb2016-10-19 14:04:41 -0700448 }
449
450 if archConfig != nil {
Dan Willemsen01a3c252019-01-11 19:02:16 -0800451 androidTargets, err := decodeArchSettings(Android, archConfig)
Dan Willemsen322acaf2016-01-12 23:07:05 -0800452 if err != nil {
453 return Config{}, err
454 }
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700455 targets[Android] = androidTargets
Dan Willemsen322acaf2016-01-12 23:07:05 -0800456 }
457
Colin Cross3b19f5d2019-09-17 14:45:31 -0700458 multilib := make(map[string]bool)
459 for _, target := range targets[Android] {
460 if seen := multilib[target.Arch.ArchType.Multilib]; seen {
461 config.multilibConflicts[target.Arch.ArchType] = true
462 }
463 multilib[target.Arch.ArchType.Multilib] = true
464 }
465
Jingwen Chenc711fec2020-11-22 23:52:50 -0500466 // Map of OS to compilation targets.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700467 config.Targets = targets
Jingwen Chenc711fec2020-11-22 23:52:50 -0500468
469 // Compilation targets for host tools.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700470 config.BuildOSTarget = config.Targets[BuildOs][0]
471 config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0]
Jingwen Chenc711fec2020-11-22 23:52:50 -0500472
473 // Compilation targets for Android.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700474 if len(config.Targets[Android]) > 0 {
475 config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
Jaewoong Jung642916f2020-10-09 17:25:15 -0700476 config.AndroidFirstDeviceTarget = firstTarget(config.Targets[Android], "lib64", "lib32")[0]
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700477 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700478
Colin Cross1a6acd42020-06-16 17:51:46 -0700479 if Bool(config.productVariables.GcovCoverage) && Bool(config.productVariables.ClangCoverage) {
480 return Config{}, fmt.Errorf("GcovCoverage and ClangCoverage cannot both be set")
481 }
482
483 config.productVariables.Native_coverage = proptools.BoolPtr(
484 Bool(config.productVariables.GcovCoverage) ||
485 Bool(config.productVariables.ClangCoverage))
486
Chris Parsonsf3c96ef2020-09-29 02:23:17 -0400487 config.BazelContext, err = NewBazelContext(config)
Colin Cross3f40fa42015-01-30 17:27:36 -0800488
Jingwen Chenc711fec2020-11-22 23:52:50 -0500489 return Config{config}, err
490}
Colin Cross988414c2020-01-11 01:11:46 +0000491
Colin Cross98be1bb2019-12-13 20:41:13 -0800492// mockFileSystem replaces all reads with accesses to the provided map of
493// filenames to contents stored as a byte slice.
494func (c *config) mockFileSystem(bp string, fs map[string][]byte) {
495 mockFS := map[string][]byte{}
496
497 if _, exists := mockFS["Android.bp"]; !exists {
498 mockFS["Android.bp"] = []byte(bp)
499 }
500
501 for k, v := range fs {
502 mockFS[k] = v
503 }
504
505 // no module list file specified; find every file named Blueprints or Android.bp
506 pathsToParse := []string{}
507 for candidate := range mockFS {
508 base := filepath.Base(candidate)
509 if base == "Blueprints" || base == "Android.bp" {
510 pathsToParse = append(pathsToParse, candidate)
511 }
512 }
513 if len(pathsToParse) < 1 {
514 panic(fmt.Sprintf("No Blueprint or Android.bp files found in mock filesystem: %v\n", mockFS))
515 }
516 mockFS[blueprint.MockModuleListFile] = []byte(strings.Join(pathsToParse, "\n"))
517
518 c.fs = pathtools.MockFs(mockFS)
519 c.mockBpList = blueprint.MockModuleListFile
520}
521
Colin Crosse87040b2017-12-11 15:52:26 -0800522func (c *config) StopBefore() bootstrap.StopBefore {
523 return c.stopBefore
Dan Willemsen218f6562015-07-08 18:13:11 -0700524}
525
Jingwen Chenc711fec2020-11-22 23:52:50 -0500526// SetStopBefore configures soong_build to exit earlier at a specific point.
Colin Crosse87040b2017-12-11 15:52:26 -0800527func (c *config) SetStopBefore(stopBefore bootstrap.StopBefore) {
528 c.stopBefore = stopBefore
529}
530
531var _ bootstrap.ConfigStopBefore = (*config)(nil)
532
Jingwen Chenc711fec2020-11-22 23:52:50 -0500533// BlueprintToolLocation returns the directory containing build system tools
534// from Blueprint, like soong_zip and merge_zips.
Dan Willemsenc2aa4a92016-05-26 15:13:03 -0700535func (c *config) BlueprintToolLocation() string {
536 return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin")
537}
538
Colin Crosse87040b2017-12-11 15:52:26 -0800539var _ bootstrap.ConfigBlueprintToolLocation = (*config)(nil)
540
Dan Willemsen60e62f02018-11-16 21:05:32 -0800541func (c *config) HostToolPath(ctx PathContext, tool string) Path {
542 return PathForOutput(ctx, "host", c.PrebuiltOS(), "bin", tool)
543}
544
Martin Stjernholm7260d062019-12-09 21:47:14 +0000545func (c *config) HostJNIToolPath(ctx PathContext, path string) Path {
546 ext := ".so"
547 if runtime.GOOS == "darwin" {
548 ext = ".dylib"
549 }
550 return PathForOutput(ctx, "host", c.PrebuiltOS(), "lib64", path+ext)
551}
552
553func (c *config) HostJavaToolPath(ctx PathContext, path string) Path {
554 return PathForOutput(ctx, "host", c.PrebuiltOS(), "framework", path)
555}
556
Jingwen Chen2838c812020-11-23 01:06:40 -0500557// NonHermeticHostSystemTool looks for non-hermetic tools from the system we're
558// running on. These tools are not checked-in to AOSP, and therefore could lead
559// to reproducibility problems. Should not be used for other than finding the
560// XCode SDK (xcrun, sw_vers), etc. See ui/build/paths/config.go for the
561// allowlist of host system tools.
562func (c *config) NonHermeticHostSystemTool(name string) string {
Dan Willemsen66068722017-05-08 21:15:59 +0000563 for _, dir := range filepath.SplitList(c.Getenv("PATH")) {
564 path := filepath.Join(dir, name)
565 if s, err := os.Stat(path); err != nil {
566 continue
567 } else if m := s.Mode(); !s.IsDir() && m&0111 != 0 {
568 return path
569 }
570 }
Jingwen Chen2838c812020-11-23 01:06:40 -0500571 panic(fmt.Errorf(
572 "Unable to use '%s' as a host system tool for build system "+
573 "hermeticity reasons. See build/soong/ui/build/paths/config.go "+
574 "for the full list of allowed host tools on your system.", name))
Dan Willemsen66068722017-05-08 21:15:59 +0000575}
576
Jingwen Chenc711fec2020-11-22 23:52:50 -0500577// PrebuiltOS returns the name of the host OS used in prebuilts directories.
Colin Cross1332b002015-04-07 17:11:30 -0700578func (c *config) PrebuiltOS() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800579 switch runtime.GOOS {
580 case "linux":
581 return "linux-x86"
582 case "darwin":
583 return "darwin-x86"
584 default:
585 panic("Unknown GOOS")
586 }
587}
588
589// GoRoot returns the path to the root directory of the Go toolchain.
Colin Cross1332b002015-04-07 17:11:30 -0700590func (c *config) GoRoot() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800591 return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS())
592}
593
Jingwen Chenc711fec2020-11-22 23:52:50 -0500594// PrebuiltBuildTool returns the path to a tool in the prebuilts directory containing
595// checked-in tools, like Kati, Ninja or Toybox, for the current host OS.
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700596func (c *config) PrebuiltBuildTool(ctx PathContext, tool string) Path {
597 return PathForSource(ctx, "prebuilts/build-tools", c.PrebuiltOS(), "bin", tool)
598}
599
Jingwen Chenc711fec2020-11-22 23:52:50 -0500600// CpPreserveSymlinksFlags returns the host-specific flag for the cp(1) command
601// to preserve symlinks.
Colin Cross1332b002015-04-07 17:11:30 -0700602func (c *config) CpPreserveSymlinksFlags() string {
Colin Cross485e5722015-08-27 13:28:01 -0700603 switch runtime.GOOS {
Colin Cross3f40fa42015-01-30 17:27:36 -0800604 case "darwin":
605 return "-R"
606 case "linux":
607 return "-d"
608 default:
609 return ""
610 }
611}
Colin Cross68f55102015-03-25 14:43:57 -0700612
Colin Cross1332b002015-04-07 17:11:30 -0700613func (c *config) Getenv(key string) string {
Colin Cross68f55102015-03-25 14:43:57 -0700614 var val string
615 var exists bool
Colin Crossc1e86a32015-04-15 12:33:28 -0700616 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800617 defer c.envLock.Unlock()
618 if c.envDeps == nil {
619 c.envDeps = make(map[string]string)
620 }
Colin Cross68f55102015-03-25 14:43:57 -0700621 if val, exists = c.envDeps[key]; !exists {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700622 if c.envFrozen {
623 panic("Cannot access new environment variables after envdeps are frozen")
624 }
Colin Cross6ccbc912017-10-10 23:07:38 -0700625 val, _ = c.env[key]
Colin Cross68f55102015-03-25 14:43:57 -0700626 c.envDeps[key] = val
627 }
628 return val
629}
630
Colin Cross99d7c232016-11-23 16:52:04 -0800631func (c *config) GetenvWithDefault(key string, defaultValue string) string {
632 ret := c.Getenv(key)
633 if ret == "" {
634 return defaultValue
635 }
636 return ret
637}
638
639func (c *config) IsEnvTrue(key string) bool {
640 value := c.Getenv(key)
641 return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
642}
643
644func (c *config) IsEnvFalse(key string) bool {
645 value := c.Getenv(key)
646 return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
647}
648
Jingwen Chenc711fec2020-11-22 23:52:50 -0500649// EnvDeps returns the environment variables this build depends on. The first
650// call to this function blocks future reads from the environment.
Colin Cross1332b002015-04-07 17:11:30 -0700651func (c *config) EnvDeps() map[string]string {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700652 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800653 defer c.envLock.Unlock()
Dan Willemsene7680ba2015-09-11 17:06:19 -0700654 c.envFrozen = true
Colin Cross68f55102015-03-25 14:43:57 -0700655 return c.envDeps
656}
Colin Cross35cec122015-04-02 14:37:16 -0700657
Jingwen Chencda22c92020-11-23 00:22:30 -0500658func (c *config) KatiEnabled() bool {
659 return c.katiEnabled
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800660}
661
Nan Zhang581fd212018-01-10 16:06:12 -0800662func (c *config) BuildId() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800663 return String(c.productVariables.BuildId)
Nan Zhang581fd212018-01-10 16:06:12 -0800664}
665
Jingwen Chenc711fec2020-11-22 23:52:50 -0500666// BuildNumberFile returns the path to a text file containing metadata
667// representing the current build's number.
668//
669// Rules that want to reference the build number should read from this file
670// without depending on it. They will run whenever their other dependencies
671// require them to run and get the current build number. This ensures they don't
672// rebuild on every incremental build when the build number changes.
Colin Cross2a2e0db2020-02-21 16:55:46 -0800673func (c *config) BuildNumberFile(ctx PathContext) Path {
674 return PathForOutput(ctx, String(c.productVariables.BuildNumberFile))
Nan Zhang581fd212018-01-10 16:06:12 -0800675}
676
Jingwen Chenc711fec2020-11-22 23:52:50 -0500677// DeviceName returns the name of the current device target.
Colin Cross35cec122015-04-02 14:37:16 -0700678// TODO: take an AndroidModuleContext to select the device name for multi-device builds
Colin Cross1332b002015-04-07 17:11:30 -0700679func (c *config) DeviceName() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800680 return *c.productVariables.DeviceName
Colin Cross35cec122015-04-02 14:37:16 -0700681}
682
Anton Hansson53c88442019-03-18 15:53:16 +0000683func (c *config) DeviceResourceOverlays() []string {
684 return c.productVariables.DeviceResourceOverlays
685}
686
687func (c *config) ProductResourceOverlays() []string {
688 return c.productVariables.ProductResourceOverlays
Colin Cross30e076a2015-04-13 13:58:27 -0700689}
690
Colin Crossbfd347d2018-05-09 11:11:35 -0700691func (c *config) PlatformVersionName() string {
692 return String(c.productVariables.Platform_version_name)
693}
694
Dan Albert4f378d72020-07-23 17:32:15 -0700695func (c *config) PlatformSdkVersion() ApiLevel {
696 return uncheckedFinalApiLevel(*c.productVariables.Platform_sdk_version)
Colin Cross30e076a2015-04-13 13:58:27 -0700697}
698
Colin Crossd09b0b62018-04-18 11:06:47 -0700699func (c *config) PlatformSdkCodename() string {
700 return String(c.productVariables.Platform_sdk_codename)
701}
702
Colin Cross092c9da2019-04-02 22:56:43 -0700703func (c *config) PlatformSecurityPatch() string {
704 return String(c.productVariables.Platform_security_patch)
705}
706
707func (c *config) PlatformPreviewSdkVersion() string {
708 return String(c.productVariables.Platform_preview_sdk_version)
709}
710
711func (c *config) PlatformMinSupportedTargetSdkVersion() string {
712 return String(c.productVariables.Platform_min_supported_target_sdk_version)
713}
714
715func (c *config) PlatformBaseOS() string {
716 return String(c.productVariables.Platform_base_os)
717}
718
Dan Albert1a246272020-07-06 14:49:35 -0700719func (c *config) MinSupportedSdkVersion() ApiLevel {
720 return uncheckedFinalApiLevel(16)
721}
722
723func (c *config) FinalApiLevels() []ApiLevel {
724 var levels []ApiLevel
Dan Albert4f378d72020-07-23 17:32:15 -0700725 for i := 1; i <= c.PlatformSdkVersion().FinalOrFutureInt(); i++ {
Dan Albert1a246272020-07-06 14:49:35 -0700726 levels = append(levels, uncheckedFinalApiLevel(i))
727 }
728 return levels
729}
730
731func (c *config) PreviewApiLevels() []ApiLevel {
732 var levels []ApiLevel
733 for i, codename := range c.PlatformVersionActiveCodenames() {
734 levels = append(levels, ApiLevel{
735 value: codename,
736 number: i,
737 isPreview: true,
738 })
739 }
740 return levels
741}
742
743func (c *config) AllSupportedApiLevels() []ApiLevel {
744 var levels []ApiLevel
745 levels = append(levels, c.FinalApiLevels()...)
746 return append(levels, c.PreviewApiLevels()...)
Dan Albertf5415d72017-08-17 16:19:59 -0700747}
748
Jingwen Chenc711fec2020-11-22 23:52:50 -0500749// DefaultAppTargetSdk returns the API level that platform apps are targeting.
750// This converts a codename to the exact ApiLevel it represents.
Dan Albert4f378d72020-07-23 17:32:15 -0700751func (c *config) DefaultAppTargetSdk(ctx EarlyModuleContext) ApiLevel {
Colin Crossd09b0b62018-04-18 11:06:47 -0700752 if Bool(c.productVariables.Platform_sdk_final) {
753 return c.PlatformSdkVersion()
Colin Crossd09b0b62018-04-18 11:06:47 -0700754 }
Jingwen Chenc711fec2020-11-22 23:52:50 -0500755 codename := c.PlatformSdkCodename()
756 if codename == "" {
757 return NoneApiLevel
758 }
759 if codename == "REL" {
760 panic("Platform_sdk_codename should not be REL when Platform_sdk_final is true")
761 }
762 return ApiLevelOrPanic(ctx, codename)
Colin Crossd09b0b62018-04-18 11:06:47 -0700763}
764
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800765func (c *config) AppsDefaultVersionName() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800766 return String(c.productVariables.AppsDefaultVersionName)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800767}
768
Dan Albert31384de2017-07-28 12:39:46 -0700769// Codenames that are active in the current lunch target.
770func (c *config) PlatformVersionActiveCodenames() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800771 return c.productVariables.Platform_version_active_codenames
Dan Albert31384de2017-07-28 12:39:46 -0700772}
773
Colin Crossface4e42017-10-30 17:32:15 -0700774func (c *config) ProductAAPTConfig() []string {
Colin Crossa74ca042019-01-31 14:31:51 -0800775 return c.productVariables.AAPTConfig
Colin Cross30e076a2015-04-13 13:58:27 -0700776}
777
Colin Crossface4e42017-10-30 17:32:15 -0700778func (c *config) ProductAAPTPreferredConfig() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800779 return String(c.productVariables.AAPTPreferredConfig)
Colin Cross30e076a2015-04-13 13:58:27 -0700780}
781
Colin Crossface4e42017-10-30 17:32:15 -0700782func (c *config) ProductAAPTCharacteristics() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800783 return String(c.productVariables.AAPTCharacteristics)
Colin Crossface4e42017-10-30 17:32:15 -0700784}
785
786func (c *config) ProductAAPTPrebuiltDPI() []string {
Colin Crossa74ca042019-01-31 14:31:51 -0800787 return c.productVariables.AAPTPrebuiltDPI
Colin Cross30e076a2015-04-13 13:58:27 -0700788}
789
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700790func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800791 defaultCert := String(c.productVariables.DefaultAppCertificate)
Colin Cross61ae0b72017-12-01 17:16:02 -0800792 if defaultCert != "" {
793 return PathForSource(ctx, filepath.Dir(defaultCert))
Colin Cross61ae0b72017-12-01 17:16:02 -0800794 }
Jingwen Chenc711fec2020-11-22 23:52:50 -0500795 return PathForSource(ctx, "build/make/target/product/security")
Colin Cross30e076a2015-04-13 13:58:27 -0700796}
797
Colin Crosse1731a52017-12-14 11:22:55 -0800798func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800799 defaultCert := String(c.productVariables.DefaultAppCertificate)
Colin Cross61ae0b72017-12-01 17:16:02 -0800800 if defaultCert != "" {
Colin Crosse1731a52017-12-14 11:22:55 -0800801 return PathForSource(ctx, defaultCert+".x509.pem"), PathForSource(ctx, defaultCert+".pk8")
Colin Cross61ae0b72017-12-01 17:16:02 -0800802 }
Jingwen Chenc711fec2020-11-22 23:52:50 -0500803 defaultDir := c.DefaultAppCertificateDir(ctx)
804 return defaultDir.Join(ctx, "testkey.x509.pem"), defaultDir.Join(ctx, "testkey.pk8")
Colin Cross30e076a2015-04-13 13:58:27 -0700805}
Colin Cross6ff51382015-12-17 16:39:19 -0800806
Jiyong Park9335a262018-12-24 11:31:58 +0900807func (c *config) ApexKeyDir(ctx ModuleContext) SourcePath {
808 // TODO(b/121224311): define another variable such as TARGET_APEX_KEY_OVERRIDE
809 defaultCert := String(c.productVariables.DefaultAppCertificate)
Dan Willemsen412160e2019-04-09 21:36:26 -0700810 if defaultCert == "" || filepath.Dir(defaultCert) == "build/make/target/product/security" {
Jiyong Park9335a262018-12-24 11:31:58 +0900811 // When defaultCert is unset or is set to the testkeys path, use the APEX keys
812 // that is under the module dir
Colin Cross07e51612019-03-05 12:46:40 -0800813 return pathForModuleSrc(ctx)
Jiyong Park9335a262018-12-24 11:31:58 +0900814 }
Jingwen Chenc711fec2020-11-22 23:52:50 -0500815 // If not, APEX keys are under the specified directory
816 return PathForSource(ctx, filepath.Dir(defaultCert))
Jiyong Park9335a262018-12-24 11:31:58 +0900817}
818
Jingwen Chenc711fec2020-11-22 23:52:50 -0500819// AllowMissingDependencies configures Blueprint/Soong to not fail when modules
820// are configured to depend on non-existent modules. Note that this does not
821// affect missing input dependencies at the Ninja level.
Colin Cross6ff51382015-12-17 16:39:19 -0800822func (c *config) AllowMissingDependencies() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800823 return Bool(c.productVariables.Allow_missing_dependencies)
Colin Cross6ff51382015-12-17 16:39:19 -0800824}
Dan Willemsen322acaf2016-01-12 23:07:05 -0800825
Jeongik Cha816a23a2020-07-08 01:09:23 +0900826// Returns true if a full platform source tree cannot be assumed.
Colin Crossfc3674a2017-09-18 17:41:52 -0700827func (c *config) UnbundledBuild() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800828 return Bool(c.productVariables.Unbundled_build)
Colin Crossfc3674a2017-09-18 17:41:52 -0700829}
830
Martin Stjernholmfd9eb4b2020-06-17 01:13:15 +0100831// Returns true if building apps that aren't bundled with the platform.
832// UnbundledBuild() is always true when this is true.
833func (c *config) UnbundledBuildApps() bool {
834 return Bool(c.productVariables.Unbundled_build_apps)
835}
836
Jeongik Cha816a23a2020-07-08 01:09:23 +0900837// Returns true if building modules against prebuilt SDKs.
838func (c *config) AlwaysUsePrebuiltSdks() bool {
839 return Bool(c.productVariables.Always_use_prebuilt_sdks)
Colin Cross1f367bf2018-12-18 22:46:24 -0800840}
841
Paul Duffin9a89a2a2020-10-28 19:20:06 +0000842// Returns true if the boot jars check should be skipped.
843func (c *config) SkipBootJarsCheck() bool {
844 return Bool(c.productVariables.Skip_boot_jars_check)
845}
846
Doug Horn21b94272019-01-16 12:06:11 -0800847func (c *config) Fuchsia() bool {
848 return Bool(c.productVariables.Fuchsia)
849}
850
Colin Cross126a25c2017-10-31 13:55:34 -0700851func (c *config) MinimizeJavaDebugInfo() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800852 return Bool(c.productVariables.MinimizeJavaDebugInfo) && !Bool(c.productVariables.Eng)
Colin Cross126a25c2017-10-31 13:55:34 -0700853}
854
Colin Crossed064c02018-09-05 16:28:13 -0700855func (c *config) Debuggable() bool {
856 return Bool(c.productVariables.Debuggable)
857}
858
Jaewoong Jung1d6eb682018-11-29 15:08:44 -0800859func (c *config) Eng() bool {
860 return Bool(c.productVariables.Eng)
861}
862
Jiyong Park8d52f862018-07-07 18:02:07 +0900863func (c *config) DevicePrimaryArchType() ArchType {
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700864 return c.Targets[Android][0].Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +0900865}
866
Colin Cross893d8162017-04-26 17:34:03 -0700867func (c *config) SkipMegaDeviceInstall(path string) bool {
868 return Bool(c.Mega_device) &&
869 strings.HasPrefix(path, filepath.Join(c.buildDir, "target", "product"))
Dan Willemsen322acaf2016-01-12 23:07:05 -0800870}
Colin Cross16b23492016-01-06 14:41:07 -0800871
872func (c *config) SanitizeHost() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800873 return append([]string(nil), c.productVariables.SanitizeHost...)
Colin Cross16b23492016-01-06 14:41:07 -0800874}
875
876func (c *config) SanitizeDevice() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800877 return append([]string(nil), c.productVariables.SanitizeDevice...)
Colin Cross23ae82a2016-11-02 14:34:39 -0700878}
879
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700880func (c *config) SanitizeDeviceDiag() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800881 return append([]string(nil), c.productVariables.SanitizeDeviceDiag...)
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700882}
883
Colin Cross23ae82a2016-11-02 14:34:39 -0700884func (c *config) SanitizeDeviceArch() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800885 return append([]string(nil), c.productVariables.SanitizeDeviceArch...)
Colin Cross16b23492016-01-06 14:41:07 -0800886}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700887
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800888func (c *config) EnableCFI() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800889 if c.productVariables.EnableCFI == nil {
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -0800890 return true
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -0800891 }
Jingwen Chenc711fec2020-11-22 23:52:50 -0500892 return *c.productVariables.EnableCFI
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800893}
894
Kostya Kortchinskyd5275c82019-02-01 08:42:56 -0800895func (c *config) DisableScudo() bool {
896 return Bool(c.productVariables.DisableScudo)
897}
898
Colin Crossa1ad8d12016-06-01 17:09:44 -0700899func (c *config) Android64() bool {
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700900 for _, t := range c.Targets[Android] {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700901 if t.Arch.ArchType.Multilib == "lib64" {
902 return true
903 }
904 }
905
906 return false
907}
Colin Cross9272ade2016-08-17 15:24:12 -0700908
Colin Cross9d45bb72016-08-29 16:14:13 -0700909func (c *config) UseGoma() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800910 return Bool(c.productVariables.UseGoma)
Colin Cross9d45bb72016-08-29 16:14:13 -0700911}
912
Ramy Medhatbbf25672019-07-17 12:30:04 +0000913func (c *config) UseRBE() bool {
914 return Bool(c.productVariables.UseRBE)
915}
916
Ramy Medhat8ea054a2020-01-27 14:19:44 -0500917func (c *config) UseRBEJAVAC() bool {
918 return Bool(c.productVariables.UseRBEJAVAC)
919}
920
921func (c *config) UseRBER8() bool {
922 return Bool(c.productVariables.UseRBER8)
923}
924
925func (c *config) UseRBED8() bool {
926 return Bool(c.productVariables.UseRBED8)
927}
928
Colin Cross8b8bec32019-11-15 13:18:43 -0800929func (c *config) UseRemoteBuild() bool {
930 return c.UseGoma() || c.UseRBE()
931}
932
Colin Cross66548102018-06-19 22:47:35 -0700933func (c *config) RunErrorProne() bool {
934 return c.IsEnvTrue("RUN_ERROR_PRONE")
935}
936
Jingwen Chenc711fec2020-11-22 23:52:50 -0500937// XrefCorpusName returns the Kythe cross-reference corpus name.
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800938func (c *config) XrefCorpusName() string {
939 return c.Getenv("XREF_CORPUS")
940}
941
Jingwen Chenc711fec2020-11-22 23:52:50 -0500942// XrefCuEncoding returns the compilation unit encoding to use for Kythe code
943// xrefs. Can be 'json' (default), 'proto' or 'all'.
Sasha Smundak6c2d4f92020-01-09 17:34:23 -0800944func (c *config) XrefCuEncoding() string {
945 if enc := c.Getenv("KYTHE_KZIP_ENCODING"); enc != "" {
946 return enc
947 }
948 return "json"
949}
950
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800951func (c *config) EmitXrefRules() bool {
952 return c.XrefCorpusName() != ""
953}
954
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700955func (c *config) ClangTidy() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800956 return Bool(c.productVariables.ClangTidy)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700957}
958
959func (c *config) TidyChecks() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800960 if c.productVariables.TidyChecks == nil {
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700961 return ""
962 }
Dan Willemsen45133ac2018-03-09 21:22:06 -0800963 return *c.productVariables.TidyChecks
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700964}
965
Colin Cross0f4e0d62016-07-27 10:56:55 -0700966func (c *config) LibartImgHostBaseAddress() string {
967 return "0x60000000"
968}
969
970func (c *config) LibartImgDeviceBaseAddress() string {
Elliott Hughesda3a0712020-03-06 16:55:28 -0800971 return "0x70000000"
Colin Cross0f4e0d62016-07-27 10:56:55 -0700972}
973
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800974func (c *config) ArtUseReadBarrier() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800975 return Bool(c.productVariables.ArtUseReadBarrier)
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800976}
977
Jingwen Chenc711fec2020-11-22 23:52:50 -0500978// Enforce Runtime Resource Overlays for a module. RROs supersede static RROs,
979// but some modules still depend on it.
980//
981// More info: https://source.android.com/devices/architecture/rros
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700982func (c *config) EnforceRROForModule(name string) bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800983 enforceList := c.productVariables.EnforceRROTargets
Jeongik Chab9b13272020-03-09 12:37:05 +0900984 // TODO(b/150820813) Some modules depend on static overlay, remove this after eliminating the dependency.
985 exemptedList := c.productVariables.EnforceRROExemptedTargets
Roland Levillainf6cc2612020-07-09 16:58:14 +0100986 if len(exemptedList) > 0 {
Jeongik Chab9b13272020-03-09 12:37:05 +0900987 if InList(name, exemptedList) {
988 return false
989 }
990 }
Roland Levillainf6cc2612020-07-09 16:58:14 +0100991 if len(enforceList) > 0 {
Yo Chiang4ebd06a2019-10-01 13:13:41 +0800992 if InList("*", enforceList) {
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700993 return true
994 }
Colin Crossa74ca042019-01-31 14:31:51 -0800995 return InList(name, enforceList)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700996 }
997 return false
998}
999
Jaewoong Jungc779cd42020-10-06 18:56:10 -07001000func (c *config) EnforceRROExemptedForModule(name string) bool {
1001 return InList(name, c.productVariables.EnforceRROExemptedTargets)
1002}
1003
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001004func (c *config) EnforceRROExcludedOverlay(path string) bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001005 excluded := c.productVariables.EnforceRROExcludedOverlays
Roland Levillainf6cc2612020-07-09 16:58:14 +01001006 if len(excluded) > 0 {
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001007 return HasAnyPrefix(path, excluded)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001008 }
1009 return false
1010}
1011
1012func (c *config) ExportedNamespaces() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001013 return append([]string(nil), c.productVariables.NamespacesToExport...)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001014}
1015
1016func (c *config) HostStaticBinaries() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001017 return Bool(c.productVariables.HostStaticBinaries)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -07001018}
1019
Colin Cross5a0dcd52018-10-05 14:20:06 -07001020func (c *config) UncompressPrivAppDex() bool {
1021 return Bool(c.productVariables.UncompressPrivAppDex)
1022}
1023
1024func (c *config) ModulesLoadedByPrivilegedModules() []string {
1025 return c.productVariables.ModulesLoadedByPrivilegedModules
1026}
1027
Jingwen Chenc711fec2020-11-22 23:52:50 -05001028// DexpreoptGlobalConfigPath returns the path to the dexpreopt.config file in
1029// the output directory, if it was created during the product configuration
1030// phase by Kati.
Jingwen Chenebb0b572020-11-02 00:24:57 -05001031func (c *config) DexpreoptGlobalConfigPath(ctx PathContext) OptionalPath {
Colin Cross988414c2020-01-11 01:11:46 +00001032 if c.productVariables.DexpreoptGlobalConfig == nil {
Jingwen Chenebb0b572020-11-02 00:24:57 -05001033 return OptionalPathForPath(nil)
1034 }
1035 return OptionalPathForPath(
1036 pathForBuildToolDep(ctx, *c.productVariables.DexpreoptGlobalConfig))
1037}
1038
Jingwen Chenc711fec2020-11-22 23:52:50 -05001039// DexpreoptGlobalConfig returns the raw byte contents of the dexpreopt global
1040// configuration. Since the configuration file was created by Kati during
1041// product configuration (externally of soong_build), it's not tracked, so we
1042// also manually add a Ninja file dependency on the configuration file to the
1043// rule that creates the main build.ninja file. This ensures that build.ninja is
1044// regenerated correctly if dexpreopt.config changes.
Jingwen Chenebb0b572020-11-02 00:24:57 -05001045func (c *config) DexpreoptGlobalConfig(ctx PathContext) ([]byte, error) {
1046 path := c.DexpreoptGlobalConfigPath(ctx)
1047 if !path.Valid() {
Colin Cross988414c2020-01-11 01:11:46 +00001048 return nil, nil
1049 }
Jingwen Chenebb0b572020-11-02 00:24:57 -05001050 ctx.AddNinjaFileDeps(path.String())
1051 return ioutil.ReadFile(absolutePath(path.String()))
Colin Cross43f08db2018-11-12 10:13:39 -08001052}
1053
David Brazdil91b4e3e2019-01-23 21:04:05 +00001054func (c *config) FrameworksBaseDirExists(ctx PathContext) bool {
1055 return ExistentPathForSource(ctx, "frameworks", "base").Valid()
1056}
1057
Inseob Kimae553032019-05-14 18:52:49 +09001058func (c *config) VndkSnapshotBuildArtifacts() bool {
1059 return Bool(c.productVariables.VndkSnapshotBuildArtifacts)
1060}
1061
Colin Cross3b19f5d2019-09-17 14:45:31 -07001062func (c *config) HasMultilibConflict(arch ArchType) bool {
1063 return c.multilibConflicts[arch]
1064}
1065
Colin Cross9272ade2016-08-17 15:24:12 -07001066func (c *deviceConfig) Arches() []Arch {
1067 var arches []Arch
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001068 for _, target := range c.config.Targets[Android] {
Colin Cross9272ade2016-08-17 15:24:12 -07001069 arches = append(arches, target.Arch)
1070 }
1071 return arches
1072}
Dan Willemsend2ede872016-11-18 14:54:24 -08001073
Jayant Chowdhary34ce67d2018-03-08 11:00:50 -08001074func (c *deviceConfig) BinderBitness() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001075 is32BitBinder := c.config.productVariables.Binder32bit
Jayant Chowdhary34ce67d2018-03-08 11:00:50 -08001076 if is32BitBinder != nil && *is32BitBinder {
1077 return "32"
1078 }
1079 return "64"
1080}
1081
Dan Willemsen4353bc42016-12-05 17:16:02 -08001082func (c *deviceConfig) VendorPath() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001083 if c.config.productVariables.VendorPath != nil {
1084 return *c.config.productVariables.VendorPath
Dan Willemsen4353bc42016-12-05 17:16:02 -08001085 }
1086 return "vendor"
1087}
1088
Justin Yun71549282017-11-17 12:10:28 +09001089func (c *deviceConfig) VndkVersion() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001090 return String(c.config.productVariables.DeviceVndkVersion)
Justin Yun71549282017-11-17 12:10:28 +09001091}
1092
Jeongik Cha219141c2020-08-06 23:00:37 +09001093func (c *deviceConfig) CurrentApiLevelForVendorModules() string {
1094 return StringDefault(c.config.productVariables.DeviceCurrentApiLevelForVendorModules, "current")
1095}
1096
Justin Yun8fe12122017-12-07 17:18:15 +09001097func (c *deviceConfig) PlatformVndkVersion() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001098 return String(c.config.productVariables.Platform_vndk_version)
Justin Yun8fe12122017-12-07 17:18:15 +09001099}
1100
Justin Yun5f7f7e82019-11-18 19:52:14 +09001101func (c *deviceConfig) ProductVndkVersion() string {
1102 return String(c.config.productVariables.ProductVndkVersion)
1103}
1104
Justin Yun71549282017-11-17 12:10:28 +09001105func (c *deviceConfig) ExtraVndkVersions() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001106 return c.config.productVariables.ExtraVndkVersions
Dan Willemsend2ede872016-11-18 14:54:24 -08001107}
Jack He8cc71432016-12-08 15:45:07 -08001108
Vic Yangefd249e2018-11-12 20:19:56 -08001109func (c *deviceConfig) VndkUseCoreVariant() bool {
1110 return Bool(c.config.productVariables.VndkUseCoreVariant)
1111}
1112
Jiyong Park1a5d7b12018-01-15 15:05:10 +09001113func (c *deviceConfig) SystemSdkVersions() []string {
Colin Crossa74ca042019-01-31 14:31:51 -08001114 return c.config.productVariables.DeviceSystemSdkVersions
Jiyong Park1a5d7b12018-01-15 15:05:10 +09001115}
1116
1117func (c *deviceConfig) PlatformSystemSdkVersions() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001118 return c.config.productVariables.Platform_systemsdk_versions
Jiyong Park1a5d7b12018-01-15 15:05:10 +09001119}
1120
Jiyong Park2db76922017-11-08 16:03:48 +09001121func (c *deviceConfig) OdmPath() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001122 if c.config.productVariables.OdmPath != nil {
1123 return *c.config.productVariables.OdmPath
Jiyong Park2db76922017-11-08 16:03:48 +09001124 }
1125 return "odm"
1126}
1127
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +09001128func (c *deviceConfig) ProductPath() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001129 if c.config.productVariables.ProductPath != nil {
1130 return *c.config.productVariables.ProductPath
Jiyong Park2db76922017-11-08 16:03:48 +09001131 }
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +09001132 return "product"
Jiyong Park2db76922017-11-08 16:03:48 +09001133}
1134
Justin Yund5f6c822019-06-25 16:47:17 +09001135func (c *deviceConfig) SystemExtPath() string {
1136 if c.config.productVariables.SystemExtPath != nil {
1137 return *c.config.productVariables.SystemExtPath
Dario Frenifd05a742018-05-29 13:28:54 +01001138 }
Justin Yund5f6c822019-06-25 16:47:17 +09001139 return "system_ext"
Dario Frenifd05a742018-05-29 13:28:54 +01001140}
1141
Jack He8cc71432016-12-08 15:45:07 -08001142func (c *deviceConfig) BtConfigIncludeDir() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001143 return String(c.config.productVariables.BtConfigIncludeDir)
Jack He8cc71432016-12-08 15:45:07 -08001144}
Dan Willemsen581341d2017-02-09 16:16:31 -08001145
Jiyong Parkd773eb32017-07-03 13:18:12 +09001146func (c *deviceConfig) DeviceKernelHeaderDirs() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001147 return c.config.productVariables.DeviceKernelHeaders
Jiyong Parkd773eb32017-07-03 13:18:12 +09001148}
1149
Yi Kongceb5b762020-03-20 15:22:27 +08001150func (c *deviceConfig) SamplingPGO() bool {
1151 return Bool(c.config.productVariables.SamplingPGO)
1152}
1153
Roland Levillainada12702020-06-09 13:07:36 +01001154// JavaCoverageEnabledForPath returns whether Java code coverage is enabled for
1155// path. Coverage is enabled by default when the product variable
1156// JavaCoveragePaths is empty. If JavaCoveragePaths is not empty, coverage is
1157// enabled for any path which is part of this variable (and not part of the
1158// JavaCoverageExcludePaths product variable). Value "*" in JavaCoveragePaths
1159// represents any path.
1160func (c *deviceConfig) JavaCoverageEnabledForPath(path string) bool {
1161 coverage := false
Chris Gross2f748692020-06-24 20:36:59 +00001162 if len(c.config.productVariables.JavaCoveragePaths) == 0 ||
Roland Levillainada12702020-06-09 13:07:36 +01001163 InList("*", c.config.productVariables.JavaCoveragePaths) ||
1164 HasAnyPrefix(path, c.config.productVariables.JavaCoveragePaths) {
1165 coverage = true
1166 }
Roland Levillainf6cc2612020-07-09 16:58:14 +01001167 if coverage && len(c.config.productVariables.JavaCoverageExcludePaths) > 0 {
Roland Levillainada12702020-06-09 13:07:36 +01001168 if HasAnyPrefix(path, c.config.productVariables.JavaCoverageExcludePaths) {
1169 coverage = false
1170 }
1171 }
1172 return coverage
1173}
1174
Colin Cross1a6acd42020-06-16 17:51:46 -07001175// Returns true if gcov or clang coverage is enabled.
Dan Willemsen581341d2017-02-09 16:16:31 -08001176func (c *deviceConfig) NativeCoverageEnabled() bool {
Colin Cross1a6acd42020-06-16 17:51:46 -07001177 return Bool(c.config.productVariables.GcovCoverage) ||
1178 Bool(c.config.productVariables.ClangCoverage)
Dan Willemsen581341d2017-02-09 16:16:31 -08001179}
1180
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001181func (c *deviceConfig) ClangCoverageEnabled() bool {
1182 return Bool(c.config.productVariables.ClangCoverage)
1183}
1184
Colin Cross1a6acd42020-06-16 17:51:46 -07001185func (c *deviceConfig) GcovCoverageEnabled() bool {
1186 return Bool(c.config.productVariables.GcovCoverage)
1187}
1188
Roland Levillain4f5297b2020-06-09 12:44:06 +01001189// NativeCoverageEnabledForPath returns whether (GCOV- or Clang-based) native
1190// code coverage is enabled for path. By default, coverage is not enabled for a
1191// given path unless it is part of the NativeCoveragePaths product variable (and
1192// not part of the NativeCoverageExcludePaths product variable). Value "*" in
1193// NativeCoveragePaths represents any path.
1194func (c *deviceConfig) NativeCoverageEnabledForPath(path string) bool {
Ryan Campbell469a18a2017-02-27 09:01:54 -08001195 coverage := false
Roland Levillainf6cc2612020-07-09 16:58:14 +01001196 if len(c.config.productVariables.NativeCoveragePaths) > 0 {
Roland Levillain4f5297b2020-06-09 12:44:06 +01001197 if InList("*", c.config.productVariables.NativeCoveragePaths) || HasAnyPrefix(path, c.config.productVariables.NativeCoveragePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -07001198 coverage = true
Dan Willemsen581341d2017-02-09 16:16:31 -08001199 }
1200 }
Roland Levillainf6cc2612020-07-09 16:58:14 +01001201 if coverage && len(c.config.productVariables.NativeCoverageExcludePaths) > 0 {
Roland Levillain4f5297b2020-06-09 12:44:06 +01001202 if HasAnyPrefix(path, c.config.productVariables.NativeCoverageExcludePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -07001203 coverage = false
Ryan Campbell469a18a2017-02-27 09:01:54 -08001204 }
1205 }
1206 return coverage
Dan Willemsen581341d2017-02-09 16:16:31 -08001207}
Ivan Lozano5f595532017-07-13 14:46:05 -07001208
Pirama Arumuga Nainar49540802018-01-29 23:11:42 -08001209func (c *deviceConfig) PgoAdditionalProfileDirs() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001210 return c.config.productVariables.PgoAdditionalProfileDirs
Pirama Arumuga Nainar49540802018-01-29 23:11:42 -08001211}
1212
Tri Vo35a51432018-03-25 20:00:00 -07001213func (c *deviceConfig) VendorSepolicyDirs() []string {
1214 return c.config.productVariables.BoardVendorSepolicyDirs
1215}
1216
1217func (c *deviceConfig) OdmSepolicyDirs() []string {
1218 return c.config.productVariables.BoardOdmSepolicyDirs
1219}
1220
Felixa20a8752020-05-17 18:28:35 +02001221func (c *deviceConfig) SystemExtPublicSepolicyDirs() []string {
1222 return c.config.productVariables.SystemExtPublicSepolicyDirs
Tri Vo35a51432018-03-25 20:00:00 -07001223}
1224
Felixa20a8752020-05-17 18:28:35 +02001225func (c *deviceConfig) SystemExtPrivateSepolicyDirs() []string {
1226 return c.config.productVariables.SystemExtPrivateSepolicyDirs
Tri Vo35a51432018-03-25 20:00:00 -07001227}
1228
Inseob Kim0866b002019-04-15 20:21:29 +09001229func (c *deviceConfig) SepolicyM4Defs() []string {
1230 return c.config.productVariables.BoardSepolicyM4Defs
1231}
1232
Jiyong Park7f67f482019-01-05 12:57:48 +09001233func (c *deviceConfig) OverrideManifestPackageNameFor(name string) (manifestName string, overridden bool) {
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001234 return findOverrideValue(c.config.productVariables.ManifestPackageNameOverrides, name,
1235 "invalid override rule %q in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES should be <module_name>:<manifest_name>")
1236}
1237
1238func (c *deviceConfig) OverrideCertificateFor(name string) (certificatePath string, overridden bool) {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001239 return findOverrideValue(c.config.productVariables.CertificateOverrides, name,
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001240 "invalid override rule %q in PRODUCT_CERTIFICATE_OVERRIDES should be <module_name>:<certificate_module_name>")
1241}
1242
Jaewoong Jung9d22a912019-01-23 16:27:47 -08001243func (c *deviceConfig) OverridePackageNameFor(name string) string {
1244 newName, overridden := findOverrideValue(
1245 c.config.productVariables.PackageNameOverrides,
1246 name,
1247 "invalid override rule %q in PRODUCT_PACKAGE_NAME_OVERRIDES should be <module_name>:<package_name>")
1248 if overridden {
1249 return newName
1250 }
1251 return name
1252}
1253
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001254func findOverrideValue(overrides []string, name string, errorMsg string) (newValue string, overridden bool) {
Jiyong Park7f67f482019-01-05 12:57:48 +09001255 if overrides == nil || len(overrides) == 0 {
1256 return "", false
1257 }
1258 for _, o := range overrides {
1259 split := strings.Split(o, ":")
1260 if len(split) != 2 {
1261 // This shouldn't happen as this is first checked in make, but just in case.
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001262 panic(fmt.Errorf(errorMsg, o))
Jiyong Park7f67f482019-01-05 12:57:48 +09001263 }
1264 if matchPattern(split[0], name) {
1265 return substPattern(split[0], split[1], name), true
1266 }
1267 }
1268 return "", false
1269}
1270
Ivan Lozano5f595532017-07-13 14:46:05 -07001271func (c *config) IntegerOverflowDisabledForPath(path string) bool {
Roland Levillainf6cc2612020-07-09 16:58:14 +01001272 if len(c.productVariables.IntegerOverflowExcludePaths) == 0 {
Ivan Lozano5f595532017-07-13 14:46:05 -07001273 return false
1274 }
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001275 return HasAnyPrefix(path, c.productVariables.IntegerOverflowExcludePaths)
Ivan Lozano5f595532017-07-13 14:46:05 -07001276}
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001277
1278func (c *config) CFIDisabledForPath(path string) bool {
Roland Levillainf6cc2612020-07-09 16:58:14 +01001279 if len(c.productVariables.CFIExcludePaths) == 0 {
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001280 return false
1281 }
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001282 return HasAnyPrefix(path, c.productVariables.CFIExcludePaths)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001283}
1284
1285func (c *config) CFIEnabledForPath(path string) bool {
Roland Levillainf6cc2612020-07-09 16:58:14 +01001286 if len(c.productVariables.CFIIncludePaths) == 0 {
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001287 return false
1288 }
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001289 return HasAnyPrefix(path, c.productVariables.CFIIncludePaths)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001290}
Colin Crosse15ddaf2017-12-04 11:24:31 -08001291
Dan Willemsen0fe78662018-03-26 12:41:18 -07001292func (c *config) VendorConfig(name string) VendorConfig {
Colin Cross9d34f352019-11-22 16:03:51 -08001293 return soongconfig.Config(c.productVariables.VendorVars[name])
Dan Willemsen0fe78662018-03-26 12:41:18 -07001294}
1295
Colin Cross395f2cf2018-10-24 16:10:32 -07001296func (c *config) NdkAbis() bool {
1297 return Bool(c.productVariables.Ndk_abis)
1298}
1299
Martin Stjernholmc1ecc432019-11-15 15:00:31 +00001300func (c *config) AmlAbis() bool {
1301 return Bool(c.productVariables.Aml_abis)
1302}
1303
Dan Albert23d37e02018-11-28 08:30:10 -08001304func (c *config) ExcludeDraftNdkApis() bool {
1305 return Bool(c.productVariables.Exclude_draft_ndk_apis)
1306}
1307
Jiyong Park8fd61922018-11-08 02:50:25 +09001308func (c *config) FlattenApex() bool {
Roland Levillaina3863212019-08-12 19:56:16 +01001309 return Bool(c.productVariables.Flatten_apex)
Jiyong Park8fd61922018-11-08 02:50:25 +09001310}
1311
Jeongik Chac9464142019-01-07 12:07:27 +09001312func (c *config) EnforceSystemCertificate() bool {
1313 return Bool(c.productVariables.EnforceSystemCertificate)
1314}
1315
Colin Cross440e0d02020-06-11 11:32:11 -07001316func (c *config) EnforceSystemCertificateAllowList() []string {
1317 return c.productVariables.EnforceSystemCertificateAllowList
Jeongik Chac9464142019-01-07 12:07:27 +09001318}
1319
Jeongik Cha2cc570d2019-10-29 15:44:45 +09001320func (c *config) EnforceProductPartitionInterface() bool {
1321 return Bool(c.productVariables.EnforceProductPartitionInterface)
1322}
1323
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001324func (c *config) InstallExtraFlattenedApexes() bool {
1325 return Bool(c.productVariables.InstallExtraFlattenedApexes)
1326}
1327
Colin Crossf24a22a2019-01-31 14:12:44 -08001328func (c *config) ProductHiddenAPIStubs() []string {
1329 return c.productVariables.ProductHiddenAPIStubs
Colin Cross8faf8fc2019-01-16 15:15:52 -08001330}
1331
Colin Crossf24a22a2019-01-31 14:12:44 -08001332func (c *config) ProductHiddenAPIStubsSystem() []string {
1333 return c.productVariables.ProductHiddenAPIStubsSystem
Colin Cross8faf8fc2019-01-16 15:15:52 -08001334}
1335
Colin Crossf24a22a2019-01-31 14:12:44 -08001336func (c *config) ProductHiddenAPIStubsTest() []string {
1337 return c.productVariables.ProductHiddenAPIStubsTest
Colin Cross8faf8fc2019-01-16 15:15:52 -08001338}
Dan Willemsen71c74602019-04-10 12:27:35 -07001339
Dan Willemsen54879d12019-04-18 10:08:46 -07001340func (c *deviceConfig) TargetFSConfigGen() []string {
Dan Willemsen71c74602019-04-10 12:27:35 -07001341 return c.config.productVariables.TargetFSConfigGen
1342}
Inseob Kim0866b002019-04-15 20:21:29 +09001343
1344func (c *config) ProductPublicSepolicyDirs() []string {
1345 return c.productVariables.ProductPublicSepolicyDirs
1346}
1347
1348func (c *config) ProductPrivateSepolicyDirs() []string {
1349 return c.productVariables.ProductPrivateSepolicyDirs
1350}
1351
1352func (c *config) ProductCompatibleProperty() bool {
1353 return Bool(c.productVariables.ProductCompatibleProperty)
1354}
Inseob Kim1f086e22019-05-09 13:29:15 +09001355
Colin Cross50ddcc42019-05-16 12:28:22 -07001356func (c *config) MissingUsesLibraries() []string {
1357 return c.productVariables.MissingUsesLibraries
1358}
1359
Inseob Kim1f086e22019-05-09 13:29:15 +09001360func (c *deviceConfig) DeviceArch() string {
1361 return String(c.config.productVariables.DeviceArch)
1362}
1363
1364func (c *deviceConfig) DeviceArchVariant() string {
1365 return String(c.config.productVariables.DeviceArchVariant)
1366}
1367
1368func (c *deviceConfig) DeviceSecondaryArch() string {
1369 return String(c.config.productVariables.DeviceSecondaryArch)
1370}
1371
1372func (c *deviceConfig) DeviceSecondaryArchVariant() string {
1373 return String(c.config.productVariables.DeviceSecondaryArchVariant)
1374}
Yifan Hong82db7352020-01-21 16:12:26 -08001375
1376func (c *deviceConfig) BoardUsesRecoveryAsBoot() bool {
1377 return Bool(c.config.productVariables.BoardUsesRecoveryAsBoot)
1378}
Yifan Hong97365ee2020-07-29 09:51:57 -07001379
1380func (c *deviceConfig) BoardKernelBinaries() []string {
1381 return c.config.productVariables.BoardKernelBinaries
1382}
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001383
Yifan Hong42bef8d2020-08-05 14:36:09 -07001384func (c *deviceConfig) BoardKernelModuleInterfaceVersions() []string {
1385 return c.config.productVariables.BoardKernelModuleInterfaceVersions
1386}
1387
Yifan Hongdd8dacc2020-10-21 15:40:17 -07001388func (c *deviceConfig) BoardMoveRecoveryResourcesToVendorBoot() bool {
1389 return Bool(c.config.productVariables.BoardMoveRecoveryResourcesToVendorBoot)
1390}
1391
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001392// The ConfiguredJarList struct provides methods for handling a list of (apex, jar) pairs.
1393// Such lists are used in the build system for things like bootclasspath jars or system server jars.
1394// The apex part is either an apex name, or a special names "platform" or "system_ext". Jar is a
1395// module name. The pairs come from Make product variables as a list of colon-separated strings.
1396//
1397// Examples:
1398// - "com.android.art:core-oj"
1399// - "platform:framework"
1400// - "system_ext:foo"
1401//
1402type ConfiguredJarList struct {
Jingwen Chenc711fec2020-11-22 23:52:50 -05001403 // A list of apex components, which can be an apex name,
1404 // or special names like "platform" or "system_ext".
1405 apexes []string
1406
1407 // A list of jar module name components.
1408 jars []string
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001409}
1410
Jingwen Chenc711fec2020-11-22 23:52:50 -05001411// Len returns the length of the list of jars.
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001412func (l *ConfiguredJarList) Len() int {
1413 return len(l.jars)
1414}
1415
Jingwen Chenc711fec2020-11-22 23:52:50 -05001416// Jar returns the idx-th jar component of (apex, jar) pairs.
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001417func (l *ConfiguredJarList) Jar(idx int) string {
1418 return l.jars[idx]
1419}
1420
Jingwen Chenc711fec2020-11-22 23:52:50 -05001421// Apex returns the idx-th apex component of (apex, jar) pairs.
Paul Duffin9a89a2a2020-10-28 19:20:06 +00001422func (l *ConfiguredJarList) Apex(idx int) string {
1423 return l.apexes[idx]
1424}
1425
Jingwen Chenc711fec2020-11-22 23:52:50 -05001426// ContainsJar returns true if the (apex, jar) pairs contains a pair with the
1427// given jar module name.
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001428func (l *ConfiguredJarList) ContainsJar(jar string) bool {
1429 return InList(jar, l.jars)
1430}
1431
1432// If the list contains the given (apex, jar) pair.
1433func (l *ConfiguredJarList) containsApexJarPair(apex, jar string) bool {
1434 for i := 0; i < l.Len(); i++ {
Paul Duffin1e8c6072020-10-23 18:28:55 +01001435 if apex == l.apexes[i] && jar == l.jars[i] {
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001436 return true
1437 }
1438 }
1439 return false
1440}
1441
Jingwen Chenc711fec2020-11-22 23:52:50 -05001442// IndexOfJar returns the first pair with the given jar name on the list, or -1
1443// if not found.
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001444func (l *ConfiguredJarList) IndexOfJar(jar string) int {
1445 return IndexList(jar, l.jars)
1446}
1447
Paul Duffin7d584e92020-10-23 18:26:03 +01001448func copyAndAppend(list []string, item string) []string {
1449 // Create the result list to be 1 longer than the input.
1450 result := make([]string, len(list)+1)
1451
1452 // Copy the whole input list into the result.
1453 count := copy(result, list)
1454
1455 // Insert the extra item at the end.
1456 result[count] = item
1457
1458 return result
1459}
1460
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001461// Append an (apex, jar) pair to the list.
Paul Duffin7d584e92020-10-23 18:26:03 +01001462func (l *ConfiguredJarList) Append(apex string, jar string) ConfiguredJarList {
1463 // Create a copy of the backing arrays before appending to avoid sharing backing
1464 // arrays that are mutated across instances.
1465 apexes := copyAndAppend(l.apexes, apex)
1466 jars := copyAndAppend(l.jars, jar)
1467
1468 return ConfiguredJarList{apexes, jars}
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001469}
1470
Jingwen Chenc711fec2020-11-22 23:52:50 -05001471// RemoveList filters out a list of (apex, jar) pairs from the receiving list of pairs.
Paul Duffin7d584e92020-10-23 18:26:03 +01001472func (l *ConfiguredJarList) RemoveList(list ConfiguredJarList) ConfiguredJarList {
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001473 apexes := make([]string, 0, l.Len())
1474 jars := make([]string, 0, l.Len())
1475
1476 for i, jar := range l.jars {
Paul Duffin1e8c6072020-10-23 18:28:55 +01001477 apex := l.apexes[i]
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001478 if !list.containsApexJarPair(apex, jar) {
1479 apexes = append(apexes, apex)
1480 jars = append(jars, jar)
1481 }
1482 }
1483
Paul Duffin7d584e92020-10-23 18:26:03 +01001484 return ConfiguredJarList{apexes, jars}
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001485}
1486
Jingwen Chenc711fec2020-11-22 23:52:50 -05001487// CopyOfJars returns a copy of the list of strings containing jar module name
1488// components.
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001489func (l *ConfiguredJarList) CopyOfJars() []string {
1490 return CopyOf(l.jars)
1491}
1492
Jingwen Chenc711fec2020-11-22 23:52:50 -05001493// CopyOfApexJarPairs returns a copy of the list of strings with colon-separated
1494// (apex, jar) pairs.
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001495func (l *ConfiguredJarList) CopyOfApexJarPairs() []string {
1496 pairs := make([]string, 0, l.Len())
1497
1498 for i, jar := range l.jars {
Paul Duffin1e8c6072020-10-23 18:28:55 +01001499 apex := l.apexes[i]
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001500 pairs = append(pairs, apex+":"+jar)
1501 }
1502
1503 return pairs
1504}
1505
Jingwen Chenc711fec2020-11-22 23:52:50 -05001506// BuildPaths returns a list of build paths based on the given directory prefix.
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001507func (l *ConfiguredJarList) BuildPaths(ctx PathContext, dir OutputPath) WritablePaths {
1508 paths := make(WritablePaths, l.Len())
1509 for i, jar := range l.jars {
1510 paths[i] = dir.Join(ctx, ModuleStem(jar)+".jar")
1511 }
1512 return paths
1513}
1514
Jingwen Chenc711fec2020-11-22 23:52:50 -05001515// UnmarshalJSON converts JSON configuration from raw bytes into a
1516// ConfiguredJarList structure.
Paul Duffin69d1fb12020-10-23 21:14:20 +01001517func (l *ConfiguredJarList) UnmarshalJSON(b []byte) error {
1518 // Try and unmarshal into a []string each item of which contains a pair
1519 // <apex>:<jar>.
1520 var list []string
1521 err := json.Unmarshal(b, &list)
1522 if err != nil {
1523 // Did not work so return
1524 return err
1525 }
1526
1527 apexes, jars, err := splitListOfPairsIntoPairOfLists(list)
1528 if err != nil {
1529 return err
1530 }
1531 l.apexes = apexes
1532 l.jars = jars
1533 return nil
1534}
1535
Jingwen Chenc711fec2020-11-22 23:52:50 -05001536// ModuleStem hardcodes the stem of framework-minus-apex to return "framework".
1537//
1538// TODO(b/139391334): hard coded until we find a good way to query the stem of a
1539// module before any other mutators are run.
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001540func ModuleStem(module string) string {
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001541 if module == "framework-minus-apex" {
1542 return "framework"
1543 }
1544 return module
1545}
1546
Jingwen Chenc711fec2020-11-22 23:52:50 -05001547// DevicePaths computes the on-device paths for the list of (apex, jar) pairs,
1548// based on the operating system.
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001549func (l *ConfiguredJarList) DevicePaths(cfg Config, ostype OsType) []string {
1550 paths := make([]string, l.Len())
1551 for i, jar := range l.jars {
1552 apex := l.apexes[i]
1553 name := ModuleStem(jar) + ".jar"
1554
1555 var subdir string
1556 if apex == "platform" {
1557 subdir = "system/framework"
1558 } else if apex == "system_ext" {
1559 subdir = "system_ext/framework"
1560 } else {
1561 subdir = filepath.Join("apex", apex, "javalib")
1562 }
1563
1564 if ostype.Class == Host {
1565 paths[i] = filepath.Join(cfg.Getenv("OUT_DIR"), "host", cfg.PrebuiltOS(), subdir, name)
1566 } else {
1567 paths[i] = filepath.Join("/", subdir, name)
1568 }
1569 }
1570 return paths
1571}
1572
Paul Duffin7d584e92020-10-23 18:26:03 +01001573func (l *ConfiguredJarList) String() string {
1574 var pairs []string
1575 for i := 0; i < l.Len(); i++ {
1576 pairs = append(pairs, l.apexes[i]+":"+l.jars[i])
1577 }
1578 return strings.Join(pairs, ",")
1579}
1580
Paul Duffin01416602020-10-23 21:04:03 +01001581func splitListOfPairsIntoPairOfLists(list []string) ([]string, []string, error) {
1582 // Now we need to populate this list by splitting each item in the slice of
1583 // pairs and appending them to the appropriate list of apexes or jars.
1584 apexes := make([]string, len(list))
1585 jars := make([]string, len(list))
1586
1587 for i, apexjar := range list {
1588 apex, jar, err := splitConfiguredJarPair(apexjar)
1589 if err != nil {
1590 return nil, nil, err
1591 }
1592 apexes[i] = apex
1593 jars[i] = jar
1594 }
1595
1596 return apexes, jars, nil
1597}
1598
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001599// Expected format for apexJarValue = <apex name>:<jar name>
Paul Duffin01416602020-10-23 21:04:03 +01001600func splitConfiguredJarPair(str string) (string, string, error) {
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001601 pair := strings.SplitN(str, ":", 2)
1602 if len(pair) == 2 {
Paul Duffin01416602020-10-23 21:04:03 +01001603 return pair[0], pair[1], nil
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001604 } else {
Paul Duffin01416602020-10-23 21:04:03 +01001605 return "error-apex", "error-jar", fmt.Errorf("malformed (apex, jar) pair: '%s', expected format: <apex>:<jar>", str)
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001606 }
1607}
1608
Jingwen Chenc711fec2020-11-22 23:52:50 -05001609// CreateTestConfiguredJarList is a function to create ConfiguredJarList for
1610// tests.
Paul Duffine10dfa42020-10-23 21:23:44 +01001611func CreateTestConfiguredJarList(list []string) ConfiguredJarList {
Paul Duffin01416602020-10-23 21:04:03 +01001612 apexes, jars, err := splitListOfPairsIntoPairOfLists(list)
1613 if err != nil {
Paul Duffine10dfa42020-10-23 21:23:44 +01001614 panic(err)
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001615 }
1616
Paul Duffin01416602020-10-23 21:04:03 +01001617 return ConfiguredJarList{apexes, jars}
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001618}
1619
Jingwen Chenc711fec2020-11-22 23:52:50 -05001620// EmptyConfiguredJarList returns an empty jar list.
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001621func EmptyConfiguredJarList() ConfiguredJarList {
1622 return ConfiguredJarList{}
1623}
1624
1625var earlyBootJarsKey = NewOnceKey("earlyBootJars")
1626
1627func (c *config) BootJars() []string {
1628 return c.Once(earlyBootJarsKey, func() interface{} {
Paul Duffin69d1fb12020-10-23 21:14:20 +01001629 list := c.productVariables.BootJars.CopyOfJars()
Jingwen Chenc711fec2020-11-22 23:52:50 -05001630 return append(list, c.productVariables.UpdatableBootJars.CopyOfJars()...)
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001631 }).([]string)
1632}
Paul Duffin9a89a2a2020-10-28 19:20:06 +00001633
1634func (c *config) NonUpdatableBootJars() ConfiguredJarList {
1635 return c.productVariables.BootJars
1636}
1637
1638func (c *config) UpdatableBootJars() ConfiguredJarList {
1639 return c.productVariables.UpdatableBootJars
1640}