blob: 5abda26fcaadaca13e4a382a5dd19e8ed490c037 [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
Colin Cross6ccbc912017-10-10 23:07:38 -070081 env map[string]string
Dan Willemsene7680ba2015-09-11 17:06:19 -070082 envLock sync.Mutex
83 envDeps map[string]string
84 envFrozen bool
Dan Willemsen5ba07e82015-12-11 13:51:06 -080085
86 inMake bool
Colin Cross1e7d3702016-08-24 15:25:47 -070087
Colin Cross32616ed2017-09-05 21:56:44 -070088 captureBuild bool // true for tests, saves build parameters for each module
89 ignoreEnvironment bool // true for tests, returns empty from all Getenv calls
Colin Crosscec81712017-07-13 14:43:27 -070090
Colin Cross9272ade2016-08-17 15:24:12 -070091 OncePer
92}
93
94type deviceConfig struct {
Dan Willemsen00269f22017-07-06 16:59:48 -070095 config *config
Colin Cross9272ade2016-08-17 15:24:12 -070096 OncePer
Colin Cross3f40fa42015-01-30 17:27:36 -080097}
98
Colin Cross485e5722015-08-27 13:28:01 -070099type jsonConfigurable interface {
Colin Cross27385972015-09-18 10:57:10 -0700100 SetDefaultConfig()
Colin Cross485e5722015-08-27 13:28:01 -0700101}
Colin Cross3f40fa42015-01-30 17:27:36 -0800102
Colin Cross485e5722015-08-27 13:28:01 -0700103func loadConfig(config *config) error {
Dan Willemsen87b17d12015-07-14 00:39:06 -0700104 err := loadFromConfigFile(&config.FileConfigurableOptions, config.ConfigFileName)
Colin Cross485e5722015-08-27 13:28:01 -0700105 if err != nil {
106 return err
107 }
108
Dan Willemsen87b17d12015-07-14 00:39:06 -0700109 return loadFromConfigFile(&config.ProductVariables, config.ProductVariablesFileName)
Colin Cross485e5722015-08-27 13:28:01 -0700110}
111
112// loads configuration options from a JSON file in the cwd.
113func loadFromConfigFile(configurable jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800114 // Try to open the file
Colin Cross485e5722015-08-27 13:28:01 -0700115 configFileReader, err := os.Open(filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800116 defer configFileReader.Close()
117 if os.IsNotExist(err) {
118 // Need to create a file, so that blueprint & ninja don't get in
119 // a dependency tracking loop.
120 // Make a file-configurable-options with defaults, write it out using
121 // a json writer.
Colin Cross27385972015-09-18 10:57:10 -0700122 configurable.SetDefaultConfig()
123 err = saveToConfigFile(configurable, filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800124 if err != nil {
125 return err
126 }
127 } else {
128 // Make a decoder for it
129 jsonDecoder := json.NewDecoder(configFileReader)
Colin Cross485e5722015-08-27 13:28:01 -0700130 err = jsonDecoder.Decode(configurable)
Colin Cross3f40fa42015-01-30 17:27:36 -0800131 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700132 return fmt.Errorf("config file: %s did not parse correctly: "+err.Error(), filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800133 }
134 }
135
Colin Cross3f40fa42015-01-30 17:27:36 -0800136 // No error
137 return nil
138}
139
Colin Crossd8f20142016-11-03 09:43:26 -0700140// atomically writes the config file in case two copies of soong_build are running simultaneously
141// (for example, docs generation and ninja manifest generation)
Colin Cross485e5722015-08-27 13:28:01 -0700142func saveToConfigFile(config jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800143 data, err := json.MarshalIndent(&config, "", " ")
144 if err != nil {
145 return fmt.Errorf("cannot marshal config data: %s", err.Error())
146 }
147
Colin Crossd8f20142016-11-03 09:43:26 -0700148 f, err := ioutil.TempFile(filepath.Dir(filename), "config")
Colin Cross3f40fa42015-01-30 17:27:36 -0800149 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700150 return fmt.Errorf("cannot create empty config file %s: %s\n", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800151 }
Colin Crossd8f20142016-11-03 09:43:26 -0700152 defer os.Remove(f.Name())
153 defer f.Close()
Colin Cross3f40fa42015-01-30 17:27:36 -0800154
Colin Crossd8f20142016-11-03 09:43:26 -0700155 _, err = f.Write(data)
Colin Cross3f40fa42015-01-30 17:27:36 -0800156 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700157 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
158 }
159
Colin Crossd8f20142016-11-03 09:43:26 -0700160 _, err = f.WriteString("\n")
Colin Cross485e5722015-08-27 13:28:01 -0700161 if err != nil {
162 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800163 }
164
Colin Crossd8f20142016-11-03 09:43:26 -0700165 f.Close()
166 os.Rename(f.Name(), filename)
167
Colin Cross3f40fa42015-01-30 17:27:36 -0800168 return nil
169}
170
Colin Crossce75d2c2016-10-06 16:12:58 -0700171// TestConfig returns a Config object suitable for using for tests
Colin Cross6ccbc912017-10-10 23:07:38 -0700172func TestConfig(buildDir string, env map[string]string) Config {
Dan Willemsen00269f22017-07-06 16:59:48 -0700173 config := &config{
174 ProductVariables: productVariables{
175 DeviceName: stringPtr("test_device"),
176 },
177
Colin Cross6ccbc912017-10-10 23:07:38 -0700178 buildDir: buildDir,
179 captureBuild: true,
180 env: env,
Dan Willemsen00269f22017-07-06 16:59:48 -0700181 }
182 config.deviceConfig = &deviceConfig{
183 config: config,
184 }
185
186 return Config{config}
Colin Crossce75d2c2016-10-06 16:12:58 -0700187}
188
Colin Crossae4c6182017-09-15 17:33:55 -0700189// TestConfig returns a Config object suitable for using for tests that need to run the arch mutator
Colin Cross6ccbc912017-10-10 23:07:38 -0700190func TestArchConfig(buildDir string, env map[string]string) Config {
191 testConfig := TestConfig(buildDir, env)
Colin Crossae4c6182017-09-15 17:33:55 -0700192 config := testConfig.config
193
194 config.Targets = map[OsClass][]Target{
195 Device: []Target{
Jiyong Park6a43f042017-10-12 23:05:00 +0900196 {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Native: true}},
197 {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Native: true}},
Colin Crossae4c6182017-09-15 17:33:55 -0700198 },
199 Host: []Target{
200 {BuildOs, Arch{ArchType: X86_64}},
201 {BuildOs, Arch{ArchType: X86}},
202 },
203 }
204
205 return testConfig
206}
207
Colin Cross3f40fa42015-01-30 17:27:36 -0800208// New creates a new Config object. The srcDir argument specifies the path to
209// the root source directory. It also loads the config file, if found.
Dan Willemsen87b17d12015-07-14 00:39:06 -0700210func NewConfig(srcDir, buildDir string) (Config, error) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800211 // Make a config with default options
Colin Cross9272ade2016-08-17 15:24:12 -0700212 config := &config{
213 ConfigFileName: filepath.Join(buildDir, configFileName),
214 ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName),
Dan Willemsen87b17d12015-07-14 00:39:06 -0700215
Colin Cross6ccbc912017-10-10 23:07:38 -0700216 env: originalEnv,
217
Colin Cross9272ade2016-08-17 15:24:12 -0700218 srcDir: srcDir,
219 buildDir: buildDir,
Colin Cross68f55102015-03-25 14:43:57 -0700220 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800221
Dan Willemsen00269f22017-07-06 16:59:48 -0700222 config.deviceConfig = &deviceConfig{
Colin Cross9272ade2016-08-17 15:24:12 -0700223 config: config,
224 }
225
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700226 // Sanity check the build and source directories. This won't catch strange
227 // configurations with symlinks, but at least checks the obvious cases.
228 absBuildDir, err := filepath.Abs(buildDir)
229 if err != nil {
230 return Config{}, err
231 }
232
233 absSrcDir, err := filepath.Abs(srcDir)
234 if err != nil {
235 return Config{}, err
236 }
237
238 if strings.HasPrefix(absSrcDir, absBuildDir) {
239 return Config{}, fmt.Errorf("Build dir must not contain source directory")
240 }
241
Colin Cross3f40fa42015-01-30 17:27:36 -0800242 // Load any configurable options from the configuration file
Colin Cross9272ade2016-08-17 15:24:12 -0700243 err = loadConfig(config)
Colin Cross3f40fa42015-01-30 17:27:36 -0800244 if err != nil {
Colin Crossc3c0a492015-04-10 15:43:55 -0700245 return Config{}, err
Colin Cross3f40fa42015-01-30 17:27:36 -0800246 }
247
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800248 inMakeFile := filepath.Join(buildDir, ".soong.in_make")
249 if _, err := os.Stat(inMakeFile); err == nil {
250 config.inMake = true
251 }
252
Colin Crossa1ad8d12016-06-01 17:09:44 -0700253 targets, err := decodeTargetProductVariables(config)
Dan Willemsen218f6562015-07-08 18:13:11 -0700254 if err != nil {
255 return Config{}, err
256 }
257
Dan Albert4098deb2016-10-19 14:04:41 -0700258 var archConfig []archConfig
Dan Willemsen322acaf2016-01-12 23:07:05 -0800259 if Bool(config.Mega_device) {
Dan Albert4098deb2016-10-19 14:04:41 -0700260 archConfig = getMegaDeviceConfig()
261 } else if Bool(config.Ndk_abis) {
262 archConfig = getNdkAbisConfig()
263 }
264
265 if archConfig != nil {
266 deviceTargets, err := decodeArchSettings(archConfig)
Dan Willemsen322acaf2016-01-12 23:07:05 -0800267 if err != nil {
268 return Config{}, err
269 }
Colin Crossa1ad8d12016-06-01 17:09:44 -0700270 targets[Device] = deviceTargets
Dan Willemsen322acaf2016-01-12 23:07:05 -0800271 }
272
Colin Crossa1ad8d12016-06-01 17:09:44 -0700273 config.Targets = targets
274 config.BuildOsVariant = targets[Host][0].String()
Dan Willemsen218f6562015-07-08 18:13:11 -0700275
Colin Cross9272ade2016-08-17 15:24:12 -0700276 return Config{config}, nil
Colin Cross3f40fa42015-01-30 17:27:36 -0800277}
278
Dan Willemsen218f6562015-07-08 18:13:11 -0700279func (c *config) RemoveAbandonedFiles() bool {
280 return false
281}
282
Dan Willemsenc2aa4a92016-05-26 15:13:03 -0700283func (c *config) BlueprintToolLocation() string {
284 return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin")
285}
286
Dan Willemsen66068722017-05-08 21:15:59 +0000287// HostSystemTool looks for non-hermetic tools from the system we're running on.
288// Generally shouldn't be used, but useful to find the XCode SDK, etc.
289func (c *config) HostSystemTool(name string) string {
290 for _, dir := range filepath.SplitList(c.Getenv("PATH")) {
291 path := filepath.Join(dir, name)
292 if s, err := os.Stat(path); err != nil {
293 continue
294 } else if m := s.Mode(); !s.IsDir() && m&0111 != 0 {
295 return path
296 }
297 }
298 return name
299}
300
Colin Cross3f40fa42015-01-30 17:27:36 -0800301// PrebuiltOS returns the name of the host OS used in prebuilts directories
Colin Cross1332b002015-04-07 17:11:30 -0700302func (c *config) PrebuiltOS() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800303 switch runtime.GOOS {
304 case "linux":
305 return "linux-x86"
306 case "darwin":
307 return "darwin-x86"
308 default:
309 panic("Unknown GOOS")
310 }
311}
312
313// GoRoot returns the path to the root directory of the Go toolchain.
Colin Cross1332b002015-04-07 17:11:30 -0700314func (c *config) GoRoot() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800315 return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS())
316}
317
Colin Cross1332b002015-04-07 17:11:30 -0700318func (c *config) CpPreserveSymlinksFlags() string {
Colin Cross485e5722015-08-27 13:28:01 -0700319 switch runtime.GOOS {
Colin Cross3f40fa42015-01-30 17:27:36 -0800320 case "darwin":
321 return "-R"
322 case "linux":
323 return "-d"
324 default:
325 return ""
326 }
327}
Colin Cross68f55102015-03-25 14:43:57 -0700328
Colin Cross1332b002015-04-07 17:11:30 -0700329func (c *config) Getenv(key string) string {
Colin Cross68f55102015-03-25 14:43:57 -0700330 var val string
331 var exists bool
Colin Crossc1e86a32015-04-15 12:33:28 -0700332 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800333 defer c.envLock.Unlock()
334 if c.envDeps == nil {
335 c.envDeps = make(map[string]string)
336 }
Colin Cross68f55102015-03-25 14:43:57 -0700337 if val, exists = c.envDeps[key]; !exists {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700338 if c.envFrozen {
339 panic("Cannot access new environment variables after envdeps are frozen")
340 }
Colin Cross6ccbc912017-10-10 23:07:38 -0700341 val, _ = c.env[key]
Colin Cross68f55102015-03-25 14:43:57 -0700342 c.envDeps[key] = val
343 }
344 return val
345}
346
Colin Cross99d7c232016-11-23 16:52:04 -0800347func (c *config) GetenvWithDefault(key string, defaultValue string) string {
348 ret := c.Getenv(key)
349 if ret == "" {
350 return defaultValue
351 }
352 return ret
353}
354
355func (c *config) IsEnvTrue(key string) bool {
356 value := c.Getenv(key)
357 return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
358}
359
360func (c *config) IsEnvFalse(key string) bool {
361 value := c.Getenv(key)
362 return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
363}
364
Colin Cross1332b002015-04-07 17:11:30 -0700365func (c *config) EnvDeps() map[string]string {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700366 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800367 defer c.envLock.Unlock()
Dan Willemsene7680ba2015-09-11 17:06:19 -0700368 c.envFrozen = true
Colin Cross68f55102015-03-25 14:43:57 -0700369 return c.envDeps
370}
Colin Cross35cec122015-04-02 14:37:16 -0700371
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800372func (c *config) EmbeddedInMake() bool {
373 return c.inMake
374}
375
Colin Cross35cec122015-04-02 14:37:16 -0700376// DeviceName returns the name of the current device target
377// TODO: take an AndroidModuleContext to select the device name for multi-device builds
Colin Cross1332b002015-04-07 17:11:30 -0700378func (c *config) DeviceName() string {
Dan Willemsen1d31ec32015-09-22 16:56:09 -0700379 return *c.ProductVariables.DeviceName
Colin Cross35cec122015-04-02 14:37:16 -0700380}
381
Dan Willemsendd0e2c32015-10-20 14:29:35 -0700382func (c *config) DeviceUsesClang() bool {
383 if c.ProductVariables.DeviceUsesClang != nil {
384 return *c.ProductVariables.DeviceUsesClang
385 }
Dan Willemsen0084d782016-03-01 14:54:24 -0800386 return true
Dan Willemsendd0e2c32015-10-20 14:29:35 -0700387}
388
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700389func (c *config) ResourceOverlays() []SourcePath {
Colin Cross30e076a2015-04-13 13:58:27 -0700390 return nil
391}
392
393func (c *config) PlatformVersion() string {
394 return "M"
395}
396
Dan Albert073379e2016-11-10 10:46:36 -0800397func (c *config) PlatformSdkVersionInt() int {
398 return *c.ProductVariables.Platform_sdk_version
399}
400
Colin Cross30e076a2015-04-13 13:58:27 -0700401func (c *config) PlatformSdkVersion() string {
Dan Albert073379e2016-11-10 10:46:36 -0800402 return strconv.Itoa(c.PlatformSdkVersionInt())
Colin Cross30e076a2015-04-13 13:58:27 -0700403}
404
Dan Albertf5415d72017-08-17 16:19:59 -0700405func (c *config) MinSupportedSdkVersion() int {
Dan Albertd4db4ac2017-08-10 12:18:31 -0700406 return 14
Dan Albertf5415d72017-08-17 16:19:59 -0700407}
408
Colin Cross595a4062017-08-31 12:30:37 -0700409func (c *config) DefaultAppTargetSdkInt() int {
410 if Bool(c.ProductVariables.Platform_sdk_final) {
411 return c.PlatformSdkVersionInt()
412 } else {
413 return 10000
414 }
415}
416
Dan Albert31384de2017-07-28 12:39:46 -0700417// Codenames that are active in the current lunch target.
418func (c *config) PlatformVersionActiveCodenames() []string {
419 return c.ProductVariables.Platform_version_active_codenames
420}
421
422// Codenames that are available in the branch but not included in the current
423// lunch target.
424func (c *config) PlatformVersionFutureCodenames() []string {
425 return c.ProductVariables.Platform_version_future_codenames
426}
427
428// All possible codenames in the current branch. NB: Not named AllCodenames
429// because "all" has historically meant "active" in make, and still does in
430// build.prop.
431func (c *config) PlatformVersionCombinedCodenames() []string {
432 combined := []string{}
433 combined = append(combined, c.PlatformVersionActiveCodenames()...)
434 combined = append(combined, c.PlatformVersionFutureCodenames()...)
435 return combined
Dan Albert30c9d6e2017-03-28 14:54:55 -0700436}
437
Colin Cross30e076a2015-04-13 13:58:27 -0700438func (c *config) BuildNumber() string {
439 return "000000"
440}
441
442func (c *config) ProductAaptConfig() []string {
443 return []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"}
444}
445
446func (c *config) ProductAaptPreferredConfig() string {
447 return "xhdpi"
448}
449
450func (c *config) ProductAaptCharacteristics() string {
451 return "nosdcard"
452}
453
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700454func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
455 return PathForSource(ctx, "build/target/product/security")
Colin Cross30e076a2015-04-13 13:58:27 -0700456}
457
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700458func (c *config) DefaultAppCertificate(ctx PathContext) SourcePath {
459 return c.DefaultAppCertificateDir(ctx).Join(ctx, "testkey")
Colin Cross30e076a2015-04-13 13:58:27 -0700460}
Colin Cross6ff51382015-12-17 16:39:19 -0800461
462func (c *config) AllowMissingDependencies() bool {
Dan Willemsenb5038162016-03-16 12:35:33 -0700463 return Bool(c.ProductVariables.Allow_missing_dependencies)
Colin Cross6ff51382015-12-17 16:39:19 -0800464}
Dan Willemsen322acaf2016-01-12 23:07:05 -0800465
Colin Crossfc3674a2017-09-18 17:41:52 -0700466func (c *config) UnbundledBuild() bool {
467 return Bool(c.ProductVariables.Unbundled_build)
468}
469
Colin Cross1e7d3702016-08-24 15:25:47 -0700470func (c *config) DevicePrefer32BitExecutables() bool {
471 return Bool(c.ProductVariables.DevicePrefer32BitExecutables)
472}
473
Dan Willemsen7f730fd2016-01-14 11:22:23 -0800474func (c *config) SkipDeviceInstall() bool {
Colin Cross893d8162017-04-26 17:34:03 -0700475 return c.EmbeddedInMake()
476}
477
478func (c *config) SkipMegaDeviceInstall(path string) bool {
479 return Bool(c.Mega_device) &&
480 strings.HasPrefix(path, filepath.Join(c.buildDir, "target", "product"))
Dan Willemsen322acaf2016-01-12 23:07:05 -0800481}
Colin Cross16b23492016-01-06 14:41:07 -0800482
483func (c *config) SanitizeHost() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700484 return append([]string(nil), c.ProductVariables.SanitizeHost...)
Colin Cross16b23492016-01-06 14:41:07 -0800485}
486
487func (c *config) SanitizeDevice() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700488 return append([]string(nil), c.ProductVariables.SanitizeDevice...)
489}
490
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700491func (c *config) SanitizeDeviceDiag() []string {
492 return append([]string(nil), c.ProductVariables.SanitizeDeviceDiag...)
493}
494
Colin Cross23ae82a2016-11-02 14:34:39 -0700495func (c *config) SanitizeDeviceArch() []string {
496 return append([]string(nil), c.ProductVariables.SanitizeDeviceArch...)
Colin Cross16b23492016-01-06 14:41:07 -0800497}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700498
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800499func (c *config) EnableCFI() bool {
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -0800500 if c.ProductVariables.EnableCFI == nil {
501 return true
502 } else {
503 return *c.ProductVariables.EnableCFI
504 }
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800505}
506
Colin Crossa1ad8d12016-06-01 17:09:44 -0700507func (c *config) Android64() bool {
508 for _, t := range c.Targets[Device] {
509 if t.Arch.ArchType.Multilib == "lib64" {
510 return true
511 }
512 }
513
514 return false
515}
Colin Cross9272ade2016-08-17 15:24:12 -0700516
Colin Cross9d45bb72016-08-29 16:14:13 -0700517func (c *config) UseGoma() bool {
518 return Bool(c.ProductVariables.UseGoma)
519}
520
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700521func (c *config) ClangTidy() bool {
522 return Bool(c.ProductVariables.ClangTidy)
523}
524
525func (c *config) TidyChecks() string {
526 if c.ProductVariables.TidyChecks == nil {
527 return ""
528 }
529 return *c.ProductVariables.TidyChecks
530}
531
Colin Cross0f4e0d62016-07-27 10:56:55 -0700532func (c *config) LibartImgHostBaseAddress() string {
533 return "0x60000000"
534}
535
536func (c *config) LibartImgDeviceBaseAddress() string {
Colin Cross20e13652017-06-22 15:34:51 -0700537 archType := Common
538 if len(c.Targets[Device]) > 0 {
539 archType = c.Targets[Device][0].Arch.ArchType
540 }
541 switch archType {
Colin Cross0f4e0d62016-07-27 10:56:55 -0700542 default:
543 return "0x70000000"
544 case Mips, Mips64:
Chris Larsenae7f3e22017-05-30 16:36:58 -0700545 return "0x5C000000"
Colin Cross0f4e0d62016-07-27 10:56:55 -0700546 }
547}
548
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800549func (c *config) ArtUseReadBarrier() bool {
550 return Bool(c.ProductVariables.ArtUseReadBarrier)
551}
552
Colin Cross9272ade2016-08-17 15:24:12 -0700553func (c *deviceConfig) Arches() []Arch {
554 var arches []Arch
555 for _, target := range c.config.Targets[Device] {
556 arches = append(arches, target.Arch)
557 }
558 return arches
559}
Dan Willemsend2ede872016-11-18 14:54:24 -0800560
Dan Willemsen4353bc42016-12-05 17:16:02 -0800561func (c *deviceConfig) VendorPath() string {
562 if c.config.ProductVariables.VendorPath != nil {
563 return *c.config.ProductVariables.VendorPath
564 }
565 return "vendor"
566}
567
Dan Willemsen11b26142017-03-19 18:30:37 -0700568func (c *deviceConfig) CompileVndk() bool {
Dan Willemsend2ede872016-11-18 14:54:24 -0800569 if c.config.ProductVariables.DeviceVndkVersion == nil {
Dan Willemsen11b26142017-03-19 18:30:37 -0700570 return false
Dan Willemsend2ede872016-11-18 14:54:24 -0800571 }
Dan Willemsen11b26142017-03-19 18:30:37 -0700572 return *c.config.ProductVariables.DeviceVndkVersion == "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800573}
Jack He8cc71432016-12-08 15:45:07 -0800574
575func (c *deviceConfig) BtConfigIncludeDir() string {
576 return String(c.config.ProductVariables.BtConfigIncludeDir)
577}
Dan Willemsen581341d2017-02-09 16:16:31 -0800578
Jiyong Parkd773eb32017-07-03 13:18:12 +0900579func (c *deviceConfig) DeviceKernelHeaderDirs() []string {
580 return c.config.ProductVariables.DeviceKernelHeaders
581}
582
Dan Willemsen581341d2017-02-09 16:16:31 -0800583func (c *deviceConfig) NativeCoverageEnabled() bool {
584 return Bool(c.config.ProductVariables.NativeCoverage)
585}
586
587func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
Ryan Campbell469a18a2017-02-27 09:01:54 -0800588 coverage := false
Dan Willemsen581341d2017-02-09 16:16:31 -0800589 if c.config.ProductVariables.CoveragePaths != nil {
Ivan Lozano5f595532017-07-13 14:46:05 -0700590 if prefixInList(path, *c.config.ProductVariables.CoveragePaths) {
591 coverage = true
Dan Willemsen581341d2017-02-09 16:16:31 -0800592 }
593 }
Ryan Campbell469a18a2017-02-27 09:01:54 -0800594 if coverage && c.config.ProductVariables.CoverageExcludePaths != nil {
Ivan Lozano5f595532017-07-13 14:46:05 -0700595 if prefixInList(path, *c.config.ProductVariables.CoverageExcludePaths) {
596 coverage = false
Ryan Campbell469a18a2017-02-27 09:01:54 -0800597 }
598 }
599 return coverage
Dan Willemsen581341d2017-02-09 16:16:31 -0800600}
Ivan Lozano5f595532017-07-13 14:46:05 -0700601
602func (c *config) IntegerOverflowDisabledForPath(path string) bool {
603 if c.ProductVariables.IntegerOverflowExcludePaths == nil {
604 return false
605 }
606 return prefixInList(path, *c.ProductVariables.IntegerOverflowExcludePaths)
607}