| 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 | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 18 | "encoding" | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 19 | "fmt" | 
|  | 20 | "reflect" | 
|  | 21 | "runtime" | 
|  | 22 | "strings" | 
| Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 23 |  | 
| Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 24 | "github.com/google/blueprint" | 
| Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 25 | "github.com/google/blueprint/bootstrap" | 
| Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 26 | "github.com/google/blueprint/proptools" | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 27 | ) | 
|  | 28 |  | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 29 | /* | 
|  | 30 | Example blueprints file containing all variant property groups, with comment listing what type | 
|  | 31 | of variants get properties in that group: | 
|  | 32 |  | 
|  | 33 | module { | 
|  | 34 | arch: { | 
|  | 35 | arm: { | 
|  | 36 | // Host or device variants with arm architecture | 
|  | 37 | }, | 
|  | 38 | arm64: { | 
|  | 39 | // Host or device variants with arm64 architecture | 
|  | 40 | }, | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 41 | x86: { | 
|  | 42 | // Host or device variants with x86 architecture | 
|  | 43 | }, | 
|  | 44 | x86_64: { | 
|  | 45 | // Host or device variants with x86_64 architecture | 
|  | 46 | }, | 
|  | 47 | }, | 
|  | 48 | multilib: { | 
|  | 49 | lib32: { | 
|  | 50 | // Host or device variants for 32-bit architectures | 
|  | 51 | }, | 
|  | 52 | lib64: { | 
|  | 53 | // Host or device variants for 64-bit architectures | 
|  | 54 | }, | 
|  | 55 | }, | 
|  | 56 | target: { | 
|  | 57 | android: { | 
| Martin Stjernholm | e284b48 | 2020-09-23 21:03:27 +0100 | [diff] [blame] | 58 | // Device variants (implies Bionic) | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 59 | }, | 
|  | 60 | host: { | 
|  | 61 | // Host variants | 
|  | 62 | }, | 
| Martin Stjernholm | e284b48 | 2020-09-23 21:03:27 +0100 | [diff] [blame] | 63 | bionic: { | 
|  | 64 | // Bionic (device and host) variants | 
|  | 65 | }, | 
|  | 66 | linux_bionic: { | 
|  | 67 | // Bionic host variants | 
|  | 68 | }, | 
|  | 69 | linux: { | 
|  | 70 | // Bionic (device and host) and Linux glibc variants | 
|  | 71 | }, | 
| Dan Willemsen | 5746bd4 | 2017-10-02 19:42:01 -0700 | [diff] [blame] | 72 | linux_glibc: { | 
| Martin Stjernholm | e284b48 | 2020-09-23 21:03:27 +0100 | [diff] [blame] | 73 | // Linux host variants (using non-Bionic libc) | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 74 | }, | 
|  | 75 | darwin: { | 
|  | 76 | // Darwin host variants | 
|  | 77 | }, | 
|  | 78 | windows: { | 
|  | 79 | // Windows host variants | 
|  | 80 | }, | 
|  | 81 | not_windows: { | 
|  | 82 | // Non-windows host variants | 
|  | 83 | }, | 
| Martin Stjernholm | e284b48 | 2020-09-23 21:03:27 +0100 | [diff] [blame] | 84 | android_arm: { | 
|  | 85 | // Any <os>_<arch> combination restricts to that os and arch | 
|  | 86 | }, | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 87 | }, | 
|  | 88 | } | 
|  | 89 | */ | 
| Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 90 |  | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 91 | // An Arch indicates a single CPU architecture. | 
|  | 92 | type Arch struct { | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 93 | // The type of the architecture (arm, arm64, x86, or x86_64). | 
|  | 94 | ArchType ArchType | 
|  | 95 |  | 
|  | 96 | // The variant of the architecture, for example "armv7-a" or "armv7-a-neon" for arm. | 
|  | 97 | ArchVariant string | 
|  | 98 |  | 
|  | 99 | // The variant of the CPU, for example "cortex-a53" for arm64. | 
|  | 100 | CpuVariant string | 
|  | 101 |  | 
|  | 102 | // The list of Android app ABIs supported by the CPU architecture, for example "arm64-v8a". | 
|  | 103 | Abi []string | 
|  | 104 |  | 
|  | 105 | // The list of arch-specific features supported by the CPU architecture, for example "neon". | 
| Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 106 | ArchFeatures []string | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 107 | } | 
|  | 108 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 109 | // String returns the Arch as a string.  The value is used as the name of the variant created | 
|  | 110 | // by archMutator. | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 111 | func (a Arch) String() string { | 
| Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 112 | s := a.ArchType.String() | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 113 | if a.ArchVariant != "" { | 
|  | 114 | s += "_" + a.ArchVariant | 
|  | 115 | } | 
|  | 116 | if a.CpuVariant != "" { | 
|  | 117 | s += "_" + a.CpuVariant | 
|  | 118 | } | 
|  | 119 | return s | 
|  | 120 | } | 
|  | 121 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 122 | // ArchType is used to define the 4 supported architecture types (arm, arm64, x86, x86_64), as | 
|  | 123 | // well as the "common" architecture used for modules that support multiple architectures, for | 
|  | 124 | // example Java modules. | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 125 | type ArchType struct { | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 126 | // Name is the name of the architecture type, "arm", "arm64", "x86", or "x86_64". | 
|  | 127 | Name string | 
|  | 128 |  | 
|  | 129 | // Field is the name of the field used in properties that refer to the architecture, e.g. "Arm64". | 
|  | 130 | Field string | 
|  | 131 |  | 
|  | 132 | // Multilib is either "lib32" or "lib64" for 32-bit or 64-bit architectures. | 
| Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 133 | Multilib string | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 134 | } | 
|  | 135 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 136 | // String returns the name of the ArchType. | 
|  | 137 | func (a ArchType) String() string { | 
|  | 138 | return a.Name | 
|  | 139 | } | 
|  | 140 |  | 
|  | 141 | const COMMON_VARIANT = "common" | 
|  | 142 |  | 
|  | 143 | var ( | 
|  | 144 | archTypeList []ArchType | 
|  | 145 |  | 
|  | 146 | Arm    = newArch("arm", "lib32") | 
|  | 147 | Arm64  = newArch("arm64", "lib64") | 
|  | 148 | X86    = newArch("x86", "lib32") | 
|  | 149 | X86_64 = newArch("x86_64", "lib64") | 
|  | 150 |  | 
|  | 151 | Common = ArchType{ | 
|  | 152 | Name: COMMON_VARIANT, | 
|  | 153 | } | 
|  | 154 | ) | 
|  | 155 |  | 
|  | 156 | var archTypeMap = map[string]ArchType{} | 
|  | 157 |  | 
| Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 158 | func newArch(name, multilib string) ArchType { | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 159 | archType := ArchType{ | 
| Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 160 | Name:     name, | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 161 | Field:    proptools.FieldNameForProperty(name), | 
| Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 162 | Multilib: multilib, | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 163 | } | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 164 | archTypeList = append(archTypeList, archType) | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 165 | archTypeMap[name] = archType | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 166 | return archType | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 167 | } | 
|  | 168 |  | 
| Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 169 | // ArchTypeList returns the a slice copy of the 4 supported ArchTypes for arm, | 
|  | 170 | // arm64, x86 and x86_64. | 
| Jaewoong Jung | 1ce9ac6 | 2019-08-13 14:11:33 -0700 | [diff] [blame] | 171 | func ArchTypeList() []ArchType { | 
|  | 172 | return append([]ArchType(nil), archTypeList...) | 
|  | 173 | } | 
|  | 174 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 175 | // MarshalText allows an ArchType to be serialized through any encoder that supports | 
|  | 176 | // encoding.TextMarshaler. | 
| Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 177 | func (a ArchType) MarshalText() ([]byte, error) { | 
| Jeongik Cha | bec4d03 | 2021-04-15 08:55:38 +0900 | [diff] [blame] | 178 | return []byte(a.String()), nil | 
| Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 179 | } | 
|  | 180 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 181 | var _ encoding.TextMarshaler = ArchType{} | 
| Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 182 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 183 | // UnmarshalText allows an ArchType to be deserialized through any decoder that supports | 
|  | 184 | // encoding.TextUnmarshaler. | 
| Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 185 | func (a *ArchType) UnmarshalText(text []byte) error { | 
|  | 186 | if u, ok := archTypeMap[string(text)]; ok { | 
|  | 187 | *a = u | 
|  | 188 | return nil | 
|  | 189 | } | 
|  | 190 |  | 
|  | 191 | return fmt.Errorf("unknown ArchType %q", text) | 
|  | 192 | } | 
|  | 193 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 194 | var _ encoding.TextUnmarshaler = &ArchType{} | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 195 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 196 | // OsClass is an enum that describes whether a variant of a module runs on the host, on the device, | 
|  | 197 | // or is generic. | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 198 | type OsClass int | 
|  | 199 |  | 
|  | 200 | const ( | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 201 | // Generic is used for variants of modules that are not OS-specific. | 
| Dan Willemsen | 0e2d97b | 2016-11-28 17:50:06 -0800 | [diff] [blame] | 202 | Generic OsClass = iota | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 203 | // Device is used for variants of modules that run on the device. | 
| Dan Willemsen | 0e2d97b | 2016-11-28 17:50:06 -0800 | [diff] [blame] | 204 | Device | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 205 | // Host is used for variants of modules that run on the host. | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 206 | Host | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 207 | ) | 
|  | 208 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 209 | // String returns the OsClass as a string. | 
| Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 210 | func (class OsClass) String() string { | 
|  | 211 | switch class { | 
|  | 212 | case Generic: | 
|  | 213 | return "generic" | 
|  | 214 | case Device: | 
|  | 215 | return "device" | 
|  | 216 | case Host: | 
|  | 217 | return "host" | 
| Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 218 | default: | 
|  | 219 | panic(fmt.Errorf("unknown class %d", class)) | 
|  | 220 | } | 
|  | 221 | } | 
|  | 222 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 223 | // OsType describes an OS variant of a module. | 
|  | 224 | type OsType struct { | 
|  | 225 | // Name is the name of the OS.  It is also used as the name of the property in Android.bp | 
|  | 226 | // files. | 
|  | 227 | Name string | 
|  | 228 |  | 
|  | 229 | // Field is the name of the OS converted to an exported field name, i.e. with the first | 
|  | 230 | // character capitalized. | 
|  | 231 | Field string | 
|  | 232 |  | 
|  | 233 | // Class is the OsClass of the OS. | 
|  | 234 | Class OsClass | 
|  | 235 |  | 
|  | 236 | // DefaultDisabled is set when the module variants for the OS should not be created unless | 
|  | 237 | // the module explicitly requests them.  This is used to limit Windows cross compilation to | 
|  | 238 | // only modules that need it. | 
|  | 239 | DefaultDisabled bool | 
|  | 240 | } | 
|  | 241 |  | 
|  | 242 | // String returns the name of the OsType. | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 243 | func (os OsType) String() string { | 
|  | 244 | return os.Name | 
| Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 245 | } | 
|  | 246 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 247 | // Bionic returns true if the OS uses the Bionic libc runtime, i.e. if the OS is Android or | 
|  | 248 | // is Linux with Bionic. | 
| Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 249 | func (os OsType) Bionic() bool { | 
|  | 250 | return os == Android || os == LinuxBionic | 
|  | 251 | } | 
|  | 252 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 253 | // Linux returns true if the OS uses the Linux kernel, i.e. if the OS is Android or is Linux | 
|  | 254 | // with or without the Bionic libc runtime. | 
| Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 255 | func (os OsType) Linux() bool { | 
|  | 256 | return os == Android || os == Linux || os == LinuxBionic | 
|  | 257 | } | 
|  | 258 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 259 | // newOsType constructs an OsType and adds it to the global lists. | 
|  | 260 | func newOsType(name string, class OsClass, defDisabled bool, archTypes ...ArchType) OsType { | 
|  | 261 | checkCalledFromInit() | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 262 | os := OsType{ | 
|  | 263 | Name:  name, | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 264 | Field: proptools.FieldNameForProperty(name), | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 265 | Class: class, | 
| Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 266 |  | 
|  | 267 | DefaultDisabled: defDisabled, | 
| Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 268 | } | 
| Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 269 | osTypeList = append(osTypeList, os) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 270 |  | 
|  | 271 | if _, found := commonTargetMap[name]; found { | 
|  | 272 | panic(fmt.Errorf("Found Os type duplicate during OsType registration: %q", name)) | 
|  | 273 | } else { | 
| Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 274 | commonTargetMap[name] = Target{Os: os, Arch: CommonArch} | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 275 | } | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 276 | osArchTypeMap[os] = archTypes | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 277 |  | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 278 | return os | 
|  | 279 | } | 
|  | 280 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 281 | // osByName returns the OsType that has the given name, or NoOsType if none match. | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 282 | func osByName(name string) OsType { | 
| Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 283 | for _, os := range osTypeList { | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 284 | if os.Name == name { | 
|  | 285 | return os | 
|  | 286 | } | 
|  | 287 | } | 
|  | 288 |  | 
|  | 289 | return NoOsType | 
| Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 290 | } | 
|  | 291 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 292 | // BuildOs returns the OsType for the OS that the build is running on. | 
|  | 293 | var BuildOs = func() OsType { | 
|  | 294 | switch runtime.GOOS { | 
|  | 295 | case "linux": | 
|  | 296 | return Linux | 
|  | 297 | case "darwin": | 
|  | 298 | return Darwin | 
|  | 299 | default: | 
|  | 300 | panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS)) | 
|  | 301 | } | 
|  | 302 | }() | 
| dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 303 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 304 | // BuildArch returns the ArchType for the CPU that the build is running on. | 
|  | 305 | var BuildArch = func() ArchType { | 
|  | 306 | switch runtime.GOARCH { | 
|  | 307 | case "amd64": | 
|  | 308 | return X86_64 | 
|  | 309 | default: | 
|  | 310 | panic(fmt.Sprintf("unsupported Arch: %s", runtime.GOARCH)) | 
|  | 311 | } | 
|  | 312 | }() | 
|  | 313 |  | 
|  | 314 | var ( | 
| Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 315 | // osTypeList contains a list of all the supported OsTypes, including ones not supported | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 316 | // by the current build host or the target device. | 
| Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 317 | osTypeList []OsType | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 318 | // commonTargetMap maps names of OsTypes to the corresponding common Target, i.e. the | 
|  | 319 | // Target with the same OsType and the common ArchType. | 
|  | 320 | commonTargetMap = make(map[string]Target) | 
|  | 321 | // osArchTypeMap maps OsTypes to the list of supported ArchTypes for that OS. | 
|  | 322 | osArchTypeMap = map[OsType][]ArchType{} | 
|  | 323 |  | 
|  | 324 | // NoOsType is a placeholder for when no OS is needed. | 
|  | 325 | NoOsType OsType | 
|  | 326 | // Linux is the OS for the Linux kernel plus the glibc runtime. | 
|  | 327 | Linux = newOsType("linux_glibc", Host, false, X86, X86_64) | 
|  | 328 | // Darwin is the OS for MacOS/Darwin host machines. | 
|  | 329 | Darwin = newOsType("darwin", Host, false, X86_64) | 
|  | 330 | // LinuxBionic is the OS for the Linux kernel plus the Bionic libc runtime, but without the | 
|  | 331 | // rest of Android. | 
|  | 332 | LinuxBionic = newOsType("linux_bionic", Host, false, Arm64, X86_64) | 
|  | 333 | // Windows the OS for Windows host machines. | 
|  | 334 | Windows = newOsType("windows", Host, true, X86, X86_64) | 
|  | 335 | // Android is the OS for target devices that run all of Android, including the Linux kernel | 
|  | 336 | // and the Bionic libc runtime. | 
|  | 337 | Android = newOsType("android", Device, false, Arm, Arm64, X86, X86_64) | 
|  | 338 | // Fuchsia is the OS for target devices that run Fuchsia. | 
|  | 339 | Fuchsia = newOsType("fuchsia", Device, false, Arm64, X86_64) | 
|  | 340 |  | 
|  | 341 | // CommonOS is a pseudo OSType for a common OS variant, which is OsType agnostic and which | 
|  | 342 | // has dependencies on all the OS variants. | 
|  | 343 | CommonOS = newOsType("common_os", Generic, false) | 
| Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 344 |  | 
|  | 345 | // CommonArch is the Arch for all modules that are os-specific but not arch specific, | 
|  | 346 | // for example most Java modules. | 
|  | 347 | CommonArch = Arch{ArchType: Common} | 
| dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 348 | ) | 
|  | 349 |  | 
| Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 350 | // OsTypeList returns a slice copy of the supported OsTypes. | 
|  | 351 | func OsTypeList() []OsType { | 
|  | 352 | return append([]OsType(nil), osTypeList...) | 
|  | 353 | } | 
|  | 354 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 355 | // Target specifies the OS and architecture that a module is being compiled for. | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 356 | type Target struct { | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 357 | // Os the OS that the module is being compiled for (e.g. "linux_glibc", "android"). | 
|  | 358 | Os OsType | 
|  | 359 | // Arch is the architecture that the module is being compiled for. | 
|  | 360 | Arch Arch | 
|  | 361 | // NativeBridge is NativeBridgeEnabled if the architecture is supported using NativeBridge | 
|  | 362 | // (i.e. arm on x86) for this device. | 
|  | 363 | NativeBridge NativeBridgeSupport | 
|  | 364 | // NativeBridgeHostArchName is the name of the real architecture that is used to implement | 
|  | 365 | // the NativeBridge architecture.  For example, for arm on x86 this would be "x86". | 
| dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 366 | NativeBridgeHostArchName string | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 367 | // NativeBridgeRelativePath is the name of the subdirectory that will contain NativeBridge | 
|  | 368 | // libraries and binaries. | 
| dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 369 | NativeBridgeRelativePath string | 
| Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 370 |  | 
|  | 371 | // HostCross is true when the target cannot run natively on the current build host. | 
|  | 372 | // For example, linux_glibc_x86 returns true on a regular x86/i686/Linux machines, but returns false | 
|  | 373 | // on Mac (different OS), or on 64-bit only i686/Linux machines (unsupported arch). | 
|  | 374 | HostCross bool | 
| Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 375 | } | 
|  | 376 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 377 | // NativeBridgeSupport is an enum that specifies if a Target supports NativeBridge. | 
|  | 378 | type NativeBridgeSupport bool | 
|  | 379 |  | 
|  | 380 | const ( | 
|  | 381 | NativeBridgeDisabled NativeBridgeSupport = false | 
|  | 382 | NativeBridgeEnabled  NativeBridgeSupport = true | 
|  | 383 | ) | 
|  | 384 |  | 
|  | 385 | // String returns the OS and arch variations used for the Target. | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 386 | func (target Target) String() string { | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 387 | return target.OsVariation() + "_" + target.ArchVariation() | 
|  | 388 | } | 
|  | 389 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 390 | // OsVariation returns the name of the variation used by the osMutator for the Target. | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 391 | func (target Target) OsVariation() string { | 
|  | 392 | return target.Os.String() | 
| Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 393 | } | 
|  | 394 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 395 | // ArchVariation returns the name of the variation used by the archMutator for the Target. | 
| Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 396 | func (target Target) ArchVariation() string { | 
|  | 397 | var variation string | 
| dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 398 | if target.NativeBridge { | 
| Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 399 | variation = "native_bridge_" | 
| dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 400 | } | 
| Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 401 | variation += target.Arch.String() | 
|  | 402 |  | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 403 | return variation | 
| Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 404 | } | 
|  | 405 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 406 | // Variations returns a list of blueprint.Variations for the osMutator and archMutator for the | 
|  | 407 | // Target. | 
| Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 408 | func (target Target) Variations() []blueprint.Variation { | 
|  | 409 | return []blueprint.Variation{ | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 410 | {Mutator: "os", Variation: target.OsVariation()}, | 
| Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 411 | {Mutator: "arch", Variation: target.ArchVariation()}, | 
|  | 412 | } | 
| Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 413 | } | 
|  | 414 |  | 
| Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 415 | func registerBp2buildArchPathDepsMutator(ctx RegisterMutatorsContext) { | 
|  | 416 | ctx.BottomUp("bp2build-arch-pathdeps", bp2buildArchPathDepsMutator).Parallel() | 
|  | 417 | } | 
|  | 418 |  | 
|  | 419 | // add dependencies for architecture specific properties tagged with `android:"path"` | 
|  | 420 | func bp2buildArchPathDepsMutator(ctx BottomUpMutatorContext) { | 
|  | 421 | var module Module | 
|  | 422 | module = ctx.Module() | 
|  | 423 |  | 
|  | 424 | m := module.base() | 
|  | 425 | if !m.ArchSpecific() { | 
|  | 426 | return | 
|  | 427 | } | 
|  | 428 |  | 
|  | 429 | // addPathDepsForProps does not descend into sub structs, so we need to descend into the | 
|  | 430 | // arch-specific properties ourselves | 
|  | 431 | properties := []interface{}{} | 
|  | 432 | for _, archProperties := range m.archProperties { | 
|  | 433 | for _, archProps := range archProperties { | 
|  | 434 | archPropValues := reflect.ValueOf(archProps).Elem() | 
|  | 435 | // there are three "arch" variations, descend into each | 
|  | 436 | for _, variant := range []string{"Arch", "Multilib", "Target"} { | 
|  | 437 | // The properties are an interface, get the value (a pointer) that it points to | 
|  | 438 | archProps := archPropValues.FieldByName(variant).Elem() | 
|  | 439 | if archProps.IsNil() { | 
|  | 440 | continue | 
|  | 441 | } | 
|  | 442 | // And then a pointer to a struct | 
|  | 443 | archProps = archProps.Elem() | 
|  | 444 | for i := 0; i < archProps.NumField(); i += 1 { | 
|  | 445 | f := archProps.Field(i) | 
|  | 446 | // If the value of the field is a struct (as opposed to a pointer to a struct) then step | 
|  | 447 | // into the BlueprintEmbed field. | 
|  | 448 | if f.Kind() == reflect.Struct { | 
|  | 449 | f = f.FieldByName("BlueprintEmbed") | 
|  | 450 | } | 
|  | 451 | if f.IsZero() { | 
|  | 452 | continue | 
|  | 453 | } | 
|  | 454 | props := f.Interface().(interface{}) | 
|  | 455 | properties = append(properties, props) | 
|  | 456 | } | 
|  | 457 | } | 
|  | 458 | } | 
|  | 459 | } | 
|  | 460 | addPathDepsForProps(ctx, properties) | 
|  | 461 | } | 
|  | 462 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 463 | // osMutator splits an arch-specific module into a variant for each OS that is enabled for the | 
|  | 464 | // module.  It uses the HostOrDevice value passed to InitAndroidArchModule and the | 
|  | 465 | // device_supported and host_supported properties to determine which OsTypes are enabled for this | 
|  | 466 | // module, then searches through the Targets to determine which have enabled Targets for this | 
|  | 467 | // module. | 
| Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 468 | func osMutator(bpctx blueprint.BottomUpMutatorContext) { | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 469 | var module Module | 
|  | 470 | var ok bool | 
| Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 471 | if module, ok = bpctx.Module().(Module); !ok { | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 472 | // The module is not a Soong module, it is a Blueprint module. | 
| Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 473 | if bootstrap.IsBootstrapModule(bpctx.Module()) { | 
|  | 474 | // Bootstrap Go modules are always the build OS or linux bionic. | 
|  | 475 | config := bpctx.Config().(Config) | 
|  | 476 | osNames := []string{config.BuildOSTarget.OsVariation()} | 
|  | 477 | for _, hostCrossTarget := range config.Targets[LinuxBionic] { | 
|  | 478 | if hostCrossTarget.Arch.ArchType == config.BuildOSTarget.Arch.ArchType { | 
|  | 479 | osNames = append(osNames, hostCrossTarget.OsVariation()) | 
|  | 480 | } | 
|  | 481 | } | 
|  | 482 | osNames = FirstUniqueStrings(osNames) | 
|  | 483 | bpctx.CreateVariations(osNames...) | 
|  | 484 | } | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 485 | return | 
|  | 486 | } | 
|  | 487 |  | 
| Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 488 | // Bootstrap Go module support above requires this mutator to be a | 
|  | 489 | // blueprint.BottomUpMutatorContext because android.BottomUpMutatorContext | 
|  | 490 | // filters out non-Soong modules.  Now that we've handled them, create a | 
|  | 491 | // normal android.BottomUpMutatorContext. | 
| Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 492 | mctx := bottomUpMutatorContextFactory(bpctx, module, false, false) | 
| Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 493 |  | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 494 | base := module.base() | 
|  | 495 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 496 | // Nothing to do for modules that are not architecture specific (e.g. a genrule). | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 497 | if !base.ArchSpecific() { | 
|  | 498 | return | 
|  | 499 | } | 
|  | 500 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 501 | // Collect a list of OSTypes supported by this module based on the HostOrDevice value | 
|  | 502 | // passed to InitAndroidArchModule and the device_supported and host_supported properties. | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 503 | var moduleOSList []OsType | 
| Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 504 | for _, os := range osTypeList { | 
| Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 505 | for _, t := range mctx.Config().Targets[os] { | 
| Colin Cross | 08d6f8f | 2020-11-19 02:33:19 +0000 | [diff] [blame] | 506 | if base.supportsTarget(t) { | 
| Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 507 | moduleOSList = append(moduleOSList, os) | 
|  | 508 | break | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 509 | } | 
|  | 510 | } | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 511 | } | 
|  | 512 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 513 | // If there are no supported OSes then disable the module. | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 514 | if len(moduleOSList) == 0 { | 
| Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 515 | base.Disable() | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 516 | return | 
|  | 517 | } | 
|  | 518 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 519 | // Convert the list of supported OsTypes to the variation names. | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 520 | osNames := make([]string, len(moduleOSList)) | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 521 | for i, os := range moduleOSList { | 
|  | 522 | osNames[i] = os.String() | 
|  | 523 | } | 
|  | 524 |  | 
| Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 525 | createCommonOSVariant := base.commonProperties.CreateCommonOSVariant | 
|  | 526 | if createCommonOSVariant { | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 527 | // A CommonOS variant was requested so add it to the list of OS variants to | 
| Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 528 | // create. It needs to be added to the end because it needs to depend on the | 
|  | 529 | // the other variants in the list returned by CreateVariations(...) and inter | 
|  | 530 | // variant dependencies can only be created from a later variant in that list to | 
|  | 531 | // an earlier one. That is because variants are always processed in the order in | 
|  | 532 | // which they are returned from CreateVariations(...). | 
|  | 533 | osNames = append(osNames, CommonOS.Name) | 
|  | 534 | moduleOSList = append(moduleOSList, CommonOS) | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 535 | } | 
|  | 536 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 537 | // Create the variations, annotate each one with which OS it was created for, and | 
|  | 538 | // squash the appropriate OS-specific properties into the top level properties. | 
| Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 539 | modules := mctx.CreateVariations(osNames...) | 
|  | 540 | for i, m := range modules { | 
|  | 541 | m.base().commonProperties.CompileOS = moduleOSList[i] | 
|  | 542 | m.base().setOSProperties(mctx) | 
|  | 543 | } | 
|  | 544 |  | 
|  | 545 | if createCommonOSVariant { | 
|  | 546 | // A CommonOS variant was requested so add dependencies from it (the last one in | 
|  | 547 | // the list) to the OS type specific variants. | 
|  | 548 | last := len(modules) - 1 | 
|  | 549 | commonOSVariant := modules[last] | 
|  | 550 | commonOSVariant.base().commonProperties.CommonOSVariant = true | 
|  | 551 | for _, module := range modules[0:last] { | 
|  | 552 | // Ignore modules that are enabled. Note, this will only avoid adding | 
|  | 553 | // dependencies on OsType variants that are explicitly disabled in their | 
|  | 554 | // properties. The CommonOS variant will still depend on disabled variants | 
|  | 555 | // if they are disabled afterwards, e.g. in archMutator if | 
|  | 556 | if module.Enabled() { | 
|  | 557 | mctx.AddInterVariantDependency(commonOsToOsSpecificVariantTag, commonOSVariant, module) | 
|  | 558 | } | 
|  | 559 | } | 
|  | 560 | } | 
|  | 561 | } | 
|  | 562 |  | 
| Colin Cross | c179ea6 | 2020-10-09 10:54:15 -0700 | [diff] [blame] | 563 | type archDepTag struct { | 
|  | 564 | blueprint.BaseDependencyTag | 
|  | 565 | name string | 
|  | 566 | } | 
| Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 567 |  | 
| Colin Cross | c179ea6 | 2020-10-09 10:54:15 -0700 | [diff] [blame] | 568 | // Identifies the dependency from CommonOS variant to the os specific variants. | 
|  | 569 | var commonOsToOsSpecificVariantTag = archDepTag{name: "common os to os specific"} | 
|  | 570 |  | 
| Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 571 | // Get the OsType specific variants for the current CommonOS variant. | 
|  | 572 | // | 
|  | 573 | // The returned list will only contain enabled OsType specific variants of the | 
|  | 574 | // module referenced in the supplied context. An empty list is returned if there | 
|  | 575 | // are no enabled variants or the supplied context is not for an CommonOS | 
|  | 576 | // variant. | 
|  | 577 | func GetOsSpecificVariantsOfCommonOSVariant(mctx BaseModuleContext) []Module { | 
|  | 578 | var variants []Module | 
|  | 579 | mctx.VisitDirectDeps(func(m Module) { | 
|  | 580 | if mctx.OtherModuleDependencyTag(m) == commonOsToOsSpecificVariantTag { | 
|  | 581 | if m.Enabled() { | 
|  | 582 | variants = append(variants, m) | 
|  | 583 | } | 
|  | 584 | } | 
|  | 585 | }) | 
| Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 586 | return variants | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 587 | } | 
|  | 588 |  | 
| Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 589 | // archMutator splits a module into a variant for each Target requested by the module.  Target selection | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 590 | // for a module is in three levels, OsClass, multilib, and then Target. | 
| Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 591 | // OsClass selection is determined by: | 
|  | 592 | //    - The HostOrDeviceSupported value passed in to InitAndroidArchModule by the module type factory, which selects | 
|  | 593 | //      whether the module type can compile for host, device or both. | 
|  | 594 | //    - The host_supported and device_supported properties on the module. | 
| Roland Levillain | f5b635d | 2019-06-05 14:42:57 +0100 | [diff] [blame] | 595 | // If host is supported for the module, the Host and HostCross OsClasses are selected.  If device is supported | 
| Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 596 | // for the module, the Device OsClass is selected. | 
|  | 597 | // Within each selected OsClass, the multilib selection is determined by: | 
| Jaewoong Jung | 02b2d4d | 2019-06-06 15:19:57 -0700 | [diff] [blame] | 598 | //    - The compile_multilib property if it set (which may be overridden by target.android.compile_multilib or | 
| Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 599 | //      target.host.compile_multilib). | 
|  | 600 | //    - The default multilib passed to InitAndroidArchModule if compile_multilib was not set. | 
|  | 601 | // Valid multilib values include: | 
|  | 602 | //    "both": compile for all Targets supported by the OsClass (generally x86_64 and x86, or arm64 and arm). | 
|  | 603 | //    "first": compile for only a single preferred Target supported by the OsClass.  This is generally x86_64 or arm64, | 
| Elliott Hughes | 79ae341 | 2020-04-17 15:49:49 -0700 | [diff] [blame] | 604 | //        but may be arm for a 32-bit only build. | 
| Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 605 | //    "32": compile for only a single 32-bit Target supported by the OsClass. | 
|  | 606 | //    "64": compile for only a single 64-bit Target supported by the OsClass. | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 607 | //    "common": compile a for a single Target that will work on all Targets supported by the OsClass (for example Java). | 
|  | 608 | //    "common_first": compile a for a Target that will work on all Targets supported by the OsClass | 
|  | 609 | //        (same as "common"), plus a second Target for the preferred Target supported by the OsClass | 
|  | 610 | //        (same as "first").  This is used for java_binary that produces a common .jar and a wrapper | 
|  | 611 | //        executable script. | 
| Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 612 | // | 
|  | 613 | // Once the list of Targets is determined, the module is split into a variant for each Target. | 
|  | 614 | // | 
|  | 615 | // Modules can be initialized with InitAndroidMultiTargetsArchModule, in which case they will be split by OsClass, | 
|  | 616 | // but will have a common Target that is expected to handle all other selected Targets via ctx.MultiTargets(). | 
| Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 617 | func archMutator(bpctx blueprint.BottomUpMutatorContext) { | 
| Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 618 | var module Module | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 619 | var ok bool | 
| Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 620 | if module, ok = bpctx.Module().(Module); !ok { | 
|  | 621 | if bootstrap.IsBootstrapModule(bpctx.Module()) { | 
|  | 622 | // Bootstrap Go modules are always the build architecture. | 
|  | 623 | bpctx.CreateVariations(bpctx.Config().(Config).BuildOSTarget.ArchVariation()) | 
|  | 624 | } | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 625 | return | 
|  | 626 | } | 
|  | 627 |  | 
| Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 628 | // Bootstrap Go module support above requires this mutator to be a | 
|  | 629 | // blueprint.BottomUpMutatorContext because android.BottomUpMutatorContext | 
|  | 630 | // filters out non-Soong modules.  Now that we've handled them, create a | 
|  | 631 | // normal android.BottomUpMutatorContext. | 
| Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 632 | mctx := bottomUpMutatorContextFactory(bpctx, module, false, false) | 
| Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 633 |  | 
| Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 634 | base := module.base() | 
|  | 635 |  | 
|  | 636 | if !base.ArchSpecific() { | 
| Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 637 | return | 
|  | 638 | } | 
|  | 639 |  | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 640 | os := base.commonProperties.CompileOS | 
| Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 641 | if os == CommonOS { | 
|  | 642 | // Make sure that the target related properties are initialized for the | 
|  | 643 | // CommonOS variant. | 
|  | 644 | addTargetProperties(module, commonTargetMap[os.Name], nil, true) | 
|  | 645 |  | 
|  | 646 | // Do not create arch specific variants for the CommonOS variant. | 
|  | 647 | return | 
|  | 648 | } | 
|  | 649 |  | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 650 | osTargets := mctx.Config().Targets[os] | 
| Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 651 | image := base.commonProperties.ImageVariation | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 652 | // Filter NativeBridge targets unless they are explicitly supported. | 
|  | 653 | // Skip creating native bridge variants for non-core modules. | 
| Colin Cross | 83bead4 | 2019-12-18 10:45:46 -0800 | [diff] [blame] | 654 | if os == Android && | 
|  | 655 | !(Bool(base.commonProperties.Native_bridge_supported) && image == CoreVariation) { | 
|  | 656 |  | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 657 | var targets []Target | 
|  | 658 | for _, t := range osTargets { | 
|  | 659 | if !t.NativeBridge { | 
|  | 660 | targets = append(targets, t) | 
| Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 661 | } | 
|  | 662 | } | 
| Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 663 |  | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 664 | osTargets = targets | 
|  | 665 | } | 
| Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 666 |  | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 667 | // only the primary arch in the ramdisk / vendor_ramdisk / recovery partition | 
| Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 668 | if os == Android && (module.InstallInRecovery() || module.InstallInRamdisk() || module.InstallInVendorRamdisk() || module.InstallInDebugRamdisk()) { | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 669 | osTargets = []Target{osTargets[0]} | 
|  | 670 | } | 
| dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 671 |  | 
| Jaewoong Jung | 003d808 | 2021-02-24 17:39:54 -0800 | [diff] [blame] | 672 | // Windows builds always prefer 32-bit | 
|  | 673 | prefer32 := os == Windows | 
| dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 674 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 675 | // Determine the multilib selection for this module. | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 676 | multilib, extraMultilib := decodeMultilib(base, os.Class) | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 677 |  | 
|  | 678 | // Convert the multilib selection into a list of Targets. | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 679 | targets, err := decodeMultilibTargets(multilib, osTargets, prefer32) | 
|  | 680 | if err != nil { | 
|  | 681 | mctx.ModuleErrorf("%s", err.Error()) | 
|  | 682 | } | 
| Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 683 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 684 | // If the module is using extraMultilib, decode the extraMultilib selection into | 
|  | 685 | // a separate list of Targets. | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 686 | var multiTargets []Target | 
|  | 687 | if extraMultilib != "" { | 
|  | 688 | multiTargets, err = decodeMultilibTargets(extraMultilib, osTargets, prefer32) | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 689 | if err != nil { | 
|  | 690 | mctx.ModuleErrorf("%s", err.Error()) | 
|  | 691 | } | 
| Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 692 | } | 
|  | 693 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 694 | // Recovery is always the primary architecture, filter out any other architectures. | 
| Inseob Kim | 20fb5d4 | 2021-02-02 20:07:58 +0900 | [diff] [blame] | 695 | // Common arch is also allowed | 
| Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 696 | if image == RecoveryVariation { | 
|  | 697 | primaryArch := mctx.Config().DevicePrimaryArchType() | 
| Inseob Kim | 20fb5d4 | 2021-02-02 20:07:58 +0900 | [diff] [blame] | 698 | targets = filterToArch(targets, primaryArch, Common) | 
|  | 699 | multiTargets = filterToArch(multiTargets, primaryArch, Common) | 
| Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 700 | } | 
|  | 701 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 702 | // If there are no supported targets disable the module. | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 703 | if len(targets) == 0 { | 
| Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 704 | base.Disable() | 
| Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 705 | return | 
|  | 706 | } | 
|  | 707 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 708 | // Convert the targets into a list of arch variation names. | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 709 | targetNames := make([]string, len(targets)) | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 710 | for i, target := range targets { | 
|  | 711 | targetNames[i] = target.ArchVariation() | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 712 | } | 
|  | 713 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 714 | // Create the variations, annotate each one with which Target it was created for, and | 
|  | 715 | // squash the appropriate arch-specific properties into the top level properties. | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 716 | modules := mctx.CreateVariations(targetNames...) | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 717 | for i, m := range modules { | 
| Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 718 | addTargetProperties(m, targets[i], multiTargets, i == 0) | 
| Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 719 | m.base().setArchProperties(mctx) | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 720 | } | 
|  | 721 | } | 
|  | 722 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 723 | // addTargetProperties annotates a variant with the Target is is being compiled for, the list | 
|  | 724 | // of additional Targets it is supporting (if any), and whether it is the primary Target for | 
|  | 725 | // the module. | 
| Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 726 | func addTargetProperties(m Module, target Target, multiTargets []Target, primaryTarget bool) { | 
|  | 727 | m.base().commonProperties.CompileTarget = target | 
|  | 728 | m.base().commonProperties.CompileMultiTargets = multiTargets | 
|  | 729 | m.base().commonProperties.CompilePrimary = primaryTarget | 
|  | 730 | } | 
|  | 731 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 732 | // decodeMultilib returns the appropriate compile_multilib property for the module, or the default | 
|  | 733 | // multilib from the factory's call to InitAndroidArchModule if none was set.  For modules that | 
|  | 734 | // called InitAndroidMultiTargetsArchModule it always returns "common" for multilib, and returns | 
|  | 735 | // the actual multilib in extraMultilib. | 
| Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 736 | func decodeMultilib(base *ModuleBase, class OsClass) (multilib, extraMultilib string) { | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 737 | // First check the "android.compile_multilib" or "host.compile_multilib" properties. | 
| Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 738 | switch class { | 
|  | 739 | case Device: | 
|  | 740 | multilib = String(base.commonProperties.Target.Android.Compile_multilib) | 
| Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 741 | case Host: | 
| Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 742 | multilib = String(base.commonProperties.Target.Host.Compile_multilib) | 
|  | 743 | } | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 744 |  | 
|  | 745 | // If those aren't set, try the "compile_multilib" property. | 
| Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 746 | if multilib == "" { | 
|  | 747 | multilib = String(base.commonProperties.Compile_multilib) | 
|  | 748 | } | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 749 |  | 
|  | 750 | // If that wasn't set, use the default multilib set by the factory. | 
| Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 751 | if multilib == "" { | 
|  | 752 | multilib = base.commonProperties.Default_multilib | 
|  | 753 | } | 
|  | 754 |  | 
|  | 755 | if base.commonProperties.UseTargetVariants { | 
|  | 756 | return multilib, "" | 
|  | 757 | } else { | 
|  | 758 | // For app modules a single arch variant will be created per OS class which is expected to handle all the | 
|  | 759 | // selected arches.  Return the common-type as multilib and any Android.bp provided multilib as extraMultilib | 
|  | 760 | if multilib == base.commonProperties.Default_multilib { | 
|  | 761 | multilib = "first" | 
|  | 762 | } | 
|  | 763 | return base.commonProperties.Default_multilib, multilib | 
|  | 764 | } | 
|  | 765 | } | 
|  | 766 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 767 | // filterToArch takes a list of Targets and an ArchType, and returns a modified list that contains | 
| Inseob Kim | 20fb5d4 | 2021-02-02 20:07:58 +0900 | [diff] [blame] | 768 | // only Targets that have the specified ArchTypes. | 
|  | 769 | func filterToArch(targets []Target, archs ...ArchType) []Target { | 
| Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 770 | for i := 0; i < len(targets); i++ { | 
| Inseob Kim | 20fb5d4 | 2021-02-02 20:07:58 +0900 | [diff] [blame] | 771 | found := false | 
|  | 772 | for _, arch := range archs { | 
|  | 773 | if targets[i].Arch.ArchType == arch { | 
|  | 774 | found = true | 
|  | 775 | break | 
|  | 776 | } | 
|  | 777 | } | 
|  | 778 | if !found { | 
| Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 779 | targets = append(targets[:i], targets[i+1:]...) | 
|  | 780 | i-- | 
|  | 781 | } | 
|  | 782 | } | 
|  | 783 | return targets | 
|  | 784 | } | 
|  | 785 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 786 | // archPropRoot is a struct type used as the top level of the arch-specific properties.  It | 
|  | 787 | // contains the "arch", "multilib", and "target" property structs.  It is used to split up the | 
|  | 788 | // property structs to limit how much is allocated when a single arch-specific property group is | 
|  | 789 | // used.  The types are interface{} because they will hold instances of runtime-created types. | 
| Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 790 | type archPropRoot struct { | 
|  | 791 | Arch, Multilib, Target interface{} | 
|  | 792 | } | 
|  | 793 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 794 | // archPropTypeDesc holds the runtime-created types for the property structs to instantiate to | 
|  | 795 | // create an archPropRoot property struct. | 
|  | 796 | type archPropTypeDesc struct { | 
|  | 797 | arch, multilib, target reflect.Type | 
|  | 798 | } | 
|  | 799 |  | 
| Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 800 | // createArchPropTypeDesc takes a reflect.Type that is either a struct or a pointer to a struct, and | 
|  | 801 | // returns lists of reflect.Types that contains the arch-variant properties inside structs for each | 
|  | 802 | // arch, multilib and target property. | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 803 | // | 
|  | 804 | // This is a relatively expensive operation, so the results are cached in the global | 
|  | 805 | // archPropTypeMap.  It is constructed entirely based on compile-time data, so there is no need | 
|  | 806 | // to isolate the results between multiple tests running in parallel. | 
| Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 807 | func createArchPropTypeDesc(props reflect.Type) []archPropTypeDesc { | 
| Colin Cross | b1d8c99 | 2020-01-21 11:43:29 -0800 | [diff] [blame] | 808 | // Each property struct shard will be nested many times under the runtime generated arch struct, | 
|  | 809 | // which can hit the limit of 64kB for the name of runtime generated structs.  They are nested | 
|  | 810 | // 97 times now, which may grow in the future, plus there is some overhead for the containing | 
|  | 811 | // type.  This number may need to be reduced if too many are added, but reducing it too far | 
|  | 812 | // could cause problems if a single deeply nested property no longer fits in the name. | 
|  | 813 | const maxArchTypeNameSize = 500 | 
|  | 814 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 815 | // Convert the type to a new set of types that contains only the arch-specific properties | 
|  | 816 | // (those that are tagged with `android:"arch_specific"`), and sharded into multiple types | 
|  | 817 | // to keep the runtime-generated names under the limit. | 
| Colin Cross | b1d8c99 | 2020-01-21 11:43:29 -0800 | [diff] [blame] | 818 | propShards, _ := proptools.FilterPropertyStructSharded(props, maxArchTypeNameSize, filterArchStruct) | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 819 |  | 
|  | 820 | // If the type has no arch-specific properties there is nothing to do. | 
| Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 821 | if len(propShards) == 0 { | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 822 | return nil | 
|  | 823 | } | 
|  | 824 |  | 
| Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 825 | var ret []archPropTypeDesc | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 826 | for _, props := range propShards { | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 827 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 828 | // variantFields takes a list of variant property field names and returns a list the | 
|  | 829 | // StructFields with the names and the type of the current shard. | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 830 | variantFields := func(names []string) []reflect.StructField { | 
|  | 831 | ret := make([]reflect.StructField, len(names)) | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 832 |  | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 833 | for i, name := range names { | 
|  | 834 | ret[i].Name = name | 
|  | 835 | ret[i].Type = props | 
| Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 836 | } | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 837 |  | 
|  | 838 | return ret | 
|  | 839 | } | 
|  | 840 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 841 | // Create a type that contains the properties in this shard repeated for each | 
|  | 842 | // architecture, architecture variant, and architecture feature. | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 843 | archFields := make([]reflect.StructField, len(archTypeList)) | 
|  | 844 | for i, arch := range archTypeList { | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 845 | var variants []string | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 846 |  | 
|  | 847 | for _, archVariant := range archVariants[arch] { | 
|  | 848 | archVariant := variantReplacer.Replace(archVariant) | 
|  | 849 | variants = append(variants, proptools.FieldNameForProperty(archVariant)) | 
|  | 850 | } | 
|  | 851 | for _, feature := range archFeatures[arch] { | 
|  | 852 | feature := variantReplacer.Replace(feature) | 
|  | 853 | variants = append(variants, proptools.FieldNameForProperty(feature)) | 
|  | 854 | } | 
|  | 855 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 856 | // Create the StructFields for each architecture variant architecture feature | 
|  | 857 | // (e.g. "arch.arm.cortex-a53" or "arch.arm.neon"). | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 858 | fields := variantFields(variants) | 
|  | 859 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 860 | // Create the StructField for the architecture itself (e.g. "arch.arm").  The special | 
|  | 861 | // "BlueprintEmbed" name is used by Blueprint to put the properties in the | 
|  | 862 | // parent struct. | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 863 | fields = append([]reflect.StructField{{ | 
|  | 864 | Name:      "BlueprintEmbed", | 
|  | 865 | Type:      props, | 
|  | 866 | Anonymous: true, | 
|  | 867 | }}, fields...) | 
|  | 868 |  | 
|  | 869 | archFields[i] = reflect.StructField{ | 
|  | 870 | Name: arch.Field, | 
|  | 871 | Type: reflect.StructOf(fields), | 
|  | 872 | } | 
|  | 873 | } | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 874 |  | 
|  | 875 | // Create the type of the "arch" property struct for this shard. | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 876 | archType := reflect.StructOf(archFields) | 
|  | 877 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 878 | // Create the type for the "multilib" property struct for this shard, containing the | 
|  | 879 | // "multilib.lib32" and "multilib.lib64" property structs. | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 880 | multilibType := reflect.StructOf(variantFields([]string{"Lib32", "Lib64"})) | 
|  | 881 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 882 | // Start with a list of the special targets | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 883 | targets := []string{ | 
|  | 884 | "Host", | 
|  | 885 | "Android64", | 
|  | 886 | "Android32", | 
|  | 887 | "Bionic", | 
|  | 888 | "Linux", | 
|  | 889 | "Not_windows", | 
|  | 890 | "Arm_on_x86", | 
|  | 891 | "Arm_on_x86_64", | 
| Victor Khimenko | c26fcf4 | 2020-05-07 22:16:33 +0200 | [diff] [blame] | 892 | "Native_bridge", | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 893 | } | 
| Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 894 | for _, os := range osTypeList { | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 895 | // Add all the OSes. | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 896 | targets = append(targets, os.Field) | 
|  | 897 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 898 | // Add the OS/Arch combinations, e.g. "android_arm64". | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 899 | for _, archType := range osArchTypeMap[os] { | 
| Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 900 | targets = append(targets, GetCompoundTargetName(os, archType)) | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 901 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 902 | // Also add the special "linux_<arch>" and "bionic_<arch>" property structs. | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 903 | if os.Linux() { | 
|  | 904 | target := "Linux_" + archType.Name | 
|  | 905 | if !InList(target, targets) { | 
|  | 906 | targets = append(targets, target) | 
|  | 907 | } | 
|  | 908 | } | 
|  | 909 | if os.Bionic() { | 
|  | 910 | target := "Bionic_" + archType.Name | 
|  | 911 | if !InList(target, targets) { | 
|  | 912 | targets = append(targets, target) | 
|  | 913 | } | 
| Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 914 | } | 
|  | 915 | } | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 916 | } | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 917 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 918 | // Create the type for the "target" property struct for this shard. | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 919 | targetType := reflect.StructOf(variantFields(targets)) | 
| Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 920 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 921 | // Return a descriptor of the 3 runtime-created types. | 
| Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 922 | ret = append(ret, archPropTypeDesc{ | 
|  | 923 | arch:     reflect.PtrTo(archType), | 
|  | 924 | multilib: reflect.PtrTo(multilibType), | 
|  | 925 | target:   reflect.PtrTo(targetType), | 
|  | 926 | }) | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 927 | } | 
|  | 928 | return ret | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 929 | } | 
|  | 930 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 931 | // variantReplacer converts architecture variant or architecture feature names into names that | 
|  | 932 | // are valid for an Android.bp file. | 
|  | 933 | var variantReplacer = strings.NewReplacer("-", "_", ".", "_") | 
|  | 934 |  | 
|  | 935 | // filterArchStruct returns true if the given field is an architecture specific property. | 
| Colin Cross | 7444910 | 2019-09-25 11:26:40 -0700 | [diff] [blame] | 936 | func filterArchStruct(field reflect.StructField, prefix string) (bool, reflect.StructField) { | 
|  | 937 | if proptools.HasTag(field, "android", "arch_variant") { | 
|  | 938 | // The arch_variant field isn't necessary past this point | 
|  | 939 | // Instead of wasting space, just remove it. Go also has a | 
|  | 940 | // 16-bit limit on structure name length. The name is constructed | 
|  | 941 | // based on the Go source representation of the structure, so | 
|  | 942 | // the tag names count towards that length. | 
| Colin Cross | b4fecbf | 2020-01-21 11:38:47 -0800 | [diff] [blame] | 943 |  | 
|  | 944 | androidTag := field.Tag.Get("android") | 
|  | 945 | values := strings.Split(androidTag, ",") | 
|  | 946 |  | 
|  | 947 | if string(field.Tag) != `android:"`+strings.Join(values, ",")+`"` { | 
|  | 948 | panic(fmt.Errorf("unexpected tag format %q", field.Tag)) | 
| Colin Cross | 7444910 | 2019-09-25 11:26:40 -0700 | [diff] [blame] | 949 | } | 
| Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 950 | // don't delete path tag as it is needed for bp2build | 
| Colin Cross | b4fecbf | 2020-01-21 11:38:47 -0800 | [diff] [blame] | 951 | // these tags don't need to be present in the runtime generated struct type. | 
| Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 952 | values = RemoveListFromList(values, []string{"arch_variant", "variant_prepend"}) | 
|  | 953 | if len(values) > 0 && values[0] != "path" { | 
| Colin Cross | b4fecbf | 2020-01-21 11:38:47 -0800 | [diff] [blame] | 954 | panic(fmt.Errorf("unknown tags %q in field %q", values, prefix+field.Name)) | 
| Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 955 | } else if len(values) == 1 { | 
|  | 956 | field.Tag = reflect.StructTag(`android:"` + strings.Join(values, ",") + `"`) | 
|  | 957 | } else { | 
|  | 958 | field.Tag = `` | 
| Colin Cross | b4fecbf | 2020-01-21 11:38:47 -0800 | [diff] [blame] | 959 | } | 
|  | 960 |  | 
| Colin Cross | 7444910 | 2019-09-25 11:26:40 -0700 | [diff] [blame] | 961 | return true, field | 
|  | 962 | } | 
|  | 963 | return false, field | 
|  | 964 | } | 
|  | 965 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 966 | // archPropTypeMap contains a cache of the results of createArchPropTypeDesc for each type.  It is | 
|  | 967 | // shared across all Contexts, but is constructed based only on compile-time information so there | 
|  | 968 | // is no risk of contaminating one Context with data from another. | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 969 | var archPropTypeMap OncePer | 
|  | 970 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 971 | // initArchModule adds the architecture-specific property structs to a Module. | 
|  | 972 | func initArchModule(m Module) { | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 973 |  | 
|  | 974 | base := m.base() | 
|  | 975 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 976 | // Store the original list of top level property structs | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 977 | base.generalProperties = m.GetProperties() | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 978 |  | 
|  | 979 | for _, properties := range base.generalProperties { | 
|  | 980 | propertiesValue := reflect.ValueOf(properties) | 
| Colin Cross | 62496a0 | 2016-08-08 15:49:17 -0700 | [diff] [blame] | 981 | t := propertiesValue.Type() | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 982 | if propertiesValue.Kind() != reflect.Ptr { | 
| Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 983 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", | 
|  | 984 | propertiesValue.Interface())) | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 985 | } | 
|  | 986 |  | 
|  | 987 | propertiesValue = propertiesValue.Elem() | 
|  | 988 | if propertiesValue.Kind() != reflect.Struct { | 
| Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 989 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", | 
|  | 990 | propertiesValue.Interface())) | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 991 | } | 
|  | 992 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 993 | // Get or create the arch-specific property struct types for this property struct type. | 
| Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 994 | archPropTypes := archPropTypeMap.Once(NewCustomOnceKey(t), func() interface{} { | 
| Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 995 | return createArchPropTypeDesc(t) | 
|  | 996 | }).([]archPropTypeDesc) | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 997 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 998 | // Instantiate one of each arch-specific property struct type and add it to the | 
|  | 999 | // properties for the Module. | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1000 | var archProperties []interface{} | 
|  | 1001 | for _, t := range archPropTypes { | 
| Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1002 | archProperties = append(archProperties, &archPropRoot{ | 
|  | 1003 | Arch:     reflect.Zero(t.arch).Interface(), | 
|  | 1004 | Multilib: reflect.Zero(t.multilib).Interface(), | 
|  | 1005 | Target:   reflect.Zero(t.target).Interface(), | 
|  | 1006 | }) | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1007 | } | 
| Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1008 | base.archProperties = append(base.archProperties, archProperties) | 
|  | 1009 | m.AddProperties(archProperties...) | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1010 | } | 
|  | 1011 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1012 | // Update the list of properties that can be set by a defaults module or a call to | 
|  | 1013 | // AppendMatchingProperties or PrependMatchingProperties. | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1014 | base.customizableProperties = m.GetProperties() | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1015 | } | 
|  | 1016 |  | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1017 | func maybeBlueprintEmbed(src reflect.Value) reflect.Value { | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1018 | // If the value of the field is a struct (as opposed to a pointer to a struct) then step | 
|  | 1019 | // into the BlueprintEmbed field. | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1020 | if src.Kind() == reflect.Struct { | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1021 | return src.FieldByName("BlueprintEmbed") | 
|  | 1022 | } else { | 
|  | 1023 | return src | 
| Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1024 | } | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1025 | } | 
|  | 1026 |  | 
|  | 1027 | // Merges the property struct in srcValue into dst. | 
| Liz Kammer | b6dbc87 | 2021-05-14 15:14:40 -0400 | [diff] [blame] | 1028 | func mergePropertyStruct(ctx ArchVariantContext, dst interface{}, srcValue reflect.Value) { | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1029 | src := maybeBlueprintEmbed(srcValue).Interface() | 
| Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1030 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1031 | // order checks the `android:"variant_prepend"` tag to handle properties where the | 
|  | 1032 | // arch-specific value needs to come before the generic value, for example for lists of | 
|  | 1033 | // include directories. | 
| Colin Cross | 6ee75b6 | 2016-05-05 15:57:15 -0700 | [diff] [blame] | 1034 | order := func(property string, | 
|  | 1035 | dstField, srcField reflect.StructField, | 
|  | 1036 | dstValue, srcValue interface{}) (proptools.Order, error) { | 
|  | 1037 | if proptools.HasTag(dstField, "android", "variant_prepend") { | 
|  | 1038 | return proptools.Prepend, nil | 
|  | 1039 | } else { | 
|  | 1040 | return proptools.Append, nil | 
|  | 1041 | } | 
|  | 1042 | } | 
|  | 1043 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1044 | // Squash the located property struct into the destination property struct. | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1045 | err := proptools.ExtendMatchingProperties([]interface{}{dst}, src, nil, order) | 
| Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1046 | if err != nil { | 
|  | 1047 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { | 
|  | 1048 | ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) | 
|  | 1049 | } else { | 
|  | 1050 | panic(err) | 
|  | 1051 | } | 
|  | 1052 | } | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1053 | } | 
| Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 1054 |  | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1055 | // Returns the immediate child of the input property struct that corresponds to | 
|  | 1056 | // the sub-property "field". | 
| Liz Kammer | b6dbc87 | 2021-05-14 15:14:40 -0400 | [diff] [blame] | 1057 | func getChildPropertyStruct(ctx ArchVariantContext, | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1058 | src reflect.Value, field, userFriendlyField string) (reflect.Value, bool) { | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1059 |  | 
|  | 1060 | // Step into non-nil pointers to structs in the src value. | 
|  | 1061 | if src.Kind() == reflect.Ptr { | 
|  | 1062 | if src.IsNil() { | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1063 | return reflect.Value{}, false | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1064 | } | 
|  | 1065 | src = src.Elem() | 
|  | 1066 | } | 
|  | 1067 |  | 
|  | 1068 | // Find the requested field in the src struct. | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1069 | child := src.FieldByName(proptools.FieldNameForProperty(field)) | 
|  | 1070 | if !child.IsValid() { | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1071 | ctx.ModuleErrorf("field %q does not exist", userFriendlyField) | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1072 | return reflect.Value{}, false | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1073 | } | 
|  | 1074 |  | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1075 | if child.IsZero() { | 
|  | 1076 | return reflect.Value{}, false | 
|  | 1077 | } | 
|  | 1078 |  | 
|  | 1079 | return child, true | 
| Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1080 | } | 
|  | 1081 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1082 | // Squash the appropriate OS-specific property structs into the matching top level property structs | 
|  | 1083 | // based on the CompileOS value that was annotated on the variant. | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1084 | func (m *ModuleBase) setOSProperties(ctx BottomUpMutatorContext) { | 
|  | 1085 | os := m.commonProperties.CompileOS | 
|  | 1086 |  | 
|  | 1087 | for i := range m.generalProperties { | 
|  | 1088 | genProps := m.generalProperties[i] | 
|  | 1089 | if m.archProperties[i] == nil { | 
|  | 1090 | continue | 
|  | 1091 | } | 
|  | 1092 | for _, archProperties := range m.archProperties[i] { | 
|  | 1093 | archPropValues := reflect.ValueOf(archProperties).Elem() | 
|  | 1094 |  | 
| Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1095 | targetProp := archPropValues.FieldByName("Target").Elem() | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1096 |  | 
|  | 1097 | // Handle host-specific properties in the form: | 
|  | 1098 | // target: { | 
|  | 1099 | //     host: { | 
|  | 1100 | //         key: value, | 
|  | 1101 | //     }, | 
|  | 1102 | // }, | 
| Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1103 | if os.Class == Host { | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1104 | field := "Host" | 
|  | 1105 | prefix := "target.host" | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1106 | if hostProperties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { | 
|  | 1107 | mergePropertyStruct(ctx, genProps, hostProperties) | 
|  | 1108 | } | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1109 | } | 
|  | 1110 |  | 
|  | 1111 | // Handle target OS generalities of the form: | 
|  | 1112 | // target: { | 
|  | 1113 | //     bionic: { | 
|  | 1114 | //         key: value, | 
|  | 1115 | //     }, | 
|  | 1116 | // } | 
|  | 1117 | if os.Linux() { | 
|  | 1118 | field := "Linux" | 
|  | 1119 | prefix := "target.linux" | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1120 | if linuxProperties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { | 
|  | 1121 | mergePropertyStruct(ctx, genProps, linuxProperties) | 
|  | 1122 | } | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1123 | } | 
|  | 1124 |  | 
|  | 1125 | if os.Bionic() { | 
|  | 1126 | field := "Bionic" | 
|  | 1127 | prefix := "target.bionic" | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1128 | if bionicProperties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { | 
|  | 1129 | mergePropertyStruct(ctx, genProps, bionicProperties) | 
|  | 1130 | } | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1131 | } | 
|  | 1132 |  | 
|  | 1133 | // Handle target OS properties in the form: | 
|  | 1134 | // target: { | 
|  | 1135 | //     linux_glibc: { | 
|  | 1136 | //         key: value, | 
|  | 1137 | //     }, | 
|  | 1138 | //     not_windows: { | 
|  | 1139 | //         key: value, | 
|  | 1140 | //     }, | 
|  | 1141 | //     android { | 
|  | 1142 | //         key: value, | 
|  | 1143 | //     }, | 
|  | 1144 | // }, | 
|  | 1145 | field := os.Field | 
|  | 1146 | prefix := "target." + os.Name | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1147 | if osProperties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { | 
|  | 1148 | mergePropertyStruct(ctx, genProps, osProperties) | 
|  | 1149 | } | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1150 |  | 
| Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1151 | if os.Class == Host && os != Windows { | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1152 | field := "Not_windows" | 
|  | 1153 | prefix := "target.not_windows" | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1154 | if notWindowsProperties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { | 
|  | 1155 | mergePropertyStruct(ctx, genProps, notWindowsProperties) | 
|  | 1156 | } | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1157 | } | 
|  | 1158 |  | 
|  | 1159 | // Handle 64-bit device properties in the form: | 
|  | 1160 | // target { | 
|  | 1161 | //     android64 { | 
|  | 1162 | //         key: value, | 
|  | 1163 | //     }, | 
|  | 1164 | //     android32 { | 
|  | 1165 | //         key: value, | 
|  | 1166 | //     }, | 
|  | 1167 | // }, | 
|  | 1168 | // WARNING: this is probably not what you want to use in your blueprints file, it selects | 
|  | 1169 | // options for all targets on a device that supports 64-bit binaries, not just the targets | 
|  | 1170 | // that are being compiled for 64-bit.  Its expected use case is binaries like linker and | 
|  | 1171 | // debuggerd that need to know when they are a 32-bit process running on a 64-bit device | 
|  | 1172 | if os.Class == Device { | 
|  | 1173 | if ctx.Config().Android64() { | 
|  | 1174 | field := "Android64" | 
|  | 1175 | prefix := "target.android64" | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1176 | if android64Properties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { | 
|  | 1177 | mergePropertyStruct(ctx, genProps, android64Properties) | 
|  | 1178 | } | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1179 | } else { | 
|  | 1180 | field := "Android32" | 
|  | 1181 | prefix := "target.android32" | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1182 | if android32Properties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { | 
|  | 1183 | mergePropertyStruct(ctx, genProps, android32Properties) | 
|  | 1184 | } | 
| Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1185 | } | 
|  | 1186 | } | 
|  | 1187 | } | 
|  | 1188 | } | 
|  | 1189 | } | 
|  | 1190 |  | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1191 | // Returns the struct containing the properties specific to the given | 
|  | 1192 | // architecture type. These look like this in Blueprint files: | 
|  | 1193 | // arch: { | 
|  | 1194 | //     arm64: { | 
|  | 1195 | //         key: value, | 
|  | 1196 | //     }, | 
|  | 1197 | // }, | 
|  | 1198 | // This struct will also contain sub-structs containing to the architecture/CPU | 
|  | 1199 | // variants and features that themselves contain properties specific to those. | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1200 | func getArchTypeStruct(ctx ArchVariantContext, archProperties interface{}, archType ArchType) (reflect.Value, bool) { | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1201 | archPropValues := reflect.ValueOf(archProperties).Elem() | 
|  | 1202 | archProp := archPropValues.FieldByName("Arch").Elem() | 
|  | 1203 | prefix := "arch." + archType.Name | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1204 | return getChildPropertyStruct(ctx, archProp, archType.Name, prefix) | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1205 | } | 
|  | 1206 |  | 
|  | 1207 | // Returns the struct containing the properties specific to a given multilib | 
|  | 1208 | // value. These look like this in the Blueprint file: | 
|  | 1209 | // multilib: { | 
|  | 1210 | //     lib32: { | 
|  | 1211 | //         key: value, | 
|  | 1212 | //     }, | 
|  | 1213 | // }, | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1214 | func getMultilibStruct(ctx ArchVariantContext, archProperties interface{}, archType ArchType) (reflect.Value, bool) { | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1215 | archPropValues := reflect.ValueOf(archProperties).Elem() | 
|  | 1216 | multilibProp := archPropValues.FieldByName("Multilib").Elem() | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1217 | return getChildPropertyStruct(ctx, multilibProp, archType.Multilib, "multilib."+archType.Multilib) | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1218 | } | 
|  | 1219 |  | 
| Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 1220 | func GetCompoundTargetName(os OsType, arch ArchType) string { | 
|  | 1221 | return os.Field + "_" + arch.Name | 
|  | 1222 | } | 
|  | 1223 |  | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1224 | // Returns the structs corresponding to the properties specific to the given | 
|  | 1225 | // architecture and OS in archProperties. | 
|  | 1226 | func getArchProperties(ctx BaseMutatorContext, archProperties interface{}, arch Arch, os OsType, nativeBridgeEnabled bool) []reflect.Value { | 
|  | 1227 | result := make([]reflect.Value, 0) | 
|  | 1228 | archPropValues := reflect.ValueOf(archProperties).Elem() | 
|  | 1229 |  | 
|  | 1230 | targetProp := archPropValues.FieldByName("Target").Elem() | 
|  | 1231 |  | 
|  | 1232 | archType := arch.ArchType | 
|  | 1233 |  | 
|  | 1234 | if arch.ArchType != Common { | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1235 | archStruct, ok := getArchTypeStruct(ctx, archProperties, arch.ArchType) | 
|  | 1236 | if ok { | 
|  | 1237 | result = append(result, archStruct) | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1238 |  | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1239 | // Handle arch-variant-specific properties in the form: | 
|  | 1240 | // arch: { | 
|  | 1241 | //     arm: { | 
|  | 1242 | //         variant: { | 
|  | 1243 | //             key: value, | 
|  | 1244 | //         }, | 
|  | 1245 | //     }, | 
|  | 1246 | // }, | 
|  | 1247 | v := variantReplacer.Replace(arch.ArchVariant) | 
|  | 1248 | if v != "" { | 
|  | 1249 | prefix := "arch." + archType.Name + "." + v | 
|  | 1250 | if variantProperties, ok := getChildPropertyStruct(ctx, archStruct, v, prefix); ok { | 
|  | 1251 | result = append(result, variantProperties) | 
|  | 1252 | } | 
|  | 1253 | } | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1254 |  | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1255 | // Handle cpu-variant-specific properties in the form: | 
|  | 1256 | // arch: { | 
|  | 1257 | //     arm: { | 
|  | 1258 | //         variant: { | 
|  | 1259 | //             key: value, | 
|  | 1260 | //         }, | 
|  | 1261 | //     }, | 
|  | 1262 | // }, | 
|  | 1263 | if arch.CpuVariant != arch.ArchVariant { | 
|  | 1264 | c := variantReplacer.Replace(arch.CpuVariant) | 
|  | 1265 | if c != "" { | 
|  | 1266 | prefix := "arch." + archType.Name + "." + c | 
|  | 1267 | if cpuVariantProperties, ok := getChildPropertyStruct(ctx, archStruct, c, prefix); ok { | 
|  | 1268 | result = append(result, cpuVariantProperties) | 
|  | 1269 | } | 
|  | 1270 | } | 
|  | 1271 | } | 
|  | 1272 |  | 
|  | 1273 | // Handle arch-feature-specific properties in the form: | 
|  | 1274 | // arch: { | 
|  | 1275 | //     arm: { | 
|  | 1276 | //         feature: { | 
|  | 1277 | //             key: value, | 
|  | 1278 | //         }, | 
|  | 1279 | //     }, | 
|  | 1280 | // }, | 
|  | 1281 | for _, feature := range arch.ArchFeatures { | 
|  | 1282 | prefix := "arch." + archType.Name + "." + feature | 
|  | 1283 | if featureProperties, ok := getChildPropertyStruct(ctx, archStruct, feature, prefix); ok { | 
|  | 1284 | result = append(result, featureProperties) | 
|  | 1285 | } | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1286 | } | 
|  | 1287 | } | 
|  | 1288 |  | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1289 | if multilibProperties, ok := getMultilibStruct(ctx, archProperties, archType); ok { | 
|  | 1290 | result = append(result, multilibProperties) | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1291 | } | 
|  | 1292 |  | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1293 | // Handle combined OS-feature and arch specific properties in the form: | 
|  | 1294 | // target: { | 
|  | 1295 | //     bionic_x86: { | 
|  | 1296 | //         key: value, | 
|  | 1297 | //     }, | 
|  | 1298 | // } | 
|  | 1299 | if os.Linux() { | 
|  | 1300 | field := "Linux_" + arch.ArchType.Name | 
|  | 1301 | userFriendlyField := "target.linux_" + arch.ArchType.Name | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1302 | if linuxProperties, ok := getChildPropertyStruct(ctx, targetProp, field, userFriendlyField); ok { | 
|  | 1303 | result = append(result, linuxProperties) | 
|  | 1304 | } | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1305 | } | 
|  | 1306 |  | 
|  | 1307 | if os.Bionic() { | 
|  | 1308 | field := "Bionic_" + archType.Name | 
|  | 1309 | userFriendlyField := "target.bionic_" + archType.Name | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1310 | if bionicProperties, ok := getChildPropertyStruct(ctx, targetProp, field, userFriendlyField); ok { | 
|  | 1311 | result = append(result, bionicProperties) | 
|  | 1312 | } | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1313 | } | 
|  | 1314 |  | 
|  | 1315 | // Handle combined OS and arch specific properties in the form: | 
|  | 1316 | // target: { | 
|  | 1317 | //     linux_glibc_x86: { | 
|  | 1318 | //         key: value, | 
|  | 1319 | //     }, | 
|  | 1320 | //     linux_glibc_arm: { | 
|  | 1321 | //         key: value, | 
|  | 1322 | //     }, | 
|  | 1323 | //     android_arm { | 
|  | 1324 | //         key: value, | 
|  | 1325 | //     }, | 
|  | 1326 | //     android_x86 { | 
|  | 1327 | //         key: value, | 
|  | 1328 | //     }, | 
|  | 1329 | // }, | 
| Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 1330 | field := GetCompoundTargetName(os, archType) | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1331 | userFriendlyField := "target." + os.Name + "_" + archType.Name | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1332 | if osArchProperties, ok := getChildPropertyStruct(ctx, targetProp, field, userFriendlyField); ok { | 
|  | 1333 | result = append(result, osArchProperties) | 
|  | 1334 | } | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1335 | } | 
|  | 1336 |  | 
|  | 1337 | // Handle arm on x86 properties in the form: | 
|  | 1338 | // target { | 
|  | 1339 | //     arm_on_x86 { | 
|  | 1340 | //         key: value, | 
|  | 1341 | //     }, | 
|  | 1342 | //     arm_on_x86_64 { | 
|  | 1343 | //         key: value, | 
|  | 1344 | //     }, | 
|  | 1345 | // }, | 
|  | 1346 | if os.Class == Device { | 
|  | 1347 | if arch.ArchType == X86 && (hasArmAbi(arch) || | 
|  | 1348 | hasArmAndroidArch(ctx.Config().Targets[Android])) { | 
|  | 1349 | field := "Arm_on_x86" | 
|  | 1350 | userFriendlyField := "target.arm_on_x86" | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1351 | if armOnX86Properties, ok := getChildPropertyStruct(ctx, targetProp, field, userFriendlyField); ok { | 
|  | 1352 | result = append(result, armOnX86Properties) | 
|  | 1353 | } | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1354 | } | 
|  | 1355 | if arch.ArchType == X86_64 && (hasArmAbi(arch) || | 
|  | 1356 | hasArmAndroidArch(ctx.Config().Targets[Android])) { | 
|  | 1357 | field := "Arm_on_x86_64" | 
|  | 1358 | userFriendlyField := "target.arm_on_x86_64" | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1359 | if armOnX8664Properties, ok := getChildPropertyStruct(ctx, targetProp, field, userFriendlyField); ok { | 
|  | 1360 | result = append(result, armOnX8664Properties) | 
|  | 1361 | } | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1362 | } | 
|  | 1363 | if os == Android && nativeBridgeEnabled { | 
|  | 1364 | userFriendlyField := "Native_bridge" | 
|  | 1365 | prefix := "target.native_bridge" | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1366 | if nativeBridgeProperties, ok := getChildPropertyStruct(ctx, targetProp, userFriendlyField, prefix); ok { | 
|  | 1367 | result = append(result, nativeBridgeProperties) | 
|  | 1368 | } | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1369 | } | 
|  | 1370 | } | 
|  | 1371 |  | 
|  | 1372 | return result | 
|  | 1373 | } | 
|  | 1374 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1375 | // Squash the appropriate arch-specific property structs into the matching top level property | 
|  | 1376 | // structs based on the CompileTarget value that was annotated on the variant. | 
| Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1377 | func (m *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) { | 
|  | 1378 | arch := m.Arch() | 
|  | 1379 | os := m.Os() | 
| Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 1380 |  | 
| Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1381 | for i := range m.generalProperties { | 
|  | 1382 | genProps := m.generalProperties[i] | 
|  | 1383 | if m.archProperties[i] == nil { | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1384 | continue | 
|  | 1385 | } | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1386 |  | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1387 | propStructs := make([]reflect.Value, 0) | 
|  | 1388 | for _, archProperty := range m.archProperties[i] { | 
|  | 1389 | propStructShard := getArchProperties(ctx, archProperty, arch, os, m.Target().NativeBridge == NativeBridgeEnabled) | 
|  | 1390 | propStructs = append(propStructs, propStructShard...) | 
|  | 1391 | } | 
| Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1392 |  | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1393 | for _, propStruct := range propStructs { | 
|  | 1394 | mergePropertyStruct(ctx, genProps, propStruct) | 
| Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1395 | } | 
| Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1396 | } | 
|  | 1397 | } | 
|  | 1398 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1399 | // Convert the arch product variables into a list of targets for each OsType. | 
| Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1400 | func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) { | 
| Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1401 | variables := config.productVariables | 
| Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1402 |  | 
| Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1403 | targets := make(map[OsType][]Target) | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1404 | var targetErr error | 
|  | 1405 |  | 
| dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1406 | addTarget := func(os OsType, archName string, archVariant, cpuVariant *string, abi []string, | 
| dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1407 | nativeBridgeEnabled NativeBridgeSupport, nativeBridgeHostArchName *string, | 
|  | 1408 | nativeBridgeRelativePath *string) { | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1409 | if targetErr != nil { | 
|  | 1410 | return | 
| Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1411 | } | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1412 |  | 
| Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1413 | arch, err := decodeArch(os, archName, archVariant, cpuVariant, abi) | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1414 | if err != nil { | 
|  | 1415 | targetErr = err | 
|  | 1416 | return | 
|  | 1417 | } | 
| dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1418 | nativeBridgeRelativePathStr := String(nativeBridgeRelativePath) | 
|  | 1419 | nativeBridgeHostArchNameStr := String(nativeBridgeHostArchName) | 
|  | 1420 |  | 
|  | 1421 | // Use guest arch as relative install path by default | 
|  | 1422 | if nativeBridgeEnabled && nativeBridgeRelativePathStr == "" { | 
|  | 1423 | nativeBridgeRelativePathStr = arch.ArchType.String() | 
|  | 1424 | } | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1425 |  | 
| Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1426 | // A target is considered as HostCross if it's a host target which can't run natively on | 
|  | 1427 | // the currently configured build machine (either because the OS is different or because of | 
|  | 1428 | // the unsupported arch) | 
|  | 1429 | hostCross := false | 
|  | 1430 | if os.Class == Host { | 
|  | 1431 | var osSupported bool | 
|  | 1432 | if os == BuildOs { | 
|  | 1433 | osSupported = true | 
|  | 1434 | } else if BuildOs.Linux() && os.Linux() { | 
|  | 1435 | // LinuxBionic and Linux are compatible | 
|  | 1436 | osSupported = true | 
|  | 1437 | } else { | 
|  | 1438 | osSupported = false | 
|  | 1439 | } | 
|  | 1440 |  | 
|  | 1441 | var archSupported bool | 
|  | 1442 | if arch.ArchType == Common { | 
|  | 1443 | archSupported = true | 
|  | 1444 | } else if arch.ArchType.Name == *variables.HostArch { | 
|  | 1445 | archSupported = true | 
|  | 1446 | } else if variables.HostSecondaryArch != nil && arch.ArchType.Name == *variables.HostSecondaryArch { | 
|  | 1447 | archSupported = true | 
|  | 1448 | } else { | 
|  | 1449 | archSupported = false | 
|  | 1450 | } | 
|  | 1451 | if !osSupported || !archSupported { | 
|  | 1452 | hostCross = true | 
|  | 1453 | } | 
|  | 1454 | } | 
|  | 1455 |  | 
| Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1456 | targets[os] = append(targets[os], | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1457 | Target{ | 
| dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1458 | Os:                       os, | 
|  | 1459 | Arch:                     arch, | 
|  | 1460 | NativeBridge:             nativeBridgeEnabled, | 
|  | 1461 | NativeBridgeHostArchName: nativeBridgeHostArchNameStr, | 
|  | 1462 | NativeBridgeRelativePath: nativeBridgeRelativePathStr, | 
| Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1463 | HostCross:                hostCross, | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1464 | }) | 
| Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1465 | } | 
|  | 1466 |  | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1467 | if variables.HostArch == nil { | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1468 | return nil, fmt.Errorf("No host primary architecture set") | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1469 | } | 
|  | 1470 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1471 | // The primary host target, which must always exist. | 
| dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1472 | addTarget(BuildOs, *variables.HostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1473 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1474 | // An optional secondary host target. | 
| Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1475 | if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" { | 
| dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1476 | addTarget(BuildOs, *variables.HostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) | 
| Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1477 | } | 
|  | 1478 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1479 | // Optional cross-compiled host targets, generally Windows. | 
| Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1480 | if String(variables.CrossHost) != "" { | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1481 | crossHostOs := osByName(*variables.CrossHost) | 
|  | 1482 | if crossHostOs == NoOsType { | 
|  | 1483 | return nil, fmt.Errorf("Unknown cross host OS %q", *variables.CrossHost) | 
|  | 1484 | } | 
|  | 1485 |  | 
| Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1486 | if String(variables.CrossHostArch) == "" { | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1487 | return nil, fmt.Errorf("No cross-host primary architecture set") | 
| Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1488 | } | 
|  | 1489 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1490 | // The primary cross-compiled host target. | 
| dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1491 | addTarget(crossHostOs, *variables.CrossHostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) | 
| Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1492 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1493 | // An optional secondary cross-compiled host target. | 
| Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1494 | if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" { | 
| dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1495 | addTarget(crossHostOs, *variables.CrossHostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) | 
| Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1496 | } | 
|  | 1497 | } | 
|  | 1498 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1499 | // Optional device targets | 
| Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1500 | if variables.DeviceArch != nil && *variables.DeviceArch != "" { | 
| Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 1501 | var target = Android | 
|  | 1502 | if Bool(variables.Fuchsia) { | 
|  | 1503 | target = Fuchsia | 
|  | 1504 | } | 
|  | 1505 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1506 | // The primary device target. | 
| Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 1507 | addTarget(target, *variables.DeviceArch, variables.DeviceArchVariant, | 
| dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1508 | variables.DeviceCpuVariant, variables.DeviceAbi, NativeBridgeDisabled, nil, nil) | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1509 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1510 | // An optional secondary device target. | 
| Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1511 | if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" { | 
|  | 1512 | addTarget(Android, *variables.DeviceSecondaryArch, | 
|  | 1513 | variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant, | 
| dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1514 | variables.DeviceSecondaryAbi, NativeBridgeDisabled, nil, nil) | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1515 | } | 
| dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1516 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1517 | // An optional NativeBridge device target. | 
| dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1518 | if variables.NativeBridgeArch != nil && *variables.NativeBridgeArch != "" { | 
|  | 1519 | addTarget(Android, *variables.NativeBridgeArch, | 
|  | 1520 | variables.NativeBridgeArchVariant, variables.NativeBridgeCpuVariant, | 
| dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1521 | variables.NativeBridgeAbi, NativeBridgeEnabled, variables.DeviceArch, | 
|  | 1522 | variables.NativeBridgeRelativePath) | 
| dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1523 | } | 
|  | 1524 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1525 | // An optional secondary NativeBridge device target. | 
| dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1526 | if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" && | 
|  | 1527 | variables.NativeBridgeSecondaryArch != nil && *variables.NativeBridgeSecondaryArch != "" { | 
|  | 1528 | addTarget(Android, *variables.NativeBridgeSecondaryArch, | 
|  | 1529 | variables.NativeBridgeSecondaryArchVariant, | 
|  | 1530 | variables.NativeBridgeSecondaryCpuVariant, | 
| dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1531 | variables.NativeBridgeSecondaryAbi, | 
|  | 1532 | NativeBridgeEnabled, | 
|  | 1533 | variables.DeviceSecondaryArch, | 
|  | 1534 | variables.NativeBridgeSecondaryRelativePath) | 
| dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1535 | } | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1536 | } | 
|  | 1537 |  | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1538 | if targetErr != nil { | 
|  | 1539 | return nil, targetErr | 
|  | 1540 | } | 
|  | 1541 |  | 
|  | 1542 | return targets, nil | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1543 | } | 
|  | 1544 |  | 
| Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1545 | // hasArmAbi returns true if arch has at least one arm ABI | 
|  | 1546 | func hasArmAbi(arch Arch) bool { | 
| Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 1547 | return PrefixInList(arch.Abi, "arm") | 
| Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1548 | } | 
|  | 1549 |  | 
| dimitry | 628db6f | 2019-05-22 17:16:21 +0200 | [diff] [blame] | 1550 | // hasArmArch returns true if targets has at least non-native_bridge arm Android arch | 
| Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 1551 | func hasArmAndroidArch(targets []Target) bool { | 
|  | 1552 | for _, target := range targets { | 
| Victor Khimenko | 1a31f80 | 2020-09-17 03:07:31 +0200 | [diff] [blame] | 1553 | if target.Os == Android && target.Arch.ArchType == Arm { | 
| Victor Khimenko | 5eb8ec1 | 2018-03-21 20:30:54 +0100 | [diff] [blame] | 1554 | return true | 
|  | 1555 | } | 
|  | 1556 | } | 
|  | 1557 | return false | 
|  | 1558 | } | 
|  | 1559 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1560 | // archConfig describes a built-in configuration. | 
| Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1561 | type archConfig struct { | 
|  | 1562 | arch        string | 
|  | 1563 | archVariant string | 
|  | 1564 | cpuVariant  string | 
|  | 1565 | abi         []string | 
|  | 1566 | } | 
|  | 1567 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1568 | // getNdkAbisConfig returns a list of archConfigs for the ABIs supported by the NDK. | 
| Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1569 | func getNdkAbisConfig() []archConfig { | 
|  | 1570 | return []archConfig{ | 
| Dan Albert | 6bba644 | 2020-01-30 15:16:49 -0800 | [diff] [blame] | 1571 | {"arm", "armv7-a", "", []string{"armeabi-v7a"}}, | 
| Tamas Petz | bca786d | 2021-01-20 18:56:33 +0100 | [diff] [blame] | 1572 | {"arm64", "armv8-a-branchprot", "", []string{"arm64-v8a"}}, | 
| Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1573 | {"x86", "", "", []string{"x86"}}, | 
|  | 1574 | {"x86_64", "", "", []string{"x86_64"}}, | 
|  | 1575 | } | 
|  | 1576 | } | 
|  | 1577 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1578 | // getAmlAbisConfig returns a list of archConfigs for the ABIs supported by mainline modules. | 
| Martin Stjernholm | c1ecc43 | 2019-11-15 15:00:31 +0000 | [diff] [blame] | 1579 | func getAmlAbisConfig() []archConfig { | 
|  | 1580 | return []archConfig{ | 
| Martin Stjernholm | 9368834 | 2020-10-16 21:45:10 +0100 | [diff] [blame] | 1581 | {"arm", "armv7-a-neon", "", []string{"armeabi-v7a"}}, | 
| Martin Stjernholm | c1ecc43 | 2019-11-15 15:00:31 +0000 | [diff] [blame] | 1582 | {"arm64", "armv8-a", "", []string{"arm64-v8a"}}, | 
|  | 1583 | {"x86", "", "", []string{"x86"}}, | 
|  | 1584 | {"x86_64", "", "", []string{"x86_64"}}, | 
|  | 1585 | } | 
|  | 1586 | } | 
|  | 1587 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1588 | // decodeArchSettings converts a list of archConfigs into a list of Targets for the given OsType. | 
| Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1589 | func decodeArchSettings(os OsType, archConfigs []archConfig) ([]Target, error) { | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1590 | var ret []Target | 
| Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1591 |  | 
| Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1592 | for _, config := range archConfigs { | 
| Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1593 | arch, err := decodeArch(os, config.arch, &config.archVariant, | 
| Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1594 | &config.cpuVariant, config.abi) | 
| Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1595 | if err != nil { | 
|  | 1596 | return nil, err | 
|  | 1597 | } | 
| Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 1598 |  | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1599 | ret = append(ret, Target{ | 
|  | 1600 | Os:   Android, | 
|  | 1601 | Arch: arch, | 
|  | 1602 | }) | 
| Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1603 | } | 
|  | 1604 |  | 
|  | 1605 | return ret, nil | 
|  | 1606 | } | 
|  | 1607 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1608 | // decodeArch converts a set of strings from product variables into an Arch struct. | 
| Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1609 | func decodeArch(os OsType, arch string, archVariant, cpuVariant *string, abi []string) (Arch, error) { | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1610 | // Verify the arch is valid | 
| Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1611 | archType, ok := archTypeMap[arch] | 
|  | 1612 | if !ok { | 
|  | 1613 | return Arch{}, fmt.Errorf("unknown arch %q", arch) | 
|  | 1614 | } | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1615 |  | 
| Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1616 | a := Arch{ | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1617 | ArchType:    archType, | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1618 | ArchVariant: String(archVariant), | 
|  | 1619 | CpuVariant:  String(cpuVariant), | 
| Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1620 | Abi:         abi, | 
| Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1621 | } | 
|  | 1622 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1623 | // Convert generic arch variants into the empty string. | 
| Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1624 | if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" { | 
|  | 1625 | a.ArchVariant = "" | 
|  | 1626 | } | 
|  | 1627 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1628 | // Convert generic CPU variants into the empty string. | 
| Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1629 | if a.CpuVariant == a.ArchType.Name || a.CpuVariant == "generic" { | 
|  | 1630 | a.CpuVariant = "" | 
|  | 1631 | } | 
|  | 1632 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1633 | // Filter empty ABIs out of the list. | 
| Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1634 | for i := 0; i < len(a.Abi); i++ { | 
|  | 1635 | if a.Abi[i] == "" { | 
|  | 1636 | a.Abi = append(a.Abi[:i], a.Abi[i+1:]...) | 
|  | 1637 | i-- | 
|  | 1638 | } | 
|  | 1639 | } | 
|  | 1640 |  | 
| Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1641 | if a.ArchVariant == "" { | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1642 | // Set ArchFeatures from the default arch features. | 
| Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1643 | if featureMap, ok := defaultArchFeatureMap[os]; ok { | 
|  | 1644 | a.ArchFeatures = featureMap[archType] | 
|  | 1645 | } | 
|  | 1646 | } else { | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1647 | // Set ArchFeatures from the arch type. | 
| Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1648 | if featureMap, ok := archFeatureMap[archType]; ok { | 
|  | 1649 | a.ArchFeatures = featureMap[a.ArchVariant] | 
|  | 1650 | } | 
| Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 1651 | } | 
|  | 1652 |  | 
| Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1653 | return a, nil | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1654 | } | 
|  | 1655 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1656 | // filterMultilibTargets takes a list of Targets and a multilib value and returns a new list of | 
|  | 1657 | // Targets containing only those that have the given multilib value. | 
| Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1658 | func filterMultilibTargets(targets []Target, multilib string) []Target { | 
|  | 1659 | var ret []Target | 
|  | 1660 | for _, t := range targets { | 
|  | 1661 | if t.Arch.ArchType.Multilib == multilib { | 
|  | 1662 | ret = append(ret, t) | 
|  | 1663 | } | 
|  | 1664 | } | 
|  | 1665 | return ret | 
|  | 1666 | } | 
|  | 1667 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1668 | // getCommonTargets returns the set of Os specific common architecture targets for each Os in a list | 
|  | 1669 | // of targets. | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 1670 | func getCommonTargets(targets []Target) []Target { | 
|  | 1671 | var ret []Target | 
|  | 1672 | set := make(map[string]bool) | 
|  | 1673 |  | 
|  | 1674 | for _, t := range targets { | 
|  | 1675 | if _, found := set[t.Os.String()]; !found { | 
|  | 1676 | set[t.Os.String()] = true | 
|  | 1677 | ret = append(ret, commonTargetMap[t.Os.String()]) | 
|  | 1678 | } | 
|  | 1679 | } | 
|  | 1680 |  | 
|  | 1681 | return ret | 
|  | 1682 | } | 
|  | 1683 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1684 | // firstTarget takes a list of Targets and a list of multilib values and returns a list of Targets | 
|  | 1685 | // that contains zero or one Target for each OsType, selecting the one that matches the earliest | 
|  | 1686 | // filter. | 
| Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1687 | func firstTarget(targets []Target, filters ...string) []Target { | 
| Jiyong Park | 2210198 | 2020-09-17 19:09:58 +0900 | [diff] [blame] | 1688 | // find the first target from each OS | 
|  | 1689 | var ret []Target | 
|  | 1690 | hasHost := false | 
|  | 1691 | set := make(map[OsType]bool) | 
|  | 1692 |  | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1693 | for _, filter := range filters { | 
|  | 1694 | buildTargets := filterMultilibTargets(targets, filter) | 
| Jiyong Park | 2210198 | 2020-09-17 19:09:58 +0900 | [diff] [blame] | 1695 | for _, t := range buildTargets { | 
|  | 1696 | if _, found := set[t.Os]; !found { | 
|  | 1697 | hasHost = hasHost || (t.Os.Class == Host) | 
|  | 1698 | set[t.Os] = true | 
|  | 1699 | ret = append(ret, t) | 
|  | 1700 | } | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1701 | } | 
|  | 1702 | } | 
| Jiyong Park | 2210198 | 2020-09-17 19:09:58 +0900 | [diff] [blame] | 1703 | return ret | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1704 | } | 
|  | 1705 |  | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1706 | // decodeMultilibTargets uses the module's multilib setting to select one or more targets from a | 
|  | 1707 | // list of Targets. | 
| Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 1708 | func decodeMultilibTargets(multilib string, targets []Target, prefer32 bool) ([]Target, error) { | 
| Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1709 | var buildTargets []Target | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1710 |  | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1711 | switch multilib { | 
|  | 1712 | case "common": | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1713 | buildTargets = getCommonTargets(targets) | 
|  | 1714 | case "common_first": | 
|  | 1715 | buildTargets = getCommonTargets(targets) | 
|  | 1716 | if prefer32 { | 
| Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1717 | buildTargets = append(buildTargets, firstTarget(targets, "lib32", "lib64")...) | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1718 | } else { | 
| Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1719 | buildTargets = append(buildTargets, firstTarget(targets, "lib64", "lib32")...) | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1720 | } | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1721 | case "both": | 
| Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 1722 | if prefer32 { | 
|  | 1723 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) | 
|  | 1724 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) | 
|  | 1725 | } else { | 
|  | 1726 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) | 
|  | 1727 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) | 
|  | 1728 | } | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1729 | case "32": | 
| Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1730 | buildTargets = filterMultilibTargets(targets, "lib32") | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1731 | case "64": | 
| Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1732 | buildTargets = filterMultilibTargets(targets, "lib64") | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1733 | case "first": | 
|  | 1734 | if prefer32 { | 
| Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1735 | buildTargets = firstTarget(targets, "lib32", "lib64") | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1736 | } else { | 
| Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1737 | buildTargets = firstTarget(targets, "lib64", "lib32") | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1738 | } | 
| Victor Chang | 9448e8f | 2020-09-14 15:34:16 +0100 | [diff] [blame] | 1739 | case "first_prefer32": | 
|  | 1740 | buildTargets = firstTarget(targets, "lib32", "lib64") | 
| Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1741 | case "prefer32": | 
| Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1742 | buildTargets = filterMultilibTargets(targets, "lib32") | 
|  | 1743 | if len(buildTargets) == 0 { | 
|  | 1744 | buildTargets = filterMultilibTargets(targets, "lib64") | 
|  | 1745 | } | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1746 | default: | 
| Victor Chang | 9448e8f | 2020-09-14 15:34:16 +0100 | [diff] [blame] | 1747 | return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", "64", "prefer32" or "first_prefer32" found %q`, | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1748 | multilib) | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1749 | } | 
|  | 1750 |  | 
| Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1751 | return buildTargets, nil | 
| Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1752 | } | 
| Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 1753 |  | 
| Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1754 | func (m *ModuleBase) getArchPropertySet(propertySet interface{}, archType ArchType) interface{} { | 
|  | 1755 | archString := archType.Field | 
|  | 1756 | for i := range m.archProperties { | 
|  | 1757 | if m.archProperties[i] == nil { | 
|  | 1758 | // Skip over nil properties | 
|  | 1759 | continue | 
|  | 1760 | } | 
|  | 1761 |  | 
|  | 1762 | // Not archProperties are usable; this function looks for properties of a very specific | 
|  | 1763 | // form, and ignores the rest. | 
|  | 1764 | for _, archProperty := range m.archProperties[i] { | 
|  | 1765 | // archPropValue is a property struct, we are looking for the form: | 
|  | 1766 | // `arch: { arm: { key: value, ... }}` | 
|  | 1767 | archPropValue := reflect.ValueOf(archProperty).Elem() | 
|  | 1768 |  | 
|  | 1769 | // Unwrap src so that it should looks like a pointer to `arm: { key: value, ... }` | 
|  | 1770 | src := archPropValue.FieldByName("Arch").Elem() | 
|  | 1771 |  | 
|  | 1772 | // Step into non-nil pointers to structs in the src value. | 
|  | 1773 | if src.Kind() == reflect.Ptr { | 
|  | 1774 | if src.IsNil() { | 
|  | 1775 | continue | 
|  | 1776 | } | 
|  | 1777 | src = src.Elem() | 
|  | 1778 | } | 
|  | 1779 |  | 
|  | 1780 | // Find the requested field (e.g. arm, x86) in the src struct. | 
|  | 1781 | src = src.FieldByName(archString) | 
|  | 1782 |  | 
|  | 1783 | // We only care about structs. | 
|  | 1784 | if !src.IsValid() || src.Kind() != reflect.Struct { | 
|  | 1785 | continue | 
|  | 1786 | } | 
|  | 1787 |  | 
|  | 1788 | // If the value of the field is a struct then step into the | 
|  | 1789 | // BlueprintEmbed field. The special "BlueprintEmbed" name is | 
|  | 1790 | // used by createArchPropTypeDesc to embed the arch properties | 
|  | 1791 | // in the parent struct, so the src arch prop should be in this | 
|  | 1792 | // field. | 
|  | 1793 | // | 
|  | 1794 | // See createArchPropTypeDesc for more details on how Arch-specific | 
|  | 1795 | // module properties are processed from the nested props and written | 
|  | 1796 | // into the module's archProperties. | 
|  | 1797 | src = src.FieldByName("BlueprintEmbed") | 
|  | 1798 |  | 
|  | 1799 | // Clone the destination prop, since we want a unique prop struct per arch. | 
|  | 1800 | propertySetClone := reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface() | 
|  | 1801 |  | 
|  | 1802 | // Copy the located property struct into the cloned destination property struct. | 
|  | 1803 | err := proptools.ExtendMatchingProperties([]interface{}{propertySetClone}, src.Interface(), nil, proptools.OrderReplace) | 
|  | 1804 | if err != nil { | 
|  | 1805 | // This is fine, it just means the src struct doesn't match the type of propertySet. | 
|  | 1806 | continue | 
|  | 1807 | } | 
|  | 1808 |  | 
|  | 1809 | return propertySetClone | 
|  | 1810 | } | 
|  | 1811 | } | 
|  | 1812 | // No property set was found specific to the given arch, so return an empty | 
|  | 1813 | // property set. | 
|  | 1814 | return reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface() | 
|  | 1815 | } | 
|  | 1816 |  | 
|  | 1817 | // getMultilibPropertySet returns a property set struct matching the type of | 
|  | 1818 | // `propertySet`, containing multilib-specific module properties for the given architecture. | 
|  | 1819 | // If no multilib-specific properties exist for the given architecture, returns an empty property | 
|  | 1820 | // set matching `propertySet`'s type. | 
|  | 1821 | func (m *ModuleBase) getMultilibPropertySet(propertySet interface{}, archType ArchType) interface{} { | 
|  | 1822 | // archType.Multilib is lowercase (for example, lib32) but property struct field is | 
|  | 1823 | // capitalized, such as Lib32, so use strings.Title to capitalize it. | 
|  | 1824 | multiLibString := strings.Title(archType.Multilib) | 
|  | 1825 |  | 
|  | 1826 | for i := range m.archProperties { | 
|  | 1827 | if m.archProperties[i] == nil { | 
|  | 1828 | // Skip over nil properties | 
|  | 1829 | continue | 
|  | 1830 | } | 
|  | 1831 |  | 
|  | 1832 | // Not archProperties are usable; this function looks for properties of a very specific | 
|  | 1833 | // form, and ignores the rest. | 
|  | 1834 | for _, archProperties := range m.archProperties[i] { | 
|  | 1835 | // archPropValue is a property struct, we are looking for the form: | 
|  | 1836 | // `multilib: { lib32: { key: value, ... }}` | 
|  | 1837 | archPropValue := reflect.ValueOf(archProperties).Elem() | 
|  | 1838 |  | 
|  | 1839 | // Unwrap src so that it should looks like a pointer to `lib32: { key: value, ... }` | 
|  | 1840 | src := archPropValue.FieldByName("Multilib").Elem() | 
|  | 1841 |  | 
|  | 1842 | // Step into non-nil pointers to structs in the src value. | 
|  | 1843 | if src.Kind() == reflect.Ptr { | 
|  | 1844 | if src.IsNil() { | 
|  | 1845 | // Ignore nil pointers. | 
|  | 1846 | continue | 
|  | 1847 | } | 
|  | 1848 | src = src.Elem() | 
|  | 1849 | } | 
|  | 1850 |  | 
|  | 1851 | // Find the requested field (e.g. lib32) in the src struct. | 
|  | 1852 | src = src.FieldByName(multiLibString) | 
|  | 1853 |  | 
|  | 1854 | // We only care about valid struct pointers. | 
|  | 1855 | if !src.IsValid() || src.Kind() != reflect.Ptr || src.Elem().Kind() != reflect.Struct { | 
|  | 1856 | continue | 
|  | 1857 | } | 
|  | 1858 |  | 
|  | 1859 | // Get the zero value for the requested property set. | 
|  | 1860 | propertySetClone := reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface() | 
|  | 1861 |  | 
|  | 1862 | // Copy the located property struct into the "zero" property set struct. | 
|  | 1863 | err := proptools.ExtendMatchingProperties([]interface{}{propertySetClone}, src.Interface(), nil, proptools.OrderReplace) | 
|  | 1864 |  | 
|  | 1865 | if err != nil { | 
|  | 1866 | // This is fine, it just means the src struct doesn't match. | 
|  | 1867 | continue | 
|  | 1868 | } | 
|  | 1869 |  | 
|  | 1870 | return propertySetClone | 
|  | 1871 | } | 
|  | 1872 | } | 
|  | 1873 |  | 
|  | 1874 | // There were no multilib properties specifically matching the given archtype. | 
|  | 1875 | // Return zeroed value. | 
|  | 1876 | return reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface() | 
|  | 1877 | } | 
|  | 1878 |  | 
| Liz Kammer | b6dbc87 | 2021-05-14 15:14:40 -0400 | [diff] [blame] | 1879 | // ArchVariantContext defines the limited context necessary to retrieve arch_variant properties. | 
|  | 1880 | type ArchVariantContext interface { | 
|  | 1881 | ModuleErrorf(fmt string, args ...interface{}) | 
|  | 1882 | PropertyErrorf(property, fmt string, args ...interface{}) | 
|  | 1883 | } | 
|  | 1884 |  | 
| Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 1885 | // GetArchProperties returns a map of architectures to the values of the | 
| Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1886 | // properties of the 'propertySet' struct that are specific to that architecture. | 
| Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 1887 | // | 
|  | 1888 | // For example, passing a struct { Foo bool, Bar string } will return an | 
|  | 1889 | // interface{} that can be type asserted back into the same struct, containing | 
|  | 1890 | // the arch specific property value specified by the module if defined. | 
| Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1891 | // | 
|  | 1892 | // Arch-specific properties may come from an arch stanza or a multilib stanza; properties | 
|  | 1893 | // in these stanzas are combined. | 
|  | 1894 | // For example: `arch: { x86: { Foo: ["bar"] } }, multilib: { lib32: {` Foo: ["baz"] } }` | 
|  | 1895 | // will result in `Foo: ["bar", "baz"]` being returned for architecture x86, if the given | 
|  | 1896 | // propertyset contains `Foo []string`. | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1897 | // | 
|  | 1898 | // Implemented in a way very similar to GetTargetProperties(). | 
| Liz Kammer | b6dbc87 | 2021-05-14 15:14:40 -0400 | [diff] [blame] | 1899 | func (m *ModuleBase) GetArchProperties(ctx ArchVariantContext, propertySet interface{}) map[ArchType]interface{} { | 
| Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 1900 | // Return value of the arch types to the prop values for that arch. | 
|  | 1901 | archToProp := map[ArchType]interface{}{} | 
|  | 1902 |  | 
|  | 1903 | // Nothing to do for non-arch-specific modules. | 
|  | 1904 | if !m.ArchSpecific() { | 
|  | 1905 | return archToProp | 
|  | 1906 | } | 
|  | 1907 |  | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1908 | dstType := reflect.ValueOf(propertySet).Type() | 
|  | 1909 | var archProperties []interface{} | 
|  | 1910 |  | 
|  | 1911 | // First find the property set in the module that corresponds to the requested | 
|  | 1912 | // one. m.archProperties[i] corresponds to m.generalProperties[i]. | 
|  | 1913 | for i, generalProp := range m.generalProperties { | 
|  | 1914 | srcType := reflect.ValueOf(generalProp).Type() | 
|  | 1915 | if srcType == dstType { | 
|  | 1916 | archProperties = m.archProperties[i] | 
|  | 1917 | break | 
|  | 1918 | } | 
|  | 1919 | } | 
|  | 1920 |  | 
|  | 1921 | if archProperties == nil { | 
|  | 1922 | // This module does not have the property set requested | 
|  | 1923 | return archToProp | 
|  | 1924 | } | 
|  | 1925 |  | 
|  | 1926 | // For each arch type (x86, arm64, etc.) | 
| Chris Parsons | c424b76 | 2021-04-29 18:06:50 -0400 | [diff] [blame] | 1927 | for _, arch := range ArchTypeList() { | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1928 | // Arch properties are sometimes sharded (see createArchPropTypeDesc() ). | 
|  | 1929 | // Iterate over ever shard and extract a struct with the same type as the | 
|  | 1930 | // input one that contains the data specific to that arch. | 
|  | 1931 | propertyStructs := make([]reflect.Value, 0) | 
|  | 1932 | for _, archProperty := range archProperties { | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1933 | archTypeStruct, ok := getArchTypeStruct(ctx, archProperty, arch) | 
|  | 1934 | if ok { | 
|  | 1935 | propertyStructs = append(propertyStructs, archTypeStruct) | 
|  | 1936 | } | 
|  | 1937 | multilibStruct, ok := getMultilibStruct(ctx, archProperty, arch) | 
|  | 1938 | if ok { | 
|  | 1939 | propertyStructs = append(propertyStructs, multilibStruct) | 
|  | 1940 | } | 
| Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 1941 | } | 
|  | 1942 |  | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1943 | // Create a new instance of the requested property set | 
|  | 1944 | value := reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface() | 
|  | 1945 |  | 
|  | 1946 | // Merge all the structs together | 
|  | 1947 | for _, propertyStruct := range propertyStructs { | 
|  | 1948 | mergePropertyStruct(ctx, value, propertyStruct) | 
|  | 1949 | } | 
|  | 1950 |  | 
|  | 1951 | archToProp[arch] = value | 
| Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 1952 | } | 
| Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1953 |  | 
| Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 1954 | return archToProp | 
|  | 1955 | } | 
| Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 1956 |  | 
| Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 1957 | // Returns a struct matching the propertySet interface, containing properties specific to the targetName | 
|  | 1958 | // For example, given these arguments: | 
|  | 1959 | //    propertySet = BaseCompilerProperties | 
|  | 1960 | //    targetName = "android_arm" | 
|  | 1961 | // And given this Android.bp fragment: | 
|  | 1962 | //    target: | 
|  | 1963 | //       android_arm: { | 
|  | 1964 | //          srcs: ["foo.c"], | 
|  | 1965 | //       } | 
|  | 1966 | //       android_arm64: { | 
|  | 1967 | //          srcs: ["bar.c"], | 
|  | 1968 | //      } | 
|  | 1969 | //    } | 
|  | 1970 | // This would return a BaseCompilerProperties with BaseCompilerProperties.Srcs = ["foo.c"] | 
|  | 1971 | func getTargetStruct(ctx ArchVariantContext, propertySet interface{}, archProperties []interface{}, targetName string) interface{} { | 
|  | 1972 | propertyStructs := make([]reflect.Value, 0) | 
|  | 1973 | for _, archProperty := range archProperties { | 
|  | 1974 | archPropValues := reflect.ValueOf(archProperty).Elem() | 
|  | 1975 | targetProp := archPropValues.FieldByName("Target").Elem() | 
|  | 1976 | targetStruct, ok := getChildPropertyStruct(ctx, targetProp, targetName, targetName) | 
|  | 1977 | if ok { | 
|  | 1978 | propertyStructs = append(propertyStructs, targetStruct) | 
|  | 1979 | } | 
|  | 1980 | } | 
|  | 1981 |  | 
|  | 1982 | // Create a new instance of the requested property set | 
|  | 1983 | value := reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface() | 
|  | 1984 |  | 
|  | 1985 | // Merge all the structs together | 
|  | 1986 | for _, propertyStruct := range propertyStructs { | 
|  | 1987 | mergePropertyStruct(ctx, value, propertyStruct) | 
|  | 1988 | } | 
|  | 1989 |  | 
|  | 1990 | return value | 
|  | 1991 | } | 
|  | 1992 |  | 
|  | 1993 | // Properties corresponds to e.g. Target: android: {...} | 
|  | 1994 | // ArchProperties corresponds to e.g. Target: android_arm: {...}, android_arm64: {...}, ... | 
|  | 1995 | type TargetProperties struct { | 
|  | 1996 | Properties     interface{} | 
|  | 1997 | ArchProperties map[ArchType]interface{} | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1998 | } | 
|  | 1999 |  | 
| Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 2000 | // GetTargetProperties returns a map of OS target (e.g. android, windows) to the | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 2001 | // values of the properties of the 'propertySet' struct that are specific to | 
|  | 2002 | // that OS target. | 
| Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 2003 | // | 
|  | 2004 | // For example, passing a struct { Foo bool, Bar string } will return an | 
|  | 2005 | // interface{} that can be type asserted back into the same struct, containing | 
|  | 2006 | // the os-specific property value specified by the module if defined. | 
|  | 2007 | // | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 2008 | // Implemented in a way very similar to GetArchProperties(). | 
| Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 2009 | // | 
|  | 2010 | // NOTE: "Target" == OS | 
|  | 2011 | func (m *ModuleBase) GetTargetProperties(ctx ArchVariantContext, propertySet interface{}) map[OsType]TargetProperties { | 
|  | 2012 | // Return value of the target types to the prop values for that target. | 
|  | 2013 | targetToProp := map[OsType]TargetProperties{} | 
| Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 2014 |  | 
| Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 2015 | // Nothing to do for non-target-specific modules. | 
| Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 2016 | if !m.ArchSpecific() { | 
| Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 2017 | return targetToProp | 
| Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 2018 | } | 
|  | 2019 |  | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 2020 | dstType := reflect.ValueOf(propertySet).Type() | 
|  | 2021 | var archProperties []interface{} | 
|  | 2022 |  | 
|  | 2023 | // First find the property set in the module that corresponds to the requested | 
|  | 2024 | // one. m.archProperties[i] corresponds to m.generalProperties[i]. | 
|  | 2025 | for i, generalProp := range m.generalProperties { | 
|  | 2026 | srcType := reflect.ValueOf(generalProp).Type() | 
|  | 2027 | if srcType == dstType { | 
|  | 2028 | archProperties = m.archProperties[i] | 
|  | 2029 | break | 
|  | 2030 | } | 
|  | 2031 | } | 
|  | 2032 |  | 
|  | 2033 | if archProperties == nil { | 
|  | 2034 | // This module does not have the property set requested | 
| Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 2035 | return targetToProp | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 2036 | } | 
|  | 2037 |  | 
| Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 2038 | // For android, linux, ... | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 2039 | for _, os := range osTypeList { | 
|  | 2040 | if os == CommonOS { | 
|  | 2041 | // It looks like this OS value is not used in Blueprint files | 
| Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 2042 | continue | 
|  | 2043 | } | 
| Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 2044 | targetProperties := TargetProperties{ | 
|  | 2045 | Properties:     getTargetStruct(ctx, propertySet, archProperties, os.Field), | 
|  | 2046 | ArchProperties: make(map[ArchType]interface{}), | 
| Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 2047 | } | 
| Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 2048 | // For arm, x86, ... | 
|  | 2049 | for _, arch := range osArchTypeMap[os] { | 
|  | 2050 | targetName := GetCompoundTargetName(os, arch) | 
|  | 2051 | targetProperties.ArchProperties[arch] = getTargetStruct(ctx, propertySet, archProperties, targetName) | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 2052 | } | 
| Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 2053 | targetToProp[os] = targetProperties | 
| Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 2054 | } | 
| Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 2055 |  | 
| Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 2056 | return targetToProp | 
| Jingwen Chen | 91220d7 | 2021-03-24 02:18:33 -0400 | [diff] [blame] | 2057 | } |