blob: db833eca7bdd63f01f03351f3f090d82d288a010 [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 }
Colin Cross15cd21a2018-02-27 11:26:02 -0800135 } else if err != nil {
136 return fmt.Errorf("config file: could not open %s: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800137 } else {
138 // Make a decoder for it
139 jsonDecoder := json.NewDecoder(configFileReader)
Colin Cross485e5722015-08-27 13:28:01 -0700140 err = jsonDecoder.Decode(configurable)
Colin Cross3f40fa42015-01-30 17:27:36 -0800141 if err != nil {
Colin Cross15cd21a2018-02-27 11:26:02 -0800142 return fmt.Errorf("config file: %s did not parse correctly: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800143 }
144 }
145
Colin Cross3f40fa42015-01-30 17:27:36 -0800146 // No error
147 return nil
148}
149
Colin Crossd8f20142016-11-03 09:43:26 -0700150// atomically writes the config file in case two copies of soong_build are running simultaneously
151// (for example, docs generation and ninja manifest generation)
Colin Cross485e5722015-08-27 13:28:01 -0700152func saveToConfigFile(config jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800153 data, err := json.MarshalIndent(&config, "", " ")
154 if err != nil {
155 return fmt.Errorf("cannot marshal config data: %s", err.Error())
156 }
157
Colin Crossd8f20142016-11-03 09:43:26 -0700158 f, err := ioutil.TempFile(filepath.Dir(filename), "config")
Colin Cross3f40fa42015-01-30 17:27:36 -0800159 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700160 return fmt.Errorf("cannot create empty config file %s: %s\n", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800161 }
Colin Crossd8f20142016-11-03 09:43:26 -0700162 defer os.Remove(f.Name())
163 defer f.Close()
Colin Cross3f40fa42015-01-30 17:27:36 -0800164
Colin Crossd8f20142016-11-03 09:43:26 -0700165 _, err = f.Write(data)
Colin Cross3f40fa42015-01-30 17:27:36 -0800166 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700167 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
168 }
169
Colin Crossd8f20142016-11-03 09:43:26 -0700170 _, err = f.WriteString("\n")
Colin Cross485e5722015-08-27 13:28:01 -0700171 if err != nil {
172 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800173 }
174
Colin Crossd8f20142016-11-03 09:43:26 -0700175 f.Close()
176 os.Rename(f.Name(), filename)
177
Colin Cross3f40fa42015-01-30 17:27:36 -0800178 return nil
179}
180
Colin Crossce75d2c2016-10-06 16:12:58 -0700181// TestConfig returns a Config object suitable for using for tests
Colin Cross6ccbc912017-10-10 23:07:38 -0700182func TestConfig(buildDir string, env map[string]string) Config {
Dan Willemsen00269f22017-07-06 16:59:48 -0700183 config := &config{
184 ProductVariables: productVariables{
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800185 DeviceName: stringPtr("test_device"),
186 Platform_sdk_version: intPtr(26),
187 AAPTConfig: &[]string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"},
188 AAPTPreferredConfig: stringPtr("xhdpi"),
189 AAPTCharacteristics: stringPtr("nosdcard"),
190 AAPTPrebuiltDPI: &[]string{"xhdpi", "xxhdpi"},
Dan Willemsen00269f22017-07-06 16:59:48 -0700191 },
192
Colin Cross6ccbc912017-10-10 23:07:38 -0700193 buildDir: buildDir,
194 captureBuild: true,
195 env: env,
Dan Willemsen00269f22017-07-06 16:59:48 -0700196 }
197 config.deviceConfig = &deviceConfig{
198 config: config,
199 }
200
Colin Cross1369cdb2017-09-29 17:58:17 -0700201 if err := config.fromEnv(); err != nil {
202 panic(err)
203 }
204
Dan Willemsen00269f22017-07-06 16:59:48 -0700205 return Config{config}
Colin Crossce75d2c2016-10-06 16:12:58 -0700206}
207
Colin Crossae4c6182017-09-15 17:33:55 -0700208// TestConfig returns a Config object suitable for using for tests that need to run the arch mutator
Colin Cross6ccbc912017-10-10 23:07:38 -0700209func TestArchConfig(buildDir string, env map[string]string) Config {
210 testConfig := TestConfig(buildDir, env)
Colin Crossae4c6182017-09-15 17:33:55 -0700211 config := testConfig.config
212
213 config.Targets = map[OsClass][]Target{
214 Device: []Target{
Jiyong Park6a43f042017-10-12 23:05:00 +0900215 {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Native: true}},
216 {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Native: true}},
Colin Crossae4c6182017-09-15 17:33:55 -0700217 },
218 Host: []Target{
219 {BuildOs, Arch{ArchType: X86_64}},
220 {BuildOs, Arch{ArchType: X86}},
221 },
222 }
223
224 return testConfig
225}
226
Colin Cross3f40fa42015-01-30 17:27:36 -0800227// New creates a new Config object. The srcDir argument specifies the path to
228// the root source directory. It also loads the config file, if found.
Dan Willemsen87b17d12015-07-14 00:39:06 -0700229func NewConfig(srcDir, buildDir string) (Config, error) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800230 // Make a config with default options
Colin Cross9272ade2016-08-17 15:24:12 -0700231 config := &config{
232 ConfigFileName: filepath.Join(buildDir, configFileName),
233 ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName),
Dan Willemsen87b17d12015-07-14 00:39:06 -0700234
Colin Cross6ccbc912017-10-10 23:07:38 -0700235 env: originalEnv,
236
Colin Cross9272ade2016-08-17 15:24:12 -0700237 srcDir: srcDir,
238 buildDir: buildDir,
Colin Cross68f55102015-03-25 14:43:57 -0700239 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800240
Dan Willemsen00269f22017-07-06 16:59:48 -0700241 config.deviceConfig = &deviceConfig{
Colin Cross9272ade2016-08-17 15:24:12 -0700242 config: config,
243 }
244
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700245 // Sanity check the build and source directories. This won't catch strange
246 // configurations with symlinks, but at least checks the obvious cases.
247 absBuildDir, err := filepath.Abs(buildDir)
248 if err != nil {
249 return Config{}, err
250 }
251
252 absSrcDir, err := filepath.Abs(srcDir)
253 if err != nil {
254 return Config{}, err
255 }
256
257 if strings.HasPrefix(absSrcDir, absBuildDir) {
258 return Config{}, fmt.Errorf("Build dir must not contain source directory")
259 }
260
Colin Cross3f40fa42015-01-30 17:27:36 -0800261 // Load any configurable options from the configuration file
Colin Cross9272ade2016-08-17 15:24:12 -0700262 err = loadConfig(config)
Colin Cross3f40fa42015-01-30 17:27:36 -0800263 if err != nil {
Colin Crossc3c0a492015-04-10 15:43:55 -0700264 return Config{}, err
Colin Cross3f40fa42015-01-30 17:27:36 -0800265 }
266
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800267 inMakeFile := filepath.Join(buildDir, ".soong.in_make")
268 if _, err := os.Stat(inMakeFile); err == nil {
269 config.inMake = true
270 }
271
Colin Crossa1ad8d12016-06-01 17:09:44 -0700272 targets, err := decodeTargetProductVariables(config)
Dan Willemsen218f6562015-07-08 18:13:11 -0700273 if err != nil {
274 return Config{}, err
275 }
276
Dan Albert4098deb2016-10-19 14:04:41 -0700277 var archConfig []archConfig
Dan Willemsen322acaf2016-01-12 23:07:05 -0800278 if Bool(config.Mega_device) {
Dan Albert4098deb2016-10-19 14:04:41 -0700279 archConfig = getMegaDeviceConfig()
280 } else if Bool(config.Ndk_abis) {
281 archConfig = getNdkAbisConfig()
282 }
283
284 if archConfig != nil {
285 deviceTargets, err := decodeArchSettings(archConfig)
Dan Willemsen322acaf2016-01-12 23:07:05 -0800286 if err != nil {
287 return Config{}, err
288 }
Colin Crossa1ad8d12016-06-01 17:09:44 -0700289 targets[Device] = deviceTargets
Dan Willemsen322acaf2016-01-12 23:07:05 -0800290 }
291
Colin Crossa1ad8d12016-06-01 17:09:44 -0700292 config.Targets = targets
293 config.BuildOsVariant = targets[Host][0].String()
Dan Willemsen218f6562015-07-08 18:13:11 -0700294
Colin Cross1369cdb2017-09-29 17:58:17 -0700295 if err := config.fromEnv(); err != nil {
296 return Config{}, err
297 }
298
Colin Cross9272ade2016-08-17 15:24:12 -0700299 return Config{config}, nil
Colin Cross3f40fa42015-01-30 17:27:36 -0800300}
301
Colin Cross1369cdb2017-09-29 17:58:17 -0700302func (c *config) fromEnv() error {
303 switch c.Getenv("EXPERIMENTAL_USE_OPENJDK9") {
304 case "":
Tobias Thierer18099fd2017-11-17 14:14:29 +0000305 if c.Getenv("RUN_ERROR_PRONE") != "true" {
306 // Use OpenJDK9, but target 1.8
307 c.useOpenJDK9 = true
308 }
Tobias Thierera7cdd152017-11-15 21:16:25 +0000309 case "false":
310 // Use OpenJDK8
Colin Cross1369cdb2017-09-29 17:58:17 -0700311 case "1.8":
312 // Use OpenJDK9, but target 1.8
313 c.useOpenJDK9 = true
314 case "true":
315 // Use OpenJDK9 and target 1.9
316 c.useOpenJDK9 = true
317 c.targetOpenJDK9 = true
318 default:
Tobias Thierer18099fd2017-11-17 14:14:29 +0000319 return fmt.Errorf(`Invalid value for EXPERIMENTAL_USE_OPENJDK9, should be "", "false", "1.8", or "true"`)
Colin Cross1369cdb2017-09-29 17:58:17 -0700320 }
321
322 return nil
323}
324
Colin Crosse87040b2017-12-11 15:52:26 -0800325func (c *config) StopBefore() bootstrap.StopBefore {
326 return c.stopBefore
Dan Willemsen218f6562015-07-08 18:13:11 -0700327}
328
Colin Crosse87040b2017-12-11 15:52:26 -0800329func (c *config) SetStopBefore(stopBefore bootstrap.StopBefore) {
330 c.stopBefore = stopBefore
331}
332
333var _ bootstrap.ConfigStopBefore = (*config)(nil)
334
Dan Willemsenc2aa4a92016-05-26 15:13:03 -0700335func (c *config) BlueprintToolLocation() string {
336 return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin")
337}
338
Colin Crosse87040b2017-12-11 15:52:26 -0800339var _ bootstrap.ConfigBlueprintToolLocation = (*config)(nil)
340
Dan Willemsen66068722017-05-08 21:15:59 +0000341// HostSystemTool looks for non-hermetic tools from the system we're running on.
342// Generally shouldn't be used, but useful to find the XCode SDK, etc.
343func (c *config) HostSystemTool(name string) string {
344 for _, dir := range filepath.SplitList(c.Getenv("PATH")) {
345 path := filepath.Join(dir, name)
346 if s, err := os.Stat(path); err != nil {
347 continue
348 } else if m := s.Mode(); !s.IsDir() && m&0111 != 0 {
349 return path
350 }
351 }
352 return name
353}
354
Colin Cross3f40fa42015-01-30 17:27:36 -0800355// PrebuiltOS returns the name of the host OS used in prebuilts directories
Colin Cross1332b002015-04-07 17:11:30 -0700356func (c *config) PrebuiltOS() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800357 switch runtime.GOOS {
358 case "linux":
359 return "linux-x86"
360 case "darwin":
361 return "darwin-x86"
362 default:
363 panic("Unknown GOOS")
364 }
365}
366
367// GoRoot returns the path to the root directory of the Go toolchain.
Colin Cross1332b002015-04-07 17:11:30 -0700368func (c *config) GoRoot() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800369 return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS())
370}
371
Colin Cross1332b002015-04-07 17:11:30 -0700372func (c *config) CpPreserveSymlinksFlags() string {
Colin Cross485e5722015-08-27 13:28:01 -0700373 switch runtime.GOOS {
Colin Cross3f40fa42015-01-30 17:27:36 -0800374 case "darwin":
375 return "-R"
376 case "linux":
377 return "-d"
378 default:
379 return ""
380 }
381}
Colin Cross68f55102015-03-25 14:43:57 -0700382
Colin Cross1332b002015-04-07 17:11:30 -0700383func (c *config) Getenv(key string) string {
Colin Cross68f55102015-03-25 14:43:57 -0700384 var val string
385 var exists bool
Colin Crossc1e86a32015-04-15 12:33:28 -0700386 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800387 defer c.envLock.Unlock()
388 if c.envDeps == nil {
389 c.envDeps = make(map[string]string)
390 }
Colin Cross68f55102015-03-25 14:43:57 -0700391 if val, exists = c.envDeps[key]; !exists {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700392 if c.envFrozen {
393 panic("Cannot access new environment variables after envdeps are frozen")
394 }
Colin Cross6ccbc912017-10-10 23:07:38 -0700395 val, _ = c.env[key]
Colin Cross68f55102015-03-25 14:43:57 -0700396 c.envDeps[key] = val
397 }
398 return val
399}
400
Colin Cross99d7c232016-11-23 16:52:04 -0800401func (c *config) GetenvWithDefault(key string, defaultValue string) string {
402 ret := c.Getenv(key)
403 if ret == "" {
404 return defaultValue
405 }
406 return ret
407}
408
409func (c *config) IsEnvTrue(key string) bool {
410 value := c.Getenv(key)
411 return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
412}
413
414func (c *config) IsEnvFalse(key string) bool {
415 value := c.Getenv(key)
416 return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
417}
418
Colin Cross1332b002015-04-07 17:11:30 -0700419func (c *config) EnvDeps() map[string]string {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700420 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800421 defer c.envLock.Unlock()
Dan Willemsene7680ba2015-09-11 17:06:19 -0700422 c.envFrozen = true
Colin Cross68f55102015-03-25 14:43:57 -0700423 return c.envDeps
424}
Colin Cross35cec122015-04-02 14:37:16 -0700425
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800426func (c *config) EmbeddedInMake() bool {
427 return c.inMake
428}
429
Nan Zhang581fd212018-01-10 16:06:12 -0800430func (c *config) BuildId() string {
431 return String(c.ProductVariables.BuildId)
432}
433
434func (c *config) BuildNumberFromFile() string {
435 return String(c.ProductVariables.BuildNumberFromFile)
436}
437
Colin Cross35cec122015-04-02 14:37:16 -0700438// DeviceName returns the name of the current device target
439// TODO: take an AndroidModuleContext to select the device name for multi-device builds
Colin Cross1332b002015-04-07 17:11:30 -0700440func (c *config) DeviceName() string {
Dan Willemsen1d31ec32015-09-22 16:56:09 -0700441 return *c.ProductVariables.DeviceName
Colin Cross35cec122015-04-02 14:37:16 -0700442}
443
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800444func (c *config) ResourceOverlays() []string {
445 if c.ProductVariables.ResourceOverlays == nil {
446 return nil
447 }
448 return *c.ProductVariables.ResourceOverlays
Colin Cross30e076a2015-04-13 13:58:27 -0700449}
450
Dan Albert073379e2016-11-10 10:46:36 -0800451func (c *config) PlatformSdkVersionInt() int {
452 return *c.ProductVariables.Platform_sdk_version
453}
454
Colin Cross30e076a2015-04-13 13:58:27 -0700455func (c *config) PlatformSdkVersion() string {
Dan Albert073379e2016-11-10 10:46:36 -0800456 return strconv.Itoa(c.PlatformSdkVersionInt())
Colin Cross30e076a2015-04-13 13:58:27 -0700457}
458
Dan Albertf5415d72017-08-17 16:19:59 -0700459func (c *config) MinSupportedSdkVersion() int {
Dan Albertd4db4ac2017-08-10 12:18:31 -0700460 return 14
Dan Albertf5415d72017-08-17 16:19:59 -0700461}
462
Colin Cross595a4062017-08-31 12:30:37 -0700463func (c *config) DefaultAppTargetSdkInt() int {
464 if Bool(c.ProductVariables.Platform_sdk_final) {
465 return c.PlatformSdkVersionInt()
466 } else {
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900467 return FutureApiLevel
Colin Cross595a4062017-08-31 12:30:37 -0700468 }
469}
470
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800471func (c *config) AppsDefaultVersionName() string {
472 return String(c.ProductVariables.AppsDefaultVersionName)
473}
474
Dan Albert31384de2017-07-28 12:39:46 -0700475// Codenames that are active in the current lunch target.
476func (c *config) PlatformVersionActiveCodenames() []string {
477 return c.ProductVariables.Platform_version_active_codenames
478}
479
480// Codenames that are available in the branch but not included in the current
481// lunch target.
482func (c *config) PlatformVersionFutureCodenames() []string {
483 return c.ProductVariables.Platform_version_future_codenames
484}
485
486// All possible codenames in the current branch. NB: Not named AllCodenames
487// because "all" has historically meant "active" in make, and still does in
488// build.prop.
489func (c *config) PlatformVersionCombinedCodenames() []string {
490 combined := []string{}
491 combined = append(combined, c.PlatformVersionActiveCodenames()...)
492 combined = append(combined, c.PlatformVersionFutureCodenames()...)
493 return combined
Dan Albert30c9d6e2017-03-28 14:54:55 -0700494}
495
Colin Crossface4e42017-10-30 17:32:15 -0700496func (c *config) ProductAAPTConfig() []string {
Colin Crosse15ddaf2017-12-04 11:24:31 -0800497 return stringSlice(c.ProductVariables.AAPTConfig)
Colin Cross30e076a2015-04-13 13:58:27 -0700498}
499
Colin Crossface4e42017-10-30 17:32:15 -0700500func (c *config) ProductAAPTPreferredConfig() string {
Colin Crosse15ddaf2017-12-04 11:24:31 -0800501 return String(c.ProductVariables.AAPTPreferredConfig)
Colin Cross30e076a2015-04-13 13:58:27 -0700502}
503
Colin Crossface4e42017-10-30 17:32:15 -0700504func (c *config) ProductAAPTCharacteristics() string {
Colin Crosse15ddaf2017-12-04 11:24:31 -0800505 return String(c.ProductVariables.AAPTCharacteristics)
Colin Crossface4e42017-10-30 17:32:15 -0700506}
507
508func (c *config) ProductAAPTPrebuiltDPI() []string {
Colin Crosse15ddaf2017-12-04 11:24:31 -0800509 return stringSlice(c.ProductVariables.AAPTPrebuiltDPI)
Colin Cross30e076a2015-04-13 13:58:27 -0700510}
511
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700512func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
Colin Cross61ae0b72017-12-01 17:16:02 -0800513 defaultCert := String(c.ProductVariables.DefaultAppCertificate)
514 if defaultCert != "" {
515 return PathForSource(ctx, filepath.Dir(defaultCert))
516 } else {
517 return PathForSource(ctx, "build/target/product/security")
518 }
Colin Cross30e076a2015-04-13 13:58:27 -0700519}
520
Colin Crosse1731a52017-12-14 11:22:55 -0800521func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) {
Colin Cross61ae0b72017-12-01 17:16:02 -0800522 defaultCert := String(c.ProductVariables.DefaultAppCertificate)
523 if defaultCert != "" {
Colin Crosse1731a52017-12-14 11:22:55 -0800524 return PathForSource(ctx, defaultCert+".x509.pem"), PathForSource(ctx, defaultCert+".pk8")
Colin Cross61ae0b72017-12-01 17:16:02 -0800525 } else {
Colin Crosse1731a52017-12-14 11:22:55 -0800526 defaultDir := c.DefaultAppCertificateDir(ctx)
527 return defaultDir.Join(ctx, "testkey.x509.pem"), defaultDir.Join(ctx, "testkey.pk8")
Colin Cross61ae0b72017-12-01 17:16:02 -0800528 }
Colin Cross30e076a2015-04-13 13:58:27 -0700529}
Colin Cross6ff51382015-12-17 16:39:19 -0800530
531func (c *config) AllowMissingDependencies() bool {
Dan Willemsenb5038162016-03-16 12:35:33 -0700532 return Bool(c.ProductVariables.Allow_missing_dependencies)
Colin Cross6ff51382015-12-17 16:39:19 -0800533}
Dan Willemsen322acaf2016-01-12 23:07:05 -0800534
Colin Crossfc3674a2017-09-18 17:41:52 -0700535func (c *config) UnbundledBuild() bool {
536 return Bool(c.ProductVariables.Unbundled_build)
537}
538
Colin Cross0d3f8c02017-10-24 10:51:45 -0700539func (c *config) IsPdkBuild() bool {
540 return Bool(c.ProductVariables.Pdk)
541}
542
Colin Cross126a25c2017-10-31 13:55:34 -0700543func (c *config) MinimizeJavaDebugInfo() bool {
544 return Bool(c.ProductVariables.MinimizeJavaDebugInfo) && !Bool(c.ProductVariables.Eng)
545}
546
Colin Cross1e7d3702016-08-24 15:25:47 -0700547func (c *config) DevicePrefer32BitExecutables() bool {
548 return Bool(c.ProductVariables.DevicePrefer32BitExecutables)
549}
550
Dan Willemsen7f730fd2016-01-14 11:22:23 -0800551func (c *config) SkipDeviceInstall() bool {
Colin Cross893d8162017-04-26 17:34:03 -0700552 return c.EmbeddedInMake()
553}
554
555func (c *config) SkipMegaDeviceInstall(path string) bool {
556 return Bool(c.Mega_device) &&
557 strings.HasPrefix(path, filepath.Join(c.buildDir, "target", "product"))
Dan Willemsen322acaf2016-01-12 23:07:05 -0800558}
Colin Cross16b23492016-01-06 14:41:07 -0800559
560func (c *config) SanitizeHost() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700561 return append([]string(nil), c.ProductVariables.SanitizeHost...)
Colin Cross16b23492016-01-06 14:41:07 -0800562}
563
564func (c *config) SanitizeDevice() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700565 return append([]string(nil), c.ProductVariables.SanitizeDevice...)
566}
567
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700568func (c *config) SanitizeDeviceDiag() []string {
569 return append([]string(nil), c.ProductVariables.SanitizeDeviceDiag...)
570}
571
Colin Cross23ae82a2016-11-02 14:34:39 -0700572func (c *config) SanitizeDeviceArch() []string {
573 return append([]string(nil), c.ProductVariables.SanitizeDeviceArch...)
Colin Cross16b23492016-01-06 14:41:07 -0800574}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700575
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800576func (c *config) EnableCFI() bool {
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -0800577 if c.ProductVariables.EnableCFI == nil {
578 return true
579 } else {
580 return *c.ProductVariables.EnableCFI
581 }
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800582}
583
Colin Crossa1ad8d12016-06-01 17:09:44 -0700584func (c *config) Android64() bool {
585 for _, t := range c.Targets[Device] {
586 if t.Arch.ArchType.Multilib == "lib64" {
587 return true
588 }
589 }
590
591 return false
592}
Colin Cross9272ade2016-08-17 15:24:12 -0700593
Alan Leungc37c6342017-12-13 00:28:49 -0800594func (c *config) UseD8Desugar() bool {
Alan Leunge2fb6292017-12-20 01:15:56 -0800595 return !c.IsEnvFalse("USE_D8_DESUGAR")
Alan Leungc37c6342017-12-13 00:28:49 -0800596}
597
Colin Cross9d45bb72016-08-29 16:14:13 -0700598func (c *config) UseGoma() bool {
599 return Bool(c.ProductVariables.UseGoma)
600}
601
Colin Cross1369cdb2017-09-29 17:58:17 -0700602// Returns true if OpenJDK9 prebuilts are being used
603func (c *config) UseOpenJDK9() bool {
604 return c.useOpenJDK9
605}
606
607// Returns true if -source 1.9 -target 1.9 is being passed to javac
608func (c *config) TargetOpenJDK9() bool {
609 return c.targetOpenJDK9
610}
611
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700612func (c *config) ClangTidy() bool {
613 return Bool(c.ProductVariables.ClangTidy)
614}
615
616func (c *config) TidyChecks() string {
617 if c.ProductVariables.TidyChecks == nil {
618 return ""
619 }
620 return *c.ProductVariables.TidyChecks
621}
622
Colin Cross0f4e0d62016-07-27 10:56:55 -0700623func (c *config) LibartImgHostBaseAddress() string {
624 return "0x60000000"
625}
626
627func (c *config) LibartImgDeviceBaseAddress() string {
Colin Cross20e13652017-06-22 15:34:51 -0700628 archType := Common
629 if len(c.Targets[Device]) > 0 {
630 archType = c.Targets[Device][0].Arch.ArchType
631 }
632 switch archType {
Colin Cross0f4e0d62016-07-27 10:56:55 -0700633 default:
634 return "0x70000000"
635 case Mips, Mips64:
Chris Larsenae7f3e22017-05-30 16:36:58 -0700636 return "0x5C000000"
Colin Cross0f4e0d62016-07-27 10:56:55 -0700637 }
638}
639
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800640func (c *config) ArtUseReadBarrier() bool {
641 return Bool(c.ProductVariables.ArtUseReadBarrier)
642}
643
Colin Cross9272ade2016-08-17 15:24:12 -0700644func (c *deviceConfig) Arches() []Arch {
645 var arches []Arch
646 for _, target := range c.config.Targets[Device] {
647 arches = append(arches, target.Arch)
648 }
649 return arches
650}
Dan Willemsend2ede872016-11-18 14:54:24 -0800651
Jayant Chowdhary34ce67d2018-03-08 11:00:50 -0800652func (c *deviceConfig) BinderBitness() string {
653 is32BitBinder := c.config.ProductVariables.Binder32bit
654 if is32BitBinder != nil && *is32BitBinder {
655 return "32"
656 }
657 return "64"
658}
659
Dan Willemsen4353bc42016-12-05 17:16:02 -0800660func (c *deviceConfig) VendorPath() string {
661 if c.config.ProductVariables.VendorPath != nil {
662 return *c.config.ProductVariables.VendorPath
663 }
664 return "vendor"
665}
666
Justin Yun71549282017-11-17 12:10:28 +0900667func (c *deviceConfig) VndkVersion() string {
668 return String(c.config.ProductVariables.DeviceVndkVersion)
669}
670
Justin Yun8fe12122017-12-07 17:18:15 +0900671func (c *deviceConfig) PlatformVndkVersion() string {
672 return String(c.config.ProductVariables.Platform_vndk_version)
673}
674
Justin Yun71549282017-11-17 12:10:28 +0900675func (c *deviceConfig) ExtraVndkVersions() []string {
676 return c.config.ProductVariables.ExtraVndkVersions
Dan Willemsend2ede872016-11-18 14:54:24 -0800677}
Jack He8cc71432016-12-08 15:45:07 -0800678
Jiyong Park1a5d7b12018-01-15 15:05:10 +0900679func (c *deviceConfig) SystemSdkVersions() []string {
680 if c.config.ProductVariables.DeviceSystemSdkVersions == nil {
681 return nil
682 }
683 return *c.config.ProductVariables.DeviceSystemSdkVersions
684}
685
686func (c *deviceConfig) PlatformSystemSdkVersions() []string {
687 return c.config.ProductVariables.Platform_systemsdk_versions
688}
689
Jiyong Park2db76922017-11-08 16:03:48 +0900690func (c *deviceConfig) OdmPath() string {
691 if c.config.ProductVariables.OdmPath != nil {
692 return *c.config.ProductVariables.OdmPath
693 }
694 return "odm"
695}
696
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900697func (c *deviceConfig) ProductPath() string {
698 if c.config.ProductVariables.ProductPath != nil {
699 return *c.config.ProductVariables.ProductPath
Jiyong Park2db76922017-11-08 16:03:48 +0900700 }
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900701 return "product"
Jiyong Park2db76922017-11-08 16:03:48 +0900702}
703
Jack He8cc71432016-12-08 15:45:07 -0800704func (c *deviceConfig) BtConfigIncludeDir() string {
705 return String(c.config.ProductVariables.BtConfigIncludeDir)
706}
Dan Willemsen581341d2017-02-09 16:16:31 -0800707
Jiyong Parkd773eb32017-07-03 13:18:12 +0900708func (c *deviceConfig) DeviceKernelHeaderDirs() []string {
709 return c.config.ProductVariables.DeviceKernelHeaders
710}
711
Dan Willemsen581341d2017-02-09 16:16:31 -0800712func (c *deviceConfig) NativeCoverageEnabled() bool {
713 return Bool(c.config.ProductVariables.NativeCoverage)
714}
715
716func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
Ryan Campbell469a18a2017-02-27 09:01:54 -0800717 coverage := false
Dan Willemsen581341d2017-02-09 16:16:31 -0800718 if c.config.ProductVariables.CoveragePaths != nil {
Colin Crossb4330e22017-12-22 15:47:09 -0800719 if PrefixInList(path, *c.config.ProductVariables.CoveragePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -0700720 coverage = true
Dan Willemsen581341d2017-02-09 16:16:31 -0800721 }
722 }
Ryan Campbell469a18a2017-02-27 09:01:54 -0800723 if coverage && c.config.ProductVariables.CoverageExcludePaths != nil {
Colin Crossb4330e22017-12-22 15:47:09 -0800724 if PrefixInList(path, *c.config.ProductVariables.CoverageExcludePaths) {
Ivan Lozano5f595532017-07-13 14:46:05 -0700725 coverage = false
Ryan Campbell469a18a2017-02-27 09:01:54 -0800726 }
727 }
728 return coverage
Dan Willemsen581341d2017-02-09 16:16:31 -0800729}
Ivan Lozano5f595532017-07-13 14:46:05 -0700730
Pirama Arumuga Nainar49540802018-01-29 23:11:42 -0800731func (c *deviceConfig) PgoAdditionalProfileDirs() []string {
732 return c.config.ProductVariables.PgoAdditionalProfileDirs
733}
734
Ivan Lozano5f595532017-07-13 14:46:05 -0700735func (c *config) IntegerOverflowDisabledForPath(path string) bool {
736 if c.ProductVariables.IntegerOverflowExcludePaths == nil {
737 return false
738 }
Colin Crossb4330e22017-12-22 15:47:09 -0800739 return PrefixInList(path, *c.ProductVariables.IntegerOverflowExcludePaths)
Ivan Lozano5f595532017-07-13 14:46:05 -0700740}
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700741
742func (c *config) CFIDisabledForPath(path string) bool {
743 if c.ProductVariables.CFIExcludePaths == nil {
744 return false
745 }
Colin Crossb4330e22017-12-22 15:47:09 -0800746 return PrefixInList(path, *c.ProductVariables.CFIExcludePaths)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700747}
748
749func (c *config) CFIEnabledForPath(path string) bool {
750 if c.ProductVariables.CFIIncludePaths == nil {
751 return false
752 }
Colin Crossb4330e22017-12-22 15:47:09 -0800753 return PrefixInList(path, *c.ProductVariables.CFIIncludePaths)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700754}
Colin Crosse15ddaf2017-12-04 11:24:31 -0800755
756func stringSlice(s *[]string) []string {
757 if s != nil {
758 return *s
759 } else {
760 return nil
761 }
762}