Don't panic when DevicePrimaryArchType is called in a host only build
Check the length of c.Targets[Android] before getting the first
element, and return Common if the length is set. Fixes a panic
when a tradefed_binary is defined in a host-only build.
Test: aosp-build-tools build
Change-Id: I89f1dd13aa1aff5eb7d39e0b66eeedcb7d930fa0
diff --git a/android/config.go b/android/config.go
index 8e01e18..4a4da08 100644
--- a/android/config.go
+++ b/android/config.go
@@ -892,8 +892,13 @@
return Bool(c.productVariables.Eng)
}
+// DevicePrimaryArchType returns the ArchType for the first configured device architecture, or
+// Common if there are no device architectures.
func (c *config) DevicePrimaryArchType() ArchType {
- return c.Targets[Android][0].Arch.ArchType
+ if androidTargets := c.Targets[Android]; len(androidTargets) > 0 {
+ return androidTargets[0].Arch.ArchType
+ }
+ return Common
}
func (c *config) SanitizeHost() []string {