Switch everything to platforms

This patch switches the codebase over from using the "cpu"
mechanism to using bazel platforms. See
https://docs.bazel.build/versions/master/platforms.html for some more
information.

Most of the substantial changes are in //tools. Instead of using
`cc_toolchain_suite` rules, we now use regular `toolchain` rules that
are registered in the WORKSPACE. That also means that bazel now uses
the target platform to select the compiler.

All --cpu=* arguments should now be --config=* arguments. For example,
`--cpu=roborio` should now be `--config=roborio`. The CI script and
all documentation has been updated to reflect that.

The remainder of the changes revolve around tagging all targets with
`target_compatible_with`.  The old mechanism allowed us to specify
repo-wide defaults. The new mechanism does not. That means every
target that didn't have any compatibility specified, now requires
compatibility with `@platforms//os:linux`.

I used buildozer for the vast majority of `target_compatible_with`
changes. buildozer automatically buildifies any BUILD files it
touches. That means this patch also contains a few non-functional
changes that I was too lazy to remove.

Change-Id: I66d6e6ad9161520ee397597cdb492585820a3acd
diff --git a/debian/BUILD b/debian/BUILD
index b893511..348163e 100644
--- a/debian/BUILD
+++ b/debian/BUILD
@@ -115,9 +115,10 @@
     srcs = [
         "download_packages.py",
     ],
-    python_version = "PY3",
     main = "download_packages.py",
