mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 17:07:15 +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',
|
||||
'ZIPPER',
|
||||
'collect_runfiles',
|
||||
'long_path')
|
||||
load(
|
||||
"//java/google/registry/builddefs:defs.bzl",
|
||||
"ZIPPER",
|
||||
"collect_runfiles",
|
||||
"long_path",
|
||||
)
|
||||
|
||||
def _zip_file(ctx):
|
||||
"""Implementation of zip_file() rule."""
|
||||
for s, d in ctx.attr.mappings.items():
|
||||
if (s.startswith('/') or s.endswith('/') or
|
||||
d.startswith('/') or d.endswith('/')):
|
||||
fail('mappings should not begin or end with slash')
|
||||
if (s.startswith("/") or s.endswith("/") or
|
||||
d.startswith("/") or d.endswith("/")):
|
||||
fail("mappings should not begin or end with slash")
|
||||
srcs = depset()
|
||||
srcs += ctx.files.srcs
|
||||
srcs += ctx.files.data
|
||||
srcs += collect_runfiles(ctx.attr.data)
|
||||
mapped = _map_sources(ctx, srcs, ctx.attr.mappings)
|
||||
cmd = [
|
||||
'#!/bin/sh',
|
||||
'set -e',
|
||||
"#!/bin/sh",
|
||||
"set -e",
|
||||
'repo="$(pwd)"',
|
||||
'zipper="${repo}/%s"' % ctx.file._zipper.path,
|
||||
'archive="${repo}/%s"' % ctx.outputs.out.path,
|
||||
'tmp="$(mktemp -d "${TMPDIR:-/tmp}/zip_file.XXXXXXXXXX")"',
|
||||
'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 += [
|
||||
('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}"'),
|
||||
'cd "${repo}"',
|
||||
'rm -rf "${tmp}"',
|
||||
]
|
||||
if hasattr(ctx, 'bin_dir'):
|
||||
script = ctx.new_file(ctx.bin_dir, '%s.sh' % ctx.label.name)
|
||||
if hasattr(ctx, "bin_dir"):
|
||||
script = ctx.new_file(ctx.bin_dir, "%s.sh" % ctx.label.name)
|
||||
else:
|
||||
# TODO(kchodorow): remove this once Bazel 4.0+ is required.
|
||||
script = ctx.new_file(ctx.configuration.bin_dir, '%s.sh' % ctx.label.name)
|
||||
ctx.file_action(output=script, content='\n'.join(cmd), executable=True)
|
||||
script = ctx.new_file(ctx.configuration.bin_dir, "%s.sh" % ctx.label.name)
|
||||
ctx.file_action(output = script, content = "\n".join(cmd), executable = True)
|
||||
inputs = [ctx.file._zipper]
|
||||
inputs += [dep.zip_file for dep in ctx.attr.deps]
|
||||
inputs += list(srcs)
|
||||
|
@ -174,16 +186,23 @@ def _zip_file(ctx):
|
|||
inputs = inputs,
|
||||
outputs = [ctx.outputs.out],
|
||||
executable = script,
|
||||
mnemonic='zip',
|
||||
progress_message='Creating zip with %d inputs %s' % (
|
||||
len(inputs), ctx.label))
|
||||
mnemonic = "zip",
|
||||
progress_message = "Creating zip with %d inputs %s" % (
|
||||
len(inputs),
|
||||
ctx.label,
|
||||
),
|
||||
)
|
||||
return struct(files = depset([ctx.outputs.out]), zip_file = ctx.outputs.out)
|
||||
|
||||
def _map_sources(ctx, srcs, mappings):
|
||||
"""Calculates paths in zip file for srcs."""
|
||||
|
||||
# order mappings with more path components first
|
||||
mappings = sorted([(-len(source.split('/')), source, dest)
|
||||
for source, dest in mappings.items()])
|
||||
mappings = sorted([
|
||||
(-len(source.split("/")), source, dest)
|
||||
for source, dest in mappings.items()
|
||||
])
|
||||
|
||||
# get rid of the integer part of tuple used for sorting
|
||||
mappings = [(source, dest) for _, source, dest in mappings]
|
||||
mappings_indexes = range(len(mappings))
|
||||
|
@ -197,7 +216,7 @@ def _map_sources(ctx, srcs, mappings):
|
|||
dest = mappings[i][1]
|
||||
if not source:
|
||||
if dest:
|
||||
zip_path = dest + '/' + run_path
|
||||
zip_path = dest + "/" + run_path
|
||||
else:
|
||||
zip_path = run_path
|
||||
elif source == run_path:
|
||||
|
@ -205,7 +224,7 @@ def _map_sources(ctx, srcs, mappings):
|
|||
zip_path = dest
|
||||
else:
|
||||
zip_path = run_path
|
||||
elif run_path.startswith(source + '/'):
|
||||
elif run_path.startswith(source + "/"):
|
||||
if dest:
|
||||
zip_path = dest + run_path[len(source):]
|
||||
else:
|
||||
|
@ -215,7 +234,7 @@ def _map_sources(ctx, srcs, mappings):
|
|||
used[i] = True
|
||||
break
|
||||
if not zip_path:
|
||||
fail('no mapping matched: ' + run_path)
|
||||
fail("no mapping matched: " + run_path)
|
||||
mapped += [(file_.path, zip_path)]
|
||||
for i in mappings_indexes:
|
||||
if not used[i]:
|
||||
|
@ -226,11 +245,12 @@ zip_file = rule(
|
|||
implementation = _zip_file,
|
||||
output_to_genfiles = True,
|
||||
attrs = {
|
||||
'out': attr.output(mandatory=True),
|
||||
'srcs': attr.label_list(allow_files=True),
|
||||
'data': attr.label_list(cfg='data', allow_files=True),
|
||||
'deps': attr.label_list(providers=['zip_file']),
|
||||
'exclude': attr.string_list(),
|
||||
'mappings': attr.string_dict(),
|
||||
'_zipper': attr.label(default=Label(ZIPPER), single_file=True),
|
||||
})
|
||||
"out": attr.output(mandatory = True),
|
||||
"srcs": attr.label_list(allow_files = True),
|
||||
"data": attr.label_list(cfg = "data", allow_files = True),
|
||||
"deps": attr.label_list(providers = ["zip_file"]),
|
||||
"exclude": attr.string_list(),
|
||||
"mappings": attr.string_dict(),
|
||||
"_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_yaml_snakeyaml = False,
|
||||
omit_xerces_xmlParserAPIs = False,
|
||||
omit_xpp3=False,):
|
||||
omit_xpp3 = False):
|
||||
"""Imports dependencies for Nomulus."""
|
||||
domain_registry_bazel_check()
|
||||
if not omit_com_beust_jcommander:
|
||||
|
@ -513,7 +513,7 @@ def com_google_api_client_appengine():
|
|||
"@com_google_api_client",
|
||||
"@com_google_api_client_servlet",
|
||||
"@com_google_http_client_appengine",
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
def com_google_api_client_jackson2():
|
||||
|
@ -608,7 +608,7 @@ def com_google_api_client_servlet():
|
|||
"@com_google_oauth_client_servlet",
|
||||
"@com_google_api_client",
|
||||
"@javax_servlet_api",
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
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_http_client",
|
||||
"@com_google_http_client_jackson2",
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
def com_google_appengine_tools_appengine_mapreduce():
|
||||
|
@ -880,7 +880,7 @@ def com_google_appengine_tools_appengine_mapreduce():
|
|||
"@com_google_http_client_jackson2",
|
||||
"@com_fasterxml_jackson_core_jackson_databind",
|
||||
"@com_fasterxml_jackson_core",
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
def com_google_appengine_tools_appengine_pipeline():
|
||||
|
@ -898,7 +898,7 @@ def com_google_appengine_tools_appengine_pipeline():
|
|||
"@com_google_guava",
|
||||
"@javax_servlet_api",
|
||||
"@com_google_appengine_tools_appengine_gcs_client",
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
def com_google_appengine_tools_sdk():
|
||||
|
@ -1517,11 +1517,13 @@ def com_google_template_soy():
|
|||
" output_licenses = [\"unencumbered\"],\n" +
|
||||
" runtime_deps = [\":com_google_template_soy\"],\n" +
|
||||
")\n") % (name, name)
|
||||
for name in ("SoyParseInfoGenerator",
|
||||
for name in (
|
||||
"SoyParseInfoGenerator",
|
||||
"SoyToJbcSrcCompiler",
|
||||
"SoyToJsSrcCompiler",
|
||||
"SoyToPySrcCompiler",
|
||||
"SoyToIncrementalDomSrcCompiler")
|
||||
"SoyToIncrementalDomSrcCompiler",
|
||||
)
|
||||
]),
|
||||
)
|
||||
|
||||
|
@ -1939,7 +1941,6 @@ def jline():
|
|||
],
|
||||
)
|
||||
|
||||
|
||||
def joda_time():
|
||||
java_import_external(
|
||||
name = "joda_time",
|
||||
|
@ -2505,14 +2506,19 @@ def _check_bazel_version(project, bazel_version):
|
|||
minimum_bazel_version = _parse_bazel_version(bazel_version)
|
||||
if minimum_bazel_version > current_bazel_version:
|
||||
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):
|
||||
# Remove commit from version.
|
||||
version = bazel_version.split(" ", 1)[0]
|
||||
|
||||
# Split into (release, date) parts and only return the release
|
||||
# as a tuple of integers.
|
||||
parts = version.split("-", 1)
|
||||
|
||||
# Turn "release" into a tuple of ints.
|
||||
version_tuple = ()
|
||||
for number in parts[0].split("."):
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
#
|
||||
# .'``'. ...
|
||||
# :o o `....'` ;
|
||||
|
|
|
@ -14,23 +14,24 @@
|
|||
|
||||
"""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):
|
||||
"""Implementation of zip_contents_test() rule."""
|
||||
cmd = [
|
||||
'set -e',
|
||||
"set -e",
|
||||
'repo="$(pwd)"',
|
||||
'zipper="${repo}/%s"' % ctx.file._zipper.short_path,
|
||||
'archive="${repo}/%s"' % ctx.file.src.short_path,
|
||||
('listing="$("${zipper}" v "${archive}"' +
|
||||
' | grep -v ^d | awk \'{print $3}\' | LC_ALL=C sort)"'),
|
||||
'if [[ "${listing}" != "%s" ]]; then' % (
|
||||
'\n'.join(ctx.attr.contents.keys())),
|
||||
"\n".join(ctx.attr.contents.keys())
|
||||
),
|
||||
' echo "archive had different file listing:"',
|
||||
' "${zipper}" v "${archive}" | grep -v ^d',
|
||||
' exit 1',
|
||||
'fi',
|
||||
" exit 1",
|
||||
"fi",
|
||||
'tmp="$(mktemp -d "${TMPDIR:-/tmp}/zip_contents_test.XXXXXXXXXX")"',
|
||||
'cd "${tmp}"',
|
||||
'"${zipper}" x "${archive}"',
|
||||
|
@ -40,22 +41,26 @@ def _impl(ctx):
|
|||
'if [[ "$(cat "%s")" != "%s" ]]; then' % (path, data),
|
||||
' echo "%s had different contents:"' % path,
|
||||
' cat "%s"' % path,
|
||||
' exit 1',
|
||||
'fi',
|
||||
" exit 1",
|
||||
"fi",
|
||||
]
|
||||
cmd += [
|
||||
'cd "${repo}"',
|
||||
'rm -rf "${tmp}"',
|
||||
]
|
||||
cmd += ['cd "${repo}"',
|
||||
'rm -rf "${tmp}"']
|
||||
ctx.file_action(
|
||||
output = ctx.outputs.executable,
|
||||
content='\n'.join(cmd),
|
||||
executable=True)
|
||||
content = "\n".join(cmd),
|
||||
executable = True,
|
||||
)
|
||||
return struct(runfiles = ctx.runfiles([ctx.file.src, ctx.file._zipper]))
|
||||
|
||||
zip_contents_test = rule(
|
||||
implementation = _impl,
|
||||
test = True,
|
||||
attrs = {
|
||||
'src': attr.label(allow_single_file=True),
|
||||
'contents': attr.string_dict(),
|
||||
'_zipper': attr.label(default=Label(ZIPPER), single_file=True),
|
||||
})
|
||||
"src": attr.label(allow_single_file = True),
|
||||
"contents": attr.string_dict(),
|
||||
"_zipper": attr.label(default = Label(ZIPPER), single_file = True),
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue