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