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