Buildified the world again.

bzl files were pretty off.

Change-Id: Ief87d7c0a08c6706c8c6c573afef95a6d51968e7
diff --git a/tools/build_rules/empty_main.bzl b/tools/build_rules/empty_main.bzl
index dbe9120..3305e1a 100644
--- a/tools/build_rules/empty_main.bzl
+++ b/tools/build_rules/empty_main.bzl
@@ -1,6 +1,7 @@
-'''Returns a select which is either srcs or an empty main function.'''
+"""Returns a select which is either srcs or an empty main function."""
+
 def empty_main_if_asan(srcs):
-  return select({
-    '//tools:has_asan': [ '//tools/cpp:empty_main' ],
-    '//conditions:default': srcs,
-  })
+    return select({
+        "//tools:has_asan": ["//tools/cpp:empty_main"],
+        "//conditions:default": srcs,
+    })
diff --git a/tools/build_rules/fortran.bzl b/tools/build_rules/fortran.bzl
index cbd4447..22882ac 100644
--- a/tools/build_rules/fortran.bzl
+++ b/tools/build_rules/fortran.bzl
@@ -1,51 +1,60 @@
 load("@//tools/build_rules:select.bzl", "compiler_select")
 
 def _single_fortran_object_impl(ctx):
-  toolchain_cflags = (ctx.fragments.cpp.compiler_options([]) +
-      ctx.fragments.cpp.c_options +
-      ctx.fragments.cpp.unfiltered_compiler_options([]) +
-      ['-fPIC', '-Wno-maybe-uninitialized', '-Wno-unused-dummy-argument',
-       '-Wno-conversion', '-Wno-unused-variable', '-Wno-character-truncation'])
+    toolchain_cflags = (ctx.fragments.cpp.compiler_options([]) +
+                        ctx.fragments.cpp.c_options +
+                        ctx.fragments.cpp.unfiltered_compiler_options([]) +
+                        [
+                            "-fPIC",
+                            "-Wno-maybe-uninitialized",
+                            "-Wno-unused-dummy-argument",
+                            "-Wno-conversion",
+                            "-Wno-unused-variable",
+                            "-Wno-character-truncation",
+                        ])
 
-  cmd = toolchain_cflags + ['-c', ctx.file.src.path, '-o', ctx.outputs.pic_o.path]
-  filtered_cmd = []
-  # Strip out the C/C++/Clang specific flags.
-  exclude_flags = ['-fcolor-diagnostics',
-                   '-Wswitch-enum',
-                   '-Wpointer-arith',
-                   '-Wcast-qual',
-                   '-Wwrite-strings',
-                   '-Wsign-compare',
-                   '-Wformat=2',
-                   '-Werror',
-                   '-Wextra',
-                   '-Wno-builtin-macro-redefined',
-                   '-Wunused-local-typedefs',
-                   '-D__has_feature(x)=0',
-                   '-fmacro-backtrace-limit=0']
+    cmd = toolchain_cflags + ["-c", ctx.file.src.path, "-o", ctx.outputs.pic_o.path]
+    filtered_cmd = []
 
-  for flag in cmd:
-    if flag not in exclude_flags and not (flag.startswith('-fsanitize') or
-                                          flag.startswith('-fno-sanitize')):
-      filtered_cmd.append(flag)
+    # Strip out the C/C++/Clang specific flags.
+    exclude_flags = [
+        "-fcolor-diagnostics",
+        "-Wswitch-enum",
+        "-Wpointer-arith",
+        "-Wcast-qual",
+        "-Wwrite-strings",
+        "-Wsign-compare",
+        "-Wformat=2",
+        "-Werror",
+        "-Wextra",
+        "-Wno-builtin-macro-redefined",
+        "-Wunused-local-typedefs",
+        "-D__has_feature(x)=0",
+        "-fmacro-backtrace-limit=0",
+    ]
 
-  ctx.action(
-    inputs = [ctx.file.src] + ctx.files._cc_toolchain,
-    outputs = [ctx.outputs.pic_o],
-    mnemonic = "Fortran",
-    executable = ctx.fragments.cpp.compiler_executable,
-    arguments = filtered_cmd,
-    progress_message = 'Building %s' % ctx.outputs.pic_o.short_path,
-  )
+    for flag in cmd:
+        if flag not in exclude_flags and not (flag.startswith("-fsanitize") or
+                                              flag.startswith("-fno-sanitize")):
+            filtered_cmd.append(flag)
+
+    ctx.action(
+        inputs = [ctx.file.src] + ctx.files._cc_toolchain,
+        outputs = [ctx.outputs.pic_o],
+        mnemonic = "Fortran",
+        executable = ctx.fragments.cpp.compiler_executable,
+        arguments = filtered_cmd,
+        progress_message = "Building %s" % ctx.outputs.pic_o.short_path,
+    )
 
 def _define_fortran_output(src):
