blob: 630785b8baca6600d73d7c68c6f8c7f7fbb112f0 [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
Colin Cross6ff51382015-12-17 16:39:19 -080034
Colin Cross3f40fa42015-01-30 17:27:36 -080035// The configuration file name
Dan Willemsen87b17d12015-07-14 00:39:06 -070036const configFileName = "soong.config"
37const productVariablesFileName = "soong.variables"
Colin Cross3f40fa42015-01-30 17:27:36 -080038
39// A FileConfigurableOptions contains options which can be configured by the
40// config file. These will be included in the config struct.
41type FileConfigurableOptions struct {
Dan Willemsen322acaf2016-01-12 23:07:05 -080042 Mega_device *bool `json:",omitempty"`
Dan Albert4098deb2016-10-19 14:04:41 -070043 Ndk_abis *bool `json:",omitempty"`
Dan Willemsen01a405a2016-06-13 17:19:03 -070044 Host_bionic *bool `json:",omitempty"`
Colin Cross3f40fa42015-01-30 17:27:36 -080045}
46
Colin Cross27385972015-09-18 10:57:10 -070047func (f *FileConfigurableOptions) SetDefaultConfig() {
48 *f = FileConfigurableOptions{}
Colin Cross3f40fa42015-01-30 17:27:36 -080049}
50
Colin Cross9272ade2016-08-17 15:24:12 -070051// A Config object represents the entire build configuration for Android.
Colin Crossc3c0a492015-04-10 15:43:55 -070052type Config struct {
53 *config
54}
55
Jeff Gastonefc1b412017-03-29 17:29:06 -070056func (c Config) BuildDir() string {
57 return c.buildDir
58}
59
Colin Cross9272ade2016-08-17 15:24:12 -070060// A DeviceConfig object represents the configuration for a particular device being built. For
61// now there will only be one of these, but in the future there may be multiple devices being
62// built
63type DeviceConfig struct {
64 *deviceConfig
65}
66
Colin Cross1332b002015-04-07 17:11:30 -070067type config struct {
Colin Cross3f40fa42015-01-30 17:27:36 -080068 FileConfigurableOptions
Colin Cross485e5722015-08-27 13:28:01 -070069 ProductVariables productVariables
Colin Cross3f40fa42015-01-30 17:27:36 -080070
Colin Crosse87040b2017-12-11 15:52:26 -080071 PrimaryBuilder string
Dan Willemsen87b17d12015-07-14 00:39:06 -070072 ConfigFileName string
73 ProductVariablesFileName string
74
Colin Crossa1ad8d12016-06-01 17:09:44 -070075 Targets map[OsClass][]Target
76 BuildOsVariant string
Dan Willemsen218f6562015-07-08 18:13:11 -070077
Colin Cross9272ade2016-08-17 15:24:12 -070078 deviceConfig *deviceConfig
79
Dan Willemsen87b17d12015-07-14 00:39:06 -070080 srcDir string // the path of the root source directory
81 buildDir string // the path of the build output directory
Colin Crossc1e86a32015-04-15 12:33:28 -070082
Colin Cross6ccbc912017-10-10 23:07:38 -070083 env map[string]string
Dan Willemsene7680ba2015-09-11 17:06:19 -070084 envLock sync.Mutex
85 envDeps map[string]string
86 envFrozen bool
Dan Willemsen5ba07e82015-12-11 13:51:06 -080087
88 inMake bool
Colin Cross1e7d3702016-08-24 15:25:47 -070089
Colin Cross32616ed2017-09-05 21:56:44 -070090 captureBuild bool // true for tests, saves build parameters for each module
91 ignoreEnvironment bool // true for tests, returns empty from all Getenv calls
Colin Crosscec81712017-07-13 14:43:27 -070092
Colin Cross1369cdb2017-09-29 17:58:17 -070093 useOpenJDK9 bool // Use OpenJDK9, but possibly target 1.8
94 targetOpenJDK9 bool // Use OpenJDK9 and target 1.9
95
Colin Crosse87040b2017-12-11 15:52:26 -080096 stopBefore bootstrap.StopBefore
97
Colin Cross9272ade2016-08-17 15:24:12 -070098 OncePer
99}
100
101type deviceConfig struct {
Dan Willemsen00269f22017-07-06 16:59:48 -0700102 config *config
Colin Cross9272ade2016-08-17 15:24:12 -0700103 OncePer
Colin Cross3f40fa42015-01-30 17:27:36 -0800104}
105
Colin Cross485e5722015-08-27 13:28:01 -0700106type jsonConfigurable interface {
Colin Cross27385972015-09-18 10:57:10 -0700107 SetDefaultConfig()
Colin Cross485e5722015-08-27 13:28:01 -0700108}
Colin Cross3f40fa42015-01-30 17:27:36 -0800109
Colin Cross485e5722015-08-27 13:28:01 -0700110func loadConfig(config *config) error {
Dan Willemsen87b17d12015-07-14 00:39:06 -0700111 err := loadFromConfigFile(&config.FileConfigurableOptions, config.ConfigFileName)
Colin Cross485e5722015-08-27 13:28:01 -0700112 if err != nil {
113 return err
114 }
115
Dan Willemsen87b17d12015-07-14 00:39:06 -0700116 return loadFromConfigFile(&config.ProductVariables, config.ProductVariablesFileName)
Colin Cross485e5722015-08-27 13:28:01 -0700117}
118
119// loads configuration options from a JSON file in the cwd.
120func loadFromConfigFile(configurable jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800121 // Try to open the file
Colin Cross485e5722015-08-27 13:28:01 -0700122 configFileReader, err := os.Open(filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800123 defer configFileReader.Close()
124 if os.IsNotExist(err) {
125 // Need to create a file, so that blueprint & ninja don't get in
126 // a dependency tracking loop.
127 // Make a file-configurable-options with defaults, write it out using
128 // a json writer.
Colin Cross27385972015-09-18 10:57:10 -0700129 configurable.SetDefaultConfig()
130 err = saveToConfigFile(configurable, filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800131 if err != nil {
132 return err
133 }
134 } else {
135 // Make a decoder for it
136 jsonDecoder := json.NewDecoder(configFileReader)
Colin Cross485e5722015-08-27 13:28:01 -0700137 err = jsonDecoder.Decode(configurable)
Colin Cross3f40fa42015-01-30 17:27:36 -0800138 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700139 return fmt.Errorf("config file: %s did not parse correctly: "+err.Error(), filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800140 }
141 }
142
Colin Cross3f40fa42015-01-30 17:27:36 -0800143 // No error
144 return nil
145}
146
Colin Crossd8f20142016-11-03 09:43:26 -0700147// atomically writes the config file in case two copies of soong_build are running simultaneously
148// (for example, docs generation and ninja manifest generation)
Colin Cross485e5722015-08-27 13:28:01 -0700149func saveToConfigFile(config jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800150 data, err := json.MarshalIndent(&config, "", " ")
151 if err != nil {
152 return fmt.Errorf("cannot marshal config data: %s", err.Error())
153 }
154
Colin Crossd8f20142016-11-03 09:43:26 -0700155 f, err := ioutil.TempFile(filepath.Dir(filename), "config")
Colin Cross3f40fa42015-01-30 17:27:36 -0800156 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700157 return fmt.Errorf("cannot create empty config file %s: %s\n", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800158 }
Colin Crossd8f20142016-11-03 09:43:26 -0700159 defer os.Remove(f.Name())
160 defer f.Close()
Colin Cross3f40fa42015-01-30 17:27:36 -0800161
Colin Crossd8f20142016-11-03 09:43:26 -0700162 _, err = f.Write(data)
Colin Cross3f40fa42015-01-30 17:27:36 -0800163 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700164 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
165 }
166
Colin Crossd8f20142016-11-03 09:43:26 -0700167 _, err = f.WriteString("\n")
Colin Cross485e5722015-08-27 13:28:01 -0700168 if err != nil {
169 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800170 }
171
Colin Crossd8f20142016-11-03 09:43:26 -0700172 f.Close()
173 os.Rename(f.Name(), filename)
174
Colin Cross3f40fa42015-01-30 17:27:36 -0800175 return nil
176}
177
Colin Crossce75d2c2016-10-06 16:12:58 -0700178// TestConfig returns a Config object suitable for using for tests
Colin Cross6ccbc912017-10-10 23:07:38 -0700179func TestConfig(buildDir string, env map[string]string) Config {
Dan Willemsen00269f22017-07-06 16:59:48 -0700180 config := &config{
181 ProductVariables: productVariables{
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800182 DeviceName: stringPtr("test_device"),
183 Platform_sdk_version: intPtr(26),
184 AAPTConfig: &[]string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"},
185 AAPTPreferredConfig: stringPtr("xhdpi"),
186 AAPTCharacteristics: stringPtr("nosdcard"),
187 AAPTPrebuiltDPI: &[]string{"xhdpi", "xxhdpi"},
Dan Willemsen00269f22017-07-06 16:59:48 -0700188 },
189
Colin Cross6ccbc912017-10-10 23:07:38 -0700190 buildDir: buildDir,
191 captureBuild: true,
192 env: env,
Dan Willemsen00269f22017-07-06 16:59:48 -0700193 }
194 config.deviceConfig = &deviceConfig{
195 config: config,
196 }
197
Colin Cross1369cdb2017-09-29 17:58:17 -0700198 if err := config.fromEnv(); err != nil {
199 panic(err)
200 }
201
Dan Willemsen00269f22017-07-06 16:59:48 -0700202 return Config{config}
Colin Crossce75d2c2016-10-06 16:12:58 -0700203}
204
Colin Crossae4c6182017-09-15 17:33:55 -0700205// TestConfig returns a Config object suitable for using for tests that need to run the arch mutator
Colin Cross6ccbc912017-10-10 23:07:38 -0700206func TestArchConfig(buildDir string, env map[string]string) Config {
207 testConfig := TestConfig(buildDir, env)
Colin Crossae4c6182017-09-15 17:33:55 -0700208 config := testConfig.config
209
210 config.Targets = map[OsClass][]Target{
211 Device: []Target{
Jiyong Park6a43f042017-10-12 23:05:00 +0900212 {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Native: true}},
213 {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Native: true}},
Colin Crossae4c6182017-09-15 17:33:55 -0700214 },
215 Host: []Target{
216 {BuildOs, Arch{ArchType: X86_64}},
217 {BuildOs, Arch{ArchType: X86}},
218 },
219 }
220
221 return testConfig
222}
223
Colin Cross3f40fa42015-01-30 17:27:36 -0800224// New creates a new Config object. The srcDir argument specifies the path to
225// the root source directory. It also loads the config file, if found.
Dan Willemsen87b17d12015-07-14 00:39:06 -0700226func NewConfig(srcDir, buildDir string) (Config, error) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800227 // Make a config with default options
Colin Cross9272ade2016-08-17 15:24:12 -0700228 config := &config{
229 ConfigFileName: filepath.Join(buildDir, configFileName),
230 ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName),
Dan Willemsen87b17d12015-07-14 00:39:06 -0700231
Colin Cross6ccbc912017-10-10 23:07:38 -0700232 env: originalEnv,
233
Colin Cross9272ade2016-08-17 15:24:12 -0700234 srcDir: srcDir,
235 buildDir: buildDir,
Colin Cross68f55102015-03-25 14:43:57 -0700236 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800237
Dan Willemsen00269f22017-07-06 16:59:48 -0700238 config.deviceConfig = &deviceConfig{
Colin Cross9272ade2016-08-17 15:24:12 -0700239 config: config,
240 }
241
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700242 // Sanity check the build and source directories. This won't catch strange
243 // configurations with symlinks, but at least checks the obvious cases.
244 absBuildDir, err := filepath.Abs(buildDir)
245 if err != nil {
246 return Config{}, err
247 }
248
249 absSrcDir, err := filepath.Abs(srcDir)
250 if err != nil {
251 return Config{}, err
252 }
253
254 if strings.HasPrefix(absSrcDir, absBuildDir) {
255 return Config{}, fmt.Errorf("Build dir must not contain source directory")
256 }
257
Colin Cross3f40fa42015-01-30 17:27:36 -0800258 // Load any configurable options from the configuration file
Colin Cross9272ade2016-08-17 15:24:12 -0700259 err = loadConfig(config)
Colin Cross3f40fa42015-01-30 17:27:36 -0800260 if err != nil {
Colin Crossc3c0a492015-04-10 15:43:55 -0700261 return Config{}, err
Colin Cross3f40fa42015-01-30 17:27:36 -0800262 }
263
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800264 inMakeFile := filepath.Join(buildDir, ".soong.in_make")
265 if _, err := os.Stat(inMakeFile); err == nil {
266 config.inMake = true
267 }
268
Colin Crossa1ad8d12016-06-01 17:09:44 -0700269 targets, err := decodeTargetProductVariables(config)
Dan Willemsen218f6562015-07-08 18:13:11 -0700270 if err != nil {
271 return Config{}, err
272 }
273
Dan Albert4098deb2016-10-19 14:04:41 -0700274 var archConfig []archConfig
Dan Willemsen322acaf2016-01-12 23:07:05 -0800275 if Bool(config.Mega_device) {
Dan Albert4098deb2016-10-19 14:04:41 -0700276 archConfig = getMegaDeviceConfig()
277 } else if Bool(config.Ndk_abis) {
278 archConfig = getNdkAbisConfig()
279 }
280
281 if archConfig != nil {
282 deviceTargets, err := decodeArchSettings(archConfig)
Dan Willemsen322acaf2016-01-12 23:07:05 -0800283 if err != nil {
284 return Config{}, err
285 }
Colin Crossa1ad8d12016-06-01 17:09:44 -0700286 targets[Device] = deviceTargets
Dan Willemsen322acaf2016-01-12 23:07:05 -0800287 }
288
Colin Crossa1ad8d12016-06-01 17:09:44 -0700289 config.Targets = targets
290 config.BuildOsVariant = targets[Host][0].String()
Dan Willemsen218f6562015-07-08 18:13:11 -0700291
Colin Cross1369cdb2017-09-29 17:58:17 -0700292 if err := config.fromEnv(); err != nil {
293 return Config{}, err
294 }
295
Colin Cross9272ade2016-08-17 15:24:12 -0700296 return Config{config}, nil
Colin Cross3f40fa42015-01-30 17:27:36 -0800297}
298
Colin Cross1369cdb2017-09-29 17:58:17 -0700299func (c *config) fromEnv() error {
300 switch c.Getenv("EXPERIMENTAL_USE_OPENJDK9") {
301 case "":
Tobias Thierer18099fd2017-11-17 14:14:29 +0000302 if c.Getenv("RUN_ERROR_PRONE") != "true" {
303 // Use OpenJDK9, but target 1.8
304 c.useOpenJDK9 = true
305 }
Tobias Thierera7cdd152017-11-15 21:16:25 +0000306 case "false":
307 // Use OpenJDK8
Colin Cross1369cdb2017-09-29 17:58:17 -0700308 case "1.8":
309 // Use OpenJDK9, but target 1.8
310 c.useOpenJDK9 = true
311 case "true":
312 // Use OpenJDK9 and target 1.9
313 c.useOpenJDK9 = true
314 c.targetOpenJDK9 = true
315 default:
Tobias Thierer18099fd2017-11-17 14:14:29 +0000316 return fmt.Errorf(`Invalid value for EXPERIMENTAL_USE_OPENJDK9, should be "", "false", "1.8", or "true"`)
Colin Cross1369cdb2017-09-29 17:58:17 -0700317 }
318
319 return nil
320}
321
Colin Crosse87040b2017-12-11 15:52:26 -0800322func (c *config) StopBefore() bootstrap.StopBefore {
323 return c.stopBefore
Dan Willemsen218f6562015-07-08 18:13:11 -0700324}
325
Colin Crosse87040b2017-12-11 15:52:26 -0800326func (c *config) SetStopBefore(stopBefore bootstrap.StopBefore) {
327 c.stopBefore = stopBefore
328}
329
330var _ bootstrap.ConfigStopBefore = (*config)(nil)
331
Dan Willemsenc2aa4a92016-05-26 15:13:03 -0700332func (c *config) BlueprintToolLocation() string {
333 return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin")
334}
335
Colin Crosse87040b2017-12-11 15:52:26 -0800336var _ bootstrap.ConfigBlueprintToolLocation = (*config)(nil)
337
Dan Willemsen66068722017-05-08 21:15:59 +0000338// HostSystemTool looks for non-hermetic tools from the system we're running on.
339// Generally shouldn't be used, but useful to find the XCode SDK, etc.
340func (c *config) HostSystemTool(name string) string {
341 for _, dir := range filepath.SplitList(c.Getenv("PATH")) {
342 path := filepath.Join(dir, name)
343 if s, err := os.Stat(path); err != nil {
344 continue
345 } else if m := s.Mode(); !s.IsDir() && m&0111 != 0 {
346 return path
347 }
348 }
349 return name
350}
351
Colin Cross3f40fa42015-01-30 17:27:36 -0800352// PrebuiltOS returns the name of the host OS used in prebuilts directories
Colin Cross1332b002015-04-07 17:11:30 -0700353func (c *config) PrebuiltOS() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800354 switch runtime.GOOS {
355 case "linux":
356 return "linux-x86"
357 case "darwin":
358 return "darwin-x86"
359 default:
360 panic("Unknown GOOS")
361 }
362}
363
364// GoRoot returns the path to the root directory of the Go toolchain.
Colin Cross1332b002015-04-07 17:11:30 -0700365func (c *config) GoRoot() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800366 return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS())
367}
368
Colin Cross1332b002015-04-07 17:11:30 -0700369func (c *config) CpPreserveSymlinksFlags() string {
Colin Cross485e5722015-08-27 13:28:01 -0700370 switch runtime.GOOS {
Colin Cross3f40fa42015-01-30 17:27:36 -0800371 case "darwin":
372 return "-R"
373 case "linux":
374 return "-d"
375 default:
376 return ""
377 }
378}
Colin Cross68f55102015-03-25 14:43:57 -0700379
Colin Cross1332b002015-04-07 17:11:30 -0700380func (c *config) Getenv(key string) string {
Colin Cross68f55102015-03-25 14:43:57 -0700381 var val string
382 var exists bool
Colin Crossc1e86a32015-04-15 12:33:28 -0700383 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800384 defer c.envLock.Unlock()
385 if c.envDeps == nil {
386 c.envDeps = make(map[string]string)
387 }
Colin Cross68f55102015-03-25 14:43:57 -0700388 if val, exists = c.envDeps[key]; !exists {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700389 if c.envFrozen {
390 panic("Cannot access new environment variables after envdeps are frozen")
391 }
Colin Cross6ccbc912017-10-10 23:07:38 -0700392 val, _ = c.env[key]
Colin Cross68f55102015-03-25 14:43:57 -0700393 c.envDeps[key] = val
394 }
395 return val
396}
397
Colin Cross99d7c232016-11-23 16:52:04 -0800398func (c *config) GetenvWithDefault(key string, defaultValue string) string {
399 ret := c.Getenv(key)
400 if ret == "" {
401 return defaultValue
402 }
403 return ret
404}
405
406func (c *config) IsEnvTrue(key string) bool {
407 value := c.Getenv(key)
408 return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
409}
410
411func (c *config) IsEnvFalse(key string) bool {
412 value := c.Getenv(key)
413 return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
414}
415
Colin Cross1332b002015-04-07 17:11:30 -0700416func (c *config) EnvDeps() map[string]string {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700417 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800418 defer c.envLock.Unlock()
Dan Willemsene7680ba2015-09-11 17:06:19 -0700419 c.envFrozen = true
Colin Cross68f55102015-03-25 14:43:57 -0700420 return c.envDeps
421}
Colin Cross35cec122015-04-02 14:37:16 -0700422
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800423func (c *config) EmbeddedInMake() bool {
424 return c.inMake
425}
426
Colin Cross35cec122015-04-02 14:37:16 -0700427// DeviceName returns the name of the current device target
428// TODO: take an AndroidModuleContext to select the device name for multi-device builds
Colin Cross1332b002015-04-07 17:11:30 -0700429func (c *config) DeviceName() string {
Dan Willemsen1d31ec32015-09-22 16:56:09 -0700430 return *c.ProductVariables.DeviceName
Colin Cross35cec122015-04-02 14:37:16 -0700431}
432
Dan Willemsendd0e2c32015-10-20 14:29:35 -0700433func (c *config) DeviceUsesClang() bool {
434 if c.ProductVariables.DeviceUsesClang != nil {
435 return *c.ProductVariables.DeviceUsesClang
436 }
Dan Willemsen0084d782016-03-01 14:54:24 -0800437 return true
Dan Willemsendd0e2c32015-10-20 14:29:35 -0700438}
439
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800440func (c *config) ResourceOverlays() []string {
441 if c.ProductVariables.ResourceOverlays == nil {
442 return nil
443 }
444 return *c.ProductVariables.ResourceOverlays
Colin Cross30e076a2015-04-13 13:58:27 -0700445}
446
Dan Albert073379e2016-11-10 10:46:36 -0800447func (c *config) PlatformSdkVersionInt() int {
448 return *c.ProductVariables.Platform_sdk_version
449}
450
Colin Cross30e076a2015-04-13 13:58:27 -0700451func (c *config) PlatformSdkVersion() string {
Dan Albert073379e2016-11-10 10:46:36 -0800452 return strconv.Itoa(c.PlatformSdkVersionInt())
Colin Cross30e076a2015-04-13 13:58:27 -0700453}
454
Dan Albertf5415d72017-08-17 16:19:59 -0700455func (c *config) MinSupportedSdkVersion() int {
Dan Albertd4db4ac2017-08-10 12:18:31 -0700456 return 14
Dan Albertf5415d72017-08-17 16:19:59 -0700457}
458
Colin Cross595a4062017-08-31 12:30:37 -0700459func (c *config) DefaultAppTargetSdkInt() int {
460 if Bool(c.ProductVariables.Platform_sdk_final) {
461 return c.PlatformSdkVersionInt()
462 } else {
463 return 10000
464 }
465}
466
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800467func (c *config) AppsDefaultVersionName() string {
468 return String(c.ProductVariables.AppsDefaultVersionName)
469}
470
Dan Albert31384de2017-07-28 12:39:46 -0700471// Codenames that are active in the current lunch target.
472func (c *config) PlatformVersionActiveCodenames() []string {
473 return c.ProductVariables.Platform_version_active_codenames
474}
475
476// Codenames that are available in the branch but not included in the current
477// lunch target.
478func (c *config) PlatformVersionFutureCodenames() []string {
479 return c.ProductVariables.Platform_version_future_codenames
480}
481
482// All possible codenames in the current branch. NB: Not named AllCodenames
483// because "all" has historically meant "active" in make, and still does in
484// build.prop.
485func (c *config) PlatformVersionCombinedCodenames() []string {
486 combined := []string{}
487 combined = append(combined, c.PlatformVersionActiveCodenames()...)
488 combined = append(combined, c.PlatformVersionFutureCodenames()...)
489 return combined
Dan Albert30c9d6e2017-03-28 14:54:55 -0700490}
491
Colin Crossface4e42017-10-30 17:32:15 -0700492func (c *config) ProductAAPTConfig() []string {
Colin Crosse15ddaf2017-12-04 11:24:31 -0800493 return stringSlice(c.ProductVariables.AAPTConfig)
Colin Cross30e076a2015-04-13 13:58:27 -0700494}
495
Colin Crossface4e42017-10-30 17:32:15 -0700496func (c *config) ProductAAPTPreferredConfig() string {
Colin Crosse15ddaf2017-12-04 11:24:31 -0800497 return String(c.ProductVariables.AAPTPreferredConfig)
Colin Cross30e076a2015-04-13 13:58:27 -0700498}
499
Colin Crossface4e42017-10-30 17:32:15 -0700500func (c *config) ProductAAPTCharacteristics() string {
Colin Crosse15ddaf2017-12-04 11:24:31 -0800501 return String(c.ProductVariables.AAPTCharacteristics)
Colin Crossface4e42017-10-30 17:32:15 -0700502}
503
504func (c *config) ProductAAPTPrebuiltDPI() []string {
Colin Crosse15ddaf2017-12-04 11:24:31 -0800505 return stringSlice(c.ProductVariables.AAPTPrebuiltDPI)
Colin Cross30e076a2015-04-13 13:58:27 -0700506}
507
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700508func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
Colin Cross61ae0b72017-12-01 17:16:02 -0800509 defaultCert := String(c.ProductVariables.DefaultAppCertificate)
510 if defaultCert != "" {
511 return PathForSource(ctx, filepath.Dir(defaultCert))
512 } else {
513 return PathForSource(ctx, "build/target/product/security")
514 }
Colin Cross30e076a2015-04-13 13:58:27 -0700515}
516
Colin Crosse1731a52017-12-14 11:22:55 -0800517func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) {
Colin Cross61ae0b72017-12-01 17:16:02 -0800518 defaultCert := String(c.ProductVariables.DefaultAppCertificate)
519 if defaultCert != "" {
Colin Crosse1731a52017-12-14 11:22:55 -0800520 return PathForSource(ctx, defaultCert+".x509.pem"), PathForSource(ctx, defaultCert+".pk8")
Colin Cross61ae0b72017-12-01 17:16:02 -0800521 } else {
Colin Crosse1731a52017-12-14 11:22:55 -0800522 defaultDir := c.DefaultAppCertificateDir(ctx)
523 return defaultDir.Join(ctx, "testkey.x509.pem"), defaultDir.Join(ctx, "testkey.pk8")
Colin Cross61ae0b72017-12-01 17:16:02 -0800524 }
Colin Cross30e076a2015-04-13 13:58:27 -0700525}
Colin Cross6ff51382015-12-17 16:39:19 -0800526
527func (c *config) AllowMissingDependencies() bool {
Dan Willemsenb5038162016-03-16 12:35:33 -0700528 return Bool(c.ProductVariables.Allow_missing_dependencies)
Colin Cross6ff51382015-12-17 16:39:19 -0800529}
Dan Willemsen322acaf2016-01-12 23:07:05 -0800530
Colin Crossfc3674a2017-09-18 17:41:52 -0700531func (c *config) UnbundledBuild() bool {
532 return Bool(c.ProductVariables.Unbundled_build)
533}
534
Colin Cross0d3f8c02017-10-24 10:51:45 -0700535func (c *config) IsPdkBuild() bool {
536 return Bool(c.ProductVariables.Pdk)
537}
538
Colin Cross126a25c2017-10-31 13:55:34 -0700539func (c *config) MinimizeJavaDebugInfo() bool {
540 return Bool(c.ProductVariables.MinimizeJavaDebugInfo) && !Bool(c.ProductVariables.Eng)
541}
542
Colin Cross1e7d3702016-08-24 15:25:47 -0700543func (c *config) DevicePrefer32BitExecutables() bool {
544 return Bool(c.ProductVariables.DevicePrefer32BitExecutables)
545}
546
Dan Willemsen7f730fd2016-01-14 11:22:23 -0800547func (c *config) SkipDeviceInstall() bool {
Colin Cross893d8162017-04-26 17:34:03 -0700548 return c.EmbeddedInMake()
549}
550
551func (c *config) SkipMegaDeviceInstall(path string) bool {
552 return Bool(c.Mega_device) &&
553 strings.HasPrefix(path, filepath.Join(c.buildDir, "target", "product"))
Dan Willemsen322acaf2016-01-12 23:07:05 -0800554}
Colin Cross16b23492016-01-06 14:41:07 -0800555
556func (c *config) SanitizeHost() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700557 return append([]string(nil), c.ProductVariables.SanitizeHost...)
Colin Cross16b23492016-01-06 14:41:07 -0800558}
559
560func (c *config) SanitizeDevice() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700561 return append([]string(nil), c.ProductVariables.SanitizeDevice...)
562}
563
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700564func (c *config) SanitizeDeviceDiag() []string {
565 return append([]string(nil), c.ProductVariables.SanitizeDeviceDiag...)
566}
567
Colin Cross23ae82a2016-11-02 14:34:39 -0700568func (c *config) SanitizeDeviceArch() []string {
569 return append([]string(nil), c.ProductVariables.SanitizeDeviceArch...)
Colin Cross16b23492016-01-06 14:41:07 -0800570}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700571
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800572func (c *config) EnableCFI() bool {
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -0800573 if c.ProductVariables.EnableCFI == nil {
574 return true
575 } else {
576 return *c.ProductVariables.EnableCFI
577 }
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800578}
579
Colin Crossa1ad8d12016-06-01 17:09:44 -0700580func (c *config) Android64() bool {
581 for _, t := range c.Targets[Device] {
582 if t.Arch.ArchType.Multilib == "lib64" {
583 return true
584 }
585 }
586
587 return false
588}
Colin Cross9272ade2016-08-17 15:24:12 -0700589
Alan Leungc37c6342017-12-13 00:28:49 -0800590func (c *config) UseD8Desugar() bool {
Alan Leunge2fb6292017-12-20 01:15:56 -0800591 return !c.IsEnvFalse("USE_D8_DESUGAR")
Alan Leungc37c6342017-12-13 00:28:49 -0800592}
593
Colin Cross9d45bb72016-08-29 16:14:13 -0700594func (c *config) UseGoma() bool {
595 return Bool(c.ProductVariables.UseGoma)
596}
597
Colin Cross1369cdb2017-09-29 17:58:17 -0700598// Returns true if OpenJDK9 prebuilts are being used
599func (c *config) UseOpenJDK9() bool {
600 return c.useOpenJDK9
601}
602
603// Returns true if -source 1.9 -target 1.9 is being passed to javac
604func (c *config) TargetOpenJDK9() bool {
605 return c.targetOpenJDK9
606}
607
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700608func (c *config) ClangTidy() bool {
609 return Bool(c.ProductVariables.ClangTidy)
610}
611
612func (c *config) TidyChecks() string {
613 if c.ProductVariables.TidyChecks == nil {
614 return ""
615 }
616 return *c.ProductVariables.TidyChecks
617}
618
Colin Cross0f4e0d62016-07-27 10:56:55 -0700619func (c *config) LibartImgHostBaseAddress() string {
620 return "0x60000000"
621}
622
623func (c *config) LibartImgDeviceBaseAddress() string {
Colin Cross20e13652017-06-22 15:34:51 -0700624 archType := Common
625 if len(c.Targets[Device]) > 0 {
626 archType = c.Targets[Device][0].Arch.ArchType
627 }
628 switch archType {
Colin Cross0f4e0d62016-07-27 10:56:55 -0700629 default:
630 return "0x70000000"
631 case Mips, Mips64:
Chris Larsenae7f3e22017-05-30 16:36:58 -0700632 return "0x5C000000"
Colin Cross0f4e0d62016-07-27 10:56:55 -0700633 }
634}
635
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800636func (c *config) ArtUseReadBarrier() bool {
637 return Bool(c.ProductVariables.ArtUseReadBarrier)
638}
639
Colin Cross9272ade2016-08-17 15:24:12 -0700640func (c *deviceConfig) Arches() []Arch {
641 var arches []Arch
642 for _, target := range c.config.Targets[Device] {
643 arches = append(arches, target.Arch)
644 }
645 return arches
646}
Dan Willemsend2ede872016-11-18 14:54:24 -0800647
Dan Willemsen4353bc42016-12-05 17:16:02 -0800648func (c *deviceConfig) VendorPath() string {
649 if c.config.ProductVariables.VendorPath != nil {
650 return *c.config.ProductVariables.VendorPath
651 }
652 return "vendor"
653}
654
Justin Yun71549282017-11-17 12:10:28 +0900655func (c *deviceConfig) VndkVersion() string {
656 return String(c.config.ProductVariables.DeviceVndkVersion)
657}
658
Justin Yun8fe12122017-12-07 17:18:15 +0900659func (c *deviceConfig) PlatformVndkVersion() string {
660 return String(c.config.ProductVariables.Platform_vndk_version)
661}
662
Justin Yun71549282017-11-17 12:10:28 +0900663func (c *deviceConfig) ExtraVndkVersions() []string {
664 return c.config.ProductVariables.ExtraVndkVersions
Dan Willemsend2ede872016-11-18 14:54:24 -0800665}
Jack He8cc71432016-12-08 15:45:07 -0800666
Jiyong Park2db76922017-11-08 16:03:48 +0900667func (c *deviceConfig) OdmPath() string {
668 if c.config.ProductVariables.OdmPath != nil {
669 return *c.config.ProductVariables.OdmPath
670 }
671 return "odm"
672}
673
674func (c *deviceConfig) OemPath() string {
675 if c.config.ProductVariables.OemPath != nil {
676 return *c.config.ProductVariables.OemPath
677 }
678 return "oem"
679}
680
Jack He8cc71432016-12-08 15:45:07 -0800681func (c *deviceConfig) BtConfigIncludeDir() string {
682 return String(c.config.ProductVariables.BtConfigIncludeDir)
683}
Dan Willemsen581341d2017-02-09 16:16:31 -0800684
Jiyong Parkd773eb32017-07-03 13:18:12 +0900685func (c *deviceConfig) DeviceKernelHeaderDirs() []string {
686 return c.config.ProductVariables.DeviceKernelHeaders
687}
688
Dan Willemsen581341d2017-02-09 16:16:31 -0800689func (c *deviceConfig) NativeCoverageEnabled() bool {
690 return Bool(c.config.ProductVariables.NativeCoverage)
691}
692
693func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
Ryan Campbell469a18a2017-02-27 09:01:54 -0800694 coverage := false
Dan Willemsen581341d2017-02-09 16:16:31 -0800695 if c.config.ProductVariables.CoveragePaths != nil {
Colin Crossb4330e22017-12-22 15:47:09 -0800696 if PrefixInList(path, *c.config.ProductVariables.CoveragePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -0700697 coverage = true
Dan Willemsen581341d2017-02-09 16:16:31 -0800698 }
699 }
Ryan Campbell469a18a2017-02-27 09:01:54 -0800700 if coverage && c.config.ProductVariables.CoverageExcludePaths != nil {
Colin Crossb4330e22017-12-22 15:47:09 -0800701 if PrefixInList(path, *c.config.ProductVariables.CoverageExcludePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -0700702 coverage = false
Ryan Campbell469a18a2017-02-27 09:01:54 -0800703 }
704 }
705 return coverage
Dan Willemsen581341d2017-02-09 16:16:31 -0800706}
Ivan Lozano5f595532017-07-13 14:46:05 -0700707
708func (c *config) IntegerOverflowDisabledForPath(path string) bool {
709 if c.ProductVariables.IntegerOverflowExcludePaths == nil {
710 return false
711 }
Colin Crossb4330e22017-12-22 15:47:09 -0800712 return PrefixInList(path, *c.ProductVariables.IntegerOverflowExcludePaths)
Ivan Lozano5f595532017-07-13 14:46:05 -0700713}
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700714
715func (c *config) CFIDisabledForPath(path string) bool {
716 if c.ProductVariables.CFIExcludePaths == nil {
717 return false
718 }
Colin Crossb4330e22017-12-22 15:47:09 -0800719 return PrefixInList(path, *c.ProductVariables.CFIExcludePaths)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700720}
721
722func (c *config) CFIEnabledForPath(path string) bool {
723 if c.ProductVariables.CFIIncludePaths == nil {
724 return false
725 }
Colin Crossb4330e22017-12-22 15:47:09 -0800726 return PrefixInList(path, *c.ProductVariables.CFIIncludePaths)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700727}
Colin Crosse15ddaf2017-12-04 11:24:31 -0800728
729func stringSlice(s *[]string) []string {
730 if s != nil {
731 return *s
732 } else {
733 return nil
734 }
735}