aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorGravatar vladmos <vladmos@google.com>2018-06-01 04:51:21 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-01 04:52:44 -0700
commit20a042faa91acf8db78684de9f38c4e628d61dd6 (patch)
treec2fc5c6d30cb51cb3f6e30ed0fb2d25f5525585f /scripts
parent2269ee2af91b7df13820381d61e8e4e26a257b3a (diff)
Format all bzl files with buildifier
This CL aslo enables a presubmit check for correct formatting of all bzl files in //third_party/bazel. PiperOrigin-RevId: 198857055
Diffstat (limited to 'scripts')
-rw-r--r--scripts/docs/jekyll.bzl121
-rw-r--r--scripts/packages/self_extract_binary.bzl81
2 files changed, 106 insertions, 96 deletions
diff --git a/scripts/docs/jekyll.bzl b/scripts/docs/jekyll.bzl
index 3552f4a23b..0ca0c3eee9 100644
--- a/scripts/docs/jekyll.bzl
+++ b/scripts/docs/jekyll.bzl
@@ -14,70 +14,77 @@
"""Quick rule to build a Jekyll site."""
def _bucket_from_workspace_name(wname):
- """Try to assert the bucket name from the workspace name.
+ """Try to assert the bucket name from the workspace name.
- E.g. it will answer www.bazel.build if the workspace name is build_bazel_www.
+ E.g. it will answer www.bazel.build if the workspace name is build_bazel_www.
- Args:
- wname: workspace name
+ Args:
+ wname: workspace name
- Returns:
- the guessed name of the bucket for this workspace.
- """
- revlist = []
- for part in wname.split("_"):
- revlist.insert(0, part)
- return ".".join(revlist)
+ Returns:
+ the guessed name of the bucket for this workspace.
+ """
+ revlist = []
+ for part in wname.split("_"):
+ revlist.insert(0, part)
+ return ".".join(revlist)
def _impl(ctx):
- """Quick and non-hermetic rule to build a Jekyll site."""
- source = ctx.actions.declare_directory(ctx.attr.name + "-srcs")
- output = ctx.actions.declare_directory(ctx.attr.name + "-build")
+ """Quick and non-hermetic rule to build a Jekyll site."""
+ source = ctx.actions.declare_directory(ctx.attr.name + "-srcs")
+ output = ctx.actions.declare_directory(ctx.attr.name + "-build")
- ctx.actions.run_shell(inputs = ctx.files.srcs,
- outputs = [source],
- command = ("mkdir -p %s\n" % (source.path)) +
- "\n".join([
- "tar xf %s -C %s" % (src.path, source.path) for src in ctx.files.srcs])
- )
- ctx.actions.run(
- inputs = [source],
- outputs = [output],
- executable = "jekyll",
- use_default_shell_env = True,
- arguments = ["build", "-q", "-s", source.path, "-d", output.path]
- )
- ctx.actions.run(
- inputs = [output],
- outputs = [ctx.outputs.out],
- executable = "tar",
- arguments = ["cf", ctx.outputs.out.path, "-C", output.path, "."]
- )
+ ctx.actions.run_shell(
+ inputs = ctx.files.srcs,
+ outputs = [source],
+ command = ("mkdir -p %s\n" % (source.path)) +
+ "\n".join([
+ "tar xf %s -C %s" % (src.path, source.path)
+ for src in ctx.files.srcs
+ ]),
+ )
+ ctx.actions.run(
+ inputs = [source],
+ outputs = [output],
+ executable = "jekyll",
+ use_default_shell_env = True,
+ arguments = ["build", "-q", "-s", source.path, "-d", output.path],
+ )
+ ctx.actions.run(
+ inputs = [output],
+ outputs = [ctx.outputs.out],
+ executable = "tar",
+ arguments = ["cf", ctx.outputs.out.path, "-C", output.path, "."],
+ )
- # Create a shell script to serve the site locally or push with the --push
- # flag.
- bucket = ctx.attr.bucket if ctx.attr.bucket else _bucket_from_workspace_name(ctx.workspace_name)
+ # Create a shell script to serve the site locally or push with the --push
+ # flag.
+ bucket = ctx.attr.bucket if ctx.attr.bucket else _bucket_from_workspace_name(ctx.workspace_name)
- ctx.actions.expand_template(
- template=ctx.file._jekyll_build_tpl,
- output=ctx.outputs.executable,
- substitutions={
- "%{workspace_name}": ctx.workspace_name,
- "%{source_dir}": source.short_path,
- "%{prod_dir}": output.short_path,
- "%{bucket}": bucket,
- },
- is_executable=True)
- return [DefaultInfo(runfiles=ctx.runfiles(files=[source, output]))]
+ ctx.actions.expand_template(
+ template = ctx.file._jekyll_build_tpl,
+ output = ctx.outputs.executable,
+ substitutions = {
+ "%{workspace_name}": ctx.workspace_name,
+ "%{source_dir}": source.short_path,
+ "%{prod_dir}": output.short_path,
+ "%{bucket}": bucket,
+ },
+ is_executable = True,
+ )
+ return [DefaultInfo(runfiles = ctx.runfiles(files = [source, output]))]
jekyll_build = rule(
- implementation = _impl,
- executable = True,
- attrs = {
- "srcs": attr.label_list(allow_empty=False),
- "bucket": attr.string(),
- "_jekyll_build_tpl": attr.label(
- default=":jekyll_build.sh.tpl",
- allow_files=True,
- single_file=True)},
- outputs = {"out": "%{name}.tar"})
+ implementation = _impl,
+ executable = True,
+ attrs = {
+ "srcs": attr.label_list(allow_empty = False),
+ "bucket": attr.string(),
+ "_jekyll_build_tpl": attr.label(
+ default = ":jekyll_build.sh.tpl",
+ allow_files = True,
+ single_file = True,
+ ),
+ },
+ outputs = {"out": "%{name}.tar"},
+)
diff --git a/scripts/packages/self_extract_binary.bzl b/scripts/packages/self_extract_binary.bzl
index 75f19279c3..24e3ddf2b5 100644
--- a/scripts/packages/self_extract_binary.bzl
+++ b/scripts/packages/self_extract_binary.bzl
@@ -33,45 +33,48 @@ and a ZIP footer with the following entries:
"""
def _self_extract_binary(ctx):
- """Implementation for the self_extract_binary rule."""
- # This is a bit complex for stripping out timestamps
- zip_artifact = ctx.new_file(ctx.label.name + ".zip")
- touch_empty_files = [
- "mkdir -p $(dirname ${tmpdir}/%s); touch ${tmpdir}/%s" % (f, f)
- for f in ctx.attr.empty_files
- ]
- cp_resources = [
- ("mkdir -p $(dirname ${tmpdir}/%s)\n" % r.short_path +
- "cp %s ${tmpdir}/%s" % (r.path, r.short_path))
- for r in ctx.files.resources
- ]
- cp_flatten_resources = [
- "cp %s ${tmpdir}/%s" % (r.path, r.basename)
- for r in ctx.files.flatten_resources
- ]
- ctx.action(
- inputs = ctx.files.resources + ctx.files.flatten_resources,
- outputs = [zip_artifact],
- command = "\n".join([
- "tmpdir=$(mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXX)",
- "trap \"rm -fr ${tmpdir}\" EXIT"
- ] + touch_empty_files + cp_resources + cp_flatten_resources + [
- "find ${tmpdir} -exec touch -t 198001010000.00 '{}' ';'",
- "(d=${PWD}; cd ${tmpdir}; zip -rq ${d}/%s *)" % zip_artifact.path,
- ]),
- mnemonic = "ZipBin",
- )
- ctx.action(
- inputs = [ctx.file.launcher, zip_artifact],
- outputs = [ctx.outputs.executable],
- command = "\n".join([
- "cat %s %s > %s" % (ctx.file.launcher.path,
- zip_artifact.path,
- ctx.outputs.executable.path),
- "zip -qA %s" % ctx.outputs.executable.path
- ]),
- mnemonic = "BuildSelfExtractable",
- )
+ """Implementation for the self_extract_binary rule."""
+
+ # This is a bit complex for stripping out timestamps
+ zip_artifact = ctx.new_file(ctx.label.name + ".zip")
+ touch_empty_files = [
+ "mkdir -p $(dirname ${tmpdir}/%s); touch ${tmpdir}/%s" % (f, f)
+ for f in ctx.attr.empty_files
+ ]
+ cp_resources = [
+ ("mkdir -p $(dirname ${tmpdir}/%s)\n" % r.short_path +
+ "cp %s ${tmpdir}/%s" % (r.path, r.short_path))
+ for r in ctx.files.resources
+ ]
+ cp_flatten_resources = [
+ "cp %s ${tmpdir}/%s" % (r.path, r.basename)
+ for r in ctx.files.flatten_resources
+ ]
+ ctx.action(
+ inputs = ctx.files.resources + ctx.files.flatten_resources,
+ outputs = [zip_artifact],
+ command = "\n".join([
+ "tmpdir=$(mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXX)",
+ "trap \"rm -fr ${tmpdir}\" EXIT",
+ ] + touch_empty_files + cp_resources + cp_flatten_resources + [
+ "find ${tmpdir} -exec touch -t 198001010000.00 '{}' ';'",
+ "(d=${PWD}; cd ${tmpdir}; zip -rq ${d}/%s *)" % zip_artifact.path,
+ ]),
+ mnemonic = "ZipBin",
+ )
+ ctx.action(
+ inputs = [ctx.file.launcher, zip_artifact],
+ outputs = [ctx.outputs.executable],
+ command = "\n".join([
+ "cat %s %s > %s" % (
+ ctx.file.launcher.path,
+ zip_artifact.path,
+ ctx.outputs.executable.path,
+ ),
+ "zip -qA %s" % ctx.outputs.executable.path,
+ ]),
+ mnemonic = "BuildSelfExtractable",
+ )
self_extract_binary = rule(
_self_extract_binary,