Skip to content

[Bug]: Guidance for calling js_run_binary(chdir = package_name()) is incorrect in case the repo is external #2275

@EdSchouten

Description

@EdSchouten

What happened?

There are many places in the tree where js_run_binary() is invoked with chdir = package_name(). It should be noticed that this is not correct in case the repo in which js_run_binary() is not the main binary. For example, if I create a Bazel project that depends on the Bonanza repo as follows:

git_override(
    module_name = "build_bonanza",
    commit = "c45401ceea0071815df1d696afa26fb80eaeb0f5",
    remote = "https://github.com/buildbarn/bonanza.git",
)

Then building @build_bonanza//cmd/bonanza_browser:generate_stylesheet fails as follows:

bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/build_bonanza+/cmd/bonanza_browser/generate_stylesheet_/generate_stylesheet: line 449: cd: cmd/bonanza_browser: No such file or directory

If I patch up the Bonanza repo as follows, the target does build:

diff --git a/cmd/bonanza_browser/BUILD.bazel b/cmd/bonanza_browser/BUILD.bazel
index 7c5d9fc..ce3b4bd 100644
--- a/cmd/bonanza_browser/BUILD.bazel
+++ b/cmd/bonanza_browser/BUILD.bazel
@@ -71,7 +71,10 @@ js_run_binary(
     name = "stylesheet",
     outs = ["stylesheet.css"],
     args = ["stylesheet.css"],
-    chdir = package_name(),
+    chdir = "external/%s/%s" % (
+        repo_name(),
+        package_name(),
+    ),
     tool = ":generate_stylesheet",
 )

I think what is needed is proper guidance on how to use the chdir option properly.

Version

Bazel 8.3.1 running on a Mac, using rules_js v2.3.8

How to reproduce

Any other information?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions