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