10000 fix: use Label.repo_name instead of Label.workspace_name (#2082) · aspect-build/rules_js@a365f47 · GitHub
[go: up one dir, main page]

Skip to content

Commit a365f47

Browse files
authored
fix: use Label.repo_name instead of Label.workspace_name (#2082)
According to the documentation, Label.workspace_name is deprecated: https://bazel.build/rules/lib/builtins/Label.html#workspace_name Label.repo_name behaves identically and is available in Bazel 6 and later.
1 parent 4488c9f commit a365f47

File tree

8 files changed

+26
-26
lines changed

8 files changed

+26
-26
lines changed

js/private/js_binary.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def _bash_launcher(ctx, nodeinfo, entry_point_path, log_prefix_rule_set, log_pre
376376
"JS_BINARY__PACKAGE": ctx.label.package,
377377
"JS_BINARY__TARGET_NAME": ctx.label.name,
378378
"JS_BINARY__TARGET": "{}//{}:{}".format(
379-
"@" + ctx.label.workspace_name if ctx.label.workspace_name else "",
379+
"@" + ctx.label.repo_name if ctx.label.repo_name else "",
380380
ctx.label.package,
381381
ctx.label.name,
382382
),

js/private/js_helpers.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def gather_npm_package_store_infos(targets):
7575
return depset(transitive = npm_package_store_infos)
7676

7777
def copy_js_file_to_bin_action(ctx, file):
78-
if ctx.label.workspace_name != file.owner.workspace_name or ctx.label.package != file.owner.package:
78+
if ctx.label.repo_name != file.owner.repo_name or ctx.label.package != file.owner.package:
7979
msg = """
8080
8181
Expected to find source file {file_basename} in '{this_package}', but instead it is in '{file_package}'.
@@ -101,9 +101,9 @@ this option is not needed.
101101
102102
""".format(
103103
file_basename = file.basename,
104-
file_package = "%s//%s" % (file.owner.workspace_name, file.owner.package),
104+
file_package = "%s//%s" % (file.owner.repo_name, file.owner.package),
105105
new_target_name = file.basename.replace(".", "_"),
106-
this_package = "%s//%s" % (ctx.label.workspace_name, ctx.label.package),
106+
this_package = "%s//%s" % (ctx.label.repo_name, ctx.label.package),
107107
this_target = ctx.label,
108108
)
109109
fail(msg)

js/private/js_image_layer.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def _build_layer(ctx, type, all_entries_json, entries, inputs):
310310
return output
311311

312312
def _select_layer(layers, destination, file):
313-
is_node = file.owner.workspace_name != "" and "/bin/nodejs/" in destination
313+
is_node = file.owner.repo_name != "" and "/bin/nodejs/" in destination
314314
is_js_patches = "/js/private/node-patches" in destination
315315
if is_node or is_js_patches:
316316
return layers.node
@@ -382,7 +382,7 @@ def _js_image_layer_impl(ctx):
382382
entry = {
383383
"dest": file.path,
384384
"root": file.root.path,
385-
"is_external": file.owner.workspace_name != "",
385+
"is_external": file.owner.repo_name != "",
386386
"is_source": file.is_source,
387387
"is_directory": file.is_directory,
388388
}

npm/extensions.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ WARNING: Cannot determine home directory in order to load home `.npmrc` file in
148148
lifecycle_hooks_execution_requirements = i.lifecycle_hooks_execution_requirements,
149149
lifecycle_hooks_use_default_shell_env = i.lifecycle_hooks_use_default_shell_env,
150150
link_packages = i.link_packages,
151-
# attr.pnpm_lock.workspace_name is a canonical repository name, so it needs to be qualified with an extra '@'.
152-
link_workspace = attr.link_workspace if attr.link_workspace else "@" + attr.pnpm_lock.workspace_name,
151+
# attr.pnpm_lock.repo_name is a canonical repository name, so it needs to be qualified with an extra '@'.
152+
link_workspace = attr.link_workspace if attr.link_workspace else "@" + attr.pnpm_lock.repo_name,
153153
npm_auth = i.npm_auth,
154154
npm_auth_basic = i.npm_auth_basic,
155155
npm_auth_password = i.npm_auth_password,

npm/private/npm_link_package_store.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ def _npm_link_package_store_impl(ctx):
6767
if not package_store_directory:
6868
fail("src must be a npm_link_package that provides a package_store_directory")
6969

70-
if package_store_directory.owner.workspace_name != ctx.label.workspace_name:
70+
if package_store_directory.owner.repo_name != ctx.label.repo_name:
7171
msg = "expected package_store_directory to be in the same workspace as the link target '{}' but found '{}'".format(
72-
ctx.label.workspace_name,
73-
package_store_directory.owner.workspace_name,
72+
ctx.label.repo_name,
73+
package_store_directory.owner.repo_name,
7474
)
7575
fail(msg)
7676

npm/private/npm_package_store.bzl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ def _npm_package_store_impl(ctx):
202202
npm_pkg_info = ctx.attr.src[NpmPackageInfo]
203203

204204
# output the package as a TreeArtifact to its package store location
205-
if ctx.label.workspace_name and ctx.label.package:
206-
expected_short_path = "../{}/{}/{}".format(ctx.label.workspace_name, ctx.label.package, package_store_directory_path)
207-
elif ctx.label.workspace_name:
208-
expected_short_path = "../{}/{}".format(ctx.label.workspace_name, package_store_directory_path)
205+
if ctx.label.repo_name and ctx.label.package:
206+
expected_short_path = "../{}/{}/{}".format(ctx.label.repo_name, ctx.label.package, package_store_directory_path)
207+
elif ctx.label.repo_name:
208+
expected_short_path = "../{}/{}".format(ctx.label.repo_name, package_store_directory_path)
209209
elif ctx.label.package:
210210
expected_short_path = "{}/{}".format(ctx.label.package, package_store_directory_path)
211211
else:
@@ -308,18 +308,18 @@ deps of npm_package_store must be in the same package.""" % (ctx.label.package,
308308
jsinfo = ctx.attr.src[JsInfo]
309309

310310
# Symlink to the directory of the target that created this JsInfo
311-
if ctx.label.workspace_name and ctx.label.package:
312-
symlink_path = "external/{}/{}/{}".format(ctx.label.workspace_name, ctx.label.package, package_store_directory_path)
313-
elif ctx.label.workspace_name:
314-
symlink_path = "external/{}/{}".format(ctx.label.workspace_name, package_store_directory_path)
311+
if ctx.label.repo_name and ctx.label.package:
312+
symlink_path = "external/{}/{}/{}".format(ctx.label.repo_name, ctx.label.package, package_store_directory_path)
313+
elif ctx.label.repo_name:
314+
symlink_path = "external/{}/{}".format(ctx.label.repo_name, package_store_directory_path)
315315
else:
316316
symlink_path = package_store_directory_path
317317

318318
# The package JsInfo including all direct and transitive sources, store info etc.
319319
js_infos.append(jsinfo)
320320

321-
if jsinfo.target.workspace_name:
322-
target_path = "{}/external/{}/{}".format(ctx.bin_dir.path, jsinfo.target.workspace_name, jsinfo.target.package)
321+
if jsinfo.target.repo_name:
322+
target_path = "{}/external/{}/{}".format(ctx.bin_dir.path, jsinfo.target.repo_name, jsinfo.target.package)
323323
else:
324324
target_path = "{}/{}".format(ctx.bin_dir.path, jsinfo.target.package)
325325
package_store_directory = utils.make_symlink(ctx, symlink_path, target_path)

npm/private/npm_translate_lock_state.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def _init_importer_labels(priv, label_store):
188188
################################################################################
189189
def _init_link_workspace(priv, _, attr, label_store):
190190
# initialize link_workspace either from pnpm_lock label or from override
191-
priv["link_workspace"] = attr.link_workspace if attr.link_workspace else label_store.label("pnpm_lock").workspace_name
191+
priv["link_workspace"] = attr.link_workspace if attr.link_workspace else label_store.label("pnpm_lock").repo_name
192192

193193
################################################################################
194194
def _init_external_repository_action_cache(priv, attr):

npm/private/repository_label_store.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ def _make_sibling_label(sibling_label, path):
C804
1515
dirname = paths.dirname(sibling_label.name)
1616
if path.startswith("../"):
1717
# we have no idea what package this sibling is in so just assume the root package which works for repository rules
18-
return Label("@@{}//:{}".format(sibling_label.workspace_name, paths.normalize(paths.join(sibling_label.package, dirname, path))))
18+
return Label("@@{}//:{}".format(sibling_label.repo_name, paths.normalize(paths.join(sibling_label.package, dirname, path))))
1919
else:
20-
return Label("@@{}//{}:{}".format(sibling_label.workspace_name, sibling_label.package, paths.join(dirname, path)))
20+
return Label("@@{}//{}:{}".format(sibling_label.repo_name, sibling_label.package, paths.join(dirname, path)))
2121

2222
################################################################################
2323
def _seed_root(priv, rctx_path, label):
24-
if priv["root"] and label.workspace_name != priv["root"]["workspace"]:
24+
if priv["root"] and label.repo_name != priv["root"]["workspace"]:
2525
fail("cannot seed_root twice with different workspaces")
2626
if priv["root"]:
2727
# already seed_rooted with the same workspace
2828
return
2929
seed_root_path = str(rctx_path(label))
3030
seed_root_depth = len(paths.join(label.package, label.name).split("/"))
3131
priv["root"] = {
32-
"workspace": label.workspace_name,
32+
"workspace": label.repo_name,
3333
"path": "/".join(seed_root_path.split("/")[:-seed_root_depth]),
3434
}
3535

0 commit comments

Comments
 (0)
0