Skip to content

Commit

Permalink
refactor: drop support for Bazel 5 (#1589)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan authored Apr 3, 2024
1 parent 8e81103 commit b7bfff3
Show file tree
Hide file tree
Showing 51 changed files with 669 additions and 4,845 deletions.
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ e2e/**/*-docs.md
examples/**/*-docs.md
js/private/coverage/coverage.js
js/private/node-patches/fs.js
js/private/node-patches_legacy/fs.js
min/
npm/private/test/vendored/
js/private/worker/worker.js
Expand Down
7 changes: 2 additions & 5 deletions docs/js_binary.md

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

4 changes: 2 additions & 2 deletions e2e/npm_translate_lock/snapshots/bzlmod/repositories.bzl

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

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

7 changes: 0 additions & 7 deletions js/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
"Public API"

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

exports_files(
glob(["*.bzl"]),
visibility = ["//docs:__pkg__"],
)

config_setting(
name = "allow_unresolved_symlinks",
values = {bazel_features.flags.allow_unresolved_symlinks: "true"},
visibility = ["//visibility:public"],
)

config_setting(
name = "enable_runfiles",
values = {"enable_runfiles": "true"},
Expand Down
8 changes: 0 additions & 8 deletions js/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ def js_binary(**kwargs):
Label("@aspect_rules_js//js:enable_runfiles"): True,
"//conditions:default": False,
}),
unresolved_symlinks_enabled = select({
Label("@aspect_rules_js//js:allow_unresolved_symlinks"): True,
"//conditions:default": False,
}),
**kwargs
)

Expand All @@ -45,10 +41,6 @@ def js_test(**kwargs):
Label("@aspect_rules_js//js:enable_runfiles"): True,
"//conditions:default": False,
}),
unresolved_symlinks_enabled = select({
Label("@aspect_rules_js//js:allow_unresolved_symlinks"): True,
"//conditions:default": False,
}),
**kwargs
)

