blob: 99bbe9183446a0454f49a1b3b20869d64bcf1716 [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// 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 Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
17import (
Colin Cross74ba9622019-02-11 15:11:14 -080018 "encoding"
Colin Cross3f40fa42015-01-30 17:27:36 -080019 "fmt"
20 "reflect"
21 "runtime"
22 "strings"
Colin Crossf6566ed2015-03-24 11:13:38 -070023
Colin Cross0f7d2ef2019-10-16 11:03:10 -070024 "github.com/google/blueprint"
Colin Cross617b88a2020-08-24 18:04:09 -070025 "github.com/google/blueprint/bootstrap"
Colin Crossf6566ed2015-03-24 11:13:38 -070026 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080027)
28
Colin Cross3f40fa42015-01-30 17:27:36 -080029/*
30Example blueprints file containing all variant property groups, with comment listing what type
31of variants get properties in that group:
32
33module {
34 arch: {
35 arm: {
36 // Host or device variants with arm architecture
37 },
38 arm64: {
39 // Host or device variants with arm64 architecture
40 },
Colin Cross3f40fa42015-01-30 17:27:36 -080041 x86: {
42 // Host or device variants with x86 architecture
43 },
44 x86_64: {
45 // Host or device variants with x86_64 architecture
46 },
47 },
48 multilib: {
49 lib32: {
50 // Host or device variants for 32-bit architectures
51 },
52 lib64: {
53 // Host or device variants for 64-bit architectures
54 },
55 },
56 target: {
57 android: {
Martin Stjernholme284b482020-09-23 21:03:27 +010058 // Device variants (implies Bionic)
Colin Cross3f40fa42015-01-30 17:27:36 -080059 },
60 host: {
61 // Host variants
62 },
Martin Stjernholme284b482020-09-23 21:03:27 +010063 bionic: {
64 // Bionic (device and host) variants
65 },
66 linux_bionic: {
67 // Bionic host variants
68 },
69 linux: {
70 // Bionic (device and host) and Linux glibc variants
71 },
Dan Willemsen5746bd42017-10-02 19:42:01 -070072 linux_glibc: {
Martin Stjernholme284b482020-09-23 21:03:27 +010073 // Linux host variants (using non-Bionic libc)
Colin Cross3f40fa42015-01-30 17:27:36 -080074 },
75 darwin: {
76 // Darwin host variants
77 },
78 windows: {
79 // Windows host variants
80 },
81 not_windows: {
82 // Non-windows host variants
83 },
Martin Stjernholme284b482020-09-23 21:03:27 +010084 android_arm: {
85 // Any <os>_<arch> combination restricts to that os and arch
86 },
Colin Cross3f40fa42015-01-30 17:27:36 -080087 },
88}
89*/
Colin Cross7d5136f2015-05-11 13:39:40 -070090
Colin Cross3f40fa42015-01-30 17:27:36 -080091// An Arch indicates a single CPU architecture.
92type Arch struct {
Colin Crossa6845402020-11-16 15:08:19 -080093 // The type of the architecture (arm, arm64, x86, or x86_64).
94 ArchType ArchType
95
96 // The variant of the architecture, for example "armv7-a" or "armv7-a-neon" for arm.
97 ArchVariant string
98
99 // The variant of the CPU, for example "cortex-a53" for arm64.
100 CpuVariant string
101
102 // The list of Android app ABIs supported by the CPU architecture, for example "arm64-v8a".
103 Abi []string
104
105 // The list of arch-specific features supported by the CPU architecture, for example "neon".
Colin Crossc5c24ad2015-11-20 15:35:00 -0800106 ArchFeatures []string
Colin Cross3f40fa42015-01-30 17:27:36 -0800107}
108
Colin Crossa6845402020-11-16 15:08:19 -0800109// String returns the Arch as a string. The value is used as the name of the variant created
110// by archMutator.
Colin Cross3f40fa42015-01-30 17:27:36 -0800111func (a Arch) String() string {
Colin Crossd3ba0392015-05-07 14:11:29 -0700112 s := a.ArchType.String()
Colin Cross3f40fa42015-01-30 17:27:36 -0800113 if a.ArchVariant != "" {
114 s += "_" + a.ArchVariant
115 }
116 if a.CpuVariant != "" {
117 s += "_" + a.CpuVariant
118 }
119 return s
120}
121
Colin Crossa6845402020-11-16 15:08:19 -0800122// ArchType is used to define the 4 supported architecture types (arm, arm64, x86, x86_64), as
123// well as the "common" architecture used for modules that support multiple architectures, for
124// example Java modules.
Colin Cross3f40fa42015-01-30 17:27:36 -0800125type ArchType struct {
Colin Crossa6845402020-11-16 15:08:19 -0800126 // Name is the name of the architecture type, "arm", "arm64", "x86", or "x86_64".
127 Name string
128
129 // Field is the name of the field used in properties that refer to the architecture, e.g. "Arm64".
130 Field string
131
132 // Multilib is either "lib32" or "lib64" for 32-bit or 64-bit architectures.
Colin Crossec193632015-07-06 17:49:43 -0700133 Multilib string
Colin Cross3f40fa42015-01-30 17:27:36 -0800134}
135
Colin Crossa6845402020-11-16 15:08:19 -0800136// String returns the name of the ArchType.
137func (a ArchType) String() string {
138 return a.Name
139}
140
141const COMMON_VARIANT = "common"
142
143var (
144 archTypeList []ArchType
145
146 Arm = newArch("arm", "lib32")
147 Arm64 = newArch("arm64", "lib64")
148 X86 = newArch("x86", "lib32")
149 X86_64 = newArch("x86_64", "lib64")
150
151 Common = ArchType{
152 Name: COMMON_VARIANT,
153 }
154)
155
156var archTypeMap = map[string]ArchType{}
157
Colin Crossec193632015-07-06 17:49:43 -0700158func newArch(name, multilib string) ArchType {
Dan Willemsenb1957a52016-06-23 23:44:54 -0700159 archType := ArchType{
Colin Crossec193632015-07-06 17:49:43 -0700160 Name: name,
Dan Willemsenb1957a52016-06-23 23:44:54 -0700161 Field: proptools.FieldNameForProperty(name),
Colin Crossec193632015-07-06 17:49:43 -0700162 Multilib: multilib,
Colin Cross3f40fa42015-01-30 17:27:36 -0800163 }
Dan Willemsenb1957a52016-06-23 23:44:54 -0700164 archTypeList = append(archTypeList, archType)
Colin Crossa6845402020-11-16 15:08:19 -0800165 archTypeMap[name] = archType
Dan Willemsenb1957a52016-06-23 23:44:54 -0700166 return archType
Colin Cross3f40fa42015-01-30 17:27:36 -0800167}
168
Colin Crossa6845402020-11-16 15:08:19 -0800169// ArchTypeList returns the 4 supported ArchTypes for arm, arm64, x86 and x86_64.
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -0700170func ArchTypeList() []ArchType {
171 return append([]ArchType(nil), archTypeList...)
172}
173
Colin Crossa6845402020-11-16 15:08:19 -0800174// MarshalText allows an ArchType to be serialized through any encoder that supports
175// encoding.TextMarshaler.
Colin Cross74ba9622019-02-11 15:11:14 -0800176func (a ArchType) MarshalText() ([]byte, error) {
Jeongik Chabec4d032021-04-15 08:55:38 +0900177 return []byte(a.String()), nil
Colin Cross74ba9622019-02-11 15:11:14 -0800178}
179
Colin Crossa6845402020-11-16 15:08:19 -0800180var _ encoding.TextMarshaler = ArchType{}
Colin Cross74ba9622019-02-11 15:11:14 -0800181
Colin Crossa6845402020-11-16 15:08:19 -0800182// UnmarshalText allows an ArchType to be deserialized through any decoder that supports
183// encoding.TextUnmarshaler.
Colin Cross74ba9622019-02-11 15:11:14 -0800184func (a *ArchType) UnmarshalText(text []byte) error {
185 if u, ok := archTypeMap[string(text)]; ok {
186 *a = u
187 return nil
188 }
189
190 return fmt.Errorf("unknown ArchType %q", text)
191}
192
Colin Crossa6845402020-11-16 15:08:19 -0800193var _ encoding.TextUnmarshaler = &ArchType{}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700194
Colin Crossa6845402020-11-16 15:08:19 -0800195// OsClass is an enum that describes whether a variant of a module runs on the host, on the device,
196// or is generic.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700197type OsClass int
198
199const (
Colin Crossa6845402020-11-16 15:08:19 -0800200 // Generic is used for variants of modules that are not OS-specific.
Dan Willemsen0e2d97b2016-11-28 17:50:06 -0800201 Generic OsClass = iota
Colin Crossa6845402020-11-16 15:08:19 -0800202 // Device is used for variants of modules that run on the device.
Dan Willemsen0e2d97b2016-11-28 17:50:06 -0800203 Device
Colin Crossa6845402020-11-16 15:08:19 -0800204 // Host is used for variants of modules that run on the host.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700205 Host
Colin Crossa1ad8d12016-06-01 17:09:44 -0700206)
207
Colin Crossa6845402020-11-16 15:08:19 -0800208// String returns the OsClass as a string.
Colin Cross67a5c132017-05-09 13:45:28 -0700209func (class OsClass) String() string {
210 switch class {
211 case Generic:
212 return "generic"
213 case Device:
214 return "device"
215 case Host:
216 return "host"
Colin Cross67a5c132017-05-09 13:45:28 -0700217 default:
218 panic(fmt.Errorf("unknown class %d", class))
219 }
220}
221
Colin Crossa6845402020-11-16 15:08:19 -0800222// OsType describes an OS variant of a module.
223type OsType struct {
224 // Name is the name of the OS. It is also used as the name of the property in Android.bp
225 // files.
226 Name string
227
228 // Field is the name of the OS converted to an exported field name, i.e. with the first
229 // character capitalized.
230 Field string
231
232 // Class is the OsClass of the OS.
233 Class OsClass
234
235 // DefaultDisabled is set when the module variants for the OS should not be created unless
236 // the module explicitly requests them. This is used to limit Windows cross compilation to
237 // only modules that need it.
238 DefaultDisabled bool
239}
240
241// String returns the name of the OsType.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700242func (os OsType) String() string {
243 return os.Name
Colin Cross54c71122016-06-01 17:09:44 -0700244}
245
Colin Crossa6845402020-11-16 15:08:19 -0800246// Bionic returns true if the OS uses the Bionic libc runtime, i.e. if the OS is Android or
247// is Linux with Bionic.
Dan Willemsen866b5632017-09-22 12:28:24 -0700248func (os OsType) Bionic() bool {
249 return os == Android || os == LinuxBionic
250}
251
Colin Crossa6845402020-11-16 15:08:19 -0800252// Linux returns true if the OS uses the Linux kernel, i.e. if the OS is Android or is Linux
253// with or without the Bionic libc runtime.
Dan Willemsen866b5632017-09-22 12:28:24 -0700254func (os OsType) Linux() bool {
255 return os == Android || os == Linux || os == LinuxBionic
256}
257
Colin Crossa6845402020-11-16 15:08:19 -0800258// newOsType constructs an OsType and adds it to the global lists.
259func newOsType(name string, class OsClass, defDisabled bool, archTypes ...ArchType) OsType {
260 checkCalledFromInit()
Colin Crossa1ad8d12016-06-01 17:09:44 -0700261 os := OsType{
262 Name: name,
Colin Crossa6845402020-11-16 15:08:19 -0800263 Field: proptools.FieldNameForProperty(name),
Colin Crossa1ad8d12016-06-01 17:09:44 -0700264 Class: class,
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800265
266 DefaultDisabled: defDisabled,
Colin Cross54c71122016-06-01 17:09:44 -0700267 }
Paul Duffina04c1072020-03-02 10:16:35 +0000268 OsTypeList = append(OsTypeList, os)
Nan Zhangdb0b9a32017-02-27 10:12:13 -0800269
270 if _, found := commonTargetMap[name]; found {
271 panic(fmt.Errorf("Found Os type duplicate during OsType registration: %q", name))
272 } else {
Colin Crosse9fe2942020-11-10 18:12:15 -0800273 commonTargetMap[name] = Target{Os: os, Arch: CommonArch}
Nan Zhangdb0b9a32017-02-27 10:12:13 -0800274 }
Colin Crossa6845402020-11-16 15:08:19 -0800275 osArchTypeMap[os] = archTypes
Nan Zhangdb0b9a32017-02-27 10:12:13 -0800276
Colin Crossa1ad8d12016-06-01 17:09:44 -0700277 return os
278}
279
Colin Crossa6845402020-11-16 15:08:19 -0800280// osByName returns the OsType that has the given name, or NoOsType if none match.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700281func osByName(name string) OsType {
Paul Duffina04c1072020-03-02 10:16:35 +0000282 for _, os := range OsTypeList {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700283 if os.Name == name {
284 return os
285 }
286 }
287
288 return NoOsType
Dan Willemsen490fd492015-11-24 17:53:15 -0800289}
290
Colin Crossa6845402020-11-16 15:08:19 -0800291// BuildOs returns the OsType for the OS that the build is running on.
292var BuildOs = func() OsType {
293 switch runtime.GOOS {
294 case "linux":
295 return Linux
296 case "darwin":
297 return Darwin
298 default:
299 panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS))
300 }
301}()
dimitry1f33e402019-03-26 12:39:31 +0100302
Colin Crossa6845402020-11-16 15:08:19 -0800303// BuildArch returns the ArchType for the CPU that the build is running on.
304var BuildArch = func() ArchType {
305 switch runtime.GOARCH {
306 case "amd64":
307 return X86_64
308 default:
309 panic(fmt.Sprintf("unsupported Arch: %s", runtime.GOARCH))
310 }
311}()
312
313var (
314 // OsTypeList contains a list of all the supported OsTypes, including ones not supported
315 // by the current build host or the target device.
316 OsTypeList []OsType
317 // commonTargetMap maps names of OsTypes to the corresponding common Target, i.e. the
318 // Target with the same OsType and the common ArchType.
319 commonTargetMap = make(map[string]Target)
320 // osArchTypeMap maps OsTypes to the list of supported ArchTypes for that OS.
321 osArchTypeMap = map[OsType][]ArchType{}
322
323 // NoOsType is a placeholder for when no OS is needed.
324 NoOsType OsType
325 // Linux is the OS for the Linux kernel plus the glibc runtime.
326 Linux = newOsType("linux_glibc", Host, false, X86, X86_64)
327 // Darwin is the OS for MacOS/Darwin host machines.
328 Darwin = newOsType("darwin", Host, false, X86_64)
329 // LinuxBionic is the OS for the Linux kernel plus the Bionic libc runtime, but without the
330 // rest of Android.
331 LinuxBionic = newOsType("linux_bionic", Host, false, Arm64, X86_64)
332 // Windows the OS for Windows host machines.
333 Windows = newOsType("windows", Host, true, X86, X86_64)
334 // Android is the OS for target devices that run all of Android, including the Linux kernel
335 // and the Bionic libc runtime.
336 Android = newOsType("android", Device, false, Arm, Arm64, X86, X86_64)
337 // Fuchsia is the OS for target devices that run Fuchsia.
338 Fuchsia = newOsType("fuchsia", Device, false, Arm64, X86_64)
339
340 // CommonOS is a pseudo OSType for a common OS variant, which is OsType agnostic and which
341 // has dependencies on all the OS variants.
342 CommonOS = newOsType("common_os", Generic, false)
Colin Crosse9fe2942020-11-10 18:12:15 -0800343
344 // CommonArch is the Arch for all modules that are os-specific but not arch specific,
345 // for example most Java modules.
346 CommonArch = Arch{ArchType: Common}
dimitry1f33e402019-03-26 12:39:31 +0100347)
348
Colin Crossa6845402020-11-16 15:08:19 -0800349// Target specifies the OS and architecture that a module is being compiled for.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700350type Target struct {
Colin Crossa6845402020-11-16 15:08:19 -0800351 // Os the OS that the module is being compiled for (e.g. "linux_glibc", "android").
352 Os OsType
353 // Arch is the architecture that the module is being compiled for.
354 Arch Arch
355 // NativeBridge is NativeBridgeEnabled if the architecture is supported using NativeBridge
356 // (i.e. arm on x86) for this device.
357 NativeBridge NativeBridgeSupport
358 // NativeBridgeHostArchName is the name of the real architecture that is used to implement
359 // the NativeBridge architecture. For example, for arm on x86 this would be "x86".
dimitry8d6dde82019-07-11 10:23:53 +0200360 NativeBridgeHostArchName string
Colin Crossa6845402020-11-16 15:08:19 -0800361 // NativeBridgeRelativePath is the name of the subdirectory that will contain NativeBridge
362 // libraries and binaries.
dimitry8d6dde82019-07-11 10:23:53 +0200363 NativeBridgeRelativePath string
Jiyong Park1613e552020-09-14 19:43:17 +0900364
365 // HostCross is true when the target cannot run natively on the current build host.
366 // For example, linux_glibc_x86 returns true on a regular x86/i686/Linux machines, but returns false
367 // on Mac (different OS), or on 64-bit only i686/Linux machines (unsupported arch).
368 HostCross bool
Colin Crossd3ba0392015-05-07 14:11:29 -0700369}
370
Colin Crossa6845402020-11-16 15:08:19 -0800371// NativeBridgeSupport is an enum that specifies if a Target supports NativeBridge.
372type NativeBridgeSupport bool
373
374const (
375 NativeBridgeDisabled NativeBridgeSupport = false
376 NativeBridgeEnabled NativeBridgeSupport = true
377)
378
379// String returns the OS and arch variations used for the Target.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700380func (target Target) String() string {
Colin Crossa195f912019-10-16 11:07:20 -0700381 return target.OsVariation() + "_" + target.ArchVariation()
382}
383
Colin Crossa6845402020-11-16 15:08:19 -0800384// OsVariation returns the name of the variation used by the osMutator for the Target.
Colin Crossa195f912019-10-16 11:07:20 -0700385func (target Target) OsVariation() string {
386 return target.Os.String()
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700387}
388
Colin Crossa6845402020-11-16 15:08:19 -0800389// ArchVariation returns the name of the variation used by the archMutator for the Target.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700390func (target Target) ArchVariation() string {
391 var variation string
dimitry1f33e402019-03-26 12:39:31 +0100392 if target.NativeBridge {
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700393 variation = "native_bridge_"
dimitry1f33e402019-03-26 12:39:31 +0100394 }
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700395 variation += target.Arch.String()
396
Colin Crossa195f912019-10-16 11:07:20 -0700397 return variation
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700398}
399
Colin Crossa6845402020-11-16 15:08:19 -0800400// Variations returns a list of blueprint.Variations for the osMutator and archMutator for the
401// Target.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700402func (target Target) Variations() []blueprint.Variation {
403 return []blueprint.Variation{
Colin Crossa195f912019-10-16 11:07:20 -0700404 {Mutator: "os", Variation: target.OsVariation()},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700405 {Mutator: "arch", Variation: target.ArchVariation()},
406 }
Dan Willemsen490fd492015-11-24 17:53:15 -0800407}
408
Colin Crossa6845402020-11-16 15:08:19 -0800409// osMutator splits an arch-specific module into a variant for each OS that is enabled for the
410// module. It uses the HostOrDevice value passed to InitAndroidArchModule and the
411// device_supported and host_supported properties to determine which OsTypes are enabled for this
412// module, then searches through the Targets to determine which have enabled Targets for this
413// module.
Colin Cross617b88a2020-08-24 18:04:09 -0700414func osMutator(bpctx blueprint.BottomUpMutatorContext) {
Colin Crossa195f912019-10-16 11:07:20 -0700415 var module Module
416 var ok bool
Colin Cross617b88a2020-08-24 18:04:09 -0700417 if module, ok = bpctx.Module().(Module); !ok {
Colin Crossa6845402020-11-16 15:08:19 -0800418 // The module is not a Soong module, it is a Blueprint module.
Colin Cross617b88a2020-08-24 18:04:09 -0700419 if bootstrap.IsBootstrapModule(bpctx.Module()) {
420 // Bootstrap Go modules are always the build OS or linux bionic.
421 config := bpctx.Config().(Config)
422 osNames := []string{config.BuildOSTarget.OsVariation()}
423 for _, hostCrossTarget := range config.Targets[LinuxBionic] {
424 if hostCrossTarget.Arch.ArchType == config.BuildOSTarget.Arch.ArchType {
425 osNames = append(osNames, hostCrossTarget.OsVariation())
426 }
427 }
428 osNames = FirstUniqueStrings(osNames)
429 bpctx.CreateVariations(osNames...)
430 }
Colin Crossa195f912019-10-16 11:07:20 -0700431 return
432 }
433
Colin Cross617b88a2020-08-24 18:04:09 -0700434 // Bootstrap Go module support above requires this mutator to be a
435 // blueprint.BottomUpMutatorContext because android.BottomUpMutatorContext
436 // filters out non-Soong modules. Now that we've handled them, create a
437 // normal android.BottomUpMutatorContext.
Liz Kammer356f7d42021-01-26 09:18:53 -0500438 mctx := bottomUpMutatorContextFactory(bpctx, module, false, false)
Colin Cross617b88a2020-08-24 18:04:09 -0700439
Colin Crossa195f912019-10-16 11:07:20 -0700440 base := module.base()
441
Colin Crossa6845402020-11-16 15:08:19 -0800442 // Nothing to do for modules that are not architecture specific (e.g. a genrule).
Colin Crossa195f912019-10-16 11:07:20 -0700443 if !base.ArchSpecific() {
444 return
445 }
446
Colin Crossa6845402020-11-16 15:08:19 -0800447 // Collect a list of OSTypes supported by this module based on the HostOrDevice value
448 // passed to InitAndroidArchModule and the device_supported and host_supported properties.
Colin Crossa195f912019-10-16 11:07:20 -0700449 var moduleOSList []OsType
Paul Duffina04c1072020-03-02 10:16:35 +0000450 for _, os := range OsTypeList {
Jiyong Park1613e552020-09-14 19:43:17 +0900451 for _, t := range mctx.Config().Targets[os] {
Colin Cross08d6f8f2020-11-19 02:33:19 +0000452 if base.supportsTarget(t) {
Jiyong Park1613e552020-09-14 19:43:17 +0900453 moduleOSList = append(moduleOSList, os)
454 break
Colin Crossa195f912019-10-16 11:07:20 -0700455 }
456 }
Colin Crossa195f912019-10-16 11:07:20 -0700457 }
458
Colin Crossa6845402020-11-16 15:08:19 -0800459 // If there are no supported OSes then disable the module.
Colin Crossa195f912019-10-16 11:07:20 -0700460 if len(moduleOSList) == 0 {
Inseob Kimeec88e12020-01-22 11:11:29 +0900461 base.Disable()
Colin Crossa195f912019-10-16 11:07:20 -0700462 return
463 }
464
Colin Crossa6845402020-11-16 15:08:19 -0800465 // Convert the list of supported OsTypes to the variation names.
Colin Crossa195f912019-10-16 11:07:20 -0700466 osNames := make([]string, len(moduleOSList))
Colin Crossa195f912019-10-16 11:07:20 -0700467 for i, os := range moduleOSList {
468 osNames[i] = os.String()
469 }
470
Paul Duffin1356d8c2020-02-25 19:26:33 +0000471 createCommonOSVariant := base.commonProperties.CreateCommonOSVariant
472 if createCommonOSVariant {
Colin Crossa6845402020-11-16 15:08:19 -0800473 // A CommonOS variant was requested so add it to the list of OS variants to
Paul Duffin1356d8c2020-02-25 19:26:33 +0000474 // create. It needs to be added to the end because it needs to depend on the
475 // the other variants in the list returned by CreateVariations(...) and inter
476 // variant dependencies can only be created from a later variant in that list to
477 // an earlier one. That is because variants are always processed in the order in
478 // which they are returned from CreateVariations(...).
479 osNames = append(osNames, CommonOS.Name)
480 moduleOSList = append(moduleOSList, CommonOS)
Colin Crossa195f912019-10-16 11:07:20 -0700481 }
482
Colin Crossa6845402020-11-16 15:08:19 -0800483 // Create the variations, annotate each one with which OS it was created for, and
484 // squash the appropriate OS-specific properties into the top level properties.
Paul Duffin1356d8c2020-02-25 19:26:33 +0000485 modules := mctx.CreateVariations(osNames...)
486 for i, m := range modules {
487 m.base().commonProperties.CompileOS = moduleOSList[i]
488 m.base().setOSProperties(mctx)
489 }
490
491 if createCommonOSVariant {
492 // A CommonOS variant was requested so add dependencies from it (the last one in
493 // the list) to the OS type specific variants.
494 last := len(modules) - 1
495 commonOSVariant := modules[last]
496 commonOSVariant.base().commonProperties.CommonOSVariant = true
497 for _, module := range modules[0:last] {
498 // Ignore modules that are enabled. Note, this will only avoid adding
499 // dependencies on OsType variants that are explicitly disabled in their
500 // properties. The CommonOS variant will still depend on disabled variants
501 // if they are disabled afterwards, e.g. in archMutator if
502 if module.Enabled() {
503 mctx.AddInterVariantDependency(commonOsToOsSpecificVariantTag, commonOSVariant, module)
504 }
505 }
506 }
507}
508
Colin Crossc179ea62020-10-09 10:54:15 -0700509type archDepTag struct {
510 blueprint.BaseDependencyTag
511 name string
512}
Paul Duffin1356d8c2020-02-25 19:26:33 +0000513
Colin Crossc179ea62020-10-09 10:54:15 -0700514// Identifies the dependency from CommonOS variant to the os specific variants.
515var commonOsToOsSpecificVariantTag = archDepTag{name: "common os to os specific"}
516
Paul Duffin1356d8c2020-02-25 19:26:33 +0000517// Get the OsType specific variants for the current CommonOS variant.
518//
519// The returned list will only contain enabled OsType specific variants of the
520// module referenced in the supplied context. An empty list is returned if there
521// are no enabled variants or the supplied context is not for an CommonOS
522// variant.
523func GetOsSpecificVariantsOfCommonOSVariant(mctx BaseModuleContext) []Module {
524 var variants []Module
525 mctx.VisitDirectDeps(func(m Module) {
526 if mctx.OtherModuleDependencyTag(m) == commonOsToOsSpecificVariantTag {
527 if m.Enabled() {
528 variants = append(variants, m)
529 }
530 }
531 })
Paul Duffin1356d8c2020-02-25 19:26:33 +0000532 return variants
Colin Crossa195f912019-10-16 11:07:20 -0700533}
534
Colin Crossee0bc3b2018-10-02 22:01:37 -0700535// archMutator splits a module into a variant for each Target requested by the module. Target selection
Colin Crossa6845402020-11-16 15:08:19 -0800536// for a module is in three levels, OsClass, multilib, and then Target.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700537// OsClass selection is determined by:
538// - The HostOrDeviceSupported value passed in to InitAndroidArchModule by the module type factory, which selects
539// whether the module type can compile for host, device or both.
540// - The host_supported and device_supported properties on the module.
Roland Levillainf5b635d2019-06-05 14:42:57 +0100541// If host is supported for the module, the Host and HostCross OsClasses are selected. If device is supported
Colin Crossee0bc3b2018-10-02 22:01:37 -0700542// for the module, the Device OsClass is selected.
543// Within each selected OsClass, the multilib selection is determined by:
Jaewoong Jung02b2d4d2019-06-06 15:19:57 -0700544// - The compile_multilib property if it set (which may be overridden by target.android.compile_multilib or
Colin Crossee0bc3b2018-10-02 22:01:37 -0700545// target.host.compile_multilib).
546// - The default multilib passed to InitAndroidArchModule if compile_multilib was not set.
547// Valid multilib values include:
548// "both": compile for all Targets supported by the OsClass (generally x86_64 and x86, or arm64 and arm).
549// "first": compile for only a single preferred Target supported by the OsClass. This is generally x86_64 or arm64,
Elliott Hughes79ae3412020-04-17 15:49:49 -0700550// but may be arm for a 32-bit only build.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700551// "32": compile for only a single 32-bit Target supported by the OsClass.
552// "64": compile for only a single 64-bit Target supported by the OsClass.
Colin Crossa6845402020-11-16 15:08:19 -0800553// "common": compile a for a single Target that will work on all Targets supported by the OsClass (for example Java).
554// "common_first": compile a for a Target that will work on all Targets supported by the OsClass
555// (same as "common"), plus a second Target for the preferred Target supported by the OsClass
556// (same as "first"). This is used for java_binary that produces a common .jar and a wrapper
557// executable script.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700558//
559// Once the list of Targets is determined, the module is split into a variant for each Target.
560//
561// Modules can be initialized with InitAndroidMultiTargetsArchModule, in which case they will be split by OsClass,
562// but will have a common Target that is expected to handle all other selected Targets via ctx.MultiTargets().
Colin Cross617b88a2020-08-24 18:04:09 -0700563func archMutator(bpctx blueprint.BottomUpMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700564 var module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800565 var ok bool
Colin Cross617b88a2020-08-24 18:04:09 -0700566 if module, ok = bpctx.Module().(Module); !ok {
567 if bootstrap.IsBootstrapModule(bpctx.Module()) {
568 // Bootstrap Go modules are always the build architecture.
569 bpctx.CreateVariations(bpctx.Config().(Config).BuildOSTarget.ArchVariation())
570 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800571 return
572 }
573
Colin Cross617b88a2020-08-24 18:04:09 -0700574 // Bootstrap Go module support above requires this mutator to be a
575 // blueprint.BottomUpMutatorContext because android.BottomUpMutatorContext
576 // filters out non-Soong modules. Now that we've handled them, create a
577 // normal android.BottomUpMutatorContext.
Liz Kammer356f7d42021-01-26 09:18:53 -0500578 mctx := bottomUpMutatorContextFactory(bpctx, module, false, false)
Colin Cross617b88a2020-08-24 18:04:09 -0700579
Colin Cross5eca7cb2018-10-02 14:02:10 -0700580 base := module.base()
581
582 if !base.ArchSpecific() {
Colin Crossb9db4802016-06-03 01:50:47 +0000583 return
584 }
585
Colin Crossa195f912019-10-16 11:07:20 -0700586 os := base.commonProperties.CompileOS
Paul Duffin1356d8c2020-02-25 19:26:33 +0000587 if os == CommonOS {
588 // Make sure that the target related properties are initialized for the
589 // CommonOS variant.
590 addTargetProperties(module, commonTargetMap[os.Name], nil, true)
591
592 // Do not create arch specific variants for the CommonOS variant.
593 return
594 }
595
Colin Crossa195f912019-10-16 11:07:20 -0700596 osTargets := mctx.Config().Targets[os]
Colin Crossfb0c16e2019-11-20 17:12:35 -0800597 image := base.commonProperties.ImageVariation
Colin Crossa6845402020-11-16 15:08:19 -0800598 // Filter NativeBridge targets unless they are explicitly supported.
599 // Skip creating native bridge variants for non-core modules.
Colin Cross83bead42019-12-18 10:45:46 -0800600 if os == Android &&
601 !(Bool(base.commonProperties.Native_bridge_supported) && image == CoreVariation) {
602
Colin Crossa195f912019-10-16 11:07:20 -0700603 var targets []Target
604 for _, t := range osTargets {
605 if !t.NativeBridge {
606 targets = append(targets, t)
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700607 }
608 }
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700609
Colin Crossa195f912019-10-16 11:07:20 -0700610 osTargets = targets
611 }
Colin Crossee0bc3b2018-10-02 22:01:37 -0700612
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700613 // only the primary arch in the ramdisk / vendor_ramdisk / recovery partition
614 if os == Android && (module.InstallInRecovery() || module.InstallInRamdisk() || module.InstallInVendorRamdisk()) {
Colin Crossa195f912019-10-16 11:07:20 -0700615 osTargets = []Target{osTargets[0]}
616 }
dimitry1f33e402019-03-26 12:39:31 +0100617
Jaewoong Jung003d8082021-02-24 17:39:54 -0800618 // Windows builds always prefer 32-bit
619 prefer32 := os == Windows
dimitry1f33e402019-03-26 12:39:31 +0100620
Colin Crossa6845402020-11-16 15:08:19 -0800621 // Determine the multilib selection for this module.
Colin Crossa195f912019-10-16 11:07:20 -0700622 multilib, extraMultilib := decodeMultilib(base, os.Class)
Colin Crossa6845402020-11-16 15:08:19 -0800623
624 // Convert the multilib selection into a list of Targets.
Colin Crossa195f912019-10-16 11:07:20 -0700625 targets, err := decodeMultilibTargets(multilib, osTargets, prefer32)
626 if err != nil {
627 mctx.ModuleErrorf("%s", err.Error())
628 }
Colin Cross5eca7cb2018-10-02 14:02:10 -0700629
Colin Crossa6845402020-11-16 15:08:19 -0800630 // If the module is using extraMultilib, decode the extraMultilib selection into
631 // a separate list of Targets.
Colin Crossa195f912019-10-16 11:07:20 -0700632 var multiTargets []Target
633 if extraMultilib != "" {
634 multiTargets, err = decodeMultilibTargets(extraMultilib, osTargets, prefer32)
Colin Crossa1ad8d12016-06-01 17:09:44 -0700635 if err != nil {
636 mctx.ModuleErrorf("%s", err.Error())
637 }
Colin Crossb9db4802016-06-03 01:50:47 +0000638 }
639
Colin Crossa6845402020-11-16 15:08:19 -0800640 // Recovery is always the primary architecture, filter out any other architectures.
Inseob Kim20fb5d42021-02-02 20:07:58 +0900641 // Common arch is also allowed
Colin Crossfb0c16e2019-11-20 17:12:35 -0800642 if image == RecoveryVariation {
643 primaryArch := mctx.Config().DevicePrimaryArchType()
Inseob Kim20fb5d42021-02-02 20:07:58 +0900644 targets = filterToArch(targets, primaryArch, Common)
645 multiTargets = filterToArch(multiTargets, primaryArch, Common)
Colin Crossfb0c16e2019-11-20 17:12:35 -0800646 }
647
Colin Crossa6845402020-11-16 15:08:19 -0800648 // If there are no supported targets disable the module.
Colin Crossa195f912019-10-16 11:07:20 -0700649 if len(targets) == 0 {
Inseob Kimeec88e12020-01-22 11:11:29 +0900650 base.Disable()
Dan Willemsen3f32f032016-07-11 14:36:48 -0700651 return
652 }
653
Colin Crossa6845402020-11-16 15:08:19 -0800654 // Convert the targets into a list of arch variation names.
Colin Crossa195f912019-10-16 11:07:20 -0700655 targetNames := make([]string, len(targets))
Colin Crossa195f912019-10-16 11:07:20 -0700656 for i, target := range targets {
657 targetNames[i] = target.ArchVariation()
Colin Crossa1ad8d12016-06-01 17:09:44 -0700658 }
659
Colin Crossa6845402020-11-16 15:08:19 -0800660 // Create the variations, annotate each one with which Target it was created for, and
661 // squash the appropriate arch-specific properties into the top level properties.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700662 modules := mctx.CreateVariations(targetNames...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800663 for i, m := range modules {
Paul Duffin1356d8c2020-02-25 19:26:33 +0000664 addTargetProperties(m, targets[i], multiTargets, i == 0)
Colin Cross617b88a2020-08-24 18:04:09 -0700665 m.base().setArchProperties(mctx)
Colin Cross3f40fa42015-01-30 17:27:36 -0800666 }
667}
668
Colin Crossa6845402020-11-16 15:08:19 -0800669// addTargetProperties annotates a variant with the Target is is being compiled for, the list
670// of additional Targets it is supporting (if any), and whether it is the primary Target for
671// the module.
Paul Duffin1356d8c2020-02-25 19:26:33 +0000672func addTargetProperties(m Module, target Target, multiTargets []Target, primaryTarget bool) {
673 m.base().commonProperties.CompileTarget = target
674 m.base().commonProperties.CompileMultiTargets = multiTargets
675 m.base().commonProperties.CompilePrimary = primaryTarget
676}
677
Colin Crossa6845402020-11-16 15:08:19 -0800678// decodeMultilib returns the appropriate compile_multilib property for the module, or the default
679// multilib from the factory's call to InitAndroidArchModule if none was set. For modules that
680// called InitAndroidMultiTargetsArchModule it always returns "common" for multilib, and returns
681// the actual multilib in extraMultilib.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700682func decodeMultilib(base *ModuleBase, class OsClass) (multilib, extraMultilib string) {
Colin Crossa6845402020-11-16 15:08:19 -0800683 // First check the "android.compile_multilib" or "host.compile_multilib" properties.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700684 switch class {
685 case Device:
686 multilib = String(base.commonProperties.Target.Android.Compile_multilib)
Jiyong Park1613e552020-09-14 19:43:17 +0900687 case Host:
Colin Crossee0bc3b2018-10-02 22:01:37 -0700688 multilib = String(base.commonProperties.Target.Host.Compile_multilib)
689 }
Colin Crossa6845402020-11-16 15:08:19 -0800690
691 // If those aren't set, try the "compile_multilib" property.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700692 if multilib == "" {
693 multilib = String(base.commonProperties.Compile_multilib)
694 }
Colin Crossa6845402020-11-16 15:08:19 -0800695
696 // If that wasn't set, use the default multilib set by the factory.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700697 if multilib == "" {
698 multilib = base.commonProperties.Default_multilib
699 }
700
701 if base.commonProperties.UseTargetVariants {
702 return multilib, ""
703 } else {
704 // For app modules a single arch variant will be created per OS class which is expected to handle all the
705 // selected arches. Return the common-type as multilib and any Android.bp provided multilib as extraMultilib
706 if multilib == base.commonProperties.Default_multilib {
707 multilib = "first"
708 }
709 return base.commonProperties.Default_multilib, multilib
710 }
711}
712
Colin Crossa6845402020-11-16 15:08:19 -0800713// filterToArch takes a list of Targets and an ArchType, and returns a modified list that contains
Inseob Kim20fb5d42021-02-02 20:07:58 +0900714// only Targets that have the specified ArchTypes.
715func filterToArch(targets []Target, archs ...ArchType) []Target {
Colin Crossfb0c16e2019-11-20 17:12:35 -0800716 for i := 0; i < len(targets); i++ {
Inseob Kim20fb5d42021-02-02 20:07:58 +0900717 found := false
718 for _, arch := range archs {
719 if targets[i].Arch.ArchType == arch {
720 found = true
721 break
722 }
723 }
724 if !found {
Colin Crossfb0c16e2019-11-20 17:12:35 -0800725 targets = append(targets[:i], targets[i+1:]...)
726 i--
727 }
728 }
729 return targets
730}
731
Colin Crossa6845402020-11-16 15:08:19 -0800732// archPropRoot is a struct type used as the top level of the arch-specific properties. It
733// contains the "arch", "multilib", and "target" property structs. It is used to split up the
734// property structs to limit how much is allocated when a single arch-specific property group is
735// used. The types are interface{} because they will hold instances of runtime-created types.
Colin Crosscbbd13f2020-01-17 14:08:22 -0800736type archPropRoot struct {
737 Arch, Multilib, Target interface{}
738}
739
Colin Crossa6845402020-11-16 15:08:19 -0800740// archPropTypeDesc holds the runtime-created types for the property structs to instantiate to
741// create an archPropRoot property struct.
742type archPropTypeDesc struct {
743 arch, multilib, target reflect.Type
744}
745
Colin Crosscbbd13f2020-01-17 14:08:22 -0800746// createArchPropTypeDesc takes a reflect.Type that is either a struct or a pointer to a struct, and
747// returns lists of reflect.Types that contains the arch-variant properties inside structs for each
748// arch, multilib and target property.
Colin Crossa6845402020-11-16 15:08:19 -0800749//
750// This is a relatively expensive operation, so the results are cached in the global
751// archPropTypeMap. It is constructed entirely based on compile-time data, so there is no need
752// to isolate the results between multiple tests running in parallel.
Colin Crosscbbd13f2020-01-17 14:08:22 -0800753func createArchPropTypeDesc(props reflect.Type) []archPropTypeDesc {
Colin Crossb1d8c992020-01-21 11:43:29 -0800754 // Each property struct shard will be nested many times under the runtime generated arch struct,
755 // which can hit the limit of 64kB for the name of runtime generated structs. They are nested
756 // 97 times now, which may grow in the future, plus there is some overhead for the containing
757 // type. This number may need to be reduced if too many are added, but reducing it too far
758 // could cause problems if a single deeply nested property no longer fits in the name.
759 const maxArchTypeNameSize = 500
760
Colin Crossa6845402020-11-16 15:08:19 -0800761 // Convert the type to a new set of types that contains only the arch-specific properties
762 // (those that are tagged with `android:"arch_specific"`), and sharded into multiple types
763 // to keep the runtime-generated names under the limit.
Colin Crossb1d8c992020-01-21 11:43:29 -0800764 propShards, _ := proptools.FilterPropertyStructSharded(props, maxArchTypeNameSize, filterArchStruct)
Colin Crossa6845402020-11-16 15:08:19 -0800765
766 // If the type has no arch-specific properties there is nothing to do.
Colin Crosscb988072019-01-24 14:58:11 -0800767 if len(propShards) == 0 {
Dan Willemsenb1957a52016-06-23 23:44:54 -0700768 return nil
769 }
770
Colin Crosscbbd13f2020-01-17 14:08:22 -0800771 var ret []archPropTypeDesc
Colin Crossc17727d2018-10-24 12:42:09 -0700772 for _, props := range propShards {
Dan Willemsenb1957a52016-06-23 23:44:54 -0700773
Colin Crossa6845402020-11-16 15:08:19 -0800774 // variantFields takes a list of variant property field names and returns a list the
775 // StructFields with the names and the type of the current shard.
Colin Crossc17727d2018-10-24 12:42:09 -0700776 variantFields := func(names []string) []reflect.StructField {
777 ret := make([]reflect.StructField, len(names))
Dan Willemsenb1957a52016-06-23 23:44:54 -0700778
Colin Crossc17727d2018-10-24 12:42:09 -0700779 for i, name := range names {
780 ret[i].Name = name
781 ret[i].Type = props
Dan Willemsen866b5632017-09-22 12:28:24 -0700782 }
Colin Crossc17727d2018-10-24 12:42:09 -0700783
784 return ret
785 }
786
Colin Crossa6845402020-11-16 15:08:19 -0800787 // Create a type that contains the properties in this shard repeated for each
788 // architecture, architecture variant, and architecture feature.
Colin Crossc17727d2018-10-24 12:42:09 -0700789 archFields := make([]reflect.StructField, len(archTypeList))
790 for i, arch := range archTypeList {
Colin Crossa6845402020-11-16 15:08:19 -0800791 var variants []string
Colin Crossc17727d2018-10-24 12:42:09 -0700792
793 for _, archVariant := range archVariants[arch] {
794 archVariant := variantReplacer.Replace(archVariant)
795 variants = append(variants, proptools.FieldNameForProperty(archVariant))
796 }
797 for _, feature := range archFeatures[arch] {
798 feature := variantReplacer.Replace(feature)
799 variants = append(variants, proptools.FieldNameForProperty(feature))
800 }
801
Colin Crossa6845402020-11-16 15:08:19 -0800802 // Create the StructFields for each architecture variant architecture feature
803 // (e.g. "arch.arm.cortex-a53" or "arch.arm.neon").
Colin Crossc17727d2018-10-24 12:42:09 -0700804 fields := variantFields(variants)
805
Colin Crossa6845402020-11-16 15:08:19 -0800806 // Create the StructField for the architecture itself (e.g. "arch.arm"). The special
807 // "BlueprintEmbed" name is used by Blueprint to put the properties in the
808 // parent struct.
Colin Crossc17727d2018-10-24 12:42:09 -0700809 fields = append([]reflect.StructField{{
810 Name: "BlueprintEmbed",
811 Type: props,
812 Anonymous: true,
813 }}, fields...)
814
815 archFields[i] = reflect.StructField{
816 Name: arch.Field,
817 Type: reflect.StructOf(fields),
818 }
819 }
Colin Crossa6845402020-11-16 15:08:19 -0800820
821 // Create the type of the "arch" property struct for this shard.
Colin Crossc17727d2018-10-24 12:42:09 -0700822 archType := reflect.StructOf(archFields)
823
Colin Crossa6845402020-11-16 15:08:19 -0800824 // Create the type for the "multilib" property struct for this shard, containing the
825 // "multilib.lib32" and "multilib.lib64" property structs.
Colin Crossc17727d2018-10-24 12:42:09 -0700826 multilibType := reflect.StructOf(variantFields([]string{"Lib32", "Lib64"}))
827
Colin Crossa6845402020-11-16 15:08:19 -0800828 // Start with a list of the special targets
Colin Crossc17727d2018-10-24 12:42:09 -0700829 targets := []string{
830 "Host",
831 "Android64",
832 "Android32",
833 "Bionic",
834 "Linux",
835 "Not_windows",
836 "Arm_on_x86",
837 "Arm_on_x86_64",
Victor Khimenkoc26fcf42020-05-07 22:16:33 +0200838 "Native_bridge",
Colin Crossc17727d2018-10-24 12:42:09 -0700839 }
Paul Duffina04c1072020-03-02 10:16:35 +0000840 for _, os := range OsTypeList {
Colin Crossa6845402020-11-16 15:08:19 -0800841 // Add all the OSes.
Colin Crossc17727d2018-10-24 12:42:09 -0700842 targets = append(targets, os.Field)
843
Colin Crossa6845402020-11-16 15:08:19 -0800844 // Add the OS/Arch combinations, e.g. "android_arm64".
Colin Crossc17727d2018-10-24 12:42:09 -0700845 for _, archType := range osArchTypeMap[os] {
846 targets = append(targets, os.Field+"_"+archType.Name)
847
Colin Crossa6845402020-11-16 15:08:19 -0800848 // Also add the special "linux_<arch>" and "bionic_<arch>" property structs.
Colin Crossc17727d2018-10-24 12:42:09 -0700849 if os.Linux() {
850 target := "Linux_" + archType.Name
851 if !InList(target, targets) {
852 targets = append(targets, target)
853 }
854 }
855 if os.Bionic() {
856 target := "Bionic_" + archType.Name
857 if !InList(target, targets) {
858 targets = append(targets, target)
859 }
Dan Willemsen866b5632017-09-22 12:28:24 -0700860 }
861 }
Dan Willemsenb1957a52016-06-23 23:44:54 -0700862 }
Dan Willemsenb1957a52016-06-23 23:44:54 -0700863
Colin Crossa6845402020-11-16 15:08:19 -0800864 // Create the type for the "target" property struct for this shard.
Colin Crossc17727d2018-10-24 12:42:09 -0700865 targetType := reflect.StructOf(variantFields(targets))
Colin Crosscbbd13f2020-01-17 14:08:22 -0800866
Colin Crossa6845402020-11-16 15:08:19 -0800867 // Return a descriptor of the 3 runtime-created types.
Colin Crosscbbd13f2020-01-17 14:08:22 -0800868 ret = append(ret, archPropTypeDesc{
869 arch: reflect.PtrTo(archType),
870 multilib: reflect.PtrTo(multilibType),
871 target: reflect.PtrTo(targetType),
872 })
Colin Crossc17727d2018-10-24 12:42:09 -0700873 }
874 return ret
Dan Willemsenb1957a52016-06-23 23:44:54 -0700875}
876
Colin Crossa6845402020-11-16 15:08:19 -0800877// variantReplacer converts architecture variant or architecture feature names into names that
878// are valid for an Android.bp file.
879var variantReplacer = strings.NewReplacer("-", "_", ".", "_")
880
881// filterArchStruct returns true if the given field is an architecture specific property.
Colin Cross74449102019-09-25 11:26:40 -0700882func filterArchStruct(field reflect.StructField, prefix string) (bool, reflect.StructField) {
883 if proptools.HasTag(field, "android", "arch_variant") {
884 // The arch_variant field isn't necessary past this point
885 // Instead of wasting space, just remove it. Go also has a
886 // 16-bit limit on structure name length. The name is constructed
887 // based on the Go source representation of the structure, so
888 // the tag names count towards that length.
Colin Crossb4fecbf2020-01-21 11:38:47 -0800889
890 androidTag := field.Tag.Get("android")
891 values := strings.Split(androidTag, ",")
892
893 if string(field.Tag) != `android:"`+strings.Join(values, ",")+`"` {
894 panic(fmt.Errorf("unexpected tag format %q", field.Tag))
Colin Cross74449102019-09-25 11:26:40 -0700895 }
Colin Crossb4fecbf2020-01-21 11:38:47 -0800896 // these tags don't need to be present in the runtime generated struct type.
897 values = RemoveListFromList(values, []string{"arch_variant", "variant_prepend", "path"})
898 if len(values) > 0 {
899 panic(fmt.Errorf("unknown tags %q in field %q", values, prefix+field.Name))
900 }
901
902 field.Tag = ""
Colin Cross74449102019-09-25 11:26:40 -0700903 return true, field
904 }
905 return false, field
906}
907
Colin Crossa6845402020-11-16 15:08:19 -0800908// archPropTypeMap contains a cache of the results of createArchPropTypeDesc for each type. It is
909// shared across all Contexts, but is constructed based only on compile-time information so there
910// is no risk of contaminating one Context with data from another.
Dan Willemsenb1957a52016-06-23 23:44:54 -0700911var archPropTypeMap OncePer
912
Colin Crossa6845402020-11-16 15:08:19 -0800913// initArchModule adds the architecture-specific property structs to a Module.
914func initArchModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800915
916 base := m.base()
917
Colin Crossa6845402020-11-16 15:08:19 -0800918 // Store the original list of top level property structs
Colin Cross36242852017-06-23 15:06:31 -0700919 base.generalProperties = m.GetProperties()
Colin Cross3f40fa42015-01-30 17:27:36 -0800920
921 for _, properties := range base.generalProperties {
922 propertiesValue := reflect.ValueOf(properties)
Colin Cross62496a02016-08-08 15:49:17 -0700923 t := propertiesValue.Type()
Colin Cross3f40fa42015-01-30 17:27:36 -0800924 if propertiesValue.Kind() != reflect.Ptr {
Colin Crossca860ac2016-01-04 14:34:37 -0800925 panic(fmt.Errorf("properties must be a pointer to a struct, got %T",
926 propertiesValue.Interface()))
Colin Cross3f40fa42015-01-30 17:27:36 -0800927 }
928
929 propertiesValue = propertiesValue.Elem()
930 if propertiesValue.Kind() != reflect.Struct {
Colin Crossca860ac2016-01-04 14:34:37 -0800931 panic(fmt.Errorf("properties must be a pointer to a struct, got %T",
932 propertiesValue.Interface()))
Colin Cross3f40fa42015-01-30 17:27:36 -0800933 }
934
Colin Crossa6845402020-11-16 15:08:19 -0800935 // Get or create the arch-specific property struct types for this property struct type.
Colin Cross571cccf2019-02-04 11:22:08 -0800936 archPropTypes := archPropTypeMap.Once(NewCustomOnceKey(t), func() interface{} {
Colin Crosscbbd13f2020-01-17 14:08:22 -0800937 return createArchPropTypeDesc(t)
938 }).([]archPropTypeDesc)
Colin Cross3f40fa42015-01-30 17:27:36 -0800939
Colin Crossa6845402020-11-16 15:08:19 -0800940 // Instantiate one of each arch-specific property struct type and add it to the
941 // properties for the Module.
Colin Crossc17727d2018-10-24 12:42:09 -0700942 var archProperties []interface{}
943 for _, t := range archPropTypes {
Colin Crosscbbd13f2020-01-17 14:08:22 -0800944 archProperties = append(archProperties, &archPropRoot{
945 Arch: reflect.Zero(t.arch).Interface(),
946 Multilib: reflect.Zero(t.multilib).Interface(),
947 Target: reflect.Zero(t.target).Interface(),
948 })
Dan Willemsenb1957a52016-06-23 23:44:54 -0700949 }
Colin Crossc17727d2018-10-24 12:42:09 -0700950 base.archProperties = append(base.archProperties, archProperties)
951 m.AddProperties(archProperties...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800952 }
953
Colin Crossa6845402020-11-16 15:08:19 -0800954 // Update the list of properties that can be set by a defaults module or a call to
955 // AppendMatchingProperties or PrependMatchingProperties.
Colin Cross36242852017-06-23 15:06:31 -0700956 base.customizableProperties = m.GetProperties()
Colin Cross3f40fa42015-01-30 17:27:36 -0800957}
958
Colin Crossa6845402020-11-16 15:08:19 -0800959// appendProperties squashes properties from the given field of the given src property struct
960// into the dst property struct. Returns the reflect.Value of the field in the src property
961// struct to be used for further appendProperties calls on fields of that property struct.
Colin Cross4157e882019-06-06 16:57:04 -0700962func (m *ModuleBase) appendProperties(ctx BottomUpMutatorContext,
Dan Willemsenb1957a52016-06-23 23:44:54 -0700963 dst interface{}, src reflect.Value, field, srcPrefix string) reflect.Value {
Colin Cross06a931b2015-10-28 17:23:31 -0700964
Colin Crossa6845402020-11-16 15:08:19 -0800965 // Step into non-nil pointers to structs in the src value.
Colin Crosscbbd13f2020-01-17 14:08:22 -0800966 if src.Kind() == reflect.Ptr {
967 if src.IsNil() {
968 return src
969 }
970 src = src.Elem()
971 }
972
Colin Crossa6845402020-11-16 15:08:19 -0800973 // Find the requested field in the src struct.
Dan Willemsenb1957a52016-06-23 23:44:54 -0700974 src = src.FieldByName(field)
975 if !src.IsValid() {
Colin Crosseeabb892015-11-20 13:07:51 -0800976 ctx.ModuleErrorf("field %q does not exist", srcPrefix)
Dan Willemsenb1957a52016-06-23 23:44:54 -0700977 return src
Colin Cross85a88972015-11-23 13:29:51 -0800978 }
979
Colin Crossa6845402020-11-16 15:08:19 -0800980 // Save the value of the field in the src struct to return.
Dan Willemsenb1957a52016-06-23 23:44:54 -0700981 ret := src
Colin Cross85a88972015-11-23 13:29:51 -0800982
Colin Crossa6845402020-11-16 15:08:19 -0800983 // If the value of the field is a struct (as opposed to a pointer to a struct) then step
984 // into the BlueprintEmbed field.
Dan Willemsenb1957a52016-06-23 23:44:54 -0700985 if src.Kind() == reflect.Struct {
986 src = src.FieldByName("BlueprintEmbed")
Colin Cross06a931b2015-10-28 17:23:31 -0700987 }
988
Colin Crossa6845402020-11-16 15:08:19 -0800989 // order checks the `android:"variant_prepend"` tag to handle properties where the
990 // arch-specific value needs to come before the generic value, for example for lists of
991 // include directories.
Colin Cross6ee75b62016-05-05 15:57:15 -0700992 order := func(property string,
993 dstField, srcField reflect.StructField,
994 dstValue, srcValue interface{}) (proptools.Order, error) {
995 if proptools.HasTag(dstField, "android", "variant_prepend") {
996 return proptools.Prepend, nil
997 } else {
998 return proptools.Append, nil
999 }
1000 }
1001
Colin Crossa6845402020-11-16 15:08:19 -08001002 // Squash the located property struct into the destination property struct.
Dan Willemsenb1957a52016-06-23 23:44:54 -07001003 err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, order)
Colin Cross06a931b2015-10-28 17:23:31 -07001004 if err != nil {
1005 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
1006 ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
1007 } else {
1008 panic(err)
1009 }
1010 }
Colin Cross85a88972015-11-23 13:29:51 -08001011
Dan Willemsenb1957a52016-06-23 23:44:54 -07001012 return ret
Colin Cross06a931b2015-10-28 17:23:31 -07001013}
1014
Colin Crossa6845402020-11-16 15:08:19 -08001015// Squash the appropriate OS-specific property structs into the matching top level property structs
1016// based on the CompileOS value that was annotated on the variant.
Colin Crossa195f912019-10-16 11:07:20 -07001017func (m *ModuleBase) setOSProperties(ctx BottomUpMutatorContext) {
1018 os := m.commonProperties.CompileOS
1019
1020 for i := range m.generalProperties {
1021 genProps := m.generalProperties[i]
1022 if m.archProperties[i] == nil {
1023 continue
1024 }
1025 for _, archProperties := range m.archProperties[i] {
1026 archPropValues := reflect.ValueOf(archProperties).Elem()
1027
Colin Crosscbbd13f2020-01-17 14:08:22 -08001028 targetProp := archPropValues.FieldByName("Target").Elem()
Colin Crossa195f912019-10-16 11:07:20 -07001029
1030 // Handle host-specific properties in the form:
1031 // target: {
1032 // host: {
1033 // key: value,
1034 // },
1035 // },
Jiyong Park1613e552020-09-14 19:43:17 +09001036 if os.Class == Host {
Colin Crossa195f912019-10-16 11:07:20 -07001037 field := "Host"
1038 prefix := "target.host"
1039 m.appendProperties(ctx, genProps, targetProp, field, prefix)
1040 }
1041
1042 // Handle target OS generalities of the form:
1043 // target: {
1044 // bionic: {
1045 // key: value,
1046 // },
1047 // }
1048 if os.Linux() {
1049 field := "Linux"
1050 prefix := "target.linux"
1051 m.appendProperties(ctx, genProps, targetProp, field, prefix)
1052 }
1053
1054 if os.Bionic() {
1055 field := "Bionic"
1056 prefix := "target.bionic"
1057 m.appendProperties(ctx, genProps, targetProp, field, prefix)
1058 }
1059
1060 // Handle target OS properties in the form:
1061 // target: {
1062 // linux_glibc: {
1063 // key: value,
1064 // },
1065 // not_windows: {
1066 // key: value,
1067 // },
1068 // android {
1069 // key: value,
1070 // },
1071 // },
1072 field := os.Field
1073 prefix := "target." + os.Name
1074 m.appendProperties(ctx, genProps, targetProp, field, prefix)
1075
Jiyong Park1613e552020-09-14 19:43:17 +09001076 if os.Class == Host && os != Windows {
Colin Crossa195f912019-10-16 11:07:20 -07001077 field := "Not_windows"
1078 prefix := "target.not_windows"
1079 m.appendProperties(ctx, genProps, targetProp, field, prefix)
1080 }
1081
1082 // Handle 64-bit device properties in the form:
1083 // target {
1084 // android64 {
1085 // key: value,
1086 // },
1087 // android32 {
1088 // key: value,
1089 // },
1090 // },
1091 // WARNING: this is probably not what you want to use in your blueprints file, it selects
1092 // options for all targets on a device that supports 64-bit binaries, not just the targets
1093 // that are being compiled for 64-bit. Its expected use case is binaries like linker and
1094 // debuggerd that need to know when they are a 32-bit process running on a 64-bit device
1095 if os.Class == Device {
1096 if ctx.Config().Android64() {
1097 field := "Android64"
1098 prefix := "target.android64"
1099 m.appendProperties(ctx, genProps, targetProp, field, prefix)
1100 } else {
1101 field := "Android32"
1102 prefix := "target.android32"
1103 m.appendProperties(ctx, genProps, targetProp, field, prefix)
1104 }
1105 }
1106 }
1107 }
1108}
1109
Colin Crossa6845402020-11-16 15:08:19 -08001110// Squash the appropriate arch-specific property structs into the matching top level property
1111// structs based on the CompileTarget value that was annotated on the variant.
Colin Cross4157e882019-06-06 16:57:04 -07001112func (m *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
1113 arch := m.Arch()
1114 os := m.Os()
Colin Crossd3ba0392015-05-07 14:11:29 -07001115
Colin Cross4157e882019-06-06 16:57:04 -07001116 for i := range m.generalProperties {
1117 genProps := m.generalProperties[i]
1118 if m.archProperties[i] == nil {
Dan Willemsenb1957a52016-06-23 23:44:54 -07001119 continue
1120 }
Colin Cross4157e882019-06-06 16:57:04 -07001121 for _, archProperties := range m.archProperties[i] {
Colin Crossc17727d2018-10-24 12:42:09 -07001122 archPropValues := reflect.ValueOf(archProperties).Elem()
Dan Willemsenb1957a52016-06-23 23:44:54 -07001123
Colin Crosscbbd13f2020-01-17 14:08:22 -08001124 archProp := archPropValues.FieldByName("Arch").Elem()
1125 multilibProp := archPropValues.FieldByName("Multilib").Elem()
1126 targetProp := archPropValues.FieldByName("Target").Elem()
Dan Willemsenb1957a52016-06-23 23:44:54 -07001127
Colin Crossc17727d2018-10-24 12:42:09 -07001128 // Handle arch-specific properties in the form:
Colin Crossd5934c82017-10-02 13:55:26 -07001129 // arch: {
Colin Crossc17727d2018-10-24 12:42:09 -07001130 // arm64: {
Colin Crossd5934c82017-10-02 13:55:26 -07001131 // key: value,
1132 // },
1133 // },
Colin Crossc17727d2018-10-24 12:42:09 -07001134 t := arch.ArchType
1135
1136 if arch.ArchType != Common {
1137 field := proptools.FieldNameForProperty(t.Name)
1138 prefix := "arch." + t.Name
Colin Cross4157e882019-06-06 16:57:04 -07001139 archStruct := m.appendProperties(ctx, genProps, archProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001140
1141 // Handle arch-variant-specific properties in the form:
1142 // arch: {
1143 // variant: {
1144 // key: value,
1145 // },
1146 // },
1147 v := variantReplacer.Replace(arch.ArchVariant)
1148 if v != "" {
1149 field := proptools.FieldNameForProperty(v)
1150 prefix := "arch." + t.Name + "." + v
Colin Cross4157e882019-06-06 16:57:04 -07001151 m.appendProperties(ctx, genProps, archStruct, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001152 }
1153
1154 // Handle cpu-variant-specific properties in the form:
1155 // arch: {
1156 // variant: {
1157 // key: value,
1158 // },
1159 // },
1160 if arch.CpuVariant != arch.ArchVariant {
1161 c := variantReplacer.Replace(arch.CpuVariant)
1162 if c != "" {
1163 field := proptools.FieldNameForProperty(c)
1164 prefix := "arch." + t.Name + "." + c
Colin Cross4157e882019-06-06 16:57:04 -07001165 m.appendProperties(ctx, genProps, archStruct, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001166 }
1167 }
1168
1169 // Handle arch-feature-specific properties in the form:
1170 // arch: {
1171 // feature: {
1172 // key: value,
1173 // },
1174 // },
1175 for _, feature := range arch.ArchFeatures {
1176 field := proptools.FieldNameForProperty(feature)
1177 prefix := "arch." + t.Name + "." + feature
Colin Cross4157e882019-06-06 16:57:04 -07001178 m.appendProperties(ctx, genProps, archStruct, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001179 }
1180
1181 // Handle multilib-specific properties in the form:
1182 // multilib: {
1183 // lib32: {
1184 // key: value,
1185 // },
1186 // },
1187 field = proptools.FieldNameForProperty(t.Multilib)
1188 prefix = "multilib." + t.Multilib
Colin Cross4157e882019-06-06 16:57:04 -07001189 m.appendProperties(ctx, genProps, multilibProp, field, prefix)
Colin Cross08016332016-12-20 09:53:14 -08001190 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001191
Colin Crossa195f912019-10-16 11:07:20 -07001192 // Handle combined OS-feature and arch specific properties in the form:
Colin Crossc17727d2018-10-24 12:42:09 -07001193 // target: {
Colin Crossc17727d2018-10-24 12:42:09 -07001194 // bionic_x86: {
1195 // key: value,
1196 // },
1197 // }
Colin Crossa195f912019-10-16 11:07:20 -07001198 if os.Linux() && arch.ArchType != Common {
1199 field := "Linux_" + arch.ArchType.Name
1200 prefix := "target.linux_" + arch.ArchType.Name
Colin Cross4157e882019-06-06 16:57:04 -07001201 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossd5934c82017-10-02 13:55:26 -07001202 }
Colin Crossc5c24ad2015-11-20 15:35:00 -08001203
Colin Crossa195f912019-10-16 11:07:20 -07001204 if os.Bionic() && arch.ArchType != Common {
1205 field := "Bionic_" + t.Name
1206 prefix := "target.bionic_" + t.Name
Colin Cross4157e882019-06-06 16:57:04 -07001207 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001208 }
1209
Colin Crossa195f912019-10-16 11:07:20 -07001210 // Handle combined OS and arch specific properties in the form:
Colin Crossc17727d2018-10-24 12:42:09 -07001211 // target: {
Colin Crossc17727d2018-10-24 12:42:09 -07001212 // linux_glibc_x86: {
1213 // key: value,
1214 // },
1215 // linux_glibc_arm: {
1216 // key: value,
1217 // },
Colin Crossc17727d2018-10-24 12:42:09 -07001218 // android_arm {
1219 // key: value,
1220 // },
1221 // android_x86 {
Colin Crossd5934c82017-10-02 13:55:26 -07001222 // key: value,
1223 // },
1224 // },
Colin Crossc17727d2018-10-24 12:42:09 -07001225 if arch.ArchType != Common {
Colin Crossa195f912019-10-16 11:07:20 -07001226 field := os.Field + "_" + t.Name
1227 prefix := "target." + os.Name + "_" + t.Name
Colin Cross4157e882019-06-06 16:57:04 -07001228 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossd5934c82017-10-02 13:55:26 -07001229 }
1230
Colin Crossa195f912019-10-16 11:07:20 -07001231 // Handle arm on x86 properties in the form:
Colin Crossc17727d2018-10-24 12:42:09 -07001232 // target {
Colin Crossa195f912019-10-16 11:07:20 -07001233 // arm_on_x86 {
Colin Crossc17727d2018-10-24 12:42:09 -07001234 // key: value,
1235 // },
Colin Crossa195f912019-10-16 11:07:20 -07001236 // arm_on_x86_64 {
Colin Crossd5934c82017-10-02 13:55:26 -07001237 // key: value,
1238 // },
1239 // },
Colin Crossc17727d2018-10-24 12:42:09 -07001240 if os.Class == Device {
Victor Khimenko1a31f802020-09-17 03:07:31 +02001241 if arch.ArchType == X86 && (hasArmAbi(arch) ||
1242 hasArmAndroidArch(ctx.Config().Targets[Android])) {
Colin Crossc17727d2018-10-24 12:42:09 -07001243 field := "Arm_on_x86"
1244 prefix := "target.arm_on_x86"
Colin Cross4157e882019-06-06 16:57:04 -07001245 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001246 }
Victor Khimenko1a31f802020-09-17 03:07:31 +02001247 if arch.ArchType == X86_64 && (hasArmAbi(arch) ||
1248 hasArmAndroidArch(ctx.Config().Targets[Android])) {
Colin Crossc17727d2018-10-24 12:42:09 -07001249 field := "Arm_on_x86_64"
1250 prefix := "target.arm_on_x86_64"
Colin Cross4157e882019-06-06 16:57:04 -07001251 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001252 }
Victor Khimenkoc26fcf42020-05-07 22:16:33 +02001253 if os == Android && m.Target().NativeBridge == NativeBridgeEnabled {
1254 field := "Native_bridge"
1255 prefix := "target.native_bridge"
1256 m.appendProperties(ctx, genProps, targetProp, field, prefix)
1257 }
Colin Cross4247f0d2017-04-13 16:56:14 -07001258 }
Colin Crossbb2e2b72016-12-08 17:23:53 -08001259 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001260 }
1261}
1262
Colin Crossa6845402020-11-16 15:08:19 -08001263// Convert the arch product variables into a list of targets for each OsType.
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001264func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001265 variables := config.productVariables
Dan Willemsen490fd492015-11-24 17:53:15 -08001266
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001267 targets := make(map[OsType][]Target)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001268 var targetErr error
1269
dimitry1f33e402019-03-26 12:39:31 +01001270 addTarget := func(os OsType, archName string, archVariant, cpuVariant *string, abi []string,
dimitry8d6dde82019-07-11 10:23:53 +02001271 nativeBridgeEnabled NativeBridgeSupport, nativeBridgeHostArchName *string,
1272 nativeBridgeRelativePath *string) {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001273 if targetErr != nil {
1274 return
Dan Willemsen490fd492015-11-24 17:53:15 -08001275 }
Colin Crossa1ad8d12016-06-01 17:09:44 -07001276
Dan Willemsen01a3c252019-01-11 19:02:16 -08001277 arch, err := decodeArch(os, archName, archVariant, cpuVariant, abi)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001278 if err != nil {
1279 targetErr = err
1280 return
1281 }
dimitry8d6dde82019-07-11 10:23:53 +02001282 nativeBridgeRelativePathStr := String(nativeBridgeRelativePath)
1283 nativeBridgeHostArchNameStr := String(nativeBridgeHostArchName)
1284
1285 // Use guest arch as relative install path by default
1286 if nativeBridgeEnabled && nativeBridgeRelativePathStr == "" {
1287 nativeBridgeRelativePathStr = arch.ArchType.String()
1288 }
Colin Crossa1ad8d12016-06-01 17:09:44 -07001289
Jiyong Park1613e552020-09-14 19:43:17 +09001290 // A target is considered as HostCross if it's a host target which can't run natively on
1291 // the currently configured build machine (either because the OS is different or because of
1292 // the unsupported arch)
1293 hostCross := false
1294 if os.Class == Host {
1295 var osSupported bool
1296 if os == BuildOs {
1297 osSupported = true
1298 } else if BuildOs.Linux() && os.Linux() {
1299 // LinuxBionic and Linux are compatible
1300 osSupported = true
1301 } else {
1302 osSupported = false
1303 }
1304
1305 var archSupported bool
1306 if arch.ArchType == Common {
1307 archSupported = true
1308 } else if arch.ArchType.Name == *variables.HostArch {
1309 archSupported = true
1310 } else if variables.HostSecondaryArch != nil && arch.ArchType.Name == *variables.HostSecondaryArch {
1311 archSupported = true
1312 } else {
1313 archSupported = false
1314 }
1315 if !osSupported || !archSupported {
1316 hostCross = true
1317 }
1318 }
1319
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001320 targets[os] = append(targets[os],
Colin Crossa1ad8d12016-06-01 17:09:44 -07001321 Target{
dimitry8d6dde82019-07-11 10:23:53 +02001322 Os: os,
1323 Arch: arch,
1324 NativeBridge: nativeBridgeEnabled,
1325 NativeBridgeHostArchName: nativeBridgeHostArchNameStr,
1326 NativeBridgeRelativePath: nativeBridgeRelativePathStr,
Jiyong Park1613e552020-09-14 19:43:17 +09001327 HostCross: hostCross,
Colin Crossa1ad8d12016-06-01 17:09:44 -07001328 })
Dan Willemsen490fd492015-11-24 17:53:15 -08001329 }
1330
Colin Cross4225f652015-09-17 14:33:42 -07001331 if variables.HostArch == nil {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001332 return nil, fmt.Errorf("No host primary architecture set")
Colin Cross4225f652015-09-17 14:33:42 -07001333 }
1334
Colin Crossa6845402020-11-16 15:08:19 -08001335 // The primary host target, which must always exist.
dimitry8d6dde82019-07-11 10:23:53 +02001336 addTarget(BuildOs, *variables.HostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil)
Colin Cross4225f652015-09-17 14:33:42 -07001337
Colin Crossa6845402020-11-16 15:08:19 -08001338 // An optional secondary host target.
Colin Crosseeabb892015-11-20 13:07:51 -08001339 if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" {
dimitry8d6dde82019-07-11 10:23:53 +02001340 addTarget(BuildOs, *variables.HostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil)
Dan Willemsen490fd492015-11-24 17:53:15 -08001341 }
1342
Colin Crossa6845402020-11-16 15:08:19 -08001343 // Optional cross-compiled host targets, generally Windows.
Colin Crossff3ae9d2018-04-10 16:15:18 -07001344 if String(variables.CrossHost) != "" {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001345 crossHostOs := osByName(*variables.CrossHost)
1346 if crossHostOs == NoOsType {
1347 return nil, fmt.Errorf("Unknown cross host OS %q", *variables.CrossHost)
1348 }
1349
Colin Crossff3ae9d2018-04-10 16:15:18 -07001350 if String(variables.CrossHostArch) == "" {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001351 return nil, fmt.Errorf("No cross-host primary architecture set")
Dan Willemsen490fd492015-11-24 17:53:15 -08001352 }
1353
Colin Crossa6845402020-11-16 15:08:19 -08001354 // The primary cross-compiled host target.
dimitry8d6dde82019-07-11 10:23:53 +02001355 addTarget(crossHostOs, *variables.CrossHostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil)
Dan Willemsen490fd492015-11-24 17:53:15 -08001356
Colin Crossa6845402020-11-16 15:08:19 -08001357 // An optional secondary cross-compiled host target.
Dan Willemsen490fd492015-11-24 17:53:15 -08001358 if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" {
dimitry8d6dde82019-07-11 10:23:53 +02001359 addTarget(crossHostOs, *variables.CrossHostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil)
Dan Willemsen490fd492015-11-24 17:53:15 -08001360 }
1361 }
1362
Colin Crossa6845402020-11-16 15:08:19 -08001363 // Optional device targets
Dan Willemsen3f32f032016-07-11 14:36:48 -07001364 if variables.DeviceArch != nil && *variables.DeviceArch != "" {
Doug Horn21b94272019-01-16 12:06:11 -08001365 var target = Android
1366 if Bool(variables.Fuchsia) {
1367 target = Fuchsia
1368 }
1369
Colin Crossa6845402020-11-16 15:08:19 -08001370 // The primary device target.
Doug Horn21b94272019-01-16 12:06:11 -08001371 addTarget(target, *variables.DeviceArch, variables.DeviceArchVariant,
dimitry8d6dde82019-07-11 10:23:53 +02001372 variables.DeviceCpuVariant, variables.DeviceAbi, NativeBridgeDisabled, nil, nil)
Colin Cross4225f652015-09-17 14:33:42 -07001373
Colin Crossa6845402020-11-16 15:08:19 -08001374 // An optional secondary device target.
Dan Willemsen3f32f032016-07-11 14:36:48 -07001375 if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" {
1376 addTarget(Android, *variables.DeviceSecondaryArch,
1377 variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant,
dimitry8d6dde82019-07-11 10:23:53 +02001378 variables.DeviceSecondaryAbi, NativeBridgeDisabled, nil, nil)
Colin Cross4225f652015-09-17 14:33:42 -07001379 }
dimitry1f33e402019-03-26 12:39:31 +01001380
Colin Crossa6845402020-11-16 15:08:19 -08001381 // An optional NativeBridge device target.
dimitry1f33e402019-03-26 12:39:31 +01001382 if variables.NativeBridgeArch != nil && *variables.NativeBridgeArch != "" {
1383 addTarget(Android, *variables.NativeBridgeArch,
1384 variables.NativeBridgeArchVariant, variables.NativeBridgeCpuVariant,
dimitry8d6dde82019-07-11 10:23:53 +02001385 variables.NativeBridgeAbi, NativeBridgeEnabled, variables.DeviceArch,
1386 variables.NativeBridgeRelativePath)
dimitry1f33e402019-03-26 12:39:31 +01001387 }
1388
Colin Crossa6845402020-11-16 15:08:19 -08001389 // An optional secondary NativeBridge device target.
dimitry1f33e402019-03-26 12:39:31 +01001390 if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" &&
1391 variables.NativeBridgeSecondaryArch != nil && *variables.NativeBridgeSecondaryArch != "" {
1392 addTarget(Android, *variables.NativeBridgeSecondaryArch,
1393 variables.NativeBridgeSecondaryArchVariant,
1394 variables.NativeBridgeSecondaryCpuVariant,
dimitry8d6dde82019-07-11 10:23:53 +02001395 variables.NativeBridgeSecondaryAbi,
1396 NativeBridgeEnabled,
1397 variables.DeviceSecondaryArch,
1398 variables.NativeBridgeSecondaryRelativePath)
dimitry1f33e402019-03-26 12:39:31 +01001399 }
Colin Cross4225f652015-09-17 14:33:42 -07001400 }
1401
Colin Crossa1ad8d12016-06-01 17:09:44 -07001402 if targetErr != nil {
1403 return nil, targetErr
1404 }
1405
1406 return targets, nil
Colin Cross4225f652015-09-17 14:33:42 -07001407}
1408
Colin Crossbb2e2b72016-12-08 17:23:53 -08001409// hasArmAbi returns true if arch has at least one arm ABI
1410func hasArmAbi(arch Arch) bool {
Jaewoong Jung3aff5782020-02-11 07:54:35 -08001411 return PrefixInList(arch.Abi, "arm")
Colin Crossbb2e2b72016-12-08 17:23:53 -08001412}
1413
dimitry628db6f2019-05-22 17:16:21 +02001414// hasArmArch returns true if targets has at least non-native_bridge arm Android arch
Colin Cross4247f0d2017-04-13 16:56:14 -07001415func hasArmAndroidArch(targets []Target) bool {
1416 for _, target := range targets {
Victor Khimenko1a31f802020-09-17 03:07:31 +02001417 if target.Os == Android && target.Arch.ArchType == Arm {
Victor Khimenko5eb8ec12018-03-21 20:30:54 +01001418 return true
1419 }
1420 }
1421 return false
1422}
1423
Colin Crossa6845402020-11-16 15:08:19 -08001424// archConfig describes a built-in configuration.
Dan Albert4098deb2016-10-19 14:04:41 -07001425type archConfig struct {
1426 arch string
1427 archVariant string
1428 cpuVariant string
1429 abi []string
1430}
1431
Colin Crossa6845402020-11-16 15:08:19 -08001432// getNdkAbisConfig returns a list of archConfigs for the ABIs supported by the NDK.
Dan Albert4098deb2016-10-19 14:04:41 -07001433func getNdkAbisConfig() []archConfig {
1434 return []archConfig{
Dan Albert6bba6442020-01-30 15:16:49 -08001435 {"arm", "armv7-a", "", []string{"armeabi-v7a"}},
Tamas Petzbca786d2021-01-20 18:56:33 +01001436 {"arm64", "armv8-a-branchprot", "", []string{"arm64-v8a"}},
Dan Albert4098deb2016-10-19 14:04:41 -07001437 {"x86", "", "", []string{"x86"}},
1438 {"x86_64", "", "", []string{"x86_64"}},
1439 }
1440}
1441
Colin Crossa6845402020-11-16 15:08:19 -08001442// getAmlAbisConfig returns a list of archConfigs for the ABIs supported by mainline modules.
Martin Stjernholmc1ecc432019-11-15 15:00:31 +00001443func getAmlAbisConfig() []archConfig {
1444 return []archConfig{
Martin Stjernholm93688342020-10-16 21:45:10 +01001445 {"arm", "armv7-a-neon", "", []string{"armeabi-v7a"}},
Martin Stjernholmc1ecc432019-11-15 15:00:31 +00001446 {"arm64", "armv8-a", "", []string{"arm64-v8a"}},
1447 {"x86", "", "", []string{"x86"}},
1448 {"x86_64", "", "", []string{"x86_64"}},
1449 }
1450}
1451
Colin Crossa6845402020-11-16 15:08:19 -08001452// decodeArchSettings converts a list of archConfigs into a list of Targets for the given OsType.
Dan Willemsen01a3c252019-01-11 19:02:16 -08001453func decodeArchSettings(os OsType, archConfigs []archConfig) ([]Target, error) {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001454 var ret []Target
Dan Willemsen322acaf2016-01-12 23:07:05 -08001455
Dan Albert4098deb2016-10-19 14:04:41 -07001456 for _, config := range archConfigs {
Dan Willemsen01a3c252019-01-11 19:02:16 -08001457 arch, err := decodeArch(os, config.arch, &config.archVariant,
Colin Crossa74ca042019-01-31 14:31:51 -08001458 &config.cpuVariant, config.abi)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001459 if err != nil {
1460 return nil, err
1461 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001462
Colin Crossa1ad8d12016-06-01 17:09:44 -07001463 ret = append(ret, Target{
1464 Os: Android,
1465 Arch: arch,
1466 })
Dan Willemsen322acaf2016-01-12 23:07:05 -08001467 }
1468
1469 return ret, nil
1470}
1471
Colin Crossa6845402020-11-16 15:08:19 -08001472// decodeArch converts a set of strings from product variables into an Arch struct.
Colin Crossa74ca042019-01-31 14:31:51 -08001473func decodeArch(os OsType, arch string, archVariant, cpuVariant *string, abi []string) (Arch, error) {
Colin Crossa6845402020-11-16 15:08:19 -08001474 // Verify the arch is valid
Colin Crosseeabb892015-11-20 13:07:51 -08001475 archType, ok := archTypeMap[arch]
1476 if !ok {
1477 return Arch{}, fmt.Errorf("unknown arch %q", arch)
1478 }
Colin Cross4225f652015-09-17 14:33:42 -07001479
Colin Crosseeabb892015-11-20 13:07:51 -08001480 a := Arch{
Colin Cross4225f652015-09-17 14:33:42 -07001481 ArchType: archType,
Colin Crossa6845402020-11-16 15:08:19 -08001482 ArchVariant: String(archVariant),
1483 CpuVariant: String(cpuVariant),
Colin Crossa74ca042019-01-31 14:31:51 -08001484 Abi: abi,
Colin Crosseeabb892015-11-20 13:07:51 -08001485 }
1486
Colin Crossa6845402020-11-16 15:08:19 -08001487 // Convert generic arch variants into the empty string.
Colin Crosseeabb892015-11-20 13:07:51 -08001488 if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" {
1489 a.ArchVariant = ""
1490 }
1491
Colin Crossa6845402020-11-16 15:08:19 -08001492 // Convert generic CPU variants into the empty string.
Colin Crosseeabb892015-11-20 13:07:51 -08001493 if a.CpuVariant == a.ArchType.Name || a.CpuVariant == "generic" {
1494 a.CpuVariant = ""
1495 }
1496
Colin Crossa6845402020-11-16 15:08:19 -08001497 // Filter empty ABIs out of the list.
Colin Crosseeabb892015-11-20 13:07:51 -08001498 for i := 0; i < len(a.Abi); i++ {
1499 if a.Abi[i] == "" {
1500 a.Abi = append(a.Abi[:i], a.Abi[i+1:]...)
1501 i--
1502 }
1503 }
1504
Dan Willemsen01a3c252019-01-11 19:02:16 -08001505 if a.ArchVariant == "" {
Colin Crossa6845402020-11-16 15:08:19 -08001506 // Set ArchFeatures from the default arch features.
Dan Willemsen01a3c252019-01-11 19:02:16 -08001507 if featureMap, ok := defaultArchFeatureMap[os]; ok {
1508 a.ArchFeatures = featureMap[archType]
1509 }
1510 } else {
Colin Crossa6845402020-11-16 15:08:19 -08001511 // Set ArchFeatures from the arch type.
Dan Willemsen01a3c252019-01-11 19:02:16 -08001512 if featureMap, ok := archFeatureMap[archType]; ok {
1513 a.ArchFeatures = featureMap[a.ArchVariant]
1514 }
Colin Crossc5c24ad2015-11-20 15:35:00 -08001515 }
1516
Colin Crosseeabb892015-11-20 13:07:51 -08001517 return a, nil
Colin Cross4225f652015-09-17 14:33:42 -07001518}
1519
Colin Crossa6845402020-11-16 15:08:19 -08001520// filterMultilibTargets takes a list of Targets and a multilib value and returns a new list of
1521// Targets containing only those that have the given multilib value.
Colin Cross69617d32016-09-06 10:39:07 -07001522func filterMultilibTargets(targets []Target, multilib string) []Target {
1523 var ret []Target
1524 for _, t := range targets {
1525 if t.Arch.ArchType.Multilib == multilib {
1526 ret = append(ret, t)
1527 }
1528 }
1529 return ret
1530}
1531
Colin Crossa6845402020-11-16 15:08:19 -08001532// getCommonTargets returns the set of Os specific common architecture targets for each Os in a list
1533// of targets.
Nan Zhangdb0b9a32017-02-27 10:12:13 -08001534func getCommonTargets(targets []Target) []Target {
1535 var ret []Target
1536 set := make(map[string]bool)
1537
1538 for _, t := range targets {
1539 if _, found := set[t.Os.String()]; !found {
1540 set[t.Os.String()] = true
1541 ret = append(ret, commonTargetMap[t.Os.String()])
1542 }
1543 }
1544
1545 return ret
1546}
1547
Colin Crossa6845402020-11-16 15:08:19 -08001548// firstTarget takes a list of Targets and a list of multilib values and returns a list of Targets
1549// that contains zero or one Target for each OsType, selecting the one that matches the earliest
1550// filter.
Colin Cross3dceee32018-09-06 10:19:57 -07001551func firstTarget(targets []Target, filters ...string) []Target {
Jiyong Park22101982020-09-17 19:09:58 +09001552 // find the first target from each OS
1553 var ret []Target
1554 hasHost := false
1555 set := make(map[OsType]bool)
1556
Colin Cross6b4a32d2017-12-05 13:42:45 -08001557 for _, filter := range filters {
1558 buildTargets := filterMultilibTargets(targets, filter)
Jiyong Park22101982020-09-17 19:09:58 +09001559 for _, t := range buildTargets {
1560 if _, found := set[t.Os]; !found {
1561 hasHost = hasHost || (t.Os.Class == Host)
1562 set[t.Os] = true
1563 ret = append(ret, t)
1564 }
Colin Cross6b4a32d2017-12-05 13:42:45 -08001565 }
1566 }
Jiyong Park22101982020-09-17 19:09:58 +09001567 return ret
Colin Cross6b4a32d2017-12-05 13:42:45 -08001568}
1569
Colin Crossa6845402020-11-16 15:08:19 -08001570// decodeMultilibTargets uses the module's multilib setting to select one or more targets from a
1571// list of Targets.
Colin Crossee0bc3b2018-10-02 22:01:37 -07001572func decodeMultilibTargets(multilib string, targets []Target, prefer32 bool) ([]Target, error) {
Colin Crossa6845402020-11-16 15:08:19 -08001573 var buildTargets []Target
Colin Cross6b4a32d2017-12-05 13:42:45 -08001574
Colin Cross4225f652015-09-17 14:33:42 -07001575 switch multilib {
1576 case "common":
Colin Cross6b4a32d2017-12-05 13:42:45 -08001577 buildTargets = getCommonTargets(targets)
1578 case "common_first":
1579 buildTargets = getCommonTargets(targets)
1580 if prefer32 {
Colin Cross3dceee32018-09-06 10:19:57 -07001581 buildTargets = append(buildTargets, firstTarget(targets, "lib32", "lib64")...)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001582 } else {
Colin Cross3dceee32018-09-06 10:19:57 -07001583 buildTargets = append(buildTargets, firstTarget(targets, "lib64", "lib32")...)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001584 }
Colin Cross4225f652015-09-17 14:33:42 -07001585 case "both":
Colin Cross8b74d172016-09-13 09:59:14 -07001586 if prefer32 {
1587 buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...)
1588 buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...)
1589 } else {
1590 buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...)
1591 buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...)
1592 }
Colin Cross4225f652015-09-17 14:33:42 -07001593 case "32":
Colin Cross69617d32016-09-06 10:39:07 -07001594 buildTargets = filterMultilibTargets(targets, "lib32")
Colin Cross4225f652015-09-17 14:33:42 -07001595 case "64":
Colin Cross69617d32016-09-06 10:39:07 -07001596 buildTargets = filterMultilibTargets(targets, "lib64")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001597 case "first":
1598 if prefer32 {
Colin Cross3dceee32018-09-06 10:19:57 -07001599 buildTargets = firstTarget(targets, "lib32", "lib64")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001600 } else {
Colin Cross3dceee32018-09-06 10:19:57 -07001601 buildTargets = firstTarget(targets, "lib64", "lib32")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001602 }
Victor Chang9448e8f2020-09-14 15:34:16 +01001603 case "first_prefer32":
1604 buildTargets = firstTarget(targets, "lib32", "lib64")
Colin Cross69617d32016-09-06 10:39:07 -07001605 case "prefer32":
Colin Cross3dceee32018-09-06 10:19:57 -07001606 buildTargets = filterMultilibTargets(targets, "lib32")
1607 if len(buildTargets) == 0 {
1608 buildTargets = filterMultilibTargets(targets, "lib64")
1609 }
Colin Cross4225f652015-09-17 14:33:42 -07001610 default:
Victor Chang9448e8f2020-09-14 15:34:16 +01001611 return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", "64", "prefer32" or "first_prefer32" found %q`,
Colin Cross4225f652015-09-17 14:33:42 -07001612 multilib)
Colin Cross4225f652015-09-17 14:33:42 -07001613 }
1614
Colin Crossa1ad8d12016-06-01 17:09:44 -07001615 return buildTargets, nil
Colin Cross4225f652015-09-17 14:33:42 -07001616}
Jingwen Chen5d864492021-02-24 07:20:12 -05001617
1618// GetArchProperties returns a map of architectures to the values of the
1619// properties of the 'dst' struct that are specific to that architecture.
1620//
1621// For example, passing a struct { Foo bool, Bar string } will return an
1622// interface{} that can be type asserted back into the same struct, containing
1623// the arch specific property value specified by the module if defined.
1624func (m *ModuleBase) GetArchProperties(dst interface{}) map[ArchType]interface{} {
1625 // Return value of the arch types to the prop values for that arch.
1626 archToProp := map[ArchType]interface{}{}
1627
1628 // Nothing to do for non-arch-specific modules.
1629 if !m.ArchSpecific() {
1630 return archToProp
1631 }
1632
1633 // archProperties has the type of [][]interface{}. Looks complicated, so let's
1634 // explain this step by step.
1635 //
1636 // Loop over the outer index, which determines the property struct that
1637 // contains a matching set of properties in dst that we're interested in.
1638 // For example, BaseCompilerProperties or BaseLinkerProperties.
1639 for i := range m.archProperties {
1640 if m.archProperties[i] == nil {
1641 // Skip over nil arch props
1642 continue
1643 }
1644
1645 // Non-nil arch prop, let's see if the props match up.
1646 for _, arch := range ArchTypeList() {
1647 // e.g X86, Arm
1648 field := arch.Field
1649
1650 // If it's not nil, loop over the inner index, which determines the arch variant
1651 // of the prop type. In an Android.bp file, this is like looping over:
1652 //
1653 // arch: { arm: { key: value, ... }, x86: { key: value, ... } }
1654 for _, archProperties := range m.archProperties[i] {
1655 archPropValues := reflect.ValueOf(archProperties).Elem()
1656
1657 // This is the archPropRoot struct. Traverse into the Arch nested struct.
1658 src := archPropValues.FieldByName("Arch").Elem()
1659
1660 // Step into non-nil pointers to structs in the src value.
1661 if src.Kind() == reflect.Ptr {
1662 if src.IsNil() {
1663 // Ignore nil pointers.
1664 continue
1665 }
1666 src = src.Elem()
1667 }
1668
1669 // Find the requested field (e.g. x86, x86_64) in the src struct.
1670 src = src.FieldByName(field)
1671 if !src.IsValid() {
1672 continue
1673 }
1674
1675 // We only care about structs. These are not the droids you are looking for.
1676 if src.Kind() != reflect.Struct {
1677 continue
1678 }
1679
1680 // If the value of the field is a struct then step into the
1681 // BlueprintEmbed field. The special "BlueprintEmbed" name is
1682 // used by createArchPropTypeDesc to embed the arch properties
1683 // in the parent struct, so the src arch prop should be in this
1684 // field.
1685 //
1686 // See createArchPropTypeDesc for more details on how Arch-specific
1687 // module properties are processed from the nested props and written
1688 // into the module's archProperties.
1689 src = src.FieldByName("BlueprintEmbed")
1690
1691 // Clone the destination prop, since we want a unique prop struct per arch.
1692 dstClone := reflect.New(reflect.ValueOf(dst).Elem().Type()).Interface()
1693
1694 // Copy the located property struct into the cloned destination property struct.
1695 err := proptools.ExtendMatchingProperties([]interface{}{dstClone}, src.Interface(), nil, proptools.OrderReplace)
1696 if err != nil {
1697 // This is fine, it just means the src struct doesn't match.
1698 continue
1699 }
1700
1701 // Found the prop for the arch, you have.
1702 archToProp[arch] = dstClone
1703
1704 // Go to the next prop.
1705 break
1706 }
1707 }
1708 }
1709 return archToProp
1710}