+    python_version = "PY3",
     srcs_version = "PY2AND3",
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 download_packages(
@@ -134,6 +135,7 @@
         "python3-numpy",
         "python3-scipy",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 download_packages(
@@ -152,6 +154,7 @@
         "gcc",
         "gfortran",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 download_packages(
@@ -159,6 +162,7 @@
     packages = [
         "patch",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 download_packages(
@@ -166,6 +170,7 @@
     packages = [
         "pandoc",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 download_packages(
@@ -176,6 +181,7 @@
         "libusb-1.0-0-dev",
         "libusb-dev",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 download_packages(
@@ -183,6 +189,7 @@
     packages = [
         "g++-mingw-w64-x86-64",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 download_packages(
@@ -190,6 +197,7 @@
     packages = [
         "patchelf",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 download_packages(
@@ -212,6 +220,7 @@
         "python3-matplotlib",
         "python3-tk",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 # This list was obtained by manually looking at the output from:
@@ -229,6 +238,7 @@
         "libtinfo5",
         "zlib1g",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 download_packages(
@@ -251,6 +261,7 @@
         "python3-gi-cairo",
         "python3-shapely",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 download_packages(
@@ -258,66 +269,79 @@
     packages = [
         "m4",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "python",
     files = python_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "clang_6p0",
     files = clang_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "patch",
     files = patch_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "rsync",
     files = rsync_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "ssh_v3",
     files = ssh_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "pandoc",
     files = pandoc_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "libusb",
     files = libusb_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "mingw_compiler",
     files = mingw_compiler_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "patchelf",
     files = patchelf_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "matplotlib",
     files = matplotlib_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "arm_frc_gnueabi_deps",
     files = arm_frc_gnueabi_deps_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "python_gtk",
     files = python_gtk_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 # Starting point for opencv package list below.
@@ -363,6 +387,7 @@
         "libopencv-viz-dev",
         "libopencv-viz3.2",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 # This list was generated with download_packages.py on armhf and then
@@ -370,27 +395,32 @@
 generate_deb_tarball(
     name = "opencv_armhf_v3",
     files = opencv_armhf_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 # This was hand-written based on opencv_armhf.bzl.
 generate_deb_tarball(
     name = "opencv_amd64",
     files = opencv_amd64_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "gstreamer_amd64",
     files = gstreamer_amd64_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "gstreamer_armhf",
     files = gstreamer_armhf_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "m4",
     files = m4_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 download_packages(
@@ -398,16 +428,19 @@
     packages = [
         "liblzma-dev",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "lzma_amd64",
     files = lzma_amd64_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 generate_deb_tarball(
     name = "lzma_arm64",
     files = lzma_arm64_debs,
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 exports_files([
diff --git a/debian/libusb.BUILD b/debian/libusb.BUILD
index 7c41058..ea82ce4 100644
--- a/debian/libusb.BUILD
+++ b/debian/libusb.BUILD
@@ -23,6 +23,6 @@
     includes = [
         "usr/include",
     ],
-    restricted_to = ["@//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     visibility = ["//visibility:public"],
 )
diff --git a/debian/matplotlib.bzl b/debian/matplotlib.bzl
index 7032745..e647682 100644
--- a/debian/matplotlib.bzl
+++ b/debian/matplotlib.bzl
@@ -240,6 +240,6 @@
             ":usr/share/matplotlib/mpl-data/matplotlibrc",
         ] + native.glob(["etc/**"]),
         imports = ["usr/lib/python" + version + "/dist-packages", version, "."],
-        restricted_to = ["@//tools:k8"],
+        target_compatible_with = ["@platforms//cpu:x86_64"],
         visibility = ["//visibility:public"],
     )
diff --git a/debian/ni-libraries-2018.BUILD b/debian/ni-libraries-2018.BUILD
index ca17626..6f703ff 100644
--- a/debian/ni-libraries-2018.BUILD
+++ b/debian/ni-libraries-2018.BUILD
@@ -14,6 +14,6 @@
         "include",
     ],
     linkstatic = True,
-    restricted_to = ["@//tools:roborio"],
+    target_compatible_with = ["@//tools/platforms/hardware:roborio"],
     visibility = ["//visibility:public"],
 )
diff --git a/debian/ni-libraries.BUILD b/debian/ni-libraries.BUILD
index 9661248..78252a6 100644
--- a/debian/ni-libraries.BUILD
+++ b/debian/ni-libraries.BUILD
@@ -18,6 +18,6 @@
     ],
     linkopts = ["-ldl"],
     linkstatic = True,
-    restricted_to = ["@//tools:roborio"],
+    target_compatible_with = ["@//tools/platforms/hardware:roborio"],
     visibility = ["//visibility:public"],
 )
diff --git a/debian/packages.bzl b/debian/packages.bzl
index 987f77f..2914388 100644
--- a/debian/packages.bzl
+++ b/debian/packages.bzl
@@ -24,7 +24,7 @@
 
 # TODO(phil): Deal with armhf packages. Right now only works for amd64.
 
-def download_packages(name, packages, excludes = [], force_includes = []):
+def download_packages(name, packages, excludes = [], force_includes = [], target_compatible_with = None):
     """Downloads a set of packages as well as their dependencies.
 
     You can also specify excludes in case some of the dependencies are meta
@@ -52,6 +52,7 @@
         # would like it to.
         cmd = "$(location //debian:download_packages) %s %s %s | tee $@ >&2" %
               (force_includes, excludes_list, package_list),
+        target_compatible_with = target_compatible_with,
     )
 
 def _convert_deb_to_target(deb):
@@ -80,7 +81,7 @@
                 downloaded_file_path = f,
             )
 
-def generate_deb_tarball(name, files):
+def generate_deb_tarball(name, files, target_compatible_with = None):
     """Takes all debs in the dictionary and generates one tarball from them.
 
     This can then be uploaded and used as another WORKSPACE entry.
@@ -95,10 +96,12 @@
                 srcs = ["@%s//file" % dep],
                 outs = ["extracted_%s.tar" % dep],
                 cmd = "dpkg-deb --fsys-tarfile $(SRCS) > $@",
+                target_compatible_with = target_compatible_with,
             )
 
     pkg_tar(
         name = name,
         extension = "tar.gz",
         deps = ["extracted_%s.tar" % dep for dep in deps],
+        target_compatible_with = target_compatible_with,
     )
diff --git a/debian/python_gtk.BUILD b/debian/python_gtk.BUILD
index e1cdc99..48b924d 100644
--- a/debian/python_gtk.BUILD
+++ b/debian/python_gtk.BUILD
@@ -162,6 +162,6 @@
         "rpathed/usr/lib/x86_64-linux-gnu/libgeos_c.so",
     ],
     imports = ["usr/lib/python3/dist-packages"],
-    restricted_to = ["@//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     visibility = ["//visibility:public"],
 )
diff --git a/debian/slycot.BUILD b/debian/slycot.BUILD
index a384ebd..9ef3055 100644
--- a/debian/slycot.BUILD
+++ b/debian/slycot.BUILD
@@ -14,7 +14,7 @@
     srcs = ["slycot/src/_wrapper.pyf"],
     outs = ["slycot/src/_fortranwrapper.pyf"],
     cmd = "cat $(SRCS) | sed 's/_wrapper/_fortranwrapper/' > $(OUTS)",
-    restricted_to = ["@//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
 )
 
 # The contents of the file telling f2py how to translate various types. The
@@ -60,7 +60,7 @@
             "-i $(OUTS)",
         ]),
     ]),
-    restricted_to = ["@//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     tools = [
         "@python_repo//:f2py",
     ],
@@ -81,7 +81,7 @@
         "-Wno-unused-function",
         "-Wno-unused-but-set-variable",
     ],
-    restricted_to = ["@//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":slicot",
         "@python_repo//:python2.7_f2py",
@@ -97,7 +97,7 @@
     name = "slycot/_fortranwrapper.so",
     linkshared = True,
     linkstatic = True,
-    restricted_to = ["@//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":slicot",
         ":slycot_c",
@@ -128,7 +128,7 @@
         ":slycot/_fortranwrapper.so",
     ],
     imports = ["."],
-    restricted_to = ["@//tools:k8"],
+    target_compatible_with = ["@platforms//cpu:x86_64"],
     visibility = ["//visibility:public"],
 )