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 | 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 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 27 | "github.com/google/blueprint" |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 28 | "github.com/google/blueprint/bootstrap" |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 29 | "github.com/google/blueprint/pathtools" |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 30 | "github.com/google/blueprint/proptools" |
Colin Cross | 9d34f35 | 2019-11-22 16:03:51 -0800 | [diff] [blame] | 31 | |
| 32 | "android/soong/android/soongconfig" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 33 | ) |
| 34 | |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 35 | var Bool = proptools.Bool |
Jack He | 8cc7143 | 2016-12-08 15:45:07 -0800 | [diff] [blame] | 36 | var String = proptools.String |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 37 | var StringDefault = proptools.StringDefault |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 38 | |
Dan Albert | 0b176c8 | 2020-07-23 16:43:25 -0700 | [diff] [blame] | 39 | const FutureApiLevelInt = 10000 |
| 40 | |
| 41 | var FutureApiLevel = ApiLevel{ |
| 42 | value: "current", |
| 43 | number: FutureApiLevelInt, |
| 44 | isPreview: true, |
| 45 | } |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 46 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 47 | // The configuration file name |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 48 | const configFileName = "soong.config" |
| 49 | const productVariablesFileName = "soong.variables" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 50 | |
| 51 | // A FileConfigurableOptions contains options which can be configured by the |
| 52 | // config file. These will be included in the config struct. |
| 53 | type FileConfigurableOptions struct { |
Jiyong Park | 2210198 | 2020-09-17 19:09:58 +0900 | [diff] [blame] | 54 | Mega_device *bool `json:",omitempty"` |
| 55 | Host_bionic *bool `json:",omitempty"` |
| 56 | Host_bionic_arm64 *bool `json:",omitempty"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Colin Cross | 2738597 | 2015-09-18 10:57:10 -0700 | [diff] [blame] | 59 | func (f *FileConfigurableOptions) SetDefaultConfig() { |
| 60 | *f = FileConfigurableOptions{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 61 | } |
| 62 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 63 | // A Config object represents the entire build configuration for Android. |
Colin Cross | c3c0a49 | 2015-04-10 15:43:55 -0700 | [diff] [blame] | 64 | type Config struct { |
| 65 | *config |
| 66 | } |
| 67 | |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 68 | func (c Config) BuildDir() string { |
| 69 | return c.buildDir |
| 70 | } |
| 71 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 72 | // A DeviceConfig object represents the configuration for a particular device being built. For |
| 73 | // now there will only be one of these, but in the future there may be multiple devices being |
| 74 | // built |
| 75 | type DeviceConfig struct { |
| 76 | *deviceConfig |
| 77 | } |
| 78 | |
Colin Cross | 9d34f35 | 2019-11-22 16:03:51 -0800 | [diff] [blame] | 79 | type VendorConfig soongconfig.SoongConfig |
Dan Willemsen | 0fe7866 | 2018-03-26 12:41:18 -0700 | [diff] [blame] | 80 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 81 | type config struct { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 82 | FileConfigurableOptions |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 83 | productVariables productVariables |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 84 | |
Dan Willemsen | 674dc7f | 2018-03-12 18:06:05 -0700 | [diff] [blame] | 85 | // Only available on configs created by TestConfig |
| 86 | TestProductVariables *productVariables |
| 87 | |
Chris Parsons | f3c96ef | 2020-09-29 02:23:17 -0400 | [diff] [blame] | 88 | BazelContext BazelContext |
| 89 | |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 90 | PrimaryBuilder string |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 91 | ConfigFileName string |
| 92 | ProductVariablesFileName string |
| 93 | |
Jaewoong Jung | 642916f | 2020-10-09 17:25:15 -0700 | [diff] [blame] | 94 | Targets map[OsType][]Target |
| 95 | BuildOSTarget Target // the Target for tools run on the build machine |
| 96 | BuildOSCommonTarget Target // the Target for common (java) tools run on the build machine |
| 97 | AndroidCommonTarget Target // the Target for common modules for the Android device |
| 98 | AndroidFirstDeviceTarget Target // the first Target for modules for the Android device |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 99 | |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 100 | // multilibConflicts for an ArchType is true if there is earlier configured device architecture with the same |
| 101 | // multilib value. |
| 102 | multilibConflicts map[ArchType]bool |
| 103 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 104 | deviceConfig *deviceConfig |
| 105 | |
Chris Parsons | 8f232a2 | 2020-06-23 17:37:05 -0400 | [diff] [blame] | 106 | srcDir string // the path of the root source directory |
| 107 | buildDir string // the path of the build output directory |
| 108 | moduleListFile string // the path to the file which lists blueprint files to parse. |
Colin Cross | c1e86a3 | 2015-04-15 12:33:28 -0700 | [diff] [blame] | 109 | |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 110 | env map[string]string |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 111 | envLock sync.Mutex |
| 112 | envDeps map[string]string |
| 113 | envFrozen bool |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 114 | |
| 115 | inMake bool |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 116 | |
Colin Cross | 32616ed | 2017-09-05 21:56:44 -0700 | [diff] [blame] | 117 | captureBuild bool // true for tests, saves build parameters for each module |
| 118 | ignoreEnvironment bool // true for tests, returns empty from all Getenv calls |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 119 | |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 120 | stopBefore bootstrap.StopBefore |
| 121 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 122 | fs pathtools.FileSystem |
| 123 | mockBpList string |
| 124 | |
Colin Cross | 5e6a797 | 2020-06-07 16:56:32 -0700 | [diff] [blame] | 125 | // If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error |
| 126 | // in tests when a path doesn't exist. |
| 127 | testAllowNonExistentPaths bool |
| 128 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 129 | OncePer |
| 130 | } |
| 131 | |
| 132 | type deviceConfig struct { |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 133 | config *config |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 134 | OncePer |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 135 | } |
| 136 | |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 137 | type jsonConfigurable interface { |
Colin Cross | 2738597 | 2015-09-18 10:57:10 -0700 | [diff] [blame] | 138 | SetDefaultConfig() |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 139 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 140 | |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 141 | func loadConfig(config *config) error { |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 142 | err := loadFromConfigFile(&config.FileConfigurableOptions, absolutePath(config.ConfigFileName)) |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 143 | if err != nil { |
| 144 | return err |
| 145 | } |
| 146 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 147 | return loadFromConfigFile(&config.productVariables, absolutePath(config.ProductVariablesFileName)) |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | // loads configuration options from a JSON file in the cwd. |
| 151 | func loadFromConfigFile(configurable jsonConfigurable, filename string) error { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 152 | // Try to open the file |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 153 | configFileReader, err := os.Open(filename) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 154 | defer configFileReader.Close() |
| 155 | if os.IsNotExist(err) { |
| 156 | // Need to create a file, so that blueprint & ninja don't get in |
| 157 | // a dependency tracking loop. |
| 158 | // Make a file-configurable-options with defaults, write it out using |
| 159 | // a json writer. |
Colin Cross | 2738597 | 2015-09-18 10:57:10 -0700 | [diff] [blame] | 160 | configurable.SetDefaultConfig() |
| 161 | err = saveToConfigFile(configurable, filename) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 162 | if err != nil { |
| 163 | return err |
| 164 | } |
Colin Cross | 15cd21a | 2018-02-27 11:26:02 -0800 | [diff] [blame] | 165 | } else if err != nil { |
| 166 | return fmt.Errorf("config file: could not open %s: %s", filename, err.Error()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 167 | } else { |
| 168 | // Make a decoder for it |
| 169 | jsonDecoder := json.NewDecoder(configFileReader) |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 170 | err = jsonDecoder.Decode(configurable) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 171 | if err != nil { |
Colin Cross | 15cd21a | 2018-02-27 11:26:02 -0800 | [diff] [blame] | 172 | return fmt.Errorf("config file: %s did not parse correctly: %s", filename, err.Error()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 176 | // No error |
| 177 | return nil |
| 178 | } |
| 179 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 180 | // atomically writes the config file in case two copies of soong_build are running simultaneously |
| 181 | // (for example, docs generation and ninja manifest generation) |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 182 | func saveToConfigFile(config jsonConfigurable, filename string) error { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 183 | data, err := json.MarshalIndent(&config, "", " ") |
| 184 | if err != nil { |
| 185 | return fmt.Errorf("cannot marshal config data: %s", err.Error()) |
| 186 | } |
| 187 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 188 | f, err := ioutil.TempFile(filepath.Dir(filename), "config") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 189 | if err != nil { |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 190 | 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] | 191 | } |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 192 | defer os.Remove(f.Name()) |
| 193 | defer f.Close() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 194 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 195 | _, err = f.Write(data) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 196 | if err != nil { |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 197 | return fmt.Errorf("default config file: %s could not be written: %s", filename, err.Error()) |
| 198 | } |
| 199 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 200 | _, err = f.WriteString("\n") |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 201 | if err != nil { |
| 202 | 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] | 203 | } |
| 204 | |
Colin Cross | d8f2014 | 2016-11-03 09:43:26 -0700 | [diff] [blame] | 205 | f.Close() |
| 206 | os.Rename(f.Name(), filename) |
| 207 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 208 | return nil |
| 209 | } |
| 210 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 211 | // NullConfig returns a mostly empty Config for use by standalone tools like dexpreopt_gen that |
| 212 | // use the android package. |
| 213 | func NullConfig(buildDir string) Config { |
| 214 | return Config{ |
| 215 | config: &config{ |
| 216 | buildDir: buildDir, |
| 217 | fs: pathtools.OsFs, |
| 218 | }, |
| 219 | } |
| 220 | } |
| 221 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 222 | // TestConfig returns a Config object suitable for using for tests |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 223 | func TestConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config { |
Colin Cross | 9c6241f | 2019-04-22 15:51:26 -0700 | [diff] [blame] | 224 | envCopy := make(map[string]string) |
| 225 | for k, v := range env { |
| 226 | envCopy[k] = v |
| 227 | } |
| 228 | |
| 229 | // Copy the real PATH value to the test environment, it's needed by HostSystemTool() used in x86_darwin_host.go |
| 230 | envCopy["PATH"] = originalEnv["PATH"] |
| 231 | |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 232 | config := &config{ |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 233 | productVariables: productVariables{ |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 234 | DeviceName: stringPtr("test_device"), |
| 235 | Platform_sdk_version: intPtr(30), |
| 236 | Platform_sdk_codename: stringPtr("S"), |
| 237 | Platform_version_active_codenames: []string{"S"}, |
| 238 | DeviceSystemSdkVersions: []string{"14", "15"}, |
| 239 | Platform_systemsdk_versions: []string{"29", "30"}, |
| 240 | AAPTConfig: []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"}, |
| 241 | AAPTPreferredConfig: stringPtr("xhdpi"), |
| 242 | AAPTCharacteristics: stringPtr("nosdcard"), |
| 243 | AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"}, |
| 244 | UncompressPrivAppDex: boolPtr(true), |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 245 | }, |
| 246 | |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 247 | buildDir: buildDir, |
| 248 | captureBuild: true, |
Colin Cross | 9c6241f | 2019-04-22 15:51:26 -0700 | [diff] [blame] | 249 | env: envCopy, |
Colin Cross | 5e6a797 | 2020-06-07 16:56:32 -0700 | [diff] [blame] | 250 | |
| 251 | // Set testAllowNonExistentPaths so that test contexts don't need to specify every path |
| 252 | // passed to PathForSource or PathForModuleSrc. |
| 253 | testAllowNonExistentPaths: true, |
Chris Parsons | f3c96ef | 2020-09-29 02:23:17 -0400 | [diff] [blame] | 254 | |
| 255 | BazelContext: noopBazelContext{}, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 256 | } |
| 257 | config.deviceConfig = &deviceConfig{ |
| 258 | config: config, |
| 259 | } |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 260 | config.TestProductVariables = &config.productVariables |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 261 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 262 | config.mockFileSystem(bp, fs) |
| 263 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 264 | if err := config.fromEnv(); err != nil { |
| 265 | panic(err) |
| 266 | } |
| 267 | |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 268 | return Config{config} |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 271 | func TestArchConfigNativeBridge(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config { |
| 272 | testConfig := TestArchConfig(buildDir, env, bp, fs) |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 273 | config := testConfig.config |
| 274 | |
Colin Cross | 0d99f7c | 2019-05-14 16:01:24 -0700 | [diff] [blame] | 275 | config.Targets[Android] = []Target{ |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 276 | {Android, Arch{ArchType: X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false}, |
| 277 | {Android, Arch{ArchType: X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", "", false}, |
| 278 | {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeEnabled, "x86_64", "arm64", false}, |
| 279 | {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeEnabled, "x86", "arm", false}, |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | return testConfig |
| 283 | } |
| 284 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 285 | func TestArchConfigFuchsia(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config { |
| 286 | testConfig := TestConfig(buildDir, env, bp, fs) |
Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 287 | config := testConfig.config |
| 288 | |
| 289 | config.Targets = map[OsType][]Target{ |
| 290 | Fuchsia: []Target{ |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 291 | {Fuchsia, Arch{ArchType: Arm64, ArchVariant: "", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false}, |
Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 292 | }, |
| 293 | BuildOs: []Target{ |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 294 | {BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", false}, |
Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 295 | }, |
| 296 | } |
| 297 | |
| 298 | return testConfig |
| 299 | } |
| 300 | |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 301 | // TestConfig returns a Config object suitable for using for tests that need to run the arch mutator |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 302 | func TestArchConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) Config { |
| 303 | testConfig := TestConfig(buildDir, env, bp, fs) |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 304 | config := testConfig.config |
| 305 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 306 | config.Targets = map[OsType][]Target{ |
| 307 | Android: []Target{ |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 308 | {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false}, |
| 309 | {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", "", false}, |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 310 | }, |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 311 | BuildOs: []Target{ |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 312 | {BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", false}, |
| 313 | {BuildOs, Arch{ArchType: X86}, NativeBridgeDisabled, "", "", false}, |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 314 | }, |
| 315 | } |
| 316 | |
Colin Cross | 0d99f7c | 2019-05-14 16:01:24 -0700 | [diff] [blame] | 317 | if runtime.GOOS == "darwin" { |
| 318 | config.Targets[BuildOs] = config.Targets[BuildOs][:1] |
| 319 | } |
| 320 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 321 | config.BuildOSTarget = config.Targets[BuildOs][0] |
| 322 | config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0] |
| 323 | config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0] |
Jaewoong Jung | 642916f | 2020-10-09 17:25:15 -0700 | [diff] [blame] | 324 | config.AndroidFirstDeviceTarget = firstTarget(config.Targets[Android], "lib64", "lib32")[0] |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 325 | config.TestProductVariables.DeviceArch = proptools.StringPtr("arm64") |
| 326 | config.TestProductVariables.DeviceArchVariant = proptools.StringPtr("armv8-a") |
| 327 | config.TestProductVariables.DeviceSecondaryArch = proptools.StringPtr("arm") |
| 328 | config.TestProductVariables.DeviceSecondaryArchVariant = proptools.StringPtr("armv7-a-neon") |
Colin Cross | 2a07692 | 2018-10-04 23:28:25 -0700 | [diff] [blame] | 329 | |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 330 | return testConfig |
| 331 | } |
| 332 | |
Chris Parsons | f3c96ef | 2020-09-29 02:23:17 -0400 | [diff] [blame] | 333 | // Returns a config object which is "reset" for another bootstrap run. |
| 334 | // Only per-run data is reset. Data which needs to persist across multiple |
| 335 | // runs in the same program execution is carried over (such as Bazel context |
| 336 | // or environment deps). |
| 337 | func ConfigForAdditionalRun(c Config) (Config, error) { |
| 338 | newConfig, err := NewConfig(c.srcDir, c.buildDir, c.moduleListFile) |
| 339 | if err != nil { |
| 340 | return Config{}, err |
| 341 | } |
| 342 | newConfig.BazelContext = c.BazelContext |
| 343 | newConfig.envDeps = c.envDeps |
| 344 | return newConfig, nil |
| 345 | } |
| 346 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 347 | // New creates a new Config object. The srcDir argument specifies the path to |
| 348 | // the root source directory. It also loads the config file, if found. |
Chris Parsons | 8f232a2 | 2020-06-23 17:37:05 -0400 | [diff] [blame] | 349 | func NewConfig(srcDir, buildDir string, moduleListFile string) (Config, error) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 350 | // Make a config with default options |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 351 | config := &config{ |
| 352 | ConfigFileName: filepath.Join(buildDir, configFileName), |
| 353 | ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName), |
Dan Willemsen | 87b17d1 | 2015-07-14 00:39:06 -0700 | [diff] [blame] | 354 | |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 355 | env: originalEnv, |
| 356 | |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 357 | srcDir: srcDir, |
| 358 | buildDir: buildDir, |
| 359 | multilibConflicts: make(map[ArchType]bool), |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 360 | |
Chris Parsons | 8f232a2 | 2020-06-23 17:37:05 -0400 | [diff] [blame] | 361 | moduleListFile: moduleListFile, |
| 362 | fs: pathtools.NewOsFs(absSrcDir), |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 363 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 364 | |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 365 | config.deviceConfig = &deviceConfig{ |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 366 | config: config, |
| 367 | } |
| 368 | |
Liz Kammer | 7941b30 | 2020-07-28 13:27:34 -0700 | [diff] [blame] | 369 | // Soundness check of the build and source directories. This won't catch strange |
| 370 | // configurations with symlinks, but at least checks the obvious case. |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 371 | absBuildDir, err := filepath.Abs(buildDir) |
| 372 | if err != nil { |
| 373 | return Config{}, err |
| 374 | } |
| 375 | |
| 376 | absSrcDir, err := filepath.Abs(srcDir) |
| 377 | if err != nil { |
| 378 | return Config{}, err |
| 379 | } |
| 380 | |
| 381 | if strings.HasPrefix(absSrcDir, absBuildDir) { |
| 382 | return Config{}, fmt.Errorf("Build dir must not contain source directory") |
| 383 | } |
| 384 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 385 | // Load any configurable options from the configuration file |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 386 | err = loadConfig(config) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 387 | if err != nil { |
Colin Cross | c3c0a49 | 2015-04-10 15:43:55 -0700 | [diff] [blame] | 388 | return Config{}, err |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 389 | } |
| 390 | |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 391 | inMakeFile := filepath.Join(buildDir, ".soong.in_make") |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 392 | if _, err := os.Stat(absolutePath(inMakeFile)); err == nil { |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 393 | config.inMake = true |
| 394 | } |
| 395 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 396 | targets, err := decodeTargetProductVariables(config) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 397 | if err != nil { |
| 398 | return Config{}, err |
| 399 | } |
| 400 | |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 401 | // Make the CommonOS OsType available for all products. |
| 402 | targets[CommonOS] = []Target{commonTargetMap[CommonOS.Name]} |
| 403 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 404 | var archConfig []archConfig |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 405 | if Bool(config.Mega_device) { |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 406 | archConfig = getMegaDeviceConfig() |
Colin Cross | 395f2cf | 2018-10-24 16:10:32 -0700 | [diff] [blame] | 407 | } else if config.NdkAbis() { |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 408 | archConfig = getNdkAbisConfig() |
Martin Stjernholm | c1ecc43 | 2019-11-15 15:00:31 +0000 | [diff] [blame] | 409 | } else if config.AmlAbis() { |
| 410 | archConfig = getAmlAbisConfig() |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | if archConfig != nil { |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 414 | androidTargets, err := decodeArchSettings(Android, archConfig) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 415 | if err != nil { |
| 416 | return Config{}, err |
| 417 | } |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 418 | targets[Android] = androidTargets |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 419 | } |
| 420 | |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 421 | multilib := make(map[string]bool) |
| 422 | for _, target := range targets[Android] { |
| 423 | if seen := multilib[target.Arch.ArchType.Multilib]; seen { |
| 424 | config.multilibConflicts[target.Arch.ArchType] = true |
| 425 | } |
| 426 | multilib[target.Arch.ArchType.Multilib] = true |
| 427 | } |
| 428 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 429 | config.Targets = targets |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 430 | config.BuildOSTarget = config.Targets[BuildOs][0] |
| 431 | config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0] |
| 432 | if len(config.Targets[Android]) > 0 { |
| 433 | config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0] |
Jaewoong Jung | 642916f | 2020-10-09 17:25:15 -0700 | [diff] [blame] | 434 | config.AndroidFirstDeviceTarget = firstTarget(config.Targets[Android], "lib64", "lib32")[0] |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 435 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 436 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 437 | if err := config.fromEnv(); err != nil { |
| 438 | return Config{}, err |
| 439 | } |
| 440 | |
Colin Cross | 1a6acd4 | 2020-06-16 17:51:46 -0700 | [diff] [blame] | 441 | if Bool(config.productVariables.GcovCoverage) && Bool(config.productVariables.ClangCoverage) { |
| 442 | return Config{}, fmt.Errorf("GcovCoverage and ClangCoverage cannot both be set") |
| 443 | } |
| 444 | |
| 445 | config.productVariables.Native_coverage = proptools.BoolPtr( |
| 446 | Bool(config.productVariables.GcovCoverage) || |
| 447 | Bool(config.productVariables.ClangCoverage)) |
| 448 | |
Chris Parsons | f3c96ef | 2020-09-29 02:23:17 -0400 | [diff] [blame] | 449 | config.BazelContext, err = NewBazelContext(config) |
| 450 | if err != nil { |
| 451 | return Config{}, err |
| 452 | } |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 453 | return Config{config}, nil |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 454 | } |
| 455 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 456 | var TestConfigOsFs = map[string][]byte{} |
| 457 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 458 | // mockFileSystem replaces all reads with accesses to the provided map of |
| 459 | // filenames to contents stored as a byte slice. |
| 460 | func (c *config) mockFileSystem(bp string, fs map[string][]byte) { |
| 461 | mockFS := map[string][]byte{} |
| 462 | |
| 463 | if _, exists := mockFS["Android.bp"]; !exists { |
| 464 | mockFS["Android.bp"] = []byte(bp) |
| 465 | } |
| 466 | |
| 467 | for k, v := range fs { |
| 468 | mockFS[k] = v |
| 469 | } |
| 470 | |
| 471 | // no module list file specified; find every file named Blueprints or Android.bp |
| 472 | pathsToParse := []string{} |
| 473 | for candidate := range mockFS { |
| 474 | base := filepath.Base(candidate) |
| 475 | if base == "Blueprints" || base == "Android.bp" { |
| 476 | pathsToParse = append(pathsToParse, candidate) |
| 477 | } |
| 478 | } |
| 479 | if len(pathsToParse) < 1 { |
| 480 | panic(fmt.Sprintf("No Blueprint or Android.bp files found in mock filesystem: %v\n", mockFS)) |
| 481 | } |
| 482 | mockFS[blueprint.MockModuleListFile] = []byte(strings.Join(pathsToParse, "\n")) |
| 483 | |
| 484 | c.fs = pathtools.MockFs(mockFS) |
| 485 | c.mockBpList = blueprint.MockModuleListFile |
| 486 | } |
| 487 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 488 | func (c *config) fromEnv() error { |
Pete Gillin | 0c2143e | 2019-05-02 15:32:11 +0100 | [diff] [blame] | 489 | switch c.Getenv("EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9") { |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 490 | case "", "true": |
Pete Gillin | a1c9e9d | 2019-10-17 14:52:07 +0100 | [diff] [blame] | 491 | // Do nothing |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 492 | default: |
Pete Gillin | a1c9e9d | 2019-10-17 14:52:07 +0100 | [diff] [blame] | 493 | return fmt.Errorf("The environment variable EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9 is no longer supported. Java language level 9 is now the global default.") |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | return nil |
| 497 | } |
| 498 | |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 499 | func (c *config) StopBefore() bootstrap.StopBefore { |
| 500 | return c.stopBefore |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 503 | func (c *config) SetStopBefore(stopBefore bootstrap.StopBefore) { |
| 504 | c.stopBefore = stopBefore |
| 505 | } |
| 506 | |
| 507 | var _ bootstrap.ConfigStopBefore = (*config)(nil) |
| 508 | |
Dan Willemsen | c2aa4a9 | 2016-05-26 15:13:03 -0700 | [diff] [blame] | 509 | func (c *config) BlueprintToolLocation() string { |
| 510 | return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin") |
| 511 | } |
| 512 | |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 513 | var _ bootstrap.ConfigBlueprintToolLocation = (*config)(nil) |
| 514 | |
Dan Willemsen | 60e62f0 | 2018-11-16 21:05:32 -0800 | [diff] [blame] | 515 | func (c *config) HostToolPath(ctx PathContext, tool string) Path { |
| 516 | return PathForOutput(ctx, "host", c.PrebuiltOS(), "bin", tool) |
| 517 | } |
| 518 | |
Martin Stjernholm | 7260d06 | 2019-12-09 21:47:14 +0000 | [diff] [blame] | 519 | func (c *config) HostJNIToolPath(ctx PathContext, path string) Path { |
| 520 | ext := ".so" |
| 521 | if runtime.GOOS == "darwin" { |
| 522 | ext = ".dylib" |
| 523 | } |
| 524 | return PathForOutput(ctx, "host", c.PrebuiltOS(), "lib64", path+ext) |
| 525 | } |
| 526 | |
| 527 | func (c *config) HostJavaToolPath(ctx PathContext, path string) Path { |
| 528 | return PathForOutput(ctx, "host", c.PrebuiltOS(), "framework", path) |
| 529 | } |
| 530 | |
Dan Willemsen | 6606872 | 2017-05-08 21:15:59 +0000 | [diff] [blame] | 531 | // HostSystemTool looks for non-hermetic tools from the system we're running on. |
| 532 | // Generally shouldn't be used, but useful to find the XCode SDK, etc. |
| 533 | func (c *config) HostSystemTool(name string) string { |
| 534 | for _, dir := range filepath.SplitList(c.Getenv("PATH")) { |
| 535 | path := filepath.Join(dir, name) |
| 536 | if s, err := os.Stat(path); err != nil { |
| 537 | continue |
| 538 | } else if m := s.Mode(); !s.IsDir() && m&0111 != 0 { |
| 539 | return path |
| 540 | } |
| 541 | } |
| 542 | return name |
| 543 | } |
| 544 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 545 | // PrebuiltOS returns the name of the host OS used in prebuilts directories |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 546 | func (c *config) PrebuiltOS() string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 547 | switch runtime.GOOS { |
| 548 | case "linux": |
| 549 | return "linux-x86" |
| 550 | case "darwin": |
| 551 | return "darwin-x86" |
| 552 | default: |
| 553 | panic("Unknown GOOS") |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | // GoRoot returns the path to the root directory of the Go toolchain. |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 558 | func (c *config) GoRoot() string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 559 | return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS()) |
| 560 | } |
| 561 | |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 562 | func (c *config) PrebuiltBuildTool(ctx PathContext, tool string) Path { |
| 563 | return PathForSource(ctx, "prebuilts/build-tools", c.PrebuiltOS(), "bin", tool) |
| 564 | } |
| 565 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 566 | func (c *config) CpPreserveSymlinksFlags() string { |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 567 | switch runtime.GOOS { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 568 | case "darwin": |
| 569 | return "-R" |
| 570 | case "linux": |
| 571 | return "-d" |
| 572 | default: |
| 573 | return "" |
| 574 | } |
| 575 | } |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 576 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 577 | func (c *config) Getenv(key string) string { |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 578 | var val string |
| 579 | var exists bool |
Colin Cross | c1e86a3 | 2015-04-15 12:33:28 -0700 | [diff] [blame] | 580 | c.envLock.Lock() |
Colin Cross | c0d58b4 | 2017-02-06 15:40:41 -0800 | [diff] [blame] | 581 | defer c.envLock.Unlock() |
| 582 | if c.envDeps == nil { |
| 583 | c.envDeps = make(map[string]string) |
| 584 | } |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 585 | if val, exists = c.envDeps[key]; !exists { |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 586 | if c.envFrozen { |
| 587 | panic("Cannot access new environment variables after envdeps are frozen") |
| 588 | } |
Colin Cross | 6ccbc91 | 2017-10-10 23:07:38 -0700 | [diff] [blame] | 589 | val, _ = c.env[key] |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 590 | c.envDeps[key] = val |
| 591 | } |
| 592 | return val |
| 593 | } |
| 594 | |
Colin Cross | 99d7c23 | 2016-11-23 16:52:04 -0800 | [diff] [blame] | 595 | func (c *config) GetenvWithDefault(key string, defaultValue string) string { |
| 596 | ret := c.Getenv(key) |
| 597 | if ret == "" { |
| 598 | return defaultValue |
| 599 | } |
| 600 | return ret |
| 601 | } |
| 602 | |
| 603 | func (c *config) IsEnvTrue(key string) bool { |
| 604 | value := c.Getenv(key) |
| 605 | return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true" |
| 606 | } |
| 607 | |
| 608 | func (c *config) IsEnvFalse(key string) bool { |
| 609 | value := c.Getenv(key) |
| 610 | return value == "0" || value == "n" || value == "no" || value == "off" || value == "false" |
| 611 | } |
| 612 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 613 | func (c *config) EnvDeps() map[string]string { |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 614 | c.envLock.Lock() |
Colin Cross | c0d58b4 | 2017-02-06 15:40:41 -0800 | [diff] [blame] | 615 | defer c.envLock.Unlock() |
Dan Willemsen | e7680ba | 2015-09-11 17:06:19 -0700 | [diff] [blame] | 616 | c.envFrozen = true |
Colin Cross | 68f5510 | 2015-03-25 14:43:57 -0700 | [diff] [blame] | 617 | return c.envDeps |
| 618 | } |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 619 | |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 620 | func (c *config) EmbeddedInMake() bool { |
| 621 | return c.inMake |
| 622 | } |
| 623 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 624 | func (c *config) BuildId() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 625 | return String(c.productVariables.BuildId) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 626 | } |
| 627 | |
Colin Cross | 2a2e0db | 2020-02-21 16:55:46 -0800 | [diff] [blame] | 628 | func (c *config) BuildNumberFile(ctx PathContext) Path { |
| 629 | return PathForOutput(ctx, String(c.productVariables.BuildNumberFile)) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 630 | } |
| 631 | |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 632 | // DeviceName returns the name of the current device target |
| 633 | // 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] | 634 | func (c *config) DeviceName() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 635 | return *c.productVariables.DeviceName |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 638 | func (c *config) DeviceResourceOverlays() []string { |
| 639 | return c.productVariables.DeviceResourceOverlays |
| 640 | } |
| 641 | |
| 642 | func (c *config) ProductResourceOverlays() []string { |
| 643 | return c.productVariables.ProductResourceOverlays |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 644 | } |
| 645 | |
Colin Cross | bfd347d | 2018-05-09 11:11:35 -0700 | [diff] [blame] | 646 | func (c *config) PlatformVersionName() string { |
| 647 | return String(c.productVariables.Platform_version_name) |
| 648 | } |
| 649 | |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 650 | func (c *config) PlatformSdkVersion() ApiLevel { |
| 651 | return uncheckedFinalApiLevel(*c.productVariables.Platform_sdk_version) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 654 | func (c *config) PlatformSdkCodename() string { |
| 655 | return String(c.productVariables.Platform_sdk_codename) |
| 656 | } |
| 657 | |
Colin Cross | 092c9da | 2019-04-02 22:56:43 -0700 | [diff] [blame] | 658 | func (c *config) PlatformSecurityPatch() string { |
| 659 | return String(c.productVariables.Platform_security_patch) |
| 660 | } |
| 661 | |
| 662 | func (c *config) PlatformPreviewSdkVersion() string { |
| 663 | return String(c.productVariables.Platform_preview_sdk_version) |
| 664 | } |
| 665 | |
| 666 | func (c *config) PlatformMinSupportedTargetSdkVersion() string { |
| 667 | return String(c.productVariables.Platform_min_supported_target_sdk_version) |
| 668 | } |
| 669 | |
| 670 | func (c *config) PlatformBaseOS() string { |
| 671 | return String(c.productVariables.Platform_base_os) |
| 672 | } |
| 673 | |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 674 | func (c *config) MinSupportedSdkVersion() ApiLevel { |
| 675 | return uncheckedFinalApiLevel(16) |
| 676 | } |
| 677 | |
| 678 | func (c *config) FinalApiLevels() []ApiLevel { |
| 679 | var levels []ApiLevel |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 680 | for i := 1; i <= c.PlatformSdkVersion().FinalOrFutureInt(); i++ { |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 681 | levels = append(levels, uncheckedFinalApiLevel(i)) |
| 682 | } |
| 683 | return levels |
| 684 | } |
| 685 | |
| 686 | func (c *config) PreviewApiLevels() []ApiLevel { |
| 687 | var levels []ApiLevel |
| 688 | for i, codename := range c.PlatformVersionActiveCodenames() { |
| 689 | levels = append(levels, ApiLevel{ |
| 690 | value: codename, |
| 691 | number: i, |
| 692 | isPreview: true, |
| 693 | }) |
| 694 | } |
| 695 | return levels |
| 696 | } |
| 697 | |
| 698 | func (c *config) AllSupportedApiLevels() []ApiLevel { |
| 699 | var levels []ApiLevel |
| 700 | levels = append(levels, c.FinalApiLevels()...) |
| 701 | return append(levels, c.PreviewApiLevels()...) |
Dan Albert | f5415d7 | 2017-08-17 16:19:59 -0700 | [diff] [blame] | 702 | } |
| 703 | |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 704 | func (c *config) DefaultAppTargetSdk(ctx EarlyModuleContext) ApiLevel { |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 705 | if Bool(c.productVariables.Platform_sdk_final) { |
| 706 | return c.PlatformSdkVersion() |
| 707 | } else { |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 708 | codename := c.PlatformSdkCodename() |
| 709 | if codename == "" { |
| 710 | return NoneApiLevel |
| 711 | } |
| 712 | if codename == "REL" { |
| 713 | panic("Platform_sdk_codename should not be REL when Platform_sdk_final is true") |
| 714 | } |
| 715 | return ApiLevelOrPanic(ctx, codename) |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 719 | func (c *config) AppsDefaultVersionName() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 720 | return String(c.productVariables.AppsDefaultVersionName) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 721 | } |
| 722 | |
Dan Albert | 31384de | 2017-07-28 12:39:46 -0700 | [diff] [blame] | 723 | // Codenames that are active in the current lunch target. |
| 724 | func (c *config) PlatformVersionActiveCodenames() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 725 | return c.productVariables.Platform_version_active_codenames |
Dan Albert | 31384de | 2017-07-28 12:39:46 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 728 | func (c *config) ProductAAPTConfig() []string { |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 729 | return c.productVariables.AAPTConfig |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 732 | func (c *config) ProductAAPTPreferredConfig() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 733 | return String(c.productVariables.AAPTPreferredConfig) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 734 | } |
| 735 | |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 736 | func (c *config) ProductAAPTCharacteristics() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 737 | return String(c.productVariables.AAPTCharacteristics) |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | func (c *config) ProductAAPTPrebuiltDPI() []string { |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 741 | return c.productVariables.AAPTPrebuiltDPI |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 744 | func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 745 | defaultCert := String(c.productVariables.DefaultAppCertificate) |
Colin Cross | 61ae0b7 | 2017-12-01 17:16:02 -0800 | [diff] [blame] | 746 | if defaultCert != "" { |
| 747 | return PathForSource(ctx, filepath.Dir(defaultCert)) |
| 748 | } else { |
Dan Willemsen | 412160e | 2019-04-09 21:36:26 -0700 | [diff] [blame] | 749 | return PathForSource(ctx, "build/make/target/product/security") |
Colin Cross | 61ae0b7 | 2017-12-01 17:16:02 -0800 | [diff] [blame] | 750 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Colin Cross | e1731a5 | 2017-12-14 11:22:55 -0800 | [diff] [blame] | 753 | func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 754 | defaultCert := String(c.productVariables.DefaultAppCertificate) |
Colin Cross | 61ae0b7 | 2017-12-01 17:16:02 -0800 | [diff] [blame] | 755 | if defaultCert != "" { |
Colin Cross | e1731a5 | 2017-12-14 11:22:55 -0800 | [diff] [blame] | 756 | return PathForSource(ctx, defaultCert+".x509.pem"), PathForSource(ctx, defaultCert+".pk8") |
Colin Cross | 61ae0b7 | 2017-12-01 17:16:02 -0800 | [diff] [blame] | 757 | } else { |
Colin Cross | e1731a5 | 2017-12-14 11:22:55 -0800 | [diff] [blame] | 758 | defaultDir := c.DefaultAppCertificateDir(ctx) |
| 759 | return defaultDir.Join(ctx, "testkey.x509.pem"), defaultDir.Join(ctx, "testkey.pk8") |
Colin Cross | 61ae0b7 | 2017-12-01 17:16:02 -0800 | [diff] [blame] | 760 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 761 | } |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 762 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 763 | func (c *config) ApexKeyDir(ctx ModuleContext) SourcePath { |
| 764 | // TODO(b/121224311): define another variable such as TARGET_APEX_KEY_OVERRIDE |
| 765 | defaultCert := String(c.productVariables.DefaultAppCertificate) |
Dan Willemsen | 412160e | 2019-04-09 21:36:26 -0700 | [diff] [blame] | 766 | if defaultCert == "" || filepath.Dir(defaultCert) == "build/make/target/product/security" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 767 | // When defaultCert is unset or is set to the testkeys path, use the APEX keys |
| 768 | // that is under the module dir |
Colin Cross | 07e5161 | 2019-03-05 12:46:40 -0800 | [diff] [blame] | 769 | return pathForModuleSrc(ctx) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 770 | } else { |
| 771 | // If not, APEX keys are under the specified directory |
| 772 | return PathForSource(ctx, filepath.Dir(defaultCert)) |
| 773 | } |
| 774 | } |
| 775 | |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 776 | func (c *config) AllowMissingDependencies() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 777 | return Bool(c.productVariables.Allow_missing_dependencies) |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 778 | } |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 779 | |
Jeongik Cha | 816a23a | 2020-07-08 01:09:23 +0900 | [diff] [blame] | 780 | // Returns true if a full platform source tree cannot be assumed. |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 781 | func (c *config) UnbundledBuild() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 782 | return Bool(c.productVariables.Unbundled_build) |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Martin Stjernholm | fd9eb4b | 2020-06-17 01:13:15 +0100 | [diff] [blame] | 785 | // Returns true if building apps that aren't bundled with the platform. |
| 786 | // UnbundledBuild() is always true when this is true. |
| 787 | func (c *config) UnbundledBuildApps() bool { |
| 788 | return Bool(c.productVariables.Unbundled_build_apps) |
| 789 | } |
| 790 | |
Jeongik Cha | 816a23a | 2020-07-08 01:09:23 +0900 | [diff] [blame] | 791 | // Returns true if building modules against prebuilt SDKs. |
| 792 | func (c *config) AlwaysUsePrebuiltSdks() bool { |
| 793 | return Bool(c.productVariables.Always_use_prebuilt_sdks) |
Colin Cross | 1f367bf | 2018-12-18 22:46:24 -0800 | [diff] [blame] | 794 | } |
| 795 | |
Paul Duffin | 9a89a2a | 2020-10-28 19:20:06 +0000 | [diff] [blame] | 796 | // Returns true if the boot jars check should be skipped. |
| 797 | func (c *config) SkipBootJarsCheck() bool { |
| 798 | return Bool(c.productVariables.Skip_boot_jars_check) |
| 799 | } |
| 800 | |
Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 801 | func (c *config) Fuchsia() bool { |
| 802 | return Bool(c.productVariables.Fuchsia) |
| 803 | } |
| 804 | |
Colin Cross | 126a25c | 2017-10-31 13:55:34 -0700 | [diff] [blame] | 805 | func (c *config) MinimizeJavaDebugInfo() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 806 | return Bool(c.productVariables.MinimizeJavaDebugInfo) && !Bool(c.productVariables.Eng) |
Colin Cross | 126a25c | 2017-10-31 13:55:34 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Colin Cross | ed064c0 | 2018-09-05 16:28:13 -0700 | [diff] [blame] | 809 | func (c *config) Debuggable() bool { |
| 810 | return Bool(c.productVariables.Debuggable) |
| 811 | } |
| 812 | |
Jaewoong Jung | 1d6eb68 | 2018-11-29 15:08:44 -0800 | [diff] [blame] | 813 | func (c *config) Eng() bool { |
| 814 | return Bool(c.productVariables.Eng) |
| 815 | } |
| 816 | |
Jiyong Park | 8d52f86 | 2018-07-07 18:02:07 +0900 | [diff] [blame] | 817 | func (c *config) DevicePrimaryArchType() ArchType { |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 818 | return c.Targets[Android][0].Arch.ArchType |
Jiyong Park | 8d52f86 | 2018-07-07 18:02:07 +0900 | [diff] [blame] | 819 | } |
| 820 | |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 821 | func (c *config) SkipMegaDeviceInstall(path string) bool { |
| 822 | return Bool(c.Mega_device) && |
| 823 | strings.HasPrefix(path, filepath.Join(c.buildDir, "target", "product")) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 824 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 825 | |
| 826 | func (c *config) SanitizeHost() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 827 | return append([]string(nil), c.productVariables.SanitizeHost...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | func (c *config) SanitizeDevice() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 831 | return append([]string(nil), c.productVariables.SanitizeDevice...) |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 832 | } |
| 833 | |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 834 | func (c *config) SanitizeDeviceDiag() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 835 | return append([]string(nil), c.productVariables.SanitizeDeviceDiag...) |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 838 | func (c *config) SanitizeDeviceArch() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 839 | return append([]string(nil), c.productVariables.SanitizeDeviceArch...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 840 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 841 | |
Vishwath Mohan | 1b017a7 | 2017-01-19 13:54:55 -0800 | [diff] [blame] | 842 | func (c *config) EnableCFI() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 843 | if c.productVariables.EnableCFI == nil { |
Vishwath Mohan | c32c3eb | 2017-01-24 14:20:54 -0800 | [diff] [blame] | 844 | return true |
| 845 | } else { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 846 | return *c.productVariables.EnableCFI |
Vishwath Mohan | c32c3eb | 2017-01-24 14:20:54 -0800 | [diff] [blame] | 847 | } |
Vishwath Mohan | 1b017a7 | 2017-01-19 13:54:55 -0800 | [diff] [blame] | 848 | } |
| 849 | |
Kostya Kortchinsky | d5275c8 | 2019-02-01 08:42:56 -0800 | [diff] [blame] | 850 | func (c *config) DisableScudo() bool { |
| 851 | return Bool(c.productVariables.DisableScudo) |
| 852 | } |
| 853 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 854 | func (c *config) Android64() bool { |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 855 | for _, t := range c.Targets[Android] { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 856 | if t.Arch.ArchType.Multilib == "lib64" { |
| 857 | return true |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | return false |
| 862 | } |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 863 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 864 | func (c *config) UseGoma() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 865 | return Bool(c.productVariables.UseGoma) |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 866 | } |
| 867 | |
Ramy Medhat | bbf2567 | 2019-07-17 12:30:04 +0000 | [diff] [blame] | 868 | func (c *config) UseRBE() bool { |
| 869 | return Bool(c.productVariables.UseRBE) |
| 870 | } |
| 871 | |
Ramy Medhat | 8ea054a | 2020-01-27 14:19:44 -0500 | [diff] [blame] | 872 | func (c *config) UseRBEJAVAC() bool { |
| 873 | return Bool(c.productVariables.UseRBEJAVAC) |
| 874 | } |
| 875 | |
| 876 | func (c *config) UseRBER8() bool { |
| 877 | return Bool(c.productVariables.UseRBER8) |
| 878 | } |
| 879 | |
| 880 | func (c *config) UseRBED8() bool { |
| 881 | return Bool(c.productVariables.UseRBED8) |
| 882 | } |
| 883 | |
Colin Cross | 8b8bec3 | 2019-11-15 13:18:43 -0800 | [diff] [blame] | 884 | func (c *config) UseRemoteBuild() bool { |
| 885 | return c.UseGoma() || c.UseRBE() |
| 886 | } |
| 887 | |
Colin Cross | 6654810 | 2018-06-19 22:47:35 -0700 | [diff] [blame] | 888 | func (c *config) RunErrorProne() bool { |
| 889 | return c.IsEnvTrue("RUN_ERROR_PRONE") |
| 890 | } |
| 891 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 892 | func (c *config) XrefCorpusName() string { |
| 893 | return c.Getenv("XREF_CORPUS") |
| 894 | } |
| 895 | |
Sasha Smundak | 6c2d4f9 | 2020-01-09 17:34:23 -0800 | [diff] [blame] | 896 | // Returns Compilation Unit encoding to use. Can be 'json' (default), 'proto' or 'all'. |
| 897 | func (c *config) XrefCuEncoding() string { |
| 898 | if enc := c.Getenv("KYTHE_KZIP_ENCODING"); enc != "" { |
| 899 | return enc |
| 900 | } |
| 901 | return "json" |
| 902 | } |
| 903 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 904 | func (c *config) EmitXrefRules() bool { |
| 905 | return c.XrefCorpusName() != "" |
| 906 | } |
| 907 | |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 908 | func (c *config) ClangTidy() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 909 | return Bool(c.productVariables.ClangTidy) |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | func (c *config) TidyChecks() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 913 | if c.productVariables.TidyChecks == nil { |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 914 | return "" |
| 915 | } |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 916 | return *c.productVariables.TidyChecks |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Colin Cross | 0f4e0d6 | 2016-07-27 10:56:55 -0700 | [diff] [blame] | 919 | func (c *config) LibartImgHostBaseAddress() string { |
| 920 | return "0x60000000" |
| 921 | } |
| 922 | |
| 923 | func (c *config) LibartImgDeviceBaseAddress() string { |
Elliott Hughes | da3a071 | 2020-03-06 16:55:28 -0800 | [diff] [blame] | 924 | return "0x70000000" |
Colin Cross | 0f4e0d6 | 2016-07-27 10:56:55 -0700 | [diff] [blame] | 925 | } |
| 926 | |
Hiroshi Yamauchi | e2a1063 | 2016-12-19 13:44:41 -0800 | [diff] [blame] | 927 | func (c *config) ArtUseReadBarrier() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 928 | return Bool(c.productVariables.ArtUseReadBarrier) |
Hiroshi Yamauchi | e2a1063 | 2016-12-19 13:44:41 -0800 | [diff] [blame] | 929 | } |
| 930 | |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 931 | func (c *config) EnforceRROForModule(name string) bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 932 | enforceList := c.productVariables.EnforceRROTargets |
Jeongik Cha | b9b1327 | 2020-03-09 12:37:05 +0900 | [diff] [blame] | 933 | // TODO(b/150820813) Some modules depend on static overlay, remove this after eliminating the dependency. |
| 934 | exemptedList := c.productVariables.EnforceRROExemptedTargets |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 935 | if len(exemptedList) > 0 { |
Jeongik Cha | b9b1327 | 2020-03-09 12:37:05 +0900 | [diff] [blame] | 936 | if InList(name, exemptedList) { |
| 937 | return false |
| 938 | } |
| 939 | } |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 940 | if len(enforceList) > 0 { |
Yo Chiang | 4ebd06a | 2019-10-01 13:13:41 +0800 | [diff] [blame] | 941 | if InList("*", enforceList) { |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 942 | return true |
| 943 | } |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 944 | return InList(name, enforceList) |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 945 | } |
| 946 | return false |
| 947 | } |
| 948 | |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 949 | func (c *config) EnforceRROExemptedForModule(name string) bool { |
| 950 | return InList(name, c.productVariables.EnforceRROExemptedTargets) |
| 951 | } |
| 952 | |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 953 | func (c *config) EnforceRROExcludedOverlay(path string) bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 954 | excluded := c.productVariables.EnforceRROExcludedOverlays |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 955 | if len(excluded) > 0 { |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 956 | return HasAnyPrefix(path, excluded) |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 957 | } |
| 958 | return false |
| 959 | } |
| 960 | |
| 961 | func (c *config) ExportedNamespaces() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 962 | return append([]string(nil), c.productVariables.NamespacesToExport...) |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | func (c *config) HostStaticBinaries() bool { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 966 | return Bool(c.productVariables.HostStaticBinaries) |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 967 | } |
| 968 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 969 | func (c *config) UncompressPrivAppDex() bool { |
| 970 | return Bool(c.productVariables.UncompressPrivAppDex) |
| 971 | } |
| 972 | |
| 973 | func (c *config) ModulesLoadedByPrivilegedModules() []string { |
| 974 | return c.productVariables.ModulesLoadedByPrivilegedModules |
| 975 | } |
| 976 | |
Jingwen Chen | ebb0b57 | 2020-11-02 00:24:57 -0500 | [diff] [blame^] | 977 | func (c *config) DexpreoptGlobalConfigPath(ctx PathContext) OptionalPath { |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 978 | if c.productVariables.DexpreoptGlobalConfig == nil { |
Jingwen Chen | ebb0b57 | 2020-11-02 00:24:57 -0500 | [diff] [blame^] | 979 | return OptionalPathForPath(nil) |
| 980 | } |
| 981 | return OptionalPathForPath( |
| 982 | pathForBuildToolDep(ctx, *c.productVariables.DexpreoptGlobalConfig)) |
| 983 | } |
| 984 | |
| 985 | func (c *config) DexpreoptGlobalConfig(ctx PathContext) ([]byte, error) { |
| 986 | path := c.DexpreoptGlobalConfigPath(ctx) |
| 987 | if !path.Valid() { |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 988 | return nil, nil |
| 989 | } |
Jingwen Chen | ebb0b57 | 2020-11-02 00:24:57 -0500 | [diff] [blame^] | 990 | ctx.AddNinjaFileDeps(path.String()) |
| 991 | return ioutil.ReadFile(absolutePath(path.String())) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 992 | } |
| 993 | |
David Brazdil | 91b4e3e | 2019-01-23 21:04:05 +0000 | [diff] [blame] | 994 | func (c *config) FrameworksBaseDirExists(ctx PathContext) bool { |
| 995 | return ExistentPathForSource(ctx, "frameworks", "base").Valid() |
| 996 | } |
| 997 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 998 | func (c *config) VndkSnapshotBuildArtifacts() bool { |
| 999 | return Bool(c.productVariables.VndkSnapshotBuildArtifacts) |
| 1000 | } |
| 1001 | |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 1002 | func (c *config) HasMultilibConflict(arch ArchType) bool { |
| 1003 | return c.multilibConflicts[arch] |
| 1004 | } |
| 1005 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 1006 | func (c *deviceConfig) Arches() []Arch { |
| 1007 | var arches []Arch |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1008 | for _, target := range c.config.Targets[Android] { |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 1009 | arches = append(arches, target.Arch) |
| 1010 | } |
| 1011 | return arches |
| 1012 | } |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 1013 | |
Jayant Chowdhary | 34ce67d | 2018-03-08 11:00:50 -0800 | [diff] [blame] | 1014 | func (c *deviceConfig) BinderBitness() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1015 | is32BitBinder := c.config.productVariables.Binder32bit |
Jayant Chowdhary | 34ce67d | 2018-03-08 11:00:50 -0800 | [diff] [blame] | 1016 | if is32BitBinder != nil && *is32BitBinder { |
| 1017 | return "32" |
| 1018 | } |
| 1019 | return "64" |
| 1020 | } |
| 1021 | |
Dan Willemsen | 4353bc4 | 2016-12-05 17:16:02 -0800 | [diff] [blame] | 1022 | func (c *deviceConfig) VendorPath() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1023 | if c.config.productVariables.VendorPath != nil { |
| 1024 | return *c.config.productVariables.VendorPath |
Dan Willemsen | 4353bc4 | 2016-12-05 17:16:02 -0800 | [diff] [blame] | 1025 | } |
| 1026 | return "vendor" |
| 1027 | } |
| 1028 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 1029 | func (c *deviceConfig) VndkVersion() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1030 | return String(c.config.productVariables.DeviceVndkVersion) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 1031 | } |
| 1032 | |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 1033 | func (c *deviceConfig) CurrentApiLevelForVendorModules() string { |
| 1034 | return StringDefault(c.config.productVariables.DeviceCurrentApiLevelForVendorModules, "current") |
| 1035 | } |
| 1036 | |
Justin Yun | 8fe1212 | 2017-12-07 17:18:15 +0900 | [diff] [blame] | 1037 | func (c *deviceConfig) PlatformVndkVersion() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1038 | return String(c.config.productVariables.Platform_vndk_version) |
Justin Yun | 8fe1212 | 2017-12-07 17:18:15 +0900 | [diff] [blame] | 1039 | } |
| 1040 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 1041 | func (c *deviceConfig) ProductVndkVersion() string { |
| 1042 | return String(c.config.productVariables.ProductVndkVersion) |
| 1043 | } |
| 1044 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 1045 | func (c *deviceConfig) ExtraVndkVersions() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1046 | return c.config.productVariables.ExtraVndkVersions |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 1047 | } |
Jack He | 8cc7143 | 2016-12-08 15:45:07 -0800 | [diff] [blame] | 1048 | |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 1049 | func (c *deviceConfig) VndkUseCoreVariant() bool { |
| 1050 | return Bool(c.config.productVariables.VndkUseCoreVariant) |
| 1051 | } |
| 1052 | |
Jiyong Park | 1a5d7b1 | 2018-01-15 15:05:10 +0900 | [diff] [blame] | 1053 | func (c *deviceConfig) SystemSdkVersions() []string { |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1054 | return c.config.productVariables.DeviceSystemSdkVersions |
Jiyong Park | 1a5d7b1 | 2018-01-15 15:05:10 +0900 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | func (c *deviceConfig) PlatformSystemSdkVersions() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1058 | return c.config.productVariables.Platform_systemsdk_versions |
Jiyong Park | 1a5d7b1 | 2018-01-15 15:05:10 +0900 | [diff] [blame] | 1059 | } |
| 1060 | |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1061 | func (c *deviceConfig) OdmPath() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1062 | if c.config.productVariables.OdmPath != nil { |
| 1063 | return *c.config.productVariables.OdmPath |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1064 | } |
| 1065 | return "odm" |
| 1066 | } |
| 1067 | |
Jaekyun Seok | 5cfbfbb | 2018-01-10 19:00:15 +0900 | [diff] [blame] | 1068 | func (c *deviceConfig) ProductPath() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1069 | if c.config.productVariables.ProductPath != nil { |
| 1070 | return *c.config.productVariables.ProductPath |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1071 | } |
Jaekyun Seok | 5cfbfbb | 2018-01-10 19:00:15 +0900 | [diff] [blame] | 1072 | return "product" |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1073 | } |
| 1074 | |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 1075 | func (c *deviceConfig) SystemExtPath() string { |
| 1076 | if c.config.productVariables.SystemExtPath != nil { |
| 1077 | return *c.config.productVariables.SystemExtPath |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 1078 | } |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 1079 | return "system_ext" |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 1080 | } |
| 1081 | |
Jack He | 8cc7143 | 2016-12-08 15:45:07 -0800 | [diff] [blame] | 1082 | func (c *deviceConfig) BtConfigIncludeDir() string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1083 | return String(c.config.productVariables.BtConfigIncludeDir) |
Jack He | 8cc7143 | 2016-12-08 15:45:07 -0800 | [diff] [blame] | 1084 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1085 | |
Jiyong Park | d773eb3 | 2017-07-03 13:18:12 +0900 | [diff] [blame] | 1086 | func (c *deviceConfig) DeviceKernelHeaderDirs() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1087 | return c.config.productVariables.DeviceKernelHeaders |
Jiyong Park | d773eb3 | 2017-07-03 13:18:12 +0900 | [diff] [blame] | 1088 | } |
| 1089 | |
Yi Kong | ceb5b76 | 2020-03-20 15:22:27 +0800 | [diff] [blame] | 1090 | func (c *deviceConfig) SamplingPGO() bool { |
| 1091 | return Bool(c.config.productVariables.SamplingPGO) |
| 1092 | } |
| 1093 | |
Roland Levillain | ada1270 | 2020-06-09 13:07:36 +0100 | [diff] [blame] | 1094 | // JavaCoverageEnabledForPath returns whether Java code coverage is enabled for |
| 1095 | // path. Coverage is enabled by default when the product variable |
| 1096 | // JavaCoveragePaths is empty. If JavaCoveragePaths is not empty, coverage is |
| 1097 | // enabled for any path which is part of this variable (and not part of the |
| 1098 | // JavaCoverageExcludePaths product variable). Value "*" in JavaCoveragePaths |
| 1099 | // represents any path. |
| 1100 | func (c *deviceConfig) JavaCoverageEnabledForPath(path string) bool { |
| 1101 | coverage := false |
Chris Gross | 2f74869 | 2020-06-24 20:36:59 +0000 | [diff] [blame] | 1102 | if len(c.config.productVariables.JavaCoveragePaths) == 0 || |
Roland Levillain | ada1270 | 2020-06-09 13:07:36 +0100 | [diff] [blame] | 1103 | InList("*", c.config.productVariables.JavaCoveragePaths) || |
| 1104 | HasAnyPrefix(path, c.config.productVariables.JavaCoveragePaths) { |
| 1105 | coverage = true |
| 1106 | } |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 1107 | if coverage && len(c.config.productVariables.JavaCoverageExcludePaths) > 0 { |
Roland Levillain | ada1270 | 2020-06-09 13:07:36 +0100 | [diff] [blame] | 1108 | if HasAnyPrefix(path, c.config.productVariables.JavaCoverageExcludePaths) { |
| 1109 | coverage = false |
| 1110 | } |
| 1111 | } |
| 1112 | return coverage |
| 1113 | } |
| 1114 | |
Colin Cross | 1a6acd4 | 2020-06-16 17:51:46 -0700 | [diff] [blame] | 1115 | // Returns true if gcov or clang coverage is enabled. |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1116 | func (c *deviceConfig) NativeCoverageEnabled() bool { |
Colin Cross | 1a6acd4 | 2020-06-16 17:51:46 -0700 | [diff] [blame] | 1117 | return Bool(c.config.productVariables.GcovCoverage) || |
| 1118 | Bool(c.config.productVariables.ClangCoverage) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1119 | } |
| 1120 | |
Oliver Nguyen | 1382ab6 | 2019-12-06 15:22:41 -0800 | [diff] [blame] | 1121 | func (c *deviceConfig) ClangCoverageEnabled() bool { |
| 1122 | return Bool(c.config.productVariables.ClangCoverage) |
| 1123 | } |
| 1124 | |
Colin Cross | 1a6acd4 | 2020-06-16 17:51:46 -0700 | [diff] [blame] | 1125 | func (c *deviceConfig) GcovCoverageEnabled() bool { |
| 1126 | return Bool(c.config.productVariables.GcovCoverage) |
| 1127 | } |
| 1128 | |
Roland Levillain | 4f5297b | 2020-06-09 12:44:06 +0100 | [diff] [blame] | 1129 | // NativeCoverageEnabledForPath returns whether (GCOV- or Clang-based) native |
| 1130 | // code coverage is enabled for path. By default, coverage is not enabled for a |
| 1131 | // given path unless it is part of the NativeCoveragePaths product variable (and |
| 1132 | // not part of the NativeCoverageExcludePaths product variable). Value "*" in |
| 1133 | // NativeCoveragePaths represents any path. |
| 1134 | func (c *deviceConfig) NativeCoverageEnabledForPath(path string) bool { |
Ryan Campbell | 469a18a | 2017-02-27 09:01:54 -0800 | [diff] [blame] | 1135 | coverage := false |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 1136 | if len(c.config.productVariables.NativeCoveragePaths) > 0 { |
Roland Levillain | 4f5297b | 2020-06-09 12:44:06 +0100 | [diff] [blame] | 1137 | if InList("*", c.config.productVariables.NativeCoveragePaths) || HasAnyPrefix(path, c.config.productVariables.NativeCoveragePaths) { |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 1138 | coverage = true |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1139 | } |
| 1140 | } |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 1141 | if coverage && len(c.config.productVariables.NativeCoverageExcludePaths) > 0 { |
Roland Levillain | 4f5297b | 2020-06-09 12:44:06 +0100 | [diff] [blame] | 1142 | if HasAnyPrefix(path, c.config.productVariables.NativeCoverageExcludePaths) { |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 1143 | coverage = false |
Ryan Campbell | 469a18a | 2017-02-27 09:01:54 -0800 | [diff] [blame] | 1144 | } |
| 1145 | } |
| 1146 | return coverage |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1147 | } |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 1148 | |
Pirama Arumuga Nainar | 4954080 | 2018-01-29 23:11:42 -0800 | [diff] [blame] | 1149 | func (c *deviceConfig) PgoAdditionalProfileDirs() []string { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1150 | return c.config.productVariables.PgoAdditionalProfileDirs |
Pirama Arumuga Nainar | 4954080 | 2018-01-29 23:11:42 -0800 | [diff] [blame] | 1151 | } |
| 1152 | |
Tri Vo | 35a5143 | 2018-03-25 20:00:00 -0700 | [diff] [blame] | 1153 | func (c *deviceConfig) VendorSepolicyDirs() []string { |
| 1154 | return c.config.productVariables.BoardVendorSepolicyDirs |
| 1155 | } |
| 1156 | |
| 1157 | func (c *deviceConfig) OdmSepolicyDirs() []string { |
| 1158 | return c.config.productVariables.BoardOdmSepolicyDirs |
| 1159 | } |
| 1160 | |
Felix | a20a875 | 2020-05-17 18:28:35 +0200 | [diff] [blame] | 1161 | func (c *deviceConfig) SystemExtPublicSepolicyDirs() []string { |
| 1162 | return c.config.productVariables.SystemExtPublicSepolicyDirs |
Tri Vo | 35a5143 | 2018-03-25 20:00:00 -0700 | [diff] [blame] | 1163 | } |
| 1164 | |
Felix | a20a875 | 2020-05-17 18:28:35 +0200 | [diff] [blame] | 1165 | func (c *deviceConfig) SystemExtPrivateSepolicyDirs() []string { |
| 1166 | return c.config.productVariables.SystemExtPrivateSepolicyDirs |
Tri Vo | 35a5143 | 2018-03-25 20:00:00 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
Inseob Kim | 0866b00 | 2019-04-15 20:21:29 +0900 | [diff] [blame] | 1169 | func (c *deviceConfig) SepolicyM4Defs() []string { |
| 1170 | return c.config.productVariables.BoardSepolicyM4Defs |
| 1171 | } |
| 1172 | |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 1173 | func (c *deviceConfig) OverrideManifestPackageNameFor(name string) (manifestName string, overridden bool) { |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1174 | return findOverrideValue(c.config.productVariables.ManifestPackageNameOverrides, name, |
| 1175 | "invalid override rule %q in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES should be <module_name>:<manifest_name>") |
| 1176 | } |
| 1177 | |
| 1178 | func (c *deviceConfig) OverrideCertificateFor(name string) (certificatePath string, overridden bool) { |
Jaewoong Jung | acb6db3 | 2019-02-28 16:22:30 +0000 | [diff] [blame] | 1179 | return findOverrideValue(c.config.productVariables.CertificateOverrides, name, |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1180 | "invalid override rule %q in PRODUCT_CERTIFICATE_OVERRIDES should be <module_name>:<certificate_module_name>") |
| 1181 | } |
| 1182 | |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 1183 | func (c *deviceConfig) OverridePackageNameFor(name string) string { |
| 1184 | newName, overridden := findOverrideValue( |
| 1185 | c.config.productVariables.PackageNameOverrides, |
| 1186 | name, |
| 1187 | "invalid override rule %q in PRODUCT_PACKAGE_NAME_OVERRIDES should be <module_name>:<package_name>") |
| 1188 | if overridden { |
| 1189 | return newName |
| 1190 | } |
| 1191 | return name |
| 1192 | } |
| 1193 | |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1194 | func findOverrideValue(overrides []string, name string, errorMsg string) (newValue string, overridden bool) { |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 1195 | if overrides == nil || len(overrides) == 0 { |
| 1196 | return "", false |
| 1197 | } |
| 1198 | for _, o := range overrides { |
| 1199 | split := strings.Split(o, ":") |
| 1200 | if len(split) != 2 { |
| 1201 | // This shouldn't happen as this is first checked in make, but just in case. |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1202 | panic(fmt.Errorf(errorMsg, o)) |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 1203 | } |
| 1204 | if matchPattern(split[0], name) { |
| 1205 | return substPattern(split[0], split[1], name), true |
| 1206 | } |
| 1207 | } |
| 1208 | return "", false |
| 1209 | } |
| 1210 | |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 1211 | func (c *config) IntegerOverflowDisabledForPath(path string) bool { |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 1212 | if len(c.productVariables.IntegerOverflowExcludePaths) == 0 { |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 1213 | return false |
| 1214 | } |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 1215 | return HasAnyPrefix(path, c.productVariables.IntegerOverflowExcludePaths) |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 1216 | } |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 1217 | |
| 1218 | func (c *config) CFIDisabledForPath(path string) bool { |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 1219 | if len(c.productVariables.CFIExcludePaths) == 0 { |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 1220 | return false |
| 1221 | } |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 1222 | return HasAnyPrefix(path, c.productVariables.CFIExcludePaths) |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | func (c *config) CFIEnabledForPath(path string) bool { |
Roland Levillain | f6cc261 | 2020-07-09 16:58:14 +0100 | [diff] [blame] | 1226 | if len(c.productVariables.CFIIncludePaths) == 0 { |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 1227 | return false |
| 1228 | } |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 1229 | return HasAnyPrefix(path, c.productVariables.CFIIncludePaths) |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 1230 | } |
Colin Cross | e15ddaf | 2017-12-04 11:24:31 -0800 | [diff] [blame] | 1231 | |
Dan Willemsen | 0fe7866 | 2018-03-26 12:41:18 -0700 | [diff] [blame] | 1232 | func (c *config) VendorConfig(name string) VendorConfig { |
Colin Cross | 9d34f35 | 2019-11-22 16:03:51 -0800 | [diff] [blame] | 1233 | return soongconfig.Config(c.productVariables.VendorVars[name]) |
Dan Willemsen | 0fe7866 | 2018-03-26 12:41:18 -0700 | [diff] [blame] | 1234 | } |
| 1235 | |
Colin Cross | 395f2cf | 2018-10-24 16:10:32 -0700 | [diff] [blame] | 1236 | func (c *config) NdkAbis() bool { |
| 1237 | return Bool(c.productVariables.Ndk_abis) |
| 1238 | } |
| 1239 | |
Martin Stjernholm | c1ecc43 | 2019-11-15 15:00:31 +0000 | [diff] [blame] | 1240 | func (c *config) AmlAbis() bool { |
| 1241 | return Bool(c.productVariables.Aml_abis) |
| 1242 | } |
| 1243 | |
Dan Albert | 23d37e0 | 2018-11-28 08:30:10 -0800 | [diff] [blame] | 1244 | func (c *config) ExcludeDraftNdkApis() bool { |
| 1245 | return Bool(c.productVariables.Exclude_draft_ndk_apis) |
| 1246 | } |
| 1247 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1248 | func (c *config) FlattenApex() bool { |
Roland Levillain | a386321 | 2019-08-12 19:56:16 +0100 | [diff] [blame] | 1249 | return Bool(c.productVariables.Flatten_apex) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1250 | } |
| 1251 | |
Jeongik Cha | c946414 | 2019-01-07 12:07:27 +0900 | [diff] [blame] | 1252 | func (c *config) EnforceSystemCertificate() bool { |
| 1253 | return Bool(c.productVariables.EnforceSystemCertificate) |
| 1254 | } |
| 1255 | |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 1256 | func (c *config) EnforceSystemCertificateAllowList() []string { |
| 1257 | return c.productVariables.EnforceSystemCertificateAllowList |
Jeongik Cha | c946414 | 2019-01-07 12:07:27 +0900 | [diff] [blame] | 1258 | } |
| 1259 | |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 1260 | func (c *config) EnforceProductPartitionInterface() bool { |
| 1261 | return Bool(c.productVariables.EnforceProductPartitionInterface) |
| 1262 | } |
| 1263 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 1264 | func (c *config) InstallExtraFlattenedApexes() bool { |
| 1265 | return Bool(c.productVariables.InstallExtraFlattenedApexes) |
| 1266 | } |
| 1267 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 1268 | func (c *config) ProductHiddenAPIStubs() []string { |
| 1269 | return c.productVariables.ProductHiddenAPIStubs |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 1270 | } |
| 1271 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 1272 | func (c *config) ProductHiddenAPIStubsSystem() []string { |
| 1273 | return c.productVariables.ProductHiddenAPIStubsSystem |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 1274 | } |
| 1275 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 1276 | func (c *config) ProductHiddenAPIStubsTest() []string { |
| 1277 | return c.productVariables.ProductHiddenAPIStubsTest |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 1278 | } |
Dan Willemsen | 71c7460 | 2019-04-10 12:27:35 -0700 | [diff] [blame] | 1279 | |
Dan Willemsen | 54879d1 | 2019-04-18 10:08:46 -0700 | [diff] [blame] | 1280 | func (c *deviceConfig) TargetFSConfigGen() []string { |
Dan Willemsen | 71c7460 | 2019-04-10 12:27:35 -0700 | [diff] [blame] | 1281 | return c.config.productVariables.TargetFSConfigGen |
| 1282 | } |
Inseob Kim | 0866b00 | 2019-04-15 20:21:29 +0900 | [diff] [blame] | 1283 | |
| 1284 | func (c *config) ProductPublicSepolicyDirs() []string { |
| 1285 | return c.productVariables.ProductPublicSepolicyDirs |
| 1286 | } |
| 1287 | |
| 1288 | func (c *config) ProductPrivateSepolicyDirs() []string { |
| 1289 | return c.productVariables.ProductPrivateSepolicyDirs |
| 1290 | } |
| 1291 | |
| 1292 | func (c *config) ProductCompatibleProperty() bool { |
| 1293 | return Bool(c.productVariables.ProductCompatibleProperty) |
| 1294 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 1295 | |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 1296 | func (c *config) MissingUsesLibraries() []string { |
| 1297 | return c.productVariables.MissingUsesLibraries |
| 1298 | } |
| 1299 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 1300 | func (c *deviceConfig) DeviceArch() string { |
| 1301 | return String(c.config.productVariables.DeviceArch) |
| 1302 | } |
| 1303 | |
| 1304 | func (c *deviceConfig) DeviceArchVariant() string { |
| 1305 | return String(c.config.productVariables.DeviceArchVariant) |
| 1306 | } |
| 1307 | |
| 1308 | func (c *deviceConfig) DeviceSecondaryArch() string { |
| 1309 | return String(c.config.productVariables.DeviceSecondaryArch) |
| 1310 | } |
| 1311 | |
| 1312 | func (c *deviceConfig) DeviceSecondaryArchVariant() string { |
| 1313 | return String(c.config.productVariables.DeviceSecondaryArchVariant) |
| 1314 | } |
Yifan Hong | 82db735 | 2020-01-21 16:12:26 -0800 | [diff] [blame] | 1315 | |
| 1316 | func (c *deviceConfig) BoardUsesRecoveryAsBoot() bool { |
| 1317 | return Bool(c.config.productVariables.BoardUsesRecoveryAsBoot) |
| 1318 | } |
Yifan Hong | 97365ee | 2020-07-29 09:51:57 -0700 | [diff] [blame] | 1319 | |
| 1320 | func (c *deviceConfig) BoardKernelBinaries() []string { |
| 1321 | return c.config.productVariables.BoardKernelBinaries |
| 1322 | } |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1323 | |
Yifan Hong | 42bef8d | 2020-08-05 14:36:09 -0700 | [diff] [blame] | 1324 | func (c *deviceConfig) BoardKernelModuleInterfaceVersions() []string { |
| 1325 | return c.config.productVariables.BoardKernelModuleInterfaceVersions |
| 1326 | } |
| 1327 | |
Yifan Hong | dd8dacc | 2020-10-21 15:40:17 -0700 | [diff] [blame] | 1328 | func (c *deviceConfig) BoardMoveRecoveryResourcesToVendorBoot() bool { |
| 1329 | return Bool(c.config.productVariables.BoardMoveRecoveryResourcesToVendorBoot) |
| 1330 | } |
| 1331 | |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1332 | // The ConfiguredJarList struct provides methods for handling a list of (apex, jar) pairs. |
| 1333 | // Such lists are used in the build system for things like bootclasspath jars or system server jars. |
| 1334 | // The apex part is either an apex name, or a special names "platform" or "system_ext". Jar is a |
| 1335 | // module name. The pairs come from Make product variables as a list of colon-separated strings. |
| 1336 | // |
| 1337 | // Examples: |
| 1338 | // - "com.android.art:core-oj" |
| 1339 | // - "platform:framework" |
| 1340 | // - "system_ext:foo" |
| 1341 | // |
| 1342 | type ConfiguredJarList struct { |
| 1343 | apexes []string // A list of apex components. |
| 1344 | jars []string // A list of jar components. |
| 1345 | } |
| 1346 | |
| 1347 | // The length of the list. |
| 1348 | func (l *ConfiguredJarList) Len() int { |
| 1349 | return len(l.jars) |
| 1350 | } |
| 1351 | |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1352 | // Jar component of idx-th pair on the list. |
| 1353 | func (l *ConfiguredJarList) Jar(idx int) string { |
| 1354 | return l.jars[idx] |
| 1355 | } |
| 1356 | |
Paul Duffin | 9a89a2a | 2020-10-28 19:20:06 +0000 | [diff] [blame] | 1357 | // Apex component of idx-th pair on the list. |
| 1358 | func (l *ConfiguredJarList) Apex(idx int) string { |
| 1359 | return l.apexes[idx] |
| 1360 | } |
| 1361 | |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1362 | // If the list contains a pair with the given jar. |
| 1363 | func (l *ConfiguredJarList) ContainsJar(jar string) bool { |
| 1364 | return InList(jar, l.jars) |
| 1365 | } |
| 1366 | |
| 1367 | // If the list contains the given (apex, jar) pair. |
| 1368 | func (l *ConfiguredJarList) containsApexJarPair(apex, jar string) bool { |
| 1369 | for i := 0; i < l.Len(); i++ { |
Paul Duffin | 1e8c607 | 2020-10-23 18:28:55 +0100 | [diff] [blame] | 1370 | if apex == l.apexes[i] && jar == l.jars[i] { |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1371 | return true |
| 1372 | } |
| 1373 | } |
| 1374 | return false |
| 1375 | } |
| 1376 | |
| 1377 | // Index of the first pair with the given jar on the list, or -1 if none. |
| 1378 | func (l *ConfiguredJarList) IndexOfJar(jar string) int { |
| 1379 | return IndexList(jar, l.jars) |
| 1380 | } |
| 1381 | |
Paul Duffin | 7d584e9 | 2020-10-23 18:26:03 +0100 | [diff] [blame] | 1382 | func copyAndAppend(list []string, item string) []string { |
| 1383 | // Create the result list to be 1 longer than the input. |
| 1384 | result := make([]string, len(list)+1) |
| 1385 | |
| 1386 | // Copy the whole input list into the result. |
| 1387 | count := copy(result, list) |
| 1388 | |
| 1389 | // Insert the extra item at the end. |
| 1390 | result[count] = item |
| 1391 | |
| 1392 | return result |
| 1393 | } |
| 1394 | |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1395 | // Append an (apex, jar) pair to the list. |
Paul Duffin | 7d584e9 | 2020-10-23 18:26:03 +0100 | [diff] [blame] | 1396 | func (l *ConfiguredJarList) Append(apex string, jar string) ConfiguredJarList { |
| 1397 | // Create a copy of the backing arrays before appending to avoid sharing backing |
| 1398 | // arrays that are mutated across instances. |
| 1399 | apexes := copyAndAppend(l.apexes, apex) |
| 1400 | jars := copyAndAppend(l.jars, jar) |
| 1401 | |
| 1402 | return ConfiguredJarList{apexes, jars} |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | // Filter out sublist. |
Paul Duffin | 7d584e9 | 2020-10-23 18:26:03 +0100 | [diff] [blame] | 1406 | func (l *ConfiguredJarList) RemoveList(list ConfiguredJarList) ConfiguredJarList { |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1407 | apexes := make([]string, 0, l.Len()) |
| 1408 | jars := make([]string, 0, l.Len()) |
| 1409 | |
| 1410 | for i, jar := range l.jars { |
Paul Duffin | 1e8c607 | 2020-10-23 18:28:55 +0100 | [diff] [blame] | 1411 | apex := l.apexes[i] |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1412 | if !list.containsApexJarPair(apex, jar) { |
| 1413 | apexes = append(apexes, apex) |
| 1414 | jars = append(jars, jar) |
| 1415 | } |
| 1416 | } |
| 1417 | |
Paul Duffin | 7d584e9 | 2020-10-23 18:26:03 +0100 | [diff] [blame] | 1418 | return ConfiguredJarList{apexes, jars} |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | // A copy of the list of strings containing jar components. |
| 1422 | func (l *ConfiguredJarList) CopyOfJars() []string { |
| 1423 | return CopyOf(l.jars) |
| 1424 | } |
| 1425 | |
| 1426 | // A copy of the list of strings with colon-separated (apex, jar) pairs. |
| 1427 | func (l *ConfiguredJarList) CopyOfApexJarPairs() []string { |
| 1428 | pairs := make([]string, 0, l.Len()) |
| 1429 | |
| 1430 | for i, jar := range l.jars { |
Paul Duffin | 1e8c607 | 2020-10-23 18:28:55 +0100 | [diff] [blame] | 1431 | apex := l.apexes[i] |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1432 | pairs = append(pairs, apex+":"+jar) |
| 1433 | } |
| 1434 | |
| 1435 | return pairs |
| 1436 | } |
| 1437 | |
| 1438 | // A list of build paths based on the given directory prefix. |
| 1439 | func (l *ConfiguredJarList) BuildPaths(ctx PathContext, dir OutputPath) WritablePaths { |
| 1440 | paths := make(WritablePaths, l.Len()) |
| 1441 | for i, jar := range l.jars { |
| 1442 | paths[i] = dir.Join(ctx, ModuleStem(jar)+".jar") |
| 1443 | } |
| 1444 | return paths |
| 1445 | } |
| 1446 | |
Paul Duffin | 69d1fb1 | 2020-10-23 21:14:20 +0100 | [diff] [blame] | 1447 | // Called when loading configuration from JSON into a configuration structure. |
| 1448 | func (l *ConfiguredJarList) UnmarshalJSON(b []byte) error { |
| 1449 | // Try and unmarshal into a []string each item of which contains a pair |
| 1450 | // <apex>:<jar>. |
| 1451 | var list []string |
| 1452 | err := json.Unmarshal(b, &list) |
| 1453 | if err != nil { |
| 1454 | // Did not work so return |
| 1455 | return err |
| 1456 | } |
| 1457 | |
| 1458 | apexes, jars, err := splitListOfPairsIntoPairOfLists(list) |
| 1459 | if err != nil { |
| 1460 | return err |
| 1461 | } |
| 1462 | l.apexes = apexes |
| 1463 | l.jars = jars |
| 1464 | return nil |
| 1465 | } |
| 1466 | |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1467 | func ModuleStem(module string) string { |
| 1468 | // b/139391334: the stem of framework-minus-apex is framework. This is hard coded here until we |
| 1469 | // find a good way to query the stem of a module before any other mutators are run. |
| 1470 | if module == "framework-minus-apex" { |
| 1471 | return "framework" |
| 1472 | } |
| 1473 | return module |
| 1474 | } |
| 1475 | |
| 1476 | // A list of on-device paths. |
| 1477 | func (l *ConfiguredJarList) DevicePaths(cfg Config, ostype OsType) []string { |
| 1478 | paths := make([]string, l.Len()) |
| 1479 | for i, jar := range l.jars { |
| 1480 | apex := l.apexes[i] |
| 1481 | name := ModuleStem(jar) + ".jar" |
| 1482 | |
| 1483 | var subdir string |
| 1484 | if apex == "platform" { |
| 1485 | subdir = "system/framework" |
| 1486 | } else if apex == "system_ext" { |
| 1487 | subdir = "system_ext/framework" |
| 1488 | } else { |
| 1489 | subdir = filepath.Join("apex", apex, "javalib") |
| 1490 | } |
| 1491 | |
| 1492 | if ostype.Class == Host { |
| 1493 | paths[i] = filepath.Join(cfg.Getenv("OUT_DIR"), "host", cfg.PrebuiltOS(), subdir, name) |
| 1494 | } else { |
| 1495 | paths[i] = filepath.Join("/", subdir, name) |
| 1496 | } |
| 1497 | } |
| 1498 | return paths |
| 1499 | } |
| 1500 | |
Paul Duffin | 7d584e9 | 2020-10-23 18:26:03 +0100 | [diff] [blame] | 1501 | func (l *ConfiguredJarList) String() string { |
| 1502 | var pairs []string |
| 1503 | for i := 0; i < l.Len(); i++ { |
| 1504 | pairs = append(pairs, l.apexes[i]+":"+l.jars[i]) |
| 1505 | } |
| 1506 | return strings.Join(pairs, ",") |
| 1507 | } |
| 1508 | |
Paul Duffin | 0141660 | 2020-10-23 21:04:03 +0100 | [diff] [blame] | 1509 | func splitListOfPairsIntoPairOfLists(list []string) ([]string, []string, error) { |
| 1510 | // Now we need to populate this list by splitting each item in the slice of |
| 1511 | // pairs and appending them to the appropriate list of apexes or jars. |
| 1512 | apexes := make([]string, len(list)) |
| 1513 | jars := make([]string, len(list)) |
| 1514 | |
| 1515 | for i, apexjar := range list { |
| 1516 | apex, jar, err := splitConfiguredJarPair(apexjar) |
| 1517 | if err != nil { |
| 1518 | return nil, nil, err |
| 1519 | } |
| 1520 | apexes[i] = apex |
| 1521 | jars[i] = jar |
| 1522 | } |
| 1523 | |
| 1524 | return apexes, jars, nil |
| 1525 | } |
| 1526 | |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1527 | // Expected format for apexJarValue = <apex name>:<jar name> |
Paul Duffin | 0141660 | 2020-10-23 21:04:03 +0100 | [diff] [blame] | 1528 | func splitConfiguredJarPair(str string) (string, string, error) { |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1529 | pair := strings.SplitN(str, ":", 2) |
| 1530 | if len(pair) == 2 { |
Paul Duffin | 0141660 | 2020-10-23 21:04:03 +0100 | [diff] [blame] | 1531 | return pair[0], pair[1], nil |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1532 | } else { |
Paul Duffin | 0141660 | 2020-10-23 21:04:03 +0100 | [diff] [blame] | 1533 | return "error-apex", "error-jar", fmt.Errorf("malformed (apex, jar) pair: '%s', expected format: <apex>:<jar>", str) |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1534 | } |
| 1535 | } |
| 1536 | |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 1537 | func CreateTestConfiguredJarList(list []string) ConfiguredJarList { |
Paul Duffin | 0141660 | 2020-10-23 21:04:03 +0100 | [diff] [blame] | 1538 | apexes, jars, err := splitListOfPairsIntoPairOfLists(list) |
| 1539 | if err != nil { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 1540 | panic(err) |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1541 | } |
| 1542 | |
Paul Duffin | 0141660 | 2020-10-23 21:04:03 +0100 | [diff] [blame] | 1543 | return ConfiguredJarList{apexes, jars} |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | func EmptyConfiguredJarList() ConfiguredJarList { |
| 1547 | return ConfiguredJarList{} |
| 1548 | } |
| 1549 | |
| 1550 | var earlyBootJarsKey = NewOnceKey("earlyBootJars") |
| 1551 | |
| 1552 | func (c *config) BootJars() []string { |
| 1553 | return c.Once(earlyBootJarsKey, func() interface{} { |
Paul Duffin | 69d1fb1 | 2020-10-23 21:14:20 +0100 | [diff] [blame] | 1554 | list := c.productVariables.BootJars.CopyOfJars() |
| 1555 | list = append(list, c.productVariables.UpdatableBootJars.CopyOfJars()...) |
| 1556 | return list |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 1557 | }).([]string) |
| 1558 | } |
Paul Duffin | 9a89a2a | 2020-10-28 19:20:06 +0000 | [diff] [blame] | 1559 | |
| 1560 | func (c *config) NonUpdatableBootJars() ConfiguredJarList { |
| 1561 | return c.productVariables.BootJars |
| 1562 | } |
| 1563 | |
| 1564 | func (c *config) UpdatableBootJars() ConfiguredJarList { |
| 1565 | return c.productVariables.UpdatableBootJars |
| 1566 | } |