blob: b5ec9758886899eb2e39ca6088e23bcd1669c0c3 [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 Willemsen5951c8a2016-07-19 19:08:14 -070024 "strconv"
Dan Willemsen34cc69e2015-09-23 15:26:20 -070025 "strings"
Colin Crossc1e86a32015-04-15 12:33:28 -070026 "sync"
Colin Cross6ff51382015-12-17 16:39:19 -080027
Colin Crosse87040b2017-12-11 15:52:26 -080028 "github.com/google/blueprint/bootstrap"
Colin Cross6ff51382015-12-17 16:39:19 -080029 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080030)
31
Colin Cross6ff51382015-12-17 16:39:19 -080032var Bool = proptools.Bool
Jack He8cc71432016-12-08 15:45:07 -080033var String = proptools.String
Jiyong Park1a5d7b12018-01-15 15:05:10 +090034var FutureApiLevel = 10000
Colin Cross6ff51382015-12-17 16:39:19 -080035
Colin Cross3f40fa42015-01-30 17:27:36 -080036// The configuration file name
Dan Willemsen87b17d12015-07-14 00:39:06 -070037const configFileName = "soong.config"
38const productVariablesFileName = "soong.variables"
Colin Cross3f40fa42015-01-30 17:27:36 -080039
40// A FileConfigurableOptions contains options which can be configured by the
41// config file. These will be included in the config struct.
42type FileConfigurableOptions struct {
Dan Willemsen322acaf2016-01-12 23:07:05 -080043 Mega_device *bool `json:",omitempty"`
Dan Albert4098deb2016-10-19 14:04:41 -070044 Ndk_abis *bool `json:",omitempty"`
Dan Willemsen01a405a2016-06-13 17:19:03 -070045 Host_bionic *bool `json:",omitempty"`
Colin Cross3f40fa42015-01-30 17:27:36 -080046}
47
Colin Cross27385972015-09-18 10:57:10 -070048func (f *FileConfigurableOptions) SetDefaultConfig() {
49 *f = FileConfigurableOptions{}
Colin Cross3f40fa42015-01-30 17:27:36 -080050}
51
Colin Cross9272ade2016-08-17 15:24:12 -070052// A Config object represents the entire build configuration for Android.
Colin Crossc3c0a492015-04-10 15:43:55 -070053type Config struct {
54 *config
55}
56
Jeff Gastonefc1b412017-03-29 17:29:06 -070057func (c Config) BuildDir() string {
58 return c.buildDir
59}
60
Colin Cross9272ade2016-08-17 15:24:12 -070061// A DeviceConfig object represents the configuration for a particular device being built. For
62// now there will only be one of these, but in the future there may be multiple devices being
63// built
64type DeviceConfig struct {
65 *deviceConfig
66}
67
Colin Cross1332b002015-04-07 17:11:30 -070068type config struct {
Colin Cross3f40fa42015-01-30 17:27:36 -080069 FileConfigurableOptions
Colin Cross485e5722015-08-27 13:28:01 -070070 ProductVariables productVariables
Colin Cross3f40fa42015-01-30 17:27:36 -080071
Colin Crosse87040b2017-12-11 15:52:26 -080072 PrimaryBuilder string
Dan Willemsen87b17d12015-07-14 00:39:06 -070073 ConfigFileName string
74 ProductVariablesFileName string
75
Colin Crossa1ad8d12016-06-01 17:09:44 -070076 Targets map[OsClass][]Target
77 BuildOsVariant string
Dan Willemsen218f6562015-07-08 18:13:11 -070078
Colin Cross9272ade2016-08-17 15:24:12 -070079 deviceConfig *deviceConfig
80
Dan Willemsen87b17d12015-07-14 00:39:06 -070081 srcDir string // the path of the root source directory
82 buildDir string // the path of the build output directory
Colin Crossc1e86a32015-04-15 12:33:28 -070083
Colin Cross6ccbc912017-10-10 23:07:38 -070084 env map[string]string
Dan Willemsene7680ba2015-09-11 17:06:19 -070085 envLock sync.Mutex
86 envDeps map[string]string
87 envFrozen bool
Dan Willemsen5ba07e82015-12-11 13:51:06 -080088
89 inMake bool
Colin Cross1e7d3702016-08-24 15:25:47 -070090
Colin Cross32616ed2017-09-05 21:56:44 -070091 captureBuild bool // true for tests, saves build parameters for each module
92 ignoreEnvironment bool // true for tests, returns empty from all Getenv calls
Colin Crosscec81712017-07-13 14:43:27 -070093
Colin Cross1369cdb2017-09-29 17:58:17 -070094 useOpenJDK9 bool // Use OpenJDK9, but possibly target 1.8
95 targetOpenJDK9 bool // Use OpenJDK9 and target 1.9
96
Colin Crosse87040b2017-12-11 15:52:26 -080097 stopBefore bootstrap.StopBefore
98
Colin Cross9272ade2016-08-17 15:24:12 -070099 OncePer
100}
101
102type deviceConfig struct {
Dan Willemsen00269f22017-07-06 16:59:48 -0700103 config *config
Colin Cross9272ade2016-08-17 15:24:12 -0700104 OncePer
Colin Cross3f40fa42015-01-30 17:27:36 -0800105}
106
Colin Cross485e5722015-08-27 13:28:01 -0700107type jsonConfigurable interface {
Colin Cross27385972015-09-18 10:57:10 -0700108 SetDefaultConfig()
Colin Cross485e5722015-08-27 13:28:01 -0700109}
Colin Cross3f40fa42015-01-30 17:27:36 -0800110
Colin Cross485e5722015-08-27 13:28:01 -0700111func loadConfig(config *config) error {
Dan Willemsen87b17d12015-07-14 00:39:06 -0700112 err := loadFromConfigFile(&config.FileConfigurableOptions, config.ConfigFileName)
Colin Cross485e5722015-08-27 13:28:01 -0700113 if err != nil {
114 return err
115 }
116
Dan Willemsen87b17d12015-07-14 00:39:06 -0700117 return loadFromConfigFile(&config.ProductVariables, config.ProductVariablesFileName)
Colin Cross485e5722015-08-27 13:28:01 -0700118}
119
120// loads configuration options from a JSON file in the cwd.
121func loadFromConfigFile(configurable jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800122 // Try to open the file
Colin Cross485e5722015-08-27 13:28:01 -0700123 configFileReader, err := os.Open(filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800124 defer configFileReader.Close()
125 if os.IsNotExist(err) {
126 // Need to create a file, so that blueprint & ninja don't get in
127 // a dependency tracking loop.
128 // Make a file-configurable-options with defaults, write it out using
129 // a json writer.
Colin Cross27385972015-09-18 10:57:10 -0700130 configurable.SetDefaultConfig()
131 err = saveToConfigFile(configurable, filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800132 if err != nil {
133 return err
134 }
135 } else {
136 // Make a decoder for it
137 jsonDecoder := json.NewDecoder(configFileReader)
Colin Cross485e5722015-08-27 13:28:01 -0700138 err = jsonDecoder.Decode(configurable)
Colin Cross3f40fa42015-01-30 17:27:36 -0800139 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700140 return fmt.Errorf("config file: %s did not parse correctly: "+err.Error(), filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800141 }
142 }
143
Colin Cross3f40fa42015-01-30 17:27:36 -0800144 // No error
145 return nil
146}
147
Colin Crossd8f20142016-11-03 09:43:26 -0700148// atomically writes the config file in case two copies of soong_build are running simultaneously
149// (for example, docs generation and ninja manifest generation)
Colin Cross485e5722015-08-27 13:28:01 -0700150func saveToConfigFile(config jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800151 data, err := json.MarshalIndent(&config, "", " ")
152 if err != nil {
153 return fmt.Errorf("cannot marshal config data: %s", err.Error())
154 }
155
Colin Crossd8f20142016-11-03 09:43:26 -0700156 f, err := ioutil.TempFile(filepath.Dir(filename), "config")
Colin Cross3f40fa42015-01-30 17:27:36 -0800157 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700158 return fmt.Errorf("cannot create empty config file %s: %s\n", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800159 }
Colin Crossd8f20142016-11-03 09:43:26 -0700160 defer os.Remove(f.Name())
161 defer f.Close()
Colin Cross3f40fa42015-01-30 17:27:36 -0800162
Colin Crossd8f20142016-11-03 09:43:26 -0700163 _, err = f.Write(data)
Colin Cross3f40fa42015-01-30 17:27:36 -0800164 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700165 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
166 }
167
Colin Crossd8f20142016-11-03 09:43:26 -0700168 _, err = f.WriteString("\n")
Colin Cross485e5722015-08-27 13:28:01 -0700169 if err != nil {
170 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800171 }
172
Colin Crossd8f20142016-11-03 09:43:26 -0700173 f.Close()
174 os.Rename(f.Name(), filename)
175
Colin Cross3f40fa42015-01-30 17:27:36 -0800176 return nil
177}
178
Colin Crossce75d2c2016-10-06 16:12:58 -0700179// TestConfig returns a Config object suitable for using for tests
Colin Cross6ccbc912017-10-10 23:07:38 -0700180func TestConfig(buildDir string, env map[string]string) Config {
Dan Willemsen00269f22017-07-06 16:59:48 -0700181 config := &config{
182 ProductVariables: productVariables{
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800183 DeviceName: stringPtr("test_device"),
184 Platform_sdk_version: intPtr(26),
185 AAPTConfig: &[]string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"},
186 AAPTPreferredConfig: stringPtr("xhdpi"),
187 AAPTCharacteristics: stringPtr("nosdcard"),
188 AAPTPrebuiltDPI: &[]string{"xhdpi", "xxhdpi"},
Dan Willemsen00269f22017-07-06 16:59:48 -0700189 },
190
Colin Cross6ccbc912017-10-10 23:07:38 -0700191 buildDir: buildDir,
192 captureBuild: true,
193 env: env,
Dan Willemsen00269f22017-07-06 16:59:48 -0700194 }
195 config.deviceConfig = &deviceConfig{
196 config: config,
197 }
198
Colin Cross1369cdb2017-09-29 17:58:17 -0700199 if err := config.fromEnv(); err != nil {
200 panic(err)
201 }
202
Dan Willemsen00269f22017-07-06 16:59:48 -0700203 return Config{config}
Colin Crossce75d2c2016-10-06 16:12:58 -0700204}
205
Colin Crossae4c6182017-09-15 17:33:55 -0700206// TestConfig returns a Config object suitable for using for tests that need to run the arch mutator
Colin Cross6ccbc912017-10-10 23:07:38 -0700207func TestArchConfig(buildDir string, env map[string]string) Config {
208 testConfig := TestConfig(buildDir, env)
Colin Crossae4c6182017-09-15 17:33:55 -0700209 config := testConfig.config
210
211 config.Targets = map[OsClass][]Target{
212 Device: []Target{
Jiyong Park6a43f042017-10-12 23:05:00 +0900213 {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Native: true}},
214 {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Native: true}},
Colin Crossae4c6182017-09-15 17:33:55 -0700215 },
216 Host: []Target{
217 {BuildOs, Arch{ArchType: X86_64}},
218 {BuildOs, Arch{ArchType: X86}},
219 },
220 }
221
222 return testConfig
223}
224
Colin Cross3f40fa42015-01-30 17:27:36 -0800225// New creates a new Config object. The srcDir argument specifies the path to
226// the root source directory. It also loads the config file, if found.
Dan Willemsen87b17d12015-07-14 00:39:06 -0700227func NewConfig(srcDir, buildDir string) (Config, error) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800228 // Make a config with default options
Colin Cross9272ade2016-08-17 15:24:12 -0700229 config := &config{
230 ConfigFileName: filepath.Join(buildDir, configFileName),
231 ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName),
Dan Willemsen87b17d12015-07-14 00:39:06 -0700232
Colin Cross6ccbc912017-10-10 23:07:38 -0700233 env: originalEnv,
234
Colin Cross9272ade2016-08-17 15:24:12 -0700235 srcDir: srcDir,
236 buildDir: buildDir,
Colin Cross68f55102015-03-25 14:43:57 -0700237 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800238
Dan Willemsen00269f22017-07-06 16:59:48 -0700239 config.deviceConfig = &deviceConfig{
Colin Cross9272ade2016-08-17 15:24:12 -0700240 config: config,
241 }
242
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700243 // Sanity check the build and source directories. This won't catch strange
244 // configurations with symlinks, but at least checks the obvious cases.
245 absBuildDir, err := filepath.Abs(buildDir)
246 if err != nil {
247 return Config{}, err
248 }
249
250 absSrcDir, err := filepath.Abs(srcDir)
251 if err != nil {
252 return Config{}, err
253 }
254
255 if strings.HasPrefix(absSrcDir, absBuildDir) {
256 return Config{}, fmt.Errorf("Build dir must not contain source directory")
257 }
258
Colin Cross3f40fa42015-01-30 17:27:36 -0800259 // Load any configurable options from the configuration file
Colin Cross9272ade2016-08-17 15:24:12 -0700260 err = loadConfig(config)
Colin Cross3f40fa42015-01-30 17:27:36 -0800261 if err != nil {
Colin Crossc3c0a492015-04-10 15:43:55 -0700262 return Config{}, err
Colin Cross3f40fa42015-01-30 17:27:36 -0800263 }
264
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800265 inMakeFile := filepath.Join(buildDir, ".soong.in_make")
266 if _, err := os.Stat(inMakeFile); err == nil {
267 config.inMake = true
268 }
269
Colin Crossa1ad8d12016-06-01 17:09:44 -0700270 targets, err := decodeTargetProductVariables(config)
Dan Willemsen218f6562015-07-08 18:13:11 -0700271 if err != nil {
272 return Config{}, err
273 }
274
Dan Albert4098deb2016-10-19 14:04:41 -0700275 var archConfig []archConfig
Dan Willemsen322acaf2016-01-12 23:07:05 -0800276 if Bool(config.Mega_device) {
Dan Albert4098deb2016-10-19 14:04:41 -0700277 archConfig = getMegaDeviceConfig()
278 } else if Bool(config.Ndk_abis) {
279 archConfig = getNdkAbisConfig()
280 }
281
282 if archConfig != nil {
283 deviceTargets, err := decodeArchSettings(archConfig)
Dan Willemsen322acaf2016-01-12 23:07:05 -0800284 if err != nil {
285 return Config{}, err
286 }
Colin Crossa1ad8d12016-06-01 17:09:44 -0700287 targets[Device] = deviceTargets
Dan Willemsen322acaf2016-01-12 23:07:05 -0800288 }
289
Colin Crossa1ad8d12016-06-01 17:09:44 -0700290 config.Targets = targets
291 config.BuildOsVariant = targets[Host][0].String()
Dan Willemsen218f6562015-07-08 18:13:11 -0700292
Colin Cross1369cdb2017-09-29 17:58:17 -0700293 if err := config.fromEnv(); err != nil {
294 return Config{}, err
295 }
296
Colin Cross9272ade2016-08-17 15:24:12 -0700297 return Config{config}, nil
Colin Cross3f40fa42015-01-30 17:27:36 -0800298}
299
Colin Cross1369cdb2017-09-29 17:58:17 -0700300func (c *config) fromEnv() error {
301 switch c.Getenv("EXPERIMENTAL_USE_OPENJDK9") {
302 case "":
Tobias Thierer18099fd2017-11-17 14:14:29 +0000303 if c.Getenv("RUN_ERROR_PRONE") != "true" {
304 // Use OpenJDK9, but target 1.8
305 c.useOpenJDK9 = true
306 }
Tobias Thierera7cdd152017-11-15 21:16:25 +0000307 case "false":
308 // Use OpenJDK8
Colin Cross1369cdb2017-09-29 17:58:17 -0700309 case "1.8":
310 // Use OpenJDK9, but target 1.8
311 c.useOpenJDK9 = true
312 case "true":
313 // Use OpenJDK9 and target 1.9
314 c.useOpenJDK9 = true
315 c.targetOpenJDK9 = true
316 default:
Tobias Thierer18099fd2017-11-17 14:14:29 +0000317 return fmt.Errorf(`Invalid value for EXPERIMENTAL_USE_OPENJDK9, should be "", "false", "1.8", or "true"`)
Colin Cross1369cdb2017-09-29 17:58:17 -0700318 }
319
320 return nil
321}
322
Colin Crosse87040b2017-12-11 15:52:26 -0800323func (c *config) StopBefore() bootstrap.StopBefore {
324 return c.stopBefore
Dan Willemsen218f6562015-07-08 18:13:11 -0700325}
326
Colin Crosse87040b2017-12-11 15:52:26 -0800327func (c *config) SetStopBefore(stopBefore bootstrap.StopBefore) {
328 c.stopBefore = stopBefore
329}
330
331var _ bootstrap.ConfigStopBefore = (*config)(nil)
332
Dan Willemsenc2aa4a92016-05-26 15:13:03 -0700333func (c *config) BlueprintToolLocation() string {
334 return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin")
335}
336
Colin Crosse87040b2017-12-11 15:52:26 -0800337var _ bootstrap.ConfigBlueprintToolLocation = (*config)(nil)
338
Dan Willemsen66068722017-05-08 21:15:59 +0000339// HostSystemTool looks for non-hermetic tools from the system we're running on.
340// Generally shouldn't be used, but useful to find the XCode SDK, etc.
341func (c *config) HostSystemTool(name string) string {
342 for _, dir := range filepath.SplitList(c.Getenv("PATH")) {
343 path := filepath.Join(dir, name)
344 if s, err := os.Stat(path); err != nil {
345 continue
346 } else if m := s.Mode(); !s.IsDir() && m&0111 != 0 {
347 return path
348 }
349 }
350 return name
351}
352
Colin Cross3f40fa42015-01-30 17:27:36 -0800353// PrebuiltOS returns the name of the host OS used in prebuilts directories
Colin Cross1332b002015-04-07 17:11:30 -0700354func (c *config) PrebuiltOS() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800355 switch runtime.GOOS {
356 case "linux":
357 return "linux-x86"
358 case "darwin":
359 return "darwin-x86"
360 default:
361 panic("Unknown GOOS")
362 }
363}
364
365// GoRoot returns the path to the root directory of the Go toolchain.
Colin Cross1332b002015-04-07 17:11:30 -0700366func (c *config) GoRoot() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800367 return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS())
368}
369
Colin Cross1332b002015-04-07 17:11:30 -0700370func (c *config) CpPreserveSymlinksFlags() string {
Colin Cross485e5722015-08-27 13:28:01 -0700371 switch runtime.GOOS {
Colin Cross3f40fa42015-01-30 17:27:36 -0800372 case "darwin":
373 return "-R"
374 case "linux":
375 return "-d"
376 default:
377 return ""
378 }
379}
Colin Cross68f55102015-03-25 14:43:57 -0700380
Colin Cross1332b002015-04-07 17:11:30 -0700381func (c *config) Getenv(key string) string {
Colin Cross68f55102015-03-25 14:43:57 -0700382 var val string
383 var exists bool
Colin Crossc1e86a32015-04-15 12:33:28 -0700384 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800385 defer c.envLock.Unlock()
386 if c.envDeps == nil {
387 c.envDeps = make(map[string]string)
388 }
Colin Cross68f55102015-03-25 14:43:57 -0700389 if val, exists = c.envDeps[key]; !exists {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700390 if c.envFrozen {
391 panic("Cannot access new environment variables after envdeps are frozen")
392 }
Colin Cross6ccbc912017-10-10 23:07:38 -0700393 val, _ = c.env[key]
Colin Cross68f55102015-03-25 14:43:57 -0700394 c.envDeps[key] = val
395 }
396 return val
397}
398
Colin Cross99d7c232016-11-23 16:52:04 -0800399func (c *config) GetenvWithDefault(key string, defaultValue string) string {
400 ret := c.Getenv(key)
401 if ret == "" {
402 return defaultValue
403 }
404 return ret
405}
406
407func (c *config) IsEnvTrue(key string) bool {
408 value := c.Getenv(key)
409 return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
410}
411
412func (c *config) IsEnvFalse(key string) bool {
413 value := c.Getenv(key)
414 return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
415}
416
Colin Cross1332b002015-04-07 17:11:30 -0700417func (c *config) EnvDeps() map[string]string {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700418 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800419 defer c.envLock.Unlock()
Dan Willemsene7680ba2015-09-11 17:06:19 -0700420 c.envFrozen = true
Colin Cross68f55102015-03-25 14:43:57 -0700421 return c.envDeps
422}
Colin Cross35cec122015-04-02 14:37:16 -0700423
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800424func (c *config) EmbeddedInMake() bool {
425 return c.inMake
426}
427
Colin Cross35cec122015-04-02 14:37:16 -0700428// DeviceName returns the name of the current device target
429// TODO: take an AndroidModuleContext to select the device name for multi-device builds
Colin Cross1332b002015-04-07 17:11:30 -0700430func (c *config) DeviceName() string {
Dan Willemsen1d31ec32015-09-22 16:56:09 -0700431 return *c.ProductVariables.DeviceName
Colin Cross35cec122015-04-02 14:37:16 -0700432}
433
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800434func (c *config) ResourceOverlays() []string {
435 if c.ProductVariables.ResourceOverlays == nil {
436 return nil
437 }
438 return *c.ProductVariables.ResourceOverlays
Colin Cross30e076a2015-04-13 13:58:27 -0700439}
440
Dan Albert073379e2016-11-10 10:46:36 -0800441func (c *config) PlatformSdkVersionInt() int {
442 return *c.ProductVariables.Platform_sdk_version
443}
444
Colin Cross30e076a2015-04-13 13:58:27 -0700445func (c *config) PlatformSdkVersion() string {
Dan Albert073379e2016-11-10 10:46:36 -0800446 return strconv.Itoa(c.PlatformSdkVersionInt())
Colin Cross30e076a2015-04-13 13:58:27 -0700447}
448
Dan Albertf5415d72017-08-17 16:19:59 -0700449func (c *config) MinSupportedSdkVersion() int {
Dan Albertd4db4ac2017-08-10 12:18:31 -0700450 return 14
Dan Albertf5415d72017-08-17 16:19:59 -0700451}
452
Colin Cross595a4062017-08-31 12:30:37 -0700453func (c *config) DefaultAppTargetSdkInt() int {
454 if Bool(c.ProductVariables.Platform_sdk_final) {
455 return c.PlatformSdkVersionInt()
456 } else {
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900457 return FutureApiLevel
Colin Cross595a4062017-08-31 12:30:37 -0700458 }
459}
460
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800461func (c *config) AppsDefaultVersionName() string {
462 return String(c.ProductVariables.AppsDefaultVersionName)
463}
464
Dan Albert31384de2017-07-28 12:39:46 -0700465// Codenames that are active in the current lunch target.
466func (c *config) PlatformVersionActiveCodenames() []string {
467 return c.ProductVariables.Platform_version_active_codenames
468}
469
470// Codenames that are available in the branch but not included in the current
471// lunch target.
472func (c *config) PlatformVersionFutureCodenames() []string {
473 return c.ProductVariables.Platform_version_future_codenames
474}
475
476// All possible codenames in the current branch. NB: Not named AllCodenames
477// because "all" has historically meant "active" in make, and still does in
478// build.prop.
479func (c *config) PlatformVersionCombinedCodenames() []string {
480 combined := []string{}
481 combined = append(combined, c.PlatformVersionActiveCodenames()...)
482 combined = append(combined, c.PlatformVersionFutureCodenames()...)
483 return combined
Dan Albert30c9d6e2017-03-28 14:54:55 -0700484}
485
Colin Crossface4e42017-10-30 17:32:15 -0700486func (c *config) ProductAAPTConfig() []string {
Colin Crosse15ddaf2017-12-04 11:24:31 -0800487 return stringSlice(c.ProductVariables.AAPTConfig)
Colin Cross30e076a2015-04-13 13:58:27 -0700488}
489
Colin Crossface4e42017-10-30 17:32:15 -0700490func (c *config) ProductAAPTPreferredConfig() string {
Colin Crosse15ddaf2017-12-04 11:24:31 -0800491 return String(c.ProductVariables.AAPTPreferredConfig)
Colin Cross30e076a2015-04-13 13:58:27 -0700492}
493
Colin Crossface4e42017-10-30 17:32:15 -0700494func (c *config) ProductAAPTCharacteristics() string {
Colin Crosse15ddaf2017-12-04 11:24:31 -0800495 return String(c.ProductVariables.AAPTCharacteristics)
Colin Crossface4e42017-10-30 17:32:15 -0700496}
497
498func (c *config) ProductAAPTPrebuiltDPI() []string {
Colin Crosse15ddaf2017-12-04 11:24:31 -0800499 return stringSlice(c.ProductVariables.AAPTPrebuiltDPI)
Colin Cross30e076a2015-04-13 13:58:27 -0700500}
501
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700502func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
Colin Cross61ae0b72017-12-01 17:16:02 -0800503 defaultCert := String(c.ProductVariables.DefaultAppCertificate)
504 if defaultCert != "" {
505 return PathForSource(ctx, filepath.Dir(defaultCert))
506 } else {
507 return PathForSource(ctx, "build/target/product/security")
508 }
Colin Cross30e076a2015-04-13 13:58:27 -0700509}
510
Colin Crosse1731a52017-12-14 11:22:55 -0800511func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) {
Colin Cross61ae0b72017-12-01 17:16:02 -0800512 defaultCert := String(c.ProductVariables.DefaultAppCertificate)
513 if defaultCert != "" {
Colin Crosse1731a52017-12-14 11:22:55 -0800514 return PathForSource(ctx, defaultCert+".x509.pem"), PathForSource(ctx, defaultCert+".pk8")
Colin Cross61ae0b72017-12-01 17:16:02 -0800515 } else {
Colin Crosse1731a52017-12-14 11:22:55 -0800516 defaultDir := c.DefaultAppCertificateDir(ctx)
517 return defaultDir.Join(ctx, "testkey.x509.pem"), defaultDir.Join(ctx, "testkey.pk8")
Colin Cross61ae0b72017-12-01 17:16:02 -0800518 }
Colin Cross30e076a2015-04-13 13:58:27 -0700519}
Colin Cross6ff51382015-12-17 16:39:19 -0800520
521func (c *config) AllowMissingDependencies() bool {
Dan Willemsenb5038162016-03-16 12:35:33 -0700522 return Bool(c.ProductVariables.Allow_missing_dependencies)
Colin Cross6ff51382015-12-17 16:39:19 -0800523}
Dan Willemsen322acaf2016-01-12 23:07:05 -0800524
Colin Crossfc3674a2017-09-18 17:41:52 -0700525func (c *config) UnbundledBuild() bool {
526 return Bool(c.ProductVariables.Unbundled_build)
527}
528
Colin Cross0d3f8c02017-10-24 10:51:45 -0700529func (c *config) IsPdkBuild() bool {
530 return Bool(c.ProductVariables.Pdk)
531}
532
Colin Cross126a25c2017-10-31 13:55:34 -0700533func (c *config) MinimizeJavaDebugInfo() bool {
534 return Bool(c.ProductVariables.MinimizeJavaDebugInfo) && !Bool(c.ProductVariables.Eng)
535}
536
Colin Cross1e7d3702016-08-24 15:25:47 -0700537func (c *config) DevicePrefer32BitExecutables() bool {
538 return Bool(c.ProductVariables.DevicePrefer32BitExecutables)
539}
540
Dan Willemsen7f730fd2016-01-14 11:22:23 -0800541func (c *config) SkipDeviceInstall() bool {
Colin Cross893d8162017-04-26 17:34:03 -0700542 return c.EmbeddedInMake()
543}
544
545func (c *config) SkipMegaDeviceInstall(path string) bool {
546 return Bool(c.Mega_device) &&
547 strings.HasPrefix(path, filepath.Join(c.buildDir, "target", "product"))
Dan Willemsen322acaf2016-01-12 23:07:05 -0800548}
Colin Cross16b23492016-01-06 14:41:07 -0800549
550func (c *config) SanitizeHost() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700551 return append([]string(nil), c.ProductVariables.SanitizeHost...)
Colin Cross16b23492016-01-06 14:41:07 -0800552}
553
554func (c *config) SanitizeDevice() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700555 return append([]string(nil), c.ProductVariables.SanitizeDevice...)
556}
557
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700558func (c *config) SanitizeDeviceDiag() []string {
559 return append([]string(nil), c.ProductVariables.SanitizeDeviceDiag...)
560}
561
Colin Cross23ae82a2016-11-02 14:34:39 -0700562func (c *config) SanitizeDeviceArch() []string {
563 return append([]string(nil), c.ProductVariables.SanitizeDeviceArch...)
Colin Cross16b23492016-01-06 14:41:07 -0800564}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700565
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800566func (c *config) EnableCFI() bool {
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -0800567 if c.ProductVariables.EnableCFI == nil {
568 return true
569 } else {
570 return *c.ProductVariables.EnableCFI
571 }
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800572}
573
Colin Crossa1ad8d12016-06-01 17:09:44 -0700574func (c *config) Android64() bool {
575 for _, t := range c.Targets[Device] {
576 if t.Arch.ArchType.Multilib == "lib64" {
577 return true
578 }
579 }
580
581 return false
582}
Colin Cross9272ade2016-08-17 15:24:12 -0700583
Alan Leungc37c6342017-12-13 00:28:49 -0800584func (c *config) UseD8Desugar() bool {
Alan Leunge2fb6292017-12-20 01:15:56 -0800585 return !c.IsEnvFalse("USE_D8_DESUGAR")
Alan Leungc37c6342017-12-13 00:28:49 -0800586}
587
Colin Cross9d45bb72016-08-29 16:14:13 -0700588func (c *config) UseGoma() bool {
589 return Bool(c.ProductVariables.UseGoma)
590}
591
Colin Cross1369cdb2017-09-29 17:58:17 -0700592// Returns true if OpenJDK9 prebuilts are being used
593func (c *config) UseOpenJDK9() bool {
594 return c.useOpenJDK9
595}
596
597// Returns true if -source 1.9 -target 1.9 is being passed to javac
598func (c *config) TargetOpenJDK9() bool {
599 return c.targetOpenJDK9
600}
601
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700602func (c *config) ClangTidy() bool {
603 return Bool(c.ProductVariables.ClangTidy)
604}
605
606func (c *config) TidyChecks() string {
607 if c.ProductVariables.TidyChecks == nil {
608 return ""
609 }
610 return *c.ProductVariables.TidyChecks
611}
612
Colin Cross0f4e0d62016-07-27 10:56:55 -0700613func (c *config) LibartImgHostBaseAddress() string {
614 return "0x60000000"
615}
616
617func (c *config) LibartImgDeviceBaseAddress() string {
Colin Cross20e13652017-06-22 15:34:51 -0700618 archType := Common
619 if len(c.Targets[Device]) > 0 {
620 archType = c.Targets[Device][0].Arch.ArchType
621 }
622 switch archType {
Colin Cross0f4e0d62016-07-27 10:56:55 -0700623 default:
624 return "0x70000000"
625 case Mips, Mips64:
Chris Larsenae7f3e22017-05-30 16:36:58 -0700626 return "0x5C000000"
Colin Cross0f4e0d62016-07-27 10:56:55 -0700627 }
628}
629
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800630func (c *config) ArtUseReadBarrier() bool {
631 return Bool(c.ProductVariables.ArtUseReadBarrier)
632}
633
Colin Cross9272ade2016-08-17 15:24:12 -0700634func (c *deviceConfig) Arches() []Arch {
635 var arches []Arch
636 for _, target := range c.config.Targets[Device] {
637 arches = append(arches, target.Arch)
638 }
639 return arches
640}
Dan Willemsend2ede872016-11-18 14:54:24 -0800641
Dan Willemsen4353bc42016-12-05 17:16:02 -0800642func (c *deviceConfig) VendorPath() string {
643 if c.config.ProductVariables.VendorPath != nil {
644 return *c.config.ProductVariables.VendorPath
645 }
646 return "vendor"
647}
648
Justin Yun71549282017-11-17 12:10:28 +0900649func (c *deviceConfig) VndkVersion() string {
650 return String(c.config.ProductVariables.DeviceVndkVersion)
651}
652
Justin Yun8fe12122017-12-07 17:18:15 +0900653func (c *deviceConfig) PlatformVndkVersion() string {
654 return String(c.config.ProductVariables.Platform_vndk_version)
655}
656
Justin Yun71549282017-11-17 12:10:28 +0900657func (c *deviceConfig) ExtraVndkVersions() []string {
658 return c.config.ProductVariables.ExtraVndkVersions
Dan Willemsend2ede872016-11-18 14:54:24 -0800659}
Jack He8cc71432016-12-08 15:45:07 -0800660
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900661func (c *deviceConfig) SystemSdkVersions() []string {
662 if c.config.ProductVariables.DeviceSystemSdkVersions == nil {
663 return nil
664 }
665 return *c.config.ProductVariables.DeviceSystemSdkVersions
666}
667
668func (c *deviceConfig) PlatformSystemSdkVersions() []string {
669 return c.config.ProductVariables.Platform_systemsdk_versions
670}
671
Jiyong Park2db76922017-11-08 16:03:48 +0900672func (c *deviceConfig) OdmPath() string {
673 if c.config.ProductVariables.OdmPath != nil {
674 return *c.config.ProductVariables.OdmPath
675 }
676 return "odm"
677}
678
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900679func (c *deviceConfig) ProductPath() string {
680 if c.config.ProductVariables.ProductPath != nil {
681 return *c.config.ProductVariables.ProductPath
Jiyong Park2db76922017-11-08 16:03:48 +0900682 }
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900683 return "product"
Jiyong Park2db76922017-11-08 16:03:48 +0900684}
685
Jack He8cc71432016-12-08 15:45:07 -0800686func (c *deviceConfig) BtConfigIncludeDir() string {
687 return String(c.config.ProductVariables.BtConfigIncludeDir)
688}
Dan Willemsen581341d2017-02-09 16:16:31 -0800689
Jiyong Parkd773eb32017-07-03 13:18:12 +0900690func (c *deviceConfig) DeviceKernelHeaderDirs() []string {
691 return c.config.ProductVariables.DeviceKernelHeaders
692}
693
Dan Willemsen581341d2017-02-09 16:16:31 -0800694func (c *deviceConfig) NativeCoverageEnabled() bool {
695 return Bool(c.config.ProductVariables.NativeCoverage)
696}
697
698func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
Ryan Campbell469a18a2017-02-27 09:01:54 -0800699 coverage := false
Dan Willemsen581341d2017-02-09 16:16:31 -0800700 if c.config.ProductVariables.CoveragePaths != nil {
Colin Crossb4330e22017-12-22 15:47:09 -0800701 if PrefixInList(path, *c.config.ProductVariables.CoveragePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -0700702 coverage = true
Dan Willemsen581341d2017-02-09 16:16:31 -0800703 }
704 }
Ryan Campbell469a18a2017-02-27 09:01:54 -0800705 if coverage && c.config.ProductVariables.CoverageExcludePaths != nil {
Colin Crossb4330e22017-12-22 15:47:09 -0800706 if PrefixInList(path, *c.config.ProductVariables.CoverageExcludePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -0700707 coverage = false
Ryan Campbell469a18a2017-02-27 09:01:54 -0800708 }
709 }
710 return coverage
Dan Willemsen581341d2017-02-09 16:16:31 -0800711}
Ivan Lozano5f595532017-07-13 14:46:05 -0700712
713func (c *config) IntegerOverflowDisabledForPath(path string) bool {
714 if c.ProductVariables.IntegerOverflowExcludePaths == nil {
715 return false
716 }
Colin Crossb4330e22017-12-22 15:47:09 -0800717 return PrefixInList(path, *c.ProductVariables.IntegerOverflowExcludePaths)
Ivan Lozano5f595532017-07-13 14:46:05 -0700718}
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700719
720func (c *config) CFIDisabledForPath(path string) bool {
721 if c.ProductVariables.CFIExcludePaths == nil {
722 return false
723 }
Colin Crossb4330e22017-12-22 15:47:09 -0800724 return PrefixInList(path, *c.ProductVariables.CFIExcludePaths)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700725}
726
727func (c *config) CFIEnabledForPath(path string) bool {
728 if c.ProductVariables.CFIIncludePaths == nil {
729 return false
730 }
Colin Crossb4330e22017-12-22 15:47:09 -0800731 return PrefixInList(path, *c.ProductVariables.CFIIncludePaths)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700732}
Colin Crosse15ddaf2017-12-04 11:24:31 -0800733
734func stringSlice(s *[]string) []string {
735 if s != nil {
736 return *s
737 } else {
738 return nil
739 }
740}