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 |
| 32 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 33 | // The configuration file name |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 34 | const configFileName = "soong.config" |
| 35 | const productVariablesFileName = "soong.variables" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 36 | |
| 37 | // A FileConfigurableOptions contains options which can be configured by the |
| 38 | // config file. These will be included in the config struct. |
| 39 | type FileConfigurableOptions struct { |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 40 | Mega_device *bool `json:",omitempty"` |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 41 | Ndk_abis *bool `json:",omitempty"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 42 | } |
| 43 | |
Colin Cross | 2738597 | 2015-09-18 10:57:10 -0700 | [diff] [blame] | 44 | func (f *FileConfigurableOptions) SetDefaultConfig() { |
| 45 | *f = FileConfigurableOptions{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 46 | } |
| 47 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 48 | // A Config object represents the entire build configuration for Android. |
Colin Cross | c3c0a49 | 2015-04-10 15:43:55 -0700 | [diff] [blame] | 49 | type Config struct { |
| 50 | *config |
| 51 | } |
| 52 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 53 | // A DeviceConfig object represents the configuration for a particular device being built. For |
| 54 | // now there will only be one of these, but in the future there may be multiple devices being |
| 55 | // built |
| 56 | type DeviceConfig struct { |
| 57 | *deviceConfig |
| 58 | } |
| 59 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 60 | type config struct { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 61 | FileConfigurableOptions |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 62 | ProductVariables productVariables |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 63 | |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 64 | ConfigFileName string |
| 65 | ProductVariablesFileName string |
| 66 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 67 | Targets map[OsClass][]Target |
| 68 | BuildOsVariant string |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 69 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 70 | deviceConfig *deviceConfig |
| 71 | |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 72 | srcDir string // the path of the root source directory |
| 73 | buildDir string // the path of the build output directory |
Colin Cross | c1e86a3 | 2015-04-15 12:33:28 -0700 | [diff] [blame] | 74 | |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 75 | envLock sync.Mutex |
| 76 | envDeps map[string]string |
| 77 | envFrozen bool |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 78 | |
| 79 | inMake bool |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 80 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 81 | OncePer |
| 82 | } |
| 83 | |
| 84 | type deviceConfig struct { |
| 85 | config *config |
| 86 | targets []Arch |
| 87 | OncePer |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 90 | type jsonConfigurable interface { |
Colin Cross | 2738597 | 2015-09-18 10:57:10 -0700 | [diff] [blame] | 91 | SetDefaultConfig() |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 92 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 93 | |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 94 | func loadConfig(config *config) error { |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 95 | err := loadFromConfigFile(&config.FileConfigurableOptions, config.ConfigFileName) |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 96 | if err != nil { |
| 97 | return err |
| 98 | } |
| 99 | |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 100 | return loadFromConfigFile(&config.ProductVariables, config.ProductVariablesFileName) |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // loads configuration options from a JSON file in the cwd. |
| 104 | func loadFromConfigFile(configurable jsonConfigurable, filename string) error { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 105 | // Try to open the file |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 106 | configFileReader, err := os.Open(filename) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 107 | defer configFileReader.Close() |
| 108 | if os.IsNotExist(err) { |
| 109 | // Need to create a file, so that blueprint & ninja don't get in |
| 110 | // a dependency tracking loop. |
| 111 | // Make a file-configurable-options with defaults, write it out using |
| 112 | // a json writer. |
Colin Cross | 2738597 | 2015-09-18 10:57:10 -0700 | [diff] [blame] | 113 | configurable.SetDefaultConfig() |
| 114 | err = saveToConfigFile(configurable, filename) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 115 | if err != nil { |
| 116 | return err |
| 117 | } |
| 118 | } else { |
| 119 | // Make a decoder for it |
| 120 | jsonDecoder := json.NewDecoder(configFileReader) |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 121 | err = jsonDecoder.Decode(configurable) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 122 | if err != nil { |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 123 | 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] | 124 | } |
| 125 | } |
| 126 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 127 | // No error |
| 128 | return nil |
| 129 | } |
| 130 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 131 | // atomically writes the config file in case two copies of soong_build are running simultaneously |
| 132 | // (for example, docs generation and ninja manifest generation) |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 133 | func saveToConfigFile(config jsonConfigurable, filename string) error { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 134 | data, err := json.MarshalIndent(&config, "", " ") |
| 135 | if err != nil { |
| 136 | return fmt.Errorf("cannot marshal config data: %s", err.Error()) |
| 137 | } |
| 138 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 139 | f, err := ioutil.TempFile(filepath.Dir(filename), "config") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 140 | if err != nil { |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 141 | 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] | 142 | } |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 143 | defer os.Remove(f.Name()) |
| 144 | defer f.Close() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 145 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 146 | _, err = f.Write(data) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 147 | if err != nil { |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 148 | return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error()) |
| 149 | } |
| 150 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 151 | _, err = f.WriteString("\n") |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 152 | if err != nil { |
| 153 | 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] | 154 | } |
| 155 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 156 | f.Close() |
| 157 | os.Rename(f.Name(), filename) |
| 158 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 159 | return nil |
| 160 | } |
| 161 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 162 | // TestConfig returns a Config object suitable for using for tests |
Colin Cross | 0d614dd | 2016-10-14 15:38:43 -0700 | [diff] [blame] | 163 | func TestConfig(buildDir string) Config { |
| 164 | return Config{&config{ |
| 165 | buildDir: buildDir, |
| 166 | }} |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 169 | // New creates a new Config object. The srcDir argument specifies the path to |
| 170 | // the root source directory. It also loads the config file, if found. |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 171 | func NewConfig(srcDir, buildDir string) (Config, error) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 172 | // Make a config with default options |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 173 | config := &config{ |
| 174 | ConfigFileName: filepath.Join(buildDir, configFileName), |
| 175 | ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName), |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 176 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 177 | srcDir: srcDir, |
| 178 | buildDir: buildDir, |
| 179 | envDeps: make(map[string]string), |
| 180 | |
| 181 | deviceConfig: &deviceConfig{}, |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 182 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 183 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 184 | deviceConfig := &deviceConfig{ |
| 185 | config: config, |
| 186 | } |
| 187 | |
| 188 | config.deviceConfig = deviceConfig |
| 189 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 190 | // Sanity check the build and source directories. This won't catch strange |
| 191 | // configurations with symlinks, but at least checks the obvious cases. |
| 192 | absBuildDir, err := filepath.Abs(buildDir) |
| 193 | if err != nil { |
| 194 | return Config{}, err |
| 195 | } |
| 196 | |
| 197 | absSrcDir, err := filepath.Abs(srcDir) |
| 198 | if err != nil { |
| 199 | return Config{}, err |
| 200 | } |
| 201 | |
| 202 | if strings.HasPrefix(absSrcDir, absBuildDir) { |
| 203 | return Config{}, fmt.Errorf("Build dir must not contain source directory") |
| 204 | } |
| 205 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 206 | // Load any configurable options from the configuration file |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 207 | err = loadConfig(config) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 208 | if err != nil { |
Colin Cross | c3c0a49 | 2015-04-10 15:43:55 -0700 | [diff] [blame] | 209 | return Config{}, err |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 210 | } |
| 211 | |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 212 | inMakeFile := filepath.Join(buildDir, ".soong.in_make") |
| 213 | if _, err := os.Stat(inMakeFile); err == nil { |
| 214 | config.inMake = true |
| 215 | } |
| 216 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 217 | targets, err := decodeTargetProductVariables(config) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 218 | if err != nil { |
| 219 | return Config{}, err |
| 220 | } |
| 221 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 222 | var archConfig []archConfig |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 223 | if Bool(config.Mega_device) { |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 224 | archConfig = getMegaDeviceConfig() |
| 225 | } else if Bool(config.Ndk_abis) { |
| 226 | archConfig = getNdkAbisConfig() |
| 227 | } |
| 228 | |
| 229 | if archConfig != nil { |
| 230 | deviceTargets, err := decodeArchSettings(archConfig) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 231 | if err != nil { |
| 232 | return Config{}, err |
| 233 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 234 | targets[Device] = deviceTargets |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 237 | config.Targets = targets |
| 238 | config.BuildOsVariant = targets[Host][0].String() |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 239 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 240 | return Config{config}, nil |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 243 | func (c *config) RemoveAbandonedFiles() bool { |
| 244 | return false |
| 245 | } |
| 246 | |
Dan Willemsen | c2aa4a9 | 2016-05-26 15:13:03 -0700 | [diff] [blame] | 247 | func (c *config) BlueprintToolLocation() string { |
| 248 | return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin") |
| 249 | } |
| 250 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 251 | // PrebuiltOS returns the name of the host OS used in prebuilts directories |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 252 | func (c *config) PrebuiltOS() string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 253 | switch runtime.GOOS { |
| 254 | case "linux": |
| 255 | return "linux-x86" |
| 256 | case "darwin": |
| 257 | return "darwin-x86" |
| 258 | default: |
| 259 | panic("Unknown GOOS") |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | // GoRoot returns the path to the root directory of the Go toolchain. |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 264 | func (c *config) GoRoot() string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 265 | return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS()) |
| 266 | } |
| 267 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 268 | func (c *config) CpPreserveSymlinksFlags() string { |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 269 | switch runtime.GOOS { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 270 | case "darwin": |
| 271 | return "-R" |
| 272 | case "linux": |
| 273 | return "-d" |
| 274 | default: |
| 275 | return "" |
| 276 | } |
| 277 | } |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 278 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 279 | func (c *config) Getenv(key string) string { |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 280 | var val string |
| 281 | var exists bool |
Colin Cross | c1e86a3 | 2015-04-15 12:33:28 -0700 | [diff] [blame] | 282 | c.envLock.Lock() |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 283 | if val, exists = c.envDeps[key]; !exists { |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 284 | if c.envFrozen { |
| 285 | panic("Cannot access new environment variables after envdeps are frozen") |
| 286 | } |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 287 | val = os.Getenv(key) |
| 288 | c.envDeps[key] = val |
| 289 | } |
Colin Cross | c1e86a3 | 2015-04-15 12:33:28 -0700 | [diff] [blame] | 290 | c.envLock.Unlock() |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 291 | return val |
| 292 | } |
| 293 | |
Colin Cross | 99d7c23 | 2016-11-23 16:52:04 -0800 | [diff] [blame] | 294 | func (c *config) GetenvWithDefault(key string, defaultValue string) string { |
| 295 | ret := c.Getenv(key) |
| 296 | if ret == "" { |
| 297 | return defaultValue |
| 298 | } |
| 299 | return ret |
| 300 | } |
| 301 | |
| 302 | func (c *config) IsEnvTrue(key string) bool { |
| 303 | value := c.Getenv(key) |
| 304 | return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true" |
| 305 | } |
| 306 | |
| 307 | func (c *config) IsEnvFalse(key string) bool { |
| 308 | value := c.Getenv(key) |
| 309 | return value == "0" || value == "n" || value == "no" || value == "off" || value == "false" |
| 310 | } |
| 311 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 312 | func (c *config) EnvDeps() map[string]string { |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 313 | c.envLock.Lock() |
| 314 | c.envFrozen = true |
| 315 | c.envLock.Unlock() |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 316 | return c.envDeps |
| 317 | } |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 318 | |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 319 | func (c *config) EmbeddedInMake() bool { |
| 320 | return c.inMake |
| 321 | } |
| 322 | |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 323 | // DeviceName returns the name of the current device target |
| 324 | // 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] | 325 | func (c *config) DeviceName() string { |
Dan Willemsen | 1d31ec3 | 2015-09-22 16:56:09 -0700 | [diff] [blame] | 326 | return *c.ProductVariables.DeviceName |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Dan Willemsen | dd0e2c3 | 2015-10-20 14:29:35 -0700 | [diff] [blame] | 329 | func (c *config) DeviceUsesClang() bool { |
| 330 | if c.ProductVariables.DeviceUsesClang != nil { |
| 331 | return *c.ProductVariables.DeviceUsesClang |
| 332 | } |
Dan Willemsen | 0084d78 | 2016-03-01 14:54:24 -0800 | [diff] [blame] | 333 | return true |
Dan Willemsen | dd0e2c3 | 2015-10-20 14:29:35 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 336 | func (c *config) ResourceOverlays() []SourcePath { |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 337 | return nil |
| 338 | } |
| 339 | |
| 340 | func (c *config) PlatformVersion() string { |
| 341 | return "M" |
| 342 | } |
| 343 | |
Dan Albert | 073379e | 2016-11-10 10:46:36 -0800 | [diff] [blame] | 344 | func (c *config) PlatformSdkVersionInt() int { |
| 345 | return *c.ProductVariables.Platform_sdk_version |
| 346 | } |
| 347 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 348 | func (c *config) PlatformSdkVersion() string { |
Dan Albert | 073379e | 2016-11-10 10:46:36 -0800 | [diff] [blame] | 349 | return strconv.Itoa(c.PlatformSdkVersionInt()) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | func (c *config) BuildNumber() string { |
| 353 | return "000000" |
| 354 | } |
| 355 | |
| 356 | func (c *config) ProductAaptConfig() []string { |
| 357 | return []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"} |
| 358 | } |
| 359 | |
| 360 | func (c *config) ProductAaptPreferredConfig() string { |
| 361 | return "xhdpi" |
| 362 | } |
| 363 | |
| 364 | func (c *config) ProductAaptCharacteristics() string { |
| 365 | return "nosdcard" |
| 366 | } |
| 367 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 368 | func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath { |
| 369 | return PathForSource(ctx, "build/target/product/security") |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 372 | func (c *config) DefaultAppCertificate(ctx PathContext) SourcePath { |
| 373 | return c.DefaultAppCertificateDir(ctx).Join(ctx, "testkey") |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 374 | } |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 375 | |
| 376 | func (c *config) AllowMissingDependencies() bool { |
Dan Willemsen | b503816 | 2016-03-16 12:35:33 -0700 | [diff] [blame] | 377 | return Bool(c.ProductVariables.Allow_missing_dependencies) |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 378 | } |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 379 | |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 380 | func (c *config) DevicePrefer32BitExecutables() bool { |
| 381 | return Bool(c.ProductVariables.DevicePrefer32BitExecutables) |
| 382 | } |
| 383 | |
Dan Willemsen | 7f730fd | 2016-01-14 11:22:23 -0800 | [diff] [blame] | 384 | func (c *config) SkipDeviceInstall() bool { |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 385 | return c.EmbeddedInMake() || Bool(c.Mega_device) |
| 386 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 387 | |
| 388 | func (c *config) SanitizeHost() []string { |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 389 | return append([]string(nil), c.ProductVariables.SanitizeHost...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | func (c *config) SanitizeDevice() []string { |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 393 | return append([]string(nil), c.ProductVariables.SanitizeDevice...) |
| 394 | } |
| 395 | |
| 396 | func (c *config) SanitizeDeviceArch() []string { |
| 397 | return append([]string(nil), c.ProductVariables.SanitizeDeviceArch...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 398 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 399 | |
| 400 | func (c *config) Android64() bool { |
| 401 | for _, t := range c.Targets[Device] { |
| 402 | if t.Arch.ArchType.Multilib == "lib64" { |
| 403 | return true |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | return false |
| 408 | } |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 409 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 410 | func (c *config) UseGoma() bool { |
| 411 | return Bool(c.ProductVariables.UseGoma) |
| 412 | } |
| 413 | |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 414 | func (c *config) ClangTidy() bool { |
| 415 | return Bool(c.ProductVariables.ClangTidy) |
| 416 | } |
| 417 | |
| 418 | func (c *config) TidyChecks() string { |
| 419 | if c.ProductVariables.TidyChecks == nil { |
| 420 | return "" |
| 421 | } |
| 422 | return *c.ProductVariables.TidyChecks |
| 423 | } |
| 424 | |
Colin Cross | 0f4e0d6 | 2016-07-27 10:56:55 -0700 | [diff] [blame] | 425 | func (c *config) LibartImgHostBaseAddress() string { |
| 426 | return "0x60000000" |
| 427 | } |
| 428 | |
| 429 | func (c *config) LibartImgDeviceBaseAddress() string { |
| 430 | switch c.Targets[Device][0].Arch.ArchType { |
| 431 | default: |
| 432 | return "0x70000000" |
| 433 | case Mips, Mips64: |
| 434 | return "0x30000000" |
| 435 | } |
| 436 | } |
| 437 | |
Hiroshi Yamauchi | e2a1063 | 2016-12-19 13:44:41 -0800 | [diff] [blame^] | 438 | func (c *config) ArtUseReadBarrier() bool { |
| 439 | return Bool(c.ProductVariables.ArtUseReadBarrier) |
| 440 | } |
| 441 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 442 | func (c *deviceConfig) Arches() []Arch { |
| 443 | var arches []Arch |
| 444 | for _, target := range c.config.Targets[Device] { |
| 445 | arches = append(arches, target.Arch) |
| 446 | } |
| 447 | return arches |
| 448 | } |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 449 | |
Dan Willemsen | 4353bc4 | 2016-12-05 17:16:02 -0800 | [diff] [blame] | 450 | func (c *deviceConfig) VendorPath() string { |
| 451 | if c.config.ProductVariables.VendorPath != nil { |
| 452 | return *c.config.ProductVariables.VendorPath |
| 453 | } |
| 454 | return "vendor" |
| 455 | } |
| 456 | |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 457 | func (c *deviceConfig) VndkVersion() string { |
| 458 | if c.config.ProductVariables.DeviceVndkVersion == nil { |
| 459 | return "" |
| 460 | } |
| 461 | return *c.config.ProductVariables.DeviceVndkVersion |
| 462 | } |