mirror of
https://github.com/google/nomulus.git
synced 2025-05-05 06:27:51 +02:00
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
66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
# Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
"""Build rule for unit testing the zip_file() rule."""
|
|
|
|
load("//java/google/registry/builddefs:defs.bzl", "ZIPPER")
|
|
|
|
def _impl(ctx):
|
|
"""Implementation of zip_contents_test() rule."""
|
|
cmd = [
|
|
"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())
|
|
),
|
|
' echo "archive had different file listing:"',
|
|
' "${zipper}" v "${archive}" | grep -v ^d',
|
|
" exit 1",
|
|
"fi",
|
|
'tmp="$(mktemp -d "${TMPDIR:-/tmp}/zip_contents_test.XXXXXXXXXX")"',
|
|
'cd "${tmp}"',
|
|
'"${zipper}" x "${archive}"',
|
|
]
|
|
for path, data in ctx.attr.contents.items():
|
|
cmd += [
|
|
'if [[ "$(cat "%s")" != "%s" ]]; then' % (path, data),
|
|
' echo "%s had different contents:"' % path,
|
|
' cat "%s"' % path,
|
|
" exit 1",
|
|
"fi",
|
|
]
|
|
cmd += [
|
|
'cd "${repo}"',
|
|
'rm -rf "${tmp}"',
|
|
]
|
|
ctx.file_action(
|
|
output = ctx.outputs.executable,
|
|
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),
|
|
},
|
|
)
|