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" |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 22 | "strconv" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 23 | "strings" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 24 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 25 | "github.com/google/blueprint" |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 26 | "github.com/google/blueprint/bootstrap" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 28 | ) |
| 29 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 30 | /* |
| 31 | Example blueprints file containing all variant property groups, with comment listing what type |
| 32 | of variants get properties in that group: |
| 33 | |
| 34 | module { |
| 35 | arch: { |
| 36 | arm: { |
| 37 | // Host or device variants with arm architecture |
| 38 | }, |
| 39 | arm64: { |
| 40 | // Host or device variants with arm64 architecture |
| 41 | }, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 42 | x86: { |
| 43 | // Host or device variants with x86 architecture |
| 44 | }, |
| 45 | x86_64: { |
| 46 | // Host or device variants with x86_64 architecture |
| 47 | }, |
| 48 | }, |
| 49 | multilib: { |
| 50 | lib32: { |
| 51 | // Host or device variants for 32-bit architectures |
| 52 | }, |
| 53 | lib64: { |
| 54 | // Host or device variants for 64-bit architectures |
| 55 | }, |
| 56 | }, |
| 57 | target: { |
| 58 | android: { |
Martin Stjernholm | e284b48 | 2020-09-23 21:03:27 +0100 | [diff] [blame] | 59 | // Device variants (implies Bionic) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 60 | }, |
| 61 | host: { |
| 62 | // Host variants |
| 63 | }, |
Martin Stjernholm | e284b48 | 2020-09-23 21:03:27 +0100 | [diff] [blame] | 64 | bionic: { |
| 65 | // Bionic (device and host) variants |
| 66 | }, |
| 67 | linux_bionic: { |
| 68 | // Bionic host variants |
| 69 | }, |
| 70 | linux: { |
| 71 | // Bionic (device and host) and Linux glibc variants |
| 72 | }, |
Dan Willemsen | 5746bd4 | 2017-10-02 19:42:01 -0700 | [diff] [blame] | 73 | linux_glibc: { |
Martin Stjernholm | e284b48 | 2020-09-23 21:03:27 +0100 | [diff] [blame] | 74 | // Linux host variants (using non-Bionic libc) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 75 | }, |
| 76 | darwin: { |
| 77 | // Darwin host variants |
| 78 | }, |
| 79 | windows: { |
| 80 | // Windows host variants |
| 81 | }, |
| 82 | not_windows: { |
| 83 | // Non-windows host variants |
| 84 | }, |
Martin Stjernholm | e284b48 | 2020-09-23 21:03:27 +0100 | [diff] [blame] | 85 | android_arm: { |
| 86 | // Any <os>_<arch> combination restricts to that os and arch |
| 87 | }, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 88 | }, |
| 89 | } |
| 90 | */ |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 91 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 92 | // An Arch indicates a single CPU architecture. |
| 93 | type Arch struct { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 94 | // The type of the architecture (arm, arm64, x86, or x86_64). |
| 95 | ArchType ArchType |
| 96 | |
| 97 | // The variant of the architecture, for example "armv7-a" or "armv7-a-neon" for arm. |
| 98 | ArchVariant string |
| 99 | |
| 100 | // The variant of the CPU, for example "cortex-a53" for arm64. |
| 101 | CpuVariant string |
| 102 | |
| 103 | // The list of Android app ABIs supported by the CPU architecture, for example "arm64-v8a". |
| 104 | Abi []string |
| 105 | |
| 106 | // 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] | 107 | ArchFeatures []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 110 | // String returns the Arch as a string. The value is used as the name of the variant created |
| 111 | // by archMutator. |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 112 | func (a Arch) String() string { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 113 | s := a.ArchType.String() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 114 | if a.ArchVariant != "" { |
| 115 | s += "_" + a.ArchVariant |
| 116 | } |
| 117 | if a.CpuVariant != "" { |
| 118 | s += "_" + a.CpuVariant |
| 119 | } |
| 120 | return s |
| 121 | } |
| 122 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 123 | // ArchType is used to define the 4 supported architecture types (arm, arm64, x86, x86_64), as |
| 124 | // well as the "common" architecture used for modules that support multiple architectures, for |
| 125 | // example Java modules. |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 126 | type ArchType struct { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 127 | // Name is the name of the architecture type, "arm", "arm64", "x86", or "x86_64". |
| 128 | Name string |
| 129 | |
| 130 | // Field is the name of the field used in properties that refer to the architecture, e.g. "Arm64". |
| 131 | Field string |
| 132 | |
| 133 | // 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] | 134 | Multilib string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 135 | } |
| 136 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 137 | // String returns the name of the ArchType. |
| 138 | func (a ArchType) String() string { |
| 139 | return a.Name |
| 140 | } |
| 141 | |
| 142 | const COMMON_VARIANT = "common" |
| 143 | |
| 144 | var ( |
| 145 | archTypeList []ArchType |
| 146 | |
| 147 | Arm = newArch("arm", "lib32") |
| 148 | Arm64 = newArch("arm64", "lib64") |
| 149 | X86 = newArch("x86", "lib32") |
| 150 | X86_64 = newArch("x86_64", "lib64") |
| 151 | |
| 152 | Common = ArchType{ |
| 153 | Name: COMMON_VARIANT, |
| 154 | } |
| 155 | ) |
| 156 | |
| 157 | var archTypeMap = map[string]ArchType{} |
| 158 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 159 | func newArch(name, multilib string) ArchType { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 160 | archType := ArchType{ |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 161 | Name: name, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 162 | Field: proptools.FieldNameForProperty(name), |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 163 | Multilib: multilib, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 164 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 165 | archTypeList = append(archTypeList, archType) |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 166 | archTypeMap[name] = archType |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 167 | return archType |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 170 | // ArchTypeList returns the 4 supported ArchTypes for arm, 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) { |
| 178 | return []byte(strconv.Quote(a.String())), nil |
| 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 | } |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +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 { |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +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 ( |
| 315 | // OsTypeList contains a list of all the supported OsTypes, including ones not supported |
| 316 | // by the current build host or the target device. |
| 317 | OsTypeList []OsType |
| 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 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 350 | // 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] | 351 | type Target struct { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 352 | // Os the OS that the module is being compiled for (e.g. "linux_glibc", "android"). |
| 353 | Os OsType |
| 354 | // Arch is the architecture that the module is being compiled for. |
| 355 | Arch Arch |
| 356 | // NativeBridge is NativeBridgeEnabled if the architecture is supported using NativeBridge |
| 357 | // (i.e. arm on x86) for this device. |
| 358 | NativeBridge NativeBridgeSupport |
| 359 | // NativeBridgeHostArchName is the name of the real architecture that is used to implement |
| 360 | // the NativeBridge architecture. For example, for arm on x86 this would be "x86". |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 361 | NativeBridgeHostArchName string |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 362 | // NativeBridgeRelativePath is the name of the subdirectory that will contain NativeBridge |
| 363 | // libraries and binaries. |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 364 | NativeBridgeRelativePath string |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 365 | |
| 366 | // HostCross is true when the target cannot run natively on the current build host. |
| 367 | // For example, linux_glibc_x86 returns true on a regular x86/i686/Linux machines, but returns false |
| 368 | // on Mac (different OS), or on 64-bit only i686/Linux machines (unsupported arch). |
| 369 | HostCross bool |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 372 | // NativeBridgeSupport is an enum that specifies if a Target supports NativeBridge. |
| 373 | type NativeBridgeSupport bool |
| 374 | |
| 375 | const ( |
| 376 | NativeBridgeDisabled NativeBridgeSupport = false |
| 377 | NativeBridgeEnabled NativeBridgeSupport = true |
| 378 | ) |
| 379 | |
| 380 | // String returns the OS and arch variations used for the Target. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 381 | func (target Target) String() string { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 382 | return target.OsVariation() + "_" + target.ArchVariation() |
| 383 | } |
| 384 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 385 | // 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] | 386 | func (target Target) OsVariation() string { |
| 387 | return target.Os.String() |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 390 | // 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] | 391 | func (target Target) ArchVariation() string { |
| 392 | var variation string |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 393 | if target.NativeBridge { |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 394 | variation = "native_bridge_" |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 395 | } |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 396 | variation += target.Arch.String() |
| 397 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 398 | return variation |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 401 | // Variations returns a list of blueprint.Variations for the osMutator and archMutator for the |
| 402 | // Target. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 403 | func (target Target) Variations() []blueprint.Variation { |
| 404 | return []blueprint.Variation{ |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 405 | {Mutator: "os", Variation: target.OsVariation()}, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 406 | {Mutator: "arch", Variation: target.ArchVariation()}, |
| 407 | } |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 410 | // osMutator splits an arch-specific module into a variant for each OS that is enabled for the |
| 411 | // module. It uses the HostOrDevice value passed to InitAndroidArchModule and the |
| 412 | // device_supported and host_supported properties to determine which OsTypes are enabled for this |
| 413 | // module, then searches through the Targets to determine which have enabled Targets for this |
| 414 | // module. |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 415 | func osMutator(bpctx blueprint.BottomUpMutatorContext) { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 416 | var module Module |
| 417 | var ok bool |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 418 | if module, ok = bpctx.Module().(Module); !ok { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 419 | // The module is not a Soong module, it is a Blueprint module. |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 420 | if bootstrap.IsBootstrapModule(bpctx.Module()) { |
| 421 | // Bootstrap Go modules are always the build OS or linux bionic. |
| 422 | config := bpctx.Config().(Config) |
| 423 | osNames := []string{config.BuildOSTarget.OsVariation()} |
| 424 | for _, hostCrossTarget := range config.Targets[LinuxBionic] { |
| 425 | if hostCrossTarget.Arch.ArchType == config.BuildOSTarget.Arch.ArchType { |
| 426 | osNames = append(osNames, hostCrossTarget.OsVariation()) |
| 427 | } |
| 428 | } |
| 429 | osNames = FirstUniqueStrings(osNames) |
| 430 | bpctx.CreateVariations(osNames...) |
| 431 | } |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 432 | return |
| 433 | } |
| 434 | |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 435 | // Bootstrap Go module support above requires this mutator to be a |
| 436 | // blueprint.BottomUpMutatorContext because android.BottomUpMutatorContext |
| 437 | // filters out non-Soong modules. Now that we've handled them, create a |
| 438 | // normal android.BottomUpMutatorContext. |
| 439 | mctx := bottomUpMutatorContextFactory(bpctx, module, false) |
| 440 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 441 | base := module.base() |
| 442 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 443 | // 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] | 444 | if !base.ArchSpecific() { |
| 445 | return |
| 446 | } |
| 447 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 448 | // Collect a list of OSTypes supported by this module based on the HostOrDevice value |
| 449 | // passed to InitAndroidArchModule and the device_supported and host_supported properties. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 450 | var moduleOSList []OsType |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 451 | for _, os := range OsTypeList { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 452 | for _, t := range mctx.Config().Targets[os] { |
Colin Cross | 08d6f8f | 2020-11-19 02:33:19 +0000 | [diff] [blame] | 453 | if base.supportsTarget(t) { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 454 | moduleOSList = append(moduleOSList, os) |
| 455 | break |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 456 | } |
| 457 | } |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 460 | // If there are no supported OSes then disable the module. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 461 | if len(moduleOSList) == 0 { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 462 | base.Disable() |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 463 | return |
| 464 | } |
| 465 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 466 | // Convert the list of supported OsTypes to the variation names. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 467 | osNames := make([]string, len(moduleOSList)) |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 468 | for i, os := range moduleOSList { |
| 469 | osNames[i] = os.String() |
| 470 | } |
| 471 | |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 472 | createCommonOSVariant := base.commonProperties.CreateCommonOSVariant |
| 473 | if createCommonOSVariant { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 474 | // 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] | 475 | // create. It needs to be added to the end because it needs to depend on the |
| 476 | // the other variants in the list returned by CreateVariations(...) and inter |
| 477 | // variant dependencies can only be created from a later variant in that list to |
| 478 | // an earlier one. That is because variants are always processed in the order in |
| 479 | // which they are returned from CreateVariations(...). |
| 480 | osNames = append(osNames, CommonOS.Name) |
| 481 | moduleOSList = append(moduleOSList, CommonOS) |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 484 | // Create the variations, annotate each one with which OS it was created for, and |
| 485 | // squash the appropriate OS-specific properties into the top level properties. |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 486 | modules := mctx.CreateVariations(osNames...) |
| 487 | for i, m := range modules { |
| 488 | m.base().commonProperties.CompileOS = moduleOSList[i] |
| 489 | m.base().setOSProperties(mctx) |
| 490 | } |
| 491 | |
| 492 | if createCommonOSVariant { |
| 493 | // A CommonOS variant was requested so add dependencies from it (the last one in |
| 494 | // the list) to the OS type specific variants. |
| 495 | last := len(modules) - 1 |
| 496 | commonOSVariant := modules[last] |
| 497 | commonOSVariant.base().commonProperties.CommonOSVariant = true |
| 498 | for _, module := range modules[0:last] { |
| 499 | // Ignore modules that are enabled. Note, this will only avoid adding |
| 500 | // dependencies on OsType variants that are explicitly disabled in their |
| 501 | // properties. The CommonOS variant will still depend on disabled variants |
| 502 | // if they are disabled afterwards, e.g. in archMutator if |
| 503 | if module.Enabled() { |
| 504 | mctx.AddInterVariantDependency(commonOsToOsSpecificVariantTag, commonOSVariant, module) |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | |
Colin Cross | c179ea6 | 2020-10-09 10:54:15 -0700 | [diff] [blame] | 510 | type archDepTag struct { |
| 511 | blueprint.BaseDependencyTag |
| 512 | name string |
| 513 | } |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 514 | |
Colin Cross | c179ea6 | 2020-10-09 10:54:15 -0700 | [diff] [blame] | 515 | // Identifies the dependency from CommonOS variant to the os specific variants. |
| 516 | var commonOsToOsSpecificVariantTag = archDepTag{name: "common os to os specific"} |
| 517 | |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 518 | // Get the OsType specific variants for the current CommonOS variant. |
| 519 | // |
| 520 | // The returned list will only contain enabled OsType specific variants of the |
| 521 | // module referenced in the supplied context. An empty list is returned if there |
| 522 | // are no enabled variants or the supplied context is not for an CommonOS |
| 523 | // variant. |
| 524 | func GetOsSpecificVariantsOfCommonOSVariant(mctx BaseModuleContext) []Module { |
| 525 | var variants []Module |
| 526 | mctx.VisitDirectDeps(func(m Module) { |
| 527 | if mctx.OtherModuleDependencyTag(m) == commonOsToOsSpecificVariantTag { |
| 528 | if m.Enabled() { |
| 529 | variants = append(variants, m) |
| 530 | } |
| 531 | } |
| 532 | }) |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 533 | return variants |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 536 | // 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] | 537 | // for a module is in three levels, OsClass, multilib, and then Target. |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 538 | // OsClass selection is determined by: |
| 539 | // - The HostOrDeviceSupported value passed in to InitAndroidArchModule by the module type factory, which selects |
| 540 | // whether the module type can compile for host, device or both. |
| 541 | // - The host_supported and device_supported properties on the module. |
Roland Levillain | f5b635d | 2019-06-05 14:42:57 +0100 | [diff] [blame] | 542 | // 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] | 543 | // for the module, the Device OsClass is selected. |
| 544 | // Within each selected OsClass, the multilib selection is determined by: |
Jaewoong Jung | 02b2d4d | 2019-06-06 15:19:57 -0700 | [diff] [blame] | 545 | // - 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] | 546 | // target.host.compile_multilib). |
| 547 | // - The default multilib passed to InitAndroidArchModule if compile_multilib was not set. |
| 548 | // Valid multilib values include: |
| 549 | // "both": compile for all Targets supported by the OsClass (generally x86_64 and x86, or arm64 and arm). |
| 550 | // "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] | 551 | // but may be arm for a 32-bit only build. |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 552 | // "32": compile for only a single 32-bit Target supported by the OsClass. |
| 553 | // "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] | 554 | // "common": compile a for a single Target that will work on all Targets supported by the OsClass (for example Java). |
| 555 | // "common_first": compile a for a Target that will work on all Targets supported by the OsClass |
| 556 | // (same as "common"), plus a second Target for the preferred Target supported by the OsClass |
| 557 | // (same as "first"). This is used for java_binary that produces a common .jar and a wrapper |
| 558 | // executable script. |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 559 | // |
| 560 | // Once the list of Targets is determined, the module is split into a variant for each Target. |
| 561 | // |
| 562 | // Modules can be initialized with InitAndroidMultiTargetsArchModule, in which case they will be split by OsClass, |
| 563 | // 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] | 564 | func archMutator(bpctx blueprint.BottomUpMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 565 | var module Module |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 566 | var ok bool |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 567 | if module, ok = bpctx.Module().(Module); !ok { |
| 568 | if bootstrap.IsBootstrapModule(bpctx.Module()) { |
| 569 | // Bootstrap Go modules are always the build architecture. |
| 570 | bpctx.CreateVariations(bpctx.Config().(Config).BuildOSTarget.ArchVariation()) |
| 571 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 572 | return |
| 573 | } |
| 574 | |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 575 | // Bootstrap Go module support above requires this mutator to be a |
| 576 | // blueprint.BottomUpMutatorContext because android.BottomUpMutatorContext |
| 577 | // filters out non-Soong modules. Now that we've handled them, create a |
| 578 | // normal android.BottomUpMutatorContext. |
| 579 | mctx := bottomUpMutatorContextFactory(bpctx, module, false) |
| 580 | |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 581 | base := module.base() |
| 582 | |
| 583 | if !base.ArchSpecific() { |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 584 | return |
| 585 | } |
| 586 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 587 | os := base.commonProperties.CompileOS |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 588 | if os == CommonOS { |
| 589 | // Make sure that the target related properties are initialized for the |
| 590 | // CommonOS variant. |
| 591 | addTargetProperties(module, commonTargetMap[os.Name], nil, true) |
| 592 | |
| 593 | // Do not create arch specific variants for the CommonOS variant. |
| 594 | return |
| 595 | } |
| 596 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 597 | osTargets := mctx.Config().Targets[os] |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 598 | image := base.commonProperties.ImageVariation |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 599 | // Filter NativeBridge targets unless they are explicitly supported. |
| 600 | // Skip creating native bridge variants for non-core modules. |
Colin Cross | 83bead4 | 2019-12-18 10:45:46 -0800 | [diff] [blame] | 601 | if os == Android && |
| 602 | !(Bool(base.commonProperties.Native_bridge_supported) && image == CoreVariation) { |
| 603 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 604 | var targets []Target |
| 605 | for _, t := range osTargets { |
| 606 | if !t.NativeBridge { |
| 607 | targets = append(targets, t) |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 608 | } |
| 609 | } |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 610 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 611 | osTargets = targets |
| 612 | } |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 613 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 614 | // only the primary arch in the ramdisk / vendor_ramdisk / recovery partition |
| 615 | if os == Android && (module.InstallInRecovery() || module.InstallInRamdisk() || module.InstallInVendorRamdisk()) { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 616 | osTargets = []Target{osTargets[0]} |
| 617 | } |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 618 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 619 | // Some modules want compile_multilib: "first" to mean 32-bit, not 64-bit. |
| 620 | // This is used for Windows support and for HOST_PREFER_32_BIT=true support for Art modules. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 621 | prefer32 := false |
| 622 | if base.prefer32 != nil { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 623 | prefer32 = base.prefer32(mctx, base, os) |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 624 | } |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 625 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 626 | // Determine the multilib selection for this module. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 627 | multilib, extraMultilib := decodeMultilib(base, os.Class) |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 628 | |
| 629 | // Convert the multilib selection into a list of Targets. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 630 | targets, err := decodeMultilibTargets(multilib, osTargets, prefer32) |
| 631 | if err != nil { |
| 632 | mctx.ModuleErrorf("%s", err.Error()) |
| 633 | } |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 634 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 635 | // If the module is using extraMultilib, decode the extraMultilib selection into |
| 636 | // a separate list of Targets. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 637 | var multiTargets []Target |
| 638 | if extraMultilib != "" { |
| 639 | multiTargets, err = decodeMultilibTargets(extraMultilib, osTargets, prefer32) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 640 | if err != nil { |
| 641 | mctx.ModuleErrorf("%s", err.Error()) |
| 642 | } |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 643 | } |
| 644 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 645 | // Recovery is always the primary architecture, filter out any other architectures. |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 646 | if image == RecoveryVariation { |
| 647 | primaryArch := mctx.Config().DevicePrimaryArchType() |
| 648 | targets = filterToArch(targets, primaryArch) |
| 649 | multiTargets = filterToArch(multiTargets, primaryArch) |
| 650 | } |
| 651 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 652 | // If there are no supported targets disable the module. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 653 | if len(targets) == 0 { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 654 | base.Disable() |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 655 | return |
| 656 | } |
| 657 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 658 | // Convert the targets into a list of arch variation names. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 659 | targetNames := make([]string, len(targets)) |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 660 | for i, target := range targets { |
| 661 | targetNames[i] = target.ArchVariation() |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 664 | // Create the variations, annotate each one with which Target it was created for, and |
| 665 | // squash the appropriate arch-specific properties into the top level properties. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 666 | modules := mctx.CreateVariations(targetNames...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 667 | for i, m := range modules { |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 668 | addTargetProperties(m, targets[i], multiTargets, i == 0) |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 669 | m.base().setArchProperties(mctx) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 673 | // addTargetProperties annotates a variant with the Target is is being compiled for, the list |
| 674 | // of additional Targets it is supporting (if any), and whether it is the primary Target for |
| 675 | // the module. |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 676 | func addTargetProperties(m Module, target Target, multiTargets []Target, primaryTarget bool) { |
| 677 | m.base().commonProperties.CompileTarget = target |
| 678 | m.base().commonProperties.CompileMultiTargets = multiTargets |
| 679 | m.base().commonProperties.CompilePrimary = primaryTarget |
| 680 | } |
| 681 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 682 | // decodeMultilib returns the appropriate compile_multilib property for the module, or the default |
| 683 | // multilib from the factory's call to InitAndroidArchModule if none was set. For modules that |
| 684 | // called InitAndroidMultiTargetsArchModule it always returns "common" for multilib, and returns |
| 685 | // the actual multilib in extraMultilib. |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 686 | func decodeMultilib(base *ModuleBase, class OsClass) (multilib, extraMultilib string) { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 687 | // First check the "android.compile_multilib" or "host.compile_multilib" properties. |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 688 | switch class { |
| 689 | case Device: |
| 690 | multilib = String(base.commonProperties.Target.Android.Compile_multilib) |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 691 | case Host: |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 692 | multilib = String(base.commonProperties.Target.Host.Compile_multilib) |
| 693 | } |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 694 | |
| 695 | // If those aren't set, try the "compile_multilib" property. |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 696 | if multilib == "" { |
| 697 | multilib = String(base.commonProperties.Compile_multilib) |
| 698 | } |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 699 | |
| 700 | // 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] | 701 | if multilib == "" { |
| 702 | multilib = base.commonProperties.Default_multilib |
| 703 | } |
| 704 | |
| 705 | if base.commonProperties.UseTargetVariants { |
| 706 | return multilib, "" |
| 707 | } else { |
| 708 | // For app modules a single arch variant will be created per OS class which is expected to handle all the |
| 709 | // selected arches. Return the common-type as multilib and any Android.bp provided multilib as extraMultilib |
| 710 | if multilib == base.commonProperties.Default_multilib { |
| 711 | multilib = "first" |
| 712 | } |
| 713 | return base.commonProperties.Default_multilib, multilib |
| 714 | } |
| 715 | } |
| 716 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 717 | // filterToArch takes a list of Targets and an ArchType, and returns a modified list that contains |
| 718 | // only Targets that have the specified ArchType. |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 719 | func filterToArch(targets []Target, arch ArchType) []Target { |
| 720 | for i := 0; i < len(targets); i++ { |
| 721 | if targets[i].Arch.ArchType != arch { |
| 722 | targets = append(targets[:i], targets[i+1:]...) |
| 723 | i-- |
| 724 | } |
| 725 | } |
| 726 | return targets |
| 727 | } |
| 728 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 729 | // archPropRoot is a struct type used as the top level of the arch-specific properties. It |
| 730 | // contains the "arch", "multilib", and "target" property structs. It is used to split up the |
| 731 | // property structs to limit how much is allocated when a single arch-specific property group is |
| 732 | // 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] | 733 | type archPropRoot struct { |
| 734 | Arch, Multilib, Target interface{} |
| 735 | } |
| 736 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 737 | // archPropTypeDesc holds the runtime-created types for the property structs to instantiate to |
| 738 | // create an archPropRoot property struct. |
| 739 | type archPropTypeDesc struct { |
| 740 | arch, multilib, target reflect.Type |
| 741 | } |
| 742 | |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 743 | // createArchPropTypeDesc takes a reflect.Type that is either a struct or a pointer to a struct, and |
| 744 | // returns lists of reflect.Types that contains the arch-variant properties inside structs for each |
| 745 | // arch, multilib and target property. |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 746 | // |
| 747 | // This is a relatively expensive operation, so the results are cached in the global |
| 748 | // archPropTypeMap. It is constructed entirely based on compile-time data, so there is no need |
| 749 | // to isolate the results between multiple tests running in parallel. |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 750 | func createArchPropTypeDesc(props reflect.Type) []archPropTypeDesc { |
Colin Cross | b1d8c99 | 2020-01-21 11:43:29 -0800 | [diff] [blame] | 751 | // Each property struct shard will be nested many times under the runtime generated arch struct, |
| 752 | // which can hit the limit of 64kB for the name of runtime generated structs. They are nested |
| 753 | // 97 times now, which may grow in the future, plus there is some overhead for the containing |
| 754 | // type. This number may need to be reduced if too many are added, but reducing it too far |
| 755 | // could cause problems if a single deeply nested property no longer fits in the name. |
| 756 | const maxArchTypeNameSize = 500 |
| 757 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 758 | // Convert the type to a new set of types that contains only the arch-specific properties |
| 759 | // (those that are tagged with `android:"arch_specific"`), and sharded into multiple types |
| 760 | // to keep the runtime-generated names under the limit. |
Colin Cross | b1d8c99 | 2020-01-21 11:43:29 -0800 | [diff] [blame] | 761 | propShards, _ := proptools.FilterPropertyStructSharded(props, maxArchTypeNameSize, filterArchStruct) |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 762 | |
| 763 | // 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] | 764 | if len(propShards) == 0 { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 765 | return nil |
| 766 | } |
| 767 | |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 768 | var ret []archPropTypeDesc |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 769 | for _, props := range propShards { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 770 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 771 | // variantFields takes a list of variant property field names and returns a list the |
| 772 | // StructFields with the names and the type of the current shard. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 773 | variantFields := func(names []string) []reflect.StructField { |
| 774 | ret := make([]reflect.StructField, len(names)) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 775 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 776 | for i, name := range names { |
| 777 | ret[i].Name = name |
| 778 | ret[i].Type = props |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 779 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 780 | |
| 781 | return ret |
| 782 | } |
| 783 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 784 | // Create a type that contains the properties in this shard repeated for each |
| 785 | // architecture, architecture variant, and architecture feature. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 786 | archFields := make([]reflect.StructField, len(archTypeList)) |
| 787 | for i, arch := range archTypeList { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 788 | var variants []string |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 789 | |
| 790 | for _, archVariant := range archVariants[arch] { |
| 791 | archVariant := variantReplacer.Replace(archVariant) |
| 792 | variants = append(variants, proptools.FieldNameForProperty(archVariant)) |
| 793 | } |
| 794 | for _, feature := range archFeatures[arch] { |
| 795 | feature := variantReplacer.Replace(feature) |
| 796 | variants = append(variants, proptools.FieldNameForProperty(feature)) |
| 797 | } |
| 798 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 799 | // Create the StructFields for each architecture variant architecture feature |
| 800 | // (e.g. "arch.arm.cortex-a53" or "arch.arm.neon"). |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 801 | fields := variantFields(variants) |
| 802 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 803 | // Create the StructField for the architecture itself (e.g. "arch.arm"). The special |
| 804 | // "BlueprintEmbed" name is used by Blueprint to put the properties in the |
| 805 | // parent struct. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 806 | fields = append([]reflect.StructField{{ |
| 807 | Name: "BlueprintEmbed", |
| 808 | Type: props, |
| 809 | Anonymous: true, |
| 810 | }}, fields...) |
| 811 | |
| 812 | archFields[i] = reflect.StructField{ |
| 813 | Name: arch.Field, |
| 814 | Type: reflect.StructOf(fields), |
| 815 | } |
| 816 | } |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 817 | |
| 818 | // Create the type of the "arch" property struct for this shard. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 819 | archType := reflect.StructOf(archFields) |
| 820 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 821 | // Create the type for the "multilib" property struct for this shard, containing the |
| 822 | // "multilib.lib32" and "multilib.lib64" property structs. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 823 | multilibType := reflect.StructOf(variantFields([]string{"Lib32", "Lib64"})) |
| 824 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 825 | // Start with a list of the special targets |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 826 | targets := []string{ |
| 827 | "Host", |
| 828 | "Android64", |
| 829 | "Android32", |
| 830 | "Bionic", |
| 831 | "Linux", |
| 832 | "Not_windows", |
| 833 | "Arm_on_x86", |
| 834 | "Arm_on_x86_64", |
Victor Khimenko | c26fcf4 | 2020-05-07 22:16:33 +0200 | [diff] [blame] | 835 | "Native_bridge", |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 836 | } |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 837 | for _, os := range OsTypeList { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 838 | // Add all the OSes. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 839 | targets = append(targets, os.Field) |
| 840 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 841 | // Add the OS/Arch combinations, e.g. "android_arm64". |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 842 | for _, archType := range osArchTypeMap[os] { |
| 843 | targets = append(targets, os.Field+"_"+archType.Name) |
| 844 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 845 | // Also add the special "linux_<arch>" and "bionic_<arch>" property structs. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 846 | if os.Linux() { |
| 847 | target := "Linux_" + archType.Name |
| 848 | if !InList(target, targets) { |
| 849 | targets = append(targets, target) |
| 850 | } |
| 851 | } |
| 852 | if os.Bionic() { |
| 853 | target := "Bionic_" + archType.Name |
| 854 | if !InList(target, targets) { |
| 855 | targets = append(targets, target) |
| 856 | } |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 857 | } |
| 858 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 859 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 860 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 861 | // Create the type for the "target" property struct for this shard. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 862 | targetType := reflect.StructOf(variantFields(targets)) |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 863 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 864 | // Return a descriptor of the 3 runtime-created types. |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 865 | ret = append(ret, archPropTypeDesc{ |
| 866 | arch: reflect.PtrTo(archType), |
| 867 | multilib: reflect.PtrTo(multilibType), |
| 868 | target: reflect.PtrTo(targetType), |
| 869 | }) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 870 | } |
| 871 | return ret |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 874 | // variantReplacer converts architecture variant or architecture feature names into names that |
| 875 | // are valid for an Android.bp file. |
| 876 | var variantReplacer = strings.NewReplacer("-", "_", ".", "_") |
| 877 | |
| 878 | // filterArchStruct returns true if the given field is an architecture specific property. |
Colin Cross | 7444910 | 2019-09-25 11:26:40 -0700 | [diff] [blame] | 879 | func filterArchStruct(field reflect.StructField, prefix string) (bool, reflect.StructField) { |
| 880 | if proptools.HasTag(field, "android", "arch_variant") { |
| 881 | // The arch_variant field isn't necessary past this point |
| 882 | // Instead of wasting space, just remove it. Go also has a |
| 883 | // 16-bit limit on structure name length. The name is constructed |
| 884 | // based on the Go source representation of the structure, so |
| 885 | // the tag names count towards that length. |
Colin Cross | b4fecbf | 2020-01-21 11:38:47 -0800 | [diff] [blame] | 886 | |
| 887 | androidTag := field.Tag.Get("android") |
| 888 | values := strings.Split(androidTag, ",") |
| 889 | |
| 890 | if string(field.Tag) != `android:"`+strings.Join(values, ",")+`"` { |
| 891 | panic(fmt.Errorf("unexpected tag format %q", field.Tag)) |
Colin Cross | 7444910 | 2019-09-25 11:26:40 -0700 | [diff] [blame] | 892 | } |
Colin Cross | b4fecbf | 2020-01-21 11:38:47 -0800 | [diff] [blame] | 893 | // these tags don't need to be present in the runtime generated struct type. |
| 894 | values = RemoveListFromList(values, []string{"arch_variant", "variant_prepend", "path"}) |
| 895 | if len(values) > 0 { |
| 896 | panic(fmt.Errorf("unknown tags %q in field %q", values, prefix+field.Name)) |
| 897 | } |
| 898 | |
| 899 | field.Tag = "" |
Colin Cross | 7444910 | 2019-09-25 11:26:40 -0700 | [diff] [blame] | 900 | return true, field |
| 901 | } |
| 902 | return false, field |
| 903 | } |
| 904 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 905 | // archPropTypeMap contains a cache of the results of createArchPropTypeDesc for each type. It is |
| 906 | // shared across all Contexts, but is constructed based only on compile-time information so there |
| 907 | // is no risk of contaminating one Context with data from another. |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 908 | var archPropTypeMap OncePer |
| 909 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 910 | // initArchModule adds the architecture-specific property structs to a Module. |
| 911 | func initArchModule(m Module) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 912 | |
| 913 | base := m.base() |
| 914 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 915 | // Store the original list of top level property structs |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 916 | base.generalProperties = m.GetProperties() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 917 | |
| 918 | for _, properties := range base.generalProperties { |
| 919 | propertiesValue := reflect.ValueOf(properties) |
Colin Cross | 62496a0 | 2016-08-08 15:49:17 -0700 | [diff] [blame] | 920 | t := propertiesValue.Type() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 921 | if propertiesValue.Kind() != reflect.Ptr { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 922 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 923 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | propertiesValue = propertiesValue.Elem() |
| 927 | if propertiesValue.Kind() != reflect.Struct { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 928 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 929 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 930 | } |
| 931 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 932 | // 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] | 933 | archPropTypes := archPropTypeMap.Once(NewCustomOnceKey(t), func() interface{} { |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 934 | return createArchPropTypeDesc(t) |
| 935 | }).([]archPropTypeDesc) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 936 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 937 | // Instantiate one of each arch-specific property struct type and add it to the |
| 938 | // properties for the Module. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 939 | var archProperties []interface{} |
| 940 | for _, t := range archPropTypes { |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 941 | archProperties = append(archProperties, &archPropRoot{ |
| 942 | Arch: reflect.Zero(t.arch).Interface(), |
| 943 | Multilib: reflect.Zero(t.multilib).Interface(), |
| 944 | Target: reflect.Zero(t.target).Interface(), |
| 945 | }) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 946 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 947 | base.archProperties = append(base.archProperties, archProperties) |
| 948 | m.AddProperties(archProperties...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 949 | } |
| 950 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 951 | // Update the list of properties that can be set by a defaults module or a call to |
| 952 | // AppendMatchingProperties or PrependMatchingProperties. |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 953 | base.customizableProperties = m.GetProperties() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 954 | } |
| 955 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 956 | // appendProperties squashes properties from the given field of the given src property struct |
| 957 | // into the dst property struct. Returns the reflect.Value of the field in the src property |
| 958 | // struct to be used for further appendProperties calls on fields of that property struct. |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 959 | func (m *ModuleBase) appendProperties(ctx BottomUpMutatorContext, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 960 | dst interface{}, src reflect.Value, field, srcPrefix string) reflect.Value { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 961 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 962 | // Step into non-nil pointers to structs in the src value. |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 963 | if src.Kind() == reflect.Ptr { |
| 964 | if src.IsNil() { |
| 965 | return src |
| 966 | } |
| 967 | src = src.Elem() |
| 968 | } |
| 969 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 970 | // Find the requested field in the src struct. |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 971 | src = src.FieldByName(field) |
| 972 | if !src.IsValid() { |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 973 | ctx.ModuleErrorf("field %q does not exist", srcPrefix) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 974 | return src |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 975 | } |
| 976 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 977 | // Save the value of the field in the src struct to return. |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 978 | ret := src |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 979 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 980 | // If the value of the field is a struct (as opposed to a pointer to a struct) then step |
| 981 | // into the BlueprintEmbed field. |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 982 | if src.Kind() == reflect.Struct { |
| 983 | src = src.FieldByName("BlueprintEmbed") |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 984 | } |
| 985 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 986 | // order checks the `android:"variant_prepend"` tag to handle properties where the |
| 987 | // arch-specific value needs to come before the generic value, for example for lists of |
| 988 | // include directories. |
Colin Cross | 6ee75b6 | 2016-05-05 15:57:15 -0700 | [diff] [blame] | 989 | order := func(property string, |
| 990 | dstField, srcField reflect.StructField, |
| 991 | dstValue, srcValue interface{}) (proptools.Order, error) { |
| 992 | if proptools.HasTag(dstField, "android", "variant_prepend") { |
| 993 | return proptools.Prepend, nil |
| 994 | } else { |
| 995 | return proptools.Append, nil |
| 996 | } |
| 997 | } |
| 998 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 999 | // Squash the located property struct into the destination property struct. |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1000 | err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, order) |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1001 | if err != nil { |
| 1002 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
| 1003 | ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
| 1004 | } else { |
| 1005 | panic(err) |
| 1006 | } |
| 1007 | } |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 1008 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1009 | return ret |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1012 | // Squash the appropriate OS-specific property structs into the matching top level property structs |
| 1013 | // based on the CompileOS value that was annotated on the variant. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1014 | func (m *ModuleBase) setOSProperties(ctx BottomUpMutatorContext) { |
| 1015 | os := m.commonProperties.CompileOS |
| 1016 | |
| 1017 | for i := range m.generalProperties { |
| 1018 | genProps := m.generalProperties[i] |
| 1019 | if m.archProperties[i] == nil { |
| 1020 | continue |
| 1021 | } |
| 1022 | for _, archProperties := range m.archProperties[i] { |
| 1023 | archPropValues := reflect.ValueOf(archProperties).Elem() |
| 1024 | |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1025 | targetProp := archPropValues.FieldByName("Target").Elem() |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1026 | |
| 1027 | // Handle host-specific properties in the form: |
| 1028 | // target: { |
| 1029 | // host: { |
| 1030 | // key: value, |
| 1031 | // }, |
| 1032 | // }, |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1033 | if os.Class == Host { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1034 | field := "Host" |
| 1035 | prefix := "target.host" |
| 1036 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1037 | } |
| 1038 | |
| 1039 | // Handle target OS generalities of the form: |
| 1040 | // target: { |
| 1041 | // bionic: { |
| 1042 | // key: value, |
| 1043 | // }, |
| 1044 | // } |
| 1045 | if os.Linux() { |
| 1046 | field := "Linux" |
| 1047 | prefix := "target.linux" |
| 1048 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1049 | } |
| 1050 | |
| 1051 | if os.Bionic() { |
| 1052 | field := "Bionic" |
| 1053 | prefix := "target.bionic" |
| 1054 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1055 | } |
| 1056 | |
| 1057 | // Handle target OS properties in the form: |
| 1058 | // target: { |
| 1059 | // linux_glibc: { |
| 1060 | // key: value, |
| 1061 | // }, |
| 1062 | // not_windows: { |
| 1063 | // key: value, |
| 1064 | // }, |
| 1065 | // android { |
| 1066 | // key: value, |
| 1067 | // }, |
| 1068 | // }, |
| 1069 | field := os.Field |
| 1070 | prefix := "target." + os.Name |
| 1071 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1072 | |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1073 | if os.Class == Host && os != Windows { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1074 | field := "Not_windows" |
| 1075 | prefix := "target.not_windows" |
| 1076 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1077 | } |
| 1078 | |
| 1079 | // Handle 64-bit device properties in the form: |
| 1080 | // target { |
| 1081 | // android64 { |
| 1082 | // key: value, |
| 1083 | // }, |
| 1084 | // android32 { |
| 1085 | // key: value, |
| 1086 | // }, |
| 1087 | // }, |
| 1088 | // WARNING: this is probably not what you want to use in your blueprints file, it selects |
| 1089 | // options for all targets on a device that supports 64-bit binaries, not just the targets |
| 1090 | // that are being compiled for 64-bit. Its expected use case is binaries like linker and |
| 1091 | // debuggerd that need to know when they are a 32-bit process running on a 64-bit device |
| 1092 | if os.Class == Device { |
| 1093 | if ctx.Config().Android64() { |
| 1094 | field := "Android64" |
| 1095 | prefix := "target.android64" |
| 1096 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1097 | } else { |
| 1098 | field := "Android32" |
| 1099 | prefix := "target.android32" |
| 1100 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1107 | // Squash the appropriate arch-specific property structs into the matching top level property |
| 1108 | // structs based on the CompileTarget value that was annotated on the variant. |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1109 | func (m *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) { |
| 1110 | arch := m.Arch() |
| 1111 | os := m.Os() |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 1112 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1113 | for i := range m.generalProperties { |
| 1114 | genProps := m.generalProperties[i] |
| 1115 | if m.archProperties[i] == nil { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1116 | continue |
| 1117 | } |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1118 | for _, archProperties := range m.archProperties[i] { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1119 | archPropValues := reflect.ValueOf(archProperties).Elem() |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1120 | |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1121 | archProp := archPropValues.FieldByName("Arch").Elem() |
| 1122 | multilibProp := archPropValues.FieldByName("Multilib").Elem() |
| 1123 | targetProp := archPropValues.FieldByName("Target").Elem() |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1124 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1125 | // Handle arch-specific properties in the form: |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1126 | // arch: { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1127 | // arm64: { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1128 | // key: value, |
| 1129 | // }, |
| 1130 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1131 | t := arch.ArchType |
| 1132 | |
| 1133 | if arch.ArchType != Common { |
| 1134 | field := proptools.FieldNameForProperty(t.Name) |
| 1135 | prefix := "arch." + t.Name |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1136 | archStruct := m.appendProperties(ctx, genProps, archProp, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1137 | |
| 1138 | // Handle arch-variant-specific properties in the form: |
| 1139 | // arch: { |
| 1140 | // variant: { |
| 1141 | // key: value, |
| 1142 | // }, |
| 1143 | // }, |
| 1144 | v := variantReplacer.Replace(arch.ArchVariant) |
| 1145 | if v != "" { |
| 1146 | field := proptools.FieldNameForProperty(v) |
| 1147 | prefix := "arch." + t.Name + "." + v |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1148 | m.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | // Handle cpu-variant-specific properties in the form: |
| 1152 | // arch: { |
| 1153 | // variant: { |
| 1154 | // key: value, |
| 1155 | // }, |
| 1156 | // }, |
| 1157 | if arch.CpuVariant != arch.ArchVariant { |
| 1158 | c := variantReplacer.Replace(arch.CpuVariant) |
| 1159 | if c != "" { |
| 1160 | field := proptools.FieldNameForProperty(c) |
| 1161 | prefix := "arch." + t.Name + "." + c |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1162 | m.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | // Handle arch-feature-specific properties in the form: |
| 1167 | // arch: { |
| 1168 | // feature: { |
| 1169 | // key: value, |
| 1170 | // }, |
| 1171 | // }, |
| 1172 | for _, feature := range arch.ArchFeatures { |
| 1173 | field := proptools.FieldNameForProperty(feature) |
| 1174 | prefix := "arch." + t.Name + "." + feature |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1175 | m.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | // Handle multilib-specific properties in the form: |
| 1179 | // multilib: { |
| 1180 | // lib32: { |
| 1181 | // key: value, |
| 1182 | // }, |
| 1183 | // }, |
| 1184 | field = proptools.FieldNameForProperty(t.Multilib) |
| 1185 | prefix = "multilib." + t.Multilib |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1186 | m.appendProperties(ctx, genProps, multilibProp, field, prefix) |
Colin Cross | 0801633 | 2016-12-20 09:53:14 -0800 | [diff] [blame] | 1187 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1188 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1189 | // Handle combined OS-feature and arch specific properties in the form: |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1190 | // target: { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1191 | // bionic_x86: { |
| 1192 | // key: value, |
| 1193 | // }, |
| 1194 | // } |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1195 | if os.Linux() && arch.ArchType != Common { |
| 1196 | field := "Linux_" + arch.ArchType.Name |
| 1197 | prefix := "target.linux_" + arch.ArchType.Name |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1198 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1199 | } |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 1200 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1201 | if os.Bionic() && arch.ArchType != Common { |
| 1202 | field := "Bionic_" + t.Name |
| 1203 | prefix := "target.bionic_" + t.Name |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1204 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1207 | // Handle combined OS and arch specific properties in the form: |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1208 | // target: { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1209 | // linux_glibc_x86: { |
| 1210 | // key: value, |
| 1211 | // }, |
| 1212 | // linux_glibc_arm: { |
| 1213 | // key: value, |
| 1214 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1215 | // android_arm { |
| 1216 | // key: value, |
| 1217 | // }, |
| 1218 | // android_x86 { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1219 | // key: value, |
| 1220 | // }, |
| 1221 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1222 | if arch.ArchType != Common { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1223 | field := os.Field + "_" + t.Name |
| 1224 | prefix := "target." + os.Name + "_" + t.Name |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1225 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1228 | // Handle arm on x86 properties in the form: |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1229 | // target { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1230 | // arm_on_x86 { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1231 | // key: value, |
| 1232 | // }, |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1233 | // arm_on_x86_64 { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1234 | // key: value, |
| 1235 | // }, |
| 1236 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1237 | if os.Class == Device { |
Victor Khimenko | 1a31f80 | 2020-09-17 03:07:31 +0200 | [diff] [blame] | 1238 | if arch.ArchType == X86 && (hasArmAbi(arch) || |
| 1239 | hasArmAndroidArch(ctx.Config().Targets[Android])) { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1240 | field := "Arm_on_x86" |
| 1241 | prefix := "target.arm_on_x86" |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1242 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1243 | } |
Victor Khimenko | 1a31f80 | 2020-09-17 03:07:31 +0200 | [diff] [blame] | 1244 | if arch.ArchType == X86_64 && (hasArmAbi(arch) || |
| 1245 | hasArmAndroidArch(ctx.Config().Targets[Android])) { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1246 | field := "Arm_on_x86_64" |
| 1247 | prefix := "target.arm_on_x86_64" |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1248 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1249 | } |
Victor Khimenko | c26fcf4 | 2020-05-07 22:16:33 +0200 | [diff] [blame] | 1250 | if os == Android && m.Target().NativeBridge == NativeBridgeEnabled { |
| 1251 | field := "Native_bridge" |
| 1252 | prefix := "target.native_bridge" |
| 1253 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1254 | } |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 1255 | } |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1256 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1257 | } |
| 1258 | } |
| 1259 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1260 | // 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] | 1261 | func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1262 | variables := config.productVariables |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1263 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1264 | targets := make(map[OsType][]Target) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1265 | var targetErr error |
| 1266 | |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1267 | addTarget := func(os OsType, archName string, archVariant, cpuVariant *string, abi []string, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1268 | nativeBridgeEnabled NativeBridgeSupport, nativeBridgeHostArchName *string, |
| 1269 | nativeBridgeRelativePath *string) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1270 | if targetErr != nil { |
| 1271 | return |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1272 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1273 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1274 | arch, err := decodeArch(os, archName, archVariant, cpuVariant, abi) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1275 | if err != nil { |
| 1276 | targetErr = err |
| 1277 | return |
| 1278 | } |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1279 | nativeBridgeRelativePathStr := String(nativeBridgeRelativePath) |
| 1280 | nativeBridgeHostArchNameStr := String(nativeBridgeHostArchName) |
| 1281 | |
| 1282 | // Use guest arch as relative install path by default |
| 1283 | if nativeBridgeEnabled && nativeBridgeRelativePathStr == "" { |
| 1284 | nativeBridgeRelativePathStr = arch.ArchType.String() |
| 1285 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1286 | |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1287 | // A target is considered as HostCross if it's a host target which can't run natively on |
| 1288 | // the currently configured build machine (either because the OS is different or because of |
| 1289 | // the unsupported arch) |
| 1290 | hostCross := false |
| 1291 | if os.Class == Host { |
| 1292 | var osSupported bool |
| 1293 | if os == BuildOs { |
| 1294 | osSupported = true |
| 1295 | } else if BuildOs.Linux() && os.Linux() { |
| 1296 | // LinuxBionic and Linux are compatible |
| 1297 | osSupported = true |
| 1298 | } else { |
| 1299 | osSupported = false |
| 1300 | } |
| 1301 | |
| 1302 | var archSupported bool |
| 1303 | if arch.ArchType == Common { |
| 1304 | archSupported = true |
| 1305 | } else if arch.ArchType.Name == *variables.HostArch { |
| 1306 | archSupported = true |
| 1307 | } else if variables.HostSecondaryArch != nil && arch.ArchType.Name == *variables.HostSecondaryArch { |
| 1308 | archSupported = true |
| 1309 | } else { |
| 1310 | archSupported = false |
| 1311 | } |
| 1312 | if !osSupported || !archSupported { |
| 1313 | hostCross = true |
| 1314 | } |
| 1315 | } |
| 1316 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1317 | targets[os] = append(targets[os], |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1318 | Target{ |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1319 | Os: os, |
| 1320 | Arch: arch, |
| 1321 | NativeBridge: nativeBridgeEnabled, |
| 1322 | NativeBridgeHostArchName: nativeBridgeHostArchNameStr, |
| 1323 | NativeBridgeRelativePath: nativeBridgeRelativePathStr, |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1324 | HostCross: hostCross, |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1325 | }) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1326 | } |
| 1327 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1328 | if variables.HostArch == nil { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1329 | return nil, fmt.Errorf("No host primary architecture set") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1332 | // The primary host target, which must always exist. |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1333 | addTarget(BuildOs, *variables.HostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1334 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1335 | // An optional secondary host target. |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1336 | if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1337 | addTarget(BuildOs, *variables.HostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1338 | } |
| 1339 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1340 | // Optional cross-compiled host targets, generally Windows. |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1341 | if String(variables.CrossHost) != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1342 | crossHostOs := osByName(*variables.CrossHost) |
| 1343 | if crossHostOs == NoOsType { |
| 1344 | return nil, fmt.Errorf("Unknown cross host OS %q", *variables.CrossHost) |
| 1345 | } |
| 1346 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1347 | if String(variables.CrossHostArch) == "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1348 | return nil, fmt.Errorf("No cross-host primary architecture set") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1349 | } |
| 1350 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1351 | // The primary cross-compiled host target. |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1352 | addTarget(crossHostOs, *variables.CrossHostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1353 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1354 | // An optional secondary cross-compiled host target. |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1355 | if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1356 | addTarget(crossHostOs, *variables.CrossHostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1357 | } |
| 1358 | } |
| 1359 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1360 | // Optional device targets |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1361 | if variables.DeviceArch != nil && *variables.DeviceArch != "" { |
Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 1362 | var target = Android |
| 1363 | if Bool(variables.Fuchsia) { |
| 1364 | target = Fuchsia |
| 1365 | } |
| 1366 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1367 | // The primary device target. |
Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 1368 | addTarget(target, *variables.DeviceArch, variables.DeviceArchVariant, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1369 | variables.DeviceCpuVariant, variables.DeviceAbi, NativeBridgeDisabled, nil, nil) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1370 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1371 | // An optional secondary device target. |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1372 | if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" { |
| 1373 | addTarget(Android, *variables.DeviceSecondaryArch, |
| 1374 | variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1375 | variables.DeviceSecondaryAbi, NativeBridgeDisabled, nil, nil) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1376 | } |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1377 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1378 | // An optional NativeBridge device target. |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1379 | if variables.NativeBridgeArch != nil && *variables.NativeBridgeArch != "" { |
| 1380 | addTarget(Android, *variables.NativeBridgeArch, |
| 1381 | variables.NativeBridgeArchVariant, variables.NativeBridgeCpuVariant, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1382 | variables.NativeBridgeAbi, NativeBridgeEnabled, variables.DeviceArch, |
| 1383 | variables.NativeBridgeRelativePath) |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1384 | } |
| 1385 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1386 | // An optional secondary NativeBridge device target. |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1387 | if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" && |
| 1388 | variables.NativeBridgeSecondaryArch != nil && *variables.NativeBridgeSecondaryArch != "" { |
| 1389 | addTarget(Android, *variables.NativeBridgeSecondaryArch, |
| 1390 | variables.NativeBridgeSecondaryArchVariant, |
| 1391 | variables.NativeBridgeSecondaryCpuVariant, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1392 | variables.NativeBridgeSecondaryAbi, |
| 1393 | NativeBridgeEnabled, |
| 1394 | variables.DeviceSecondaryArch, |
| 1395 | variables.NativeBridgeSecondaryRelativePath) |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1396 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1399 | if targetErr != nil { |
| 1400 | return nil, targetErr |
| 1401 | } |
| 1402 | |
| 1403 | return targets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1406 | // hasArmAbi returns true if arch has at least one arm ABI |
| 1407 | func hasArmAbi(arch Arch) bool { |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 1408 | return PrefixInList(arch.Abi, "arm") |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1409 | } |
| 1410 | |
dimitry | 628db6f | 2019-05-22 17:16:21 +0200 | [diff] [blame] | 1411 | // 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] | 1412 | func hasArmAndroidArch(targets []Target) bool { |
| 1413 | for _, target := range targets { |
Victor Khimenko | 1a31f80 | 2020-09-17 03:07:31 +0200 | [diff] [blame] | 1414 | if target.Os == Android && target.Arch.ArchType == Arm { |
Victor Khimenko | 5eb8ec1 | 2018-03-21 20:30:54 +0100 | [diff] [blame] | 1415 | return true |
| 1416 | } |
| 1417 | } |
| 1418 | return false |
| 1419 | } |
| 1420 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1421 | // archConfig describes a built-in configuration. |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1422 | type archConfig struct { |
| 1423 | arch string |
| 1424 | archVariant string |
| 1425 | cpuVariant string |
| 1426 | abi []string |
| 1427 | } |
| 1428 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1429 | // 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] | 1430 | func getNdkAbisConfig() []archConfig { |
| 1431 | return []archConfig{ |
Dan Albert | 6bba644 | 2020-01-30 15:16:49 -0800 | [diff] [blame] | 1432 | {"arm", "armv7-a", "", []string{"armeabi-v7a"}}, |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1433 | {"arm64", "armv8-a", "", []string{"arm64-v8a"}}, |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1434 | {"x86", "", "", []string{"x86"}}, |
| 1435 | {"x86_64", "", "", []string{"x86_64"}}, |
| 1436 | } |
| 1437 | } |
| 1438 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1439 | // 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] | 1440 | func getAmlAbisConfig() []archConfig { |
| 1441 | return []archConfig{ |
Martin Stjernholm | 9368834 | 2020-10-16 21:45:10 +0100 | [diff] [blame] | 1442 | {"arm", "armv7-a-neon", "", []string{"armeabi-v7a"}}, |
Martin Stjernholm | c1ecc43 | 2019-11-15 15:00:31 +0000 | [diff] [blame] | 1443 | {"arm64", "armv8-a", "", []string{"arm64-v8a"}}, |
| 1444 | {"x86", "", "", []string{"x86"}}, |
| 1445 | {"x86_64", "", "", []string{"x86_64"}}, |
| 1446 | } |
| 1447 | } |
| 1448 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1449 | // 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] | 1450 | func decodeArchSettings(os OsType, archConfigs []archConfig) ([]Target, error) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1451 | var ret []Target |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1452 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1453 | for _, config := range archConfigs { |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1454 | arch, err := decodeArch(os, config.arch, &config.archVariant, |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1455 | &config.cpuVariant, config.abi) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1456 | if err != nil { |
| 1457 | return nil, err |
| 1458 | } |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 1459 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1460 | ret = append(ret, Target{ |
| 1461 | Os: Android, |
| 1462 | Arch: arch, |
| 1463 | }) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | return ret, nil |
| 1467 | } |
| 1468 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1469 | // 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] | 1470 | 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] | 1471 | // Verify the arch is valid |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1472 | archType, ok := archTypeMap[arch] |
| 1473 | if !ok { |
| 1474 | return Arch{}, fmt.Errorf("unknown arch %q", arch) |
| 1475 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1476 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1477 | a := Arch{ |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1478 | ArchType: archType, |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1479 | ArchVariant: String(archVariant), |
| 1480 | CpuVariant: String(cpuVariant), |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1481 | Abi: abi, |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1482 | } |
| 1483 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1484 | // Convert generic arch variants into the empty string. |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1485 | if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" { |
| 1486 | a.ArchVariant = "" |
| 1487 | } |
| 1488 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1489 | // Convert generic CPU variants into the empty string. |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1490 | if a.CpuVariant == a.ArchType.Name || a.CpuVariant == "generic" { |
| 1491 | a.CpuVariant = "" |
| 1492 | } |
| 1493 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1494 | // Filter empty ABIs out of the list. |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1495 | for i := 0; i < len(a.Abi); i++ { |
| 1496 | if a.Abi[i] == "" { |
| 1497 | a.Abi = append(a.Abi[:i], a.Abi[i+1:]...) |
| 1498 | i-- |
| 1499 | } |
| 1500 | } |
| 1501 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1502 | if a.ArchVariant == "" { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1503 | // Set ArchFeatures from the default arch features. |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1504 | if featureMap, ok := defaultArchFeatureMap[os]; ok { |
| 1505 | a.ArchFeatures = featureMap[archType] |
| 1506 | } |
| 1507 | } else { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1508 | // Set ArchFeatures from the arch type. |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1509 | if featureMap, ok := archFeatureMap[archType]; ok { |
| 1510 | a.ArchFeatures = featureMap[a.ArchVariant] |
| 1511 | } |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 1512 | } |
| 1513 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1514 | return a, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1517 | // filterMultilibTargets takes a list of Targets and a multilib value and returns a new list of |
| 1518 | // Targets containing only those that have the given multilib value. |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1519 | func filterMultilibTargets(targets []Target, multilib string) []Target { |
| 1520 | var ret []Target |
| 1521 | for _, t := range targets { |
| 1522 | if t.Arch.ArchType.Multilib == multilib { |
| 1523 | ret = append(ret, t) |
| 1524 | } |
| 1525 | } |
| 1526 | return ret |
| 1527 | } |
| 1528 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1529 | // getCommonTargets returns the set of Os specific common architecture targets for each Os in a list |
| 1530 | // of targets. |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 1531 | func getCommonTargets(targets []Target) []Target { |
| 1532 | var ret []Target |
| 1533 | set := make(map[string]bool) |
| 1534 | |
| 1535 | for _, t := range targets { |
| 1536 | if _, found := set[t.Os.String()]; !found { |
| 1537 | set[t.Os.String()] = true |
| 1538 | ret = append(ret, commonTargetMap[t.Os.String()]) |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | return ret |
| 1543 | } |
| 1544 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1545 | // firstTarget takes a list of Targets and a list of multilib values and returns a list of Targets |
| 1546 | // that contains zero or one Target for each OsType, selecting the one that matches the earliest |
| 1547 | // filter. |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1548 | func firstTarget(targets []Target, filters ...string) []Target { |
Jiyong Park | 2210198 | 2020-09-17 19:09:58 +0900 | [diff] [blame] | 1549 | // find the first target from each OS |
| 1550 | var ret []Target |
| 1551 | hasHost := false |
| 1552 | set := make(map[OsType]bool) |
| 1553 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1554 | for _, filter := range filters { |
| 1555 | buildTargets := filterMultilibTargets(targets, filter) |
Jiyong Park | 2210198 | 2020-09-17 19:09:58 +0900 | [diff] [blame] | 1556 | for _, t := range buildTargets { |
| 1557 | if _, found := set[t.Os]; !found { |
| 1558 | hasHost = hasHost || (t.Os.Class == Host) |
| 1559 | set[t.Os] = true |
| 1560 | ret = append(ret, t) |
| 1561 | } |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1562 | } |
| 1563 | } |
Jiyong Park | 2210198 | 2020-09-17 19:09:58 +0900 | [diff] [blame] | 1564 | return ret |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1565 | } |
| 1566 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1567 | // decodeMultilibTargets uses the module's multilib setting to select one or more targets from a |
| 1568 | // list of Targets. |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 1569 | func decodeMultilibTargets(multilib string, targets []Target, prefer32 bool) ([]Target, error) { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1570 | var buildTargets []Target |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1571 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1572 | switch multilib { |
| 1573 | case "common": |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1574 | buildTargets = getCommonTargets(targets) |
| 1575 | case "common_first": |
| 1576 | buildTargets = getCommonTargets(targets) |
| 1577 | if prefer32 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1578 | buildTargets = append(buildTargets, firstTarget(targets, "lib32", "lib64")...) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1579 | } else { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1580 | buildTargets = append(buildTargets, firstTarget(targets, "lib64", "lib32")...) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1581 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1582 | case "both": |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 1583 | if prefer32 { |
| 1584 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) |
| 1585 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) |
| 1586 | } else { |
| 1587 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) |
| 1588 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) |
| 1589 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1590 | case "32": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1591 | buildTargets = filterMultilibTargets(targets, "lib32") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1592 | case "64": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1593 | buildTargets = filterMultilibTargets(targets, "lib64") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1594 | case "first": |
| 1595 | if prefer32 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1596 | buildTargets = firstTarget(targets, "lib32", "lib64") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1597 | } else { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1598 | buildTargets = firstTarget(targets, "lib64", "lib32") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1599 | } |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1600 | case "prefer32": |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1601 | buildTargets = filterMultilibTargets(targets, "lib32") |
| 1602 | if len(buildTargets) == 0 { |
| 1603 | buildTargets = filterMultilibTargets(targets, "lib64") |
| 1604 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1605 | default: |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1606 | return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", "64", or "prefer32" found %q`, |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1607 | multilib) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1610 | return buildTargets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1611 | } |