You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 10, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 10, 2026. It is now read-only.
Executing node_binary clobbers current working directory #36
Hi @driveraid. In the previous version of rules_node there was a longstanding issue of how to run a node binary in the context of various different execution scenarios (bazel run :foo, ./bazel-bin/foo, bazel test :foo_test) and so forth. Copying over the node binary to the bundle directory and exec`ing there was a way to avoid having to detect where runfiles directory was, etc. Very clever, or so I thought!
Unfortunately as I see now this does not work in a genfile context! It should be possible to redo the create_launcher function to accomodate this use case, hopefully in a non-hacky way.
As possible short-term workaround might be to adjust the location of the example/file.idl location based on the knowledge of where the script is cd'ing into. You can experiment by putting in ls -al . or find . into your genrule cmd to debug that.
Thanks @pcj.
For a short term workaround, we realized that in this case we were able to modify the IDL compiler to accept a new --chdir option, enabling bridging of the WD like follows:
It's a bit wierd, we suddenly had to disable sandboxing by issuing --genrule_strategy=standalone because the cd invocation from the runner stopped working (gen_bundle not present in sandbox)... but it's late... could be that too :)
It would be nice with a cleaner solution to this issue!
In regard to the sandbox issue, if you write your genrule as an actual build rule, you could access the files property on the node_binary provider and propagate that to the ctx.action.inputs file list.
Activity
pcj commentedon Oct 9, 2017
Hi @driveraid. In the previous version of
rules_nodethere was a longstanding issue of how to run a node binary in the context of various different execution scenarios (bazel run :foo,./bazel-bin/foo,bazel test :foo_test) and so forth. Copying over thenodebinary to the bundle directory and exec`ing there was a way to avoid having to detect where runfiles directory was, etc. Very clever, or so I thought!Unfortunately as I see now this does not work in a genfile context! It should be possible to redo the create_launcher function to accomodate this use case, hopefully in a non-hacky way.
https://github.com/pubref/rules_node/blob/master/node/internal/node_binary.bzl#L77-L93
As possible short-term workaround might be to adjust the location of the example/file.idl location based on the knowledge of where the script is cd'ing into. You can experiment by putting in
ls -al .orfind .into your genrule cmd to debug that.driveraid commentedon Oct 9, 2017
Thanks @pcj.
For a short term workaround, we realized that in this case we were able to modify the IDL compiler to accept a new
--chdiroption, enabling bridging of the WD like follows:It's a bit wierd, we suddenly had to disable sandboxing by issuing
--genrule_strategy=standalonebecause thecdinvocation from the runner stopped working (gen_bundlenot present in sandbox)... but it's late... could be that too :)It would be nice with a cleaner solution to this issue!
Thanks
pcj commentedon Oct 9, 2017
In regard to the sandbox issue, if you write your genrule as an actual build rule, you could access the files property on the node_binary provider and propagate that to the ctx.action.inputs file list.
https://github.com/pubref/rules_node/blob/master/node/internal/node_binary.bzl#L142-L144
But yeah, I get that it deserves a clean solution.
pcj commentedon Oct 26, 2017
I believe this should be fixed by #41. Please re-open if remains unresolved.
markushandell commentedon Nov 20, 2017
I can confirm that the CWD issue is fixed with 0.4.1, thanks @pcj! Will now try to go for a sandbox-safe solution as advised.