blob: 151283f839a1faa57547c4457ff87b1aa8bd4d1a [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
Brian Silverman0d57fc82016-01-24 21:02:53 -05006all_cpus = ['amd64', 'roborio', 'armhf']
Brian Silvermana7ba3aa2015-10-12 00:33:03 -04007'''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.
Brian Silverman0d57fc82016-01-24 21:02:53 -050013 Currently amd64, roborio, and armhf are recognized.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040014 'else' is also allowed as a default.
Brian Silverman0d57fc82016-01-24 21:02:53 -050015 'arm' is allowed instead of roborio and armhf.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040016Returns a select which evaluates to the correct element of values.
17'''
18def cpu_select(values):
Brian Silverman0d57fc82016-01-24 21:02:53 -050019 if 'arm' in values:
20 new_values = {}
21 for cpu in values:
22 if cpu != 'arm':
23 new_values[cpu] = values[cpu]
24 new_values['armhf'] = values['arm']
25 new_values['roborio'] = values['arm']
26 values = new_values
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040027 for cpu in all_cpus:
28 if cpu not in values:
29 if 'else' in values:
30 values[cpu] = values['else']
31 else:
32 fail('Need to handle %s CPUs!' % cpu, 'values')
33 for key in values:
34 if key not in all_cpus and key != 'else':
35 fail('Not sure what a %s CPU is!' % key, 'values')
36 return select({
37 '//tools:cpu_k8': values['amd64'],
38 '//tools:cpu_roborio': values['roborio'],
Brian Silverman0d57fc82016-01-24 21:02:53 -050039 '//tools:cpu_armhf': values['armhf'],
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040040 })
41
42'''A select wrapper for address space sizes.
43
44Args:
45 values: A mapping from address space sizes (as strings) to other things.
46Returns a select which evaluates to the correct element of values.
47'''
48def address_size_select(values):
49 if '32' not in values:
50 fail('Need to handle 32 bit addresses!', 'values')
51 if '64' not in values:
52 fail('Need to handle 64 bit addresses!', 'values')
53 return select({
54 '//tools:cpu_k8': values['64'],
55 '//tools:cpu_roborio': values['32'],
56 })
57
58'''A select wrapper for compilers.
59
60Args:
61 values: A mapping from compiler names (as strings) to other things.
62 Currently 'gcc' and 'clang' are recognized.
63Returns a select which evaluates to the correct element of values.
64'''
65def compiler_select(values):
66 if 'gcc' not in values:
67 fail('Need to handle gcc!', 'values')
68 if 'clang' not in values:
69 fail('Need to handle clang!', 'values')
70 return select({
71 '//tools:compiler_gcc': values['gcc'],
72 '//tools:compiler_clang': values['clang'],
73 })