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 | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 6 | all_cpus = [ |
| 7 | "amd64", |
| 8 | "roborio", |
| 9 | "armhf", |
Austin Schuh | de82171 | 2019-08-03 18:16:49 -0700 | [diff] [blame] | 10 | "cortex-m", |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 11 | ] |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 12 | |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 13 | """All of the CPUs we know about.""" |
| 14 | |
| 15 | """A select wrapper for CPU architectures. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 16 | |
| 17 | Args: |
| 18 | values: A mapping from architecture names (as strings) to other things. |
Austin Schuh | de82171 | 2019-08-03 18:16:49 -0700 | [diff] [blame] | 19 | Currently amd64, roborio, armhf, and cortex are recognized. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 20 | 'else' is also allowed as a default. |
Austin Schuh | de82171 | 2019-08-03 18:16:49 -0700 | [diff] [blame] | 21 | 'arm' is allowed instead of roborio, armhf, and cortex. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 22 | Returns a select which evaluates to the correct element of values. |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 23 | """ |
| 24 | |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 25 | def cpu_select(values): |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 26 | 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"] |
| 33 | new_values["cortex-m"] = values["arm"] |
| 34 | values = new_values |
| 35 | 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({ |
| 45 | "@//tools:cpu_k8": values["amd64"], |
| 46 | "@//tools:cpu_roborio": values["roborio"], |
| 47 | "@//tools:cpu_armhf": values["armhf"], |
| 48 | "@//tools:cpu_cortex_m4f": values["cortex-m"], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame^] | 49 | # TODO(phil): Support this properly. |
| 50 | #"@//tools:cpu_cortex_m4f_k22": values["cortex-m"], |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 51 | }) |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 52 | |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 53 | """A select wrapper for address space sizes. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 54 | |
| 55 | Args: |
| 56 | values: A mapping from address space sizes (as strings) to other things. |
| 57 | Returns a select which evaluates to the correct element of values. |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 58 | """ |
| 59 | |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 60 | def address_size_select(values): |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 61 | if "32" not in values: |
| 62 | fail("Need to handle 32 bit addresses!", "values") |
| 63 | if "64" not in values: |
| 64 | fail("Need to handle 64 bit addresses!", "values") |
| 65 | return select({ |
| 66 | "@//tools:cpu_k8": values["64"], |
| 67 | "@//tools:cpu_roborio": values["32"], |
| 68 | "@//tools:cpu_armhf": values["32"], |
| 69 | "@//tools:cpu_cortex_m4f": values["32"], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame^] | 70 | # TODO(phil): Support this properly. |
| 71 | #"@//tools:cpu_cortex_m4f_k22": values["32"], |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 72 | }) |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 73 | |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 74 | """A select wrapper for compilers. |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 75 | |
| 76 | Args: |
| 77 | values: A mapping from compiler names (as strings) to other things. |
| 78 | Currently 'gcc' and 'clang' are recognized. |
| 79 | Returns a select which evaluates to the correct element of values. |
Brian Silverman | 7a7c24d | 2018-09-01 17:49:09 -0700 | [diff] [blame] | 80 | """ |
| 81 | |
Brian Silverman | a7ba3aa | 2015-10-12 00:33:03 -0400 | [diff] [blame] | 82 | def compiler_select(values): |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 83 | if "gcc" not in values: |
| 84 | fail("Need to handle gcc!", "values") |
| 85 | if "clang" not in values: |
| 86 | fail("Need to handle clang!", "values") |
| 87 | return select({ |
| 88 | "@//tools:compiler_gcc": values["gcc"], |
| 89 | "@//tools:compiler_clang": values["clang"], |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 90 | }) |