blob: f5deeee5723ceb8a8df8e7d9f36858ec05116ff0 [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 {
Dan Willemsen322acaf2016-01-12 23:07:05 -080054 Mega_device *bool `json:",omitempty"`
Dan Willemsen01a405a2016-06-13 17:19:03 -070055 Host_bionic *bool `json:",omitempty"`
Colin Cross3f40fa42015-01-30 17:27:36 -080056}
57
Colin Cross27385972015-09-18 10:57:10 -070058func (f *FileConfigurableOptions) SetDefaultConfig() {
59 *f = FileConfigurableOptions{}
Colin Cross3f40fa42015-01-30 17:27:36 -080060}
61
Colin Cross9272ade2016-08-17 15:24:12 -070062// A Config object represents the entire build configuration for Android.
Colin Crossc3c0a492015-04-10 15:43:55 -070063type Config struct {
64 *config
65}
66
Jeff Gastonefc1b412017-03-29 17:29:06 -070067func (c Config) BuildDir() string {
68 return c.buildDir
69}
70
Colin Cross9272ade2016-08-17 15:24:12 -070071// A DeviceConfig object represents the configuration for a particular device being built. For
72// now there will only be one of these, but in the future there may be multiple devices being
73// built
74type DeviceConfig struct {
75 *deviceConfig
76}
77
Colin Cross9d34f352019-11-22 16:03:51 -080078type VendorConfig soongconfig.SoongConfig
Dan Willemsen0fe78662018-03-26 12:41:18 -070079
Colin Cross1332b002015-04-07 17:11:30 -070080type config struct {
Colin Cross3f40fa42015-01-30 17:27:36 -080081 FileConfigurableOptions
Dan Willemsen45133ac2018-03-09 21:22:06 -080082 productVariables productVariables
Colin Cross3f40fa42015-01-30 17:27:36 -080083
Dan Willemsen674dc7f2018-03-12 18:06:05 -070084 // Only available on configs created by TestConfig
85 TestProductVariables *productVariables
86
Colin Crosse87040b2017-12-11 15:52:26 -080087 PrimaryBuilder string
Dan Willemsen87b17d12015-07-14 00:39:06 -070088 ConfigFileName string
89 ProductVariablesFileName string
90
Colin Cross0f7d2ef2019-10-16 11:03:10 -070091 Targets map[OsType][]Target
92 BuildOSTarget Target // the Target for tools run on the build machine
93 BuildOSCommonTarget Target // the Target for common (java) tools run on the build machine
94 AndroidCommonTarget Target // the Target for common modules for the Android device
Dan Willemsen218f6562015-07-08 18:13:11 -070095
Colin Cross3b19f5d2019-09-17 14:45:31 -070096 // multilibConflicts for an ArchType is true if there is earlier configured device architecture with the same
97 // multilib value.
98 multilibConflicts map[ArchType]bool
99
Colin Cross9272ade2016-08-17 15:24:12 -0700100 deviceConfig *deviceConfig
101
Chris Parsons8f232a22020-06-23 17:37:05 -0400102 srcDir string // the path of the root source directory
103 buildDir string // the path of the build output directory
104 moduleListFile string // the path to the file which lists blueprint files to parse.
Colin Crossc1e86a32015-04-15 12:33:28 -0700105
Colin Cross6ccbc912017-10-10 23:07:38 -0700106 env map[string]string
Dan Willemsene7680ba2015-09-11 17:06:19 -0700107 envLock sync.Mutex
108 envDeps map[string]string
109 envFrozen bool
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800110
111 inMake bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700112
Colin Cross32616ed2017-09-05 21:56:44 -0700113 captureBuild bool // true for tests, saves build parameters for each module
114 ignoreEnvironment bool // true for tests, returns empty from all Getenv calls
Colin Crosscec81712017-07-13 14:43:27 -0700115
Colin Crosse87040b2017-12-11 15:52:26 -0800116 stopBefore bootstrap.StopBefore
117
Colin Cross98be1bb2019-12-13 20:41:13 -0800118 fs pathtools.FileSystem
119 mockBpList string
120
Colin Cross5e6a7972020-06-07 16:56:32 -0700121 // If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error
122 // in tests when a path doesn't exist.
123 testAllowNonExistentPaths bool
124
Colin Cross9272ade2016-08-17 15:24:12 -0700125 OncePer
126}
127
128type deviceConfig struct {
Dan Willemsen00269f22017-07-06 16:59:48 -0700129 config *config
Colin Cross9272ade2016-08-17 15:24:12 -0700130 OncePer
Colin Cross3f40fa42015-01-30 17:27:36 -0800131}
132
Colin Cross485e5722015-08-27 13:28:01 -0700133type jsonConfigurable interface {
Colin Cross27385972015-09-18 10:57:10 -0700134 SetDefaultConfig()
Colin Cross485e5722015-08-27 13:28:01 -0700135}
Colin Cross3f40fa42015-01-30 17:27:36 -0800136
Colin Cross485e5722015-08-27 13:28:01 -0700137func loadConfig(config *config) error {
Colin Cross988414c2020-01-11 01:11:46 +0000138 err := loadFromConfigFile(&config.FileConfigurableOptions, absolutePath(config.ConfigFileName))
Colin Cross485e5722015-08-27 13:28:01 -0700139 if err != nil {
140 return err
141 }
142
Colin Cross988414c2020-01-11 01:11:46 +0000143 return loadFromConfigFile(&config.productVariables, absolutePath(config.ProductVariablesFileName))
Colin Cross485e5722015-08-27 13:28:01 -0700144}
145
146// loads configuration options from a JSON file in the cwd.
147func loadFromConfigFile(configurable jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800148 // Try to open the file
Colin Cross485e5722015-08-27 13:28:01 -0700149 configFileReader, err := os.Open(filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800150 defer configFileReader.Close()
151 if os.IsNotExist(err) {
152 // Need to create a file, so that blueprint & ninja don't get in
153 // a dependency tracking loop.
154 // Make a file-configurable-options with defaults, write it out using
155 // a json writer.
Colin Cross27385972015-09-18 10:57:10 -0700156 configurable.SetDefaultConfig()
157 err = saveToConfigFile(configurable, filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800158 if err != nil {
159 return err
160 }
Colin Cross15cd21a2018-02-27 11:26:02 -0800161 } else if err != nil {
162 return fmt.Errorf("config file: could not open %s: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800163 } else {
164 // Make a decoder for it
165 jsonDecoder := json.NewDecoder(configFileReader)
Colin Cross485e5722015-08-27 13:28:01 -0700166 err = jsonDecoder.Decode(configurable)
Colin Cross3f40fa42015-01-30 17:27:36 -0800167 if err != nil {
Colin Cross15cd21a2018-02-27 11:26:02 -0800168 return fmt.Errorf("config file: %s did not parse correctly: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800169 }
170 }
171
Colin Cross3f40fa42015-01-30 17:27:36 -0800172 // No error
173 return nil
174}
175
Colin Crossd8f20142016-11-03 09:43:26 -0700176// atomically writes the config file in case two copies of soong_build are running simultaneously
177// (for example, docs generation and ninja manifest generation)
Colin Cross485e5722015-08-27 13:28:01 -0700178func saveToConfigFile(config jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800179 data, err := json.MarshalIndent(&config, "", " ")
180 if err != nil {
181 return fmt.Errorf("cannot marshal config data: %s", err.Error())
182 }
183
Colin Crossd8f20142016-11-03 09:43:26 -0700184 f, err := ioutil.TempFile(filepath.Dir(filename), "config")
Colin Cross3f40fa42015-01-30 17:27:36 -0800185 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700186 return fmt.Errorf("cannot create empty config file %s: %s\n", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800187 }
Colin Crossd8f20142016-11-03 09:43:26 -0700188 defer os.Remove(f.Name())
189 defer f.Close()
Colin Cross3f40fa42015-01-30 17:27:36 -0800190
Colin Crossd8f20142016-11-03 09:43:26 -0700191 _, err = f.Write(data)
Colin Cross3f40fa42015-01-30 17:27:36 -0800192 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700193 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
194 }
195
Colin Crossd8f20142016-11-03 09:43:26 -0700196 _, err = f.WriteString("\n")
Colin Cross485e5722015-08-27 13:28:01 -0700197 if err != nil {
198 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800199 }
200
Colin Crossd8f20142016-11-03 09:43:26 -0700201 f.Close()
202 os.Rename(f.Name(), filename)
203
Colin Cross3f40fa42015-01-30 17:27:36 -0800204 return nil
205}
206
Colin Cross988414c2020-01-11 01:11:46 +0000207// NullConfig returns a mostly empty Config for use by standalone tools like dexpreopt_gen that
208// use the android package.
209func NullConfig(buildDir string) Config {
210 return Config{
211 config: &config{
212 buildDir: buildDir,
213 fs: pathtools.OsFs,
214 },
215 }
216}
217
Colin Crossce75d2c2016-10-06 16:12:58 -0700218// TestConfig returns a Config object suitable for using for tests
Colin Cross98be1bb2019-12-13 20:41:13 -0800219func TestConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
Colin Cross9c6241f2019-04-22 15:51:26 -0700220 envCopy := make(map[string]string)
221 for k, v := range env {
222 envCopy[k] = v
223 }
224
225 // Copy the real PATH value to the test environment, it's needed by HostSystemTool() used in x86_darwin_host.go
226 envCopy["PATH"] = originalEnv["PATH"]
227
Dan Willemsen00269f22017-07-06 16:59:48 -0700228 config := &config{
Dan Willemsen45133ac2018-03-09 21:22:06 -0800229 productVariables: productVariables{
Dan Albert4f378d72020-07-23 17:32:15 -0700230 DeviceName: stringPtr("test_device"),
231 Platform_sdk_version: intPtr(30),
232 Platform_sdk_codename: stringPtr("S"),
233 Platform_version_active_codenames: []string{"S"},
234 DeviceSystemSdkVersions: []string{"14", "15"},
235 Platform_systemsdk_versions: []string{"29", "30"},
236 AAPTConfig: []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"},
237 AAPTPreferredConfig: stringPtr("xhdpi"),
238 AAPTCharacteristics: stringPtr("nosdcard"),
239 AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"},
240 UncompressPrivAppDex: boolPtr(true),
Dan Willemsen00269f22017-07-06 16:59:48 -0700241 },
242
Colin Cross6ccbc912017-10-10 23:07:38 -0700243 buildDir: buildDir,
244 captureBuild: true,
Colin Cross9c6241f2019-04-22 15:51:26 -0700245 env: envCopy,
Colin Cross5e6a7972020-06-07 16:56:32 -0700246
247 // Set testAllowNonExistentPaths so that test contexts don't need to specify every path
248 // passed to PathForSource or PathForModuleSrc.
249 testAllowNonExistentPaths: true,
Dan Willemsen00269f22017-07-06 16:59:48 -0700250 }
251 config.deviceConfig = &deviceConfig{
252 config: config,
253 }
Dan Willemsen45133ac2018-03-09 21:22:06 -0800254 config.TestProductVariables = &config.productVariables
Dan Willemsen00269f22017-07-06 16:59:48 -0700255
Colin Cross98be1bb2019-12-13 20:41:13 -0800256 config.mockFileSystem(bp, fs)
257
Colin Cross1369cdb2017-09-29 17:58:17 -0700258 if err := config.fromEnv(); err != nil {
259 panic(err)
260 }
261
Dan Willemsen00269f22017-07-06 16:59:48 -0700262 return Config{config}
Colin Crossce75d2c2016-10-06 16:12:58 -0700263}
264
Colin Cross98be1bb2019-12-13 20:41:13 -0800265func TestArchConfigNativeBridge(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
266 testConfig := TestArchConfig(buildDir, env, bp, fs)
dimitry1f33e402019-03-26 12:39:31 +0100267 config := testConfig.config
268
Colin Cross0d99f7c2019-05-14 16:01:24 -0700269 config.Targets[Android] = []Target{
Colin Cross3b19f5d2019-09-17 14:45:31 -0700270 {Android, Arch{ArchType: X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", ""},
271 {Android, Arch{ArchType: X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", ""},
272 {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeEnabled, "x86_64", "arm64"},
273 {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeEnabled, "x86", "arm"},
dimitry1f33e402019-03-26 12:39:31 +0100274 }
275
276 return testConfig
277}
278
Colin Cross98be1bb2019-12-13 20:41:13 -0800279func TestArchConfigFuchsia(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
280 testConfig := TestConfig(buildDir, env, bp, fs)
Doug Hornc32c6b02019-01-17 14:44:05 -0800281 config := testConfig.config
282
283 config.Targets = map[OsType][]Target{
284 Fuchsia: []Target{
Colin Crossf28329d2020-02-15 11:00:10 -0800285 {Fuchsia, Arch{ArchType: Arm64, ArchVariant: "", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", ""},
Doug Hornc32c6b02019-01-17 14:44:05 -0800286 },
287 BuildOs: []Target{
dimitry8d6dde82019-07-11 10:23:53 +0200288 {BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", ""},
Doug Hornc32c6b02019-01-17 14:44:05 -0800289 },
290 }
291
292 return testConfig
293}
294
Colin Crossae4c6182017-09-15 17:33:55 -0700295// TestConfig returns a Config object suitable for using for tests that need to run the arch mutator
Colin Cross98be1bb2019-12-13 20:41:13 -0800296func TestArchConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config {
297 testConfig := TestConfig(buildDir, env, bp, fs)
Colin Crossae4c6182017-09-15 17:33:55 -0700298 config := testConfig.config
299
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700300 config.Targets = map[OsType][]Target{
301 Android: []Target{
Colin Cross3b19f5d2019-09-17 14:45:31 -0700302 {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", ""},
303 {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", ""},
Colin Crossae4c6182017-09-15 17:33:55 -0700304 },
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700305 BuildOs: []Target{
dimitry8d6dde82019-07-11 10:23:53 +0200306 {BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", ""},
307 {BuildOs, Arch{ArchType: X86}, NativeBridgeDisabled, "", ""},
Colin Crossae4c6182017-09-15 17:33:55 -0700308 },
309 }
310
Colin Cross0d99f7c2019-05-14 16:01:24 -0700311 if runtime.GOOS == "darwin" {
312 config.Targets[BuildOs] = config.Targets[BuildOs][:1]
313 }
314
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700315 config.BuildOSTarget = config.Targets[BuildOs][0]
316 config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0]
317 config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
Inseob Kim1f086e22019-05-09 13:29:15 +0900318 config.TestProductVariables.DeviceArch = proptools.StringPtr("arm64")
319 config.TestProductVariables.DeviceArchVariant = proptools.StringPtr("armv8-a")
320 config.TestProductVariables.DeviceSecondaryArch = proptools.StringPtr("arm")
321 config.TestProductVariables.DeviceSecondaryArchVariant = proptools.StringPtr("armv7-a-neon")
Colin Cross2a076922018-10-04 23:28:25 -0700322
Colin Crossae4c6182017-09-15 17:33:55 -0700323 return testConfig
324}
325
Colin Cross3f40fa42015-01-30 17:27:36 -0800326// New creates a new Config object. The srcDir argument specifies the path to
327// the root source directory. It also loads the config file, if found.
Chris Parsons8f232a22020-06-23 17:37:05 -0400328func NewConfig(srcDir, buildDir string, moduleListFile string) (Config, error) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800329 // Make a config with default options
Colin Cross9272ade2016-08-17 15:24:12 -0700330 config := &config{
331 ConfigFileName: filepath.Join(buildDir, configFileName),
332 ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName),
Dan Willemsen87b17d12015-07-14 00:39:06 -0700333
Colin Cross6ccbc912017-10-10 23:07:38 -0700334 env: originalEnv,
335
Colin Cross3b19f5d2019-09-17 14:45:31 -0700336 srcDir: srcDir,
337 buildDir: buildDir,
338 multilibConflicts: make(map[ArchType]bool),
Colin Cross98be1bb2019-12-13 20:41:13 -0800339
Chris Parsons8f232a22020-06-23 17:37:05 -0400340 moduleListFile: moduleListFile,
341 fs: pathtools.NewOsFs(absSrcDir),
Colin Cross68f55102015-03-25 14:43:57 -0700342 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800343
Dan Willemsen00269f22017-07-06 16:59:48 -0700344 config.deviceConfig = &deviceConfig{
Colin Cross9272ade2016-08-17 15:24:12 -0700345 config: config,
346 }
347
Liz Kammer7941b302020-07-28 13:27:34 -0700348 // Soundness check of the build and source directories. This won't catch strange
349 // configurations with symlinks, but at least checks the obvious case.
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700350 absBuildDir, err := filepath.Abs(buildDir)
351 if err != nil {
352 return Config{}, err
353 }
354
355 absSrcDir, err := filepath.Abs(srcDir)
356 if err != nil {
357 return Config{}, err
358 }
359
360 if strings.HasPrefix(absSrcDir, absBuildDir) {
361 return Config{}, fmt.Errorf("Build dir must not contain source directory")
362 }
363
Colin Cross3f40fa42015-01-30 17:27:36 -0800364 // Load any configurable options from the configuration file
Colin Cross9272ade2016-08-17 15:24:12 -0700365 err = loadConfig(config)
Colin Cross3f40fa42015-01-30 17:27:36 -0800366 if err != nil {
Colin Crossc3c0a492015-04-10 15:43:55 -0700367 return Config{}, err
Colin Cross3f40fa42015-01-30 17:27:36 -0800368 }
369
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800370 inMakeFile := filepath.Join(buildDir, ".soong.in_make")
Colin Cross988414c2020-01-11 01:11:46 +0000371 if _, err := os.Stat(absolutePath(inMakeFile)); err == nil {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800372 config.inMake = true
373 }
374
Colin Crossa1ad8d12016-06-01 17:09:44 -0700375 targets, err := decodeTargetProductVariables(config)
Dan Willemsen218f6562015-07-08 18:13:11 -0700376 if err != nil {
377 return Config{}, err
378 }
379
Paul Duffin1356d8c2020-02-25 19:26:33 +0000380 // Make the CommonOS OsType available for all products.
381 targets[CommonOS] = []Target{commonTargetMap[CommonOS.Name]}
382
Dan Albert4098deb2016-10-19 14:04:41 -0700383 var archConfig []archConfig
Dan Willemsen322acaf2016-01-12 23:07:05 -0800384 if Bool(config.Mega_device) {
Dan Albert4098deb2016-10-19 14:04:41 -0700385 archConfig = getMegaDeviceConfig()
Colin Cross395f2cf2018-10-24 16:10:32 -0700386 } else if config.NdkAbis() {
Dan Albert4098deb2016-10-19 14:04:41 -0700387 archConfig = getNdkAbisConfig()
Martin Stjernholmc1ecc432019-11-15 15:00:31 +0000388 } else if config.AmlAbis() {
389 archConfig = getAmlAbisConfig()
Dan Albert4098deb2016-10-19 14:04:41 -0700390 }
391
392 if archConfig != nil {
Dan Willemsen01a3c252019-01-11 19:02:16 -0800393 androidTargets, err := decodeArchSettings(Android, archConfig)
Dan Willemsen322acaf2016-01-12 23:07:05 -0800394 if err != nil {
395 return Config{}, err
396 }
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700397 targets[Android] = androidTargets
Dan Willemsen322acaf2016-01-12 23:07:05 -0800398 }
399
Colin Cross3b19f5d2019-09-17 14:45:31 -0700400 multilib := make(map[string]bool)
401 for _, target := range targets[Android] {
402 if seen := multilib[target.Arch.ArchType.Multilib]; seen {
403 config.multilibConflicts[target.Arch.ArchType] = true
404 }
405 multilib[target.Arch.ArchType.Multilib] = true
406 }
407
Colin Crossa1ad8d12016-06-01 17:09:44 -0700408 config.Targets = targets
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700409 config.BuildOSTarget = config.Targets[BuildOs][0]
410 config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0]
411 if len(config.Targets[Android]) > 0 {
412 config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
413 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700414
Colin Cross1369cdb2017-09-29 17:58:17 -0700415 if err := config.fromEnv(); err != nil {
416 return Config{}, err
417 }
418
Colin Cross1a6acd42020-06-16 17:51:46 -0700419 if Bool(config.productVariables.GcovCoverage) && Bool(config.productVariables.ClangCoverage) {
420 return Config{}, fmt.Errorf("GcovCoverage and ClangCoverage cannot both be set")
421 }
422
423 config.productVariables.Native_coverage = proptools.BoolPtr(
424 Bool(config.productVariables.GcovCoverage) ||
425 Bool(config.productVariables.ClangCoverage))
426
Colin Cross9272ade2016-08-17 15:24:12 -0700427 return Config{config}, nil
Colin Cross3f40fa42015-01-30 17:27:36 -0800428}
429
Colin Cross988414c2020-01-11 01:11:46 +0000430var TestConfigOsFs = map[string][]byte{}
431
Colin Cross98be1bb2019-12-13 20:41:13 -0800432// mockFileSystem replaces all reads with accesses to the provided map of
433// filenames to contents stored as a byte slice.
434func (c *config) mockFileSystem(bp string, fs map[string][]byte) {
435 mockFS := map[string][]byte{}
436
437 if _, exists := mockFS["Android.bp"]; !exists {
438 mockFS["Android.bp"] = []byte(bp)
439 }
440
441 for k, v := range fs {
442 mockFS[k] = v
443 }
444
445 // no module list file specified; find every file named Blueprints or Android.bp
446 pathsToParse := []string{}
447 for candidate := range mockFS {
448 base := filepath.Base(candidate)
449 if base == "Blueprints" || base == "Android.bp" {
450 pathsToParse = append(pathsToParse, candidate)
451 }
452 }
453 if len(pathsToParse) < 1 {
454 panic(fmt.Sprintf("No Blueprint or Android.bp files found in mock filesystem: %v\n", mockFS))
455 }
456 mockFS[blueprint.MockModuleListFile] = []byte(strings.Join(pathsToParse, "\n"))
457
458 c.fs = pathtools.MockFs(mockFS)
459 c.mockBpList = blueprint.MockModuleListFile
460}
461
Colin Cross1369cdb2017-09-29 17:58:17 -0700462func (c *config) fromEnv() error {
Pete Gillin0c2143e2019-05-02 15:32:11 +0100463 switch c.Getenv("EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9") {
Pete Gillin1b3370f2019-10-01 13:57:31 +0100464 case "", "true":
Pete Gillina1c9e9d2019-10-17 14:52:07 +0100465 // Do nothing
Colin Cross1369cdb2017-09-29 17:58:17 -0700466 default:
Pete Gillina1c9e9d2019-10-17 14:52:07 +0100467 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 -0700468 }
469
470 return nil
471}
472
Colin Crosse87040b2017-12-11 15:52:26 -0800473func (c *config) StopBefore() bootstrap.StopBefore {
474 return c.stopBefore
Dan Willemsen218f6562015-07-08 18:13:11 -0700475}
476
Colin Crosse87040b2017-12-11 15:52:26 -0800477func (c *config) SetStopBefore(stopBefore bootstrap.StopBefore) {
478 c.stopBefore = stopBefore
479}
480
481var _ bootstrap.ConfigStopBefore = (*config)(nil)
482
Dan Willemsenc2aa4a92016-05-26 15:13:03 -0700483func (c *config) BlueprintToolLocation() string {
484 return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin")
485}
486
Colin Crosse87040b2017-12-11 15:52:26 -0800487var _ bootstrap.ConfigBlueprintToolLocation = (*config)(nil)
488
Dan Willemsen60e62f02018-11-16 21:05:32 -0800489func (c *config) HostToolPath(ctx PathContext, tool string) Path {
490 return PathForOutput(ctx, "host", c.PrebuiltOS(), "bin", tool)
491}
492
Martin Stjernholm7260d062019-12-09 21:47:14 +0000493func (c *config) HostJNIToolPath(ctx PathContext, path string) Path {
494 ext := ".so"
495 if runtime.GOOS == "darwin" {
496 ext = ".dylib"
497 }
498 return PathForOutput(ctx, "host", c.PrebuiltOS(), "lib64", path+ext)
499}
500
501func (c *config) HostJavaToolPath(ctx PathContext, path string) Path {
502 return PathForOutput(ctx, "host", c.PrebuiltOS(), "framework", path)
503}
504
Dan Willemsen66068722017-05-08 21:15:59 +0000505// HostSystemTool looks for non-hermetic tools from the system we're running on.
506// Generally shouldn't be used, but useful to find the XCode SDK, etc.
507func (c *config) HostSystemTool(name string) string {
508 for _, dir := range filepath.SplitList(c.Getenv("PATH")) {
509 path := filepath.Join(dir, name)
510 if s, err := os.Stat(path); err != nil {
511 continue
512 } else if m := s.Mode(); !s.IsDir() && m&0111 != 0 {
513 return path
514 }
515 }
516 return name
517}
518
Colin Cross3f40fa42015-01-30 17:27:36 -0800519// PrebuiltOS returns the name of the host OS used in prebuilts directories
Colin Cross1332b002015-04-07 17:11:30 -0700520func (c *config) PrebuiltOS() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800521 switch runtime.GOOS {
522 case "linux":
523 return "linux-x86"
524 case "darwin":
525 return "darwin-x86"
526 default:
527 panic("Unknown GOOS")
528 }
529}
530
531// GoRoot returns the path to the root directory of the Go toolchain.
Colin Cross1332b002015-04-07 17:11:30 -0700532func (c *config) GoRoot() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800533 return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS())
534}
535
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700536func (c *config) PrebuiltBuildTool(ctx PathContext, tool string) Path {
537 return PathForSource(ctx, "prebuilts/build-tools", c.PrebuiltOS(), "bin", tool)
538}
539
Colin Cross1332b002015-04-07 17:11:30 -0700540func (c *config) CpPreserveSymlinksFlags() string {
Colin Cross485e5722015-08-27 13:28:01 -0700541 switch runtime.GOOS {
Colin Cross3f40fa42015-01-30 17:27:36 -0800542 case "darwin":
543 return "-R"
544 case "linux":
545 return "-d"
546 default:
547 return ""
548 }
549}
Colin Cross68f55102015-03-25 14:43:57 -0700550
Colin Cross1332b002015-04-07 17:11:30 -0700551func (c *config) Getenv(key string) string {
Colin Cross68f55102015-03-25 14:43:57 -0700552 var val string
553 var exists bool
Colin Crossc1e86a32015-04-15 12:33:28 -0700554 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800555 defer c.envLock.Unlock()
556 if c.envDeps == nil {
557 c.envDeps = make(map[string]string)
558 }
Colin Cross68f55102015-03-25 14:43:57 -0700559 if val, exists = c.envDeps[key]; !exists {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700560 if c.envFrozen {
561 panic("Cannot access new environment variables after envdeps are frozen")
562 }
Colin Cross6ccbc912017-10-10 23:07:38 -0700563 val, _ = c.env[key]
Colin Cross68f55102015-03-25 14:43:57 -0700564 c.envDeps[key] = val
565 }
566 return val
567}
568
Colin Cross99d7c232016-11-23 16:52:04 -0800569func (c *config) GetenvWithDefault(key string, defaultValue string) string {
570 ret := c.Getenv(key)
571 if ret == "" {
572 return defaultValue
573 }
574 return ret
575}
576
577func (c *config) IsEnvTrue(key string) bool {
578 value := c.Getenv(key)
579 return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
580}
581
582func (c *config) IsEnvFalse(key string) bool {
583 value := c.Getenv(key)
584 return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
585}
586
Colin Cross1332b002015-04-07 17:11:30 -0700587func (c *config) EnvDeps() map[string]string {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700588 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800589 defer c.envLock.Unlock()
Dan Willemsene7680ba2015-09-11 17:06:19 -0700590 c.envFrozen = true
Colin Cross68f55102015-03-25 14:43:57 -0700591 return c.envDeps
592}
Colin Cross35cec122015-04-02 14:37:16 -0700593
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800594func (c *config) EmbeddedInMake() bool {
595 return c.inMake
596}
597
Nan Zhang581fd212018-01-10 16:06:12 -0800598func (c *config) BuildId() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800599 return String(c.productVariables.BuildId)
Nan Zhang581fd212018-01-10 16:06:12 -0800600}
601
Colin Cross2a2e0db2020-02-21 16:55:46 -0800602func (c *config) BuildNumberFile(ctx PathContext) Path {
603 return PathForOutput(ctx, String(c.productVariables.BuildNumberFile))
Nan Zhang581fd212018-01-10 16:06:12 -0800604}
605
Colin Cross35cec122015-04-02 14:37:16 -0700606// DeviceName returns the name of the current device target
607// TODO: take an AndroidModuleContext to select the device name for multi-device builds
Colin Cross1332b002015-04-07 17:11:30 -0700608func (c *config) DeviceName() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800609 return *c.productVariables.DeviceName
Colin Cross35cec122015-04-02 14:37:16 -0700610}
611
Anton Hansson53c88442019-03-18 15:53:16 +0000612func (c *config) DeviceResourceOverlays() []string {
613 return c.productVariables.DeviceResourceOverlays
614}
615
616func (c *config) ProductResourceOverlays() []string {
617 return c.productVariables.ProductResourceOverlays
Colin Cross30e076a2015-04-13 13:58:27 -0700618}
619
Colin Crossbfd347d2018-05-09 11:11:35 -0700620func (c *config) PlatformVersionName() string {
621 return String(c.productVariables.Platform_version_name)
622}
623
Dan Albert4f378d72020-07-23 17:32:15 -0700624func (c *config) PlatformSdkVersion() ApiLevel {
625 return uncheckedFinalApiLevel(*c.productVariables.Platform_sdk_version)
Colin Cross30e076a2015-04-13 13:58:27 -0700626}
627
Colin Crossd09b0b62018-04-18 11:06:47 -0700628func (c *config) PlatformSdkCodename() string {
629 return String(c.productVariables.Platform_sdk_codename)
630}
631
Colin Cross092c9da2019-04-02 22:56:43 -0700632func (c *config) PlatformSecurityPatch() string {
633 return String(c.productVariables.Platform_security_patch)
634}
635
636func (c *config) PlatformPreviewSdkVersion() string {
637 return String(c.productVariables.Platform_preview_sdk_version)
638}
639
640func (c *config) PlatformMinSupportedTargetSdkVersion() string {
641 return String(c.productVariables.Platform_min_supported_target_sdk_version)
642}
643
644func (c *config) PlatformBaseOS() string {
645 return String(c.productVariables.Platform_base_os)
646}
647
Dan Albert1a246272020-07-06 14:49:35 -0700648func (c *config) MinSupportedSdkVersion() ApiLevel {
649 return uncheckedFinalApiLevel(16)
650}
651
652func (c *config) FinalApiLevels() []ApiLevel {
653 var levels []ApiLevel
Dan Albert4f378d72020-07-23 17:32:15 -0700654 for i := 1; i <= c.PlatformSdkVersion().FinalOrFutureInt(); i++ {
Dan Albert1a246272020-07-06 14:49:35 -0700655 levels = append(levels, uncheckedFinalApiLevel(i))
656 }
657 return levels
658}
659
660func (c *config) PreviewApiLevels() []ApiLevel {
661 var levels []ApiLevel
662 for i, codename := range c.PlatformVersionActiveCodenames() {
663 levels = append(levels, ApiLevel{
664 value: codename,
665 number: i,
666 isPreview: true,
667 })
668 }
669 return levels
670}
671
672func (c *config) AllSupportedApiLevels() []ApiLevel {
673 var levels []ApiLevel
674 levels = append(levels, c.FinalApiLevels()...)
675 return append(levels, c.PreviewApiLevels()...)
Dan Albertf5415d72017-08-17 16:19:59 -0700676}
677
Dan Albert4f378d72020-07-23 17:32:15 -0700678func (c *config) DefaultAppTargetSdk(ctx EarlyModuleContext) ApiLevel {
Colin Crossd09b0b62018-04-18 11:06:47 -0700679 if Bool(c.productVariables.Platform_sdk_final) {
680 return c.PlatformSdkVersion()
681 } else {
Dan Albert4f378d72020-07-23 17:32:15 -0700682 codename := c.PlatformSdkCodename()
683 if codename == "" {
684 return NoneApiLevel
685 }
686 if codename == "REL" {
687 panic("Platform_sdk_codename should not be REL when Platform_sdk_final is true")
688 }
689 return ApiLevelOrPanic(ctx, codename)
Colin Crossd09b0b62018-04-18 11:06:47 -0700690 }
691}
692
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800693func (c *config) AppsDefaultVersionName() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800694 return String(c.productVariables.AppsDefaultVersionName)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800695}
696
Dan Albert31384de2017-07-28 12:39:46 -0700697// Codenames that are active in the current lunch target.
698func (c *config) PlatformVersionActiveCodenames() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800699 return c.productVariables.Platform_version_active_codenames
Dan Albert31384de2017-07-28 12:39:46 -0700700}
701
Colin Crossface4e42017-10-30 17:32:15 -0700702func (c *config) ProductAAPTConfig() []string {
Colin Crossa74ca042019-01-31 14:31:51 -0800703 return c.productVariables.AAPTConfig
Colin Cross30e076a2015-04-13 13:58:27 -0700704}
705
Colin Crossface4e42017-10-30 17:32:15 -0700706func (c *config) ProductAAPTPreferredConfig() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800707 return String(c.productVariables.AAPTPreferredConfig)
Colin Cross30e076a2015-04-13 13:58:27 -0700708}
709
Colin Crossface4e42017-10-30 17:32:15 -0700710func (c *config) ProductAAPTCharacteristics() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800711 return String(c.productVariables.AAPTCharacteristics)
Colin Crossface4e42017-10-30 17:32:15 -0700712}
713
714func (c *config) ProductAAPTPrebuiltDPI() []string {
Colin Crossa74ca042019-01-31 14:31:51 -0800715 return c.productVariables.AAPTPrebuiltDPI
Colin Cross30e076a2015-04-13 13:58:27 -0700716}
717
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700718func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800719 defaultCert := String(c.productVariables.DefaultAppCertificate)
Colin Cross61ae0b72017-12-01 17:16:02 -0800720 if defaultCert != "" {
721 return PathForSource(ctx, filepath.Dir(defaultCert))
722 } else {
Dan Willemsen412160e2019-04-09 21:36:26 -0700723 return PathForSource(ctx, "build/make/target/product/security")
Colin Cross61ae0b72017-12-01 17:16:02 -0800724 }
Colin Cross30e076a2015-04-13 13:58:27 -0700725}
726
Colin Crosse1731a52017-12-14 11:22:55 -0800727func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800728 defaultCert := String(c.productVariables.DefaultAppCertificate)
Colin Cross61ae0b72017-12-01 17:16:02 -0800729 if defaultCert != "" {
Colin Crosse1731a52017-12-14 11:22:55 -0800730 return PathForSource(ctx, defaultCert+".x509.pem"), PathForSource(ctx, defaultCert+".pk8")
Colin Cross61ae0b72017-12-01 17:16:02 -0800731 } else {
Colin Crosse1731a52017-12-14 11:22:55 -0800732 defaultDir := c.DefaultAppCertificateDir(ctx)
733 return defaultDir.Join(ctx, "testkey.x509.pem"), defaultDir.Join(ctx, "testkey.pk8")
Colin Cross61ae0b72017-12-01 17:16:02 -0800734 }
Colin Cross30e076a2015-04-13 13:58:27 -0700735}
Colin Cross6ff51382015-12-17 16:39:19 -0800736
Jiyong Park9335a262018-12-24 11:31:58 +0900737func (c *config) ApexKeyDir(ctx ModuleContext) SourcePath {
738 // TODO(b/121224311): define another variable such as TARGET_APEX_KEY_OVERRIDE
739 defaultCert := String(c.productVariables.DefaultAppCertificate)
Dan Willemsen412160e2019-04-09 21:36:26 -0700740 if defaultCert == "" || filepath.Dir(defaultCert) == "build/make/target/product/security" {
Jiyong Park9335a262018-12-24 11:31:58 +0900741 // When defaultCert is unset or is set to the testkeys path, use the APEX keys
742 // that is under the module dir
Colin Cross07e51612019-03-05 12:46:40 -0800743 return pathForModuleSrc(ctx)
Jiyong Park9335a262018-12-24 11:31:58 +0900744 } else {
745 // If not, APEX keys are under the specified directory
746 return PathForSource(ctx, filepath.Dir(defaultCert))
747 }
748}
749
Colin Cross6ff51382015-12-17 16:39:19 -0800750func (c *config) AllowMissingDependencies() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800751 return Bool(c.productVariables.Allow_missing_dependencies)
Colin Cross6ff51382015-12-17 16:39:19 -0800752}
Dan Willemsen322acaf2016-01-12 23:07:05 -0800753
Jeongik Cha816a23a2020-07-08 01:09:23 +0900754// Returns true if a full platform source tree cannot be assumed.
Colin Crossfc3674a2017-09-18 17:41:52 -0700755func (c *config) UnbundledBuild() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800756 return Bool(c.productVariables.Unbundled_build)
Colin Crossfc3674a2017-09-18 17:41:52 -0700757}
758
Martin Stjernholmfd9eb4b2020-06-17 01:13:15 +0100759// Returns true if building apps that aren't bundled with the platform.
760// UnbundledBuild() is always true when this is true.
761func (c *config) UnbundledBuildApps() bool {
762 return Bool(c.productVariables.Unbundled_build_apps)
763}
764
Jeongik Cha816a23a2020-07-08 01:09:23 +0900765// Returns true if building modules against prebuilt SDKs.
766func (c *config) AlwaysUsePrebuiltSdks() bool {
767 return Bool(c.productVariables.Always_use_prebuilt_sdks)
Colin Cross1f367bf2018-12-18 22:46:24 -0800768}
769
Doug Horn21b94272019-01-16 12:06:11 -0800770func (c *config) Fuchsia() bool {
771 return Bool(c.productVariables.Fuchsia)
772}
773
Colin Cross126a25c2017-10-31 13:55:34 -0700774func (c *config) MinimizeJavaDebugInfo() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800775 return Bool(c.productVariables.MinimizeJavaDebugInfo) && !Bool(c.productVariables.Eng)
Colin Cross126a25c2017-10-31 13:55:34 -0700776}
777
Colin Crossed064c02018-09-05 16:28:13 -0700778func (c *config) Debuggable() bool {
779 return Bool(c.productVariables.Debuggable)
780}
781
Jaewoong Jung1d6eb682018-11-29 15:08:44 -0800782func (c *config) Eng() bool {
783 return Bool(c.productVariables.Eng)
784}
785
Jiyong Park8d52f862018-07-07 18:02:07 +0900786func (c *config) DevicePrimaryArchType() ArchType {
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700787 return c.Targets[Android][0].Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +0900788}
789
Colin Cross893d8162017-04-26 17:34:03 -0700790func (c *config) SkipMegaDeviceInstall(path string) bool {
791 return Bool(c.Mega_device) &&
792 strings.HasPrefix(path, filepath.Join(c.buildDir, "target", "product"))
Dan Willemsen322acaf2016-01-12 23:07:05 -0800793}
Colin Cross16b23492016-01-06 14:41:07 -0800794
795func (c *config) SanitizeHost() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800796 return append([]string(nil), c.productVariables.SanitizeHost...)
Colin Cross16b23492016-01-06 14:41:07 -0800797}
798
799func (c *config) SanitizeDevice() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800800 return append([]string(nil), c.productVariables.SanitizeDevice...)
Colin Cross23ae82a2016-11-02 14:34:39 -0700801}
802
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700803func (c *config) SanitizeDeviceDiag() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800804 return append([]string(nil), c.productVariables.SanitizeDeviceDiag...)
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700805}
806
Colin Cross23ae82a2016-11-02 14:34:39 -0700807func (c *config) SanitizeDeviceArch() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800808 return append([]string(nil), c.productVariables.SanitizeDeviceArch...)
Colin Cross16b23492016-01-06 14:41:07 -0800809}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700810
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800811func (c *config) EnableCFI() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800812 if c.productVariables.EnableCFI == nil {
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -0800813 return true
814 } else {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800815 return *c.productVariables.EnableCFI
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -0800816 }
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800817}
818
Kostya Kortchinskyd5275c82019-02-01 08:42:56 -0800819func (c *config) DisableScudo() bool {
820 return Bool(c.productVariables.DisableScudo)
821}
822
Colin Crossa1ad8d12016-06-01 17:09:44 -0700823func (c *config) Android64() bool {
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700824 for _, t := range c.Targets[Android] {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700825 if t.Arch.ArchType.Multilib == "lib64" {
826 return true
827 }
828 }
829
830 return false
831}
Colin Cross9272ade2016-08-17 15:24:12 -0700832
Colin Cross9d45bb72016-08-29 16:14:13 -0700833func (c *config) UseGoma() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800834 return Bool(c.productVariables.UseGoma)
Colin Cross9d45bb72016-08-29 16:14:13 -0700835}
836
Ramy Medhatbbf25672019-07-17 12:30:04 +0000837func (c *config) UseRBE() bool {
838 return Bool(c.productVariables.UseRBE)
839}
840
Ramy Medhat8ea054a2020-01-27 14:19:44 -0500841func (c *config) UseRBEJAVAC() bool {
842 return Bool(c.productVariables.UseRBEJAVAC)
843}
844
845func (c *config) UseRBER8() bool {
846 return Bool(c.productVariables.UseRBER8)
847}
848
849func (c *config) UseRBED8() bool {
850 return Bool(c.productVariables.UseRBED8)
851}
852
Colin Cross8b8bec32019-11-15 13:18:43 -0800853func (c *config) UseRemoteBuild() bool {
854 return c.UseGoma() || c.UseRBE()
855}
856
Colin Cross66548102018-06-19 22:47:35 -0700857func (c *config) RunErrorProne() bool {
858 return c.IsEnvTrue("RUN_ERROR_PRONE")
859}
860
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800861func (c *config) XrefCorpusName() string {
862 return c.Getenv("XREF_CORPUS")
863}
864
Sasha Smundak6c2d4f92020-01-09 17:34:23 -0800865// Returns Compilation Unit encoding to use. Can be 'json' (default), 'proto' or 'all'.
866func (c *config) XrefCuEncoding() string {
867 if enc := c.Getenv("KYTHE_KZIP_ENCODING"); enc != "" {
868 return enc
869 }
870 return "json"
871}
872
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800873func (c *config) EmitXrefRules() bool {
874 return c.XrefCorpusName() != ""
875}
876
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700877func (c *config) ClangTidy() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800878 return Bool(c.productVariables.ClangTidy)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700879}
880
881func (c *config) TidyChecks() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800882 if c.productVariables.TidyChecks == nil {
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700883 return ""
884 }
Dan Willemsen45133ac2018-03-09 21:22:06 -0800885 return *c.productVariables.TidyChecks
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700886}
887
Colin Cross0f4e0d62016-07-27 10:56:55 -0700888func (c *config) LibartImgHostBaseAddress() string {
889 return "0x60000000"
890}
891
892func (c *config) LibartImgDeviceBaseAddress() string {
Elliott Hughesda3a0712020-03-06 16:55:28 -0800893 return "0x70000000"
Colin Cross0f4e0d62016-07-27 10:56:55 -0700894}
895
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800896func (c *config) ArtUseReadBarrier() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800897 return Bool(c.productVariables.ArtUseReadBarrier)
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800898}
899
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700900func (c *config) EnforceRROForModule(name string) bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800901 enforceList := c.productVariables.EnforceRROTargets
Jeongik Chab9b13272020-03-09 12:37:05 +0900902 // TODO(b/150820813) Some modules depend on static overlay, remove this after eliminating the dependency.
903 exemptedList := c.productVariables.EnforceRROExemptedTargets
Roland Levillainf6cc2612020-07-09 16:58:14 +0100904 if len(exemptedList) > 0 {
Jeongik Chab9b13272020-03-09 12:37:05 +0900905 if InList(name, exemptedList) {
906 return false
907 }
908 }
Roland Levillainf6cc2612020-07-09 16:58:14 +0100909 if len(enforceList) > 0 {
Yo Chiang4ebd06a2019-10-01 13:13:41 +0800910 if InList("*", enforceList) {
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700911 return true
912 }
Colin Crossa74ca042019-01-31 14:31:51 -0800913 return InList(name, enforceList)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700914 }
915 return false
916}
917
918func (c *config) EnforceRROExcludedOverlay(path string) bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800919 excluded := c.productVariables.EnforceRROExcludedOverlays
Roland Levillainf6cc2612020-07-09 16:58:14 +0100920 if len(excluded) > 0 {
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800921 return HasAnyPrefix(path, excluded)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700922 }
923 return false
924}
925
926func (c *config) ExportedNamespaces() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800927 return append([]string(nil), c.productVariables.NamespacesToExport...)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700928}
929
930func (c *config) HostStaticBinaries() bool {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800931 return Bool(c.productVariables.HostStaticBinaries)
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700932}
933
Colin Cross5a0dcd52018-10-05 14:20:06 -0700934func (c *config) UncompressPrivAppDex() bool {
935 return Bool(c.productVariables.UncompressPrivAppDex)
936}
937
938func (c *config) ModulesLoadedByPrivilegedModules() []string {
939 return c.productVariables.ModulesLoadedByPrivilegedModules
940}
941
Colin Cross988414c2020-01-11 01:11:46 +0000942func (c *config) DexpreoptGlobalConfig(ctx PathContext) ([]byte, error) {
943 if c.productVariables.DexpreoptGlobalConfig == nil {
944 return nil, nil
945 }
946 path := absolutePath(*c.productVariables.DexpreoptGlobalConfig)
947 ctx.AddNinjaFileDeps(path)
948 return ioutil.ReadFile(path)
Colin Cross43f08db2018-11-12 10:13:39 -0800949}
950
David Brazdil91b4e3e2019-01-23 21:04:05 +0000951func (c *config) FrameworksBaseDirExists(ctx PathContext) bool {
952 return ExistentPathForSource(ctx, "frameworks", "base").Valid()
953}
954
Inseob Kimae553032019-05-14 18:52:49 +0900955func (c *config) VndkSnapshotBuildArtifacts() bool {
956 return Bool(c.productVariables.VndkSnapshotBuildArtifacts)
957}
958
Colin Cross3b19f5d2019-09-17 14:45:31 -0700959func (c *config) HasMultilibConflict(arch ArchType) bool {
960 return c.multilibConflicts[arch]
961}
962
Colin Cross9272ade2016-08-17 15:24:12 -0700963func (c *deviceConfig) Arches() []Arch {
964 var arches []Arch
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700965 for _, target := range c.config.Targets[Android] {
Colin Cross9272ade2016-08-17 15:24:12 -0700966 arches = append(arches, target.Arch)
967 }
968 return arches
969}
Dan Willemsend2ede872016-11-18 14:54:24 -0800970
Jayant Chowdhary34ce67d2018-03-08 11:00:50 -0800971func (c *deviceConfig) BinderBitness() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800972 is32BitBinder := c.config.productVariables.Binder32bit
Jayant Chowdhary34ce67d2018-03-08 11:00:50 -0800973 if is32BitBinder != nil && *is32BitBinder {
974 return "32"
975 }
976 return "64"
977}
978
Dan Willemsen4353bc42016-12-05 17:16:02 -0800979func (c *deviceConfig) VendorPath() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800980 if c.config.productVariables.VendorPath != nil {
981 return *c.config.productVariables.VendorPath
Dan Willemsen4353bc42016-12-05 17:16:02 -0800982 }
983 return "vendor"
984}
985
Justin Yun71549282017-11-17 12:10:28 +0900986func (c *deviceConfig) VndkVersion() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800987 return String(c.config.productVariables.DeviceVndkVersion)
Justin Yun71549282017-11-17 12:10:28 +0900988}
989
Jeongik Cha219141c2020-08-06 23:00:37 +0900990func (c *deviceConfig) CurrentApiLevelForVendorModules() string {
991 return StringDefault(c.config.productVariables.DeviceCurrentApiLevelForVendorModules, "current")
992}
993
Justin Yun8fe12122017-12-07 17:18:15 +0900994func (c *deviceConfig) PlatformVndkVersion() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -0800995 return String(c.config.productVariables.Platform_vndk_version)
Justin Yun8fe12122017-12-07 17:18:15 +0900996}
997
Justin Yun5f7f7e82019-11-18 19:52:14 +0900998func (c *deviceConfig) ProductVndkVersion() string {
999 return String(c.config.productVariables.ProductVndkVersion)
1000}
1001
Justin Yun71549282017-11-17 12:10:28 +09001002func (c *deviceConfig) ExtraVndkVersions() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001003 return c.config.productVariables.ExtraVndkVersions
Dan Willemsend2ede872016-11-18 14:54:24 -08001004}
Jack He8cc71432016-12-08 15:45:07 -08001005
Vic Yangefd249e2018-11-12 20:19:56 -08001006func (c *deviceConfig) VndkUseCoreVariant() bool {
1007 return Bool(c.config.productVariables.VndkUseCoreVariant)
1008}
1009
Jiyong Park1a5d7b12018-01-15 15:05:10 +09001010func (c *deviceConfig) SystemSdkVersions() []string {
Colin Crossa74ca042019-01-31 14:31:51 -08001011 return c.config.productVariables.DeviceSystemSdkVersions
Jiyong Park1a5d7b12018-01-15 15:05:10 +09001012}
1013
1014func (c *deviceConfig) PlatformSystemSdkVersions() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001015 return c.config.productVariables.Platform_systemsdk_versions
Jiyong Park1a5d7b12018-01-15 15:05:10 +09001016}
1017
Jiyong Park2db76922017-11-08 16:03:48 +09001018func (c *deviceConfig) OdmPath() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001019 if c.config.productVariables.OdmPath != nil {
1020 return *c.config.productVariables.OdmPath
Jiyong Park2db76922017-11-08 16:03:48 +09001021 }
1022 return "odm"
1023}
1024
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +09001025func (c *deviceConfig) ProductPath() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001026 if c.config.productVariables.ProductPath != nil {
1027 return *c.config.productVariables.ProductPath
Jiyong Park2db76922017-11-08 16:03:48 +09001028 }
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +09001029 return "product"
Jiyong Park2db76922017-11-08 16:03:48 +09001030}
1031
Justin Yund5f6c822019-06-25 16:47:17 +09001032func (c *deviceConfig) SystemExtPath() string {
1033 if c.config.productVariables.SystemExtPath != nil {
1034 return *c.config.productVariables.SystemExtPath
Dario Frenifd05a742018-05-29 13:28:54 +01001035 }
Justin Yund5f6c822019-06-25 16:47:17 +09001036 return "system_ext"
Dario Frenifd05a742018-05-29 13:28:54 +01001037}
1038
Jack He8cc71432016-12-08 15:45:07 -08001039func (c *deviceConfig) BtConfigIncludeDir() string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001040 return String(c.config.productVariables.BtConfigIncludeDir)
Jack He8cc71432016-12-08 15:45:07 -08001041}
Dan Willemsen581341d2017-02-09 16:16:31 -08001042
Jiyong Parkd773eb32017-07-03 13:18:12 +09001043func (c *deviceConfig) DeviceKernelHeaderDirs() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001044 return c.config.productVariables.DeviceKernelHeaders
Jiyong Parkd773eb32017-07-03 13:18:12 +09001045}
1046
Yi Kongceb5b762020-03-20 15:22:27 +08001047func (c *deviceConfig) SamplingPGO() bool {
1048 return Bool(c.config.productVariables.SamplingPGO)
1049}
1050
Roland Levillainada12702020-06-09 13:07:36 +01001051// JavaCoverageEnabledForPath returns whether Java code coverage is enabled for
1052// path. Coverage is enabled by default when the product variable
1053// JavaCoveragePaths is empty. If JavaCoveragePaths is not empty, coverage is
1054// enabled for any path which is part of this variable (and not part of the
1055// JavaCoverageExcludePaths product variable). Value "*" in JavaCoveragePaths
1056// represents any path.
1057func (c *deviceConfig) JavaCoverageEnabledForPath(path string) bool {
1058 coverage := false
Chris Gross2f748692020-06-24 20:36:59 +00001059 if len(c.config.productVariables.JavaCoveragePaths) == 0 ||
Roland Levillainada12702020-06-09 13:07:36 +01001060 InList("*", c.config.productVariables.JavaCoveragePaths) ||
1061 HasAnyPrefix(path, c.config.productVariables.JavaCoveragePaths) {
1062 coverage = true
1063 }
Roland Levillainf6cc2612020-07-09 16:58:14 +01001064 if coverage && len(c.config.productVariables.JavaCoverageExcludePaths) > 0 {
Roland Levillainada12702020-06-09 13:07:36 +01001065 if HasAnyPrefix(path, c.config.productVariables.JavaCoverageExcludePaths) {
1066 coverage = false
1067 }
1068 }
1069 return coverage
1070}
1071
Colin Cross1a6acd42020-06-16 17:51:46 -07001072// Returns true if gcov or clang coverage is enabled.
Dan Willemsen581341d2017-02-09 16:16:31 -08001073func (c *deviceConfig) NativeCoverageEnabled() bool {
Colin Cross1a6acd42020-06-16 17:51:46 -07001074 return Bool(c.config.productVariables.GcovCoverage) ||
1075 Bool(c.config.productVariables.ClangCoverage)
Dan Willemsen581341d2017-02-09 16:16:31 -08001076}
1077
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001078func (c *deviceConfig) ClangCoverageEnabled() bool {
1079 return Bool(c.config.productVariables.ClangCoverage)
1080}
1081
Colin Cross1a6acd42020-06-16 17:51:46 -07001082func (c *deviceConfig) GcovCoverageEnabled() bool {
1083 return Bool(c.config.productVariables.GcovCoverage)
1084}
1085
Roland Levillain4f5297b2020-06-09 12:44:06 +01001086// NativeCoverageEnabledForPath returns whether (GCOV- or Clang-based) native
1087// code coverage is enabled for path. By default, coverage is not enabled for a
1088// given path unless it is part of the NativeCoveragePaths product variable (and
1089// not part of the NativeCoverageExcludePaths product variable). Value "*" in
1090// NativeCoveragePaths represents any path.
1091func (c *deviceConfig) NativeCoverageEnabledForPath(path string) bool {
Ryan Campbell469a18a2017-02-27 09:01:54 -08001092 coverage := false
Roland Levillainf6cc2612020-07-09 16:58:14 +01001093 if len(c.config.productVariables.NativeCoveragePaths) > 0 {
Roland Levillain4f5297b2020-06-09 12:44:06 +01001094 if InList("*", c.config.productVariables.NativeCoveragePaths) || HasAnyPrefix(path, c.config.productVariables.NativeCoveragePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -07001095 coverage = true
Dan Willemsen581341d2017-02-09 16:16:31 -08001096 }
1097 }
Roland Levillainf6cc2612020-07-09 16:58:14 +01001098 if coverage && len(c.config.productVariables.NativeCoverageExcludePaths) > 0 {
Roland Levillain4f5297b2020-06-09 12:44:06 +01001099 if HasAnyPrefix(path, c.config.productVariables.NativeCoverageExcludePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -07001100 coverage = false
Ryan Campbell469a18a2017-02-27 09:01:54 -08001101 }
1102 }
1103 return coverage
Dan Willemsen581341d2017-02-09 16:16:31 -08001104}
Ivan Lozano5f595532017-07-13 14:46:05 -07001105
Pirama Arumuga Nainar49540802018-01-29 23:11:42 -08001106func (c *deviceConfig) PgoAdditionalProfileDirs() []string {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001107 return c.config.productVariables.PgoAdditionalProfileDirs
Pirama Arumuga Nainar49540802018-01-29 23:11:42 -08001108}
1109
Tri Vo35a51432018-03-25 20:00:00 -07001110func (c *deviceConfig) VendorSepolicyDirs() []string {
1111 return c.config.productVariables.BoardVendorSepolicyDirs
1112}
1113
1114func (c *deviceConfig) OdmSepolicyDirs() []string {
1115 return c.config.productVariables.BoardOdmSepolicyDirs
1116}
1117
Tri Vof544fe32018-05-20 14:34:48 -07001118func (c *deviceConfig) PlatPublicSepolicyDirs() []string {
1119 return c.config.productVariables.BoardPlatPublicSepolicyDirs
Tri Vo35a51432018-03-25 20:00:00 -07001120}
1121
Tri Vof544fe32018-05-20 14:34:48 -07001122func (c *deviceConfig) PlatPrivateSepolicyDirs() []string {
1123 return c.config.productVariables.BoardPlatPrivateSepolicyDirs
Tri Vo35a51432018-03-25 20:00:00 -07001124}
1125
Inseob Kim0866b002019-04-15 20:21:29 +09001126func (c *deviceConfig) SepolicyM4Defs() []string {
1127 return c.config.productVariables.BoardSepolicyM4Defs
1128}
1129
Jiyong Park7f67f482019-01-05 12:57:48 +09001130func (c *deviceConfig) OverrideManifestPackageNameFor(name string) (manifestName string, overridden bool) {
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001131 return findOverrideValue(c.config.productVariables.ManifestPackageNameOverrides, name,
1132 "invalid override rule %q in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES should be <module_name>:<manifest_name>")
1133}
1134
1135func (c *deviceConfig) OverrideCertificateFor(name string) (certificatePath string, overridden bool) {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001136 return findOverrideValue(c.config.productVariables.CertificateOverrides, name,
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001137 "invalid override rule %q in PRODUCT_CERTIFICATE_OVERRIDES should be <module_name>:<certificate_module_name>")
1138}
1139
Jaewoong Jung9d22a912019-01-23 16:27:47 -08001140func (c *deviceConfig) OverridePackageNameFor(name string) string {
1141 newName, overridden := findOverrideValue(
1142 c.config.productVariables.PackageNameOverrides,
1143 name,
1144 "invalid override rule %q in PRODUCT_PACKAGE_NAME_OVERRIDES should be <module_name>:<package_name>")
1145 if overridden {
1146 return newName
1147 }
1148 return name
1149}
1150
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001151func findOverrideValue(overrides []string, name string, errorMsg string) (newValue string, overridden bool) {
Jiyong Park7f67f482019-01-05 12:57:48 +09001152 if overrides == nil || len(overrides) == 0 {
1153 return "", false
1154 }
1155 for _, o := range overrides {
1156 split := strings.Split(o, ":")
1157 if len(split) != 2 {
1158 // This shouldn't happen as this is first checked in make, but just in case.
Jaewoong Jung2ad817c2019-01-18 14:27:16 -08001159 panic(fmt.Errorf(errorMsg, o))
Jiyong Park7f67f482019-01-05 12:57:48 +09001160 }
1161 if matchPattern(split[0], name) {
1162 return substPattern(split[0], split[1], name), true
1163 }
1164 }
1165 return "", false
1166}
1167
Ivan Lozano5f595532017-07-13 14:46:05 -07001168func (c *config) IntegerOverflowDisabledForPath(path string) bool {
Roland Levillainf6cc2612020-07-09 16:58:14 +01001169 if len(c.productVariables.IntegerOverflowExcludePaths) == 0 {
Ivan Lozano5f595532017-07-13 14:46:05 -07001170 return false
1171 }
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001172 return HasAnyPrefix(path, c.productVariables.IntegerOverflowExcludePaths)
Ivan Lozano5f595532017-07-13 14:46:05 -07001173}
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001174
1175func (c *config) CFIDisabledForPath(path string) bool {
Roland Levillainf6cc2612020-07-09 16:58:14 +01001176 if len(c.productVariables.CFIExcludePaths) == 0 {
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001177 return false
1178 }
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001179 return HasAnyPrefix(path, c.productVariables.CFIExcludePaths)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001180}
1181
1182func (c *config) CFIEnabledForPath(path string) bool {
Roland Levillainf6cc2612020-07-09 16:58:14 +01001183 if len(c.productVariables.CFIIncludePaths) == 0 {
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001184 return false
1185 }
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001186 return HasAnyPrefix(path, c.productVariables.CFIIncludePaths)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -07001187}
Colin Crosse15ddaf2017-12-04 11:24:31 -08001188
Dan Willemsen0fe78662018-03-26 12:41:18 -07001189func (c *config) VendorConfig(name string) VendorConfig {
Colin Cross9d34f352019-11-22 16:03:51 -08001190 return soongconfig.Config(c.productVariables.VendorVars[name])
Dan Willemsen0fe78662018-03-26 12:41:18 -07001191}
1192
Colin Cross395f2cf2018-10-24 16:10:32 -07001193func (c *config) NdkAbis() bool {
1194 return Bool(c.productVariables.Ndk_abis)
1195}
1196
Martin Stjernholmc1ecc432019-11-15 15:00:31 +00001197func (c *config) AmlAbis() bool {
1198 return Bool(c.productVariables.Aml_abis)
1199}
1200
Dan Albert23d37e02018-11-28 08:30:10 -08001201func (c *config) ExcludeDraftNdkApis() bool {
1202 return Bool(c.productVariables.Exclude_draft_ndk_apis)
1203}
1204
Jiyong Park8fd61922018-11-08 02:50:25 +09001205func (c *config) FlattenApex() bool {
Roland Levillaina3863212019-08-12 19:56:16 +01001206 return Bool(c.productVariables.Flatten_apex)
Jiyong Park8fd61922018-11-08 02:50:25 +09001207}
1208
Jeongik Chac9464142019-01-07 12:07:27 +09001209func (c *config) EnforceSystemCertificate() bool {
1210 return Bool(c.productVariables.EnforceSystemCertificate)
1211}
1212
Colin Cross440e0d02020-06-11 11:32:11 -07001213func (c *config) EnforceSystemCertificateAllowList() []string {
1214 return c.productVariables.EnforceSystemCertificateAllowList
Jeongik Chac9464142019-01-07 12:07:27 +09001215}
1216
Jeongik Cha2cc570d2019-10-29 15:44:45 +09001217func (c *config) EnforceProductPartitionInterface() bool {
1218 return Bool(c.productVariables.EnforceProductPartitionInterface)
1219}
1220
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001221func (c *config) InstallExtraFlattenedApexes() bool {
1222 return Bool(c.productVariables.InstallExtraFlattenedApexes)
1223}
1224
Colin Crossf24a22a2019-01-31 14:12:44 -08001225func (c *config) ProductHiddenAPIStubs() []string {
1226 return c.productVariables.ProductHiddenAPIStubs
Colin Cross8faf8fc2019-01-16 15:15:52 -08001227}
1228
Colin Crossf24a22a2019-01-31 14:12:44 -08001229func (c *config) ProductHiddenAPIStubsSystem() []string {
1230 return c.productVariables.ProductHiddenAPIStubsSystem
Colin Cross8faf8fc2019-01-16 15:15:52 -08001231}
1232
Colin Crossf24a22a2019-01-31 14:12:44 -08001233func (c *config) ProductHiddenAPIStubsTest() []string {
1234 return c.productVariables.ProductHiddenAPIStubsTest
Colin Cross8faf8fc2019-01-16 15:15:52 -08001235}
Dan Willemsen71c74602019-04-10 12:27:35 -07001236
Dan Willemsen54879d12019-04-18 10:08:46 -07001237func (c *deviceConfig) TargetFSConfigGen() []string {
Dan Willemsen71c74602019-04-10 12:27:35 -07001238 return c.config.productVariables.TargetFSConfigGen
1239}
Inseob Kim0866b002019-04-15 20:21:29 +09001240
1241func (c *config) ProductPublicSepolicyDirs() []string {
1242 return c.productVariables.ProductPublicSepolicyDirs
1243}
1244
1245func (c *config) ProductPrivateSepolicyDirs() []string {
1246 return c.productVariables.ProductPrivateSepolicyDirs
1247}
1248
1249func (c *config) ProductCompatibleProperty() bool {
1250 return Bool(c.productVariables.ProductCompatibleProperty)
1251}
Inseob Kim1f086e22019-05-09 13:29:15 +09001252
Colin Cross50ddcc42019-05-16 12:28:22 -07001253func (c *config) MissingUsesLibraries() []string {
1254 return c.productVariables.MissingUsesLibraries
1255}
1256
Inseob Kim1f086e22019-05-09 13:29:15 +09001257func (c *deviceConfig) DeviceArch() string {
1258 return String(c.config.productVariables.DeviceArch)
1259}
1260
1261func (c *deviceConfig) DeviceArchVariant() string {
1262 return String(c.config.productVariables.DeviceArchVariant)
1263}
1264
1265func (c *deviceConfig) DeviceSecondaryArch() string {
1266 return String(c.config.productVariables.DeviceSecondaryArch)
1267}
1268
1269func (c *deviceConfig) DeviceSecondaryArchVariant() string {
1270 return String(c.config.productVariables.DeviceSecondaryArchVariant)
1271}
Yifan Hong82db7352020-01-21 16:12:26 -08001272
1273func (c *deviceConfig) BoardUsesRecoveryAsBoot() bool {
1274 return Bool(c.config.productVariables.BoardUsesRecoveryAsBoot)
1275}
Yifan Hong97365ee2020-07-29 09:51:57 -07001276
1277func (c *deviceConfig) BoardKernelBinaries() []string {
1278 return c.config.productVariables.BoardKernelBinaries
1279}
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001280
Yifan Hong42bef8d2020-08-05 14:36:09 -07001281func (c *deviceConfig) BoardKernelModuleInterfaceVersions() []string {
1282 return c.config.productVariables.BoardKernelModuleInterfaceVersions
1283}
1284
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001285// The ConfiguredJarList struct provides methods for handling a list of (apex, jar) pairs.
1286// Such lists are used in the build system for things like bootclasspath jars or system server jars.
1287// The apex part is either an apex name, or a special names "platform" or "system_ext". Jar is a
1288// module name. The pairs come from Make product variables as a list of colon-separated strings.
1289//
1290// Examples:
1291// - "com.android.art:core-oj"
1292// - "platform:framework"
1293// - "system_ext:foo"
1294//
1295type ConfiguredJarList struct {
1296 apexes []string // A list of apex components.
1297 jars []string // A list of jar components.
1298}
1299
1300// The length of the list.
1301func (l *ConfiguredJarList) Len() int {
1302 return len(l.jars)
1303}
1304
1305// Apex component of idx-th pair on the list.
1306func (l *ConfiguredJarList) apex(idx int) string {
1307 return l.apexes[idx]
1308}
1309
1310// Jar component of idx-th pair on the list.
1311func (l *ConfiguredJarList) Jar(idx int) string {
1312 return l.jars[idx]
1313}
1314
1315// If the list contains a pair with the given jar.
1316func (l *ConfiguredJarList) ContainsJar(jar string) bool {
1317 return InList(jar, l.jars)
1318}
1319
1320// If the list contains the given (apex, jar) pair.
1321func (l *ConfiguredJarList) containsApexJarPair(apex, jar string) bool {
1322 for i := 0; i < l.Len(); i++ {
1323 if apex == l.apex(i) && jar == l.Jar(i) {
1324 return true
1325 }
1326 }
1327 return false
1328}
1329
1330// Index of the first pair with the given jar on the list, or -1 if none.
1331func (l *ConfiguredJarList) IndexOfJar(jar string) int {
1332 return IndexList(jar, l.jars)
1333}
1334
1335// Append an (apex, jar) pair to the list.
1336func (l *ConfiguredJarList) Append(apex string, jar string) {
1337 l.apexes = append(l.apexes, apex)
1338 l.jars = append(l.jars, jar)
1339}
1340
1341// Filter out sublist.
1342func (l *ConfiguredJarList) RemoveList(list ConfiguredJarList) {
1343 apexes := make([]string, 0, l.Len())
1344 jars := make([]string, 0, l.Len())
1345
1346 for i, jar := range l.jars {
1347 apex := l.apex(i)
1348 if !list.containsApexJarPair(apex, jar) {
1349 apexes = append(apexes, apex)
1350 jars = append(jars, jar)
1351 }
1352 }
1353
1354 l.apexes = apexes
1355 l.jars = jars
1356}
1357
1358// A copy of itself.
1359func (l *ConfiguredJarList) CopyOf() ConfiguredJarList {
1360 return ConfiguredJarList{CopyOf(l.apexes), CopyOf(l.jars)}
1361}
1362
1363// A copy of the list of strings containing jar components.
1364func (l *ConfiguredJarList) CopyOfJars() []string {
1365 return CopyOf(l.jars)
1366}
1367
1368// A copy of the list of strings with colon-separated (apex, jar) pairs.
1369func (l *ConfiguredJarList) CopyOfApexJarPairs() []string {
1370 pairs := make([]string, 0, l.Len())
1371
1372 for i, jar := range l.jars {
1373 apex := l.apex(i)
1374 pairs = append(pairs, apex+":"+jar)
1375 }
1376
1377 return pairs
1378}
1379
1380// A list of build paths based on the given directory prefix.
1381func (l *ConfiguredJarList) BuildPaths(ctx PathContext, dir OutputPath) WritablePaths {
1382 paths := make(WritablePaths, l.Len())
1383 for i, jar := range l.jars {
1384 paths[i] = dir.Join(ctx, ModuleStem(jar)+".jar")
1385 }
1386 return paths
1387}
1388
1389func ModuleStem(module string) string {
1390 // b/139391334: the stem of framework-minus-apex is framework. This is hard coded here until we
1391 // find a good way to query the stem of a module before any other mutators are run.
1392 if module == "framework-minus-apex" {
1393 return "framework"
1394 }
1395 return module
1396}
1397
1398// A list of on-device paths.
1399func (l *ConfiguredJarList) DevicePaths(cfg Config, ostype OsType) []string {
1400 paths := make([]string, l.Len())
1401 for i, jar := range l.jars {
1402 apex := l.apexes[i]
1403 name := ModuleStem(jar) + ".jar"
1404
1405 var subdir string
1406 if apex == "platform" {
1407 subdir = "system/framework"
1408 } else if apex == "system_ext" {
1409 subdir = "system_ext/framework"
1410 } else {
1411 subdir = filepath.Join("apex", apex, "javalib")
1412 }
1413
1414 if ostype.Class == Host {
1415 paths[i] = filepath.Join(cfg.Getenv("OUT_DIR"), "host", cfg.PrebuiltOS(), subdir, name)
1416 } else {
1417 paths[i] = filepath.Join("/", subdir, name)
1418 }
1419 }
1420 return paths
1421}
1422
1423// Expected format for apexJarValue = <apex name>:<jar name>
1424func splitConfiguredJarPair(ctx PathContext, str string) (string, string) {
1425 pair := strings.SplitN(str, ":", 2)
1426 if len(pair) == 2 {
1427 return pair[0], pair[1]
1428 } else {
Ulya Trafimovich5ab276a2020-08-25 12:45:15 +01001429 ReportPathErrorf(ctx, "malformed (apex, jar) pair: '%s', expected format: <apex>:<jar>", str)
Ulya Trafimovich249386a2020-07-01 14:31:13 +01001430 return "error-apex", "error-jar"
1431 }
1432}
1433
1434func CreateConfiguredJarList(ctx PathContext, list []string) ConfiguredJarList {
1435 apexes := make([]string, 0, len(list))
1436 jars := make([]string, 0, len(list))
1437
1438 l := ConfiguredJarList{apexes, jars}
1439
1440 for _, apexjar := range list {
1441 apex, jar := splitConfiguredJarPair(ctx, apexjar)
1442 l.Append(apex, jar)
1443 }
1444
1445 return l
1446}
1447
1448func EmptyConfiguredJarList() ConfiguredJarList {
1449 return ConfiguredJarList{}
1450}
1451
1452var earlyBootJarsKey = NewOnceKey("earlyBootJars")
1453
1454func (c *config) BootJars() []string {
1455 return c.Once(earlyBootJarsKey, func() interface{} {
1456 ctx := NullPathContext{Config{c}}
1457 list := CreateConfiguredJarList(ctx,
1458 append(CopyOf(c.productVariables.BootJars), c.productVariables.UpdatableBootJars...))
1459 return list.CopyOfJars()
1460 }).([]string)
1461}