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 | |
| 6 | all_cpus = ['amd64', 'roborio'] |
| 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. |
| 13 | Currently amd64 and roborio are recognized. |
| 14 | 'else' is also allowed as a default. |
| 15 | Returns a select which evaluates to the correct element of values. |
| 16 | ''' |
| 17 | def 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 | |
| 34 | Args: |
| 35 | values: A mapping from address space sizes (as strings) to other things. |
| 36 | Returns a select which evaluates to the correct element of values. |
| 37 | ''' |
| 38 | def 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 | |
| 50 | Args: |
| 51 | values: A mapping from compiler names (as strings) to other things. |
| 52 | Currently 'gcc' and 'clang' are recognized. |
| 53 | Returns a select which evaluates to the correct element of values. |
| 54 | ''' |
| 55 | def 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 | }) |