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