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{ |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 178 | DeviceName: stringPtr("test_device"), |
| 179 | Platform_sdk_version: intPtr(26), |
| 180 | AAPTConfig: &[]string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"}, |
| 181 | AAPTPreferredConfig: stringPtr("xhdpi"), |
| 182 | AAPTCharacteristics: stringPtr("nosdcard"), |
| 183 | AAPTPrebuiltDPI: &[]string{"xhdpi", "xxhdpi"}, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 184 | }, |
| 185 | |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 186 | buildDir: buildDir, |
| 187 | captureBuild: true, |
| 188 | env: env, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 189 | } |
| 190 | config.deviceConfig = &deviceConfig{ |
| 191 | config: config, |
| 192 | } |
| 193 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 194 | if err := config.fromEnv(); err != nil { |
| 195 | panic(err) |
| 196 | } |
| 197 | |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 198 | return Config{config} |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 201 | // 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] | 202 | func TestArchConfig(buildDir string, env map[string]string) Config { |
| 203 | testConfig := TestConfig(buildDir, env) |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 204 | config := testConfig.config |
| 205 | |
| 206 | config.Targets = map[OsClass][]Target{ |
| 207 | Device: []Target{ |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 208 | {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Native: true}}, |
| 209 | {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Native: true}}, |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 210 | }, |
| 211 | Host: []Target{ |
| 212 | {BuildOs, Arch{ArchType: X86_64}}, |
| 213 | {BuildOs, Arch{ArchType: X86}}, |
| 214 | }, |
| 215 | } |
| 216 | |
| 217 | return testConfig |
| 218 | } |
| 219 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 220 | // New creates a new Config object. The srcDir argument specifies the path to |
| 221 | // the root source directory. It also loads the config file, if found. |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 222 | func NewConfig(srcDir, buildDir string) (Config, error) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 223 | // Make a config with default options |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 224 | config := &config{ |
| 225 | ConfigFileName: filepath.Join(buildDir, configFileName), |
| 226 | ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName), |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 227 | |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 228 | env: originalEnv, |
| 229 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 230 | srcDir: srcDir, |
| 231 | buildDir: buildDir, |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 232 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 233 | |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 234 | config.deviceConfig = &deviceConfig{ |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 235 | config: config, |
| 236 | } |
| 237 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 238 | // Sanity check the build and source directories. This won't catch strange |
| 239 | // configurations with symlinks, but at least checks the obvious cases. |
| 240 | absBuildDir, err := filepath.Abs(buildDir) |
| 241 | if err != nil { |
| 242 | return Config{}, err |
| 243 | } |
| 244 | |
| 245 | absSrcDir, err := filepath.Abs(srcDir) |
| 246 | if err != nil { |
| 247 | return Config{}, err |
| 248 | } |
| 249 | |
| 250 | if strings.HasPrefix(absSrcDir, absBuildDir) { |
| 251 | return Config{}, fmt.Errorf("Build dir must not contain source directory") |
| 252 | } |
| 253 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 254 | // Load any configurable options from the configuration file |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 255 | err = loadConfig(config) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 256 | if err != nil { |
Colin Cross | c3c0a49 | 2015-04-10 15:43:55 -0700 | [diff] [blame] | 257 | return Config{}, err |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 260 | inMakeFile := filepath.Join(buildDir, ".soong.in_make") |
| 261 | if _, err := os.Stat(inMakeFile); err == nil { |
| 262 | config.inMake = true |
| 263 | } |
| 264 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 265 | targets, err := decodeTargetProductVariables(config) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 266 | if err != nil { |
| 267 | return Config{}, err |
| 268 | } |
| 269 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 270 | var archConfig []archConfig |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 271 | if Bool(config.Mega_device) { |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 272 | archConfig = getMegaDeviceConfig() |
| 273 | } else if Bool(config.Ndk_abis) { |
| 274 | archConfig = getNdkAbisConfig() |
| 275 | } |
| 276 | |
| 277 | if archConfig != nil { |
| 278 | deviceTargets, err := decodeArchSettings(archConfig) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 279 | if err != nil { |
| 280 | return Config{}, err |
| 281 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 282 | targets[Device] = deviceTargets |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 283 | } |
| 284 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 285 | config.Targets = targets |
| 286 | config.BuildOsVariant = targets[Host][0].String() |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 287 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 288 | if err := config.fromEnv(); err != nil { |
| 289 | return Config{}, err |
| 290 | } |
| 291 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 292 | return Config{config}, nil |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 295 | func (c *config) fromEnv() error { |
| 296 | switch c.Getenv("EXPERIMENTAL_USE_OPENJDK9") { |
| 297 | case "": |
| 298 | // Use OpenJDK8 |
Tobias Thierer | a7cdd15 | 2017-11-15 21:16:25 +0000 | [diff] [blame] | 299 | case "false": |
| 300 | // Use OpenJDK8 |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 301 | case "1.8": |
| 302 | // Use OpenJDK9, but target 1.8 |
| 303 | c.useOpenJDK9 = true |
| 304 | case "true": |
| 305 | // Use OpenJDK9 and target 1.9 |
| 306 | c.useOpenJDK9 = true |
| 307 | c.targetOpenJDK9 = true |
| 308 | default: |
| 309 | return fmt.Errorf(`Invalid value for EXPERIMENTAL_USE_OPENJDK9, should be "", "1.8", or "true"`) |
| 310 | } |
| 311 | |
| 312 | return nil |
| 313 | } |
| 314 | |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 315 | func (c *config) RemoveAbandonedFiles() bool { |
| 316 | return false |
| 317 | } |
| 318 | |
Dan Willemsen | c2aa4a9 | 2016-05-26 15:13:03 -0700 | [diff] [blame] | 319 | func (c *config) BlueprintToolLocation() string { |
| 320 | return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin") |
| 321 | } |
| 322 | |
Dan Willemsen | 6606872 | 2017-05-08 21:15:59 +0000 | [diff] [blame] | 323 | // HostSystemTool looks for non-hermetic tools from the system we're running on. |
| 324 | // Generally shouldn't be used, but useful to find the XCode SDK, etc. |
| 325 | func (c *config) HostSystemTool(name string) string { |
| 326 | for _, dir := range filepath.SplitList(c.Getenv("PATH")) { |
| 327 | path := filepath.Join(dir, name) |
| 328 | if s, err := os.Stat(path); err != nil { |
| 329 | continue |
| 330 | } else if m := s.Mode(); !s.IsDir() && m&0111 != 0 { |
| 331 | return path |
| 332 | } |
| 333 | } |
| 334 | return name |
| 335 | } |
| 336 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 337 | // PrebuiltOS returns the name of the host OS used in prebuilts directories |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 338 | func (c *config) PrebuiltOS() string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 339 | switch runtime.GOOS { |
| 340 | case "linux": |
| 341 | return "linux-x86" |
| 342 | case "darwin": |
| 343 | return "darwin-x86" |
| 344 | default: |
| 345 | panic("Unknown GOOS") |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | // GoRoot returns the path to the root directory of the Go toolchain. |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 350 | func (c *config) GoRoot() string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 351 | return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS()) |
| 352 | } |
| 353 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 354 | func (c *config) CpPreserveSymlinksFlags() string { |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 355 | switch runtime.GOOS { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 356 | case "darwin": |
| 357 | return "-R" |
| 358 | case "linux": |
| 359 | return "-d" |
| 360 | default: |
| 361 | return "" |
| 362 | } |
| 363 | } |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 364 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 365 | func (c *config) Getenv(key string) string { |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 366 | var val string |
| 367 | var exists bool |
Colin Cross | c1e86a3 | 2015-04-15 12:33:28 -0700 | [diff] [blame] | 368 | c.envLock.Lock() |
Colin Cross | c0d58b4 | 2017-02-06 15:40:41 -0800 | [diff] [blame] | 369 | defer c.envLock.Unlock() |
| 370 | if c.envDeps == nil { |
| 371 | c.envDeps = make(map[string]string) |
| 372 | } |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 373 | if val, exists = c.envDeps[key]; !exists { |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 374 | if c.envFrozen { |
| 375 | panic("Cannot access new environment variables after envdeps are frozen") |
| 376 | } |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 377 | val, _ = c.env[key] |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 378 | c.envDeps[key] = val |
| 379 | } |
| 380 | return val |
| 381 | } |
| 382 | |
Colin Cross | 99d7c23 | 2016-11-23 16:52:04 -0800 | [diff] [blame] | 383 | func (c *config) GetenvWithDefault(key string, defaultValue string) string { |
| 384 | ret := c.Getenv(key) |
| 385 | if ret == "" { |
| 386 | return defaultValue |
| 387 | } |
| 388 | return ret |
| 389 | } |
| 390 | |
| 391 | func (c *config) IsEnvTrue(key string) bool { |
| 392 | value := c.Getenv(key) |
| 393 | return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true" |
| 394 | } |
| 395 | |
| 396 | func (c *config) IsEnvFalse(key string) bool { |
| 397 | value := c.Getenv(key) |
| 398 | return value == "0" || value == "n" || value == "no" || value == "off" || value == "false" |
| 399 | } |
| 400 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 401 | func (c *config) EnvDeps() map[string]string { |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 402 | c.envLock.Lock() |
Colin Cross | c0d58b4 | 2017-02-06 15:40:41 -0800 | [diff] [blame] | 403 | defer c.envLock.Unlock() |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 404 | c.envFrozen = true |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 405 | return c.envDeps |
| 406 | } |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 407 | |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 408 | func (c *config) EmbeddedInMake() bool { |
| 409 | return c.inMake |
| 410 | } |
| 411 | |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 412 | // DeviceName returns the name of the current device target |
| 413 | // 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] | 414 | func (c *config) DeviceName() string { |
Dan Willemsen | 1d31ec3 | 2015-09-22 16:56:09 -0700 | [diff] [blame] | 415 | return *c.ProductVariables.DeviceName |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Dan Willemsen | dd0e2c3 | 2015-10-20 14:29:35 -0700 | [diff] [blame] | 418 | func (c *config) DeviceUsesClang() bool { |
| 419 | if c.ProductVariables.DeviceUsesClang != nil { |
| 420 | return *c.ProductVariables.DeviceUsesClang |
| 421 | } |
Dan Willemsen | 0084d78 | 2016-03-01 14:54:24 -0800 | [diff] [blame] | 422 | return true |
Dan Willemsen | dd0e2c3 | 2015-10-20 14:29:35 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 425 | func (c *config) ResourceOverlays() []string { |
| 426 | if c.ProductVariables.ResourceOverlays == nil { |
| 427 | return nil |
| 428 | } |
| 429 | return *c.ProductVariables.ResourceOverlays |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Dan Albert | 073379e | 2016-11-10 10:46:36 -0800 | [diff] [blame] | 432 | func (c *config) PlatformSdkVersionInt() int { |
| 433 | return *c.ProductVariables.Platform_sdk_version |
| 434 | } |
| 435 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 436 | func (c *config) PlatformSdkVersion() string { |
Dan Albert | 073379e | 2016-11-10 10:46:36 -0800 | [diff] [blame] | 437 | return strconv.Itoa(c.PlatformSdkVersionInt()) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Dan Albert | f5415d7 | 2017-08-17 16:19:59 -0700 | [diff] [blame] | 440 | func (c *config) MinSupportedSdkVersion() int { |
Dan Albert | d4db4ac | 2017-08-10 12:18:31 -0700 | [diff] [blame] | 441 | return 14 |
Dan Albert | f5415d7 | 2017-08-17 16:19:59 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Colin Cross | 595a406 | 2017-08-31 12:30:37 -0700 | [diff] [blame] | 444 | func (c *config) DefaultAppTargetSdkInt() int { |
| 445 | if Bool(c.ProductVariables.Platform_sdk_final) { |
| 446 | return c.PlatformSdkVersionInt() |
| 447 | } else { |
| 448 | return 10000 |
| 449 | } |
| 450 | } |
| 451 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 452 | func (c *config) AppsDefaultVersionName() string { |
| 453 | return String(c.ProductVariables.AppsDefaultVersionName) |
| 454 | } |
| 455 | |
Dan Albert | 31384de | 2017-07-28 12:39:46 -0700 | [diff] [blame] | 456 | // Codenames that are active in the current lunch target. |
| 457 | func (c *config) PlatformVersionActiveCodenames() []string { |
| 458 | return c.ProductVariables.Platform_version_active_codenames |
| 459 | } |
| 460 | |
| 461 | // Codenames that are available in the branch but not included in the current |
| 462 | // lunch target. |
| 463 | func (c *config) PlatformVersionFutureCodenames() []string { |
| 464 | return c.ProductVariables.Platform_version_future_codenames |
| 465 | } |
| 466 | |
| 467 | // All possible codenames in the current branch. NB: Not named AllCodenames |
| 468 | // because "all" has historically meant "active" in make, and still does in |
| 469 | // build.prop. |
| 470 | func (c *config) PlatformVersionCombinedCodenames() []string { |
| 471 | combined := []string{} |
| 472 | combined = append(combined, c.PlatformVersionActiveCodenames()...) |
| 473 | combined = append(combined, c.PlatformVersionFutureCodenames()...) |
| 474 | return combined |
Dan Albert | 30c9d6e | 2017-03-28 14:54:55 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 477 | func (c *config) ProductAAPTConfig() []string { |
| 478 | return *c.ProductVariables.AAPTConfig |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 481 | func (c *config) ProductAAPTPreferredConfig() string { |
| 482 | return *c.ProductVariables.AAPTPreferredConfig |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 485 | func (c *config) ProductAAPTCharacteristics() string { |
| 486 | return *c.ProductVariables.AAPTCharacteristics |
| 487 | } |
| 488 | |
| 489 | func (c *config) ProductAAPTPrebuiltDPI() []string { |
| 490 | return *c.ProductVariables.AAPTPrebuiltDPI |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 493 | func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath { |
Colin Cross | 61ae0b7 | 2017-12-01 17:16:02 -0800 | [diff] [blame^] | 494 | defaultCert := String(c.ProductVariables.DefaultAppCertificate) |
| 495 | if defaultCert != "" { |
| 496 | return PathForSource(ctx, filepath.Dir(defaultCert)) |
| 497 | } else { |
| 498 | return PathForSource(ctx, "build/target/product/security") |
| 499 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 502 | func (c *config) DefaultAppCertificate(ctx PathContext) SourcePath { |
Colin Cross | 61ae0b7 | 2017-12-01 17:16:02 -0800 | [diff] [blame^] | 503 | defaultCert := String(c.ProductVariables.DefaultAppCertificate) |
| 504 | if defaultCert != "" { |
| 505 | return PathForSource(ctx, defaultCert) |
| 506 | } else { |
| 507 | return c.DefaultAppCertificateDir(ctx).Join(ctx, "testkey") |
| 508 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 509 | } |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 510 | |
| 511 | func (c *config) AllowMissingDependencies() bool { |
Dan Willemsen | b503816 | 2016-03-16 12:35:33 -0700 | [diff] [blame] | 512 | return Bool(c.ProductVariables.Allow_missing_dependencies) |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 513 | } |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 514 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 515 | func (c *config) UnbundledBuild() bool { |
| 516 | return Bool(c.ProductVariables.Unbundled_build) |
| 517 | } |
| 518 | |
Colin Cross | 0d3f8c0 | 2017-10-24 10:51:45 -0700 | [diff] [blame] | 519 | func (c *config) IsPdkBuild() bool { |
| 520 | return Bool(c.ProductVariables.Pdk) |
| 521 | } |
| 522 | |
Colin Cross | 126a25c | 2017-10-31 13:55:34 -0700 | [diff] [blame] | 523 | func (c *config) MinimizeJavaDebugInfo() bool { |
| 524 | return Bool(c.ProductVariables.MinimizeJavaDebugInfo) && !Bool(c.ProductVariables.Eng) |
| 525 | } |
| 526 | |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 527 | func (c *config) DevicePrefer32BitExecutables() bool { |
| 528 | return Bool(c.ProductVariables.DevicePrefer32BitExecutables) |
| 529 | } |
| 530 | |
Dan Willemsen | 7f730fd | 2016-01-14 11:22:23 -0800 | [diff] [blame] | 531 | func (c *config) SkipDeviceInstall() bool { |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 532 | return c.EmbeddedInMake() |
| 533 | } |
| 534 | |
| 535 | func (c *config) SkipMegaDeviceInstall(path string) bool { |
| 536 | return Bool(c.Mega_device) && |
| 537 | strings.HasPrefix(path, filepath.Join(c.buildDir, "target", "product")) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 538 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 539 | |
| 540 | func (c *config) SanitizeHost() []string { |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 541 | return append([]string(nil), c.ProductVariables.SanitizeHost...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | func (c *config) SanitizeDevice() []string { |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 545 | return append([]string(nil), c.ProductVariables.SanitizeDevice...) |
| 546 | } |
| 547 | |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 548 | func (c *config) SanitizeDeviceDiag() []string { |
| 549 | return append([]string(nil), c.ProductVariables.SanitizeDeviceDiag...) |
| 550 | } |
| 551 | |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 552 | func (c *config) SanitizeDeviceArch() []string { |
| 553 | return append([]string(nil), c.ProductVariables.SanitizeDeviceArch...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 554 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 555 | |
Vishwath Mohan | 1b017a7 | 2017-01-19 13:54:55 -0800 | [diff] [blame] | 556 | func (c *config) EnableCFI() bool { |
Vishwath Mohan | c32c3eb | 2017-01-24 14:20:54 -0800 | [diff] [blame] | 557 | if c.ProductVariables.EnableCFI == nil { |
| 558 | return true |
| 559 | } else { |
| 560 | return *c.ProductVariables.EnableCFI |
| 561 | } |
Vishwath Mohan | 1b017a7 | 2017-01-19 13:54:55 -0800 | [diff] [blame] | 562 | } |
| 563 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 564 | func (c *config) Android64() bool { |
| 565 | for _, t := range c.Targets[Device] { |
| 566 | if t.Arch.ArchType.Multilib == "lib64" { |
| 567 | return true |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | return false |
| 572 | } |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 573 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 574 | func (c *config) UseGoma() bool { |
| 575 | return Bool(c.ProductVariables.UseGoma) |
| 576 | } |
| 577 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 578 | // Returns true if OpenJDK9 prebuilts are being used |
| 579 | func (c *config) UseOpenJDK9() bool { |
| 580 | return c.useOpenJDK9 |
| 581 | } |
| 582 | |
| 583 | // Returns true if -source 1.9 -target 1.9 is being passed to javac |
| 584 | func (c *config) TargetOpenJDK9() bool { |
| 585 | return c.targetOpenJDK9 |
| 586 | } |
| 587 | |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 588 | func (c *config) ClangTidy() bool { |
| 589 | return Bool(c.ProductVariables.ClangTidy) |
| 590 | } |
| 591 | |
| 592 | func (c *config) TidyChecks() string { |
| 593 | if c.ProductVariables.TidyChecks == nil { |
| 594 | return "" |
| 595 | } |
| 596 | return *c.ProductVariables.TidyChecks |
| 597 | } |
| 598 | |
Colin Cross | 0f4e0d6 | 2016-07-27 10:56:55 -0700 | [diff] [blame] | 599 | func (c *config) LibartImgHostBaseAddress() string { |
| 600 | return "0x60000000" |
| 601 | } |
| 602 | |
| 603 | func (c *config) LibartImgDeviceBaseAddress() string { |
Colin Cross | 20e1365 | 2017-06-22 15:34:51 -0700 | [diff] [blame] | 604 | archType := Common |
| 605 | if len(c.Targets[Device]) > 0 { |
| 606 | archType = c.Targets[Device][0].Arch.ArchType |
| 607 | } |
| 608 | switch archType { |
Colin Cross | 0f4e0d6 | 2016-07-27 10:56:55 -0700 | [diff] [blame] | 609 | default: |
| 610 | return "0x70000000" |
| 611 | case Mips, Mips64: |
Chris Larsen | ae7f3e2 | 2017-05-30 16:36:58 -0700 | [diff] [blame] | 612 | return "0x5C000000" |
Colin Cross | 0f4e0d6 | 2016-07-27 10:56:55 -0700 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | |
Hiroshi Yamauchi | e2a1063 | 2016-12-19 13:44:41 -0800 | [diff] [blame] | 616 | func (c *config) ArtUseReadBarrier() bool { |
| 617 | return Bool(c.ProductVariables.ArtUseReadBarrier) |
| 618 | } |
| 619 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 620 | func (c *deviceConfig) Arches() []Arch { |
| 621 | var arches []Arch |
| 622 | for _, target := range c.config.Targets[Device] { |
| 623 | arches = append(arches, target.Arch) |
| 624 | } |
| 625 | return arches |
| 626 | } |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 627 | |
Dan Willemsen | 4353bc4 | 2016-12-05 17:16:02 -0800 | [diff] [blame] | 628 | func (c *deviceConfig) VendorPath() string { |
| 629 | if c.config.ProductVariables.VendorPath != nil { |
| 630 | return *c.config.ProductVariables.VendorPath |
| 631 | } |
| 632 | return "vendor" |
| 633 | } |
| 634 | |
Dan Willemsen | 11b2614 | 2017-03-19 18:30:37 -0700 | [diff] [blame] | 635 | func (c *deviceConfig) CompileVndk() bool { |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 636 | if c.config.ProductVariables.DeviceVndkVersion == nil { |
Dan Willemsen | 11b2614 | 2017-03-19 18:30:37 -0700 | [diff] [blame] | 637 | return false |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 638 | } |
Dan Willemsen | 11b2614 | 2017-03-19 18:30:37 -0700 | [diff] [blame] | 639 | return *c.config.ProductVariables.DeviceVndkVersion == "current" |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 640 | } |
Jack He | 8cc7143 | 2016-12-08 15:45:07 -0800 | [diff] [blame] | 641 | |
| 642 | func (c *deviceConfig) BtConfigIncludeDir() string { |
| 643 | return String(c.config.ProductVariables.BtConfigIncludeDir) |
| 644 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 645 | |
Jiyong Park | d773eb3 | 2017-07-03 13:18:12 +0900 | [diff] [blame] | 646 | func (c *deviceConfig) DeviceKernelHeaderDirs() []string { |
| 647 | return c.config.ProductVariables.DeviceKernelHeaders |
| 648 | } |
| 649 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 650 | func (c *deviceConfig) NativeCoverageEnabled() bool { |
| 651 | return Bool(c.config.ProductVariables.NativeCoverage) |
| 652 | } |
| 653 | |
| 654 | func (c *deviceConfig) CoverageEnabledForPath(path string) bool { |
Ryan Campbell | 469a18a | 2017-02-27 09:01:54 -0800 | [diff] [blame] | 655 | coverage := false |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 656 | if c.config.ProductVariables.CoveragePaths != nil { |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 657 | if prefixInList(path, *c.config.ProductVariables.CoveragePaths) { |
| 658 | coverage = true |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 659 | } |
| 660 | } |
Ryan Campbell | 469a18a | 2017-02-27 09:01:54 -0800 | [diff] [blame] | 661 | if coverage && c.config.ProductVariables.CoverageExcludePaths != nil { |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 662 | if prefixInList(path, *c.config.ProductVariables.CoverageExcludePaths) { |
| 663 | coverage = false |
Ryan Campbell | 469a18a | 2017-02-27 09:01:54 -0800 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | return coverage |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 667 | } |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 668 | |
| 669 | func (c *config) IntegerOverflowDisabledForPath(path string) bool { |
| 670 | if c.ProductVariables.IntegerOverflowExcludePaths == nil { |
| 671 | return false |
| 672 | } |
| 673 | return prefixInList(path, *c.ProductVariables.IntegerOverflowExcludePaths) |
| 674 | } |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 675 | |
| 676 | func (c *config) CFIDisabledForPath(path string) bool { |
| 677 | if c.ProductVariables.CFIExcludePaths == nil { |
| 678 | return false |
| 679 | } |
| 680 | return prefixInList(path, *c.ProductVariables.CFIExcludePaths) |
| 681 | } |
| 682 | |
| 683 | func (c *config) CFIEnabledForPath(path string) bool { |
| 684 | if c.ProductVariables.CFIIncludePaths == nil { |
| 685 | return false |
| 686 | } |
| 687 | return prefixInList(path, *c.ProductVariables.CFIIncludePaths) |
| 688 | } |