blob: dbb9fa41fff63f965a35b48fd3189039b7f88c1e [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 Cross9272ade2016-08-17 15:24:12 -070087 OncePer
88}
89
90type deviceConfig struct {
Dan Willemsen00269f22017-07-06 16:59:48 -070091 config *config
Colin Cross9272ade2016-08-17 15:24:12 -070092 OncePer
Colin Cross3f40fa42015-01-30 17:27:36 -080093}
94
Colin Cross485e5722015-08-27 13:28:01 -070095type jsonConfigurable interface {
Colin Cross27385972015-09-18 10:57:10 -070096 SetDefaultConfig()
Colin Cross485e5722015-08-27 13:28:01 -070097}
Colin Cross3f40fa42015-01-30 17:27:36 -080098
Colin Cross485e5722015-08-27 13:28:01 -070099func loadConfig(config *config) error {
Dan Willemsen87b17d12015-07-14 00:39:06 -0700100 err := loadFromConfigFile(&config.FileConfigurableOptions, config.ConfigFileName)
Colin Cross485e5722015-08-27 13:28:01 -0700101 if err != nil {
102 return err
103 }
104
Dan Willemsen87b17d12015-07-14 00:39:06 -0700105 return loadFromConfigFile(&config.ProductVariables, config.ProductVariablesFileName)
Colin Cross485e5722015-08-27 13:28:01 -0700106}
107
108// loads configuration options from a JSON file in the cwd.
109func loadFromConfigFile(configurable jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800110 // Try to open the file
Colin Cross485e5722015-08-27 13:28:01 -0700111 configFileReader, err := os.Open(filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800112 defer configFileReader.Close()
113 if os.IsNotExist(err) {
114 // Need to create a file, so that blueprint & ninja don't get in
115 // a dependency tracking loop.
116 // Make a file-configurable-options with defaults, write it out using
117 // a json writer.
Colin Cross27385972015-09-18 10:57:10 -0700118 configurable.SetDefaultConfig()
119 err = saveToConfigFile(configurable, filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800120 if err != nil {
121 return err
122 }
123 } else {
124 // Make a decoder for it
125 jsonDecoder := json.NewDecoder(configFileReader)
Colin Cross485e5722015-08-27 13:28:01 -0700126 err = jsonDecoder.Decode(configurable)
Colin Cross3f40fa42015-01-30 17:27:36 -0800127 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700128 return fmt.Errorf("config file: %s did not parse correctly: "+err.Error(), filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800129 }
130 }
131
Colin Cross3f40fa42015-01-30 17:27:36 -0800132 // No error
133 return nil
134}
135
Colin Crossd8f20142016-11-03 09:43:26 -0700136// atomically writes the config file in case two copies of soong_build are running simultaneously
137// (for example, docs generation and ninja manifest generation)
Colin Cross485e5722015-08-27 13:28:01 -0700138func saveToConfigFile(config jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800139 data, err := json.MarshalIndent(&config, "", " ")
140 if err != nil {
141 return fmt.Errorf("cannot marshal config data: %s", err.Error())
142 }
143
Colin Crossd8f20142016-11-03 09:43:26 -0700144 f, err := ioutil.TempFile(filepath.Dir(filename), "config")
Colin Cross3f40fa42015-01-30 17:27:36 -0800145 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700146 return fmt.Errorf("cannot create empty config file %s: %s\n", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800147 }
Colin Crossd8f20142016-11-03 09:43:26 -0700148 defer os.Remove(f.Name())
149 defer f.Close()
Colin Cross3f40fa42015-01-30 17:27:36 -0800150
Colin Crossd8f20142016-11-03 09:43:26 -0700151 _, err = f.Write(data)
Colin Cross3f40fa42015-01-30 17:27:36 -0800152 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700153 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
154 }
155
Colin Crossd8f20142016-11-03 09:43:26 -0700156 _, err = f.WriteString("\n")
Colin Cross485e5722015-08-27 13:28:01 -0700157 if err != nil {
158 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800159 }
160
Colin Crossd8f20142016-11-03 09:43:26 -0700161 f.Close()
162 os.Rename(f.Name(), filename)
163
Colin Cross3f40fa42015-01-30 17:27:36 -0800164 return nil
165}
166
Colin Crossce75d2c2016-10-06 16:12:58 -0700167// TestConfig returns a Config object suitable for using for tests
Colin Cross0d614dd2016-10-14 15:38:43 -0700168func TestConfig(buildDir string) Config {
Dan Willemsen00269f22017-07-06 16:59:48 -0700169 config := &config{
170 ProductVariables: productVariables{
171 DeviceName: stringPtr("test_device"),
172 },
173
Colin Cross0d614dd2016-10-14 15:38:43 -0700174 buildDir: buildDir,
Dan Willemsen00269f22017-07-06 16:59:48 -0700175 }
176 config.deviceConfig = &deviceConfig{
177 config: config,
178 }
179
180 return Config{config}
Colin Crossce75d2c2016-10-06 16:12:58 -0700181}
182
Colin Cross3f40fa42015-01-30 17:27:36 -0800183// New creates a new Config object. The srcDir argument specifies the path to
184// the root source directory. It also loads the config file, if found.
Dan Willemsen87b17d12015-07-14 00:39:06 -0700185func NewConfig(srcDir, buildDir string) (Config, error) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800186 // Make a config with default options
Colin Cross9272ade2016-08-17 15:24:12 -0700187 config := &config{
188 ConfigFileName: filepath.Join(buildDir, configFileName),
189 ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName),
Dan Willemsen87b17d12015-07-14 00:39:06 -0700190
Colin Cross9272ade2016-08-17 15:24:12 -0700191 srcDir: srcDir,
192 buildDir: buildDir,
Colin Cross68f55102015-03-25 14:43:57 -0700193 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800194
Dan Willemsen00269f22017-07-06 16:59:48 -0700195 config.deviceConfig = &deviceConfig{
Colin Cross9272ade2016-08-17 15:24:12 -0700196 config: config,
197 }
198
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700199 // Sanity check the build and source directories. This won't catch strange
200 // configurations with symlinks, but at least checks the obvious cases.
201 absBuildDir, err := filepath.Abs(buildDir)
202 if err != nil {
203 return Config{}, err
204 }
205
206 absSrcDir, err := filepath.Abs(srcDir)
207 if err != nil {
208 return Config{}, err
209 }
210
211 if strings.HasPrefix(absSrcDir, absBuildDir) {
212 return Config{}, fmt.Errorf("Build dir must not contain source directory")
213 }
214
Colin Cross3f40fa42015-01-30 17:27:36 -0800215 // Load any configurable options from the configuration file
Colin Cross9272ade2016-08-17 15:24:12 -0700216 err = loadConfig(config)
Colin Cross3f40fa42015-01-30 17:27:36 -0800217 if err != nil {
Colin Crossc3c0a492015-04-10 15:43:55 -0700218 return Config{}, err
Colin Cross3f40fa42015-01-30 17:27:36 -0800219 }
220
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800221 inMakeFile := filepath.Join(buildDir, ".soong.in_make")
222 if _, err := os.Stat(inMakeFile); err == nil {
223 config.inMake = true
224 }
225
Colin Crossa1ad8d12016-06-01 17:09:44 -0700226 targets, err := decodeTargetProductVariables(config)
Dan Willemsen218f6562015-07-08 18:13:11 -0700227 if err != nil {
228 return Config{}, err
229 }
230
Dan Albert4098deb2016-10-19 14:04:41 -0700231 var archConfig []archConfig
Dan Willemsen322acaf2016-01-12 23:07:05 -0800232 if Bool(config.Mega_device) {
Dan Albert4098deb2016-10-19 14:04:41 -0700233 archConfig = getMegaDeviceConfig()
234 } else if Bool(config.Ndk_abis) {
235 archConfig = getNdkAbisConfig()
236 }
237
238 if archConfig != nil {
239 deviceTargets, err := decodeArchSettings(archConfig)
Dan Willemsen322acaf2016-01-12 23:07:05 -0800240 if err != nil {
241 return Config{}, err
242 }
Colin Crossa1ad8d12016-06-01 17:09:44 -0700243 targets[Device] = deviceTargets
Dan Willemsen322acaf2016-01-12 23:07:05 -0800244 }
245
Colin Crossa1ad8d12016-06-01 17:09:44 -0700246 config.Targets = targets
247 config.BuildOsVariant = targets[Host][0].String()
Dan Willemsen218f6562015-07-08 18:13:11 -0700248
Colin Cross9272ade2016-08-17 15:24:12 -0700249 return Config{config}, nil
Colin Cross3f40fa42015-01-30 17:27:36 -0800250}
251
Dan Willemsen218f6562015-07-08 18:13:11 -0700252func (c *config) RemoveAbandonedFiles() bool {
253 return false
254}
255
Dan Willemsenc2aa4a92016-05-26 15:13:03 -0700256func (c *config) BlueprintToolLocation() string {
257 return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin")
258}
259
Dan Willemsen66068722017-05-08 21:15:59 +0000260// HostSystemTool looks for non-hermetic tools from the system we're running on.
261// Generally shouldn't be used, but useful to find the XCode SDK, etc.
262func (c *config) HostSystemTool(name string) string {
263 for _, dir := range filepath.SplitList(c.Getenv("PATH")) {
264 path := filepath.Join(dir, name)
265 if s, err := os.Stat(path); err != nil {
266 continue
267 } else if m := s.Mode(); !s.IsDir() && m&0111 != 0 {
268 return path
269 }
270 }
271 return name
272}
273
Colin Cross3f40fa42015-01-30 17:27:36 -0800274// PrebuiltOS returns the name of the host OS used in prebuilts directories
Colin Cross1332b002015-04-07 17:11:30 -0700275func (c *config) PrebuiltOS() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800276 switch runtime.GOOS {
277 case "linux":
278 return "linux-x86"
279 case "darwin":
280 return "darwin-x86"
281 default:
282 panic("Unknown GOOS")
283 }
284}
285
286// GoRoot returns the path to the root directory of the Go toolchain.
Colin Cross1332b002015-04-07 17:11:30 -0700287func (c *config) GoRoot() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800288 return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS())
289}
290
Colin Cross1332b002015-04-07 17:11:30 -0700291func (c *config) CpPreserveSymlinksFlags() string {
Colin Cross485e5722015-08-27 13:28:01 -0700292 switch runtime.GOOS {
Colin Cross3f40fa42015-01-30 17:27:36 -0800293 case "darwin":
294 return "-R"
295 case "linux":
296 return "-d"
297 default:
298 return ""
299 }
300}
Colin Cross68f55102015-03-25 14:43:57 -0700301
Colin Cross1332b002015-04-07 17:11:30 -0700302func (c *config) Getenv(key string) string {
Colin Cross68f55102015-03-25 14:43:57 -0700303 var val string
304 var exists bool
Colin Crossc1e86a32015-04-15 12:33:28 -0700305 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800306 defer c.envLock.Unlock()
307 if c.envDeps == nil {
308 c.envDeps = make(map[string]string)
309 }
Colin Cross68f55102015-03-25 14:43:57 -0700310 if val, exists = c.envDeps[key]; !exists {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700311 if c.envFrozen {
312 panic("Cannot access new environment variables after envdeps are frozen")
313 }
Dan Willemsen66068722017-05-08 21:15:59 +0000314 val, _ = originalEnv[key]
Colin Cross68f55102015-03-25 14:43:57 -0700315 c.envDeps[key] = val
316 }
317 return val
318}
319
Colin Cross99d7c232016-11-23 16:52:04 -0800320func (c *config) GetenvWithDefault(key string, defaultValue string) string {
321 ret := c.Getenv(key)
322 if ret == "" {
323 return defaultValue
324 }
325 return ret
326}
327
328func (c *config) IsEnvTrue(key string) bool {
329 value := c.Getenv(key)
330 return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
331}
332
333func (c *config) IsEnvFalse(key string) bool {
334 value := c.Getenv(key)
335 return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
336}
337
Colin Cross1332b002015-04-07 17:11:30 -0700338func (c *config) EnvDeps() map[string]string {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700339 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800340 defer c.envLock.Unlock()
Dan Willemsene7680ba2015-09-11 17:06:19 -0700341 c.envFrozen = true
Colin Cross68f55102015-03-25 14:43:57 -0700342 return c.envDeps
343}
Colin Cross35cec122015-04-02 14:37:16 -0700344
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800345func (c *config) EmbeddedInMake() bool {
346 return c.inMake
347}
348
Colin Cross35cec122015-04-02 14:37:16 -0700349// DeviceName returns the name of the current device target
350// TODO: take an AndroidModuleContext to select the device name for multi-device builds
Colin Cross1332b002015-04-07 17:11:30 -0700351func (c *config) DeviceName() string {
Dan Willemsen1d31ec32015-09-22 16:56:09 -0700352 return *c.ProductVariables.DeviceName
Colin Cross35cec122015-04-02 14:37:16 -0700353}
354
Dan Willemsendd0e2c32015-10-20 14:29:35 -0700355func (c *config) DeviceUsesClang() bool {
356 if c.ProductVariables.DeviceUsesClang != nil {
357 return *c.ProductVariables.DeviceUsesClang
358 }
Dan Willemsen0084d782016-03-01 14:54:24 -0800359 return true
Dan Willemsendd0e2c32015-10-20 14:29:35 -0700360}
361
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700362func (c *config) ResourceOverlays() []SourcePath {
Colin Cross30e076a2015-04-13 13:58:27 -0700363 return nil
364}
365
366func (c *config) PlatformVersion() string {
367 return "M"
368}
369
Dan Albert073379e2016-11-10 10:46:36 -0800370func (c *config) PlatformSdkVersionInt() int {
371 return *c.ProductVariables.Platform_sdk_version
372}
373
Colin Cross30e076a2015-04-13 13:58:27 -0700374func (c *config) PlatformSdkVersion() string {
Dan Albert073379e2016-11-10 10:46:36 -0800375 return strconv.Itoa(c.PlatformSdkVersionInt())
Colin Cross30e076a2015-04-13 13:58:27 -0700376}
377
Dan Albert30c9d6e2017-03-28 14:54:55 -0700378func (c *config) PlatformVersionAllCodenames() []string {
379 return c.ProductVariables.Platform_version_all_codenames
380}
381
Colin Cross30e076a2015-04-13 13:58:27 -0700382func (c *config) BuildNumber() string {
383 return "000000"
384}
385
386func (c *config) ProductAaptConfig() []string {
387 return []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"}
388}
389
390func (c *config) ProductAaptPreferredConfig() string {
391 return "xhdpi"
392}
393
394func (c *config) ProductAaptCharacteristics() string {
395 return "nosdcard"
396}
397
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700398func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
399 return PathForSource(ctx, "build/target/product/security")
Colin Cross30e076a2015-04-13 13:58:27 -0700400}
401
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700402func (c *config) DefaultAppCertificate(ctx PathContext) SourcePath {
403 return c.DefaultAppCertificateDir(ctx).Join(ctx, "testkey")
Colin Cross30e076a2015-04-13 13:58:27 -0700404}
Colin Cross6ff51382015-12-17 16:39:19 -0800405
406func (c *config) AllowMissingDependencies() bool {
Dan Willemsenb5038162016-03-16 12:35:33 -0700407 return Bool(c.ProductVariables.Allow_missing_dependencies)
Colin Cross6ff51382015-12-17 16:39:19 -0800408}
Dan Willemsen322acaf2016-01-12 23:07:05 -0800409
Colin Cross1e7d3702016-08-24 15:25:47 -0700410func (c *config) DevicePrefer32BitExecutables() bool {
411 return Bool(c.ProductVariables.DevicePrefer32BitExecutables)
412}
413
Dan Willemsen7f730fd2016-01-14 11:22:23 -0800414func (c *config) SkipDeviceInstall() bool {
Colin Cross893d8162017-04-26 17:34:03 -0700415 return c.EmbeddedInMake()
416}
417
418func (c *config) SkipMegaDeviceInstall(path string) bool {
419 return Bool(c.Mega_device) &&
420 strings.HasPrefix(path, filepath.Join(c.buildDir, "target", "product"))
Dan Willemsen322acaf2016-01-12 23:07:05 -0800421}
Colin Cross16b23492016-01-06 14:41:07 -0800422
423func (c *config) SanitizeHost() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700424 return append([]string(nil), c.ProductVariables.SanitizeHost...)
Colin Cross16b23492016-01-06 14:41:07 -0800425}
426
427func (c *config) SanitizeDevice() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700428 return append([]string(nil), c.ProductVariables.SanitizeDevice...)
429}
430
431func (c *config) SanitizeDeviceArch() []string {
432 return append([]string(nil), c.ProductVariables.SanitizeDeviceArch...)
Colin Cross16b23492016-01-06 14:41:07 -0800433}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700434
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800435func (c *config) EnableCFI() bool {
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -0800436 if c.ProductVariables.EnableCFI == nil {
437 return true
438 } else {
439 return *c.ProductVariables.EnableCFI
440 }
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800441}
442
Colin Crossa1ad8d12016-06-01 17:09:44 -0700443func (c *config) Android64() bool {
444 for _, t := range c.Targets[Device] {
445 if t.Arch.ArchType.Multilib == "lib64" {
446 return true
447 }
448 }
449
450 return false
451}
Colin Cross9272ade2016-08-17 15:24:12 -0700452
Colin Cross9d45bb72016-08-29 16:14:13 -0700453func (c *config) UseGoma() bool {
454 return Bool(c.ProductVariables.UseGoma)
455}
456
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700457func (c *config) ClangTidy() bool {
458 return Bool(c.ProductVariables.ClangTidy)
459}
460
461func (c *config) TidyChecks() string {
462 if c.ProductVariables.TidyChecks == nil {
463 return ""
464 }
465 return *c.ProductVariables.TidyChecks
466}
467
Colin Cross0f4e0d62016-07-27 10:56:55 -0700468func (c *config) LibartImgHostBaseAddress() string {
469 return "0x60000000"
470}
471
472func (c *config) LibartImgDeviceBaseAddress() string {
Colin Cross20e13652017-06-22 15:34:51 -0700473 archType := Common
474 if len(c.Targets[Device]) > 0 {
475 archType = c.Targets[Device][0].Arch.ArchType
476 }
477 switch archType {
Colin Cross0f4e0d62016-07-27 10:56:55 -0700478 default:
479 return "0x70000000"
480 case Mips, Mips64:
Chris Larsenae7f3e22017-05-30 16:36:58 -0700481 return "0x5C000000"
Colin Cross0f4e0d62016-07-27 10:56:55 -0700482 }
483}
484
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800485func (c *config) ArtUseReadBarrier() bool {
486 return Bool(c.ProductVariables.ArtUseReadBarrier)
487}
488
Colin Cross9272ade2016-08-17 15:24:12 -0700489func (c *deviceConfig) Arches() []Arch {
490 var arches []Arch
491 for _, target := range c.config.Targets[Device] {
492 arches = append(arches, target.Arch)
493 }
494 return arches
495}
Dan Willemsend2ede872016-11-18 14:54:24 -0800496
Dan Willemsen4353bc42016-12-05 17:16:02 -0800497func (c *deviceConfig) VendorPath() string {
498 if c.config.ProductVariables.VendorPath != nil {
499 return *c.config.ProductVariables.VendorPath
500 }
501 return "vendor"
502}
503
Dan Willemsen11b26142017-03-19 18:30:37 -0700504func (c *deviceConfig) CompileVndk() bool {
Dan Willemsend2ede872016-11-18 14:54:24 -0800505 if c.config.ProductVariables.DeviceVndkVersion == nil {
Dan Willemsen11b26142017-03-19 18:30:37 -0700506 return false
Dan Willemsend2ede872016-11-18 14:54:24 -0800507 }
Dan Willemsen11b26142017-03-19 18:30:37 -0700508 return *c.config.ProductVariables.DeviceVndkVersion == "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800509}
Jack He8cc71432016-12-08 15:45:07 -0800510
511func (c *deviceConfig) BtConfigIncludeDir() string {
512 return String(c.config.ProductVariables.BtConfigIncludeDir)
513}
Dan Willemsen581341d2017-02-09 16:16:31 -0800514
515func (c *deviceConfig) NativeCoverageEnabled() bool {
516 return Bool(c.config.ProductVariables.NativeCoverage)
517}
518
519func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
Ryan Campbell469a18a2017-02-27 09:01:54 -0800520 coverage := false
Dan Willemsen581341d2017-02-09 16:16:31 -0800521 if c.config.ProductVariables.CoveragePaths != nil {
522 for _, prefix := range *c.config.ProductVariables.CoveragePaths {
523 if strings.HasPrefix(path, prefix) {
Ryan Campbell469a18a2017-02-27 09:01:54 -0800524 coverage = true
525 break
Dan Willemsen581341d2017-02-09 16:16:31 -0800526 }
527 }
528 }
Ryan Campbell469a18a2017-02-27 09:01:54 -0800529 if coverage && c.config.ProductVariables.CoverageExcludePaths != nil {
530 for _, prefix := range *c.config.ProductVariables.CoverageExcludePaths {
531 if strings.HasPrefix(path, prefix) {
532 coverage = false
533 break
534 }
535 }
536 }
537 return coverage
Dan Willemsen581341d2017-02-09 16:16:31 -0800538}