Skip to content

Commit

Permalink
Don't need consistent_label_str anymore now that we no longer support…
Browse files Browse the repository at this point in the history
… Bazel 5
  • Loading branch information
gregmagolan committed Apr 3, 2024
1 parent d4dde37 commit 49e60ef
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# @generated
# Input hashes for repository rule npm_translate_lock(name = "npm", pnpm_lock = "@@//:pnpm-lock.yaml").
# This file should be checked into version control along with the pnpm-lock.yaml file.
.npmrc=-2065072158
pnpm-lock.yaml=1067049895
examples/npm_deps/patches/[email protected]=-442666336
package.json=-275319675
pnpm-workspace.yaml=-871530930
examples/js_binary/package.json=-41174383
examples/macro/package.json=857146175
examples/npm_deps/package.json=283109008
examples/npm_package/libs/lib_a/package.json=-1377103079
examples/npm_package/packages/pkg_a/package.json=-1053875011
examples/npm_package/packages/pkg_b/package.json=-994654274
examples/webpack_cli/package.json=1911342006
js/private/coverage/bundle/package.json=-1543718929
js/private/worker/src/package.json=1608383745
npm/private/test/package.json=1756993924
npm/private/test/vendored/lodash-4.17.21.tgz=-1206623349
npm/private/test/npm_package/package.json=-1991705133
npm/private/test/vendored/is-odd/package.json=1041695223
npm/private/test/vendored/semver-max/package.json=578664053
examples/linked_empty_node_modules/package.json=-1039372825
js/private/image/package.json=-1260474848
js/private/test/image/package.json=1286417612
js/private/test/js_run_devserver/package.json=-260856079
7 changes: 3 additions & 4 deletions js/private/js_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ js_binary(
load("@aspect_bazel_lib//lib:windows_utils.bzl", "create_windows_native_launcher_script")
load("@aspect_bazel_lib//lib:expand_make_vars.bzl", "expand_locations", "expand_variables")
load("@aspect_bazel_lib//lib:directory_path.bzl", "DirectoryPathInfo")
load("@aspect_bazel_lib//lib:utils.bzl", "consistent_label_str")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "COPY_FILE_TO_BIN_TOOLCHAINS")
load("@bazel_skylib//lib:dicts.bzl", "dicts")
load(":js_helpers.bzl", "LOG_LEVELS", "envs_for_log_level", "gather_runfiles")
Expand Down Expand Up @@ -429,9 +428,9 @@ def _bash_launcher(ctx, node_toolchain, entry_point_path, log_prefix_rule_set, l
node_path = _target_tool_path_to_short_path(node_toolchain.nodeinfo.target_tool_path)

launcher_subst = {
"{{target_label}}": consistent_label_str(ctx, ctx.label),
"{{template_label}}": consistent_label_str(ctx, ctx.attr._launcher_template.label),
"{{entry_point_label}}": consistent_label_str(ctx, ctx.attr.entry_point.label),
"{{target_label}}": str(ctx, ctx.label),
"{{template_label}}": str(ctx, ctx.attr._launcher_template.label),
"{{entry_point_label}}": str(ctx, ctx.attr.entry_point.label),
"{{entry_point_path}}": entry_point_path,
"{{envs}}": "\n".join(envs),
"{{fixed_args}}": " ".join(fixed_args_expanded),
Expand Down
4 changes: 2 additions & 2 deletions npm/private/npm_translate_lock_generate.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ _RESOLVED_JSON_FILENAME = "resolved.json"
# buildifier: disable=function-docstring
def generate_repository_files(rctx, pnpm_lock_label, importers, packages, patched_dependencies, root_package, default_registry, npm_registries, npm_auth, link_workspace):
generated_by_lines = [
"\"\"\"@generated by npm_translate_lock(name = \"{}\", pnpm_lock = \"{}\")\"\"\"".format(helpers.to_apparent_repo_name(rctx.name), utils.consistent_label_str(pnpm_lock_label)),
"\"\"\"@generated by npm_translate_lock(name = \"{}\", pnpm_lock = \"{}\")\"\"\"".format(helpers.to_apparent_repo_name(rctx.name), str(pnpm_lock_label)),
"", # empty line after bzl docstring since buildifier expects this if this file is vendored in
]

Expand All @@ -94,7 +94,7 @@ def generate_repository_files(rctx, pnpm_lock_label, importers, packages, patche
repositories_bzl.append("""load("@aspect_rules_js//npm:repositories.bzl", "npm_import")""")
repositories_bzl.append("")

repositories_bzl.append("# Generated npm_import repository rules corresponding to npm packages in {}".format(utils.consistent_label_str(pnpm_lock_label)))
repositories_bzl.append("# Generated npm_import repository rules corresponding to npm packages in {}".format(str(pnpm_lock_label)))
repositories_bzl.append("# buildifier: disable=function-docstring")
repositories_bzl.append("def npm_repositories():")
if len(npm_imports) == 0:
Expand Down
4 changes: 2 additions & 2 deletions npm/private/npm_translate_lock_state.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def _init_update_labels(priv, rctx, label_store):

action_cache_path = paths.join(
priv["external_repository_action_cache"],
PNPM_LOCK_ACTION_CACHE_PREFIX + base64.encode(utils.hash(helpers.to_apparent_repo_name(rctx.name) + utils.consistent_label_str(label_store.label("pnpm_lock")))),
PNPM_LOCK_ACTION_CACHE_PREFIX + base64.encode(utils.hash(helpers.to_apparent_repo_name(rctx.name) + str(label_store.label("pnpm_lock")))),
)
label_store.add_root("action_cache", action_cache_path)
for i, d in enumerate(attr.preupdate):
Expand Down Expand Up @@ -408,7 +408,7 @@ def _action_cache_miss(priv, rctx, label_store):
def _write_action_cache(priv, rctx, label_store):
contents = [
"# @generated",
"# Input hashes for repository rule npm_translate_lock(name = \"{}\", pnpm_lock = \"{}\").".format(helpers.to_apparent_repo_name(rctx.name), utils.consistent_label_str(label_store.label("pnpm_lock"))),
"# Input hashes for repository rule npm_translate_lock(name = \"{}\", pnpm_lock = \"{}\").".format(helpers.to_apparent_repo_name(rctx.name), str(label_store.label("pnpm_lock"))),
"# This file should be checked into version control along with the pnpm-lock.yaml file.",
]
for key, value in priv["input_hashes"].items():
Expand Down
10 changes: 0 additions & 10 deletions npm/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,6 @@ def _dicts_match(a, b):
return False
return True

# Generate a consistent label string between Bazel versions.
def _consistent_label_str(label):
return "//{}:{}".format(
# Starting in Bazel 6, the workspace name is empty for the local workspace and there's no other way to determine it.
# This behavior differs from Bazel 5 where the local workspace name was fully qualified in str(label).
label.package,
label.name,
)

# Copies a file from the external repository to the same relative location in the source tree
def _reverse_force_copy(rctx, label, dst = None):
if type(label) != "Label":
Expand Down Expand Up @@ -473,7 +464,6 @@ utils = struct(
default_registry = _default_registry,
hash = _hash,
dicts_match = _dicts_match,
consistent_label_str = _consistent_label_str,
reverse_force_copy = _reverse_force_copy,
exists = _exists,
home_directory = _home_directory,
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 49e60ef

Please sign in to comment.