blob: 1c48eb74e7cc4627b31a7eed0672c40590ead377 [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):
Austin Schuh8e17be92019-12-24 09:32:11 -080026 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"],
49 "@//tools:cpu_cortex_m4f_k22": values["cortex-m"],
Austin Schuh8e17be92019-12-24 09:32:11 -080050 })
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040051
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):
Austin Schuh8e17be92019-12-24 09:32:11 -080060 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({
65 "@//tools:cpu_k8": values["64"],
66 "@//tools:cpu_roborio": values["32"],
67 "@//tools:cpu_armhf": values["32"],
68 "@//tools:cpu_cortex_m4f": values["32"],
69 "@//tools:cpu_cortex_m4f_k22": values["32"],
Austin Schuh8e17be92019-12-24 09:32:11 -080070 })
Brian Silvermana7ba3aa2015-10-12 00:33:03 -040071
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):
Austin Schuh8e17be92019-12-24 09:32:11 -080081 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({
86 "@//tools:compiler_gcc": values["gcc"],
87 "@//tools:compiler_clang": values["clang"],
Austin Schuh8e17be92019-12-24 09:32:11 -080088 })