Skip to content

Commit

Permalink
Migrate to cgrindel/bazel_shlib (#5)
Browse files Browse the repository at this point in the history
Added dependency on cgrindel/bazel_shlib.
Replaced common.sh and its tests with the libraries from bazel_shlib.
  • Loading branch information
cgrindel authored Nov 17, 2021
1 parent b3bc2cd commit b7db6be
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 327 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ bzlformat_rules_dependencies()
load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies")

bazel_starlib_dependencies()

load("@cgrindel_bazel_shlib//:deps.bzl", "shlib_rules_dependencies")

shlib_rules_dependencies()
```

### 2. Create a `bazel_versions.bzl` in the root of your repository
Expand Down
6 changes: 6 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

# MARK: - bazel_shlib

load("@cgrindel_bazel_shlib//:deps.bzl", "shlib_rules_dependencies")

shlib_rules_dependencies()

# MARK: - Integration Tests

load("//:bazel_versions.bzl", "SUPPORTED_BAZEL_VERSIONS")
Expand Down
8 changes: 8 additions & 0 deletions bazel_integration_test/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ def bazel_integration_test_rules_dependencies():
strip_prefix = "bazel-integration-testing-3a6136e8f6287b04043217d94d97ba17edcb7feb",
sha256 = "bfc43a94d42e08c89a26a4711ea396a0a594bd5d55394d76aae861b299628dca",
)

maybe(
http_archive,
name = "cgrindel_bazel_shlib",
sha256 = "0f34e490950338894851c1427c9a2b783bcb699fcee8185b4d7c07e253923f67",
strip_prefix = "bazel_shlib-0.1.0",
urls = ["https://github.com/cgrindel/bazel_shlib/archive/v0.1.0.tar.gz"],
)
72 changes: 7 additions & 65 deletions tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ bzlformat_pkg(name = "bzlformat")

# MARK: - Binary Declarations

sh_library(
name = "common",
srcs = ["common.sh"],
)

sh_binary(
name = "find_child_workspace_packages",
srcs = ["find_child_workspace_packages.sh"],
visibility = ["//visibility:public"],
deps = [
":common",
"@bazel_tools//tools/bash/runfiles",
"@cgrindel_bazel_shlib//lib:arrays",
"@cgrindel_bazel_shlib//lib:files",
],
)

Expand All @@ -27,69 +23,15 @@ sh_binary(
],
visibility = ["//visibility:public"],
deps = [
":common",
"@bazel_tools//tools/bash/runfiles",
"@cgrindel_bazel_shlib//lib:arrays",
"@cgrindel_bazel_shlib//lib:files",
"@cgrindel_bazel_shlib//lib:paths",
],
)

# MARK: - Test Declarations

sh_library(
name = "assertions",
testonly = 1,
srcs = ["assertions.sh"],
)

sh_test(
name = "normalize_path_test",
srcs = ["normalize_path_test.sh"],
deps = [
":assertions",
":common",
"@bazel_tools//tools/bash/runfiles",
],
)

sh_test(
name = "upsearch_test",
srcs = ["upsearch_test.sh"],
deps = [
":assertions",
":common",
"@bazel_tools//tools/bash/runfiles",
],
)

sh_test(
name = "sort_items_test",
srcs = ["sort_items_test.sh"],
deps = [
":assertions",
":common",
"@bazel_tools//tools/bash/runfiles",
],
)

sh_test(
name = "print_by_line_test",
srcs = ["print_by_line_test.sh"],
deps = [
":assertions",
":common",
"@bazel_tools//tools/bash/runfiles",
],
)

sh_test(
name = "join_by_test",
srcs = ["join_by_test.sh"],
deps = [
":assertions",
":common",
"@bazel_tools//tools/bash/runfiles",
],
)

sh_library(
name = "setup_test_workspace",
testonly = 1,
Expand All @@ -103,9 +45,9 @@ sh_test(
":find_child_workspace_packages",
],
deps = [
":assertions",
":setup_test_workspace",
"@bazel_tools//tools/bash/runfiles",
"@cgrindel_bazel_shlib//lib:assertions",
],
)

Expand All @@ -116,8 +58,8 @@ sh_test(
":update_deleted_packages",
],
deps = [
":assertions",
":setup_test_workspace",
"@bazel_tools//tools/bash/runfiles",
"@cgrindel_bazel_shlib//lib:assertions",
],
)
16 changes: 0 additions & 16 deletions tools/assertions.sh

This file was deleted.

58 changes: 0 additions & 58 deletions tools/common.sh

This file was deleted.

22 changes: 6 additions & 16 deletions tools/find_child_workspace_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,14 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 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 || \
# Do not fail if this logic does not succeed. We are supporting being run
# outside of Bazel.
# { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
f=; set -e
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v2 ---

# Do not use helper functions as they have not been loaded yet
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null && pwd)"

# If we are being run via `bazel run` the rlocation function will exist and we
# will load the common functions using rlocation. Otherwise, we are being executed
# directly.
if [[ $(type -t rlocation) == function ]]; then
common_lib="$(rlocation cgrindel_rules_bazel_integration_test/tools/common.sh)"
else
common_lib="${script_dir}/common.sh"
fi
source "${common_lib}"
arrays_lib="$(rlocation cgrindel_bazel_shlib/lib/arrays.sh)"
source "${arrays_lib}"

files_lib="$(rlocation cgrindel_bazel_shlib/lib/files.sh)"
source "${files_lib}"

# MARK - Functions

Expand Down
2 changes: 1 addition & 1 deletion tools/find_child_workspace_packages_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v2 ---

assertions_lib="$(rlocation cgrindel_rules_bazel_integration_test/tools/assertions.sh)"
assertions_lib="$(rlocation cgrindel_bazel_shlib/lib/assertions.sh)"
source "${assertions_lib}"

find_bin="$(rlocation cgrindel_rules_bazel_integration_test/tools/find_child_workspace_packages.sh)"
Expand Down
27 changes: 0 additions & 27 deletions tools/join_by_test.sh

This file was deleted.

30 changes: 0 additions & 30 deletions tools/normalize_path_test.sh

This file was deleted.

30 changes: 0 additions & 30 deletions tools/print_by_line_test.sh

This file was deleted.

27 changes: 0 additions & 27 deletions tools/sort_items_test.sh

This file was deleted.

Loading

0 comments on commit b7db6be

Please sign in to comment.