1 # Copyright (c) 2014 The Native Client Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Conditions for scons to gn
7 Contains all conditions we iterate over (OS, CPU), as well as helper
23 class Conditions(object):
24 def __init__(self, seta, setb):
27 self._all = ['%s_%s' % (a, b) for a in seta for b in setb]
28 self._active_condition = self._all[0]
30 def get(self, key, default=False):
31 os, arch = self._active_condition.split('_')
32 if key in ["TARGET_FULLARCH", "TARGET_ARCHITECTURE"]:
34 if key == "TARGET_SUBARCH":
41 _, arch = self._active_condition.split('_')
43 if name == 'coverage_enabled':
46 if name == 'build_x86':
47 return arch == 'x86' or arch == 'x64'
49 if name == 'build_arm':
52 if name == 'build_x86_32':
55 if name == 'build_x86_64':
58 if name == 'build_mips32':
59 return arch == 'mips32'
61 if name == 'target_arm':
64 if name == 'target_x86':
65 return arch == 'x86' or arch == 'x64'
67 if name == 'target_x86_32':
70 if name == 'target_x86_64':
73 print 'Unknown bit: ' + name
82 def ActiveCondition(self):
83 return self._active_condition
85 def SetActiveCondition(self, cond):
86 if cond not in self._all:
87 raise RuntimeError('Unknown condition: ' + cond)
88 self._active_condition = cond
90 def WriteImports(self, fileobj):
93 for imp in self.imports:
94 fileobj.write('import("%s")\n' % imp)
98 class TrustedConditions(Conditions):
100 OSES = ['AND', 'CHR', 'IOS', 'LIN', 'MAC', 'WIN']
101 ARCH = ['arm', 'x86', 'x64']
102 Conditions.__init__(self, OSES, ARCH)
106 os, arch = self._active_condition.split('_')
107 osname = name[:3].upper()
109 if osname in self.SetA():
112 return Conditions.Bit(self, name)
115 class UntrustedConditions(Conditions):
117 LIBS = ['newlib', 'glibc', 'bionic']
118 ARCH = ['arm', 'x86', 'x64', 'pnacl']
119 Conditions.__init__(self, LIBS, ARCH)
121 "//native_client/build/toolchain/nacl/nacl_sdk.gni"
124 def get(self, key, default=False):
125 os, arch = self._active_condition.split('_')
126 if key == "TARGET_FULLARCH":
127 return FULLARCH[arch]
128 return Conditions.get(self, key, default)
131 libc, arch = self._active_condition.split('_')
133 if name == 'bitcode':
134 return arch == 'pnacl'
136 if name[:5] == 'nacl_':
137 return name[5:] == libc
139 return Conditions.Bit(self, name)
143 ALL = ['%s_%s' % (os, cpu) for os in OSES for cpu in CPUS]
148 for idx, cpu in enumerate(CPUS):
149 CPU_TO_BIT_MAP[cpu] = 1 << idx
150 BIT_TO_CPU_MAP[1 << idx] = cpu
152 def CPUsToBits(cpus):
155 out += CPU_TO_BIT_MAP[cpu]
159 def BitsToCPUs(cpus):
163 out.append(BIT_TO_CPU_MAP[i])