blob: 79ff32a55b9b733d9c013a4b67b009332021106d [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 Cross1369cdb2017-09-29 17:58:17 -070091 useOpenJDK9 bool // Use OpenJDK9, but possibly target 1.8
92 targetOpenJDK9 bool // Use OpenJDK9 and target 1.9
93
Colin Cross9272ade2016-08-17 15:24:12 -070094 OncePer
95}
96
97type deviceConfig struct {
Dan Willemsen00269f22017-07-06 16:59:48 -070098 config *config
Colin Cross9272ade2016-08-17 15:24:12 -070099 OncePer
Colin Cross3f40fa42015-01-30 17:27:36 -0800100}
101
Colin Cross485e5722015-08-27 13:28:01 -0700102type jsonConfigurable interface {
Colin Cross27385972015-09-18 10:57:10 -0700103 SetDefaultConfig()
Colin Cross485e5722015-08-27 13:28:01 -0700104}
Colin Cross3f40fa42015-01-30 17:27:36 -0800105
Colin Cross485e5722015-08-27 13:28:01 -0700106func loadConfig(config *config) error {
Dan Willemsen87b17d12015-07-14 00:39:06 -0700107 err := loadFromConfigFile(&config.FileConfigurableOptions, config.ConfigFileName)
Colin Cross485e5722015-08-27 13:28:01 -0700108 if err != nil {
109 return err
110 }
111
Dan Willemsen87b17d12015-07-14 00:39:06 -0700112 return loadFromConfigFile(&config.ProductVariables, config.ProductVariablesFileName)
Colin Cross485e5722015-08-27 13:28:01 -0700113}
114
115// loads configuration options from a JSON file in the cwd.
116func loadFromConfigFile(configurable jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800117 // Try to open the file
Colin Cross485e5722015-08-27 13:28:01 -0700118 configFileReader, err := os.Open(filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800119 defer configFileReader.Close()
120 if os.IsNotExist(err) {
121 // Need to create a file, so that blueprint & ninja don't get in
122 // a dependency tracking loop.
123 // Make a file-configurable-options with defaults, write it out using
124 // a json writer.
Colin Cross27385972015-09-18 10:57:10 -0700125 configurable.SetDefaultConfig()
126 err = saveToConfigFile(configurable, filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800127 if err != nil {
128 return err
129 }
130 } else {
131 // Make a decoder for it
132 jsonDecoder := json.NewDecoder(configFileReader)
Colin Cross485e5722015-08-27 13:28:01 -0700133 err = jsonDecoder.Decode(configurable)
Colin Cross3f40fa42015-01-30 17:27:36 -0800134 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700135 return fmt.Errorf("config file: %s did not parse correctly: "+err.Error(), filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800136 }
137 }
138
Colin Cross3f40fa42015-01-30 17:27:36 -0800139 // No error
140 return nil
141}
142
Colin Crossd8f20142016-11-03 09:43:26 -0700143// atomically writes the config file in case two copies of soong_build are running simultaneously
144// (for example, docs generation and ninja manifest generation)
Colin Cross485e5722015-08-27 13:28:01 -0700145func saveToConfigFile(config jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800146 data, err := json.MarshalIndent(&config, "", " ")
147 if err != nil {
148 return fmt.Errorf("cannot marshal config data: %s", err.Error())
149 }
150
Colin Crossd8f20142016-11-03 09:43:26 -0700151 f, err := ioutil.TempFile(filepath.Dir(filename), "config")
Colin Cross3f40fa42015-01-30 17:27:36 -0800152 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700153 return fmt.Errorf("cannot create empty config file %s: %s\n", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800154 }
Colin Crossd8f20142016-11-03 09:43:26 -0700155 defer os.Remove(f.Name())
156 defer f.Close()
Colin Cross3f40fa42015-01-30 17:27:36 -0800157
Colin Crossd8f20142016-11-03 09:43:26 -0700158 _, err = f.Write(data)
Colin Cross3f40fa42015-01-30 17:27:36 -0800159 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700160 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
161 }
162
Colin Crossd8f20142016-11-03 09:43:26 -0700163 _, err = f.WriteString("\n")
Colin Cross485e5722015-08-27 13:28:01 -0700164 if err != nil {
165 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800166 }
167
Colin Crossd8f20142016-11-03 09:43:26 -0700168 f.Close()
169 os.Rename(f.Name(), filename)
170
Colin Cross3f40fa42015-01-30 17:27:36 -0800171 return nil
172}
173
Colin Crossce75d2c2016-10-06 16:12:58 -0700174// TestConfig returns a Config object suitable for using for tests
Colin Cross6ccbc912017-10-10 23:07:38 -0700175func TestConfig(buildDir string, env map[string]string) Config {
Dan Willemsen00269f22017-07-06 16:59:48 -0700176 config := &config{
177 ProductVariables: productVariables{
178 DeviceName: stringPtr("test_device"),
179 },
180
Colin Cross6ccbc912017-10-10 23:07:38 -0700181 buildDir: buildDir,
182 captureBuild: true,
183 env: env,
Dan Willemsen00269f22017-07-06 16:59:48 -0700184 }
185 config.deviceConfig = &deviceConfig{
186 config: config,
187 }
188
Colin Cross1369cdb2017-09-29 17:58:17 -0700189 if err := config.fromEnv(); err != nil {
190 panic(err)
191 }
192
Dan Willemsen00269f22017-07-06 16:59:48 -0700193 return Config{config}
Colin Crossce75d2c2016-10-06 16:12:58 -0700194}
195
Colin Crossae4c6182017-09-15 17:33:55 -0700196// TestConfig returns a Config object suitable for using for tests that need to run the arch mutator
Colin Cross6ccbc912017-10-10 23:07:38 -0700197func TestArchConfig(buildDir string, env map[string]string) Config {
198 testConfig := TestConfig(buildDir, env)
Colin Crossae4c6182017-09-15 17:33:55 -0700199 config := testConfig.config
200
201 config.Targets = map[OsClass][]Target{
202 Device: []Target{
Jiyong Park6a43f042017-10-12 23:05:00 +0900203 {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Native: true}},
204 {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Native: true}},
Colin Crossae4c6182017-09-15 17:33:55 -0700205 },
206 Host: []Target{
207 {BuildOs, Arch{ArchType: X86_64}},
208 {BuildOs, Arch{ArchType: X86}},
209 },
210 }
211
212 return testConfig
213}
214
Colin Cross3f40fa42015-01-30 17:27:36 -0800215// New creates a new Config object. The srcDir argument specifies the path to
216// the root source directory. It also loads the config file, if found.
Dan Willemsen87b17d12015-07-14 00:39:06 -0700217func NewConfig(srcDir, buildDir string) (Config, error) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800218 // Make a config with default options
Colin Cross9272ade2016-08-17 15:24:12 -0700219 config := &config{
220 ConfigFileName: filepath.Join(buildDir, configFileName),
221 ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName),
Dan Willemsen87b17d12015-07-14 00:39:06 -0700222
Colin Cross6ccbc912017-10-10 23:07:38 -0700223 env: originalEnv,
224
Colin Cross9272ade2016-08-17 15:24:12 -0700225 srcDir: srcDir,
226 buildDir: buildDir,
Colin Cross68f55102015-03-25 14:43:57 -0700227 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800228
Dan Willemsen00269f22017-07-06 16:59:48 -0700229 config.deviceConfig = &deviceConfig{
Colin Cross9272ade2016-08-17 15:24:12 -0700230 config: config,
231 }
232
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700233 // Sanity check the build and source directories. This won't catch strange
234 // configurations with symlinks, but at least checks the obvious cases.
235 absBuildDir, err := filepath.Abs(buildDir)
236 if err != nil {
237 return Config{}, err
238 }
239
240 absSrcDir, err := filepath.Abs(srcDir)
241 if err != nil {
242 return Config{}, err
243 }
244
245 if strings.HasPrefix(absSrcDir, absBuildDir) {
246 return Config{}, fmt.Errorf("Build dir must not contain source directory")
247 }
248
Colin Cross3f40fa42015-01-30 17:27:36 -0800249 // Load any configurable options from the configuration file
Colin Cross9272ade2016-08-17 15:24:12 -0700250 err = loadConfig(config)
Colin Cross3f40fa42015-01-30 17:27:36 -0800251 if err != nil {
Colin Crossc3c0a492015-04-10 15:43:55 -0700252 return Config{}, err
Colin Cross3f40fa42015-01-30 17:27:36 -0800253 }
254
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800255 inMakeFile := filepath.Join(buildDir, ".soong.in_make")
256 if _, err := os.Stat(inMakeFile); err == nil {
257 config.inMake = true
258 }
259
Colin Crossa1ad8d12016-06-01 17:09:44 -0700260 targets, err := decodeTargetProductVariables(config)
Dan Willemsen218f6562015-07-08 18:13:11 -0700261 if err != nil {
262 return Config{}, err
263 }
264
Dan Albert4098deb2016-10-19 14:04:41 -0700265 var archConfig []archConfig
Dan Willemsen322acaf2016-01-12 23:07:05 -0800266 if Bool(config.Mega_device) {
Dan Albert4098deb2016-10-19 14:04:41 -0700267 archConfig = getMegaDeviceConfig()
268 } else if Bool(config.Ndk_abis) {
269 archConfig = getNdkAbisConfig()
270 }
271
272 if archConfig != nil {
273 deviceTargets, err := decodeArchSettings(archConfig)
Dan Willemsen322acaf2016-01-12 23:07:05 -0800274 if err != nil {
275 return Config{}, err
276 }
Colin Crossa1ad8d12016-06-01 17:09:44 -0700277 targets[Device] = deviceTargets
Dan Willemsen322acaf2016-01-12 23:07:05 -0800278 }
279
Colin Crossa1ad8d12016-06-01 17:09:44 -0700280 config.Targets = targets
281 config.BuildOsVariant = targets[Host][0].String()
Dan Willemsen218f6562015-07-08 18:13:11 -0700282
Colin Cross1369cdb2017-09-29 17:58:17 -0700283 if err := config.fromEnv(); err != nil {
284 return Config{}, err
285 }
286
Colin Cross9272ade2016-08-17 15:24:12 -0700287 return Config{config}, nil
Colin Cross3f40fa42015-01-30 17:27:36 -0800288}
289
Colin Cross1369cdb2017-09-29 17:58:17 -0700290func (c *config) fromEnv() error {
291 switch c.Getenv("EXPERIMENTAL_USE_OPENJDK9") {
292 case "":
293 // Use OpenJDK8
Tobias Thierera7cdd152017-11-15 21:16:25 +0000294 case "false":
295 // Use OpenJDK8
Colin Cross1369cdb2017-09-29 17:58:17 -0700296 case "1.8":
297 // Use OpenJDK9, but target 1.8
298 c.useOpenJDK9 = true
299 case "true":
300 // Use OpenJDK9 and target 1.9
301 c.useOpenJDK9 = true
302 c.targetOpenJDK9 = true
303 default:
304 return fmt.Errorf(`Invalid value for EXPERIMENTAL_USE_OPENJDK9, should be "", "1.8", or "true"`)
305 }
306
307 return nil
308}
309
Dan Willemsen218f6562015-07-08 18:13:11 -0700310func (c *config) RemoveAbandonedFiles() bool {
311 return false
312}
313
Dan Willemsenc2aa4a92016-05-26 15:13:03 -0700314func (c *config) BlueprintToolLocation() string {
315 return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin")
316}
317
Dan Willemsen66068722017-05-08 21:15:59 +0000318// HostSystemTool looks for non-hermetic tools from the system we're running on.
319// Generally shouldn't be used, but useful to find the XCode SDK, etc.
320func (c *config) HostSystemTool(name string) string {
321 for _, dir := range filepath.SplitList(c.Getenv("PATH")) {
322 path := filepath.Join(dir, name)
323 if s, err := os.Stat(path); err != nil {
324 continue
325 } else if m := s.Mode(); !s.IsDir() && m&0111 != 0 {
326 return path
327 }
328 }
329 return name
330}
331
Colin Cross3f40fa42015-01-30 17:27:36 -0800332// PrebuiltOS returns the name of the host OS used in prebuilts directories
Colin Cross1332b002015-04-07 17:11:30 -0700333func (c *config) PrebuiltOS() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800334 switch runtime.GOOS {
335 case "linux":
336 return "linux-x86"
337 case "darwin":
338 return "darwin-x86"
339 default:
340 panic("Unknown GOOS")
341 }
342}
343
344// GoRoot returns the path to the root directory of the Go toolchain.
Colin Cross1332b002015-04-07 17:11:30 -0700345func (c *config) GoRoot() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800346 return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS())
347}
348
Colin Cross1332b002015-04-07 17:11:30 -0700349func (c *config) CpPreserveSymlinksFlags() string {
Colin Cross485e5722015-08-27 13:28:01 -0700350 switch runtime.GOOS {
Colin Cross3f40fa42015-01-30 17:27:36 -0800351 case "darwin":
352 return "-R"
353 case "linux":
354 return "-d"
355 default:
356 return ""
357 }
358}
Colin Cross68f55102015-03-25 14:43:57 -0700359
Colin Cross1332b002015-04-07 17:11:30 -0700360func (c *config) Getenv(key string) string {
Colin Cross68f55102015-03-25 14:43:57 -0700361 var val string
362 var exists bool
Colin Crossc1e86a32015-04-15 12:33:28 -0700363 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800364 defer c.envLock.Unlock()
365 if c.envDeps == nil {
366 c.envDeps = make(map[string]string)
367 }
Colin Cross68f55102015-03-25 14:43:57 -0700368 if val, exists = c.envDeps[key]; !exists {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700369 if c.envFrozen {
370 panic("Cannot access new environment variables after envdeps are frozen")
371 }
Colin Cross6ccbc912017-10-10 23:07:38 -0700372 val, _ = c.env[key]
Colin Cross68f55102015-03-25 14:43:57 -0700373 c.envDeps[key] = val
374 }
375 return val
376}
377
Colin Cross99d7c232016-11-23 16:52:04 -0800378func (c *config) GetenvWithDefault(key string, defaultValue string) string {
379 ret := c.Getenv(key)
380 if ret == "" {
381 return defaultValue
382 }
383 return ret
384}
385
386func (c *config) IsEnvTrue(key string) bool {
387 value := c.Getenv(key)
388 return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
389}
390
391func (c *config) IsEnvFalse(key string) bool {
392 value := c.Getenv(key)
393 return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
394}
395
Colin Cross1332b002015-04-07 17:11:30 -0700396func (c *config) EnvDeps() map[string]string {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700397 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800398 defer c.envLock.Unlock()
Dan Willemsene7680ba2015-09-11 17:06:19 -0700399 c.envFrozen = true
Colin Cross68f55102015-03-25 14:43:57 -0700400 return c.envDeps
401}
Colin Cross35cec122015-04-02 14:37:16 -0700402
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800403func (c *config) EmbeddedInMake() bool {
404 return c.inMake
405}
406
Colin Cross35cec122015-04-02 14:37:16 -0700407// DeviceName returns the name of the current device target
408// TODO: take an AndroidModuleContext to select the device name for multi-device builds
Colin Cross1332b002015-04-07 17:11:30 -0700409func (c *config) DeviceName() string {
Dan Willemsen1d31ec32015-09-22 16:56:09 -0700410 return *c.ProductVariables.DeviceName
Colin Cross35cec122015-04-02 14:37:16 -0700411}
412
Dan Willemsendd0e2c32015-10-20 14:29:35 -0700413func (c *config) DeviceUsesClang() bool {
414 if c.ProductVariables.DeviceUsesClang != nil {
415 return *c.ProductVariables.DeviceUsesClang
416 }
Dan Willemsen0084d782016-03-01 14:54:24 -0800417 return true
Dan Willemsendd0e2c32015-10-20 14:29:35 -0700418}
419
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700420func (c *config) ResourceOverlays() []SourcePath {
Colin Cross30e076a2015-04-13 13:58:27 -0700421 return nil
422}
423
424func (c *config) PlatformVersion() string {
425 return "M"
426}
427
Dan Albert073379e2016-11-10 10:46:36 -0800428func (c *config) PlatformSdkVersionInt() int {
429 return *c.ProductVariables.Platform_sdk_version
430}
431
Colin Cross30e076a2015-04-13 13:58:27 -0700432func (c *config) PlatformSdkVersion() string {
Dan Albert073379e2016-11-10 10:46:36 -0800433 return strconv.Itoa(c.PlatformSdkVersionInt())
Colin Cross30e076a2015-04-13 13:58:27 -0700434}
435
Dan Albertf5415d72017-08-17 16:19:59 -0700436func (c *config) MinSupportedSdkVersion() int {
Dan Albertd4db4ac2017-08-10 12:18:31 -0700437 return 14
Dan Albertf5415d72017-08-17 16:19:59 -0700438}
439
Colin Cross595a4062017-08-31 12:30:37 -0700440func (c *config) DefaultAppTargetSdkInt() int {
441 if Bool(c.ProductVariables.Platform_sdk_final) {
442 return c.PlatformSdkVersionInt()
443 } else {
444 return 10000
445 }
446}
447
Dan Albert31384de2017-07-28 12:39:46 -0700448// Codenames that are active in the current lunch target.
449func (c *config) PlatformVersionActiveCodenames() []string {
450 return c.ProductVariables.Platform_version_active_codenames
451}
452
453// Codenames that are available in the branch but not included in the current
454// lunch target.
455func (c *config) PlatformVersionFutureCodenames() []string {
456 return c.ProductVariables.Platform_version_future_codenames
457}
458
459// All possible codenames in the current branch. NB: Not named AllCodenames
460// because "all" has historically meant "active" in make, and still does in
461// build.prop.
462func (c *config) PlatformVersionCombinedCodenames() []string {
463 combined := []string{}
464 combined = append(combined, c.PlatformVersionActiveCodenames()...)
465 combined = append(combined, c.PlatformVersionFutureCodenames()...)
466 return combined
Dan Albert30c9d6e2017-03-28 14:54:55 -0700467}
468
Colin Cross30e076a2015-04-13 13:58:27 -0700469func (c *config) BuildNumber() string {
470 return "000000"
471}
472
Colin Crossface4e42017-10-30 17:32:15 -0700473func (c *config) ProductAAPTConfig() []string {
474 return *c.ProductVariables.AAPTConfig
Colin Cross30e076a2015-04-13 13:58:27 -0700475}
476
Colin Crossface4e42017-10-30 17:32:15 -0700477func (c *config) ProductAAPTPreferredConfig() string {
478 return *c.ProductVariables.AAPTPreferredConfig
Colin Cross30e076a2015-04-13 13:58:27 -0700479}
480
Colin Crossface4e42017-10-30 17:32:15 -0700481func (c *config) ProductAAPTCharacteristics() string {
482 return *c.ProductVariables.AAPTCharacteristics
483}
484
485func (c *config) ProductAAPTPrebuiltDPI() []string {
486 return *c.ProductVariables.AAPTPrebuiltDPI
Colin Cross30e076a2015-04-13 13:58:27 -0700487}
488
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700489func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
490 return PathForSource(ctx, "build/target/product/security")
Colin Cross30e076a2015-04-13 13:58:27 -0700491}
492
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700493func (c *config) DefaultAppCertificate(ctx PathContext) SourcePath {
494 return c.DefaultAppCertificateDir(ctx).Join(ctx, "testkey")
Colin Cross30e076a2015-04-13 13:58:27 -0700495}
Colin Cross6ff51382015-12-17 16:39:19 -0800496
497func (c *config) AllowMissingDependencies() bool {
Dan Willemsenb5038162016-03-16 12:35:33 -0700498 return Bool(c.ProductVariables.Allow_missing_dependencies)
Colin Cross6ff51382015-12-17 16:39:19 -0800499}
Dan Willemsen322acaf2016-01-12 23:07:05 -0800500
Colin Crossfc3674a2017-09-18 17:41:52 -0700501func (c *config) UnbundledBuild() bool {
502 return Bool(c.ProductVariables.Unbundled_build)
503}
504
Colin Cross0d3f8c02017-10-24 10:51:45 -0700505func (c *config) IsPdkBuild() bool {
506 return Bool(c.ProductVariables.Pdk)
507}
508
Colin Cross126a25c2017-10-31 13:55:34 -0700509func (c *config) MinimizeJavaDebugInfo() bool {
510 return Bool(c.ProductVariables.MinimizeJavaDebugInfo) && !Bool(c.ProductVariables.Eng)
511}
512
Colin Cross1e7d3702016-08-24 15:25:47 -0700513func (c *config) DevicePrefer32BitExecutables() bool {
514 return Bool(c.ProductVariables.DevicePrefer32BitExecutables)
515}
516
Dan Willemsen7f730fd2016-01-14 11:22:23 -0800517func (c *config) SkipDeviceInstall() bool {
Colin Cross893d8162017-04-26 17:34:03 -0700518 return c.EmbeddedInMake()
519}
520
521func (c *config) SkipMegaDeviceInstall(path string) bool {
522 return Bool(c.Mega_device) &&
523 strings.HasPrefix(path, filepath.Join(c.buildDir, "target", "product"))
Dan Willemsen322acaf2016-01-12 23:07:05 -0800524}
Colin Cross16b23492016-01-06 14:41:07 -0800525
526func (c *config) SanitizeHost() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700527 return append([]string(nil), c.ProductVariables.SanitizeHost...)
Colin Cross16b23492016-01-06 14:41:07 -0800528}
529
530func (c *config) SanitizeDevice() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700531 return append([]string(nil), c.ProductVariables.SanitizeDevice...)
532}
533
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700534func (c *config) SanitizeDeviceDiag() []string {
535 return append([]string(nil), c.ProductVariables.SanitizeDeviceDiag...)
536}
537
Colin Cross23ae82a2016-11-02 14:34:39 -0700538func (c *config) SanitizeDeviceArch() []string {
539 return append([]string(nil), c.ProductVariables.SanitizeDeviceArch...)
Colin Cross16b23492016-01-06 14:41:07 -0800540}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700541
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800542func (c *config) EnableCFI() bool {
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -0800543 if c.ProductVariables.EnableCFI == nil {
544 return true
545 } else {
546 return *c.ProductVariables.EnableCFI
547 }
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800548}
549
Colin Crossa1ad8d12016-06-01 17:09:44 -0700550func (c *config) Android64() bool {
551 for _, t := range c.Targets[Device] {
552 if t.Arch.ArchType.Multilib == "lib64" {
553 return true
554 }
555 }
556
557 return false
558}
Colin Cross9272ade2016-08-17 15:24:12 -0700559
Colin Cross9d45bb72016-08-29 16:14:13 -0700560func (c *config) UseGoma() bool {
561 return Bool(c.ProductVariables.UseGoma)
562}
563
Colin Cross1369cdb2017-09-29 17:58:17 -0700564// Returns true if OpenJDK9 prebuilts are being used
565func (c *config) UseOpenJDK9() bool {
566 return c.useOpenJDK9
567}
568
569// Returns true if -source 1.9 -target 1.9 is being passed to javac
570func (c *config) TargetOpenJDK9() bool {
571 return c.targetOpenJDK9
572}
573
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700574func (c *config) ClangTidy() bool {
575 return Bool(c.ProductVariables.ClangTidy)
576}
577
578func (c *config) TidyChecks() string {
579 if c.ProductVariables.TidyChecks == nil {
580 return ""
581 }
582 return *c.ProductVariables.TidyChecks
583}
584
Colin Cross0f4e0d62016-07-27 10:56:55 -0700585func (c *config) LibartImgHostBaseAddress() string {
586 return "0x60000000"
587}
588
589func (c *config) LibartImgDeviceBaseAddress() string {
Colin Cross20e13652017-06-22 15:34:51 -0700590 archType := Common
591 if len(c.Targets[Device]) > 0 {
592 archType = c.Targets[Device][0].Arch.ArchType
593 }
594 switch archType {
Colin Cross0f4e0d62016-07-27 10:56:55 -0700595 default:
596 return "0x70000000"
597 case Mips, Mips64:
Chris Larsenae7f3e22017-05-30 16:36:58 -0700598 return "0x5C000000"
Colin Cross0f4e0d62016-07-27 10:56:55 -0700599 }
600}
601
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800602func (c *config) ArtUseReadBarrier() bool {
603 return Bool(c.ProductVariables.ArtUseReadBarrier)
604}
605
Colin Cross9272ade2016-08-17 15:24:12 -0700606func (c *deviceConfig) Arches() []Arch {
607 var arches []Arch
608 for _, target := range c.config.Targets[Device] {
609 arches = append(arches, target.Arch)
610 }
611 return arches
612}
Dan Willemsend2ede872016-11-18 14:54:24 -0800613
Dan Willemsen4353bc42016-12-05 17:16:02 -0800614func (c *deviceConfig) VendorPath() string {
615 if c.config.ProductVariables.VendorPath != nil {
616 return *c.config.ProductVariables.VendorPath
617 }
618 return "vendor"
619}
620
Dan Willemsen11b26142017-03-19 18:30:37 -0700621func (c *deviceConfig) CompileVndk() bool {
Dan Willemsend2ede872016-11-18 14:54:24 -0800622 if c.config.ProductVariables.DeviceVndkVersion == nil {
Dan Willemsen11b26142017-03-19 18:30:37 -0700623 return false
Dan Willemsend2ede872016-11-18 14:54:24 -0800624 }
Dan Willemsen11b26142017-03-19 18:30:37 -0700625 return *c.config.ProductVariables.DeviceVndkVersion == "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800626}
Jack He8cc71432016-12-08 15:45:07 -0800627
628func (c *deviceConfig) BtConfigIncludeDir() string {
629 return String(c.config.ProductVariables.BtConfigIncludeDir)
630}
Dan Willemsen581341d2017-02-09 16:16:31 -0800631
Jiyong Parkd773eb32017-07-03 13:18:12 +0900632func (c *deviceConfig) DeviceKernelHeaderDirs() []string {
633 return c.config.ProductVariables.DeviceKernelHeaders
634}
635
Dan Willemsen581341d2017-02-09 16:16:31 -0800636func (c *deviceConfig) NativeCoverageEnabled() bool {
637 return Bool(c.config.ProductVariables.NativeCoverage)
638}
639
640func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
Ryan Campbell469a18a2017-02-27 09:01:54 -0800641 coverage := false
Dan Willemsen581341d2017-02-09 16:16:31 -0800642 if c.config.ProductVariables.CoveragePaths != nil {
Ivan Lozano5f595532017-07-13 14:46:05 -0700643 if prefixInList(path, *c.config.ProductVariables.CoveragePaths) {
644 coverage = true
Dan Willemsen581341d2017-02-09 16:16:31 -0800645 }
646 }
Ryan Campbell469a18a2017-02-27 09:01:54 -0800647 if coverage && c.config.ProductVariables.CoverageExcludePaths != nil {
Ivan Lozano5f595532017-07-13 14:46:05 -0700648 if prefixInList(path, *c.config.ProductVariables.CoverageExcludePaths) {
649 coverage = false
Ryan Campbell469a18a2017-02-27 09:01:54 -0800650 }
651 }
652 return coverage
Dan Willemsen581341d2017-02-09 16:16:31 -0800653}
Ivan Lozano5f595532017-07-13 14:46:05 -0700654
655func (c *config) IntegerOverflowDisabledForPath(path string) bool {
656 if c.ProductVariables.IntegerOverflowExcludePaths == nil {
657 return false
658 }
659 return prefixInList(path, *c.ProductVariables.IntegerOverflowExcludePaths)
660}
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700661
662func (c *config) CFIDisabledForPath(path string) bool {
663 if c.ProductVariables.CFIExcludePaths == nil {
664 return false
665 }
666 return prefixInList(path, *c.ProductVariables.CFIExcludePaths)
667}
668
669func (c *config) CFIEnabledForPath(path string) bool {
670 if c.ProductVariables.CFIIncludePaths == nil {
671 return false
672 }
673 return prefixInList(path, *c.ProductVariables.CFIIncludePaths)
674}