Bug 1264482 - Use the limited string type for the different values we get out of split_triplet. r?ted draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 06 Apr 2016 09:56:35 +0900
changeset 350674 31d971391da2345d77a794d6a45f5df8ea5fd6dc
parent 350673 162b86a8401fc39261fee10b46955926a61bd539
child 350675 3469be0504dbcefa776784b49926c55ae12cd5a9
push id15385
push userbmo:mh+mozilla@glandium.org
push dateThu, 14 Apr 2016 04:41:28 +0000
reviewersted
bugs1264482
milestone48.0a1
Bug 1264482 - Use the limited string type for the different values we get out of split_triplet. r?ted
build/moz.configure/android-ndk.configure
build/moz.configure/init.configure
--- a/build/moz.configure/android-ndk.configure
+++ b/build/moz.configure/android-ndk.configure
@@ -34,17 +34,17 @@ def android_toolchain(target, host, ndk,
         return
     if toolchain:
         return toolchain[0]
     else:
         if target.cpu == 'arm' and target.endianness == 'little':
             target_base = 'arm-linux-androideabi'
         elif target.cpu == 'x86':
             target_base = 'x86'
-        elif target.cpu == 'mips' and target.endianness == 'little':
+        elif target.cpu == 'mips32' and target.endianness == 'little':
             target_base = 'mipsel-linux-android'
         else:
             die('Target cpu is not supported.')
 
         toolchain_format = '%s/toolchains/%s-%s/prebuilt/%s-%s'
 
         for version in gnu_compiler_version or ['4.9', '4.8', '4.7']:
             toolchain = toolchain_format % (ndk, target_base, version,
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -362,17 +362,34 @@ def shell(mozillabuild):
 # Host and target systems
 # ==============================================================
 option('--host', nargs=1, help='Define the system type performing the build')
 
 option('--target', nargs=1,
        help='Define the system type where the resulting executables will be '
             'used')
 
+@imports(_from='mozbuild.util', _import='LimitedString')
 def split_triplet(triplet):
+    class OS(LimitedString):
+        POSSIBLE_VALUES = ('Android', 'GNU', 'WINNT', 'OSX', 'iOS',
+                           'DragonFly', 'FreeBSD', 'NetBSD', 'OpenBSD')
+
+    class Kernel(LimitedString):
+        POSSIBLE_VALUES = ('Linux', 'kFreeBSD', 'WINNT', 'Darwin',
+                           'DragonFly', 'FreeBSD', 'NetBSD', 'OpenBSD')
+
+    class CPU(LimitedString):
+        POSSIBLE_VALUES = ('x86', 'x86_64', 'ia64', 's390', 's390x', 'ppc64',
+                           'ppc', 'Alpha', 'hppa', 'sparc64', 'sparc', 'arm',
+                           'mips32', 'mips64', 'aarch64')
+
+    class Endianness(LimitedString):
+        POSSIBLE_VALUES = ('little', 'big')
+
     # The standard triplet is defined as
     #   CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
     # There is also a quartet form:
     #   CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
     # But we can consider the "KERNEL-OPERATING_SYSTEM" as one.
     cpu, manufacturer, os = triplet.split('-', 2)
 
     # Autoconf uses config.sub to validate and canonicalize those triplets,
@@ -457,20 +474,20 @@ def split_triplet(triplet):
         canonical_cpu = 'aarch64'
         endianness = 'little'
     else:
         canonical_cpu = cpu
         endianness = 'unknown'
 
     return namespace(
         alias=triplet,
-        cpu=canonical_cpu,
-        kernel=canonical_kernel,
-        os=canonical_os,
-        endianness=endianness,
+        cpu=CPU(canonical_cpu),
+        kernel=Kernel(canonical_kernel),
+        os=OS(canonical_os),
+        endianness=Endianness(endianness),
         raw_cpu=cpu,
         raw_os=os,
         # Toolchains, most notably for cross compilation may use cpu-os
         # prefixes.
         toolchain='%s-%s' % (cpu, os),
     )
 
 
@@ -542,17 +559,17 @@ def target_variables(target):
     elif target.kernel == 'Darwin' or (target.kernel == 'Linux' and
                                        target.os == 'GNU'):
         os_target = target.kernel
         os_arch = target.kernel
     else:
         os_target = target.os
         os_arch = target.kernel
 
-    if target.os == 'Darwin' and target.cpu == 'x86':
+    if target.kernel == 'Darwin' and target.cpu == 'x86':
         os_test = 'i386'
     else:
         os_test = target.raw_cpu
 
     return namespace(
         OS_TARGET=os_target,
         OS_ARCH=os_arch,
         OS_TEST=os_test,