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