Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 1 | # 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 Silverman | 0d57fc8 | 2016-01-24 21:02:53 -0500 | [diff] [blame] | 6 | all_cpus = ['amd64', 'roborio', 'armhf'] |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 7 | '''All of the CPUs we know about.''' |
| 8 | |
| 9 | '''A select wrapper for CPU architectures. |
| 10 | |
| 11 | Args: |
| 12 | values: A mapping from architecture names (as strings) to other things. |
Brian Silverman | 0d57fc8 | 2016-01-24 21:02:53 -0500 | [diff] [blame] | 13 | Currently amd64, roborio, and armhf are recognized. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 14 | 'else' is also allowed as a default. |
Brian Silverman | 0d57fc8 | 2016-01-24 21:02:53 -0500 | [diff] [blame] | 15 | 'arm' is allowed instead of roborio and armhf. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 16 | Returns a select which evaluates to the correct element of values. |
| 17 | ''' |
| 18 | def cpu_select(values): |
Brian Silverman | 0d57fc8 | 2016-01-24 21:02:53 -0500 | [diff] [blame] | 19 | 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 Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 27 | 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 Silverman | 0d57fc8 | 2016-01-24 21:02:53 -0500 | [diff] [blame] | 39 | '//tools:cpu_armhf': values['armhf'], |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 40 | }) |
| 41 | |
| 42 | '''A select wrapper for address space sizes. |
| 43 | |
| 44 | Args: |
| 45 | values: A mapping from address space sizes (as strings) to other things. |
| 46 | Returns a select which evaluates to the correct element of values. |
| 47 | ''' |
| 48 | def 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 | |
| 60 | Args: |
| 61 | values: A mapping from compiler names (as strings) to other things. |
| 62 | Currently 'gcc' and 'clang' are recognized. |
| 63 | Returns a select which evaluates to the correct element of values. |
| 64 | ''' |
| 65 | def 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({ |
Brian Silverman | d3ad165 | 2018-02-18 22:16:29 -0500 | [diff] [blame] | 71 | '@//tools:compiler_gcc': values['gcc'], |
| 72 | '@//tools:compiler_clang': values['clang'], |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 73 | }) |