blob: c3beb08ee8208c302f5c099bfc3ae96104de51f1 [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 {
91 config *config
92 targets []Arch
93 OncePer
Colin Cross3f40fa42015-01-30 17:27:36 -080094}
95
Colin Cross485e5722015-08-27 13:28:01 -070096type jsonConfigurable interface {
Colin Cross27385972015-09-18 10:57:10 -070097 SetDefaultConfig()
Colin Cross485e5722015-08-27 13:28:01 -070098}
Colin Cross3f40fa42015-01-30 17:27:36 -080099
Colin Cross485e5722015-08-27 13:28:01 -0700100func loadConfig(config *config) error {
Dan Willemsen87b17d12015-07-14 00:39:06 -0700101 err := loadFromConfigFile(&config.FileConfigurableOptions, config.ConfigFileName)
Colin Cross485e5722015-08-27 13:28:01 -0700102 if err != nil {
103 return err
104 }
105
Dan Willemsen87b17d12015-07-14 00:39:06 -0700106 return loadFromConfigFile(&config.ProductVariables, config.ProductVariablesFileName)
Colin Cross485e5722015-08-27 13:28:01 -0700107}
108
109// loads configuration options from a JSON file in the cwd.
110func loadFromConfigFile(configurable jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800111 // Try to open the file
Colin Cross485e5722015-08-27 13:28:01 -0700112 configFileReader, err := os.Open(filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800113 defer configFileReader.Close()
114 if os.IsNotExist(err) {
115 // Need to create a file, so that blueprint & ninja don't get in
116 // a dependency tracking loop.
117 // Make a file-configurable-options with defaults, write it out using
118 // a json writer.
Colin Cross27385972015-09-18 10:57:10 -0700119 configurable.SetDefaultConfig()
120 err = saveToConfigFile(configurable, filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800121 if err != nil {
122 return err
123 }
124 } else {
125 // Make a decoder for it
126 jsonDecoder := json.NewDecoder(configFileReader)
Colin Cross485e5722015-08-27 13:28:01 -0700127 err = jsonDecoder.Decode(configurable)
Colin Cross3f40fa42015-01-30 17:27:36 -0800128 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700129 return fmt.Errorf("config file: %s did not parse correctly: "+err.Error(), filename)
Colin Cross3f40fa42015-01-30 17:27:36 -0800130 }
131 }
132
Colin Cross3f40fa42015-01-30 17:27:36 -0800133 // No error
134 return nil
135}
136
Colin Crossd8f20142016-11-03 09:43:26 -0700137// atomically writes the config file in case two copies of soong_build are running simultaneously
138// (for example, docs generation and ninja manifest generation)
Colin Cross485e5722015-08-27 13:28:01 -0700139func saveToConfigFile(config jsonConfigurable, filename string) error {
Colin Cross3f40fa42015-01-30 17:27:36 -0800140 data, err := json.MarshalIndent(&config, "", " ")
141 if err != nil {
142 return fmt.Errorf("cannot marshal config data: %s", err.Error())
143 }
144
Colin Crossd8f20142016-11-03 09:43:26 -0700145 f, err := ioutil.TempFile(filepath.Dir(filename), "config")
Colin Cross3f40fa42015-01-30 17:27:36 -0800146 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700147 return fmt.Errorf("cannot create empty config file %s: %s\n", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800148 }
Colin Crossd8f20142016-11-03 09:43:26 -0700149 defer os.Remove(f.Name())
150 defer f.Close()
Colin Cross3f40fa42015-01-30 17:27:36 -0800151
Colin Crossd8f20142016-11-03 09:43:26 -0700152 _, err = f.Write(data)
Colin Cross3f40fa42015-01-30 17:27:36 -0800153 if err != nil {
Colin Cross485e5722015-08-27 13:28:01 -0700154 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
155 }
156
Colin Crossd8f20142016-11-03 09:43:26 -0700157 _, err = f.WriteString("\n")
Colin Cross485e5722015-08-27 13:28:01 -0700158 if err != nil {
159 return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800160 }
161
Colin Crossd8f20142016-11-03 09:43:26 -0700162 f.Close()
163 os.Rename(f.Name(), filename)
164
Colin Cross3f40fa42015-01-30 17:27:36 -0800165 return nil
166}
167
Colin Crossce75d2c2016-10-06 16:12:58 -0700168// TestConfig returns a Config object suitable for using for tests
Colin Cross0d614dd2016-10-14 15:38:43 -0700169func TestConfig(buildDir string) Config {
170 return Config{&config{
171 buildDir: buildDir,
172 }}
Colin Crossce75d2c2016-10-06 16:12:58 -0700173}
174
Colin Cross3f40fa42015-01-30 17:27:36 -0800175// New creates a new Config object. The srcDir argument specifies the path to
176// the root source directory. It also loads the config file, if found.
Dan Willemsen87b17d12015-07-14 00:39:06 -0700177func NewConfig(srcDir, buildDir string) (Config, error) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800178 // Make a config with default options
Colin Cross9272ade2016-08-17 15:24:12 -0700179 config := &config{
180 ConfigFileName: filepath.Join(buildDir, configFileName),
181 ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName),
Dan Willemsen87b17d12015-07-14 00:39:06 -0700182
Colin Cross9272ade2016-08-17 15:24:12 -0700183 srcDir: srcDir,
184 buildDir: buildDir,
Colin Cross9272ade2016-08-17 15:24:12 -0700185
186 deviceConfig: &deviceConfig{},
Colin Cross68f55102015-03-25 14:43:57 -0700187 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800188
Colin Cross9272ade2016-08-17 15:24:12 -0700189 deviceConfig := &deviceConfig{
190 config: config,
191 }
192
193 config.deviceConfig = deviceConfig
194
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700195 // Sanity check the build and source directories. This won't catch strange
196 // configurations with symlinks, but at least checks the obvious cases.
197 absBuildDir, err := filepath.Abs(buildDir)
198 if err != nil {
199 return Config{}, err
200 }
201
202 absSrcDir, err := filepath.Abs(srcDir)
203 if err != nil {
204 return Config{}, err
205 }
206
207 if strings.HasPrefix(absSrcDir, absBuildDir) {
208 return Config{}, fmt.Errorf("Build dir must not contain source directory")
209 }
210
Colin Cross3f40fa42015-01-30 17:27:36 -0800211 // Load any configurable options from the configuration file
Colin Cross9272ade2016-08-17 15:24:12 -0700212 err = loadConfig(config)
Colin Cross3f40fa42015-01-30 17:27:36 -0800213 if err != nil {
Colin Crossc3c0a492015-04-10 15:43:55 -0700214 return Config{}, err
Colin Cross3f40fa42015-01-30 17:27:36 -0800215 }
216
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800217 inMakeFile := filepath.Join(buildDir, ".soong.in_make")
218 if _, err := os.Stat(inMakeFile); err == nil {
219 config.inMake = true
220 }
221
Colin Crossa1ad8d12016-06-01 17:09:44 -0700222 targets, err := decodeTargetProductVariables(config)
Dan Willemsen218f6562015-07-08 18:13:11 -0700223 if err != nil {
224 return Config{}, err
225 }
226
Dan Albert4098deb2016-10-19 14:04:41 -0700227 var archConfig []archConfig
Dan Willemsen322acaf2016-01-12 23:07:05 -0800228 if Bool(config.Mega_device) {
Dan Albert4098deb2016-10-19 14:04:41 -0700229 archConfig = getMegaDeviceConfig()
230 } else if Bool(config.Ndk_abis) {
231 archConfig = getNdkAbisConfig()
232 }
233
234 if archConfig != nil {
235 deviceTargets, err := decodeArchSettings(archConfig)
Dan Willemsen322acaf2016-01-12 23:07:05 -0800236 if err != nil {
237 return Config{}, err
238 }
Colin Crossa1ad8d12016-06-01 17:09:44 -0700239 targets[Device] = deviceTargets
Dan Willemsen322acaf2016-01-12 23:07:05 -0800240 }
241
Colin Crossa1ad8d12016-06-01 17:09:44 -0700242 config.Targets = targets
243 config.BuildOsVariant = targets[Host][0].String()
Dan Willemsen218f6562015-07-08 18:13:11 -0700244
Colin Cross9272ade2016-08-17 15:24:12 -0700245 return Config{config}, nil
Colin Cross3f40fa42015-01-30 17:27:36 -0800246}
247
Dan Willemsen218f6562015-07-08 18:13:11 -0700248func (c *config) RemoveAbandonedFiles() bool {
249 return false
250}
251
Dan Willemsenc2aa4a92016-05-26 15:13:03 -0700252func (c *config) BlueprintToolLocation() string {
253 return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin")
254}
255
Dan Willemsen66068722017-05-08 21:15:59 +0000256// HostSystemTool looks for non-hermetic tools from the system we're running on.
257// Generally shouldn't be used, but useful to find the XCode SDK, etc.
258func (c *config) HostSystemTool(name string) string {
259 for _, dir := range filepath.SplitList(c.Getenv("PATH")) {
260 path := filepath.Join(dir, name)
261 if s, err := os.Stat(path); err != nil {
262 continue
263 } else if m := s.Mode(); !s.IsDir() && m&0111 != 0 {
264 return path
265 }
266 }
267 return name
268}
269
Colin Cross3f40fa42015-01-30 17:27:36 -0800270// PrebuiltOS returns the name of the host OS used in prebuilts directories
Colin Cross1332b002015-04-07 17:11:30 -0700271func (c *config) PrebuiltOS() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800272 switch runtime.GOOS {
273 case "linux":
274 return "linux-x86"
275 case "darwin":
276 return "darwin-x86"
277 default:
278 panic("Unknown GOOS")
279 }
280}
281
282// GoRoot returns the path to the root directory of the Go toolchain.
Colin Cross1332b002015-04-07 17:11:30 -0700283func (c *config) GoRoot() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800284 return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS())
285}
286
Colin Cross1332b002015-04-07 17:11:30 -0700287func (c *config) CpPreserveSymlinksFlags() string {
Colin Cross485e5722015-08-27 13:28:01 -0700288 switch runtime.GOOS {
Colin Cross3f40fa42015-01-30 17:27:36 -0800289 case "darwin":
290 return "-R"
291 case "linux":
292 return "-d"
293 default:
294 return ""
295 }
296}
Colin Cross68f55102015-03-25 14:43:57 -0700297
Colin Cross1332b002015-04-07 17:11:30 -0700298func (c *config) Getenv(key string) string {
Colin Cross68f55102015-03-25 14:43:57 -0700299 var val string
300 var exists bool
Colin Crossc1e86a32015-04-15 12:33:28 -0700301 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800302 defer c.envLock.Unlock()
303 if c.envDeps == nil {
304 c.envDeps = make(map[string]string)
305 }
Colin Cross68f55102015-03-25 14:43:57 -0700306 if val, exists = c.envDeps[key]; !exists {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700307 if c.envFrozen {
308 panic("Cannot access new environment variables after envdeps are frozen")
309 }
Dan Willemsen66068722017-05-08 21:15:59 +0000310 val, _ = originalEnv[key]
Colin Cross68f55102015-03-25 14:43:57 -0700311 c.envDeps[key] = val
312 }
313 return val
314}
315
Colin Cross99d7c232016-11-23 16:52:04 -0800316func (c *config) GetenvWithDefault(key string, defaultValue string) string {
317 ret := c.Getenv(key)
318 if ret == "" {
319 return defaultValue
320 }
321 return ret
322}
323
324func (c *config) IsEnvTrue(key string) bool {
325 value := c.Getenv(key)
326 return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
327}
328
329func (c *config) IsEnvFalse(key string) bool {
330 value := c.Getenv(key)
331 return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
332}
333
Colin Cross1332b002015-04-07 17:11:30 -0700334func (c *config) EnvDeps() map[string]string {
Dan Willemsene7680ba2015-09-11 17:06:19 -0700335 c.envLock.Lock()
Colin Crossc0d58b42017-02-06 15:40:41 -0800336 defer c.envLock.Unlock()
Dan Willemsene7680ba2015-09-11 17:06:19 -0700337 c.envFrozen = true
Colin Cross68f55102015-03-25 14:43:57 -0700338 return c.envDeps
339}
Colin Cross35cec122015-04-02 14:37:16 -0700340
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800341func (c *config) EmbeddedInMake() bool {
342 return c.inMake
343}
344
Colin Cross35cec122015-04-02 14:37:16 -0700345// DeviceName returns the name of the current device target
346// TODO: take an AndroidModuleContext to select the device name for multi-device builds
Colin Cross1332b002015-04-07 17:11:30 -0700347func (c *config) DeviceName() string {
Dan Willemsen1d31ec32015-09-22 16:56:09 -0700348 return *c.ProductVariables.DeviceName
Colin Cross35cec122015-04-02 14:37:16 -0700349}
350
Dan Willemsendd0e2c32015-10-20 14:29:35 -0700351func (c *config) DeviceUsesClang() bool {
352 if c.ProductVariables.DeviceUsesClang != nil {
353 return *c.ProductVariables.DeviceUsesClang
354 }
Dan Willemsen0084d782016-03-01 14:54:24 -0800355 return true
Dan Willemsendd0e2c32015-10-20 14:29:35 -0700356}
357
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700358func (c *config) ResourceOverlays() []SourcePath {
Colin Cross30e076a2015-04-13 13:58:27 -0700359 return nil
360}
361
362func (c *config) PlatformVersion() string {
363 return "M"
364}
365
Dan Albert073379e2016-11-10 10:46:36 -0800366func (c *config) PlatformSdkVersionInt() int {
367 return *c.ProductVariables.Platform_sdk_version
368}
369
Colin Cross30e076a2015-04-13 13:58:27 -0700370func (c *config) PlatformSdkVersion() string {
Dan Albert073379e2016-11-10 10:46:36 -0800371 return strconv.Itoa(c.PlatformSdkVersionInt())
Colin Cross30e076a2015-04-13 13:58:27 -0700372}
373
Dan Albert30c9d6e2017-03-28 14:54:55 -0700374func (c *config) PlatformVersionAllCodenames() []string {
375 return c.ProductVariables.Platform_version_all_codenames
376}
377
Colin Cross30e076a2015-04-13 13:58:27 -0700378func (c *config) BuildNumber() string {
379 return "000000"
380}
381
382func (c *config) ProductAaptConfig() []string {
383 return []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"}
384}
385
386func (c *config) ProductAaptPreferredConfig() string {
387 return "xhdpi"
388}
389
390func (c *config) ProductAaptCharacteristics() string {
391 return "nosdcard"
392}
393
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700394func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
395 return PathForSource(ctx, "build/target/product/security")
Colin Cross30e076a2015-04-13 13:58:27 -0700396}
397
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700398func (c *config) DefaultAppCertificate(ctx PathContext) SourcePath {
399 return c.DefaultAppCertificateDir(ctx).Join(ctx, "testkey")
Colin Cross30e076a2015-04-13 13:58:27 -0700400}
Colin Cross6ff51382015-12-17 16:39:19 -0800401
402func (c *config) AllowMissingDependencies() bool {
Dan Willemsenb5038162016-03-16 12:35:33 -0700403 return Bool(c.ProductVariables.Allow_missing_dependencies)
Colin Cross6ff51382015-12-17 16:39:19 -0800404}
Dan Willemsen322acaf2016-01-12 23:07:05 -0800405
Colin Cross1e7d3702016-08-24 15:25:47 -0700406func (c *config) DevicePrefer32BitExecutables() bool {
407 return Bool(c.ProductVariables.DevicePrefer32BitExecutables)
408}
409
Dan Willemsen7f730fd2016-01-14 11:22:23 -0800410func (c *config) SkipDeviceInstall() bool {
Colin Cross893d8162017-04-26 17:34:03 -0700411 return c.EmbeddedInMake()
412}
413
414func (c *config) SkipMegaDeviceInstall(path string) bool {
415 return Bool(c.Mega_device) &&
416 strings.HasPrefix(path, filepath.Join(c.buildDir, "target", "product"))
Dan Willemsen322acaf2016-01-12 23:07:05 -0800417}
Colin Cross16b23492016-01-06 14:41:07 -0800418
419func (c *config) SanitizeHost() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700420 return append([]string(nil), c.ProductVariables.SanitizeHost...)
Colin Cross16b23492016-01-06 14:41:07 -0800421}
422
423func (c *config) SanitizeDevice() []string {
Colin Cross23ae82a2016-11-02 14:34:39 -0700424 return append([]string(nil), c.ProductVariables.SanitizeDevice...)
425}
426
427func (c *config) SanitizeDeviceArch() []string {
428 return append([]string(nil), c.ProductVariables.SanitizeDeviceArch...)
Colin Cross16b23492016-01-06 14:41:07 -0800429}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700430
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800431func (c *config) EnableCFI() bool {
Vishwath Mohanc32c3eb2017-01-24 14:20:54 -0800432 if c.ProductVariables.EnableCFI == nil {
433 return true
434 } else {
435 return *c.ProductVariables.EnableCFI
436 }
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800437}
438
Colin Crossa1ad8d12016-06-01 17:09:44 -0700439func (c *config) Android64() bool {
440 for _, t := range c.Targets[Device] {
441 if t.Arch.ArchType.Multilib == "lib64" {
442 return true
443 }
444 }
445
446 return false
447}
Colin Cross9272ade2016-08-17 15:24:12 -0700448
Colin Cross9d45bb72016-08-29 16:14:13 -0700449func (c *config) UseGoma() bool {
450 return Bool(c.ProductVariables.UseGoma)
451}
452
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700453func (c *config) ClangTidy() bool {
454 return Bool(c.ProductVariables.ClangTidy)
455}
456
457func (c *config) TidyChecks() string {
458 if c.ProductVariables.TidyChecks == nil {
459 return ""
460 }
461 return *c.ProductVariables.TidyChecks
462}
463
Colin Cross0f4e0d62016-07-27 10:56:55 -0700464func (c *config) LibartImgHostBaseAddress() string {
465 return "0x60000000"
466}
467
468func (c *config) LibartImgDeviceBaseAddress() string {
469 switch c.Targets[Device][0].Arch.ArchType {
470 default:
471 return "0x70000000"
472 case Mips, Mips64:
Chris Larsenae7f3e22017-05-30 16:36:58 -0700473 return "0x5C000000"
Colin Cross0f4e0d62016-07-27 10:56:55 -0700474 }
475}
476
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800477func (c *config) ArtUseReadBarrier() bool {
478 return Bool(c.ProductVariables.ArtUseReadBarrier)
479}
480
Colin Cross9272ade2016-08-17 15:24:12 -0700481func (c *deviceConfig) Arches() []Arch {
482 var arches []Arch
483 for _, target := range c.config.Targets[Device] {
484 arches = append(arches, target.Arch)
485 }
486 return arches
487}
Dan Willemsend2ede872016-11-18 14:54:24 -0800488
Dan Willemsen4353bc42016-12-05 17:16:02 -0800489func (c *deviceConfig) VendorPath() string {
490 if c.config.ProductVariables.VendorPath != nil {
491 return *c.config.ProductVariables.VendorPath
492 }
493 return "vendor"
494}
495
Dan Willemsen11b26142017-03-19 18:30:37 -0700496func (c *deviceConfig) CompileVndk() bool {
Dan Willemsend2ede872016-11-18 14:54:24 -0800497 if c.config.ProductVariables.DeviceVndkVersion == nil {
Dan Willemsen11b26142017-03-19 18:30:37 -0700498 return false
Dan Willemsend2ede872016-11-18 14:54:24 -0800499 }
Dan Willemsen11b26142017-03-19 18:30:37 -0700500 return *c.config.ProductVariables.DeviceVndkVersion == "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800501}
Jack He8cc71432016-12-08 15:45:07 -0800502
503func (c *deviceConfig) BtConfigIncludeDir() string {
504 return String(c.config.ProductVariables.BtConfigIncludeDir)
505}
Dan Willemsen581341d2017-02-09 16:16:31 -0800506
507func (c *deviceConfig) NativeCoverageEnabled() bool {
508 return Bool(c.config.ProductVariables.NativeCoverage)
509}
510
511func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
Ryan Campbell469a18a2017-02-27 09:01:54 -0800512 coverage := false
Dan Willemsen581341d2017-02-09 16:16:31 -0800513 if c.config.ProductVariables.CoveragePaths != nil {
514 for _, prefix := range *c.config.ProductVariables.CoveragePaths {
515 if strings.HasPrefix(path, prefix) {
Ryan Campbell469a18a2017-02-27 09:01:54 -0800516 coverage = true
517 break
Dan Willemsen581341d2017-02-09 16:16:31 -0800518 }
519 }
520 }
Ryan Campbell469a18a2017-02-27 09:01:54 -0800521 if coverage && c.config.ProductVariables.CoverageExcludePaths != nil {
522 for _, prefix := range *c.config.ProductVariables.CoverageExcludePaths {
523 if strings.HasPrefix(path, prefix) {
524 coverage = false
525 break
526 }
527 }
528 }
529 return coverage
Dan Willemsen581341d2017-02-09 16:16:31 -0800530}