From 47dd4ce9fd4db35df5a2dcde176301b67077a621 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Fri, 9 Jun 2023 16:22:37 -0700 Subject: [PATCH] chore: run buildifier --- MODULE.bazel | 10 +++++----- docs/strings.md | 6 +----- e2e/bzlmod_write_source_files_external/MODULE.bazel | 5 +---- e2e/copy_to_directory/MODULE.bazel | 6 +----- e2e/coreutils/BUILD.bazel | 10 ++++------ e2e/coreutils/MODULE.bazel | 5 ++--- e2e/smoke/BUILD.bazel | 2 +- e2e/smoke/MODULE.bazel | 4 +--- lib/BUILD.bazel | 7 +++---- lib/expand_make_vars.bzl | 1 + lib/expand_template.bzl | 2 +- lib/extensions.bzl | 6 +++--- lib/private/base64.bzl | 4 ++-- lib/private/docs/BUILD.bazel | 8 ++++---- lib/private/expand_template.bzl | 10 +++++----- lib/private/strings.bzl | 9 ++++----- lib/repositories.bzl | 1 - lib/strings.bzl | 4 +--- lib/tests/copy_to_directory/BUILD.bazel | 2 +- lib/tests/expand_template/BUILD.bazel | 2 +- lib/tests/strings_tests.bzl | 7 +++---- tools/BUILD.bazel | 2 +- tools/expand_template/BUILD.bazel | 2 +- tools/hashes.bzl | 11 +++++------ 24 files changed, 52 insertions(+), 74 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 882a6e2..88cc64c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -2,19 +2,19 @@ module( name = "aspect_bazel_lib", - compatibility_level = 1, version = "0.0.0", + compatibility_level = 1, ) # Lower-bound versions of our dependencies bazel_dep(name = "bazel_skylib", version = "1.4.1") bazel_dep(name = "platforms", version = "0.0.4") + # 0.5.4 is the first version with bzlmod support -bazel_dep(name = "stardoc", repo_name = "io_bazel_stardoc", version = "0.5.4") +bazel_dep(name = "stardoc", version = "0.5.4", repo_name = "io_bazel_stardoc") ext = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "ext") - -use_repo(ext, "copy_directory_toolchains", "copy_to_directory_toolchains", "jq_toolchains", "yq_toolchains", "coreutils_toolchains", "expand_template_toolchains") +use_repo(ext, "copy_directory_toolchains", "copy_to_directory_toolchains", "coreutils_toolchains", "expand_template_toolchains", "jq_toolchains", "yq_toolchains") register_toolchains( "@copy_directory_toolchains//:all", @@ -22,7 +22,7 @@ register_toolchains( "@jq_toolchains//:all", "@yq_toolchains//:all", "@coreutils_toolchains//:all", - "@expand_template_toolchains//:all" + "@expand_template_toolchains//:all", ) # Development-only dependencies diff --git a/docs/strings.md b/docs/strings.md index e16ae88..bbab788 100644 --- a/docs/strings.md +++ b/docs/strings.md @@ -38,16 +38,12 @@ hex(number) Format integer to hexdecimal representation -Args: - number: number to format - - **PARAMETERS** | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| number |

-

