Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1 | // 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 Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 15 | package android |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 16 | |
| 17 | import ( |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 18 | "encoding/json" |
| 19 | "fmt" |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 20 | "io/ioutil" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 21 | "os" |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 22 | "path/filepath" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 23 | "runtime" |
Dan Willemsen | 5951c8a | 2016-07-19 19:08:14 -0700 | [diff] [blame] | 24 | "strconv" |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 25 | "strings" |
Colin Cross | c1e86a3 | 2015-04-15 12:33:28 -0700 | [diff] [blame] | 26 | "sync" |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 27 | |
| 28 | "github.com/google/blueprint/proptools" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 29 | ) |
| 30 | |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 31 | var Bool = proptools.Bool |
Jack He | 8cc7143 | 2016-12-08 15:45:07 -0800 | [diff] [blame] | 32 | var String = proptools.String |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 33 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 34 | // The configuration file name |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 35 | const configFileName = "soong.config" |
| 36 | const productVariablesFileName = "soong.variables" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 37 | |
| 38 | // A FileConfigurableOptions contains options which can be configured by the |
| 39 | // config file. These will be included in the config struct. |
| 40 | type FileConfigurableOptions struct { |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 41 | Mega_device *bool `json:",omitempty"` |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 42 | Ndk_abis *bool `json:",omitempty"` |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 43 | Host_bionic *bool `json:",omitempty"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 44 | } |
| 45 | |
Colin Cross | 2738597 | 2015-09-18 10:57:10 -0700 | [diff] [blame] | 46 | func (f *FileConfigurableOptions) SetDefaultConfig() { |
| 47 | *f = FileConfigurableOptions{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 50 | // A Config object represents the entire build configuration for Android. |
Colin Cross | c3c0a49 | 2015-04-10 15:43:55 -0700 | [diff] [blame] | 51 | type Config struct { |
| 52 | *config |
| 53 | } |
| 54 | |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 55 | func (c Config) BuildDir() string { |
| 56 | return c.buildDir |
| 57 | } |
| 58 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 59 | // 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 |
| 62 | type DeviceConfig struct { |
| 63 | *deviceConfig |
| 64 | } |
| 65 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 66 | type config struct { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 67 | FileConfigurableOptions |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 68 | ProductVariables productVariables |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 69 | |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 70 | ConfigFileName string |
| 71 | ProductVariablesFileName string |
| 72 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 73 | Targets map[OsClass][]Target |
| 74 | BuildOsVariant string |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 75 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 76 | deviceConfig *deviceConfig |
| 77 | |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 78 | srcDir string // the path of the root source directory |
| 79 | buildDir string // the path of the build output directory |
Colin Cross | c1e86a3 | 2015-04-15 12:33:28 -0700 | [diff] [blame] | 80 | |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 81 | env map[string]string |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 82 | envLock sync.Mutex |
| 83 | envDeps map[string]string |
| 84 | envFrozen bool |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 85 | |
| 86 | inMake bool |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 87 | |
Colin Cross | 32616ed | 2017-09-05 21:56:44 -0700 | [diff] [blame] | 88 | captureBuild bool // true for tests, saves build parameters for each module |
| 89 | ignoreEnvironment bool // true for tests, returns empty from all Getenv calls |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 90 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 91 | useOpenJDK9 bool // Use OpenJDK9, but possibly target 1.8 |
| 92 | targetOpenJDK9 bool // Use OpenJDK9 and target 1.9 |
| 93 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 94 | OncePer |
| 95 | } |
| 96 | |
| 97 | type deviceConfig struct { |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 98 | config *config |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 99 | OncePer |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 102 | type jsonConfigurable interface { |
Colin Cross | 2738597 | 2015-09-18 10:57:10 -0700 | [diff] [blame] | 103 | SetDefaultConfig() |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 104 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 105 | |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 106 | func loadConfig(config *config) error { |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 107 | err := loadFromConfigFile(&config.FileConfigurableOptions, config.ConfigFileName) |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 108 | if err != nil { |
| 109 | return err |
| 110 | } |
| 111 | |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 112 | return loadFromConfigFile(&config.ProductVariables, config.ProductVariablesFileName) |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | // loads configuration options from a JSON file in the cwd. |
| 116 | func loadFromConfigFile(configurable jsonConfigurable, filename string) error { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 117 | // Try to open the file |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 118 | configFileReader, err := os.Open(filename) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 119 | 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 Cross | 2738597 | 2015-09-18 10:57:10 -0700 | [diff] [blame] | 125 | configurable.SetDefaultConfig() |
| 126 | err = saveToConfigFile(configurable, filename) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 127 | if err != nil { |
| 128 | return err |
| 129 | } |
| 130 | } else { |
| 131 | // Make a decoder for it |
| 132 | jsonDecoder := json.NewDecoder(configFileReader) |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 133 | err = jsonDecoder.Decode(configurable) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 134 | if err != nil { |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 135 | return fmt.Errorf("config file: %s did not parse correctly: "+err.Error(), filename) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 139 | // No error |
| 140 | return nil |
| 141 | } |
| 142 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 143 | // 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 Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 145 | func saveToConfigFile(config jsonConfigurable, filename string) error { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 146 | data, err := json.MarshalIndent(&config, "", " ") |
| 147 | if err != nil { |
| 148 | return fmt.Errorf("cannot marshal config data: %s", err.Error()) |
| 149 | } |
| 150 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 151 | f, err := ioutil.TempFile(filepath.Dir(filename), "config") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 152 | if err != nil { |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 153 | return fmt.Errorf("cannot create empty config file %s: %s\n", filename, err.Error()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 154 | } |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 155 | defer os.Remove(f.Name()) |
| 156 | defer f.Close() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 157 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 158 | _, err = f.Write(data) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 159 | if err != nil { |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 160 | return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error()) |
| 161 | } |
| 162 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 163 | _, err = f.WriteString("\n") |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 164 | if err != nil { |
| 165 | return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 168 | f.Close() |
| 169 | os.Rename(f.Name(), filename) |
| 170 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 171 | return nil |
| 172 | } |
| 173 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 174 | // TestConfig returns a Config object suitable for using for tests |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 175 | func TestConfig(buildDir string, env map[string]string) Config { |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 176 | config := &config{ |
| 177 | ProductVariables: productVariables{ |
| 178 | DeviceName: stringPtr("test_device"), |
| 179 | }, |
| 180 | |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 181 | buildDir: buildDir, |
| 182 | captureBuild: true, |
| 183 | env: env, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 184 | } |
| 185 | config.deviceConfig = &deviceConfig{ |
| 186 | config: config, |
| 187 | } |
| 188 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 189 | if err := config.fromEnv(); err != nil { |
| 190 | panic(err) |
| 191 | } |
| 192 | |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 193 | return Config{config} |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 196 | // TestConfig returns a Config object suitable for using for tests that need to run the arch mutator |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 197 | func TestArchConfig(buildDir string, env map[string]string) Config { |
| 198 | testConfig := TestConfig(buildDir, env) |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 199 | config := testConfig.config |
| 200 | |
| 201 | config.Targets = map[OsClass][]Target{ |
| 202 | Device: []Target{ |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 203 | {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Native: true}}, |
| 204 | {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Native: true}}, |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 205 | }, |
| 206 | Host: []Target{ |
| 207 | {BuildOs, Arch{ArchType: X86_64}}, |
| 208 | {BuildOs, Arch{ArchType: X86}}, |
| 209 | }, |
| 210 | } |
| 211 | |
| 212 | return testConfig |
| 213 | } |
| 214 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 215 | // 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 Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 217 | func NewConfig(srcDir, buildDir string) (Config, error) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 218 | // Make a config with default options |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 219 | config := &config{ |
| 220 | ConfigFileName: filepath.Join(buildDir, configFileName), |
| 221 | ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName), |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 222 | |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 223 | env: originalEnv, |
| 224 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 225 | srcDir: srcDir, |
| 226 | buildDir: buildDir, |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 227 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 228 | |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 229 | config.deviceConfig = &deviceConfig{ |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 230 | config: config, |
| 231 | } |
| 232 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 233 | // 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 Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 249 | // Load any configurable options from the configuration file |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 250 | err = loadConfig(config) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 251 | if err != nil { |
Colin Cross | c3c0a49 | 2015-04-10 15:43:55 -0700 | [diff] [blame] | 252 | return Config{}, err |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 253 | } |
| 254 | |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 255 | inMakeFile := filepath.Join(buildDir, ".soong.in_make") |
| 256 | if _, err := os.Stat(inMakeFile); err == nil { |
| 257 | config.inMake = true |
| 258 | } |
| 259 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 260 | targets, err := decodeTargetProductVariables(config) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 261 | if err != nil { |
| 262 | return Config{}, err |
| 263 | } |
| 264 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 265 | var archConfig []archConfig |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 266 | if Bool(config.Mega_device) { |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 267 | archConfig = getMegaDeviceConfig() |
| 268 | } else if Bool(config.Ndk_abis) { |
| 269 | archConfig = getNdkAbisConfig() |
| 270 | } |
| 271 | |
| 272 | if archConfig != nil { |
| 273 | deviceTargets, err := decodeArchSettings(archConfig) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 274 | if err != nil { |
| 275 | return Config{}, err |
| 276 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 277 | targets[Device] = deviceTargets |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 280 | config.Targets = targets |
| 281 | config.BuildOsVariant = targets[Host][0].String() |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 282 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 283 | if err := config.fromEnv(); err != nil { |
| 284 | return Config{}, err |
| 285 | } |
| 286 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 287 | return Config{config}, nil |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 288 | } |
| 289 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 290 | func (c *config) fromEnv() error { |
| 291 | switch c.Getenv("EXPERIMENTAL_USE_OPENJDK9") { |
| 292 | case "": |
| 293 | // Use OpenJDK8 |
| 294 | case "1.8": |
| 295 | // Use OpenJDK9, but target 1.8 |
| 296 | c.useOpenJDK9 = true |
| 297 | case "true": |
| 298 | // Use OpenJDK9 and target 1.9 |
| 299 | c.useOpenJDK9 = true |
| 300 | c.targetOpenJDK9 = true |
| 301 | default: |
| 302 | return fmt.Errorf(`Invalid value for EXPERIMENTAL_USE_OPENJDK9, should be "", "1.8", or "true"`) |
| 303 | } |
| 304 | |
| 305 | return nil |
| 306 | } |
| 307 | |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 308 | func (c *config) RemoveAbandonedFiles() bool { |
| 309 | return false |
| 310 | } |
| 311 | |
Dan Willemsen | c2aa4a9 | 2016-05-26 15:13:03 -0700 | [diff] [blame] | 312 | func (c *config) BlueprintToolLocation() string { |
| 313 | return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin") |
| 314 | } |
| 315 | |
Dan Willemsen | 6606872 | 2017-05-08 21:15:59 +0000 | [diff] [blame] | 316 | // HostSystemTool looks for non-hermetic tools from the system we're running on. |
| 317 | // Generally shouldn't be used, but useful to find the XCode SDK, etc. |
| 318 | func (c *config) HostSystemTool(name string) string { |
| 319 | for _, dir := range filepath.SplitList(c.Getenv("PATH")) { |
| 320 | path := filepath.Join(dir, name) |
| 321 | if s, err := os.Stat(path); err != nil { |
| 322 | continue |
| 323 | } else if m := s.Mode(); !s.IsDir() && m&0111 != 0 { |
| 324 | return path |
| 325 | } |
| 326 | } |
| 327 | return name |
| 328 | } |
| 329 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 330 | // PrebuiltOS returns the name of the host OS used in prebuilts directories |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 331 | func (c *config) PrebuiltOS() string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 332 | switch runtime.GOOS { |
| 333 | case "linux": |
| 334 | return "linux-x86" |
| 335 | case "darwin": |
| 336 | return "darwin-x86" |
| 337 | default: |
| 338 | panic("Unknown GOOS") |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | // GoRoot returns the path to the root directory of the Go toolchain. |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 343 | func (c *config) GoRoot() string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 344 | return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS()) |
| 345 | } |
| 346 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 347 | func (c *config) CpPreserveSymlinksFlags() string { |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 348 | switch runtime.GOOS { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 349 | case "darwin": |
| 350 | return "-R" |
| 351 | case "linux": |
| 352 | return "-d" |
| 353 | default: |
| 354 | return "" |
| 355 | } |
| 356 | } |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 357 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 358 | func (c *config) Getenv(key string) string { |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 359 | var val string |
| 360 | var exists bool |
Colin Cross | c1e86a3 | 2015-04-15 12:33:28 -0700 | [diff] [blame] | 361 | c.envLock.Lock() |
Colin Cross | c0d58b4 | 2017-02-06 15:40:41 -0800 | [diff] [blame] | 362 | defer c.envLock.Unlock() |
| 363 | if c.envDeps == nil { |
| 364 | c.envDeps = make(map[string]string) |
| 365 | } |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 366 | if val, exists = c.envDeps[key]; !exists { |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 367 | if c.envFrozen { |
| 368 | panic("Cannot access new environment variables after envdeps are frozen") |
| 369 | } |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 370 | val, _ = c.env[key] |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 371 | c.envDeps[key] = val |
| 372 | } |
| 373 | return val |
| 374 | } |
| 375 | |
Colin Cross | 99d7c23 | 2016-11-23 16:52:04 -0800 | [diff] [blame] | 376 | func (c *config) GetenvWithDefault(key string, defaultValue string) string { |
| 377 | ret := c.Getenv(key) |
| 378 | if ret == "" { |
| 379 | return defaultValue |
| 380 | } |
| 381 | return ret |
| 382 | } |
| 383 | |
| 384 | func (c *config) IsEnvTrue(key string) bool { |
| 385 | value := c.Getenv(key) |
| 386 | return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true" |
| 387 | } |
| 388 | |
| 389 | func (c *config) IsEnvFalse(key string) bool { |
| 390 | value := c.Getenv(key) |
| 391 | return value == "0" || value == "n" || value == "no" || value == "off" || value == "false" |
| 392 | } |
| 393 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 394 | func (c *config) EnvDeps() map[string]string { |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 395 | c.envLock.Lock() |
Colin Cross | c0d58b4 | 2017-02-06 15:40:41 -0800 | [diff] [blame] | 396 | defer c.envLock.Unlock() |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 397 | c.envFrozen = true |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 398 | return c.envDeps |
| 399 | } |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 400 | |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 401 | func (c *config) EmbeddedInMake() bool { |
| 402 | return c.inMake |
| 403 | } |
| 404 | |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 405 | // DeviceName returns the name of the current device target |
| 406 | // TODO: take an AndroidModuleContext to select the device name for multi-device builds |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 407 | func (c *config) DeviceName() string { |
Dan Willemsen | 1d31ec3 | 2015-09-22 16:56:09 -0700 | [diff] [blame] | 408 | return *c.ProductVariables.DeviceName |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Dan Willemsen | dd0e2c3 | 2015-10-20 14:29:35 -0700 | [diff] [blame] | 411 | func (c *config) DeviceUsesClang() bool { |
| 412 | if c.ProductVariables.DeviceUsesClang != nil { |
| 413 | return *c.ProductVariables.DeviceUsesClang |
| 414 | } |
Dan Willemsen | 0084d78 | 2016-03-01 14:54:24 -0800 | [diff] [blame] | 415 | return true |
Dan Willemsen | dd0e2c3 | 2015-10-20 14:29:35 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 418 | func (c *config) ResourceOverlays() []SourcePath { |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 419 | return nil |
| 420 | } |
| 421 | |
| 422 | func (c *config) PlatformVersion() string { |
| 423 | return "M" |
| 424 | } |
| 425 | |
Dan Albert | 073379e | 2016-11-10 10:46:36 -0800 | [diff] [blame] | 426 | func (c *config) PlatformSdkVersionInt() int { |
| 427 | return *c.ProductVariables.Platform_sdk_version |
| 428 | } |
| 429 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 430 | func (c *config) PlatformSdkVersion() string { |
Dan Albert | 073379e | 2016-11-10 10:46:36 -0800 | [diff] [blame] | 431 | return strconv.Itoa(c.PlatformSdkVersionInt()) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Dan Albert | f5415d7 | 2017-08-17 16:19:59 -0700 | [diff] [blame] | 434 | func (c *config) MinSupportedSdkVersion() int { |
Dan Albert | d4db4ac | 2017-08-10 12:18:31 -0700 | [diff] [blame] | 435 | return 14 |
Dan Albert | f5415d7 | 2017-08-17 16:19:59 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Colin Cross | 595a406 | 2017-08-31 12:30:37 -0700 | [diff] [blame] | 438 | func (c *config) DefaultAppTargetSdkInt() int { |
| 439 | if Bool(c.ProductVariables.Platform_sdk_final) { |
| 440 | return c.PlatformSdkVersionInt() |
| 441 | } else { |
| 442 | return 10000 |
| 443 | } |
| 444 | } |
| 445 | |
Dan Albert | 31384de | 2017-07-28 12:39:46 -0700 | [diff] [blame] | 446 | // Codenames that are active in the current lunch target. |
| 447 | func (c *config) PlatformVersionActiveCodenames() []string { |
| 448 | return c.ProductVariables.Platform_version_active_codenames |
| 449 | } |
| 450 | |
| 451 | // Codenames that are available in the branch but not included in the current |
| 452 | // lunch target. |
| 453 | func (c *config) PlatformVersionFutureCodenames() []string { |
| 454 | return c.ProductVariables.Platform_version_future_codenames |
| 455 | } |
| 456 | |
| 457 | // All possible codenames in the current branch. NB: Not named AllCodenames |
| 458 | // because "all" has historically meant "active" in make, and still does in |
| 459 | // build.prop. |
| 460 | func (c *config) PlatformVersionCombinedCodenames() []string { |
| 461 | combined := []string{} |
| 462 | combined = append(combined, c.PlatformVersionActiveCodenames()...) |
| 463 | combined = append(combined, c.PlatformVersionFutureCodenames()...) |
| 464 | return combined |
Dan Albert | 30c9d6e | 2017-03-28 14:54:55 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 467 | func (c *config) BuildNumber() string { |
| 468 | return "000000" |
| 469 | } |
| 470 | |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame^] | 471 | func (c *config) ProductAAPTConfig() []string { |
| 472 | return *c.ProductVariables.AAPTConfig |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame^] | 475 | func (c *config) ProductAAPTPreferredConfig() string { |
| 476 | return *c.ProductVariables.AAPTPreferredConfig |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame^] | 479 | func (c *config) ProductAAPTCharacteristics() string { |
| 480 | return *c.ProductVariables.AAPTCharacteristics |
| 481 | } |
| 482 | |
| 483 | func (c *config) ProductAAPTPrebuiltDPI() []string { |
| 484 | return *c.ProductVariables.AAPTPrebuiltDPI |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 487 | func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath { |
| 488 | return PathForSource(ctx, "build/target/product/security") |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 491 | func (c *config) DefaultAppCertificate(ctx PathContext) SourcePath { |
| 492 | return c.DefaultAppCertificateDir(ctx).Join(ctx, "testkey") |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 493 | } |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 494 | |
| 495 | func (c *config) AllowMissingDependencies() bool { |
Dan Willemsen | b503816 | 2016-03-16 12:35:33 -0700 | [diff] [blame] | 496 | return Bool(c.ProductVariables.Allow_missing_dependencies) |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 497 | } |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 498 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 499 | func (c *config) UnbundledBuild() bool { |
| 500 | return Bool(c.ProductVariables.Unbundled_build) |
| 501 | } |
| 502 | |
Colin Cross | 0d3f8c0 | 2017-10-24 10:51:45 -0700 | [diff] [blame] | 503 | func (c *config) IsPdkBuild() bool { |
| 504 | return Bool(c.ProductVariables.Pdk) |
| 505 | } |
| 506 | |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 507 | func (c *config) DevicePrefer32BitExecutables() bool { |
| 508 | return Bool(c.ProductVariables.DevicePrefer32BitExecutables) |
| 509 | } |
| 510 | |
Dan Willemsen | 7f730fd | 2016-01-14 11:22:23 -0800 | [diff] [blame] | 511 | func (c *config) SkipDeviceInstall() bool { |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 512 | return c.EmbeddedInMake() |
| 513 | } |
| 514 | |
| 515 | func (c *config) SkipMegaDeviceInstall(path string) bool { |
| 516 | return Bool(c.Mega_device) && |
| 517 | strings.HasPrefix(path, filepath.Join(c.buildDir, "target", "product")) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 518 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 519 | |
| 520 | func (c *config) SanitizeHost() []string { |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 521 | return append([]string(nil), c.ProductVariables.SanitizeHost...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | func (c *config) SanitizeDevice() []string { |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 525 | return append([]string(nil), c.ProductVariables.SanitizeDevice...) |
| 526 | } |
| 527 | |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 528 | func (c *config) SanitizeDeviceDiag() []string { |
| 529 | return append([]string(nil), c.ProductVariables.SanitizeDeviceDiag...) |
| 530 | } |
| 531 | |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 532 | func (c *config) SanitizeDeviceArch() []string { |
| 533 | return append([]string(nil), c.ProductVariables.SanitizeDeviceArch...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 534 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 535 | |
Vishwath Mohan | 1b017a7 | 2017-01-19 13:54:55 -0800 | [diff] [blame] | 536 | func (c *config) EnableCFI() bool { |
Vishwath Mohan | c32c3eb | 2017-01-24 14:20:54 -0800 | [diff] [blame] | 537 | if c.ProductVariables.EnableCFI == nil { |
| 538 | return true |
| 539 | } else { |
| 540 | return *c.ProductVariables.EnableCFI |
| 541 | } |
Vishwath Mohan | 1b017a7 | 2017-01-19 13:54:55 -0800 | [diff] [blame] | 542 | } |
| 543 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 544 | func (c *config) Android64() bool { |
| 545 | for _, t := range c.Targets[Device] { |
| 546 | if t.Arch.ArchType.Multilib == "lib64" { |
| 547 | return true |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | return false |
| 552 | } |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 553 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 554 | func (c *config) UseGoma() bool { |
| 555 | return Bool(c.ProductVariables.UseGoma) |
| 556 | } |
| 557 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 558 | // Returns true if OpenJDK9 prebuilts are being used |
| 559 | func (c *config) UseOpenJDK9() bool { |
| 560 | return c.useOpenJDK9 |
| 561 | } |
| 562 | |
| 563 | // Returns true if -source 1.9 -target 1.9 is being passed to javac |
| 564 | func (c *config) TargetOpenJDK9() bool { |
| 565 | return c.targetOpenJDK9 |
| 566 | } |
| 567 | |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 568 | func (c *config) ClangTidy() bool { |
| 569 | return Bool(c.ProductVariables.ClangTidy) |
| 570 | } |
| 571 | |
| 572 | func (c *config) TidyChecks() string { |
| 573 | if c.ProductVariables.TidyChecks == nil { |
| 574 | return "" |
| 575 | } |
| 576 | return *c.ProductVariables.TidyChecks |
| 577 | } |
| 578 | |
Colin Cross | 0f4e0d6 | 2016-07-27 10:56:55 -0700 | [diff] [blame] | 579 | func (c *config) LibartImgHostBaseAddress() string { |
| 580 | return "0x60000000" |
| 581 | } |
| 582 | |
| 583 | func (c *config) LibartImgDeviceBaseAddress() string { |
Colin Cross | 20e1365 | 2017-06-22 15:34:51 -0700 | [diff] [blame] | 584 | archType := Common |
| 585 | if len(c.Targets[Device]) > 0 { |
| 586 | archType = c.Targets[Device][0].Arch.ArchType |
| 587 | } |
| 588 | switch archType { |
Colin Cross | 0f4e0d6 | 2016-07-27 10:56:55 -0700 | [diff] [blame] | 589 | default: |
| 590 | return "0x70000000" |
| 591 | case Mips, Mips64: |
Chris Larsen | ae7f3e2 | 2017-05-30 16:36:58 -0700 | [diff] [blame] | 592 | return "0x5C000000" |
Colin Cross | 0f4e0d6 | 2016-07-27 10:56:55 -0700 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | |
Hiroshi Yamauchi | e2a1063 | 2016-12-19 13:44:41 -0800 | [diff] [blame] | 596 | func (c *config) ArtUseReadBarrier() bool { |
| 597 | return Bool(c.ProductVariables.ArtUseReadBarrier) |
| 598 | } |
| 599 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 600 | func (c *deviceConfig) Arches() []Arch { |
| 601 | var arches []Arch |
| 602 | for _, target := range c.config.Targets[Device] { |
| 603 | arches = append(arches, target.Arch) |
| 604 | } |
| 605 | return arches |
| 606 | } |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 607 | |
Dan Willemsen | 4353bc4 | 2016-12-05 17:16:02 -0800 | [diff] [blame] | 608 | func (c *deviceConfig) VendorPath() string { |
| 609 | if c.config.ProductVariables.VendorPath != nil { |
| 610 | return *c.config.ProductVariables.VendorPath |
| 611 | } |
| 612 | return "vendor" |
| 613 | } |
| 614 | |
Dan Willemsen | 11b2614 | 2017-03-19 18:30:37 -0700 | [diff] [blame] | 615 | func (c *deviceConfig) CompileVndk() bool { |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 616 | if c.config.ProductVariables.DeviceVndkVersion == nil { |
Dan Willemsen | 11b2614 | 2017-03-19 18:30:37 -0700 | [diff] [blame] | 617 | return false |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 618 | } |
Dan Willemsen | 11b2614 | 2017-03-19 18:30:37 -0700 | [diff] [blame] | 619 | return *c.config.ProductVariables.DeviceVndkVersion == "current" |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 620 | } |
Jack He | 8cc7143 | 2016-12-08 15:45:07 -0800 | [diff] [blame] | 621 | |
| 622 | func (c *deviceConfig) BtConfigIncludeDir() string { |
| 623 | return String(c.config.ProductVariables.BtConfigIncludeDir) |
| 624 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 625 | |
Jiyong Park | d773eb3 | 2017-07-03 13:18:12 +0900 | [diff] [blame] | 626 | func (c *deviceConfig) DeviceKernelHeaderDirs() []string { |
| 627 | return c.config.ProductVariables.DeviceKernelHeaders |
| 628 | } |
| 629 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 630 | func (c *deviceConfig) NativeCoverageEnabled() bool { |
| 631 | return Bool(c.config.ProductVariables.NativeCoverage) |
| 632 | } |
| 633 | |
| 634 | func (c *deviceConfig) CoverageEnabledForPath(path string) bool { |
Ryan Campbell | 469a18a | 2017-02-27 09:01:54 -0800 | [diff] [blame] | 635 | coverage := false |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 636 | if c.config.ProductVariables.CoveragePaths != nil { |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 637 | if prefixInList(path, *c.config.ProductVariables.CoveragePaths) { |
| 638 | coverage = true |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 639 | } |
| 640 | } |
Ryan Campbell | 469a18a | 2017-02-27 09:01:54 -0800 | [diff] [blame] | 641 | if coverage && c.config.ProductVariables.CoverageExcludePaths != nil { |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 642 | if prefixInList(path, *c.config.ProductVariables.CoverageExcludePaths) { |
| 643 | coverage = false |
Ryan Campbell | 469a18a | 2017-02-27 09:01:54 -0800 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | return coverage |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 647 | } |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 648 | |
| 649 | func (c *config) IntegerOverflowDisabledForPath(path string) bool { |
| 650 | if c.ProductVariables.IntegerOverflowExcludePaths == nil { |
| 651 | return false |
| 652 | } |
| 653 | return prefixInList(path, *c.ProductVariables.IntegerOverflowExcludePaths) |
| 654 | } |