Expand Down
44 changes: 7 additions & 37 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", "is_bazel_6_or_greater")
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 @@ -257,18 +256,6 @@ _ATTRS = {
to use npm.
""",
),
"unresolved_symlinks_enabled": attr.bool(
doc = """Whether unresolved symlinks are enabled in the current build configuration.
These are enabled with the `--allow_unresolved_symlinks` flag
(named `--experimental_allow_unresolved_symlinks in Bazel versions prior to 7.0).
Typical usage of this rule is via a macro which automatically sets this
attribute based on a `config_setting` rule.
See /js/private/BUILD.bazel in rules_js for an example.
""",
mandatory = True,
),
"node_toolchain": attr.label(
doc = """The Node.js toolchain to use for this target.
Expand Down Expand Up @@ -300,14 +287,6 @@ _ATTRS = {
allow_single_file = True,
),
"_windows_constraint": attr.label(default = "@platforms//os:windows"),
"_node_patches_legacy_files": attr.label_list(
allow_files = True,
default = ["@aspect_rules_js//js/private/node-patches_legacy:fs.js"],
),
"_node_patches_legacy": attr.label(
allow_single_file = True,
default = "@aspect_rules_js//js/private/node-patches_legacy:register.js",
),
"_node_patches_files": attr.label_list(
allow_files = True,
default = ["@aspect_rules_js//js/private/node-patches:fs.js"],
Expand All @@ -329,7 +308,7 @@ _NODE_OPTION = """JS_BINARY__NODE_OPTIONS+=(\"{value}\")"""
def _target_tool_path_to_short_path(tool_path):
return ("../" + tool_path[len("external/"):]) if tool_path.startswith("external/") else tool_path

def _bash_launcher(ctx, node_toolchain, entry_point_path, log_prefix_rule_set, log_prefix_rule, fixed_args, fixed_env, is_windows, use_legacy_node_patches):
def _bash_launcher(ctx, node_toolchain, entry_point_path, log_prefix_rule_set, log_prefix_rule, fixed_args, fixed_env, is_windows):
# Explicitly disable node fs patches on Windows:
# https://github.com/aspect-build/rules_js/issues/1137
if is_windows:
Expand Down Expand Up @@ -449,17 +428,17 @@ 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.label),
"{{template_label}}": str(ctx.attr._launcher_template.label),
"{{entry_point_label}}": str(ctx.attr.entry_point.label),
"{{entry_point_path}}": entry_point_path,
"{{envs}}": "\n".join(envs),
"{{fixed_args}}": " ".join(fixed_args_expanded),
"{{initialize_runfiles}}": BASH_INITIALIZE_RUNFILES,
"{{log_prefix_rule_set}}": log_prefix_rule_set,
"{{log_prefix_rule}}": log_prefix_rule,
"{{node_options}}": "\n".join(node_options),
"{{node_patches}}": ctx.file._node_patches_legacy.short_path if use_legacy_node_patches else ctx.file._node_patches.short_path,
"{{node_patches}}": ctx.file._node_patches.short_path,
"{{node_wrapper}}": node_wrapper.short_path,
"{{node}}": node_path,
"{{npm}}": npm_path,
Expand All @@ -478,11 +457,6 @@ def _bash_launcher(ctx, node_toolchain, entry_point_path, log_prefix_rule_set, l

def _create_launcher(ctx, log_prefix_rule_set, log_prefix_rule, fixed_args = [], fixed_env = {}):
is_windows = ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo])
is_bazel_6 = is_bazel_6_or_greater()
unresolved_symlinks_enabled = False
if hasattr(ctx.attr, "unresolved_symlinks_enabled"):
unresolved_symlinks_enabled = ctx.attr.unresolved_symlinks_enabled
use_legacy_node_patches = not is_bazel_6 or not unresolved_symlinks_enabled

if ctx.attr.node_toolchain:
node_toolchain = ctx.attr.node_toolchain[platform_common.ToolchainInfo]
Expand All @@ -504,15 +478,11 @@ def _create_launcher(ctx, log_prefix_rule_set, log_prefix_rule, fixed_args = [],
entry_point = ctx.files.entry_point[0]
entry_point_path = entry_point.short_path

bash_launcher, toolchain_files = _bash_launcher(ctx, node_toolchain, entry_point_path, log_prefix_rule_set, log_prefix_rule, fixed_args, fixed_env, is_windows, use_legacy_node_patches)
bash_launcher, toolchain_files = _bash_launcher(ctx, node_toolchain, entry_point_path, log_prefix_rule_set, log_prefix_rule, fixed_args, fixed_env, is_windows)
launcher = create_windows_native_launcher_script(ctx, bash_launcher) if is_windows else bash_launcher

launcher_files = [bash_launcher] + toolchain_files
if use_legacy_node_patches:
launcher_files.extend(ctx.files._node_patches_legacy_files + [ctx.file._node_patches_legacy])
else:
launcher_files.extend(ctx.files._node_patches_files + [ctx.file._node_patches])

launcher_files.extend(ctx.files._node_patches_files + [ctx.file._node_patches])
launcher_files.extend(node_toolchain.nodeinfo.tool_files)
if ctx.attr.include_npm:
launcher_files.extend(node_toolchain.nodeinfo.npm_files)
Expand Down
4 changes: 0 additions & 4 deletions js/private/js_run_devserver.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,6 @@ def js_run_devserver(
"@aspect_rules_js//js:enable_runfiles": True,
"//conditions:default": False,
}),
unresolved_symlinks_enabled = select({
"@aspect_rules_js//js:allow_unresolved_symlinks": True,
"//conditions:default": False,
}),
entry_point = "@aspect_rules_js//js/private:js_devserver_entrypoint",
# This rule speaks the ibazel protocol
tags = kwargs.pop("tags", []) + ["ibazel_notify_changes"],
Expand Down
13 changes: 0 additions & 13 deletions js/private/node-patches_legacy/BUILD.bazel

This file was deleted.

Loading

0 comments on commit b7bfff3

Please sign in to comment.