blob: 7e6501cde6692e14fc4284119209be05e563cffe [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 Silverman7a7c24d2018-09-01 17:49:09 -07006all_cpus = [
7 "amd64",
8 "roborio",
9 "armhf",
Austin Schuhde821712019-08-03 18:16:49 -070010 "cortex-m",
Brian Silverman7a7c24d2018-09-01 17:49:09 -070011]
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040012
Brian Silverman7a7c24d2018-09-01 17:49:09 -070013"""All of the CPUs we know about."""
14
15"""A select wrapper for CPU architectures.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040016
17Args:
18 values: A mapping from architecture names (as strings) to other things.
Austin Schuhde821712019-08-03 18:16:49 -070019 Currently amd64, roborio, armhf, and cortex are recognized.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040020 'else' is also allowed as a default.
Austin Schuhde821712019-08-03 18:16:49 -070021 'arm' is allowed instead of roborio, armhf, and cortex.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040022Returns a select which evaluates to the correct element of values.
Brian Silverman7a7c24d2018-09-01 17:49:09 -070023"""
24
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040025def cpu_select(values):
Brian Silverman0d57fc82016-01-24 21:02:53 -050026 if 'arm' in values:
27 new_values = {}
28 for cpu in values:
29 if cpu != 'arm':
30 new_values[cpu] = values[cpu]
31 new_values['armhf'] = values['arm']
32 new_values['roborio'] = values['arm']
Austin Schuhde821712019-08-03 18:16:49 -070033 new_values['cortex-m'] = values['arm']
Brian Silverman0d57fc82016-01-24 21:02:53 -050034 values = new_values
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040035 for cpu in all_cpus:
36 if cpu not in values:
37 if 'else' in values:
38 values[cpu] = values['else']
39 else:
40 fail('Need to handle %s CPUs!' % cpu, 'values')
41 for key in values:
42 if key not in all_cpus and key != 'else':
43 fail('Not sure what a %s CPU is!' % key, 'values')
44 return select({
Austin Schuhf6b94632019-02-02 22:11:27 -080045 '@//tools:cpu_k8': values['amd64'],
46 '@//tools:cpu_roborio': values['roborio'],
47 '@//tools:cpu_armhf': values['armhf'],
Austin Schuhde821712019-08-03 18:16:49 -070048 '@//tools:cpu_cortex_m4f': values['cortex-m'],
49 '@//tools:cpu_cortex_m4f_k22': values['cortex-m'],
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040050 })
51
Brian Silverman7a7c24d2018-09-01 17:49:09 -070052"""A select wrapper for address space sizes.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040053
54Args:
55 values: A mapping from address space sizes (as strings) to other things.
56Returns a select which evaluates to the correct element of values.
Brian Silverman7a7c24d2018-09-01 17:49:09 -070057"""
58
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040059def address_size_select(values):
60 if '32' not in values:
61 fail('Need to handle 32 bit addresses!', 'values')
62 if '64' not in values:
63 fail('Need to handle 64 bit addresses!', 'values')
64 return select({
Austin Schuhf6b94632019-02-02 22:11:27 -080065 '@//tools:cpu_k8': values['64'],
66 '@//tools:cpu_roborio': values['32'],
67 '@//tools:cpu_armhf': values['32'],
Austin Schuhde821712019-08-03 18:16:49 -070068 '@//tools:cpu_cortex_m4f': values['32'],
69 '@//tools:cpu_cortex_m4f_k22': values['32'],
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040070 })
71
Brian Silverman7a7c24d2018-09-01 17:49:09 -070072"""A select wrapper for compilers.
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040073
74Args:
75 values: A mapping from compiler names (as strings) to other things.
76 Currently 'gcc' and 'clang' are recognized.
77Returns a select which evaluates to the correct element of values.
Brian Silverman7a7c24d2018-09-01 17:49:09 -070078"""
79
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040080def compiler_select(values):
81 if 'gcc' not in values:
82 fail('Need to handle gcc!', 'values')
83 if 'clang' not in values:
84 fail('Need to handle clang!', 'values')
85 return select({
Brian Silvermand3ad1652018-02-18 22:16:29 -050086 '@//tools:compiler_gcc': values['gcc'],
87 '@//tools:compiler_clang': values['clang'],
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040088 })