| none | +| number | number to format | none | **RETURNS** diff --git a/e2e/bzlmod_write_source_files_external/MODULE.bazel b/e2e/bzlmod_write_source_files_external/MODULE.bazel index 9d0ab65..4ff55c3 100644 --- a/e2e/bzlmod_write_source_files_external/MODULE.bazel +++ b/e2e/bzlmod_write_source_files_external/MODULE.bazel @@ -1,17 +1,14 @@ module( name = "bzlmod_write_source_files_external", - compatibility_level = 1, version = "0.0.0", + compatibility_level = 1, ) bazel_dep(name = "aspect_bazel_lib", version = "0.0.0") - local_path_override( module_name = "aspect_bazel_lib", path = "../..", ) test_ext = use_extension("//:test_extension.bzl", "test_ext") - use_repo(test_ext, "test") - diff --git a/e2e/copy_to_directory/MODULE.bazel b/e2e/copy_to_directory/MODULE.bazel index 9bcb87d..07b28ca 100644 --- a/e2e/copy_to_directory/MODULE.bazel +++ b/e2e/copy_to_directory/MODULE.bazel @@ -1,20 +1,16 @@ module( name = "copy_to_directory", - compatibility_level = 1, version = "0.0.0", + compatibility_level = 1, ) bazel_dep(name = "bazel_skylib", version = "1.1.1") - bazel_dep(name = "aspect_bazel_lib", version = "0.0.0") - local_path_override( module_name = "aspect_bazel_lib", path = "../..", ) ext = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "ext") - ext.host() - use_repo(ext, "aspect_bazel_lib_host") diff --git a/e2e/coreutils/BUILD.bazel b/e2e/coreutils/BUILD.bazel index 1e954f0..086a2db 100644 --- a/e2e/coreutils/BUILD.bazel +++ b/e2e/coreutils/BUILD.bazel @@ -10,22 +10,21 @@ genrule( hashes( name = "hash", - src = "test.bin" + src = "test.bin", ) filegroup( name = "md5", + srcs = [":hash"], output_group = "md5", - srcs = [":hash"] ) filegroup( name = "sha1", + srcs = [":hash"], output_group = "sha1", - srcs = [":hash"] ) - # This tests that the "in" file to write_source_files can be a # label to an external repository target when bzlmod is enabled. write_source_files( @@ -34,7 +33,6 @@ write_source_files( "ls.txt.expected": ":ls.txt", "sha256.txt": ":hash", "sha1.txt": ":sha1", - "md5.txt": ":md5" + "md5.txt": ":md5", }, ) - diff --git a/e2e/coreutils/MODULE.bazel b/e2e/coreutils/MODULE.bazel index 3fecfc1..b4da586 100644 --- a/e2e/coreutils/MODULE.bazel +++ b/e2e/coreutils/MODULE.bazel @@ -1,15 +1,14 @@ module( name = "coreutils", - compatibility_level = 1, version = "0.0.0", + compatibility_level = 1, ) bazel_dep(name = "aspect_bazel_lib", version = "0.0.0") - local_path_override( module_name = "aspect_bazel_lib", path = "../..", ) ext = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "ext") -use_repo(ext, "coreutils_toolchains") \ No newline at end of file +use_repo(ext, "coreutils_toolchains") diff --git a/e2e/smoke/BUILD.bazel b/e2e/smoke/BUILD.bazel index e6dd954..173eb88 100644 --- a/e2e/smoke/BUILD.bazel +++ b/e2e/smoke/BUILD.bazel @@ -86,4 +86,4 @@ diff_test( "@aspect_bazel_lib//lib:bzlmod": "a_stamp_expected_bzlmod", "//conditions:default": "a_stamp_expected", }), -) \ No newline at end of file +) diff --git a/e2e/smoke/MODULE.bazel b/e2e/smoke/MODULE.bazel index bc0208f..8949550 100644 --- a/e2e/smoke/MODULE.bazel +++ b/e2e/smoke/MODULE.bazel @@ -1,13 +1,11 @@ module( name = "smoke", - compatibility_level = 1, version = "0.0.0", + compatibility_level = 1, ) bazel_dep(name = "bazel_skylib", version = "1.1.1") - bazel_dep(name = "aspect_bazel_lib", version = "0.0.0") - local_path_override( module_name = "aspect_bazel_lib", path = "../..", diff --git a/lib/BUILD.bazel b/lib/BUILD.bazel index 9220319..8c395e5 100644 --- a/lib/BUILD.bazel +++ b/lib/BUILD.bazel @@ -65,20 +65,19 @@ bzl_library( name = "expand_make_vars", srcs = ["expand_make_vars.bzl"], deps = [ + ":expand_template", "//lib/private/docs:expand_locations", "//lib/private/docs:expand_variables", - ":expand_template", ], ) - bzl_library( name = "expand_template", srcs = ["expand_template.bzl"], deps = [ "//lib/private/docs:expand_locations", - "//lib/private/docs:expand_variables", "//lib/private/docs:expand_template", + "//lib/private/docs:expand_variables", ], ) @@ -273,4 +272,4 @@ bzl_library( name = "strings", srcs = ["strings.bzl"], deps = ["//lib/private/docs:strings"], -) \ No newline at end of file +) diff --git a/lib/expand_make_vars.bzl b/lib/expand_make_vars.bzl index 5a1ca30..98a6e79 100644 --- a/lib/expand_make_vars.bzl +++ b/lib/expand_make_vars.bzl @@ -6,5 +6,6 @@ load(":expand_template.bzl", _expand_template = "expand_template") expand_locations = _expand_locations expand_variables = _expand_variables + # TODO: 2.0 remove re-export from this file. expand_template = _expand_template diff --git a/lib/expand_template.bzl b/lib/expand_template.bzl index 7a2e64c..78383c3 100644 --- a/lib/expand_template.bzl +++ b/lib/expand_template.bzl @@ -2,4 +2,4 @@ load("//lib/private:expand_template.bzl", _expand_template = "expand_template") -expand_template = _expand_template \ No newline at end of file +expand_template = _expand_template diff --git a/lib/extensions.bzl b/lib/extensions.bzl index 380f074..9ba9155 100644 --- a/lib/extensions.bzl +++ b/lib/extensions.bzl @@ -4,10 +4,10 @@ load( "@aspect_bazel_lib//lib:repositories.bzl", "register_copy_directory_toolchains", "register_copy_to_directory_toolchains", - "register_jq_toolchains", - "register_yq_toolchains", "register_coreutils_toolchains", "register_expand_template_toolchains", + "register_jq_toolchains", + "register_yq_toolchains", ) load("//lib/private:host_repo.bzl", "host_repo") @@ -18,7 +18,7 @@ def _toolchain_extension(mctx): register_yq_toolchains(register = False) register_coreutils_toolchains(register = False) register_expand_template_toolchains(register = False) - + create_host_repo = False for module in mctx.modules: if len(module.tags.host) > 0: diff --git a/lib/private/base64.bzl b/lib/private/base64.bzl index 59916d0..41b63e8 100644 --- a/lib/private/base64.bzl +++ b/lib/private/base64.bzl @@ -6,7 +6,7 @@ Implementation based on https://gist.github.com/trondhumbor/ce57c0c2816bb45a8fbb the subset of python available in Starlark. """ -load(":strings.bzl", "ord", "chr") +load(":strings.bzl", "chr", "ord") def decode(data): """Decode a Base64 encoded string. @@ -339,4 +339,4 @@ def _int_to_binary(i, digits = 8): fail("expected a int between 0 and 255 (inclusive)") if digits < 1 or digits > 8: fail("expected digits to be between 1 and 8 (inclusive)") - return INT_TO_BINARY[i][8 - digits:] \ No newline at end of file + return INT_TO_BINARY[i][8 - digits:] diff --git a/lib/private/docs/BUILD.bazel b/lib/private/docs/BUILD.bazel index 58ca4db..316894a 100644 --- a/lib/private/docs/BUILD.bazel +++ b/lib/private/docs/BUILD.bazel @@ -101,8 +101,8 @@ bzl_library( srcs = ["//lib/private:expand_template.bzl"], deps = [ ":expand_locations", + "//lib:stamping", "@bazel_skylib//lib:dicts", - "//lib:stamping" ], ) @@ -229,8 +229,8 @@ bzl_library( name = "base64", srcs = ["//lib/private:base64.bzl"], deps = [ - ":strings" - ] + ":strings", + ], ) bzl_library( @@ -251,7 +251,7 @@ bzl_library( bzl_library( name = "expand_template_toolchain", srcs = ["//lib/private:expand_template_toolchain.bzl"], - deps = ["//lib:stamping"] + deps = ["//lib:stamping"], ) bzl_library( diff --git a/lib/private/expand_template.bzl b/lib/private/expand_template.bzl index c8fd066..812c84f 100644 --- a/lib/private/expand_template.bzl +++ b/lib/private/expand_template.bzl @@ -1,10 +1,10 @@ "expand_template rule" + load("@bazel_skylib//lib:dicts.bzl", "dicts") load(":expand_locations.bzl", _expand_locations = "expand_locations") load(":expand_variables.bzl", _expand_variables = "expand_variables") load("//lib:stamping.bzl", "STAMP_ATTRS", "maybe_stamp") - def _expand_substitutions(ctx, substitutions): result = {} for k, v in substitutions.items(): @@ -23,7 +23,7 @@ def _expand_template_impl(ctx): substitutions_out = ctx.actions.declare_file("{}_substitutions.json".format(ctx.label.name)) ctx.actions.write( output = substitutions_out, - content = json.encode(substitutions) + content = json.encode(substitutions), ) inputs = [ @@ -90,7 +90,7 @@ such as `$(BINDIR)`, `$(TARGET_CPU)`, and `$(COMPILATION_MODE)` as documented in There are overlayed on top of substitutions when stamping is enabled for the target. - + Substitutions can contain $(execpath :target) and $(rootpath :target) expansions, $(MAKEVAR) expansions and {{STAMP_VAR}} expansions when stamping is enabled for the target. @@ -98,7 +98,7 @@ such as `$(BINDIR)`, `$(TARGET_CPU)`, and `$(COMPILATION_MODE)` as documented in ), "substitutions": attr.string_dict( doc = """Mapping of strings to substitutions. - + Substitutions can contain $(execpath :target) and $(rootpath :target) expansions, $(MAKEVAR) expansions and {{STAMP_VAR}} expansions when stamping is enabled for the target. @@ -109,7 +109,7 @@ such as `$(BINDIR)`, `$(TARGET_CPU)`, and `$(COMPILATION_MODE)` as documented in mandatory = True, allow_single_file = True, ), - }, **STAMP_ATTRS), + }, **STAMP_ATTRS), ) expand_template = rule( diff --git a/lib/private/strings.bzl b/lib/private/strings.bzl index dd67a8b..91e6215 100644 --- a/lib/private/strings.bzl +++ b/lib/private/strings.bzl @@ -530,7 +530,7 @@ def ord(c): Args: c: character whose codepoint to be returned. - + Returns: codepoint of `c` argument. """ @@ -561,11 +561,11 @@ def _to_char(n): def hex(number): """Format integer to hexdecimal representation - Args: + Args: number: number to format Returns: - hexdecimal representation of the number argument + hexdecimal representation of the number argument """ hex_string = "" @@ -578,9 +578,8 @@ def hex(number): r //= 16 else: break - + if not hex_string: hex_string = "0" return "{}0x{}".format("-" if is_signed else "", hex_string) - diff --git a/lib/repositories.bzl b/lib/repositories.bzl index 3bfb5f3..bfa8be7 100644 --- a/lib/repositories.bzl +++ b/lib/repositories.bzl @@ -166,7 +166,6 @@ def register_copy_to_directory_toolchains(name = "copy_to_directory", register = user_repository_name = name, ) - def register_expand_template_toolchains(name = "expand_template", register = True): """Registers expand_template toolchain and repositories diff --git a/lib/strings.bzl b/lib/strings.bzl index 804a722..8ae55f0 100644 --- a/lib/strings.bzl +++ b/lib/strings.bzl @@ -1,8 +1,6 @@ - - "Utilities for strings" -load("//lib/private:strings.bzl", _chr = "chr", _ord = "ord", _hex = "hex") +load("//lib/private:strings.bzl", _chr = "chr", _hex = "hex", _ord = "ord") chr = _chr ord = _ord diff --git a/lib/tests/copy_to_directory/BUILD.bazel b/lib/tests/copy_to_directory/BUILD.bazel index 857ec89..4ef22a0 100644 --- a/lib/tests/copy_to_directory/BUILD.bazel +++ b/lib/tests/copy_to_directory/BUILD.bazel @@ -196,8 +196,8 @@ copy_to_directory( ":d", ":e/e1", ":e/e2", + "//lib/tests/copy_to_directory/f/f2", "//lib/tests/copy_to_directory/f/f2:f1", - "//lib/tests/copy_to_directory/f/f2:f2", "@external_test_repo//:test_c", "@external_test_repo//:test_d", ] + make_directory_paths( diff --git a/lib/tests/expand_template/BUILD.bazel b/lib/tests/expand_template/BUILD.bazel index 902a9ea..0341dfb 100644 --- a/lib/tests/expand_template/BUILD.bazel +++ b/lib/tests/expand_template/BUILD.bazel @@ -57,4 +57,4 @@ assert_contains( name = "default_info_test", actual = ":a_tmpl_stamp", expected = "WORKSPACE:", -) \ No newline at end of file +) diff --git a/lib/tests/strings_tests.bzl b/lib/tests/strings_tests.bzl index ad5e30c..1bd339a 100644 --- a/lib/tests/strings_tests.bzl +++ b/lib/tests/strings_tests.bzl @@ -1,7 +1,7 @@ """unit tests for string""" load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") -load("//lib/private:strings.bzl", "ord", "chr", "hex") +load("//lib/private:strings.bzl", "chr", "hex", "ord") def _ord_test_impl(ctx): env = unittest.begin(ctx) @@ -20,7 +20,6 @@ def _ord_test_impl(ctx): ord_test = unittest.make(_ord_test_impl) - def _chr_test_impl(ctx): env = unittest.begin(ctx) @@ -38,7 +37,6 @@ def _chr_test_impl(ctx): chr_test = unittest.make(_chr_test_impl) - def _hex_test_impl(ctx): env = unittest.begin(ctx) @@ -46,6 +44,7 @@ def _hex_test_impl(ctx): asserts.equals(env, hex(97), "0x61") asserts.equals(env, hex(1000000000000), "0xe8d4a51000") asserts.equals(env, hex(1), "0x1") + # https://en.wikipedia.org/wiki/Signed_zero asserts.equals(env, hex(0), "0x0") asserts.equals(env, hex(-0), "0x0") @@ -61,5 +60,5 @@ def strings_test_suite(): "strings_tests", ord_test, chr_test, - hex_test + hex_test, ) diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel index 4eccb10..3b7ba99 100644 --- a/tools/BUILD.bazel +++ b/tools/BUILD.bazel @@ -28,6 +28,6 @@ release( targets = [ ":copy_directory", ":copy_to_directory", - ":expand_template" + ":expand_template", ], ) diff --git a/tools/expand_template/BUILD.bazel b/tools/expand_template/BUILD.bazel index 0b10db4..009ea0a 100644 --- a/tools/expand_template/BUILD.bazel +++ b/tools/expand_template/BUILD.bazel @@ -15,4 +15,4 @@ go_binary( name = "expand_template", embed = [":expand_template_lib"], visibility = ["//visibility:public"], -) \ No newline at end of file +) diff --git a/tools/hashes.bzl b/tools/hashes.bzl index 5a9e8b7..94ad7d2 100644 --- a/tools/hashes.bzl +++ b/tools/hashes.bzl @@ -6,7 +6,6 @@ via output groups. Based on https://github.com/bazelbuild/examples/blob/main/rules/implicit_output/hash.bzl """ - def _hash(ctx, algo, file): coreutils = ctx.toolchains["@aspect_bazel_lib//lib:coreutils_toolchain_type"] out = ctx.actions.declare_file("{}.{}".format(file.path, algo)) @@ -16,11 +15,11 @@ def _hash(ctx, algo, file): tools = [coreutils.coreutils_info.bin], # coreutils has --no-names option but it doesn't work in current version, so we have to use cut. command = """HASH=$({coreutils} hashsum --{algo} {src} | {coreutils} cut -f1 -d " ") && {coreutils} echo -ne "$HASH {basename}" > {out}""".format( - coreutils = coreutils.coreutils_info.bin.path, - algo = algo, - src = file.path, + coreutils = coreutils.coreutils_info.bin.path, + algo = algo, + src = file.path, basename = file.basename, - out = out.path + out = out.path, ), ) return out @@ -55,7 +54,7 @@ _hashes = rule( "src": attr.label( allow_single_file = True, mandatory = True, - ) + ), }, )