mirror of
https://github.com/google/nomulus.git
synced 2025-06-30 08:13:32 +02:00
Format .bzl files with buildifier
This is a part of a large-scale change: [] . All .bzl files are being formatted with buildifier. To format a file manually run `buildifier path/to/file.bzl`. Integration with `g4 fix` will be available later, but you can try using `g4 fix --format=bzl`. Tested: tap_presubmit Some tests failed; test failures are believed to be unrelated to this CL BEGIN_PUBLIC Format .bzl files with buildifier END_PUBLIC ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=203461813
This commit is contained in:
parent
390939815a
commit
0223cea8cc
6 changed files with 2462 additions and 2432 deletions
|
@ -121,52 +121,64 @@ the zipfile. If the file doesn't exist, you'll get an error.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
load('//java/google/registry/builddefs:defs.bzl',
|
load(
|
||||||
'ZIPPER',
|
"//java/google/registry/builddefs:defs.bzl",
|
||||||
'collect_runfiles',
|
"ZIPPER",
|
||||||
'long_path')
|
"collect_runfiles",
|
||||||
|
"long_path",
|
||||||
|
)
|
||||||
|
|
||||||
def _zip_file(ctx):
|
def _zip_file(ctx):
|
||||||
"""Implementation of zip_file() rule."""
|
"""Implementation of zip_file() rule."""
|
||||||
for s, d in ctx.attr.mappings.items():
|
for s, d in ctx.attr.mappings.items():
|
||||||
if (s.startswith('/') or s.endswith('/') or
|
if (s.startswith("/") or s.endswith("/") or
|
||||||
d.startswith('/') or d.endswith('/')):
|
d.startswith("/") or d.endswith("/")):
|
||||||
fail('mappings should not begin or end with slash')
|
fail("mappings should not begin or end with slash")
|
||||||
srcs = depset()
|
srcs = depset()
|
||||||
srcs += ctx.files.srcs
|
srcs += ctx.files.srcs
|
||||||
srcs += ctx.files.data
|
srcs += ctx.files.data
|
||||||
srcs += collect_runfiles(ctx.attr.data)
|
srcs += collect_runfiles(ctx.attr.data)
|
||||||
mapped = _map_sources(ctx, srcs, ctx.attr.mappings)
|
mapped = _map_sources(ctx, srcs, ctx.attr.mappings)
|
||||||
cmd = [
|
cmd = [
|
||||||
'#!/bin/sh',
|
"#!/bin/sh",
|
||||||
'set -e',
|
"set -e",
|
||||||
'repo="$(pwd)"',
|
'repo="$(pwd)"',
|
||||||
'zipper="${repo}/%s"' % ctx.file._zipper.path,
|
'zipper="${repo}/%s"' % ctx.file._zipper.path,
|
||||||
'archive="${repo}/%s"' % ctx.outputs.out.path,
|
'archive="${repo}/%s"' % ctx.outputs.out.path,
|
||||||
'tmp="$(mktemp -d "${TMPDIR:-/tmp}/zip_file.XXXXXXXXXX")"',
|
'tmp="$(mktemp -d "${TMPDIR:-/tmp}/zip_file.XXXXXXXXXX")"',
|
||||||
'cd "${tmp}"',
|
'cd "${tmp}"',
|
||||||
]
|
]
|
||||||
cmd += ['"${zipper}" x "${repo}/%s"' % dep.zip_file.path
|
|
||||||
for dep in ctx.attr.deps]
|
|
||||||
cmd += ['rm %s' % filename for filename in ctx.attr.exclude]
|
|
||||||
cmd += ['mkdir -p "${tmp}/%s"' % zip_path
|
|
||||||
for zip_path in depset(
|
|
||||||
[zip_path[:zip_path.rindex('/')]
|
|
||||||
for _, zip_path in mapped if '/' in zip_path])]
|
|
||||||
cmd += ['ln -sf "${repo}/%s" "${tmp}/%s"' % (path, zip_path)
|
|
||||||
for path, zip_path in mapped]
|
|
||||||
cmd += [
|
cmd += [
|
||||||
('find . | sed 1d | cut -c 3- | LC_ALL=C sort' +
|
'"${zipper}" x "${repo}/%s"' % dep.zip_file.path
|
||||||
|
for dep in ctx.attr.deps
|
||||||
|
]
|
||||||
|
cmd += ["rm %s" % filename for filename in ctx.attr.exclude]
|
||||||
|
cmd += [
|
||||||
|
'mkdir -p "${tmp}/%s"' % zip_path
|
||||||
|
for zip_path in depset(
|
||||||
|
[
|
||||||
|
zip_path[:zip_path.rindex("/")]
|
||||||
|
for _, zip_path in mapped
|
||||||
|
if "/" in zip_path
|
||||||
|
],
|
||||||
|
)
|
||||||
|
]
|
||||||
|
cmd += [
|
||||||
|
'ln -sf "${repo}/%s" "${tmp}/%s"' % (path, zip_path)
|
||||||
|
for path, zip_path in mapped
|
||||||
|
]
|
||||||
|
cmd += [
|
||||||
|
("find . | sed 1d | cut -c 3- | LC_ALL=C sort" +
|
||||||
' | xargs "${zipper}" cC "${archive}"'),
|
' | xargs "${zipper}" cC "${archive}"'),
|
||||||
'cd "${repo}"',
|
'cd "${repo}"',
|
||||||
'rm -rf "${tmp}"',
|
'rm -rf "${tmp}"',
|
||||||
]
|
]
|
||||||
if hasattr(ctx, 'bin_dir'):
|
if hasattr(ctx, "bin_dir"):
|
||||||
script = ctx.new_file(ctx.bin_dir, '%s.sh' % ctx.label.name)
|
script = ctx.new_file(ctx.bin_dir, "%s.sh" % ctx.label.name)
|
||||||
else:
|
else:
|
||||||
# TODO(kchodorow): remove this once Bazel 4.0+ is required.
|
# TODO(kchodorow): remove this once Bazel 4.0+ is required.
|
||||||
script = ctx.new_file(ctx.configuration.bin_dir, '%s.sh' % ctx.label.name)
|
script = ctx.new_file(ctx.configuration.bin_dir, "%s.sh" % ctx.label.name)
|
||||||
ctx.file_action(output=script, content='\n'.join(cmd), executable=True)
|
ctx.file_action(output = script, content = "\n".join(cmd), executable = True)
|
||||||
inputs = [ctx.file._zipper]
|
inputs = [ctx.file._zipper]
|
||||||
inputs += [dep.zip_file for dep in ctx.attr.deps]
|
inputs += [dep.zip_file for dep in ctx.attr.deps]
|
||||||
inputs += list(srcs)
|
inputs += list(srcs)
|
||||||
|
@ -174,16 +186,23 @@ def _zip_file(ctx):
|
||||||
inputs = inputs,
|
inputs = inputs,
|
||||||
outputs = [ctx.outputs.out],
|
outputs = [ctx.outputs.out],
|
||||||
executable = script,
|
executable = script,
|
||||||
mnemonic='zip',
|
mnemonic = "zip",
|
||||||
progress_message='Creating zip with %d inputs %s' % (
|
progress_message = "Creating zip with %d inputs %s" % (
|
||||||
len(inputs), ctx.label))
|
len(inputs),
|
||||||
|
ctx.label,
|
||||||
|
),
|
||||||
|
)
|
||||||
return struct(files = depset([ctx.outputs.out]), zip_file = ctx.outputs.out)
|
return struct(files = depset([ctx.outputs.out]), zip_file = ctx.outputs.out)
|
||||||
|
|
||||||
def _map_sources(ctx, srcs, mappings):
|
def _map_sources(ctx, srcs, mappings):
|
||||||
"""Calculates paths in zip file for srcs."""
|
"""Calculates paths in zip file for srcs."""
|
||||||
|
|
||||||
# order mappings with more path components first
|
# order mappings with more path components first
|
||||||
mappings = sorted([(-len(source.split('/')), source, dest)
|
mappings = sorted([
|
||||||
for source, dest in mappings.items()])
|
(-len(source.split("/")), source, dest)
|
||||||
|
for source, dest in mappings.items()
|
||||||
|
])
|
||||||
|
|
||||||
# get rid of the integer part of tuple used for sorting
|
# get rid of the integer part of tuple used for sorting
|
||||||
mappings = [(source, dest) for _, source, dest in mappings]
|
mappings = [(source, dest) for _, source, dest in mappings]
|
||||||
mappings_indexes = range(len(mappings))
|
mappings_indexes = range(len(mappings))
|
||||||
|
@ -197,7 +216,7 @@ def _map_sources(ctx, srcs, mappings):
|
||||||
dest = mappings[i][1]
|
dest = mappings[i][1]
|
||||||
if not source:
|
if not source:
|
||||||
if dest:
|
if dest:
|
||||||
zip_path = dest + '/' + run_path
|
zip_path = dest + "/" + run_path
|
||||||
else:
|
else:
|
||||||
zip_path = run_path
|
zip_path = run_path
|
||||||
elif source == run_path:
|
elif source == run_path:
|
||||||
|
@ -205,7 +224,7 @@ def _map_sources(ctx, srcs, mappings):
|
||||||
zip_path = dest
|
zip_path = dest
|
||||||
else:
|
else:
|
||||||
zip_path = run_path
|
zip_path = run_path
|
||||||
elif run_path.startswith(source + '/'):
|
elif run_path.startswith(source + "/"):
|
||||||
if dest:
|
if dest:
|
||||||
zip_path = dest + run_path[len(source):]
|
zip_path = dest + run_path[len(source):]
|
||||||
else:
|
else:
|
||||||
|
@ -215,7 +234,7 @@ def _map_sources(ctx, srcs, mappings):
|
||||||
used[i] = True
|
used[i] = True
|
||||||
break
|
break
|
||||||
if not zip_path:
|
if not zip_path:
|
||||||
fail('no mapping matched: ' + run_path)
|
fail("no mapping matched: " + run_path)
|
||||||
mapped += [(file_.path, zip_path)]
|
mapped += [(file_.path, zip_path)]
|
||||||
for i in mappings_indexes:
|
for i in mappings_indexes:
|
||||||
if not used[i]:
|
if not used[i]:
|
||||||
|
@ -226,11 +245,12 @@ zip_file = rule(
|
||||||
implementation = _zip_file,
|
implementation = _zip_file,
|
||||||
output_to_genfiles = True,
|
output_to_genfiles = True,
|
||||||
attrs = {
|
attrs = {
|
||||||
'out': attr.output(mandatory=True),
|
"out": attr.output(mandatory = True),
|
||||||
'srcs': attr.label_list(allow_files=True),
|
"srcs": attr.label_list(allow_files = True),
|
||||||
'data': attr.label_list(cfg='data', allow_files=True),
|
"data": attr.label_list(cfg = "data", allow_files = True),
|
||||||
'deps': attr.label_list(providers=['zip_file']),
|
"deps": attr.label_list(providers = ["zip_file"]),
|
||||||
'exclude': attr.string_list(),
|
"exclude": attr.string_list(),
|
||||||
'mappings': attr.string_dict(),
|
"mappings": attr.string_dict(),
|
||||||
'_zipper': attr.label(default=Label(ZIPPER), single_file=True),
|
"_zipper": attr.label(default = Label(ZIPPER), single_file = True),
|
||||||
})
|
},
|
||||||
|
)
|
||||||
|
|
|
@ -157,7 +157,7 @@ def domain_registry_repositories(
|
||||||
omit_org_xerial_snappy_java = False,
|
omit_org_xerial_snappy_java = False,
|
||||||
omit_org_yaml_snakeyaml = False,
|
omit_org_yaml_snakeyaml = False,
|
||||||
omit_xerces_xmlParserAPIs = False,
|
omit_xerces_xmlParserAPIs = False,
|
||||||
omit_xpp3=False,):
|
omit_xpp3 = False):
|
||||||
"""Imports dependencies for Nomulus."""
|
"""Imports dependencies for Nomulus."""
|
||||||
domain_registry_bazel_check()
|
domain_registry_bazel_check()
|
||||||
if not omit_com_beust_jcommander:
|
if not omit_com_beust_jcommander:
|
||||||
|
@ -513,7 +513,7 @@ def com_google_api_client_appengine():
|
||||||
"@com_google_api_client",
|
"@com_google_api_client",
|
||||||
"@com_google_api_client_servlet",
|
"@com_google_api_client_servlet",
|
||||||
"@com_google_http_client_appengine",
|
"@com_google_http_client_appengine",
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
def com_google_api_client_jackson2():
|
def com_google_api_client_jackson2():
|
||||||
|
@ -608,7 +608,7 @@ def com_google_api_client_servlet():
|
||||||
"@com_google_oauth_client_servlet",
|
"@com_google_oauth_client_servlet",
|
||||||
"@com_google_api_client",
|
"@com_google_api_client",
|
||||||
"@javax_servlet_api",
|
"@javax_servlet_api",
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
def com_google_apis_google_api_services_admin_directory():
|
def com_google_apis_google_api_services_admin_directory():
|
||||||
|
@ -850,7 +850,7 @@ def com_google_appengine_tools_appengine_gcs_client():
|
||||||
"@com_google_api_client_appengine",
|
"@com_google_api_client_appengine",
|
||||||
"@com_google_http_client",
|
"@com_google_http_client",
|
||||||
"@com_google_http_client_jackson2",
|
"@com_google_http_client_jackson2",
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
def com_google_appengine_tools_appengine_mapreduce():
|
def com_google_appengine_tools_appengine_mapreduce():
|
||||||
|
@ -880,7 +880,7 @@ def com_google_appengine_tools_appengine_mapreduce():
|
||||||
"@com_google_http_client_jackson2",
|
"@com_google_http_client_jackson2",
|
||||||
"@com_fasterxml_jackson_core_jackson_databind",
|
"@com_fasterxml_jackson_core_jackson_databind",
|
||||||
"@com_fasterxml_jackson_core",
|
"@com_fasterxml_jackson_core",
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
def com_google_appengine_tools_appengine_pipeline():
|
def com_google_appengine_tools_appengine_pipeline():
|
||||||
|
@ -898,7 +898,7 @@ def com_google_appengine_tools_appengine_pipeline():
|
||||||
"@com_google_guava",
|
"@com_google_guava",
|
||||||
"@javax_servlet_api",
|
"@javax_servlet_api",
|
||||||
"@com_google_appengine_tools_appengine_gcs_client",
|
"@com_google_appengine_tools_appengine_gcs_client",
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
def com_google_appengine_tools_sdk():
|
def com_google_appengine_tools_sdk():
|
||||||
|
@ -1517,11 +1517,13 @@ def com_google_template_soy():
|
||||||
" output_licenses = [\"unencumbered\"],\n" +
|
" output_licenses = [\"unencumbered\"],\n" +
|
||||||
" runtime_deps = [\":com_google_template_soy\"],\n" +
|
" runtime_deps = [\":com_google_template_soy\"],\n" +
|
||||||
")\n") % (name, name)
|
")\n") % (name, name)
|
||||||
for name in ("SoyParseInfoGenerator",
|
for name in (
|
||||||
|
"SoyParseInfoGenerator",
|
||||||
"SoyToJbcSrcCompiler",
|
"SoyToJbcSrcCompiler",
|
||||||
"SoyToJsSrcCompiler",
|
"SoyToJsSrcCompiler",
|
||||||
"SoyToPySrcCompiler",
|
"SoyToPySrcCompiler",
|
||||||
"SoyToIncrementalDomSrcCompiler")
|
"SoyToIncrementalDomSrcCompiler",
|
||||||
|
)
|
||||||
]),
|
]),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1939,7 +1941,6 @@ def jline():
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def joda_time():
|
def joda_time():
|
||||||
java_import_external(
|
java_import_external(
|
||||||
name = "joda_time",
|
name = "joda_time",
|
||||||
|
@ -2505,14 +2506,19 @@ def _check_bazel_version(project, bazel_version):
|
||||||
minimum_bazel_version = _parse_bazel_version(bazel_version)
|
minimum_bazel_version = _parse_bazel_version(bazel_version)
|
||||||
if minimum_bazel_version > current_bazel_version:
|
if minimum_bazel_version > current_bazel_version:
|
||||||
fail("%s requires Bazel >=%s but was %s" % (
|
fail("%s requires Bazel >=%s but was %s" % (
|
||||||
project, bazel_version, native.bazel_version))
|
project,
|
||||||
|
bazel_version,
|
||||||
|
native.bazel_version,
|
||||||
|
))
|
||||||
|
|
||||||
def _parse_bazel_version(bazel_version):
|
def _parse_bazel_version(bazel_version):
|
||||||
# Remove commit from version.
|
# Remove commit from version.
|
||||||
version = bazel_version.split(" ", 1)[0]
|
version = bazel_version.split(" ", 1)[0]
|
||||||
|
|
||||||
# Split into (release, date) parts and only return the release
|
# Split into (release, date) parts and only return the release
|
||||||
# as a tuple of integers.
|
# as a tuple of integers.
|
||||||
parts = version.split("-", 1)
|
parts = version.split("-", 1)
|
||||||
|
|
||||||
# Turn "release" into a tuple of ints.
|
# Turn "release" into a tuple of ints.
|
||||||
version_tuple = ()
|
version_tuple = ()
|
||||||
for number in parts[0].split("."):
|
for number in parts[0].split("."):
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# .'``'. ...
|
# .'``'. ...
|
||||||
# :o o `....'` ;
|
# :o o `....'` ;
|
||||||
|
|
|
@ -14,23 +14,24 @@
|
||||||
|
|
||||||
"""Build rule for unit testing the zip_file() rule."""
|
"""Build rule for unit testing the zip_file() rule."""
|
||||||
|
|
||||||
load('//java/google/registry/builddefs:defs.bzl', 'ZIPPER')
|
load("//java/google/registry/builddefs:defs.bzl", "ZIPPER")
|
||||||
|
|
||||||
def _impl(ctx):
|
def _impl(ctx):
|
||||||
"""Implementation of zip_contents_test() rule."""
|
"""Implementation of zip_contents_test() rule."""
|
||||||
cmd = [
|
cmd = [
|
||||||
'set -e',
|
"set -e",
|
||||||
'repo="$(pwd)"',
|
'repo="$(pwd)"',
|
||||||
'zipper="${repo}/%s"' % ctx.file._zipper.short_path,
|
'zipper="${repo}/%s"' % ctx.file._zipper.short_path,
|
||||||
'archive="${repo}/%s"' % ctx.file.src.short_path,
|
'archive="${repo}/%s"' % ctx.file.src.short_path,
|
||||||
('listing="$("${zipper}" v "${archive}"' +
|
('listing="$("${zipper}" v "${archive}"' +
|
||||||
' | grep -v ^d | awk \'{print $3}\' | LC_ALL=C sort)"'),
|
' | grep -v ^d | awk \'{print $3}\' | LC_ALL=C sort)"'),
|
||||||
'if [[ "${listing}" != "%s" ]]; then' % (
|
'if [[ "${listing}" != "%s" ]]; then' % (
|
||||||
'\n'.join(ctx.attr.contents.keys())),
|
"\n".join(ctx.attr.contents.keys())
|
||||||
|
),
|
||||||
' echo "archive had different file listing:"',
|
' echo "archive had different file listing:"',
|
||||||
' "${zipper}" v "${archive}" | grep -v ^d',
|
' "${zipper}" v "${archive}" | grep -v ^d',
|
||||||
' exit 1',
|
" exit 1",
|
||||||
'fi',
|
"fi",
|
||||||
'tmp="$(mktemp -d "${TMPDIR:-/tmp}/zip_contents_test.XXXXXXXXXX")"',
|
'tmp="$(mktemp -d "${TMPDIR:-/tmp}/zip_contents_test.XXXXXXXXXX")"',
|
||||||
'cd "${tmp}"',
|
'cd "${tmp}"',
|
||||||
'"${zipper}" x "${archive}"',
|
'"${zipper}" x "${archive}"',
|
||||||
|
@ -40,22 +41,26 @@ def _impl(ctx):
|
||||||
'if [[ "$(cat "%s")" != "%s" ]]; then' % (path, data),
|
'if [[ "$(cat "%s")" != "%s" ]]; then' % (path, data),
|
||||||
' echo "%s had different contents:"' % path,
|
' echo "%s had different contents:"' % path,
|
||||||
' cat "%s"' % path,
|
' cat "%s"' % path,
|
||||||
' exit 1',
|
" exit 1",
|
||||||
'fi',
|
"fi",
|
||||||
|
]
|
||||||
|
cmd += [
|
||||||
|
'cd "${repo}"',
|
||||||
|
'rm -rf "${tmp}"',
|
||||||
]
|
]
|
||||||
cmd += ['cd "${repo}"',
|
|
||||||
'rm -rf "${tmp}"']
|
|
||||||
ctx.file_action(
|
ctx.file_action(
|
||||||
output = ctx.outputs.executable,
|
output = ctx.outputs.executable,
|
||||||
content='\n'.join(cmd),
|
content = "\n".join(cmd),
|
||||||
executable=True)
|
executable = True,
|
||||||
|
)
|
||||||
return struct(runfiles = ctx.runfiles([ctx.file.src, ctx.file._zipper]))
|
return struct(runfiles = ctx.runfiles([ctx.file.src, ctx.file._zipper]))
|
||||||
|
|
||||||
zip_contents_test = rule(
|
zip_contents_test = rule(
|
||||||
implementation = _impl,
|
implementation = _impl,
|
||||||
test = True,
|
test = True,
|
||||||
attrs = {
|
attrs = {
|
||||||
'src': attr.label(allow_single_file=True),
|
"src": attr.label(allow_single_file = True),
|
||||||
'contents': attr.string_dict(),
|
"contents": attr.string_dict(),
|
||||||
'_zipper': attr.label(default=Label(ZIPPER), single_file=True),
|
"_zipper": attr.label(default = Label(ZIPPER), single_file = True),
|
||||||
})
|
},
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue