Skip to content

Commit

Permalink
refactor: use utils struct from Aspect bazel-lib utils.bzl (#1608)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan authored and jbedard committed May 6, 2024
1 parent 9d496c0 commit a27a85f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
6 changes: 3 additions & 3 deletions js/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"Public API"

load("@aspect_bazel_lib//lib:utils.bzl", "is_bazel_7_or_greater")
load("@aspect_bazel_lib//lib:utils.bzl", bazel_lib_utils = "utils")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

exports_files(
Expand Down Expand Up @@ -47,7 +47,7 @@ bzl_library(
deps = [
"@bazel_tools//tools/build_defs/repo:http.bzl",
"@bazel_tools//tools/build_defs/repo:utils.bzl",
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if is_bazel_7_or_greater() else []),
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if bazel_lib_utils.is_bazel_7_or_greater() else []),
)

bzl_library(
Expand All @@ -57,5 +57,5 @@ bzl_library(
deps = [
"@bazel_tools//tools/build_defs/repo:http.bzl",
"@bazel_tools//tools/build_defs/repo:utils.bzl",
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if is_bazel_7_or_greater() else []),
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if bazel_lib_utils.is_bazel_7_or_greater() else []),
)
12 changes: 6 additions & 6 deletions js/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"Internal implementation details"

load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
load("@aspect_bazel_lib//lib:utils.bzl", "is_bazel_7_or_greater")
load("@aspect_bazel_lib//lib:utils.bzl", bazel_lib_utils = "utils")
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("//js:defs.bzl", "js_binary")
Expand All @@ -28,7 +28,7 @@ bzl_library(
],
deps = [
":js_helpers",
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if is_bazel_7_or_greater() else []),
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if bazel_lib_utils.is_bazel_7_or_greater() else []),
)

bzl_library(
Expand All @@ -47,7 +47,7 @@ bzl_library(
"@aspect_bazel_lib//lib:paths",
"@aspect_bazel_lib//lib:windows_utils",
"@bazel_skylib//lib:dicts",
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if is_bazel_7_or_greater() else []),
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if bazel_lib_utils.is_bazel_7_or_greater() else []),
)

bzl_library(
Expand Down Expand Up @@ -76,7 +76,7 @@ bzl_library(
":js_info",
"@aspect_bazel_lib//lib:copy_to_bin",
"@bazel_skylib//lib:dicts",
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if is_bazel_7_or_greater() else []),
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if bazel_lib_utils.is_bazel_7_or_greater() else []),
)

bzl_library(
Expand Down Expand Up @@ -107,7 +107,7 @@ bzl_library(
":js_binary",
":js_helpers",
"@bazel_skylib//lib:dicts",
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if is_bazel_7_or_greater() else []),
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if bazel_lib_utils.is_bazel_7_or_greater() else []),
)

bzl_library(
Expand All @@ -133,7 +133,7 @@ bzl_library(
"@aspect_bazel_lib//lib:paths",
"@aspect_bazel_lib//lib:utils",
"@bazel_skylib//lib:paths",
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if is_bazel_7_or_greater() else []),
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if bazel_lib_utils.is_bazel_7_or_greater() else []),
)

copy_to_bin(
Expand Down
4 changes: 2 additions & 2 deletions js/private/js_image_layer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ js_image_layer(
"""

load("@aspect_bazel_lib//lib:paths.bzl", "to_rlocation_path")
load("@aspect_bazel_lib//lib:utils.bzl", "is_bazel_6_or_greater")
load("@aspect_bazel_lib//lib:utils.bzl", bazel_lib_utils = "utils")
load("@bazel_skylib//lib:paths.bzl", "paths")

_DOC = """Create container image layers from js_binary targets.
Expand Down Expand Up @@ -217,7 +217,7 @@ def _build_layer(ctx, type, entries, inputs):
args.add(output)
args.add(ctx.attr.compression)
args.add(ctx.attr.owner)
if not is_bazel_6_or_greater():
if not bazel_lib_utils.is_bazel_6_or_greater():
args.add("true")

ctx.actions.run(
Expand Down
4 changes: 2 additions & 2 deletions js/private/js_run_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ load("@aspect_rules_js//js:defs.bzl", "js_run_binary")
"""

load("@aspect_bazel_lib//lib:run_binary.bzl", _run_binary = "run_binary")
load("@aspect_bazel_lib//lib:utils.bzl", "to_label")
load("@aspect_bazel_lib//lib:utils.bzl", bazel_lib_utils = "utils")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", _copy_to_bin = "copy_to_bin")
load("@bazel_skylib//lib:dicts.bzl", "dicts")
load(":js_helpers.bzl", _envs_for_log_level = "envs_for_log_level")
Expand Down Expand Up @@ -332,7 +332,7 @@ WARNING: {name} is not configured to produce outputs.
If this is a generated bin from package_json.bzl, consider using the *_binary or *_test variant instead.
See https://github.com/aspect-build/rules_js/tree/main/docs#using-binaries-published-to-npm
""".format(
name = to_label(name),
name = bazel_lib_utils.to_label(name),
))

# Configure run from execroot
Expand Down
4 changes: 2 additions & 2 deletions npm/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"Internal implementation details"

load("@aspect_bazel_lib//lib:testing.bzl", "assert_contains")
load("@aspect_bazel_lib//lib:utils.bzl", "is_bazel_7_or_greater")
load("@aspect_bazel_lib//lib:utils.bzl", bazel_lib_utils = "utils")
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

Expand Down Expand Up @@ -216,7 +216,7 @@ bzl_library(
"@aspect_bazel_lib//lib:repo_utils",
"@aspect_bazel_lib//lib:utils",
"@bazel_skylib//lib:types",
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if is_bazel_7_or_greater() else []),
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if bazel_lib_utils.is_bazel_7_or_greater() else []),
)

bzl_library(
Expand Down
5 changes: 2 additions & 3 deletions npm/private/repository_label_store.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ resolve the underlying issue in the future https://github.com/bazelbuild/bazel/i
"""

load("@bazel_skylib//lib:paths.bzl", "paths")
load("@aspect_bazel_lib//lib:utils.bzl", "is_bazel_6_or_greater")

################################################################################
def _make_sibling_label(sibling_label, path):
Expand All @@ -16,9 +15,9 @@ def _make_sibling_label(sibling_label, path):
dirname = paths.dirname(sibling_label.name)
if path.startswith("../"):
# we have no idea what package this sibling is in so just assume the root package which works for repository rules
return Label("{}{}//:{}".format("@@" if is_bazel_6_or_greater() else "@", sibling_label.workspace_name, paths.normalize(paths.join(sibling_label.package, dirname, path))))
return Label("@@{}//:{}".format(sibling_label.workspace_name, paths.normalize(paths.join(sibling_label.package, dirname, path))))
else:
return Label("{}{}//{}:{}".format("@@" if is_bazel_6_or_greater() else "@", sibling_label.workspace_name, sibling_label.package, paths.join(dirname, path)))
return Label("@@{}//{}:{}".format(sibling_label.workspace_name, sibling_label.package, paths.join(dirname, path)))

################################################################################
def _seed_root(priv, rctx_path, label):
Expand Down
4 changes: 2 additions & 2 deletions npm/private/utils.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"Utility functions for npm rules"

load("@aspect_bazel_lib//lib:utils.bzl", "is_bazel_6_or_greater")
load("@aspect_bazel_lib//lib:utils.bzl", bazel_lib_utils = "utils")
load("@aspect_bazel_lib//lib:paths.bzl", "relative_file")
load("@aspect_bazel_lib//lib:repo_utils.bzl", "repo_utils")
load("@bazel_skylib//lib:paths.bzl", "paths")
Expand Down Expand Up @@ -247,7 +247,7 @@ def _virtual_store_name(name, version):
return "%s@%s" % (escaped_name, escaped_version)

def _make_symlink(ctx, symlink_path, target_file):
if not is_bazel_6_or_greater():
if not bazel_lib_utils.is_bazel_6_or_greater():
# ctx.actions.declare_symlink was added in Bazel 6
fail("A minimum version of Bazel 6 required to use rules_js")
symlink = ctx.actions.declare_symlink(symlink_path)
Expand Down

0 comments on commit a27a85f

Please sign in to comment.