blob: 18701ef3d03fb8b4d06b40441387f18d8b5628b4 [file] [log] [blame]
Brian Silvermana7ba3aa2015-10-12 00:33:03 -04001# This file contains replacements for select where the keys have more abstract
2# meanings so we can map multiple conditions to the same value easily and
3# quickly find issues where something new isn't handled.
4# It will also make adding ORs when it makes sense easy to do nicely.
5
6all_cpus = ['amd64', 'roborio']
7'''All of the CPUs we know about.'''
8
9'''A select wrapper for CPU architectures.
10
11Args:
12 values: A mapping from architecture names (as strings) to other things.
13 Currently amd64 and roborio are recognized.
14 'else' is also allowed as a default.
15Returns a select which evaluates to the correct element of values.
16'''
17def cpu_select(values):
18 for cpu in all_cpus:
19 if cpu not in values:
20 if 'else' in values:
21 values[cpu] = values['else']
22 else:
23 fail('Need to handle %s CPUs!' % cpu, 'values')
24 for key in values:
25 if key not in all_cpus and key != 'else':
26 fail('Not sure what a %s CPU is!' % key, 'values')
27 return select({
28 '//tools:cpu_k8': values['amd64'],
29 '//tools:cpu_roborio': values['roborio'],
30 })
31
32'''A select wrapper for address space sizes.
33
34Args:
35 values: A mapping from address space sizes (as strings) to other things.
36Returns a select which evaluates to the correct element of values.
37'''
38def address_size_select(values):
39 if '32' not in values:
40 fail('Need to handle 32 bit addresses!', 'values')
41 if '64' not in values:
42 fail('Need to handle 64 bit addresses!', 'values')
43 return select({
44 '//tools:cpu_k8': values['64'],
45 '//tools:cpu_roborio': values['32'],
46 })
47
48'''A select wrapper for compilers.
49
50Args:
51 values: A mapping from compiler names (as strings) to other things.
52 Currently 'gcc' and 'clang' are recognized.
53Returns a select which evaluates to the correct element of values.
54'''
55def compiler_select(values):
56 if 'gcc' not in values:
57 fail('Need to handle gcc!', 'values')
58 if 'clang' not in values:
59 fail('Need to handle clang!', 'values')
60 return select({
61 '//tools:compiler_gcc': values['gcc'],
62 '//tools:compiler_clang': values['clang'],
63 })