blob: e5c88247d31d38e8a1b78d6ef2da608ee3c2e2ca [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
17import (
Colin Cross3f40fa42015-01-30 17:27:36 -080018 "encoding/json"
19 "fmt"
Colin Crossd8f20142016-11-03 09:43:26 -070020 "io/ioutil"
Colin Cross3f40fa42015-01-30 17:27:36 -080021 "os"
Colin Cross35cec122015-04-02 14:37:16 -070022 "path/filepath"
Colin Cross3f40fa42015-01-30 17:27:36 -080023 "runtime"
Dan Willemsen34cc69e2015-09-23 15:26:20 -070024 "strings"
Colin Crossc1e86a32015-04-15 12:33:28 -070025 "sync"
Colin Cross6ff51382015-12-17 16:39:19 -080026
Colin Cross98be1bb2019-12-13 20:41:13 -080027 "github.com/google/blueprint"
Colin Crosse87040b2017-12-11 15:52:26 -080028 "github.com/google/blueprint/bootstrap"
Colin Cross98be1bb2019-12-13 20:41:13 -080029 "github.com/google/blueprint/pathtools"
Colin Cross6ff51382015-12-17 16:39:19 -080030 "github.com/google/blueprint/proptools"
Colin Cross9d34f352019-11-22 16:03:51 -080031
32 "android/soong/android/soongconfig"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross6ff51382015-12-17 16:39:19 -080035var Bool = proptools.Bool
Jack He8cc71432016-12-08 15:45:07 -080036var String = proptools.String
Jeongik Cha219141c2020-08-06 23:00:37 +090037var StringDefault = proptools.StringDefault
Jiyong Park6a927c42020-01-21 02:03:43 +090038
Dan Albert0b176c82020-07-23 16:43:25 -070039const FutureApiLevelInt = 10000
40
41var FutureApiLevel = ApiLevel{
42 value: "current",
43 number: FutureApiLevelInt,
44 isPreview: true,
45}
Colin Cross6ff51382015-12-17 16:39:19 -080046
Colin Cross3f40fa42015-01-30 17:27:36 -080047// The configuration file name
Dan Willemsen87b17d12015-07-14 00:39:06 -070048const configFileName = "soong.config"
49const productVariablesFileName = "soong.variables"
Colin Cross3f40fa42015-01-30 17:27:36 -080050
51// A FileConfigurableOptions contains options which can be configured by the
52// config file. These will be included in the config struct.
53type FileConfigurableOptions struct {
Jiyong Park22101982020-09-17 19:09:58 +090054 Mega_device *bool `json:",omitempty"`
55 Host_bionic *bool `json:",omitempty"`
56 Host_bionic_arm64 *bool `json:",omitempty"`
Colin Cross3f40fa42015-01-30 17:27:36 -080057}
58
Colin Cross27385972015-09-18 10:57:10 -070059func (f *FileConfigurableOptions) SetDefaultConfig() {
60 *f = FileConfigurableOptions{}
Colin Cross3f40fa42015-01-30 17:27:36 -080061}
62
Colin Cross9272ade2016-08-17 15:24:12 -070063// A Config object represents the entire build configuration for Android.
Colin Crossc3c0a492015-04-10 15:43:55 -070064type Config struct {
65 *config
66}
67
Jeff Gastonefc1b412017-03-29 17:29:06 -070068func (c Config) BuildDir() string {
69 return c.buildDir
70}
71
Colin Cross9272ade2016-08-17 15:24:12 -070072// A DeviceConfig object represents the configuration for a particular device being built. For
73// now there will only be one of these, but in the future there may be multiple devices being
74// built
75type DeviceConfig struct {
76 *deviceConfig
77}
78
Colin Cross9d34f352019-11-22 16:03:51 -080079type VendorConfig soongconfig.SoongConfig
Dan Willemsen0fe78662018-03-26 12:41:18 -070080
Colin Cross1332b002015-04-07 17:11:30 -070081type config struct {
Colin Cross3f40fa42015-01-30 17:27:36 -080082 FileConfigurableOptions
Dan Willemsen45133ac2018-03-09 21:22:06 -080083 productVariables productVariables
Colin Cross3f40fa42015-01-30 17:27:36 -080084
Dan Willemsen674dc7f2018-03-12 18:06:05 -070085 // Only available on configs created by TestConfig
86 TestProductVariables *productVariables
87
Chris Parsonsf3c96ef2020-09-29 02:23:17 -040088 BazelContext BazelContext
89
Colin Crosse87040b2017-12-11 15:52:26 -080090 PrimaryBuilder string
Dan Willemsen87b17d12015-07-14 00:39:06 -070091 ConfigFileName string
92 ProductVariablesFileName string
93
Jaewoong Jung642916f2020-10-09 17:25:15 -070094 Targets map[OsType][]Target
95 BuildOSTarget Target // the Target for tools run on the build machine
96 BuildOSCommonTarget Target // the Target for common (java) tools run on the build machine
97 AndroidCommonTarget Target // the Target for common modules for the Android device
98 AndroidFirstDeviceTarget Target // the first Target for modules for the Android device
Dan Willemsen218f6562015-07-08 18:13:11 -070099
Colin Cross3b19f5d2019-09-17 14:45:31 -0700100 // multilibConflicts for an ArchType is true if there is earlier configured device architecture with the same
101 // multilib value.
102 multilibConflicts map[ArchType]bool
103
Colin Cross9272ade2016-08-17 15:24:12 -0700104 deviceConfig *deviceConfig
105
Chris Parsons8f232a22020-06-23 17:37:05 -0400106 srcDir string // the path of the root source directory
107 buildDir string // the path of the build output directory
108 moduleListFile string // the path to the file which lists blueprint files to parse.
Colin Crossc1e86a32015-04-15 12:33:28 -0700109
Colin Cross6ccbc912017-10-10 23:07:38 -0700110 env map[string]string
Dan Willemsene7680ba2015-09-11 17:06:19 -0700111 envLock sync.Mutex
112 envDeps map[string]string
113 envFrozen bool
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800114
Jingwen Chencda22c92020-11-23 00:22:30 -0500115 // Changes behavior based on whether Kati runs after soong_build, or if soong_build
116 // runs standalone.
117 katiEnabled bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700118
Colin Cross32616ed2017-09-05 21:56:44 -0700119 captureBuild bool // true for tests, saves build parameters for each module
120 ignoreEnvironment bool // true for tests, returns empty from all Getenv calls
Colin Crosscec81712017-07-13 14:43:27 -0700121
Colin Crosse87040b2017-12-11 15:52:26 -0800122 stopBefore bootstrap.StopBefore
123
Colin Cross98be1bb2019-12-13 20:41:13 -0800124 fs pathtools.FileSystem
125 mockBpList string
126
Colin Cross5e6a7972020-06-07 16:56:32 -0700127 // If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error
128 // in tests when a path doesn't exist.
129 testAllowNonExistentPaths bool
130
Colin Cross12129292020-10-29 18:23:58 -0700131 ninjaFileDepsSet sync.Map
132
Colin Cross9272ade2016-08-17 15:24:12 -0700133 OncePer
134}
135
136type deviceConfig struct {
Dan Willemsen00269f22017-07-06 16:59:48 -0700137 config *config
Colin Cross9272ade2016-08-17 15:24:12 -0700138 OncePer
Colin Cross3f40fa42015-01-30 17:27:36 -0800139}
140
Colin Cross485e5722015-08-27 13:28:01 -0700141type jsonConfigurable interface {
Colin Cross27385972015-09-18 10:57:10 -0700142 SetDefaultConfig()
Colin Cross485e5722015-08-27 13:28:01 -0700143}
Colin Cross3f40fa42015-01-30 17:27:36 -0800144
Colin Cross485e5722015-08-27 13:28:01 -0700145func loadConfig(config *config) error {
Colin Cross988414c2020-01-11 01:11:46 +0000146 err := loadFromConfigFile(&config.FileConfigurableOptions, absolutePath(config.ConfigFileName))
Colin Cross485e5722015-08-27 13:28:01 -0700147 if err != nil {
148 return err
149 }
150
Colin Cross988414c2020-01-11 01:11:46 +0000151 return loadFromConfigFile(&config.productVariables, absolutePath(config.ProductVariablesFileName))
Colin Cross485e5722015-08-27 13:28:01 -0700152}
153
154// loads configuration options from a JSON file in the cwd.
155func loadFromConfigFile(configurable jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800156 // Try to open the file
Colin Cross485e5722015-08-27 13:28:01 -0700157 configFileReader, err := os.Open(filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800158 defer configFileReader.Close()
159 if os.IsNotExist(err) {
160 // Need to create a file, so that blueprint & ninja don't get in
161 // a dependency tracking loop.
162 // Make a file-configurable-options with defaults, write it out using
163 // a json writer.
Colin Cross27385972015-09-18 10:57:10 -0700164 configurable.SetDefaultConfig()
165 err = saveToConfigFile(configurable, filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800166 if err != nil {
167 return err
168 }
Colin Cross15cd21a2018-02-27 11:26:02 -0800169 } else if err != nil {
170 return fmt.Errorf("config file: could not open %s: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800171 } else {
172 // Make a decoder for it
173 jsonDecoder := json.NewDecoder(configFileReader)
Colin Cross485e5722015-08-27 13:28:01 -0700174 err = jsonDecoder.Decode(configurable)
Colin Cross3f40fa42015-01-30 17:27:36 -0800175 if err != nil {
Colin Cross15cd21a2018-02-27 11:26:02 -0800176 return fmt.Errorf("config file: %s did not parse correctly: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800177 }
178 }
179
Colin Cross3f40fa42015-01-30 17:27:36 -0800180 // No error
181 return nil
182}
183
Colin Crossd8f20142016-11-03 09:43:26 -0700184// atomically writes the config file in case two copies of soong_build are running simultaneously
185// (for example, docs generation and ninja manifest generation)
Colin Cross485e5722015-08-27 13:28:01 -0700186func saveToConfigFile(config jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800187 data, err := json.MarshalIndent(&config, "", " ")
188 if err != nil {
189 return fmt.Errorf("cannot marshal config data: %s", err.Error())
190 }
191
Colin Crossd8f20142016-11-03 09:43:26 -0700192 f, err := ioutil.TempFile(filepath.Dir(filename), "config")
Colin Cross3f40fa42015-01-30 17:27:36 -0800193 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700194 return fmt.Errorf("cannot create empty config file %s: %s\n", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800195 }
Colin Crossd8f20142016-11-03 09:43:26 -0700196 defer os.Remove(f.Name())
197 defer f.Close()
Colin Cross3f40fa42015-01-30 17:27:36 -0800198
Colin Crossd8f20142016-11-03 09:43:26 -0700199 _, err = f.Write(data)
Colin Cross3f40fa42015-01-30 17:27:36 -0800200 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700201 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
202 }
203
Colin Crossd8f20142016-11-03 09:43:26 -0700204 _, err = f.WriteString("\n")
Colin Cross485e5722015-08-27 13:28:01 -0700205 if err != nil {
206 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800207 }
208
Colin Crossd8f20142016-11-03 09:43:26 -0700209 f.Close()
210 os.Rename(f.Name(), filename)
211
Colin Cross3f40fa42015-01-30 17:27:36 -0800212 return nil
213}
214
Colin Cross988414c2020-01-11 01:11:46 +0000215// NullConfig returns a mostly empty Config for use by standalone tools like dexpreopt_gen that
216// use the android package.
217func NullConfig(buildDir string) Config {
218 return Config{
219 config: &config{
220 buildDir: buildDir,
221 fs: pathtools.OsFs,
222 },
223 }
224}
225
Colin Crossce75d2c2016-10-06 16:12:58 -0700226// TestConfig returns a Config object suitable for using for tests
Colin Cross98be1bb2019-12-13 20:41:13 -0800227func TestConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
Colin Cross9c6241f2019-04-22 15:51:26 -0700228 envCopy := make(map[string]string)
229 for k, v := range env {
230 envCopy[k] = v
231 }
232
233 // Copy the real PATH value to the test environment, it's needed by HostSystemTool() used in x86_darwin_host.go
234 envCopy["PATH"] = originalEnv["PATH"]
235
Dan Willemsen00269f22017-07-06 16:59:48 -0700236 config := &config{
Dan Willemsen45133ac2018-03-09 21:22:06 -0800237 productVariables: productVariables{
Dan Albert4f378d72020-07-23 17:32:15 -0700238 DeviceName: stringPtr("test_device"),
239 Platform_sdk_version: intPtr(30),
240 Platform_sdk_codename: stringPtr("S"),
241 Platform_version_active_codenames: []string{"S"},
242 DeviceSystemSdkVersions: []string{"14", "15"},
243 Platform_systemsdk_versions: []string{"29", "30"},
244 AAPTConfig: []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"},
245 AAPTPreferredConfig: stringPtr("xhdpi"),
246 AAPTCharacteristics: stringPtr("nosdcard"),
247 AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"},
248 UncompressPrivAppDex: boolPtr(true),
Dan Willemsen00269f22017-07-06 16:59:48 -0700249 },
250
Colin Cross6ccbc912017-10-10 23:07:38 -0700251 buildDir: buildDir,
252 captureBuild: true,
Colin Cross9c6241f2019-04-22 15:51:26 -0700253 env: envCopy,
Colin Cross5e6a7972020-06-07 16:56:32 -0700254
255 // Set testAllowNonExistentPaths so that test contexts don't need to specify every path
256 // passed to PathForSource or PathForModuleSrc.
257 testAllowNonExistentPaths: true,
Chris Parsonsf3c96ef2020-09-29 02:23:17 -0400258
259 BazelContext: noopBazelContext{},
Dan Willemsen00269f22017-07-06 16:59:48 -0700260 }
261 config.deviceConfig = &deviceConfig{
262 config: config,
263 }
Dan Willemsen45133ac2018-03-09 21:22:06 -0800264 config.TestProductVariables = &config.productVariables
Dan Willemsen00269f22017-07-06 16:59:48 -0700265
Colin Cross98be1bb2019-12-13 20:41:13 -0800266 config.mockFileSystem(bp, fs)
267
Colin Cross1369cdb2017-09-29 17:58:17 -0700268 if err := config.fromEnv(); err != nil {
269 panic(err)
270 }
271
Dan Willemsen00269f22017-07-06 16:59:48 -0700272 return Config{config}
Colin Crossce75d2c2016-10-06 16:12:58 -0700273}
274
Colin Cross98be1bb2019-12-13 20:41:13 -0800275func TestArchConfigNativeBridge(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
276 testConfig := TestArchConfig(buildDir, env, bp, fs)
dimitry1f33e402019-03-26 12:39:31 +0100277 config := testConfig.config
278
Colin Cross0d99f7c2019-05-14 16:01:24 -0700279 config.Targets[Android] = []Target{
Jiyong Park1613e552020-09-14 19:43:17 +0900280 {Android, Arch{ArchType: X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false},
281 {Android, Arch{ArchType: X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", "", false},
282 {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeEnabled, "x86_64", "arm64", false},
283 {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeEnabled, "x86", "arm", false},
dimitry1f33e402019-03-26 12:39:31 +0100284 }
285
286 return testConfig
287}
288
Colin Cross98be1bb2019-12-13 20:41:13 -0800289func TestArchConfigFuchsia(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
290 testConfig := TestConfig(buildDir, env, bp, fs)
Doug Hornc32c6b02019-01-17 14:44:05 -0800291 config := testConfig.config
292
293 config.Targets = map[OsType][]Target{
294 Fuchsia: []Target{
Jiyong Park1613e552020-09-14 19:43:17 +0900295 {Fuchsia, Arch{ArchType: Arm64, ArchVariant: "", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false},
Doug Hornc32c6b02019-01-17 14:44:05 -0800296 },
297 BuildOs: []Target{
Jiyong Park1613e552020-09-14 19:43:17 +0900298 {BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", false},
Doug Hornc32c6b02019-01-17 14:44:05 -0800299 },
300 }
301
302 return testConfig
303}
304
Colin Crossae4c6182017-09-15 17:33:55 -0700305// TestConfig returns a Config object suitable for using for tests that need to run the arch mutator
Colin Cross98be1bb2019-12-13 20:41:13 -0800306func TestArchConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
307 testConfig := TestConfig(buildDir, env, bp, fs)
Colin Crossae4c6182017-09-15 17:33:55 -0700308 config := testConfig.config
309
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700310 config.Targets = map[OsType][]Target{
311 Android: []Target{
Jiyong Park1613e552020-09-14 19:43:17 +0900312 {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false},
313 {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", "", false},
Colin Crossae4c6182017-09-15 17:33:55 -0700314 },
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700315 BuildOs: []Target{
Jiyong Park1613e552020-09-14 19:43:17 +0900316 {BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", false},
317 {BuildOs, Arch{ArchType: X86}, NativeBridgeDisabled, "", "", false},
Colin Crossae4c6182017-09-15 17:33:55 -0700318 },
319 }
320
Colin Cross0d99f7c2019-05-14 16:01:24 -0700321 if runtime.GOOS == "darwin" {
322 config.Targets[BuildOs] = config.Targets[BuildOs][:1]
323 }
324
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700325 config.BuildOSTarget = config.Targets[BuildOs][0]
326 config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0]
327 config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
Jaewoong Jung642916f2020-10-09 17:25:15 -0700328 config.AndroidFirstDeviceTarget = firstTarget(config.Targets[Android], "lib64", "lib32")[0]
Inseob Kim1f086e22019-05-09 13:29:15 +0900329 config.TestProductVariables.DeviceArch = proptools.StringPtr("arm64")
330 config.TestProductVariables.DeviceArchVariant = proptools.StringPtr("armv8-a")
331 config.TestProductVariables.DeviceSecondaryArch = proptools.StringPtr("arm")
332 config.TestProductVariables.DeviceSecondaryArchVariant = proptools.StringPtr("armv7-a-neon")
Colin Cross2a076922018-10-04 23:28:25 -0700333
Colin Crossae4c6182017-09-15 17:33:55 -0700334 return testConfig
335}
336
Chris Parsonsf3c96ef2020-09-29 02:23:17 -0400337// Returns a config object which is "reset" for another bootstrap run.
338// Only per-run data is reset. Data which needs to persist across multiple
339// runs in the same program execution is carried over (such as Bazel context
340// or environment deps).
341func ConfigForAdditionalRun(c Config) (Config, error) {
342 newConfig, err := NewConfig(c.srcDir, c.buildDir, c.moduleListFile)
343 if err != nil {
344 return Config{}, err
345 }
346 newConfig.BazelContext = c.BazelContext
347 newConfig.envDeps = c.envDeps
348 return newConfig, nil
349}
350
Colin Cross3f40fa42015-01-30 17:27:36 -0800351// New creates a new Config object. The srcDir argument specifies the path to
352// the root source directory. It also loads the config file, if found.
Chris Parsons8f232a22020-06-23 17:37:05 -0400353func NewConfig(srcDir, buildDir string, moduleListFile string) (Config, error) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800354 // Make a config with default options
Colin Cross9272ade2016-08-17 15:24:12 -0700355 config := &config{
356 ConfigFileName: filepath.Join(buildDir, configFileName),
357 ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName),
Dan Willemsen87b17d12015-07-14 00:39:06 -0700358
Colin Cross6ccbc912017-10-10 23:07:38 -0700359 env: originalEnv,
360
Colin Cross3b19f5d2019-09-17 14:45:31 -0700361 srcDir: srcDir,
362 buildDir: buildDir,
363 multilibConflicts: make(map[ArchType]bool),
Colin Cross98be1bb2019-12-13 20:41:13 -0800364
Chris Parsons8f232a22020-06-23 17:37:05 -0400365 moduleListFile: moduleListFile,
366 fs: pathtools.NewOsFs(absSrcDir),
Colin Cross68f55102015-03-25 14:43:57 -0700367 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800368
Dan Willemsen00269f22017-07-06 16:59:48 -0700369 config.deviceConfig = &deviceConfig{
Colin Cross9272ade2016-08-17 15:24:12 -0700370 config: config,
371 }
372
Liz Kammer7941b302020-07-28 13:27:34 -0700373 // Soundness check of the build and source directories. This won't catch strange
374 // configurations with symlinks, but at least checks the obvious case.
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700375 absBuildDir, err := filepath.Abs(buildDir)
376 if err != nil {
377 return Config{}, err
378 }
379
380 absSrcDir, err := filepath.Abs(srcDir)
381 if err != nil {
382 return Config{}, err
383 }
384
385 if strings.HasPrefix(absSrcDir, absBuildDir) {
386 return Config{}, fmt.Errorf("Build dir must not contain source directory")
387 }
388
Colin Cross3f40fa42015-01-30 17:27:36 -0800389 // Load any configurable options from the configuration file
Colin Cross9272ade2016-08-17 15:24:12 -0700390 err = loadConfig(config)
Colin Cross3f40fa42015-01-30 17:27:36 -0800391 if err != nil {
Colin Crossc3c0a492015-04-10 15:43:55 -0700392 return Config{}, err
Colin Cross3f40fa42015-01-30 17:27:36 -0800393 }
394
Jingwen Chencda22c92020-11-23 00:22:30 -0500395 KatiEnabledMarkerFile := filepath.Join(buildDir, ".soong.kati_enabled")
396 if _, err := os.Stat(absolutePath(KatiEnabledMarkerFile)); err == nil {
397 config.katiEnabled = true
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800398 }
399
Colin Crossa1ad8d12016-06-01 17:09:44 -0700400 targets, err := decodeTargetProductVariables(config)
Dan Willemsen218f6562015-07-08 18:13:11 -0700401 if err != nil {
402 return Config{}, err
403 }
404
Paul Duffin1356d8c2020-02-25 19:26:33 +0000405 // Make the CommonOS OsType available for all products.
406 targets[CommonOS] = []Target{commonTargetMap[CommonOS.Name]}
407
Dan Albert4098deb2016-10-19 14:04:41 -0700408 var archConfig []archConfig
Dan Willemsen322acaf2016-01-12 23:07:05 -0800409 if Bool(config.Mega_device) {
Dan Albert4098deb2016-10-19 14:04:41 -0700410 archConfig = getMegaDeviceConfig()
Colin Cross395f2cf2018-10-24 16:10:32 -0700411 } else if config.NdkAbis() {
Dan Albert4098deb2016-10-19 14:04:41 -0700412 archConfig = getNdkAbisConfig()
Martin Stjernholmc1ecc432019-11-15 15:00:31 +0000413 } else if config.AmlAbis() {
414 archConfig = getAmlAbisConfig()
Dan Albert4098deb2016-10-19 14:04:41 -0700415 }
416
417 if archConfig != nil {
Dan Willemsen01a3c252019-01-11 19:02:16 -0800418 androidTargets, err := decodeArchSettings(Android, archConfig)
Dan Willemsen322acaf2016-01-12 23:07:05 -0800419 if err != nil {
420 return Config{}, err
421 }
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700422 targets[Android] = androidTargets
Dan Willemsen322acaf2016-01-12 23:07:05 -0800423 }
424
Colin Cross3b19f5d2019-09-17 14:45:31 -0700425 multilib := make(map[string]bool)
426 for _, target := range targets[Android] {
427 if seen := multilib[target.Arch.ArchType.Multilib]; seen {
428 config.multilibConflicts[target.Arch.ArchType] = true
429 }
430 multilib[target.Arch.ArchType.Multilib] = true
431 }
432
Colin Crossa1ad8d12016-06-01 17:09:44 -0700433 config.Targets = targets
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700434 config.BuildOSTarget = config.Targets[BuildOs][0]
435 config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0]
436 if len(config.Targets[Android]) > 0 {
437 config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
Jaewoong Jung642916f2020-10-09 17:25:15 -0700438 config.AndroidFirstDeviceTarget = firstTarget(config.Targets[Android], "lib64", "lib32")[0]
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700439 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700440
Colin Cross1369cdb2017-09-29 17:58:17 -0700441 if err := config.fromEnv(); err != nil {
442 return Config{}, err
443 }
444
Colin Cross1a6acd42020-06-16 17:51:46 -0700445 if Bool(config.productVariables.GcovCoverage) && Bool(config.productVariables.ClangCoverage) {
446 return Config{}, fmt.Errorf("GcovCoverage and ClangCoverage cannot both be set")
447 }
448
449 config.productVariables.Native_coverage = proptools.BoolPtr(
450 Bool(config.productVariables.GcovCoverage) ||
451 Bool(config.productVariables.ClangCoverage))
452
Chris Parsonsf3c96ef2020-09-29 02:23:17 -0400453 config.BazelContext, err = NewBazelContext(config)
454 if err != nil {
455 return Config{}, err
456 }
Colin Cross9272ade2016-08-17 15:24:12 -0700457 return Config{config}, nil
Colin Cross3f40fa42015-01-30 17:27:36 -0800458}
459
Colin Cross988414c2020-01-11 01:11:46 +0000460var TestConfigOsFs = map[string][]byte{}
461
Colin Cross98be1bb2019-12-13 20:41:13 -0800462// mockFileSystem replaces all reads with accesses to the provided map of
463// filenames to contents stored as a byte slice.
464func (c *config) mockFileSystem(bp string, fs map[string][]byte) {
465 mockFS := map[string][]byte{}
466
467 if _, exists := mockFS["Android.bp"]; !exists {
468 mockFS["Android.bp"] = []byte(bp)
469 }
470
471 for k, v := range fs {
472 mockFS[k] = v
473 }
474
475 // no module list file specified; find every file named Blueprints or Android.bp
476 pathsToParse := []string{}
477 for candidate := range mockFS {
478 base := filepath.Base(candidate)
479 if base == "Blueprints" || base == "Android.bp" {
480 pathsToParse = append(pathsToParse, candidate)
481 }
482 }
483 if len(pathsToParse) < 1 {
484 panic(fmt.Sprintf("No Blueprint or Android.bp files found in mock filesystem: %v\n", mockFS))
485 }
486 mockFS[blueprint.MockModuleListFile] = []byte(strings.Join(pathsToParse, "\n"))
487
488 c.fs = pathtools.MockFs(mockFS)
489 c.mockBpList = blueprint.MockModuleListFile
490}
491
Colin Cross1369cdb2017-09-29 17:58:17 -0700492func (c *config) fromEnv() error {
Pete Gillin0c2143e2019-05-02 15:32:11 +0100493 switch c.Getenv("EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9") {
Pete Gillin1b3370f2019-10-01 13:57:31 +0100494 case "", "true":
Pete Gillina1c9e9d2019-10-17 14:52:07 +0100495 // Do nothing
Colin Cross1369cdb2017-09-29 17:58:17 -0700496 default:
Pete Gillina1c9e9d2019-10-17 14:52:07 +0100497 return fmt.Errorf("The environment variable EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9 is no longer supported. Java language level 9 is now the global default.")
Colin Cross1369cdb2017-09-29 17:58:17 -0700498 }
499
500 return nil
501}
502
Colin Crosse87040b2017-12-11 15:52:26 -0800503func (c *config) StopBefore() bootstrap.StopBefore {
504 return c.stopBefore
Dan Willemsen218f6562015-07-08 18:13:11 -0700505}
506
Colin Crosse87040b2017-12-11 15:52:26 -0800507func (c *config) SetStopBefore(stopBefore bootstrap.StopBefore) {
508 c.stopBefore = stopBefore
509}
510
511var _ bootstrap.ConfigStopBefore = (*config)(nil)
512
Dan Willemsenc2aa4a92016-05-26 15:13:03 -0700513func (c *config) BlueprintToolLocation() string {
514 return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin")
515}
516
Colin Crosse87040b2017-12-11 15:52:26 -0800517var _ bootstrap.ConfigBlueprintToolLocation = (*config)(nil)
518
Dan Willemsen60e62f02018-11-16 21:05:32 -0800519func (c *config) HostToolPath(ctx PathContext, tool string) Path {
520 return PathForOutput(ctx, "host", c.PrebuiltOS(), "bin", tool)
521}
522
Martin Stjernholm7260d062019-12-09 21:47:14 +0000523func (c *config) HostJNIToolPath(ctx PathContext, path string) Path {
524 ext := ".so"
525 if runtime.GOOS == "darwin" {
526 ext = ".dylib"
527 }
528 return PathForOutput(ctx, "host", c.PrebuiltOS(), "lib64", path+ext)
529}
530
531func (c *config) HostJavaToolPath(ctx PathContext, path string) Path {
532 return PathForOutput(ctx, "host", c.PrebuiltOS(), "framework", path)
533}
534
Dan Willemsen66068722017-05-08 21:15:59 +0000535// HostSystemTool looks for non-hermetic tools from the system we're running on.
536// Generally shouldn't be used, but useful to find the XCode SDK, etc.
537func (c *config) HostSystemTool(name string) string {
538 for _, dir := range filepath.SplitList(c.Getenv("PATH")) {
539 path := filepath.Join(dir, name)
540 if s, err := os.Stat(path); err != nil {
541 continue
542 } else if m := s.Mode(); !s.IsDir() && m&0111 != 0 {
543 return path
544 }
545 }
546 return name
547}
548
Colin Cross3f40fa42015-01-30 17:27:36 -0800549// PrebuiltOS returns the name of the host OS used in prebuilts directories
Colin Cross1332b002015-04-07 17:11:30 -0700550func (c *config) PrebuiltOS() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800551 switch runtime.GOOS {
552 case "linux":
553 return "linux-x86"
554 case "darwin":
555 return "darwin-x86"
556 default:
557 panic("Unknown GOOS")
558 }
559}
560
561// GoRoot returns the path to the root directory of the Go toolchain.
Colin Cross1332b002015-04-07 17:11:30 -0700562func (c *config) GoRoot() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800563 return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS())
564}
565
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700566func (c *config) PrebuiltBuildTool(ctx PathContext, tool string) Path {
567 return PathForSource(ctx, "prebuilts/build-tools", c.PrebuiltOS(), "bin", tool)
568}
569
Colin Cross1332b002015-04-07 17:11:30 -0700570func (c *config) CpPreserveSymlinksFlags() string {
Colin Cross485e5722015-08-27 13:28:01 -0700571 switch runtime.GOOS {
Colin Cross3f40fa42015-01-30 17:27:36 -0800572 case "darwin":
573 return "-R"
574 case "linux":
575 return "-d"
576 default:
577 return ""
578 }
579}
Colin Cross68f55102015-03-25 14:43:57 -0700580
Colin Cross1332b002015-04-07 17:11:30 -0700581func (c *config) Getenv(key string) string {
Colin Cross68f55102015-03-25 14:43:57 -0700582 var val string
583 var exists bool
Colin Crossc1e86a32015-04-15 12:33:28 -0700584 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800585 defer c.envLock.Unlock()
586 if c.envDeps == nil {
587 c.envDeps = make(map[string]string)
588 }
Colin Cross68f55102015-03-25 14:43:57 -0700589 if val, exists = c.envDeps[key]; !exists {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700590 if c.envFrozen {
591 panic("Cannot access new environment variables after envdeps are frozen")
592 }
Colin Cross6ccbc912017-10-10 23:07:38 -0700593 val, _ = c.env[key]
Colin Cross68f55102015-03-25 14:43:57 -0700594 c.envDeps[key] = val
595 }
596 return val
597}
598
Colin Cross99d7c232016-11-23 16:52:04 -0800599func (c *config) GetenvWithDefault(key string, defaultValue string) string {
600 ret := c.Getenv(key)
601 if ret == "" {
602 return defaultValue
603 }
604 return ret
605}
606
607func (c *config) IsEnvTrue(key string) bool {
608 value := c.Getenv(key)
609 return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
610}
611
612func (c *config) IsEnvFalse(key string) bool {
613 value := c.Getenv(key)
614 return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
615}
616
Colin Cross1332b002015-04-07 17:11:30 -0700617func (c *config) EnvDeps() map[string]string {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700618 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800619 defer c.envLock.Unlock()
Dan Willemsene7680ba2015-09-11 17:06:19 -0700620 c.envFrozen = true
Colin Cross68f55102015-03-25 14:43:57 -0700621 return c.envDeps
622}
Colin Cross35cec122015-04-02 14:37:16 -0700623
Jingwen Chencda22c92020-11-23 00:22:30 -0500624func (c *config) KatiEnabled() bool {
625 return c.katiEnabled
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800626}
627
Nan Zhang581fd212018-01-10 16:06:12 -0800628func (c *config) BuildId() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800629 return String(c.productVariables.BuildId)
Nan Zhang581fd212018-01-10 16:06:12 -0800630}
631
Colin Cross2a2e0db2020-02-21 16:55:46 -0800632func (c *config) BuildNumberFile(ctx PathContext) Path {
633 return PathForOutput(ctx, String(c.productVariables.BuildNumberFile))
Nan Zhang581fd212018-01-10 16:06:12 -0800634}
635
Colin Cross35cec122015-04-02 14:37:16 -0700636// DeviceName returns the name of the current device target
637// TODO: take an AndroidModuleContext to select the device name for multi-device builds
Colin Cross1332b002015-04-07 17:11:30 -0700638func (c *config) DeviceName() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800639 return *c.productVariables.DeviceName
Colin Cross35cec122015-04-02 14:37:16 -0700640}
641
Anton Hansson53c88442019-03-18 15:53:16 +0000642func (c *config) DeviceResourceOverlays() []string {
643 return c.productVariables.DeviceResourceOverlays
644}
645
646func (c *config) ProductResourceOverlays() []string {
647 return c.productVariables.ProductResourceOverlays
Colin Cross30e076a2015-04-13 13:58:27 -0700648}
649
Colin Crossbfd347d2018-05-09 11:11:35 -0700650func (c *config) PlatformVersionName() string {
651 return String(c.productVariables.Platform_version_name)
652}
653
Dan Albert4f378d72020-07-23 17:32:15 -0700654func (c *config) PlatformSdkVersion() ApiLevel {
655 return uncheckedFinalApiLevel(*c.productVariables.Platform_sdk_version)
Colin Cross30e076a2015-04-13 13:58:27 -0700656}
657
Colin Crossd09b0b62018-04-18 11:06:47 -0700658func (c *config) PlatformSdkCodename() string {
659 return String(c.productVariables.Platform_sdk_codename)
660}
661
Colin Cross092c9da2019-04-02 22:56:43 -0700662func (c *config) PlatformSecurityPatch() string {
663 return String(c.productVariables.Platform_security_patch)
664}
665
666func (c *config) PlatformPreviewSdkVersion() string {
667 return String(c.productVariables.Platform_preview_sdk_version)
668}
669
670func (c *config) PlatformMinSupportedTargetSdkVersion() string {
671 return String(c.productVariables.Platform_min_supported_target_sdk_version)
672}
673
674func (c *config) PlatformBaseOS() string {
675 return String(c.productVariables.Platform_base_os)
676}
677
Dan Albert1a246272020-07-06 14:49:35 -0700678func (c *config) MinSupportedSdkVersion() ApiLevel {
679 return uncheckedFinalApiLevel(16)
680}
681
682func (c *config) FinalApiLevels() []ApiLevel {
683 var levels []ApiLevel
Dan Albert4f378d72020-07-23 17:32:15 -0700684 for i := 1; i <= c.PlatformSdkVersion().FinalOrFutureInt(); i++ {
Dan Albert1a246272020-07-06 14:49:35 -0700685 levels = append(levels, uncheckedFinalApiLevel(i))
686 }
687 return levels
688}
689
690func (c *config) PreviewApiLevels() []ApiLevel {
691 var levels []ApiLevel
692 for i, codename := range c.PlatformVersionActiveCodenames() {
693 levels = append(levels, ApiLevel{
694 value: codename,
695 number: i,
696 isPreview: true,
697 })
698 }
699 return levels
700}
701
702func (c *config) AllSupportedApiLevels() []ApiLevel {
703 var levels []ApiLevel
704 levels = append(levels, c.FinalApiLevels()...)
705 return append(levels, c.PreviewApiLevels()...)
Dan Albertf5415d72017-08-17 16:19:59 -0700706}
707
Dan Albert4f378d72020-07-23 17:32:15 -0700708func (c *config) DefaultAppTargetSdk(ctx EarlyModuleContext) ApiLevel {
Colin Crossd09b0b62018-04-18 11:06:47 -0700709 if Bool(c.productVariables.Platform_sdk_final) {
710 return c.PlatformSdkVersion()
711 } else {
Dan Albert4f378d72020-07-23 17:32:15 -0700712 codename := c.PlatformSdkCodename()
713 if codename == "" {
714 return NoneApiLevel
715 }
716 if codename == "REL" {
717 panic("Platform_sdk_codename should not be REL when Platform_sdk_final is true")
718 }
719 return ApiLevelOrPanic(ctx, codename)
Colin Crossd09b0b62018-04-18 11:06:47 -0700720 }
721}
722
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800723func (c *config) AppsDefaultVersionName() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800724 return String(c.productVariables.AppsDefaultVersionName)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800725}
726
Dan Albert31384de2017-07-28 12:39:46 -0700727// Codenames that are active in the current lunch target.
728func (c *config) PlatformVersionActiveCodenames() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800729 return c.productVariables.Platform_version_active_codenames
Dan Albert31384de2017-07-28 12:39:46 -0700730}
731
Colin Crossface4e42017-10-30 17:32:15 -0700732func (c *config) ProductAAPTConfig() []string {
Colin Crossa74ca042019-01-31 14:31:51 -0800733 return c.productVariables.AAPTConfig
Colin Cross30e076a2015-04-13 13:58:27 -0700734}
735
Colin Crossface4e42017-10-30 17:32:15 -0700736func (c *config) ProductAAPTPreferredConfig() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800737 return String(c.productVariables.AAPTPreferredConfig)
Colin Cross30e076a2015-04-13 13:58:27 -0700738}
739
Colin Crossface4e42017-10-30 17:32:15 -0700740func (c *config) ProductAAPTCharacteristics() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800741 return String(c.productVariables.AAPTCharacteristics)
Colin Crossface4e42017-10-30 17:32:15 -0700742}
743
744func (c *config) ProductAAPTPrebuiltDPI() []string {
Colin Crossa74ca042019-01-31 14:31:51 -0800745 return c.productVariables.AAPTPrebuiltDPI
Colin Cross30e076a2015-04-13 13:58:27 -0700746}
747
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700748func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800749 defaultCert := String(c.productVariables.DefaultAppCertificate)
Colin Cross61ae0b72017-12-01 17:16:02 -0800750 if defaultCert != "" {
751 return PathForSource(ctx, filepath.Dir(defaultCert))
752 } else {
Dan Willemsen412160e2019-04-09 21:36:26 -0700753 return PathForSource(ctx, "build/make/target/product/security")
Colin Cross61ae0b72017-12-01 17:16:02 -0800754 }
Colin Cross30e076a2015-04-13 13:58:27 -0700755}
756
Colin Crosse1731a52017-12-14 11:22:55 -0800757func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800758 defaultCert := String(c.productVariables.DefaultAppCertificate)
Colin Cross61ae0b72017-12-01 17:16:02 -0800759 if defaultCert != "" {
Colin Crosse1731a52017-12-14 11:22:55 -0800760 return PathForSource(ctx, defaultCert+".x509.pem"), PathForSource(ctx, defaultCert+".pk8")
Colin Cross61ae0b72017-12-01 17:16:02 -0800761 } else {
Colin Crosse1731a52017-12-14 11:22:55 -0800762 defaultDir := c.DefaultAppCertificateDir(ctx)
763 return defaultDir.Join(ctx, "testkey.x509.pem"), defaultDir.Join(ctx, "testkey.pk8")
Colin Cross61ae0b72017-12-01 17:16:02 -0800764 }
Colin Cross30e076a2015-04-13 13:58:27 -0700765}
Colin Cross6ff51382015-12-17 16:39:19 -0800766
Jiyong Park9335a262018-12-24 11:31:58 +0900767func (c *config) ApexKeyDir(ctx ModuleContext) SourcePath {
768 // TODO(b/121224311): define another variable such as TARGET_APEX_KEY_OVERRIDE
769 defaultCert := String(c.productVariables.DefaultAppCertificate)
Dan Willemsen412160e2019-04-09 21:36:26 -0700770 if defaultCert == "" || filepath.Dir(defaultCert) == "build/make/target/product/security" {
Jiyong Park9335a262018-12-24 11:31:58 +0900771 // When defaultCert is unset or is set to the testkeys path, use the APEX keys
772 // that is under the module dir
Colin Cross07e51612019-03-05 12:46:40 -0800773 return pathForModuleSrc(ctx)
Jiyong Park9335a262018-12-24 11:31:58 +0900774 } else {
775 // If not, APEX keys are under the specified directory
776 return PathForSource(ctx, filepath.Dir(defaultCert))
777 }
778}
779
Colin Cross6ff51382015-12-17 16:39:19 -0800780func (c *config) AllowMissingDependencies() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800781 return Bool(c.productVariables.Allow_missing_dependencies)
Colin Cross6ff51382015-12-17 16:39:19 -0800782}
Dan Willemsen322acaf2016-01-12 23:07:05 -0800783
Jeongik Cha816a23a2020-07-08 01:09:23 +0900784// Returns true if a full platform source tree cannot be assumed.
Colin Crossfc3674a2017-09-18 17:41:52 -0700785func (c *config) UnbundledBuild() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800786 return Bool(c.productVariables.Unbundled_build)
Colin Crossfc3674a2017-09-18 17:41:52 -0700787}
788
Martin Stjernholmfd9eb4b2020-06-17 01:13:15 +0100789// Returns true if building apps that aren't bundled with the platform.
790// UnbundledBuild() is always true when this is true.
791func (c *config) UnbundledBuildApps() bool {
792 return Bool(c.productVariables.Unbundled_build_apps)
793}
794
Jeongik Cha816a23a2020-07-08 01:09:23 +0900795// Returns true if building modules against prebuilt SDKs.
796func (c *config) AlwaysUsePrebuiltSdks() bool {
797 return Bool(c.productVariables.Always_use_prebuilt_sdks)
Colin Cross1f367bf2018-12-18 22:46:24 -0800798}
799
Paul Duffin9a89a2a2020-10-28 19:20:06 +0000800// Returns true if the boot jars check should be skipped.
801func (c *config) SkipBootJarsCheck() bool {
802 return Bool(c.productVariables.Skip_boot_jars_check)
803}
804
Doug Horn21b94272019-01-16 12:06:11 -0800805func (c *config) Fuchsia() bool {
806 return Bool(c.productVariables.Fuchsia)
807}
808
Colin Cross126a25c2017-10-31 13:55:34 -0700809func (c *config) MinimizeJavaDebugInfo() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800810 return Bool(c.productVariables.MinimizeJavaDebugInfo) && !Bool(c.productVariables.Eng)
Colin Cross126a25c2017-10-31 13:55:34 -0700811}
812
Colin Crossed064c02018-09-05 16:28:13 -0700813func (c *config) Debuggable() bool {
814 return Bool(c.productVariables.Debuggable)
815}
816
Jaewoong Jung1d6eb682018-11-29 15:08:44 -0800817func (c *config) Eng() bool {
818 return Bool(c.productVariables.Eng)
819}
820
Jiyong Park8d52f862018-07-07 18:02:07 +0900821func (c *config) DevicePrimaryArchType() ArchType {
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700822 return c.Targets[Android][0].Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +0900823}
824
Colin Cross893d8162017-04-26 17:34:03 -0700825func (c *config) SkipMegaDeviceInstall(path string) bool {
826 return Bool(c.Mega_device) &&
827 strings.HasPrefix(path, filepath.Join(c.buildDir, "target", "product"))
Dan Willemsen322acaf2016-01-12 23:07:05 -0800828}
Colin Cross16b23492016-01-06 14:41:07 -0800829
830func (c *config) SanitizeHost() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800831 return append([]string(nil), c.productVariables.SanitizeHost...)
Colin Cross16b23492016-01-06 14:41:07 -0800832}
833
834func (c *config) SanitizeDevice() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800835 return append([]string(nil), c.productVariables.SanitizeDevice...)
Colin Cross23ae82a2016-11-02 14:34:39 -0700836}
837
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700838func (c *config) SanitizeDeviceDiag() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800839 return append([]string(nil), c.productVariables.SanitizeDeviceDiag...)
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700840}
841
Colin Cross23ae82a2016-11-02 14:34:39 -0700842func (c *config) SanitizeDeviceArch() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800843 return append([]string(nil), c.productVariables.SanitizeDeviceArch...)
Colin Cross16b23492016-01-06 14:41:07 -0800844}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700845
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800846func (c *config) EnableCFI() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800847 if c.productVariables.EnableCFI == nil {
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -0800848 return true
849 } else {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800850 return *c.productVariables.EnableCFI
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -0800851 }
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800852}
853
Kostya Kortchinskyd5275c82019-02-01 08:42:56 -0800854func (c *config) DisableScudo() bool {
855 return Bool(c.productVariables.DisableScudo)
856}
857
Colin Crossa1ad8d12016-06-01 17:09:44 -0700858func (c *config) Android64() bool {
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700859 for _, t := range c.Targets[Android] {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700860 if t.Arch.ArchType.Multilib == "lib64" {
861 return true
862 }
863 }
864
865 return false
866}
Colin Cross9272ade2016-08-17 15:24:12 -0700867
Colin Cross9d45bb72016-08-29 16:14:13 -0700868func (c *config) UseGoma() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800869 return Bool(c.productVariables.UseGoma)
Colin Cross9d45bb72016-08-29 16:14:13 -0700870}
871
Ramy Medhatbbf25672019-07-17 12:30:04 +0000872func (c *config) UseRBE() bool {
873 return Bool(c.productVariables.UseRBE)
874}
875
Ramy Medhat8ea054a2020-01-27 14:19:44 -0500876func (c *config) UseRBEJAVAC() bool {
877 return Bool(c.productVariables.UseRBEJAVAC)
878}
879
880func (c *config) UseRBER8() bool {
881 return Bool(c.productVariables.UseRBER8)
882}
883
884func (c *config) UseRBED8() bool {
885 return Bool(c.productVariables.UseRBED8)
886}
887
Colin Cross8b8bec32019-11-15 13:18:43 -0800888func (c *config) UseRemoteBuild() bool {
889 return c.UseGoma() || c.UseRBE()
890}
891
Colin Cross66548102018-06-19 22:47:35 -0700892func (c *config) RunErrorProne() bool {
893 return c.IsEnvTrue("RUN_ERROR_PRONE")
894}
895
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800896func (c *config) XrefCorpusName() string {
897 return c.Getenv("XREF_CORPUS")
898}
899
Sasha Smundak6c2d4f92020-01-09 17:34:23 -0800900// Returns Compilation Unit encoding to use. Can be 'json' (default), 'proto' or 'all'.
901func (c *config) XrefCuEncoding() string {
902 if enc := c.Getenv("KYTHE_KZIP_ENCODING"); enc != "" {
903 return enc
904 }
905 return "json"
906}
907
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800908func (c *config) EmitXrefRules() bool {
909 return c.XrefCorpusName() != ""
910}
911
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700912func (c *config) ClangTidy() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800913 return Bool(c.productVariables.ClangTidy)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700914}
915
916func (c *config) TidyChecks() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800917 if c.productVariables.TidyChecks == nil {
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700918 return ""
919 }
Dan Willemsen45133ac2018-03-09 21:22:06 -0800920 return *c.productVariables.TidyChecks
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700921}
922
Colin Cross0f4e0d62016-07-27 10:56:55 -0700923func (c *config) LibartImgHostBaseAddress() string {
924 return "0x60000000"
925}
926
927func (c *config) LibartImgDeviceBaseAddress() string {
Elliott Hughesda3a0712020-03-06 16:55:28 -0800928 return "0x70000000"
Colin Cross0f4e0d62016-07-27 10:56:55 -0700929}
930
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800931func (c *config) ArtUseReadBarrier() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800932 return Bool(c.productVariables.ArtUseReadBarrier)
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800933}
934
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700935func (c *config) EnforceRROForModule(name string) bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800936 enforceList := c.productVariables.EnforceRROTargets
Jeongik Chab9b13272020-03-09 12:37:05 +0900937 // TODO(b/150820813) Some modules depend on static overlay, remove this after eliminating the dependency.
938 exemptedList := c.productVariables.EnforceRROExemptedTargets
Roland Levillainf6cc2612020-07-09 16:58:14 +0100939 if len(exemptedList) > 0 {
Jeongik Chab9b13272020-03-09 12:37:05 +0900940 if InList(name, exemptedList) {
941 return false
942 }
943 }
Roland Levillainf6cc2612020-07-09 16:58:14 +0100944 if len(enforceList) > 0 {
Yo Chiang4ebd06a2019-10-01 13:13:41 +0800945 if InList("*", enforceList) {
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700946 return true
947 }
Colin Crossa74ca042019-01-31 14:31:51 -0800948 return InList(name, enforceList)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700949 }
950 return false
951}
952
Jaewoong Jungc779cd42020-10-06 18:56:10 -0700953func (c *config) EnforceRROExemptedForModule(name string) bool {
954 return InList(name, c.productVariables.EnforceRROExemptedTargets)
955}
956
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700957func (c *config) EnforceRROExcludedOverlay(path string) bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800958 excluded := c.productVariables.EnforceRROExcludedOverlays
Roland Levillainf6cc2612020-07-09 16:58:14 +0100959 if len(excluded) > 0 {
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800960 return HasAnyPrefix(path, excluded)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700961 }
962 return false
963}
964
965func (c *config) ExportedNamespaces() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800966 return append([]string(nil), c.productVariables.NamespacesToExport...)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700967}
968
969func (c *config) HostStaticBinaries() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800970 return Bool(c.productVariables.HostStaticBinaries)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700971}
972
Colin Cross5a0dcd52018-10-05 14:20:06 -0700973func (c *config) UncompressPrivAppDex() bool {
974 return Bool(c.productVariables.UncompressPrivAppDex)
975}
976
977func (c *config) ModulesLoadedByPrivilegedModules() []string {
978 return c.productVariables.ModulesLoadedByPrivilegedModules
979}
980
Jingwen Chenebb0b572020-11-02 00:24:57 -0500981func (c *config) DexpreoptGlobalConfigPath(ctx PathContext) OptionalPath {
Colin Cross988414c2020-01-11 01:11:46 +0000982 if c.productVariables.DexpreoptGlobalConfig == nil {
Jingwen Chenebb0b572020-11-02 00:24:57 -0500983 return OptionalPathForPath(nil)
984 }
985 return OptionalPathForPath(
986 pathForBuildToolDep(ctx, *c.productVariables.DexpreoptGlobalConfig))
987}
988
989func (c *config) DexpreoptGlobalConfig(ctx PathContext) ([]byte, error) {
990 path := c.DexpreoptGlobalConfigPath(ctx)
991 if !path.Valid() {
Colin Cross988414c2020-01-11 01:11:46 +0000992 return nil, nil
993 }
Jingwen Chenebb0b572020-11-02 00:24:57 -0500994 ctx.AddNinjaFileDeps(path.String())
995 return ioutil.ReadFile(absolutePath(path.String()))
Colin Cross43f08db2018-11-12 10:13:39 -0800996}
997
David Brazdil91b4e3e2019-01-23 21:04:05 +0000998func (c *config) FrameworksBaseDirExists(ctx PathContext) bool {
999 return ExistentPathForSource(ctx, "frameworks", "base").Valid()
1000}
1001
Inseob Kimae553032019-05-14 18:52:49 +09001002func (c *config) VndkSnapshotBuildArtifacts() bool {
1003 return Bool(c.productVariables.VndkSnapshotBuildArtifacts)
1004}
1005
Colin Cross3b19f5d2019-09-17 14:45:31 -07001006func (c *config) HasMultilibConflict(arch ArchType) bool {
1007 return c.multilibConflicts[arch]
1008}
1009
Colin Cross9272ade2016-08-17 15:24:12 -07001010func (c *deviceConfig) Arches() []Arch {
1011 var arches []Arch
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001012 for _, target := range c.config.Targets[Android] {
Colin Cross9272ade2016-08-17 15:24:12 -07001013 arches = append(arches, target.Arch)
1014 }
1015 return arches
1016}
Dan Willemsend2ede872016-11-18 14:54:24 -08001017
Jayant Chowdhary34ce67d2018-03-08 11:00:50 -08001018func (c *deviceConfig) BinderBitness() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001019 is32BitBinder := c.config.productVariables.Binder32bit
Jayant Chowdhary34ce67d2018-03-08 11:00:50 -08001020 if is32BitBinder != nil && *is32BitBinder {
1021 return "32"
1022 }
1023 return "64"
1024}
1025
Dan Willemsen4353bc42016-12-05 17:16:02 -08001026func (c *deviceConfig) VendorPath() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001027 if c.config.productVariables.VendorPath != nil {
1028 return *c.config.productVariables.VendorPath
Dan Willemsen4353bc42016-12-05 17:16:02 -08001029 }
1030 return "vendor"
1031}
1032
Justin Yun71549282017-11-17 12:10:28 +09001033func (c *deviceConfig) VndkVersion() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001034 return String(c.config.productVariables.DeviceVndkVersion)
Justin Yun71549282017-11-17 12:10:28 +09001035}
1036
Jeongik Cha219141c2020-08-06 23:00:37 +09001037func (c *deviceConfig) CurrentApiLevelForVendorModules() string {
1038 return StringDefault(c.config.productVariables.DeviceCurrentApiLevelForVendorModules, "current")
1039}
1040
Justin Yun8fe12122017-12-07 17:18:15 +09001041func (c *deviceConfig) PlatformVndkVersion() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001042 return String(c.config.productVariables.Platform_vndk_version)
Justin Yun8fe12122017-12-07 17:18:15 +09001043}
1044
Justin Yun5f7f7e82019-11-18 19:52:14 +09001045func (c *deviceConfig) ProductVndkVersion() string {
1046 return String(c.config.productVariables.ProductVndkVersion)
1047}
1048
Justin Yun71549282017-11-17 12:10:28 +09001049func (c *deviceConfig) ExtraVndkVersions() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001050 return c.config.productVariables.ExtraVndkVersions
Dan Willemsend2ede872016-11-18 14:54:24 -08001051}
Jack He8cc71432016-12-08 15:45:07 -08001052
Vic Yangefd249e2018-11-12 20:19:56 -08001053func (c *deviceConfig) VndkUseCoreVariant() bool {
1054 return Bool(c.config.productVariables.VndkUseCoreVariant)
1055}
1056
Jiyong Park1a5d7b12018-01-15 15:05:10 +09001057func (c *deviceConfig) SystemSdkVersions() []string {
Colin Crossa74ca042019-01-31 14:31:51 -08001058 return c.config.productVariables.DeviceSystemSdkVersions
Jiyong Park1a5d7b12018-01-15 15:05:10 +09001059}
1060
1061func (c *deviceConfig) PlatformSystemSdkVersions() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001062 return c.config.productVariables.Platform_systemsdk_versions
Jiyong Park1a5d7b12018-01-15 15:05:10 +09001063}
1064
Jiyong Park2db76922017-11-08 16:03:48 +09001065func (c *deviceConfig) OdmPath() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001066 if c.config.productVariables.OdmPath != nil {
1067 return *c.config.productVariables.OdmPath
Jiyong Park2db76922017-11-08 16:03:48 +09001068 }
1069 return "odm"
1070}
1071
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +09001072func (c *deviceConfig) ProductPath() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001073 if c.config.productVariables.ProductPath != nil {
1074 return *c.config.productVariables.ProductPath
Jiyong Park2db76922017-11-08 16:03:48 +09001075 }
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +09001076 return "product"
Jiyong Park2db76922017-11-08 16:03:48 +09001077}
1078
Justin Yund5f6c822019-06-25 16:47:17 +09001079func (c *deviceConfig) SystemExtPath() string {
1080 if c.config.productVariables.SystemExtPath != nil {
1081 return *c.config.productVariables.SystemExtPath
Dario Frenifd05a742018-05-29 13:28:54 +01001082 }
Justin Yund5f6c822019-06-25 16:47:17 +09001083 return "system_ext"
Dario Frenifd05a742018-05-29 13:28:54 +01001084}
1085
Jack He8cc71432016-12-08 15:45:07 -08001086func (c *deviceConfig) BtConfigIncludeDir() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001087 return String(c.config.productVariables.BtConfigIncludeDir)
Jack He8cc71432016-12-08 15:45:07 -08001088}
Dan Willemsen581341d2017-02-09 16:16:31 -08001089
Jiyong Parkd773eb32017-07-03 13:18:12 +09001090func (c *deviceConfig) DeviceKernelHeaderDirs() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001091 return c.config.productVariables.DeviceKernelHeaders
Jiyong Parkd773eb32017-07-03 13:18:12 +09001092}
1093
Yi Kongceb5b762020-03-20 15:22:27 +08001094func (c *deviceConfig) SamplingPGO() bool {
1095 return Bool(c.config.productVariables.SamplingPGO)
1096}
1097
Roland Levillainada12702020-06-09 13:07:36 +01001098// JavaCoverageEnabledForPath returns whether Java code coverage is enabled for
1099// path. Coverage is enabled by default when the product variable
1100// JavaCoveragePaths is empty. If JavaCoveragePaths is not empty, coverage is
1101// enabled for any path which is part of this variable (and not part of the
1102// JavaCoverageExcludePaths product variable). Value "*" in JavaCoveragePaths
1103// represents any path.
1104func (c *deviceConfig) JavaCoverageEnabledForPath(path string) bool {
1105 coverage := false
Chris Gross2f748692020-06-24 20:36:59 +00001106 if len(c.config.productVariables.JavaCoveragePaths) == 0 ||
Roland Levillainada12702020-06-09 13:07:36 +01001107 InList("*", c.config.productVariables.JavaCoveragePaths) ||
1108 HasAnyPrefix(path, c.config.productVariables.JavaCoveragePaths) {
1109 coverage = true
1110 }
Roland Levillainf6cc2612020-07-09 16:58:14 +01001111 if coverage && len(c.config.productVariables.JavaCoverageExcludePaths) > 0 {
Roland Levillainada12702020-06-09 13:07:36 +01001112 if HasAnyPrefix(path, c.config.productVariables.JavaCoverageExcludePaths) {
1113 coverage = false
1114 }
1115 }
1116 return coverage
1117}
1118
Colin Cross1a6acd42020-06-16 17:51:46 -07001119// Returns true if gcov or clang coverage is enabled.
Dan Willemsen581341d2017-02-09 16:16:31 -08001120func (c *deviceConfig) NativeCoverageEnabled() bool {
Colin Cross1a6acd42020-06-16 17:51:46 -07001121 return Bool(c.config.productVariables.GcovCoverage) ||
1122 Bool(c.config.productVariables.ClangCoverage)
Dan Willemsen581341d2017-02-09 16:16:31 -08001123}
1124
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001125func (c *deviceConfig) ClangCoverageEnabled() bool {
1126 return Bool(c.config.productVariables.ClangCoverage)
1127}
1128
Colin Cross1a6acd42020-06-16 17:51:46 -07001129func (c *deviceConfig) GcovCoverageEnabled() bool {
1130 return Bool(c.config.productVariables.GcovCoverage)
1131}
1132
Roland Levillain4f5297b2020-06-09 12:44:06 +01001133// NativeCoverageEnabledForPath returns whether (GCOV- or Clang-based) native
1134// code coverage is enabled for path. By default, coverage is not enabled for a
1135// given path unless it is part of the NativeCoveragePaths product variable (and
1136// not part of the NativeCoverageExcludePaths product variable). Value "*" in
1137// NativeCoveragePaths represents any path.
1138func (c *deviceConfig) NativeCoverageEnabledForPath(path string) bool {
Ryan Campbell469a18a2017-02-27 09:01:54 -08001139 coverage := false
Roland Levillainf6cc2612020-07-09 16:58:14 +01001140 if len(c.config.productVariables.NativeCoveragePaths) > 0 {
Roland Levillain4f5297b2020-06-09 12:44:06 +01001141 if InList("*", c.config.productVariables.NativeCoveragePaths) || HasAnyPrefix(path, c.config.productVariables.NativeCoveragePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -07001142 coverage = true
Dan Willemsen581341d2017-02-09 16:16:31 -08001143 }
1144 }
Roland Levillainf6cc2612020-07-09 16:58:14 +01001145 if coverage && len(c.config.productVariables.NativeCoverageExcludePaths) > 0 {
Roland Levillain4f5297b2020-06-09 12:44:06 +01001146 if HasAnyPrefix(path, c.config.productVariables.NativeCoverageExcludePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -07001147 coverage = false
Ryan Campbell469a18a2017-02-27 09:01:54 -08001148 }
1149 }
1150 return coverage
Dan Willemsen581341d2017-02-09 16:16:31 -08001151}
Ivan Lozano5f595532017-07-13 14:46:05 -07001152
Pirama Arumuga Nainar49540802018-01-29 23:11:42 -08001153func (c *deviceConfig) PgoAdditionalProfileDirs() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001154 return c.config.productVariables.PgoAdditionalProfileDirs
Pirama Arumuga Nainar49540802018-01-29 23:11:42 -08001155}
1156
Tri Vo35a51432018-03-25 20:00:00 -07001157func (c *deviceConfig) VendorSepolicyDirs() []string {
1158 return c.config.productVariables.BoardVendorSepolicyDirs
1159}
1160
1161func (c *deviceConfig) OdmSepolicyDirs() []string {
1162 return c.config.productVariables.BoardOdmSepolicyDirs
1163}
1164
Felixa20a8752020-05-17 18:28:35 +02001165func (c *deviceConfig) SystemExtPublicSepolicyDirs() []string {
1166 return c.config.productVariables.SystemExtPublicSepolicyDirs
Tri Vo35a51432018-03-25 20:00:00 -07001167}
1168
Felixa20a8752020-05-17 18:28:35 +02001169func (c *deviceConfig) SystemExtPrivateSepolicyDirs() []string {
1170 return c.config.productVariables.SystemExtPrivateSepolicyDirs
Tri Vo35a51432018-03-25 20:00:00 -07001171}
1172
Inseob Kim0866b002019-04-15 20:21:29 +09001173func (c *deviceConfig) SepolicyM4Defs() []string {
1174 return c.config.productVariables.BoardSepolicyM4Defs
1175}
1176
Jiyong Park7f67f482019-01-05 12:57:48 +09001177func (c *deviceConfig) OverrideManifestPackageNameFor(name string) (manifestName string, overridden bool) {
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001178 return findOverrideValue(c.config.productVariables.ManifestPackageNameOverrides, name,
1179 "invalid override rule %q in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES should be <module_name>:<manifest_name>")
1180}
1181
1182func (c *deviceConfig) OverrideCertificateFor(name string) (certificatePath string, overridden bool) {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001183 return findOverrideValue(c.config.productVariables.CertificateOverrides, name,
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001184 "invalid override rule %q in PRODUCT_CERTIFICATE_OVERRIDES should be <module_name>:<certificate_module_name>")
1185}
1186
Jaewoong Jung9d22a912019-01-23 16:27:47 -08001187func (c *deviceConfig) OverridePackageNameFor(name string) string {
1188 newName, overridden := findOverrideValue(
1189 c.config.productVariables.PackageNameOverrides,
1190 name,
1191 "invalid override rule %q in PRODUCT_PACKAGE_NAME_OVERRIDES should be <module_name>:<package_name>")
1192 if overridden {
1193 return newName
1194 }
1195 return name
1196}
1197
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001198func findOverrideValue(overrides []string, name string, errorMsg string) (newValue string, overridden bool) {
Jiyong Park7f67f482019-01-05 12:57:48 +09001199 if overrides == nil || len(overrides) == 0 {
1200 return "", false
1201 }
1202 for _, o := range overrides {
1203 split := strings.Split(o, ":")
1204 if len(split) != 2 {
1205 // This shouldn't happen as this is first checked in make, but just in case.
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001206 panic(fmt.Errorf(errorMsg, o))
Jiyong Park7f67f482019-01-05 12:57:48 +09001207 }
1208 if matchPattern(split[0], name) {
1209 return substPattern(split[0], split[1], name), true
1210 }
1211 }
1212 return "", false
1213}
1214
Ivan Lozano5f595532017-07-13 14:46:05 -07001215func (c *config) IntegerOverflowDisabledForPath(path string) bool {
Roland Levillainf6cc2612020-07-09 16:58:14 +01001216 if len(c.productVariables.IntegerOverflowExcludePaths) == 0 {
Ivan Lozano5f595532017-07-13 14:46:05 -07001217 return false
1218 }
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001219 return HasAnyPrefix(path, c.productVariables.IntegerOverflowExcludePaths)
Ivan Lozano5f595532017-07-13 14:46:05 -07001220}
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001221
1222func (c *config) CFIDisabledForPath(path string) bool {
Roland Levillainf6cc2612020-07-09 16:58:14 +01001223 if len(c.productVariables.CFIExcludePaths) == 0 {
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001224 return false
1225 }
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001226 return HasAnyPrefix(path, c.productVariables.CFIExcludePaths)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001227}
1228
1229func (c *config) CFIEnabledForPath(path string) bool {
Roland Levillainf6cc2612020-07-09 16:58:14 +01001230 if len(c.productVariables.CFIIncludePaths) == 0 {
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001231 return false
1232 }
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001233 return HasAnyPrefix(path, c.productVariables.CFIIncludePaths)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001234}
Colin Crosse15ddaf2017-12-04 11:24:31 -08001235
Dan Willemsen0fe78662018-03-26 12:41:18 -07001236func (c *config) VendorConfig(name string) VendorConfig {
Colin Cross9d34f352019-11-22 16:03:51 -08001237 return soongconfig.Config(c.productVariables.VendorVars[name])
Dan Willemsen0fe78662018-03-26 12:41:18 -07001238}
1239
Colin Cross395f2cf2018-10-24 16:10:32 -07001240func (c *config) NdkAbis() bool {
1241 return Bool(c.productVariables.Ndk_abis)
1242}
1243
Martin Stjernholmc1ecc432019-11-15 15:00:31 +00001244func (c *config) AmlAbis() bool {
1245 return Bool(c.productVariables.Aml_abis)
1246}
1247
Dan Albert23d37e02018-11-28 08:30:10 -08001248func (c *config) ExcludeDraftNdkApis() bool {
1249 return Bool(c.productVariables.Exclude_draft_ndk_apis)
1250}
1251
Jiyong Park8fd61922018-11-08 02:50:25 +09001252func (c *config) FlattenApex() bool {
Roland Levillaina3863212019-08-12 19:56:16 +01001253 return Bool(c.productVariables.Flatten_apex)
Jiyong Park8fd61922018-11-08 02:50:25 +09001254}
1255
Jeongik Chac9464142019-01-07 12:07:27 +09001256func (c *config) EnforceSystemCertificate() bool {
1257 return Bool(c.productVariables.EnforceSystemCertificate)
1258}
1259
Colin Cross440e0d02020-06-11 11:32:11 -07001260func (c *config) EnforceSystemCertificateAllowList() []string {
1261 return c.productVariables.EnforceSystemCertificateAllowList
Jeongik Chac9464142019-01-07 12:07:27 +09001262}
1263
Jeongik Cha2cc570d2019-10-29 15:44:45 +09001264func (c *config) EnforceProductPartitionInterface() bool {
1265 return Bool(c.productVariables.EnforceProductPartitionInterface)
1266}
1267
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001268func (c *config) InstallExtraFlattenedApexes() bool {
1269 return Bool(c.productVariables.InstallExtraFlattenedApexes)
1270}
1271
Colin Crossf24a22a2019-01-31 14:12:44 -08001272func (c *config) ProductHiddenAPIStubs() []string {
1273 return c.productVariables.ProductHiddenAPIStubs
Colin Cross8faf8fc2019-01-16 15:15:52 -08001274}
1275
Colin Crossf24a22a2019-01-31 14:12:44 -08001276func (c *config) ProductHiddenAPIStubsSystem() []string {
1277 return c.productVariables.ProductHiddenAPIStubsSystem
Colin Cross8faf8fc2019-01-16 15:15:52 -08001278}
1279
Colin Crossf24a22a2019-01-31 14:12:44 -08001280func (c *config) ProductHiddenAPIStubsTest() []string {
1281 return c.productVariables.ProductHiddenAPIStubsTest
Colin Cross8faf8fc2019-01-16 15:15:52 -08001282}
Dan Willemsen71c74602019-04-10 12:27:35 -07001283
Dan Willemsen54879d12019-04-18 10:08:46 -07001284func (c *deviceConfig) TargetFSConfigGen() []string {
Dan Willemsen71c74602019-04-10 12:27:35 -07001285 return c.config.productVariables.TargetFSConfigGen
1286}
Inseob Kim0866b002019-04-15 20:21:29 +09001287
1288func (c *config) ProductPublicSepolicyDirs() []string {
1289 return c.productVariables.ProductPublicSepolicyDirs
1290}
1291
1292func (c *config) ProductPrivateSepolicyDirs() []string {
1293 return c.productVariables.ProductPrivateSepolicyDirs
1294}
1295
1296func (c *config) ProductCompatibleProperty() bool {
1297 return Bool(c.productVariables.ProductCompatibleProperty)
1298}
Inseob Kim1f086e22019-05-09 13:29:15 +09001299
Colin Cross50ddcc42019-05-16 12:28:22 -07001300func (c *config) MissingUsesLibraries() []string {
1301 return c.productVariables.MissingUsesLibraries
1302}
1303
Inseob Kim1f086e22019-05-09 13:29:15 +09001304func (c *deviceConfig) DeviceArch() string {
1305 return String(c.config.productVariables.DeviceArch)
1306}
1307
1308func (c *deviceConfig) DeviceArchVariant() string {
1309 return String(c.config.productVariables.DeviceArchVariant)
1310}
1311
1312func (c *deviceConfig) DeviceSecondaryArch() string {
1313 return String(c.config.productVariables.DeviceSecondaryArch)
1314}
1315
1316func (c *deviceConfig) DeviceSecondaryArchVariant() string {
1317 return String(c.config.productVariables.DeviceSecondaryArchVariant)
1318}
Yifan Hong82db7352020-01-21 16:12:26 -08001319
1320func (c *deviceConfig) BoardUsesRecoveryAsBoot() bool {
1321 return Bool(c.config.productVariables.BoardUsesRecoveryAsBoot)
1322}
Yifan Hong97365ee2020-07-29 09:51:57 -07001323
1324func (c *deviceConfig) BoardKernelBinaries() []string {
1325 return c.config.productVariables.BoardKernelBinaries
1326}
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001327
Yifan Hong42bef8d2020-08-05 14:36:09 -07001328func (c *deviceConfig) BoardKernelModuleInterfaceVersions() []string {
1329 return c.config.productVariables.BoardKernelModuleInterfaceVersions
1330}
1331
Yifan Hongdd8dacc2020-10-21 15:40:17 -07001332func (c *deviceConfig) BoardMoveRecoveryResourcesToVendorBoot() bool {
1333 return Bool(c.config.productVariables.BoardMoveRecoveryResourcesToVendorBoot)
1334}
1335
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001336// The ConfiguredJarList struct provides methods for handling a list of (apex, jar) pairs.
1337// Such lists are used in the build system for things like bootclasspath jars or system server jars.
1338// The apex part is either an apex name, or a special names "platform" or "system_ext". Jar is a
1339// module name. The pairs come from Make product variables as a list of colon-separated strings.
1340//
1341// Examples:
1342// - "com.android.art:core-oj"
1343// - "platform:framework"
1344// - "system_ext:foo"
1345//
1346type ConfiguredJarList struct {
1347 apexes []string // A list of apex components.
1348 jars []string // A list of jar components.
1349}
1350
1351// The length of the list.
1352func (l *ConfiguredJarList) Len() int {
1353 return len(l.jars)
1354}
1355
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001356// Jar component of idx-th pair on the list.
1357func (l *ConfiguredJarList) Jar(idx int) string {
1358 return l.jars[idx]
1359}
1360
Paul Duffin9a89a2a2020-10-28 19:20:06 +00001361// Apex component of idx-th pair on the list.
1362func (l *ConfiguredJarList) Apex(idx int) string {
1363 return l.apexes[idx]
1364}
1365
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001366// If the list contains a pair with the given jar.
1367func (l *ConfiguredJarList) ContainsJar(jar string) bool {
1368 return InList(jar, l.jars)
1369}
1370
1371// If the list contains the given (apex, jar) pair.
1372func (l *ConfiguredJarList) containsApexJarPair(apex, jar string) bool {
1373 for i := 0; i < l.Len(); i++ {
Paul Duffin1e8c6072020-10-23 18:28:55 +01001374 if apex == l.apexes[i] && jar == l.jars[i] {
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001375 return true
1376 }
1377 }
1378 return false
1379}
1380
1381// Index of the first pair with the given jar on the list, or -1 if none.
1382func (l *ConfiguredJarList) IndexOfJar(jar string) int {
1383 return IndexList(jar, l.jars)
1384}
1385
Paul Duffin7d584e92020-10-23 18:26:03 +01001386func copyAndAppend(list []string, item string) []string {
1387 // Create the result list to be 1 longer than the input.
1388 result := make([]string, len(list)+1)
1389
1390 // Copy the whole input list into the result.
1391 count := copy(result, list)
1392
1393 // Insert the extra item at the end.
1394 result[count] = item
1395
1396 return result
1397}
1398
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001399// Append an (apex, jar) pair to the list.
Paul Duffin7d584e92020-10-23 18:26:03 +01001400func (l *ConfiguredJarList) Append(apex string, jar string) ConfiguredJarList {
1401 // Create a copy of the backing arrays before appending to avoid sharing backing
1402 // arrays that are mutated across instances.
1403 apexes := copyAndAppend(l.apexes, apex)
1404 jars := copyAndAppend(l.jars, jar)
1405
1406 return ConfiguredJarList{apexes, jars}
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001407}
1408
1409// Filter out sublist.
Paul Duffin7d584e92020-10-23 18:26:03 +01001410func (l *ConfiguredJarList) RemoveList(list ConfiguredJarList) ConfiguredJarList {
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001411 apexes := make([]string, 0, l.Len())
1412 jars := make([]string, 0, l.Len())
1413
1414 for i, jar := range l.jars {
Paul Duffin1e8c6072020-10-23 18:28:55 +01001415 apex := l.apexes[i]
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001416 if !list.containsApexJarPair(apex, jar) {
1417 apexes = append(apexes, apex)
1418 jars = append(jars, jar)
1419 }
1420 }
1421
Paul Duffin7d584e92020-10-23 18:26:03 +01001422 return ConfiguredJarList{apexes, jars}
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001423}
1424
1425// A copy of the list of strings containing jar components.
1426func (l *ConfiguredJarList) CopyOfJars() []string {
1427 return CopyOf(l.jars)
1428}
1429
1430// A copy of the list of strings with colon-separated (apex, jar) pairs.
1431func (l *ConfiguredJarList) CopyOfApexJarPairs() []string {
1432 pairs := make([]string, 0, l.Len())
1433
1434 for i, jar := range l.jars {
Paul Duffin1e8c6072020-10-23 18:28:55 +01001435 apex := l.apexes[i]
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001436 pairs = append(pairs, apex+":"+jar)
1437 }
1438
1439 return pairs
1440}
1441
1442// A list of build paths based on the given directory prefix.
1443func (l *ConfiguredJarList) BuildPaths(ctx PathContext, dir OutputPath) WritablePaths {
1444 paths := make(WritablePaths, l.Len())
1445 for i, jar := range l.jars {
1446 paths[i] = dir.Join(ctx, ModuleStem(jar)+".jar")
1447 }
1448 return paths
1449}
1450
Paul Duffin69d1fb12020-10-23 21:14:20 +01001451// Called when loading configuration from JSON into a configuration structure.
1452func (l *ConfiguredJarList) UnmarshalJSON(b []byte) error {
1453 // Try and unmarshal into a []string each item of which contains a pair
1454 // <apex>:<jar>.
1455 var list []string
1456 err := json.Unmarshal(b, &list)
1457 if err != nil {
1458 // Did not work so return
1459 return err
1460 }
1461
1462 apexes, jars, err := splitListOfPairsIntoPairOfLists(list)
1463 if err != nil {
1464 return err
1465 }
1466 l.apexes = apexes
1467 l.jars = jars
1468 return nil
1469}
1470
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001471func ModuleStem(module string) string {
1472 // b/139391334: the stem of framework-minus-apex is framework. This is hard coded here until we
1473 // find a good way to query the stem of a module before any other mutators are run.
1474 if module == "framework-minus-apex" {
1475 return "framework"
1476 }
1477 return module
1478}
1479
1480// A list of on-device paths.
1481func (l *ConfiguredJarList) DevicePaths(cfg Config, ostype OsType) []string {
1482 paths := make([]string, l.Len())
1483 for i, jar := range l.jars {
1484 apex := l.apexes[i]
1485 name := ModuleStem(jar) + ".jar"
1486
1487 var subdir string
1488 if apex == "platform" {
1489 subdir = "system/framework"
1490 } else if apex == "system_ext" {
1491 subdir = "system_ext/framework"
1492 } else {
1493 subdir = filepath.Join("apex", apex, "javalib")
1494 }
1495
1496 if ostype.Class == Host {
1497 paths[i] = filepath.Join(cfg.Getenv("OUT_DIR"), "host", cfg.PrebuiltOS(), subdir, name)
1498 } else {
1499 paths[i] = filepath.Join("/", subdir, name)
1500 }
1501 }
1502 return paths
1503}
1504
Paul Duffin7d584e92020-10-23 18:26:03 +01001505func (l *ConfiguredJarList) String() string {
1506 var pairs []string
1507 for i := 0; i < l.Len(); i++ {
1508 pairs = append(pairs, l.apexes[i]+":"+l.jars[i])
1509 }
1510 return strings.Join(pairs, ",")
1511}
1512
Paul Duffin01416602020-10-23 21:04:03 +01001513func splitListOfPairsIntoPairOfLists(list []string) ([]string, []string, error) {
1514 // Now we need to populate this list by splitting each item in the slice of
1515 // pairs and appending them to the appropriate list of apexes or jars.
1516 apexes := make([]string, len(list))
1517 jars := make([]string, len(list))
1518
1519 for i, apexjar := range list {
1520 apex, jar, err := splitConfiguredJarPair(apexjar)
1521 if err != nil {
1522 return nil, nil, err
1523 }
1524 apexes[i] = apex
1525 jars[i] = jar
1526 }
1527
1528 return apexes, jars, nil
1529}
1530
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001531// Expected format for apexJarValue = <apex name>:<jar name>
Paul Duffin01416602020-10-23 21:04:03 +01001532func splitConfiguredJarPair(str string) (string, string, error) {
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001533 pair := strings.SplitN(str, ":", 2)
1534 if len(pair) == 2 {
Paul Duffin01416602020-10-23 21:04:03 +01001535 return pair[0], pair[1], nil
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001536 } else {
Paul Duffin01416602020-10-23 21:04:03 +01001537 return "error-apex", "error-jar", fmt.Errorf("malformed (apex, jar) pair: '%s', expected format: <apex>:<jar>", str)
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001538 }
1539}
1540
Paul Duffine10dfa42020-10-23 21:23:44 +01001541func CreateTestConfiguredJarList(list []string) ConfiguredJarList {
Paul Duffin01416602020-10-23 21:04:03 +01001542 apexes, jars, err := splitListOfPairsIntoPairOfLists(list)
1543 if err != nil {
Paul Duffine10dfa42020-10-23 21:23:44 +01001544 panic(err)
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001545 }
1546
Paul Duffin01416602020-10-23 21:04:03 +01001547 return ConfiguredJarList{apexes, jars}
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001548}
1549
1550func EmptyConfiguredJarList() ConfiguredJarList {
1551 return ConfiguredJarList{}
1552}
1553
1554var earlyBootJarsKey = NewOnceKey("earlyBootJars")
1555
1556func (c *config) BootJars() []string {
1557 return c.Once(earlyBootJarsKey, func() interface{} {
Paul Duffin69d1fb12020-10-23 21:14:20 +01001558 list := c.productVariables.BootJars.CopyOfJars()
1559 list = append(list, c.productVariables.UpdatableBootJars.CopyOfJars()...)
1560 return list
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001561 }).([]string)
1562}
Paul Duffin9a89a2a2020-10-28 19:20:06 +00001563
1564func (c *config) NonUpdatableBootJars() ConfiguredJarList {
1565 return c.productVariables.BootJars
1566}
1567
1568func (c *config) UpdatableBootJars() ConfiguredJarList {
1569 return c.productVariables.UpdatableBootJars
1570}