Skip to content

Commit

Permalink
refactor: update js_binary executable path to {name}_/{name}
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed May 6, 2024
1 parent 935e6ea commit d25cec7
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 131 deletions.
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,7 @@ llvm_toolchain(
load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains")

llvm_register_toolchains()

load("@aspect_bazel_lib//lib:repositories.bzl", "register_expand_template_toolchains")

register_expand_template_toolchains()
14 changes: 7 additions & 7 deletions docs/js_image_layer.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/js_image_docker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ container_image(

# Since js_binary depends on bash we have to bring in a base image that has bash
base = "@debian_amd64//image", # or "@debian_arm64//image", if you are on an arm machine
# This is going to be /{root of js_image_layer}/{package_name()}/{name of js_binary}
cmd = ["/app/main"],
# This is going to be /{root of js_image_layer}/{package_name()}/{name of js_binary}_/{name of js_binary}
cmd = ["/app/main_/main"],
entrypoint = ["bash"],
layers = [
":app_layer",
Expand Down
4 changes: 2 additions & 2 deletions e2e/js_image_docker/smoketest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ schemaVersion: 2.0.0
commandTests:
- name: 'smoke'
command: 'bash'
args: ['/app/main']
args: ['/app/main_/main']
expectedOutput: ['.*WORKSPACE.*__main__', '.*main.*', '.*ARCH.*']
- name: 'smoke2'
command: '/app/main'
command: '/app/main_/main'
expectedOutput: ['.*WORKSPACE.*__main__', '.*main.*', '.*ARCH.*']
4 changes: 2 additions & 2 deletions e2e/js_image_oci/src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ oci_image(
name = "image",
# Since js_binary depends on bash we have to bring in a base image that has bash
base = "@debian",
# This is going to be /{root of js_image_layer}/{package_name()}/{name of js_binary}
cmd = ["/app/src/main"],
# This is going to be /{root of js_image_layer}/{package_name()}/{name of js_binary}_/{name of js_binary}
cmd = ["/app/src/main_/main"],
entrypoint = ["bash"],
tars = [
":layers",
Expand Down
4 changes: 2 additions & 2 deletions e2e/js_image_oci/src/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ schemaVersion: 2.0.0
commandTests:
- name: 'smoke'
command: 'bash'
args: ['/app/src/main']
args: ['/app/src/main_/main']
expectedOutput:
[
'OS',
Expand All @@ -16,7 +16,7 @@ commandTests:
' SOURCE DIRECTORY CHECK true',
]
- name: 'smoke2'
command: '/app/src/main'
command: '/app/src/main_/main'
expectedOutput:
[
'OS',
Expand Down
2 changes: 1 addition & 1 deletion e2e/worker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ copy_file(
)

js_binary(
name = "worker_binary",
name = "worker",
data = [":copy_worker_js"],
entry_point = ":copy_dummy_worker",
visibility = ["//visibility:public"],
Expand Down
2 changes: 1 addition & 1 deletion e2e/worker/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pi_rule = rule(
"worker": attr.label(
executable = True,
cfg = "exec",
default = ":worker_binary",
default = ":worker",
),
},
)
2 changes: 1 addition & 1 deletion examples/coverage/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@aspect_rules_js//js:defs.bzl", "js_test")

js_test(
name = "coverage_test",
name = "coverage",
data = [
"coverage.js",
"//:node_modules/@types/node",
Expand Down
32 changes: 19 additions & 13 deletions examples/js_binary/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Simple examples of running JS programs in node with js_binary, js_run_binary, an
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
load("@aspect_bazel_lib//lib:diff_test.bzl", "diff_test")
load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_run_binary", "js_test")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@npm//:defs.bzl", "npm_link_all_packages")
Expand Down Expand Up @@ -457,21 +458,26 @@ js_binary(
entry_point = "case10.js",
)

write_file(
expand_template(
name = "write10_launch_sh",
out = "launch_case10.sh",
content = ["""\
# --- begin runfiles.bash initialization v2 ---
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 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 || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v2 ---
$(rlocation aspect_rules_js/examples/js_binary/bin10-js_binary) "$@"
data = [":bin10-js_binary"],
is_executable = True,
substitutions = {
"{rlocationpath}": "$(rlocationpath :bin10-js_binary)",
},
template = ["""\
# --- begin runfiles.bash initialization v2 ---
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 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 || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v2 ---
$(rlocation {rlocationpath}) "$@"
"""],
)

Expand Down
2 changes: 1 addition & 1 deletion js/private/coverage/merger.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _coverage_merger_impl(ctx):
node_path = _deprecated_target_tool_path_to_short_path(nodeinfo.target_tool_path)

# Create launcher
bash_launcher = ctx.actions.declare_file(ctx.label.name)
bash_launcher = ctx.actions.declare_file("{}_/{}".format(ctx.label.name, ctx.label.name))
ctx.actions.expand_template(
template = ctx.file._launcher_template,
output = bash_launcher,
Expand Down
2 changes: 1 addition & 1 deletion js/private/js_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def _bash_launcher(ctx, nodeinfo, entry_point_path, log_prefix_rule_set, log_pre
"{{workspace_name}}": ctx.workspace_name,
}

launcher = ctx.actions.declare_file(ctx.label.name)
launcher = ctx.actions.declare_file("{}_/{}".format(ctx.label.name, ctx.label.name))
ctx.actions.expand_template(
template = ctx.file._launcher_template,
output = launcher,
Expand Down
16 changes: 8 additions & 8 deletions js/private/js_image_layer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_image_layer")
load("@rules_oci//oci:defs.bzl", "oci_image")
js_binary(
name = "binary",
name = "main",
entry_point = "main.js",
)
Expand All @@ -50,14 +50,14 @@ platform(
js_image_layer(
name = "layers",
binary = ":binary",
binary = ":main",
platform = ":amd64_linux",
root = "/app"
)
oci_image(
name = "image",
cmd = ["/app/main"],
cmd = ["/app/main_/main"],
entrypoint = ["bash"],
tars = [
":layers"
Expand All @@ -73,7 +73,7 @@ load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_image_layer")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_image_index")
js_binary(
name = "binary",
name = "main",
entry_point = "main.js",
)
Expand All @@ -87,13 +87,13 @@ js_binary(
)
js_image_layer(
name = "{}_layers".format(arch),
binary = ":binary",
binary = ":main",
platform = ":linux_{arch}",
root = "/app"
)
oci_image(
name = "{}_image".format(arch),
cmd = ["/app/main"],
cmd = ["/app/main_/main"],
entrypoint = ["bash"],
tars = [
":{}_layers".format(arch)
Expand Down Expand Up @@ -158,7 +158,7 @@ container_layer(
container_image(
name = "image",
cmd = ["/app/main"],
cmd = ["/app/main_/main"],
entrypoint = ["bash"],
layers = [
":app_layer",
Expand Down Expand Up @@ -202,7 +202,7 @@ def _runfiles_dir(root, default_info):
else:
runfiles = manifest.short_path.replace(manifest.basename, "")[:-1]

return paths.join(root, runfiles.replace(".sh", ""))
return paths.join(root, runfiles)

def _build_layer(ctx, type, entries, inputs):
entries_output = ctx.actions.declare_file("{}_{}_entries.json".format(ctx.label.name, type))
Expand Down
4 changes: 2 additions & 2 deletions js/private/test/image/checksum.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
e6a04b6344eb21154508bf246ebead12d436313739c478978cd5763262491f98 js/private/test/image/cksum_app.tar
7990126e5961588efd2af7cdccac3846dfffb8ca2e26206840df8c7a1c34c42e js/private/test/image/cksum_node_modules.tar
99bc84e3bee778a70b7ad1e25d719d50c9e1d8e4b4dfab3c5335156b2889e185 js/private/test/image/cksum_app.tar
f9388e94b2055de4a94548d65c2ec5390744abdada53678ab59c8a3410843f5e js/private/test/image/cksum_node_modules.tar
24 changes: 13 additions & 11 deletions js/private/test/image/custom_owner_app.listing
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image
-r-xr-xr-x 100/0 131 1970-01-01 00:00 app/js/private/test/image/bin
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin.runfiles
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin.runfiles/aspect_rules_js
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin.runfiles/aspect_rules_js/js
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin.runfiles/aspect_rules_js/js/private
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin.runfiles/aspect_rules_js/js/private/test
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin.runfiles/aspect_rules_js/js/private/test/image
-r-xr-xr-x 100/0 23908 1970-01-01 00:00 app/js/private/test/image/bin.runfiles/aspect_rules_js/js/private/test/image/bin
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin.runfiles/aspect_rules_js/js/private/test/image/bin_node_bin
-r-xr-xr-x 100/0 133 1970-01-01 00:00 app/js/private/test/image/bin.runfiles/aspect_rules_js/js/private/test/image/bin_node_bin/node
-r-xr-xr-x 100/0 20 1970-01-01 00:00 app/js/private/test/image/bin.runfiles/aspect_rules_js/js/private/test/image/main.js
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin_
-r-xr-xr-x 100/0 141 1970-01-01 00:00 app/js/private/test/image/bin_/bin
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin_/bin.runfiles
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin_/bin.runfiles/aspect_rules_js
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin_/bin.runfiles/aspect_rules_js/js
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin_/bin.runfiles/aspect_rules_js/js/private
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin_/bin.runfiles/aspect_rules_js/js/private/test
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin_/bin.runfiles/aspect_rules_js/js/private/test/image
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin_/bin.runfiles/aspect_rules_js/js/private/test/image/bin_
-r-xr-xr-x 100/0 23908 1970-01-01 00:00 app/js/private/test/image/bin_/bin.runfiles/aspect_rules_js/js/private/test/image/bin_/bin
drwxr-xr-x 100/0 0 1970-01-01 00:00 app/js/private/test/image/bin_/bin.runfiles/aspect_rules_js/js/private/test/image/bin_node_bin
-r-xr-xr-x 100/0 133 1970-01-01 00:00 app/js/private/test/image/bin_/bin.runfiles/aspect_rules_js/js/private/test/image/bin_node_bin/node
-r-xr-xr-x 100/0 20 1970-01-01 00:00 app/js/private/test/image/bin_/bin.runfiles/aspect_rules_js/js/private/test/image/main.js
Loading

0 comments on commit d25cec7

Please sign in to comment.