blob: f30a708c688e8fbd8af9d9200d7e57f2d66f3874 [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
28 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080029)
30
Colin Cross6ff51382015-12-17 16:39:19 -080031var Bool = proptools.Bool
Jack He8cc71432016-12-08 15:45:07 -080032var String = proptools.String
Colin Cross6ff51382015-12-17 16:39:19 -080033
Colin Cross3f40fa42015-01-30 17:27:36 -080034// The configuration file name
Dan Willemsen87b17d12015-07-14 00:39:06 -070035const configFileName = "soong.config"
36const productVariablesFileName = "soong.variables"
Colin Cross3f40fa42015-01-30 17:27:36 -080037
38// A FileConfigurableOptions contains options which can be configured by the
39// config file. These will be included in the config struct.
40type FileConfigurableOptions struct {
Dan Willemsen322acaf2016-01-12 23:07:05 -080041 Mega_device *bool `json:",omitempty"`
Dan Albert4098deb2016-10-19 14:04:41 -070042 Ndk_abis *bool `json:",omitempty"`
Dan Willemsen01a405a2016-06-13 17:19:03 -070043 Host_bionic *bool `json:",omitempty"`
Colin Cross3f40fa42015-01-30 17:27:36 -080044}
45
Colin Cross27385972015-09-18 10:57:10 -070046func (f *FileConfigurableOptions) SetDefaultConfig() {
47 *f = FileConfigurableOptions{}
Colin Cross3f40fa42015-01-30 17:27:36 -080048}
49
Colin Cross9272ade2016-08-17 15:24:12 -070050// A Config object represents the entire build configuration for Android.
Colin Crossc3c0a492015-04-10 15:43:55 -070051type Config struct {
52 *config
53}
54
Jeff Gastonefc1b412017-03-29 17:29:06 -070055func (c Config) BuildDir() string {
56 return c.buildDir
57}
58
Colin Cross9272ade2016-08-17 15:24:12 -070059// A DeviceConfig object represents the configuration for a particular device being built. For
60// now there will only be one of these, but in the future there may be multiple devices being
61// built
62type DeviceConfig struct {
63 *deviceConfig
64}
65
Colin Cross1332b002015-04-07 17:11:30 -070066type config struct {
Colin Cross3f40fa42015-01-30 17:27:36 -080067 FileConfigurableOptions
Colin Cross485e5722015-08-27 13:28:01 -070068 ProductVariables productVariables
Colin Cross3f40fa42015-01-30 17:27:36 -080069
Dan Willemsen87b17d12015-07-14 00:39:06 -070070 ConfigFileName string
71 ProductVariablesFileName string
72
Colin Crossa1ad8d12016-06-01 17:09:44 -070073 Targets map[OsClass][]Target
74 BuildOsVariant string
Dan Willemsen218f6562015-07-08 18:13:11 -070075
Colin Cross9272ade2016-08-17 15:24:12 -070076 deviceConfig *deviceConfig
77
Dan Willemsen87b17d12015-07-14 00:39:06 -070078 srcDir string // the path of the root source directory
79 buildDir string // the path of the build output directory
Colin Crossc1e86a32015-04-15 12:33:28 -070080
Dan Willemsene7680ba2015-09-11 17:06:19 -070081 envLock sync.Mutex
82 envDeps map[string]string
83 envFrozen bool
Dan Willemsen5ba07e82015-12-11 13:51:06 -080084
85 inMake bool
Colin Cross1e7d3702016-08-24 15:25:47 -070086
Colin Cross32616ed2017-09-05 21:56:44 -070087 captureBuild bool // true for tests, saves build parameters for each module
88 ignoreEnvironment bool // true for tests, returns empty from all Getenv calls
Colin Crosscec81712017-07-13 14:43:27 -070089
Colin Cross9272ade2016-08-17 15:24:12 -070090 OncePer
91}
92
93type deviceConfig struct {
Dan Willemsen00269f22017-07-06 16:59:48 -070094 config *config
Colin Cross9272ade2016-08-17 15:24:12 -070095 OncePer
Colin Cross3f40fa42015-01-30 17:27:36 -080096}
97
Colin Cross485e5722015-08-27 13:28:01 -070098type jsonConfigurable interface {
Colin Cross27385972015-09-18 10:57:10 -070099 SetDefaultConfig()
Colin Cross485e5722015-08-27 13:28:01 -0700100}
Colin Cross3f40fa42015-01-30 17:27:36 -0800101
Colin Cross485e5722015-08-27 13:28:01 -0700102func loadConfig(config *config) error {
Dan Willemsen87b17d12015-07-14 00:39:06 -0700103 err := loadFromConfigFile(&config.FileConfigurableOptions, config.ConfigFileName)
Colin Cross485e5722015-08-27 13:28:01 -0700104 if err != nil {
105 return err
106 }
107
Dan Willemsen87b17d12015-07-14 00:39:06 -0700108 return loadFromConfigFile(&config.ProductVariables, config.ProductVariablesFileName)
Colin Cross485e5722015-08-27 13:28:01 -0700109}
110
111// loads configuration options from a JSON file in the cwd.
112func loadFromConfigFile(configurable jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800113 // Try to open the file
Colin Cross485e5722015-08-27 13:28:01 -0700114 configFileReader, err := os.Open(filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800115 defer configFileReader.Close()
116 if os.IsNotExist(err) {
117 // Need to create a file, so that blueprint & ninja don't get in
118 // a dependency tracking loop.
119 // Make a file-configurable-options with defaults, write it out using
120 // a json writer.
Colin Cross27385972015-09-18 10:57:10 -0700121 configurable.SetDefaultConfig()
122 err = saveToConfigFile(configurable, filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800123 if err != nil {
124 return err
125 }
126 } else {
127 // Make a decoder for it
128 jsonDecoder := json.NewDecoder(configFileReader)
Colin Cross485e5722015-08-27 13:28:01 -0700129 err = jsonDecoder.Decode(configurable)
Colin Cross3f40fa42015-01-30 17:27:36 -0800130 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700131 return fmt.Errorf("config file: %s did not parse correctly: "+err.Error(), filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800132 }
133 }
134
Colin Cross3f40fa42015-01-30 17:27:36 -0800135 // No error
136 return nil
137}
138
Colin Crossd8f20142016-11-03 09:43:26 -0700139// atomically writes the config file in case two copies of soong_build are running simultaneously
140// (for example, docs generation and ninja manifest generation)
Colin Cross485e5722015-08-27 13:28:01 -0700141func saveToConfigFile(config jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800142 data, err := json.MarshalIndent(&config, "", " ")
143 if err != nil {
144 return fmt.Errorf("cannot marshal config data: %s", err.Error())
145 }
146
Colin Crossd8f20142016-11-03 09:43:26 -0700147 f, err := ioutil.TempFile(filepath.Dir(filename), "config")
Colin Cross3f40fa42015-01-30 17:27:36 -0800148 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700149 return fmt.Errorf("cannot create empty config file %s: %s\n", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800150 }
Colin Crossd8f20142016-11-03 09:43:26 -0700151 defer os.Remove(f.Name())
152 defer f.Close()
Colin Cross3f40fa42015-01-30 17:27:36 -0800153
Colin Crossd8f20142016-11-03 09:43:26 -0700154 _, err = f.Write(data)
Colin Cross3f40fa42015-01-30 17:27:36 -0800155 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700156 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
157 }
158
Colin Crossd8f20142016-11-03 09:43:26 -0700159 _, err = f.WriteString("\n")
Colin Cross485e5722015-08-27 13:28:01 -0700160 if err != nil {
161 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800162 }
163
Colin Crossd8f20142016-11-03 09:43:26 -0700164 f.Close()
165 os.Rename(f.Name(), filename)
166
Colin Cross3f40fa42015-01-30 17:27:36 -0800167 return nil
168}
169
Colin Crossce75d2c2016-10-06 16:12:58 -0700170// TestConfig returns a Config object suitable for using for tests
Colin Cross0d614dd2016-10-14 15:38:43 -0700171func TestConfig(buildDir string) Config {
Dan Willemsen00269f22017-07-06 16:59:48 -0700172 config := &config{
173 ProductVariables: productVariables{
174 DeviceName: stringPtr("test_device"),
175 },
176
Colin Cross32616ed2017-09-05 21:56:44 -0700177 buildDir: buildDir,
178 captureBuild: true,
179 ignoreEnvironment: true,
Dan Willemsen00269f22017-07-06 16:59:48 -0700180 }
181 config.deviceConfig = &deviceConfig{
182 config: config,
183 }
184
185 return Config{config}
Colin Crossce75d2c2016-10-06 16:12:58 -0700186}
187
Colin Crossae4c6182017-09-15 17:33:55 -0700188// TestConfig returns a Config object suitable for using for tests that need to run the arch mutator
189func TestArchConfig(buildDir string) Config {
190 testConfig := TestConfig(buildDir)
191 config := testConfig.config
192
193 config.Targets = map[OsClass][]Target{
194 Device: []Target{
195 {Android, Arch{ArchType: Arm64, Native: true}},
196 {Android, Arch{ArchType: Arm, Native: true}},
197 },
198 Host: []Target{
199 {BuildOs, Arch{ArchType: X86_64}},
200 {BuildOs, Arch{ArchType: X86}},
201 },
202 }
203
204 return testConfig
205}
206
Colin Cross3f40fa42015-01-30 17:27:36 -0800207// New creates a new Config object. The srcDir argument specifies the path to
208// the root source directory. It also loads the config file, if found.
Dan Willemsen87b17d12015-07-14 00:39:06 -0700209func NewConfig(srcDir, buildDir string) (Config, error) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800210 // Make a config with default options
Colin Cross9272ade2016-08-17 15:24:12 -0700211 config := &config{
212 ConfigFileName: filepath.Join(buildDir, configFileName),
213 ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName),
Dan Willemsen87b17d12015-07-14 00:39:06 -0700214
Colin Cross9272ade2016-08-17 15:24:12 -0700215 srcDir: srcDir,
216 buildDir: buildDir,
Colin Cross68f55102015-03-25 14:43:57 -0700217 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800218
Dan Willemsen00269f22017-07-06 16:59:48 -0700219 config.deviceConfig = &deviceConfig{
Colin Cross9272ade2016-08-17 15:24:12 -0700220 config: config,
221 }
222
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700223 // Sanity check the build and source directories. This won't catch strange
224 // configurations with symlinks, but at least checks the obvious cases.
225 absBuildDir, err := filepath.Abs(buildDir)
226 if err != nil {
227 return Config{}, err
228 }
229
230 absSrcDir, err := filepath.Abs(srcDir)
231 if err != nil {
232 return Config{}, err
233 }
234
235 if strings.HasPrefix(absSrcDir, absBuildDir) {
236 return Config{}, fmt.Errorf("Build dir must not contain source directory")
237 }
238
Colin Cross3f40fa42015-01-30 17:27:36 -0800239 // Load any configurable options from the configuration file
Colin Cross9272ade2016-08-17 15:24:12 -0700240 err = loadConfig(config)
Colin Cross3f40fa42015-01-30 17:27:36 -0800241 if err != nil {
Colin Crossc3c0a492015-04-10 15:43:55 -0700242 return Config{}, err
Colin Cross3f40fa42015-01-30 17:27:36 -0800243 }
244
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800245 inMakeFile := filepath.Join(buildDir, ".soong.in_make")
246 if _, err := os.Stat(inMakeFile); err == nil {
247 config.inMake = true
248 }
249
Colin Crossa1ad8d12016-06-01 17:09:44 -0700250 targets, err := decodeTargetProductVariables(config)
Dan Willemsen218f6562015-07-08 18:13:11 -0700251 if err != nil {
252 return Config{}, err
253 }
254
Dan Albert4098deb2016-10-19 14:04:41 -0700255 var archConfig []archConfig
Dan Willemsen322acaf2016-01-12 23:07:05 -0800256 if Bool(config.Mega_device) {
Dan Albert4098deb2016-10-19 14:04:41 -0700257 archConfig = getMegaDeviceConfig()
258 } else if Bool(config.Ndk_abis) {
259 archConfig = getNdkAbisConfig()
260 }
261
262 if archConfig != nil {
263 deviceTargets, err := decodeArchSettings(archConfig)
Dan Willemsen322acaf2016-01-12 23:07:05 -0800264 if err != nil {
265 return Config{}, err
266 }
Colin Crossa1ad8d12016-06-01 17:09:44 -0700267 targets[Device] = deviceTargets
Dan Willemsen322acaf2016-01-12 23:07:05 -0800268 }
269
Colin Crossa1ad8d12016-06-01 17:09:44 -0700270 config.Targets = targets
271 config.BuildOsVariant = targets[Host][0].String()
Dan Willemsen218f6562015-07-08 18:13:11 -0700272
Colin Cross9272ade2016-08-17 15:24:12 -0700273 return Config{config}, nil
Colin Cross3f40fa42015-01-30 17:27:36 -0800274}
275
Dan Willemsen218f6562015-07-08 18:13:11 -0700276func (c *config) RemoveAbandonedFiles() bool {
277 return false
278}
279
Dan Willemsenc2aa4a92016-05-26 15:13:03 -0700280func (c *config) BlueprintToolLocation() string {
281 return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin")
282}
283
Dan Willemsen66068722017-05-08 21:15:59 +0000284// HostSystemTool looks for non-hermetic tools from the system we're running on.
285// Generally shouldn't be used, but useful to find the XCode SDK, etc.
286func (c *config) HostSystemTool(name string) string {
287 for _, dir := range filepath.SplitList(c.Getenv("PATH")) {
288 path := filepath.Join(dir, name)
289 if s, err := os.Stat(path); err != nil {
290 continue
291 } else if m := s.Mode(); !s.IsDir() && m&0111 != 0 {
292 return path
293 }
294 }
295 return name
296}
297
Colin Cross3f40fa42015-01-30 17:27:36 -0800298// PrebuiltOS returns the name of the host OS used in prebuilts directories
Colin Cross1332b002015-04-07 17:11:30 -0700299func (c *config) PrebuiltOS() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800300 switch runtime.GOOS {
301 case "linux":
302 return "linux-x86"
303 case "darwin":
304 return "darwin-x86"
305 default:
306 panic("Unknown GOOS")
307 }
308}
309
310// GoRoot returns the path to the root directory of the Go toolchain.
Colin Cross1332b002015-04-07 17:11:30 -0700311func (c *config) GoRoot() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800312 return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS())
313}
314
Colin Cross1332b002015-04-07 17:11:30 -0700315func (c *config) CpPreserveSymlinksFlags() string {
Colin Cross485e5722015-08-27 13:28:01 -0700316 switch runtime.GOOS {
Colin Cross3f40fa42015-01-30 17:27:36 -0800317 case "darwin":
318 return "-R"
319 case "linux":
320 return "-d"
321 default:
322 return ""
323 }
324}
Colin Cross68f55102015-03-25 14:43:57 -0700325
Colin Cross1332b002015-04-07 17:11:30 -0700326func (c *config) Getenv(key string) string {
Colin Cross68f55102015-03-25 14:43:57 -0700327 var val string
328 var exists bool
Colin Crossc1e86a32015-04-15 12:33:28 -0700329 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800330 defer c.envLock.Unlock()
331 if c.envDeps == nil {
332 c.envDeps = make(map[string]string)
333 }
Colin Cross68f55102015-03-25 14:43:57 -0700334 if val, exists = c.envDeps[key]; !exists {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700335 if c.envFrozen {
336 panic("Cannot access new environment variables after envdeps are frozen")
337 }
Colin Cross32616ed2017-09-05 21:56:44 -0700338 if !c.ignoreEnvironment {
339 val, _ = originalEnv[key]
340 }
Colin Cross68f55102015-03-25 14:43:57 -0700341 c.envDeps[key] = val
342 }
343 return val
344}
345
Colin Cross99d7c232016-11-23 16:52:04 -0800346func (c *config) GetenvWithDefault(key string, defaultValue string) string {
347 ret := c.Getenv(key)
348 if ret == "" {
349 return defaultValue
350 }
351 return ret
352}
353
354func (c *config) IsEnvTrue(key string) bool {
355 value := c.Getenv(key)
356 return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
357}
358
359func (c *config) IsEnvFalse(key string) bool {
360 value := c.Getenv(key)
361 return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
362}
363
Colin Cross1332b002015-04-07 17:11:30 -0700364func (c *config) EnvDeps() map[string]string {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700365 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800366 defer c.envLock.Unlock()
Dan Willemsene7680ba2015-09-11 17:06:19 -0700367 c.envFrozen = true
Colin Cross68f55102015-03-25 14:43:57 -0700368 return c.envDeps
369}
Colin Cross35cec122015-04-02 14:37:16 -0700370
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800371func (c *config) EmbeddedInMake() bool {
372 return c.inMake
373}
374
Colin Cross35cec122015-04-02 14:37:16 -0700375// DeviceName returns the name of the current device target
376// TODO: take an AndroidModuleContext to select the device name for multi-device builds
Colin Cross1332b002015-04-07 17:11:30 -0700377func (c *config) DeviceName() string {
Dan Willemsen1d31ec32015-09-22 16:56:09 -0700378 return *c.ProductVariables.DeviceName
Colin Cross35cec122015-04-02 14:37:16 -0700379}
380
Dan Willemsendd0e2c32015-10-20 14:29:35 -0700381func (c *config) DeviceUsesClang() bool {
382 if c.ProductVariables.DeviceUsesClang != nil {
383 return *c.ProductVariables.DeviceUsesClang
384 }
Dan Willemsen0084d782016-03-01 14:54:24 -0800385 return true
Dan Willemsendd0e2c32015-10-20 14:29:35 -0700386}
387
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700388func (c *config) ResourceOverlays() []SourcePath {
Colin Cross30e076a2015-04-13 13:58:27 -0700389 return nil
390}
391
392func (c *config) PlatformVersion() string {
393 return "M"
394}
395
Dan Albert073379e2016-11-10 10:46:36 -0800396func (c *config) PlatformSdkVersionInt() int {
397 return *c.ProductVariables.Platform_sdk_version
398}
399
Colin Cross30e076a2015-04-13 13:58:27 -0700400func (c *config) PlatformSdkVersion() string {
Dan Albert073379e2016-11-10 10:46:36 -0800401 return strconv.Itoa(c.PlatformSdkVersionInt())
Colin Cross30e076a2015-04-13 13:58:27 -0700402}
403
Dan Albertf5415d72017-08-17 16:19:59 -0700404func (c *config) MinSupportedSdkVersion() int {
Dan Albertd4db4ac2017-08-10 12:18:31 -0700405 return 14
Dan Albertf5415d72017-08-17 16:19:59 -0700406}
407
Colin Cross595a4062017-08-31 12:30:37 -0700408func (c *config) DefaultAppTargetSdkInt() int {
409 if Bool(c.ProductVariables.Platform_sdk_final) {
410 return c.PlatformSdkVersionInt()
411 } else {
412 return 10000
413 }
414}
415
Dan Albert31384de2017-07-28 12:39:46 -0700416// Codenames that are active in the current lunch target.
417func (c *config) PlatformVersionActiveCodenames() []string {
418 return c.ProductVariables.Platform_version_active_codenames
419}
420
421// Codenames that are available in the branch but not included in the current
422// lunch target.
423func (c *config) PlatformVersionFutureCodenames() []string {
424 return c.ProductVariables.Platform_version_future_codenames
425}
426
427// All possible codenames in the current branch. NB: Not named AllCodenames
428// because "all" has historically meant "active" in make, and still does in
429// build.prop.
430func (c *config) PlatformVersionCombinedCodenames() []string {
431 combined := []string{}
432 combined = append(combined, c.PlatformVersionActiveCodenames()...)
433 combined = append(combined, c.PlatformVersionFutureCodenames()...)
434 return combined
Dan Albert30c9d6e2017-03-28 14:54:55 -0700435}
436
Colin Cross30e076a2015-04-13 13:58:27 -0700437func (c *config) BuildNumber() string {
438 return "000000"
439}
440
441func (c *config) ProductAaptConfig() []string {
442 return []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"}
443}
444
445func (c *config) ProductAaptPreferredConfig() string {
446 return "xhdpi"
447}
448
449func (c *config) ProductAaptCharacteristics() string {
450 return "nosdcard"
451}
452
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700453func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
454 return PathForSource(ctx, "build/target/product/security")
Colin Cross30e076a2015-04-13 13:58:27 -0700455}
456
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700457func (c *config) DefaultAppCertificate(ctx PathContext) SourcePath {
458 return c.DefaultAppCertificateDir(ctx).Join(ctx, "testkey")
Colin Cross30e076a2015-04-13 13:58:27 -0700459}
Colin Cross6ff51382015-12-17 16:39:19 -0800460
461func (c *config) AllowMissingDependencies() bool {
Dan Willemsenb5038162016-03-16 12:35:33 -0700462 return Bool(c.ProductVariables.Allow_missing_dependencies)
Colin Cross6ff51382015-12-17 16:39:19 -0800463}
Dan Willemsen322acaf2016-01-12 23:07:05 -0800464
Colin Cross1e7d3702016-08-24 15:25:47 -0700465func (c *config) DevicePrefer32BitExecutables() bool {
466 return Bool(c.ProductVariables.DevicePrefer32BitExecutables)
467}
468
Dan Willemsen7f730fd2016-01-14 11:22:23 -0800469func (c *config) SkipDeviceInstall() bool {
Colin Cross893d8162017-04-26 17:34:03 -0700470 return c.EmbeddedInMake()
471}
472
473func (c *config) SkipMegaDeviceInstall(path string) bool {
474 return Bool(c.Mega_device) &&
475 strings.HasPrefix(path, filepath.Join(c.buildDir, "target", "product"))
Dan Willemsen322acaf2016-01-12 23:07:05 -0800476}
Colin Cross16b23492016-01-06 14:41:07 -0800477
478func (c *config) SanitizeHost() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700479 return append([]string(nil), c.ProductVariables.SanitizeHost...)
Colin Cross16b23492016-01-06 14:41:07 -0800480}
481
482func (c *config) SanitizeDevice() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700483 return append([]string(nil), c.ProductVariables.SanitizeDevice...)
484}
485
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700486func (c *config) SanitizeDeviceDiag() []string {
487 return append([]string(nil), c.ProductVariables.SanitizeDeviceDiag...)
488}
489
Colin Cross23ae82a2016-11-02 14:34:39 -0700490func (c *config) SanitizeDeviceArch() []string {
491 return append([]string(nil), c.ProductVariables.SanitizeDeviceArch...)
Colin Cross16b23492016-01-06 14:41:07 -0800492}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700493
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800494func (c *config) EnableCFI() bool {
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -0800495 if c.ProductVariables.EnableCFI == nil {
496 return true
497 } else {
498 return *c.ProductVariables.EnableCFI
499 }
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800500}
501
Colin Crossa1ad8d12016-06-01 17:09:44 -0700502func (c *config) Android64() bool {
503 for _, t := range c.Targets[Device] {
504 if t.Arch.ArchType.Multilib == "lib64" {
505 return true
506 }
507 }
508
509 return false
510}
Colin Cross9272ade2016-08-17 15:24:12 -0700511
Colin Cross9d45bb72016-08-29 16:14:13 -0700512func (c *config) UseGoma() bool {
513 return Bool(c.ProductVariables.UseGoma)
514}
515
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700516func (c *config) ClangTidy() bool {
517 return Bool(c.ProductVariables.ClangTidy)
518}
519
520func (c *config) TidyChecks() string {
521 if c.ProductVariables.TidyChecks == nil {
522 return ""
523 }
524 return *c.ProductVariables.TidyChecks
525}
526
Colin Cross0f4e0d62016-07-27 10:56:55 -0700527func (c *config) LibartImgHostBaseAddress() string {
528 return "0x60000000"
529}
530
531func (c *config) LibartImgDeviceBaseAddress() string {
Colin Cross20e13652017-06-22 15:34:51 -0700532 archType := Common
533 if len(c.Targets[Device]) > 0 {
534 archType = c.Targets[Device][0].Arch.ArchType
535 }
536 switch archType {
Colin Cross0f4e0d62016-07-27 10:56:55 -0700537 default:
538 return "0x70000000"
539 case Mips, Mips64:
Chris Larsenae7f3e22017-05-30 16:36:58 -0700540 return "0x5C000000"
Colin Cross0f4e0d62016-07-27 10:56:55 -0700541 }
542}
543
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800544func (c *config) ArtUseReadBarrier() bool {
545 return Bool(c.ProductVariables.ArtUseReadBarrier)
546}
547
Colin Cross9272ade2016-08-17 15:24:12 -0700548func (c *deviceConfig) Arches() []Arch {
549 var arches []Arch
550 for _, target := range c.config.Targets[Device] {
551 arches = append(arches, target.Arch)
552 }
553 return arches
554}
Dan Willemsend2ede872016-11-18 14:54:24 -0800555
Dan Willemsen4353bc42016-12-05 17:16:02 -0800556func (c *deviceConfig) VendorPath() string {
557 if c.config.ProductVariables.VendorPath != nil {
558 return *c.config.ProductVariables.VendorPath
559 }
560 return "vendor"
561}
562
Dan Willemsen11b26142017-03-19 18:30:37 -0700563func (c *deviceConfig) CompileVndk() bool {
Dan Willemsend2ede872016-11-18 14:54:24 -0800564 if c.config.ProductVariables.DeviceVndkVersion == nil {
Dan Willemsen11b26142017-03-19 18:30:37 -0700565 return false
Dan Willemsend2ede872016-11-18 14:54:24 -0800566 }
Dan Willemsen11b26142017-03-19 18:30:37 -0700567 return *c.config.ProductVariables.DeviceVndkVersion == "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800568}
Jack He8cc71432016-12-08 15:45:07 -0800569
570func (c *deviceConfig) BtConfigIncludeDir() string {
571 return String(c.config.ProductVariables.BtConfigIncludeDir)
572}
Dan Willemsen581341d2017-02-09 16:16:31 -0800573
Jiyong Parkd773eb32017-07-03 13:18:12 +0900574func (c *deviceConfig) DeviceKernelHeaderDirs() []string {
575 return c.config.ProductVariables.DeviceKernelHeaders
576}
577
Dan Willemsen581341d2017-02-09 16:16:31 -0800578func (c *deviceConfig) NativeCoverageEnabled() bool {
579 return Bool(c.config.ProductVariables.NativeCoverage)
580}
581
582func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
Ryan Campbell469a18a2017-02-27 09:01:54 -0800583 coverage := false
Dan Willemsen581341d2017-02-09 16:16:31 -0800584 if c.config.ProductVariables.CoveragePaths != nil {
Ivan Lozano5f595532017-07-13 14:46:05 -0700585 if prefixInList(path, *c.config.ProductVariables.CoveragePaths) {
586 coverage = true
Dan Willemsen581341d2017-02-09 16:16:31 -0800587 }
588 }
Ryan Campbell469a18a2017-02-27 09:01:54 -0800589 if coverage && c.config.ProductVariables.CoverageExcludePaths != nil {
Ivan Lozano5f595532017-07-13 14:46:05 -0700590 if prefixInList(path, *c.config.ProductVariables.CoverageExcludePaths) {
591 coverage = false
Ryan Campbell469a18a2017-02-27 09:01:54 -0800592 }
593 }
594 return coverage
Dan Willemsen581341d2017-02-09 16:16:31 -0800595}
Ivan Lozano5f595532017-07-13 14:46:05 -0700596
597func (c *config) IntegerOverflowDisabledForPath(path string) bool {
598 if c.ProductVariables.IntegerOverflowExcludePaths == nil {
599 return false
600 }
601 return prefixInList(path, *c.ProductVariables.IntegerOverflowExcludePaths)
602}