From 8ef910de9042fd57b0d603c15dbaf9045192b4ea Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Fri, 21 Mar 2025 16:13:55 -0700 Subject: [PATCH] fix: js_image_layer when binary file is directly in bin_dir (#2141) --- js/private/js_image_layer.bzl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/js/private/js_image_layer.bzl b/js/private/js_image_layer.bzl index 471ab9671..c97839b62 100644 --- a/js/private/js_image_layer.bzl +++ b/js/private/js_image_layer.bzl @@ -303,15 +303,17 @@ def _write_laucher(ctx, real_binary): "Creates a call-through shell entrypoint which sets BAZEL_BINDIR to '.' then immediately invokes the original entrypoint." launcher = ctx.actions.declare_file("%s_launcher" % ctx.label.name) + substitutions = { + "#!/usr/bin/env bash": _LAUNCHER_PREABMLE, + 'export JS_BINARY__BINDIR="%s"' % real_binary.root.path: 'export JS_BINARY__BINDIR="$(pwd)"', + 'export JS_BINARY__TARGET_CPU="%s"' % ctx.expand_make_variables("", "$(TARGET_CPU)", {}): 'export JS_BINARY__TARGET_CPU="$(uname -m)"', + } + substitutions['export JS_BINARY__BINDIR="%s"' % ctx.bin_dir.path] = 'export JS_BINARY__BINDIR="$(pwd)"' + ctx.actions.expand_template( template = real_binary, output = launcher, - substitutions = { - "#!/usr/bin/env bash": _LAUNCHER_PREABMLE, - 'export JS_BINARY__BINDIR="%s"' % real_binary.root.path: 'export JS_BINARY__BINDIR="$(pwd)"', - 'export JS_BINARY__BINDIR="%s"' % ctx.bin_dir.path: 'export JS_BINARY__BINDIR="$(pwd)"', - 'export JS_BINARY__TARGET_CPU="%s"' % ctx.expand_make_variables("", "$(TARGET_CPU)", {}): 'export JS_BINARY__TARGET_CPU="$(uname -m)"', - }, + substitutions = substitutions, is_executable = True, ) return launcher