-  if not src.name.endswith('.f'):
-    fail('Fortran files must end in \'.f\'', 'src')
+    if not src.name.endswith(".f"):
+        fail("Fortran files must end in '.f'", "src")
 
-  fortran_file_base = src.name[:-2]
-  return {
-    'pic_o': fortran_file_base + '.pic.o',
-  }
+    fortran_file_base = src.name[:-2]
+    return {
+        "pic_o": fortran_file_base + ".pic.o",
+    }
 
 _single_fortran_object = rule(
     attrs = {
@@ -68,33 +77,33 @@
 )
 
 def fortran_library(name, srcs, deps = [], visibility = None):
-  """Builds a shared library from a set of fortran files.
+    """Builds a shared library from a set of fortran files.
 
-  Args:
-    srcs: list of fortran files ending in .f
-    deps: cc_library or fortran_library dependencies.
-  """
-  pic_o_files = []
-  for src in srcs:
-    pic_o_file = src[:-2] + '.pic.o'
-    _single_fortran_object(
-      name = name + '_' + pic_o_file,
-      src = src,
-      visibility = ['//visibility:private'],
-      restricted_to = ['@//tools:k8'],
+    Args:
+      srcs: list of fortran files ending in .f
+      deps: cc_library or fortran_library dependencies.
+    """
+    pic_o_files = []
+    for src in srcs:
+        pic_o_file = src[:-2] + ".pic.o"
+        _single_fortran_object(
+            name = name + "_" + pic_o_file,
+            src = src,
+            visibility = ["//visibility:private"],
+            restricted_to = ["@//tools:k8"],
+        )
+        pic_o_files.append(pic_o_file)
+
+    native.cc_library(
+        name = name,
+        deps = deps,
+        srcs = pic_o_files,
+        linkopts = [
+            "-lgfortran",
+        ],
+        visibility = visibility,
+        restricted_to = ["@//tools:k8"],
     )
-    pic_o_files.append(pic_o_file)
-
-  native.cc_library(
-    name = name,
-    deps = deps,
-    srcs = pic_o_files,
-    linkopts = [
-      '-lgfortran',
-    ],
-    visibility = visibility,
-    restricted_to = ['@//tools:k8'],
-  )
 
 f2c_copts = compiler_select({
     "clang": [
@@ -121,40 +130,40 @@
 This is useful when building externally-f2ced files."""
 
 def f2c_library(name, srcs, copts = [], **kwargs):
-  '''Converts Fortran code to C and then compiles it.
+    """Converts Fortran code to C and then compiles it.
 
-  Attrs:
-    srcs: .f source files
-    **kwargs: passed to native.cc_library
-  '''
-  c_srcs = [f[:-2] + '.c' for f in srcs]
+    Attrs:
+      srcs: .f source files
+      **kwargs: passed to native.cc_library
+    """
+    c_srcs = [f[:-2] + ".c" for f in srcs]
 
-  out_dir = c_srcs[0].split('/')[:-1]
-  for c_src in c_srcs:
-    if c_src.split('/')[:-1] != out_dir:
-      # Need to figure out how to make multiple f2c calls or something to
-      # support this, and we haven't had a use case yet.
-      fail('Multiple output directories not supported', 'srcs')
+    out_dir = c_srcs[0].split("/")[:-1]
+    for c_src in c_srcs:
+        if c_src.split("/")[:-1] != out_dir:
+            # Need to figure out how to make multiple f2c calls or something to
+            # support this, and we haven't had a use case yet.
+            fail("Multiple output directories not supported", "srcs")
 
-  native.genrule(
-    name = '_%s_f2c' % name,
-    visibility = ['//visibility:private'],
-    srcs = srcs,
-    outs = c_srcs,
-    tools = [
-      '@f2c',
-      '@//tools/build_rules:quiet_success',
-    ],
-    cmd = ' '.join([
-      '$(location @//tools/build_rules:quiet_success)',
-      '$(location @f2c)',
-      '-d$(@D)/%s' % ('/'.join(out_dir),),
-      '$(SRCS)',
-    ]),
-  )
-  native.cc_library(
-    name = name,
-    srcs = c_srcs,
-    copts = f2c_copts + copts,
-    **kwargs
-  )
+    native.genrule(
+        name = "_%s_f2c" % name,
+        visibility = ["//visibility:private"],
+        srcs = srcs,
+        outs = c_srcs,
+        tools = [
+            "@f2c",
+            "@//tools/build_rules:quiet_success",
+        ],
+        cmd = " ".join([
+            "$(location @//tools/build_rules:quiet_success)",
+            "$(location @f2c)",
+            "-d$(@D)/%s" % ("/".join(out_dir),),
+            "$(SRCS)",
+        ]),
+    )
+    native.cc_library(
+        name = name,
+        srcs = c_srcs,
+        copts = f2c_copts + copts,
+        **kwargs
+    )
diff --git a/tools/build_rules/gtk_dependent.bzl b/tools/build_rules/gtk_dependent.bzl
index 0a21a9a..819ef83 100644
--- a/tools/build_rules/gtk_dependent.bzl
+++ b/tools/build_rules/gtk_dependent.bzl
@@ -1,9 +1,9 @@
 disable_gtk_binaries = True
 
 def gtk_dependent_cc_library(**kwargs):
-  if not disable_gtk_binaries:
-    native.cc_library(**kwargs)
+    if not disable_gtk_binaries:
+        native.cc_library(**kwargs)
 
 def gtk_dependent_cc_binary(**kwargs):
-  if not disable_gtk_binaries:
-    native.cc_binary(**kwargs)
+    if not disable_gtk_binaries:
+        native.cc_binary(**kwargs)
diff --git a/tools/build_rules/label.bzl b/tools/build_rules/label.bzl
index ff02327..1382e1a 100644
--- a/tools/build_rules/label.bzl
+++ b/tools/build_rules/label.bzl
@@ -2,4 +2,4 @@
 # Starlark provides them itself
 
 def expand_label(label):
-  return '%s' % label if ':' in label else '%s:%s' % (label, label.split('/')[-1])
+    return "%s" % label if ":" in label else "%s:%s" % (label, label.split("/")[-1])
diff --git a/tools/build_rules/select.bzl b/tools/build_rules/select.bzl
index 45ba612..3483360 100644
--- a/tools/build_rules/select.bzl
+++ b/tools/build_rules/select.bzl
@@ -28,32 +28,32 @@
 """
 
 def cpu_select(values):
-  if 'arm' in values:
-    new_values = {}
-    for cpu in values:
-      if cpu != 'arm':
-        new_values[cpu] = values[cpu]
-    new_values['armhf'] = values['arm']
-    new_values['roborio'] = values['arm']
-    new_values['cortex-m'] = values['arm']
-    values = new_values
-  for cpu in all_cpus:
-    if cpu not in values:
-      if 'else' in values:
-        values[cpu] = values['else']
-      else:
-        fail('Need to handle %s CPUs!' % cpu, 'values')
-  for key in values:
-    if key not in all_cpus and key != 'else':
-      fail('Not sure what a %s CPU is!' % key, 'values')
-  return select({
-    '@//tools:cpu_k8': values['amd64'],
-    '@//tools:cpu_roborio': values['roborio'],
-    '@//tools:cpu_armhf': values['armhf'],
-    '@//tools:cpu_cortex_m4f': values['cortex-m'],
-    '@//tools:cpu_cortex_m4f_k22': values['cortex-m'],
-    '@//tools:cpu_web': None,
-  })
+    if "arm" in values:
+        new_values = {}
+        for cpu in values:
+            if cpu != "arm":
+                new_values[cpu] = values[cpu]
+        new_values["armhf"] = values["arm"]
+        new_values["roborio"] = values["arm"]
+        new_values["cortex-m"] = values["arm"]
+        values = new_values
+    for cpu in all_cpus:
+        if cpu not in values:
+            if "else" in values:
+                values[cpu] = values["else"]
+            else:
+                fail("Need to handle %s CPUs!" % cpu, "values")
+    for key in values:
+        if key not in all_cpus and key != "else":
+            fail("Not sure what a %s CPU is!" % key, "values")
+    return select({
+        "@//tools:cpu_k8": values["amd64"],
+        "@//tools:cpu_roborio": values["roborio"],
+        "@//tools:cpu_armhf": values["armhf"],
+        "@//tools:cpu_cortex_m4f": values["cortex-m"],
+        "@//tools:cpu_cortex_m4f_k22": values["cortex-m"],
+        "@//tools:cpu_web": None,
+    })
 
 """A select wrapper for address space sizes.
 
@@ -63,18 +63,18 @@
 """
 
 def address_size_select(values):
-  if '32' not in values:
-    fail('Need to handle 32 bit addresses!', 'values')
-  if '64' not in values:
-    fail('Need to handle 64 bit addresses!', 'values')
-  return select({
-    '@//tools:cpu_k8': values['64'],
-    '@//tools:cpu_roborio': values['32'],
-    '@//tools:cpu_armhf': values['32'],
-    '@//tools:cpu_cortex_m4f': values['32'],
-    '@//tools:cpu_cortex_m4f_k22': values['32'],
-    '@//tools:cpu_web': None,
-  })
+    if "32" not in values:
+        fail("Need to handle 32 bit addresses!", "values")
+    if "64" not in values:
+        fail("Need to handle 64 bit addresses!", "values")
+    return select({
+        "@//tools:cpu_k8": values["64"],
+        "@//tools:cpu_roborio": values["32"],
+        "@//tools:cpu_armhf": values["32"],
+        "@//tools:cpu_cortex_m4f": values["32"],
+        "@//tools:cpu_cortex_m4f_k22": values["32"],
+        "@//tools:cpu_web": None,
+    })
 
 """A select wrapper for compilers.
 
@@ -85,12 +85,12 @@
 """
 
 def compiler_select(values):
-  if 'gcc' not in values:
-    fail('Need to handle gcc!', 'values')
-  if 'clang' not in values:
-    fail('Need to handle clang!', 'values')
-  return select({
-    '@//tools:compiler_gcc': values['gcc'],
-    '@//tools:compiler_clang': values['clang'],
-    '@//tools:compiler_emscripten': None,
-  })
+    if "gcc" not in values:
+        fail("Need to handle gcc!", "values")
+    if "clang" not in values:
+        fail("Need to handle clang!", "values")
+    return select({
+        "@//tools:compiler_gcc": values["gcc"],
+        "@//tools:compiler_clang": values["clang"],
+        "@//tools:compiler_emscripten": None,
+    })
diff --git a/tools/cpp/emscripten/defs.bzl b/tools/cpp/emscripten/defs.bzl
index e7a1c3a..e63d67e 100644
--- a/tools/cpp/emscripten/defs.bzl
+++ b/tools/cpp/emscripten/defs.bzl
@@ -9,43 +9,42 @@
     ]
     if html_shell:
         ctx.actions.expand_template(
-            output=html_out,
-            template=html_shell,
-            substitutions={
-                "{{{ SCRIPT }}}":
-                "<script async type=\"text/javascript\" src=\"" + basename +
-                ".js\"></script>",
-            })
+            output = html_out,
+            template = html_shell,
+            substitutions = {
+                "{{{ SCRIPT }}}": "<script async type=\"text/javascript\" src=\"" + basename +
+                                  ".js\"></script>",
+            },
+        )
     else:
         tar_outs.append(html_out)
 
     ctx.actions.run_shell(
-        outputs=tar_outs,
-        inputs=[tarfile],
-        command="tar xf " + tarfile.path + " -C \"" + html_out.dirname + "\"")
+        outputs = tar_outs,
+        inputs = [tarfile],
+        command = "tar xf " + tarfile.path + " -C \"" + html_out.dirname + "\"",
+    )
 
-    return [DefaultInfo(files=depset(tar_outs + [html_out]))]
-
+    return [DefaultInfo(files = depset(tar_outs + [html_out]))]
 
 emcc_expand_files = rule(
-    attrs={
+    attrs = {
         "html_shell": attr.label(
-            mandatory=False,
-            allow_single_file=True,
+            mandatory = False,
+            allow_single_file = True,
         ),
         "tarfile": attr.label(
-            mandatory=True,
-            allow_single_file=True,
+            mandatory = True,
+            allow_single_file = True,
         ),
     },
-    doc="""
+    doc = """
     Handles the intermediate processing to extra files from a tarball
     for emcc_binary. See emcc_binary for more detail.""",
-    implementation=_emcc_expand_files_impl,
+    implementation = _emcc_expand_files_impl,
 )
 
-
-def emcc_binary(name, srcs=[], linkopts=[], html_shell=None, **kwargs):
+def emcc_binary(name, srcs = [], linkopts = [], html_shell = None, **kwargs):
     """Produces a deployable set of WebAssembly files.
 
     Depending on the settings, the exact format of the output varies.
@@ -92,14 +91,15 @@
     if html_shell:
         tarfile = basename + ".js.tar"
     native.cc_binary(
-        name=tarfile,
-        srcs=srcs,
-        linkopts=linkopts,
-        restricted_to=["//tools:web"],
-        **kwargs)
+        name = tarfile,
+        srcs = srcs,
+        linkopts = linkopts,
+        restricted_to = ["//tools:web"],
+        **kwargs
+    )
     emcc_expand_files(
-        name=basename,
-        html_shell=html_shell,
-        tarfile=tarfile,
-        restricted_to=["//tools:web"],
+        name = basename,
+        html_shell = html_shell,
+        tarfile = tarfile,
+        restricted_to = ["//tools:web"],
     )