From c3fde70677b80b34043f8d76f9bb783e9d925dbb Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Wed, 8 Mar 2023 12:09:56 -0700 Subject: [PATCH] chore: add support for `bzlmod` (#232) - Clean house: - Remove all conditional dependency code. - Remove the ability to build buildtools from source. Just use `keith/buildifier-prebuilt`. - Remove unused `binary_pkg`. - Add `MODULE.bazel` with all dependencies. - Update all example workspaces to include a `MODULE.bazel`. - Add `--noenable_bzlmod` to `shared.bazelrc` until bazelbuild/bazel#14140 is fixed. Related to #195. --- .bazelrc | 4 +- BUILD.bazel | 14 +- MODULE.bazel | 110 +++++++++++++ bazel_starlib_buildtools.bzl | 86 ---------- bazel_versions.bzl | 4 +- bzlformat/README.md | 4 +- bzlformat/tools/BUILD.bazel | 2 +- bzlformat/tools/buildifier.sh | 2 +- bzlformat/tools/missing_pkgs/BUILD.bazel | 2 +- bzlformat/tools/missing_pkgs/fix.sh | 2 +- deps.bzl | 57 +------ doc/shlib/BUILD.bazel | 1 - doc/shlib/binary_pkg.md | 26 --- doc/shlib/rules.md | 1 - examples/bzlformat/BUILD.bazel | 29 +--- examples/bzlformat/README.md | 2 - examples/bzlformat/build_buildtools/.bazelrc | 9 -- .../bzlformat/build_buildtools/BUILD.bazel | 37 ----- examples/bzlformat/build_buildtools/README.md | 32 ---- examples/bzlformat/build_buildtools/WORKSPACE | 34 ---- examples/bzlformat/simple/MODULE.bazel | 7 + examples/bzlformat/simple/WORKSPACE | 2 +- examples/markdown/simple/MODULE.bazel | 7 + examples/markdown/simple/WORKSPACE | 2 +- examples/updatesrc/simple/.bazelrc | 1 - examples/updatesrc/simple/MODULE.bazel | 7 + examples/updatesrc/simple/WORKSPACE | 2 +- go_deps.bzl | 3 + shared.bazelrc | 3 + shlib/rules/BUILD.bazel | 8 - shlib/rules/binary_pkg.bzl | 5 - shlib/rules/private/BUILD.bazel | 8 - shlib/rules/private/binary_pkg.bzl | 150 ------------------ .../missing_pkgs_tests/BUILD.bazel | 2 +- .../missing_pkgs_tests/missing_pkgs_test.sh | 2 +- .../rules_tests/binary_pkg_tests/BUILD.bazel | 128 --------------- .../binary_pkg_tests/hello_world.sh | 7 - .../binary_pkg_tests/hello_world_pkg_test.sh | 35 ---- .../binary_pkg_tests/process_file.sh | 41 ----- .../binary_pkg_tests/process_file_consumer.sh | 40 ----- .../process_file_consumer_eb_test.sh | 32 ---- .../binary_pkg_tests/process_file_pkg_test.sh | 26 --- updatesrc/BUILD.bazel | 1 + 43 files changed, 162 insertions(+), 815 deletions(-) create mode 100644 MODULE.bazel delete mode 100644 bazel_starlib_buildtools.bzl delete mode 100755 doc/shlib/binary_pkg.md delete mode 100644 examples/bzlformat/build_buildtools/.bazelrc delete mode 100644 examples/bzlformat/build_buildtools/BUILD.bazel delete mode 100644 examples/bzlformat/build_buildtools/README.md delete mode 100644 examples/bzlformat/build_buildtools/WORKSPACE create mode 100644 examples/bzlformat/simple/MODULE.bazel create mode 100644 examples/markdown/simple/MODULE.bazel create mode 100644 examples/updatesrc/simple/MODULE.bazel delete mode 100644 shlib/rules/binary_pkg.bzl delete mode 100644 shlib/rules/private/binary_pkg.bzl delete mode 100644 tests/shlib_tests/rules_tests/binary_pkg_tests/BUILD.bazel delete mode 100755 tests/shlib_tests/rules_tests/binary_pkg_tests/hello_world.sh delete mode 100755 tests/shlib_tests/rules_tests/binary_pkg_tests/hello_world_pkg_test.sh delete mode 100755 tests/shlib_tests/rules_tests/binary_pkg_tests/process_file.sh delete mode 100755 tests/shlib_tests/rules_tests/binary_pkg_tests/process_file_consumer.sh delete mode 100755 tests/shlib_tests/rules_tests/binary_pkg_tests/process_file_consumer_eb_test.sh delete mode 100755 tests/shlib_tests/rules_tests/binary_pkg_tests/process_file_pkg_test.sh diff --git a/.bazelrc b/.bazelrc index 93cf8423..555764a6 100644 --- a/.bazelrc +++ b/.bazelrc @@ -3,8 +3,8 @@ # This lets us glob() up all the files inside the examples to make them inputs to tests # (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it) # To update these lines, run `bazel run @contrib_rules_bazel_integration_test//tools:update_deleted_packages`. -build --deleted_packages=examples/bzlformat/build_buildtools,examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters -query --deleted_packages=examples/bzlformat/build_buildtools,examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters +build --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters +query --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters # Import Shared settings import %workspace%/shared.bazelrc diff --git a/BUILD.bazel b/BUILD.bazel index 90985d35..89271253 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -40,9 +40,7 @@ gazelle( bzlformat_pkg(name = "bzlformat") -bzlformat_missing_pkgs( - name = "bzlformat_missing_pkgs", -) +bzlformat_missing_pkgs(name = "bzlformat_missing_pkgs") # MARK: - Update Source Files @@ -51,6 +49,9 @@ updatesrc_update_all(name = "update_all") tidy( name = "tidy", targets = [ + # Remove the child workspace symlinks before doing some of the other + # operations that my experience infinite symlink expansion errors. + "@contrib_rules_bazel_integration_test//tools:remove_child_wksp_bazel_symlinks", "@contrib_rules_bazel_integration_test//tools:update_deleted_packages", ":bzlformat_missing_pkgs_fix", ":update_all", @@ -209,7 +210,6 @@ bzl_library( srcs = ["deps.bzl"], visibility = ["//visibility:public"], deps = [ - ":bazel_starlib_buildtools", "@bazel_tools//tools/build_defs/repo:http.bzl", "@bazel_tools//tools/build_defs/repo:utils.bzl", ], @@ -222,12 +222,6 @@ bzl_library( deps = ["@bazel_gazelle//:deps"], ) -bzl_library( - name = "bazel_starlib_buildtools", - srcs = ["bazel_starlib_buildtools.bzl"], - visibility = ["//visibility:public"], -) - bzl_library( name = "bazel_versions", srcs = ["bazel_versions.bzl"], diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 00000000..b90869c8 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,110 @@ +module( + name = "cgrindel_bazel_starlib", + version = "0.13.1", +) + +bazel_dep( + name = "bazel_skylib_gazelle_plugin", + version = "1.4.1", + dev_dependency = True, +) + +bazel_dep( + name = "rules_go", + version = "0.38.1", + repo_name = "io_bazel_rules_go", +) +bazel_dep( + name = "gazelle", + version = "0.29.0", +) +bazel_dep(name = "bazel_skylib", version = "1.4.1") +bazel_dep( + name = "stardoc", + version = "0.5.3", + repo_name = "io_bazel_stardoc", +) +bazel_dep( + name = "buildifier_prebuilt", + version = "6.0.0.1", +) + +go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps") + +# NOTE: We are not loading the Go modules from go.mod, because we are doing +# something a little weird in that we are building an executable from another +# repository. The `go mod tidy` operation does not fill in the indirect deps. +# Instead, we declare the same repos listed in `go_deps.bzl`. +# go_deps.from_file(go_mod = "//:go.mod") +go_deps.module( + path = "github.com/alecthomas/assert", + sum = "h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U=", + version = "v0.0.0-20170929043011-405dbfeb8e38", +) +go_deps.module( + path = "github.com/alecthomas/colour", + sum = "h1:nOE9rJm6dsZ66RGWYSFrXw461ZIt9A6+nHgL7FRrDUk=", + version = "v0.1.0", +) +go_deps.module( + path = "github.com/alecthomas/repr", + sum = "h1:8Uy0oSf5co/NZXje7U1z8Mpep++QJOldL2hs/sBQf48=", + version = "v0.0.0-20210801044451-80ca428c5142", +) +go_deps.module( + path = "github.com/alecthomas/template", + sum = "h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=", + version = "v0.0.0-20160405071501-a0175ee3bccc", +) +go_deps.module( + path = "github.com/alecthomas/units", + sum = "h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=", + version = "v0.0.0-20151022065526-2efee857e7cf", +) +go_deps.module( + path = "github.com/davecgh/go-spew", + sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=", + version = "v1.1.1", +) +go_deps.module( + path = "github.com/ekalinin/github-markdown-toc.go", + sum = "h1:6jRFt5qg61XfXZbP3SDaeTX+1OC1EgbHvRceYDmPAUE=", + version = "v1.2.1", +) +go_deps.module( + path = "github.com/mattn/go-isatty", + sum = "h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=", + version = "v0.0.14", +) +go_deps.module( + path = "github.com/sergi/go-diff", + sum = "h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=", + version = "v1.2.0", +) +go_deps.module( + path = "github.com/stretchr/testify", + sum = "h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=", + version = "v1.7.0", +) +go_deps.module( + path = "gopkg.in/alecthomas/kingpin.v2", + sum = "h1:CC8tJ/xljioKrK6ii3IeWVXU4Tw7VB+LbjZBJaBxN50=", + version = "v2.2.4", +) + +# Declare all of the go modules that we are going to use to build the ekalinin +# github markdown toc. +use_repo( + go_deps, + "com_github_alecthomas_assert", + "com_github_alecthomas_colour", + "com_github_alecthomas_repr", + "com_github_alecthomas_template", + "com_github_alecthomas_units", + "com_github_davecgh_go_spew", + "com_github_ekalinin_github_markdown_toc_go", + "com_github_mattn_go_isatty", + "com_github_sergi_go_diff", + "com_github_stretchr_testify", + "in_gopkg_alecthomas_kingpin_v2", +) diff --git a/bazel_starlib_buildtools.bzl b/bazel_starlib_buildtools.bzl deleted file mode 100644 index be515d1e..00000000 --- a/bazel_starlib_buildtools.bzl +++ /dev/null @@ -1,86 +0,0 @@ -"""Set up the location for `bazelbuild/buildtools`""" - -def _generate_trampoline_content(repository_ctx, filename, exec_location): - content = """\ -#!/usr/bin/env bash - -# --- begin runfiles.bash initialization v2 --- -# Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash -source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \\ - source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \\ - source "$0.runfiles/$f" 2>/dev/null || \\ - source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \\ - source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \\ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e -# --- end runfiles.bash initialization v2 --- - -""" + """\ -executable_location={executable_location} -""".format( - executable_location = exec_location, - ) + """\ -executable="$(rlocation "${executable_location}")" || \\ - (echo >&2 "Failed to locate ${executable_location}" && exit 1) - -cmd=( "${executable}" ) -[[ ${#} > 0 ]] && cmd+=( "${@}" ) -"${cmd[@]}" -""" - repository_ctx.file(filename, content, True) - -def _bazel_starlib_buildtools_impl(repository_ctx): - _generate_trampoline_content( - repository_ctx, - "buildifier.sh", - repository_ctx.attr.buildifier_location, - ) - _generate_trampoline_content( - repository_ctx, - "buildozer.sh", - repository_ctx.attr.buildozer_location, - ) - - build_content = """\ -package(default_visibility = ["//visibility:public"]) - -sh_binary( - name = "buildifier", - srcs = ["buildifier.sh"], - data = ["{buildifier}"], - deps = ["@bazel_tools//tools/bash/runfiles"], -) - -sh_binary( - name = "buildozer", - srcs = ["buildozer.sh"], - data = ["{buildozer}"], - deps = ["@bazel_tools//tools/bash/runfiles"], -) -""".format( - buildifier = repository_ctx.attr.buildifier_target, - buildozer = repository_ctx.attr.buildozer_target, - ) - repository_ctx.file("BUILD.bazel", build_content) - -bazel_starlib_buildtools = repository_rule( - implementation = _bazel_starlib_buildtools_impl, - attrs = { - "buildifier_location": attr.string( - mandatory = True, - doc = "The `buildifier` location in runfiles.", - ), - "buildifier_target": attr.string( - mandatory = True, - doc = "The `buildifier` target.", - ), - "buildozer_location": attr.string( - mandatory = True, - doc = "The `buildozer` target.", - ), - "buildozer_target": attr.string( - mandatory = True, - doc = "The `buildozer` target.", - ), - }, -) diff --git a/bazel_versions.bzl b/bazel_versions.bzl index 2568b8f0..cacccf2d 100644 --- a/bazel_versions.bzl +++ b/bazel_versions.bzl @@ -3,7 +3,9 @@ CURRENT_BAZEL_VERSION = "//:.bazelversion" OTHER_BAZEL_VERSIONS = [ - "5.4.0", + # GH195: Enable once we can use the default enable_bzlmod values (i.e., do + # not need to specify). + # "5.4.0", ] SUPPORTED_BAZEL_VERSIONS = [ diff --git a/bzlformat/README.md b/bzlformat/README.md index cb97e8c0..34bc790d 100644 --- a/bzlformat/README.md +++ b/bzlformat/README.md @@ -25,9 +25,7 @@ information. In addition to the [workspace snippet for the repository](/README.md#workspace-configuration), add the following to your `WORKSPACE` file. This is the initialization logic for the [prebuilt -buildtools](/~https://github.com/keith/buildifier-prebuilt). If you would prefer to build the -[buildtools](/~https://github.com/bazelbuild/buildtools) from source, check out the [build_buildtools -example](/examples/bzlformat/build_buildtools) +buildtools](/~https://github.com/keith/buildifier-prebuilt). ```python load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps") diff --git a/bzlformat/tools/BUILD.bazel b/bzlformat/tools/BUILD.bazel index 496460b9..08de70ee 100644 --- a/bzlformat/tools/BUILD.bazel +++ b/bzlformat/tools/BUILD.bazel @@ -5,7 +5,7 @@ load("//bzlformat:defs.bzl", "bzlformat_pkg") sh_binary( name = "buildifier", srcs = ["buildifier.sh"], - data = ["@bazel_starlib_buildtools//:buildifier"], + data = ["@buildifier_prebuilt//buildifier"], visibility = ["//visibility:public"], deps = [ "//shlib/lib:arrays", diff --git a/bzlformat/tools/buildifier.sh b/bzlformat/tools/buildifier.sh index 35b4ab01..f264cc3d 100755 --- a/bzlformat/tools/buildifier.sh +++ b/bzlformat/tools/buildifier.sh @@ -23,7 +23,7 @@ arrays_sh="$(rlocation "${arrays_sh_location}")" || \ (echo >&2 "Failed to locate ${arrays_sh_location}" && exit 1) source "${arrays_sh}" -buildifier_location=bazel_starlib_buildtools/buildifier +buildifier_location=buildifier_prebuilt/buildifier/buildifier buildifier="$(rlocation "${buildifier_location}")" || \ (echo >&2 "Failed to locate ${buildifier_location}" && exit 1) diff --git a/bzlformat/tools/missing_pkgs/BUILD.bazel b/bzlformat/tools/missing_pkgs/BUILD.bazel index 06a83870..0aa16f13 100644 --- a/bzlformat/tools/missing_pkgs/BUILD.bazel +++ b/bzlformat/tools/missing_pkgs/BUILD.bazel @@ -28,7 +28,7 @@ sh_binary( srcs = ["fix.sh"], data = [ ":find", - "@bazel_starlib_buildtools//:buildozer", + "@buildifier_prebuilt//buildozer", ], visibility = ["//visibility:public"], deps = [ diff --git a/bzlformat/tools/missing_pkgs/fix.sh b/bzlformat/tools/missing_pkgs/fix.sh index 6be26d40..de10cedb 100755 --- a/bzlformat/tools/missing_pkgs/fix.sh +++ b/bzlformat/tools/missing_pkgs/fix.sh @@ -23,7 +23,7 @@ source "${common_sh}" find_missing_pkgs_bin="$(rlocation cgrindel_bazel_starlib/bzlformat/tools/missing_pkgs/find.sh)" -buildozer_location=bazel_starlib_buildtools/buildozer +buildozer_location=buildifier_prebuilt/buildozer/buildozer buildozer="$(rlocation "${buildozer_location}")" || \ (echo >&2 "Failed to locate ${buildozer_location}" && exit 1) diff --git a/deps.bzl b/deps.bzl index 4124fcbe..e3059ce9 100644 --- a/deps.bzl +++ b/deps.bzl @@ -2,7 +2,6 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load(":bazel_starlib_buildtools.bzl", "bazel_starlib_buildtools") def _bazeldoc_dependencies(): maybe( @@ -26,53 +25,8 @@ def _prebuilt_buildtools_dependencies(): ], ) - bazel_starlib_buildtools( - name = "bazel_starlib_buildtools", - buildozer_target = "@buildifier_prebuilt//buildozer", - buildozer_location = "buildifier_prebuilt/buildozer/buildozer", - buildifier_target = "@buildifier_prebuilt//buildifier", - buildifier_location = "buildifier_prebuilt/buildifier/buildifier", - ) - -def _compile_from_source_buildtools_dependencies(): - maybe( - http_archive, - name = "com_google_protobuf", - sha256 = "930c2c3b5ecc6c9c12615cf5ad93f1cd6e12d0aba862b572e076259970ac3a53", - strip_prefix = "protobuf-3.21.12", - urls = [ - "/~https://github.com/protocolbuffers/protobuf/archive/v3.21.12.tar.gz", - ], - ) - - maybe( - http_archive, - name = "com_github_bazelbuild_buildtools", - sha256 = "ca524d4df8c91838b9e80543832cf54d945e8045f6a2b9db1a1d02eec20e8b8c", - strip_prefix = "buildtools-6.0.1", - urls = [ - "/~https://github.com/bazelbuild/buildtools/archive/refs/tags/6.0.1.tar.gz", - ], - ) - - bazel_starlib_buildtools( - name = "bazel_starlib_buildtools", - buildozer_target = "@com_github_bazelbuild_buildtools//buildozer", - buildozer_location = "com_github_bazelbuild_buildtools/buildozer/buildozer_/buildozer", - buildifier_target = "@com_github_bazelbuild_buildtools//buildifier", - buildifier_location = "com_github_bazelbuild_buildtools/buildifier/buildifier_/buildifier", - ) - -def bazel_starlib_dependencies( - use_prebuilt_buildtools = True, - use_bazeldoc = True): +def bazel_starlib_dependencies(): """Declares the dependencies for bazel-starlib. - - Args: - use_prebuilt_buildtools: A `bool` specifying whether to use a prebuilt - version of `bazelbuild/buildtools`. - use_bazeldoc: A `bool` specifying whether the `bazeldoc` dependencies - should be loaded. """ maybe( @@ -105,10 +59,5 @@ def bazel_starlib_dependencies( ], ) - if use_bazeldoc: - _bazeldoc_dependencies() - - if use_prebuilt_buildtools: - _prebuilt_buildtools_dependencies() - else: - _compile_from_source_buildtools_dependencies() + _bazeldoc_dependencies() + _prebuilt_buildtools_dependencies() diff --git a/doc/shlib/BUILD.bazel b/doc/shlib/BUILD.bazel index e9dc092e..064acdb2 100644 --- a/doc/shlib/BUILD.bazel +++ b/doc/shlib/BUILD.bazel @@ -18,7 +18,6 @@ filegroup( # MARK: - Documentation Providers _RULE_NAMES = [ - "binary_pkg", "execute_binary", ] diff --git a/doc/shlib/binary_pkg.md b/doc/shlib/binary_pkg.md deleted file mode 100755 index 34daf713..00000000 --- a/doc/shlib/binary_pkg.md +++ /dev/null @@ -1,26 +0,0 @@ - -# `binary_pkg` Rule - - - - -## binary_pkg - -
-binary_pkg(name, binary)
-
- -Generates an executable script that includes the specified binary and all of its runtime dependencies. - -This rule was created to mitigate issues with runtime (i.e., runfiles) not being propagated properly in certain situations. For instance, if an `execute_binary` embeds another `execute_binary` and the first `execute_binary` is used in an `sh_test`, the dependencies for second `execute_binary` can be lost. - - -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| binary | The binary to be executed. | Label | required | | - - diff --git a/doc/shlib/rules.md b/doc/shlib/rules.md index 7c1e9f5f..be384032 100755 --- a/doc/shlib/rules.md +++ b/doc/shlib/rules.md @@ -3,6 +3,5 @@ The rules listed below are available in this repository. - * [binary_pkg](/doc/shlib/binary_pkg.md) * [execute_binary](/doc/shlib/execute_binary.md) diff --git a/examples/bzlformat/BUILD.bazel b/examples/bzlformat/BUILD.bazel index f0d1b39b..8dcce61a 100644 --- a/examples/bzlformat/BUILD.bazel +++ b/examples/bzlformat/BUILD.bazel @@ -1,8 +1,6 @@ load( "@contrib_rules_bazel_integration_test//bazel_integration_test:defs.bzl", - "bazel_integration_test", "bazel_integration_tests", - "default_test_runner", "integration_test_utils", ) load("//:bazel_versions.bzl", "CURRENT_BAZEL_VERSION", "SUPPORTED_BAZEL_VERSIONS") @@ -15,7 +13,6 @@ filegroup( srcs = glob(["*.md"]) + [ # The child workspaces do not appear as packages in the parent workspace. # Hence, we reference the relevant doc files as files, not a target. - "build_buildtools/README.md", "simple/README.md", ], visibility = ["//:markdown_test_visibility"], @@ -31,7 +28,7 @@ sh_binary( "@contrib_rules_bazel_integration_test//tools:create_scratch_dir", # NOTE: The test runnder does not use buildozer. However, the child # workspace does not find it properly if we don't specify it here. - "@bazel_starlib_buildtools//:buildozer", + "@buildifier_prebuilt//buildozer", ], deps = [ "//shlib/lib:assertions", @@ -52,26 +49,6 @@ bazel_integration_tests( workspace_path = "simple", ) -default_test_runner( - name = "build_buildtools_test_runner", - bazel_cmds = [ - "info", - "test //...", - "run //:bzlformat_missing_pkgs_test", - ], -) - -bazel_integration_test( - name = "build_buildtools_test", - timeout = "eternal", - bazel_version = CURRENT_BAZEL_VERSION, - test_runner = ":build_buildtools_test_runner", - workspace_files = integration_test_utils.glob_workspace_files("build_buildtools") + [ - "//:workspace_integration_test_files", - ], - workspace_path = "build_buildtools", -) - test_suite( name = "smoke_integration_tests", tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS, @@ -90,8 +67,6 @@ test_suite( tests = integration_test_utils.bazel_integration_test_names( ":simple_test", SUPPORTED_BAZEL_VERSIONS, - ) + [ - ":build_buildtools_test", - ], + ), visibility = ["//:__subpackages__"], ) diff --git a/examples/bzlformat/README.md b/examples/bzlformat/README.md index 70f8c682..b8bdb8b6 100644 --- a/examples/bzlformat/README.md +++ b/examples/bzlformat/README.md @@ -2,5 +2,3 @@ - [Simple](simple/) - Demonstrates `bzlformat` using prebuilt buildtools (`buildifier`, `buildozer`). -- [Build Buildtools](build_buildtools/) - Demonstrates `bzlformat` building the buildtools - (`buildifier`, `buildozer`) from source. diff --git a/examples/bzlformat/build_buildtools/.bazelrc b/examples/bzlformat/build_buildtools/.bazelrc deleted file mode 100644 index cb4f7903..00000000 --- a/examples/bzlformat/build_buildtools/.bazelrc +++ /dev/null @@ -1,9 +0,0 @@ -# Import Shared settings -import %workspace%/../../../shared.bazelrc - -# Import CI settings. -import %workspace%/../../../ci.bazelrc - -# Try to import a local.rc file; typically, written by CI -try-import %workspace%/../../../local.bazelrc - diff --git a/examples/bzlformat/build_buildtools/BUILD.bazel b/examples/bzlformat/build_buildtools/BUILD.bazel deleted file mode 100644 index 098f56ed..00000000 --- a/examples/bzlformat/build_buildtools/BUILD.bazel +++ /dev/null @@ -1,37 +0,0 @@ -load( - "@cgrindel_bazel_starlib//bzlformat:defs.bzl", - "bzlformat_missing_pkgs", - "bzlformat_pkg", -) -load( - "@cgrindel_bazel_starlib//updatesrc:defs.bzl", - "updatesrc_update_all", -) - -# Ensures that the Starlark files in this package are formatted properly. -bzlformat_pkg( - name = "bzlformat", -) - -# Provides targets to find, test, and fix any Bazel packages that are missing bzlformat_pkg -# declarations. -# -# bzlformat_missing_pkgs_find: Find and report any Bazel packages that missing the bzlformat_pkg -# declaration. -# bzlformat_missing_pkgs_test: Like find except it fails if any missing packages are found. This is -# useful to run in CI tests to ensure that all is well. -# bzlformat_missing_pkgs_fix: Adds bzlformat_pkg declarations to any packages that are missing -# the declaration. -bzlformat_missing_pkgs( - name = "bzlformat_missing_pkgs", -) - -# Define a runnable target to execute all of the updatesrc_update targets -# that are defined in your workspace. -updatesrc_update_all( - name = "update_all", - targets_to_run = [ - # Fix the Bazel packages when we update our source files from build outputs. - ":bzlformat_missing_pkgs_fix", - ], -) diff --git a/examples/bzlformat/build_buildtools/README.md b/examples/bzlformat/build_buildtools/README.md deleted file mode 100644 index d770c13d..00000000 --- a/examples/bzlformat/build_buildtools/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# Build Buildtools from Source Example - -Demonstrates how to use `bzlformat` building the -[bazelbuild/buildtools](/~https://github.com/bazelbuild/buildtools) from source. - -## Overview - -In the `WORKSPACE` file be sure to specify that you do not want to use the prebuilt tools. - -```pytyhon -bazel_starlib_dependencies(use_prebuilt_buildtools = False) -``` - -Then, add the initialization code for the [buildtools](/~https://github.com/bazelbuild/buildtools). - -```python -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") - -go_rules_dependencies() - -go_register_toolchains(version = "1.19.1") - -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") - -gazelle_dependencies() - -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") - -protobuf_deps() -``` - - diff --git a/examples/bzlformat/build_buildtools/WORKSPACE b/examples/bzlformat/build_buildtools/WORKSPACE deleted file mode 100644 index 584b02b2..00000000 --- a/examples/bzlformat/build_buildtools/WORKSPACE +++ /dev/null @@ -1,34 +0,0 @@ -workspace(name = "build_buildtools_example") - -local_repository( - name = "cgrindel_bazel_starlib", - path = "../../..", -) - -load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies") - -# Be sure to specify that you do not want to use the prebuilt tools -bazel_starlib_dependencies( - use_bazeldoc = False, - use_prebuilt_buildtools = False, -) - -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") - -bazel_skylib_workspace() - -# Buildtools Dependencies - -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") - -go_rules_dependencies() - -go_register_toolchains(version = "1.19.1") - -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") - -gazelle_dependencies() - -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") - -protobuf_deps() diff --git a/examples/bzlformat/simple/MODULE.bazel b/examples/bzlformat/simple/MODULE.bazel new file mode 100644 index 00000000..f84a849d --- /dev/null +++ b/examples/bzlformat/simple/MODULE.bazel @@ -0,0 +1,7 @@ +bazel_dep(name = "cgrindel_bazel_starlib") +local_path_override( + module_name = "cgrindel_bazel_starlib", + path = "../../..", +) + +bazel_dep(name = "bazel_skylib", version = "1.4.1") diff --git a/examples/bzlformat/simple/WORKSPACE b/examples/bzlformat/simple/WORKSPACE index f8bc57e2..94760cdd 100644 --- a/examples/bzlformat/simple/WORKSPACE +++ b/examples/bzlformat/simple/WORKSPACE @@ -7,7 +7,7 @@ local_repository( load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies") -bazel_starlib_dependencies(use_bazeldoc = False) +bazel_starlib_dependencies() load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") diff --git a/examples/markdown/simple/MODULE.bazel b/examples/markdown/simple/MODULE.bazel new file mode 100644 index 00000000..f84a849d --- /dev/null +++ b/examples/markdown/simple/MODULE.bazel @@ -0,0 +1,7 @@ +bazel_dep(name = "cgrindel_bazel_starlib") +local_path_override( + module_name = "cgrindel_bazel_starlib", + path = "../../..", +) + +bazel_dep(name = "bazel_skylib", version = "1.4.1") diff --git a/examples/markdown/simple/WORKSPACE b/examples/markdown/simple/WORKSPACE index cfc02836..2a34045e 100644 --- a/examples/markdown/simple/WORKSPACE +++ b/examples/markdown/simple/WORKSPACE @@ -7,7 +7,7 @@ local_repository( load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies") -bazel_starlib_dependencies(use_bazeldoc = False) +bazel_starlib_dependencies() load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") diff --git a/examples/updatesrc/simple/.bazelrc b/examples/updatesrc/simple/.bazelrc index cb4f7903..63ab7f51 100644 --- a/examples/updatesrc/simple/.bazelrc +++ b/examples/updatesrc/simple/.bazelrc @@ -6,4 +6,3 @@ import %workspace%/../../../ci.bazelrc # Try to import a local.rc file; typically, written by CI try-import %workspace%/../../../local.bazelrc - diff --git a/examples/updatesrc/simple/MODULE.bazel b/examples/updatesrc/simple/MODULE.bazel new file mode 100644 index 00000000..f84a849d --- /dev/null +++ b/examples/updatesrc/simple/MODULE.bazel @@ -0,0 +1,7 @@ +bazel_dep(name = "cgrindel_bazel_starlib") +local_path_override( + module_name = "cgrindel_bazel_starlib", + path = "../../..", +) + +bazel_dep(name = "bazel_skylib", version = "1.4.1") diff --git a/examples/updatesrc/simple/WORKSPACE b/examples/updatesrc/simple/WORKSPACE index b6866d1e..b5b6817f 100644 --- a/examples/updatesrc/simple/WORKSPACE +++ b/examples/updatesrc/simple/WORKSPACE @@ -7,7 +7,7 @@ local_repository( load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies") -bazel_starlib_dependencies(use_bazeldoc = False) +bazel_starlib_dependencies() load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") diff --git a/go_deps.bzl b/go_deps.bzl index 771879bf..2b2c53f0 100644 --- a/go_deps.bzl +++ b/go_deps.bzl @@ -4,6 +4,9 @@ bazel-starlib repository. load("@bazel_gazelle//:deps.bzl", "go_repository") +# NOTE: The go_repository declarations must be kept in sync with the go_deps.module() declarations +# in MODULE.bazel. + def bazel_starlib_go_dependencies(): """Specifies the Golang dependencies for the bazel-starlib repository.""" go_repository( diff --git a/shared.bazelrc b/shared.bazelrc index d0eddb8e..e36ad3dc 100644 --- a/shared.bazelrc +++ b/shared.bazelrc @@ -6,3 +6,6 @@ build --incompatible_strict_action_env=true # Don't allow empty glob patterns by default build --incompatible_disallow_empty_glob + +# GH195: Do not use bzlmod until stardoc supports repo mappings +common --noenable_bzlmod diff --git a/shlib/rules/BUILD.bazel b/shlib/rules/BUILD.bazel index 5a68b48d..60cf7cb8 100644 --- a/shlib/rules/BUILD.bazel +++ b/shlib/rules/BUILD.bazel @@ -5,14 +5,6 @@ package(default_visibility = ["//visibility:public"]) bzlformat_pkg(name = "bzlformat") -bzl_library( - name = "binary_pkg", - srcs = ["binary_pkg.bzl"], - deps = [ - "//shlib/rules/private:binary_pkg", - ], -) - bzl_library( name = "execute_binary", srcs = ["execute_binary.bzl"], diff --git a/shlib/rules/binary_pkg.bzl b/shlib/rules/binary_pkg.bzl deleted file mode 100644 index c6d4186f..00000000 --- a/shlib/rules/binary_pkg.bzl +++ /dev/null @@ -1,5 +0,0 @@ -"""Public API for binary_pkg""" - -load("//shlib/rules/private:binary_pkg.bzl", _binary_pkg = "binary_pkg") - -binary_pkg = _binary_pkg diff --git a/shlib/rules/private/BUILD.bazel b/shlib/rules/private/BUILD.bazel index 9f848ae5..324cf7eb 100644 --- a/shlib/rules/private/BUILD.bazel +++ b/shlib/rules/private/BUILD.bazel @@ -23,14 +23,6 @@ bzl_library( ], ) -bzl_library( - name = "binary_pkg", - srcs = ["binary_pkg.bzl"], - deps = [ - "@bazel_skylib//lib:paths", - ], -) - # MARK: - Collect Files for Integation Tests filegroup( diff --git a/shlib/rules/private/binary_pkg.bzl b/shlib/rules/private/binary_pkg.bzl deleted file mode 100644 index 5cbb1ab4..00000000 --- a/shlib/rules/private/binary_pkg.bzl +++ /dev/null @@ -1,150 +0,0 @@ -"""Definition for binary_pkg rule.""" - -load("@bazel_skylib//lib:paths.bzl", "paths") - -# Lovingly inspired by https://www.linuxjournal.com/node/1005818. - -_EXTERNAL_PREFIX = "external/" -_EXTERNAL_PREFIX_LEN = len(_EXTERNAL_PREFIX) - -def _copy_to_compress_dir(ctx, compress_dir_name, file): - # Depending upon the type of file, we may copy it to multiple locations - dest_paths = [] - if file.path.startswith(_EXTERNAL_PREFIX): - dest_paths.extend([ - # Copy to the /external/ - paths.join(compress_dir_name, ctx.workspace_name, file.path), - # Copy to the - # This is needed to mimic runfiles.bash expectations. - paths.join(compress_dir_name, file.path[_EXTERNAL_PREFIX_LEN:]), - ]) - else: - dest_paths.append( - paths.join(compress_dir_name, ctx.workspace_name, file.short_path), - ) - - # Declare destination files - destinations = [ - ctx.actions.declare_file(path) - for path in dest_paths - ] - - for dest in destinations: - cp_args = ctx.actions.args() - cp_args.add_all([file, dest]) - ctx.actions.run_shell( - outputs = [dest], - inputs = [file], - arguments = [cp_args], - command = """\ -src="${1}" -dest="${2}" -mkdir -p "$(dirname "${src}")" -cp "${src}" "${dest}" -""", - ) - - return destinations - -def _binary_pkg_impl(ctx): - dest_files = [] - compress_dir_name = ctx.label.name + "_compress" - - # Make sure that something exists in the compress dir - placeholder_out = ctx.actions.declare_file( - paths.join(compress_dir_name, "placeholder"), - ) - dest_files.append(placeholder_out) - ctx.actions.write( - output = placeholder_out, - content = "# Intentionally blank", - ) - compress_dir_path = paths.dirname(placeholder_out.path) - - # Copy the binary to the compress dir - binary_dests = _copy_to_compress_dir(ctx, compress_dir_name, ctx.executable.binary) - binary_dest = binary_dests[0] - dest_files.append(binary_dest) - compress_dir_prefix_len = len(compress_dir_path) + 1 - binary_path = binary_dest.path[compress_dir_prefix_len:] - - # Copy the runfiles for the binary. - for file in ctx.attr.binary[DefaultInfo].default_runfiles.files.to_list(): - dests = _copy_to_compress_dir(ctx, compress_dir_name, file) - dest_files.extend(dests) - - # Create an archive file with the binary and the runfiles - archive_out = ctx.actions.declare_file(ctx.label.name + "_archive.tar.gz") - archive_args = ctx.actions.args() - archive_args.add(archive_out) - archive_args.add(compress_dir_path) - ctx.actions.run_shell( - outputs = [archive_out], - inputs = dest_files, - arguments = [archive_args], - command = """\ -archive="${1}" -src_dir="${2}" -compress_dir="$(basename "${src_dir}")_clean" -mkdir -p "${compress_dir}" -cp -R -L "${src_dir}"/* "${compress_dir}" -tar -czf ${archive} -C "${compress_dir}" . -""", - ) - - # Create the decompression script - decompress_out = ctx.actions.declare_file(ctx.label.name + "_decompress.sh") - ctx.actions.expand_template( - output = decompress_out, - template = ctx.file._decompress_template, - substitutions = { - "{{EXEC_BINARY}}": binary_path, - # This is a relative path that will be appended to the tmp dir - # where the executable will be run. This is not RUNFILES_DIR. - "{{RUN_DIR}}": ctx.workspace_name, - }, - is_executable = True, - ) - - # Construct the final output by concatenating the decompression script with the archive. - bin_pkg_out = ctx.actions.declare_file(ctx.label.name + ".sh") - cat_args = ctx.actions.args() - cat_args.add_all([bin_pkg_out, decompress_out, archive_out]) - ctx.actions.run_shell( - outputs = [bin_pkg_out], - inputs = [decompress_out, archive_out], - arguments = [cat_args], - command = """\ -output="${1}" -shift 1 -cat "${@}" > "${output}" -""", - ) - - return [DefaultInfo(executable = bin_pkg_out)] - -binary_pkg = rule( - implementation = _binary_pkg_impl, - executable = True, - attrs = { - "binary": attr.label( - executable = True, - mandatory = True, - cfg = "target", - doc = "The binary to be executed.", - ), - "_decompress_template": attr.label( - allow_single_file = True, - default = "@cgrindel_bazel_starlib//shlib/rules/private:decompress.sh.tmpl", - ), - }, - doc = """\ -Generates an executable script that includes the specified binary and all of its runtime \ -dependencies. - -This rule was created to mitigate issues with runtime (i.e., runfiles) not being propagated \ -properly in certain situations. For instance, if an `execute_binary` embeds another \ -`execute_binary` and the first `execute_binary` is used in an `sh_test`, the dependencies \ -for second `execute_binary` can be lost. -""", -) diff --git a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/BUILD.bazel b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/BUILD.bazel index 9873ce97..8443ce76 100644 --- a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/BUILD.bazel +++ b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/BUILD.bazel @@ -15,7 +15,7 @@ sh_binary( testonly = True, srcs = ["missing_pkgs_test.sh"], data = [ - "@bazel_starlib_buildtools//:buildozer", + "@buildifier_prebuilt//buildozer", "@contrib_rules_bazel_integration_test//tools:create_scratch_dir", ], deps = [ diff --git a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/missing_pkgs_test.sh b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/missing_pkgs_test.sh index 65a0454e..39d38983 100755 --- a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/missing_pkgs_test.sh +++ b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/missing_pkgs_test.sh @@ -26,7 +26,7 @@ messages_sh="$(rlocation "${messages_sh_location}")" || \ (echo >&2 "Failed to locate ${messages_sh_location}" && exit 1) source "${messages_sh}" -buildozer_location=bazel_starlib_buildtools/buildozer +buildozer_location=buildifier_prebuilt/buildozer/buildozer buildozer="$(rlocation "${buildozer_location}")" || \ (echo >&2 "Failed to locate ${buildozer_location}" && exit 1) diff --git a/tests/shlib_tests/rules_tests/binary_pkg_tests/BUILD.bazel b/tests/shlib_tests/rules_tests/binary_pkg_tests/BUILD.bazel deleted file mode 100644 index f38fe0bd..00000000 --- a/tests/shlib_tests/rules_tests/binary_pkg_tests/BUILD.bazel +++ /dev/null @@ -1,128 +0,0 @@ -load("@bazel_skylib//rules:write_file.bzl", "write_file") -load("//bzlformat:defs.bzl", "bzlformat_pkg") -load("//shlib/rules:binary_pkg.bzl", "binary_pkg") -load("//shlib/rules:execute_binary.bzl", "execute_binary", "file_placeholder") - -bzlformat_pkg(name = "bzlformat") - -# MARK: - Hello World - -sh_binary( - name = "hello_world", - srcs = ["hello_world.sh"], -) - -binary_pkg( - name = "hello_world_pkg", - binary = ":hello_world", -) - -sh_test( - name = "hello_world_pkg_test", - srcs = ["hello_world_pkg_test.sh"], - data = [ - ":hello_world_pkg", - ], - deps = [ - "//shlib/lib:assertions", - "@bazel_tools//tools/bash/runfiles", - ], -) - -# MARK: - Binary with Data Files - -write_file( - name = "data_file", - out = "data_file.txt", - content = [ - "This is a data file.", - ], -) - -sh_binary( - name = "process_file", - srcs = ["process_file.sh"], - data = [ - ":data_file", - ], - deps = [ - "@bazel_tools//tools/bash/runfiles", - ], -) - -binary_pkg( - name = "process_file_pkg", - binary = ":process_file", -) - -sh_test( - name = "process_file_pkg_test", - srcs = ["process_file_pkg_test.sh"], - data = [ - ":process_file_pkg", - ], - deps = [ - "//shlib/lib:assertions", - "@bazel_tools//tools/bash/runfiles", - ], -) - -# MARK: - Test execute_binary embedded - -write_file( - name = "arg_file", - out = "arg_file.txt", - content = [ - "This is an arg file.", - ], -) - -execute_binary( - name = "exec_process_file", - arguments = [ - "--file", - file_placeholder("arg_file"), - ], - binary = ":process_file", - file_arguments = { - ":arg_file": "arg_file", - }, -) - -binary_pkg( - name = "exec_process_file_pkg", - binary = ":exec_process_file", -) - -sh_binary( - name = "process_file_consumer", - srcs = ["process_file_consumer.sh"], - deps = [ - "//shlib/lib:fail", - "@bazel_tools//tools/bash/runfiles", - ], -) - -execute_binary( - name = "process_file_consumer_eb", - arguments = [ - "--process_file", - file_placeholder("process_file"), - ], - binary = ":process_file_consumer", - file_arguments = { - ":exec_process_file_pkg": "process_file", - }, -) - -sh_test( - name = "process_file_consumer_eb_test", - srcs = ["process_file_consumer_eb_test.sh"], - data = [ - ":process_file_consumer_eb", - ], - deps = [ - "//shlib/lib:assertions", - "@bazel_tools//tools/bash/runfiles", - ], -) diff --git a/tests/shlib_tests/rules_tests/binary_pkg_tests/hello_world.sh b/tests/shlib_tests/rules_tests/binary_pkg_tests/hello_world.sh deleted file mode 100755 index 54828dbd..00000000 --- a/tests/shlib_tests/rules_tests/binary_pkg_tests/hello_world.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -echo "Hello, World!" -echo "Args Count: ${#}" -for (( i = 1; i <= ${#}; i++ )); do - echo "Arg ${i}: ${!i}" -done diff --git a/tests/shlib_tests/rules_tests/binary_pkg_tests/hello_world_pkg_test.sh b/tests/shlib_tests/rules_tests/binary_pkg_tests/hello_world_pkg_test.sh deleted file mode 100755 index 4bc1f7b9..00000000 --- a/tests/shlib_tests/rules_tests/binary_pkg_tests/hello_world_pkg_test.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash - -# --- begin runfiles.bash initialization v2 --- -# Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash -source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ - source "$0.runfiles/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e -# --- end runfiles.bash initialization v2 --- - -assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ - (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) -source "${assertions_sh}" - -hello_world_pkg_sh_location=cgrindel_bazel_starlib/tests/shlib_tests/rules_tests/binary_pkg_tests/hello_world_pkg.sh -hello_world_pkg_sh="$(rlocation "${hello_world_pkg_sh_location}")" || \ - (echo >&2 "Failed to locate ${hello_world_pkg_sh_location}" && exit 1) - -# MARK - No Args - -output="$("${hello_world_pkg_sh}")" -assert_match "Hello, World!" "${output}" -assert_match "Args Count: 0" "${output}" - -# MARK - With Args - -output="$("${hello_world_pkg_sh}" chicken smidgen)" -assert_match "Hello, World!" "${output}" -assert_match "Args Count: 2" "${output}" -assert_match "Arg 1: chicken" "${output}" -assert_match "Arg 2: smidgen" "${output}" diff --git a/tests/shlib_tests/rules_tests/binary_pkg_tests/process_file.sh b/tests/shlib_tests/rules_tests/binary_pkg_tests/process_file.sh deleted file mode 100755 index 438a9318..00000000 --- a/tests/shlib_tests/rules_tests/binary_pkg_tests/process_file.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash - -# --- begin runfiles.bash initialization v2 --- -# Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash -source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ - source "$0.runfiles/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e -# --- end runfiles.bash initialization v2 --- - -# MARK - Locate Deps - -data_file_txt_location=cgrindel_bazel_starlib/tests/shlib_tests/rules_tests/binary_pkg_tests/data_file.txt -data_file_txt="$(rlocation "${data_file_txt_location}")" || \ - (echo >&2 "Failed to locate ${data_file_txt_location}" && exit 1) - -args=() -while (("$#")); do - case "${1}" in - "--file") - arg_file="${2}" - shift 2 - ;; - *) - args+=("${1}") - shift 1 - ;; - esac -done - - -data="$(< "${data_file_txt}")" -echo "Data: ${data}" - -if [[ ! -z "${arg_file:-}" ]]; then - arg_file_data="$(< "${arg_file}")" - echo "Arg File: ${arg_file_data}" -fi diff --git a/tests/shlib_tests/rules_tests/binary_pkg_tests/process_file_consumer.sh b/tests/shlib_tests/rules_tests/binary_pkg_tests/process_file_consumer.sh deleted file mode 100755 index fd4dd581..00000000 --- a/tests/shlib_tests/rules_tests/binary_pkg_tests/process_file_consumer.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash - -# --- begin runfiles.bash initialization v2 --- -# Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash -source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ - source "$0.runfiles/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e -# --- end runfiles.bash initialization v2 --- - -# MARK - Locate Deps - -fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ - (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) -source "${fail_sh}" - - -# MARK - Process Args - -args=() -while (("$#")); do - case "${1}" in - "--process_file") - process_file="${2}" - shift 2 - ;; - *) - args+=("${1}") - shift 1 - ;; - esac -done - -[[ -z "${process_file:-}" ]] && fail "Expected a process_file executable" - -"${process_file}" diff --git a/tests/shlib_tests/rules_tests/binary_pkg_tests/process_file_consumer_eb_test.sh b/tests/shlib_tests/rules_tests/binary_pkg_tests/process_file_consumer_eb_test.sh deleted file mode 100755 index de13fc25..00000000 --- a/tests/shlib_tests/rules_tests/binary_pkg_tests/process_file_consumer_eb_test.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash - -# --- begin runfiles.bash initialization v2 --- -# Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash -source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ - source "$0.runfiles/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e -# --- end runfiles.bash initialization v2 --- - -# MARK - Locate Deps - -assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ - (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) -source "${assertions_sh}" - -process_file_consumer_eb_sh_location=cgrindel_bazel_starlib/tests/shlib_tests/rules_tests/binary_pkg_tests/process_file_consumer_eb.sh -process_file_consumer_eb_sh="$(rlocation "${process_file_consumer_eb_sh_location}")" || \ - (echo >&2 "Failed to locate ${process_file_consumer_eb_sh_location}" && exit 1) - - -# MARK - Test - -output="$( "${process_file_consumer_eb_sh}" )" - -# Look for output from process_file.sh -assert_match "Data: This is a data file." "${output}" -assert_match "Arg File: This is an arg file." "${output}" diff --git a/tests/shlib_tests/rules_tests/binary_pkg_tests/process_file_pkg_test.sh b/tests/shlib_tests/rules_tests/binary_pkg_tests/process_file_pkg_test.sh deleted file mode 100755 index 30c9c840..00000000 --- a/tests/shlib_tests/rules_tests/binary_pkg_tests/process_file_pkg_test.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -# --- begin runfiles.bash initialization v2 --- -# Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash -source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ - source "$0.runfiles/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e -# --- end runfiles.bash initialization v2 --- - -assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ - (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) -source "${assertions_sh}" - -process_file_pkg_sh_location=cgrindel_bazel_starlib/tests/shlib_tests/rules_tests/binary_pkg_tests/process_file_pkg.sh -process_file_pkg_sh="$(rlocation "${process_file_pkg_sh_location}")" || \ - (echo >&2 "Failed to locate ${process_file_pkg_sh_location}" && exit 1) - -# MARK - Test - -output="$("${process_file_pkg_sh}")" -assert_match "Data: This is a data file." "${output}" diff --git a/updatesrc/BUILD.bazel b/updatesrc/BUILD.bazel index 937a8048..44aaa112 100644 --- a/updatesrc/BUILD.bazel +++ b/updatesrc/BUILD.bazel @@ -16,6 +16,7 @@ bzl_library( srcs = ["defs.bzl"], deps = [ "//updatesrc/private:providers", + "//updatesrc/private:update_srcs", "//updatesrc/private:updatesrc_diff_and_update", "//updatesrc/private:updatesrc_update", "//updatesrc/private:updatesrc_update_all",