Is it possible to customize execRoot in Bazel 7.4 ?

14 views
Skip to first unread message

Sajan Sahoo

unread,
Feb 13, 2025, 9:51:47 AMFeb 13
to bazel-discuss
Hi all,
Cross-posting from StackOverflow . I am new to Bazel, I don't know where else I can ask questions. 

Can we change or provide a custom path for execRoot in Bazel 7.4 with Bazelmod enabled?

Or at least change the name of the main repository from _main to something else ?

My problem is, before enabling Bazelmod, Some files were available at path like:

/home/ssahoo/.cache/bazel/_bazel_ssahoo/eb5a6bd7163c3bba3080b98009823a76/execroot/<workspace_name>/APP_NAME/app/javascript/styles/charges/charges.sass

Now, after enabling Bzlmod, the path has changed to

/home/ssahoo/.cache/bazel/_bazel_ssahoo/eb5a6bd7163c3bba3080b98009823a76/execroot/_main/APP_NAME/app/javascript/styles/charges/charges.sass

So TS imports that are using path <workspace_name>/APP_NAME/app/javascript/styles/charges/charges.sass fails as there is no workspace_name in the path anymore.

I know I can use `_main` or a relative path here, but I am trying to avoid changing too many files. There are hundreds of files in this monorepo using such import paths. Can I use the module name or workspace name here instead of _main? Or are there any other solutions?

Alexandre Rostovtsev

unread,
Feb 13, 2025, 6:56:45 PMFeb 13
to Sajan Sahoo, bazel-discuss
You can set a different output base directory (`--output_base=...` flag), but within that output base directory, you cannot change the main repository name; the name "_main" is hard-coded in BazelRuleClassProvider.java.

Using paths that contain a hard-coded repo name in your import statements seems fragile and generally a bad idea. For one thing, such import statements will break depending on whether your module is the root module or a dependency of another module (even if you think you wouldn't need to use it as a dependency, it might be treated a dependency in some integration tests).

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/bazel-discuss/159afa54-5bb7-4a8c-9a3f-432f903c5553n%40googlegroups.com.

Filip Filmar

unread,
Feb 13, 2025, 7:04:07 PMFeb 13
to Alexandre Rostovtsev, Sajan Sahoo, bazel-discuss
On Thu, Feb 13, 2025 at 10:56 AM 'Alexandre Rostovtsev' via bazel-discuss <bazel-...@googlegroups.com> wrote:
Using paths that contain a hard-coded repo name in your import statements seems fragile and generally a bad idea.

I think this is indeed true. But I am actually not aware of what one can do to work around this issue.

Even runfiles encode the repository name in the relative path to a resource. So, that path will be different depending on whether we're the "main" repo or an external repo.

I have two vague suggestions:
  • I think I read that there is an API that allows you to select the correct name, but I forget where or what. :/
  • In the past, I resolved this by adding the resource to runfiles and passing its $location as a command line argument. Worked ~fine in tests.
F

Reply all
Reply to author
Forward
0 new messages