Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing a RegExp as a templated_args fails on Windows #317

Closed
alan-agius4 opened this issue Sep 13, 2018 · 7 comments
Closed

Passing a RegExp as a templated_args fails on Windows #317

alan-agius4 opened this issue Sep 13, 2018 · 7 comments
Labels
bug Can Close? We will close this in 30 days if there is no further activity

Comments

@alan-agius4
Copy link
Contributor

alan-agius4 commented Sep 13, 2018

When passing a RegExp in template_args it is failing on windows.

Example

nodejs_test(
	name = "rollup_test",
	node_modules = "@runtime_deps//:node_modules",
	entry_point = "rollup/bin/rollup",
	templated_args = ["^\(json\|schema\|something\)$"],
	visibility = ["//visibility:private"],
)

Will cause an error

λ bazel test :rollup_test
INFO: Analysed target //:rollup_test (1 packages loaded).
INFO: Found 1 test target...

TIMEOUT: //:rollup_test (Summary)
      C:/users/alag/_bazel_alag/x34iiuoj/execroot/nodejs_issue/bazel-out/x64_windows-fastbuild/testlogs/rollup_test/test.log
Target //:rollup_test up-to-date:
  C:/users/alag/_bazel_alag/x34iiuoj/execroot/nodejs_issue/bazel-out/x64_windows-fastbuild/bin/rollup_test_bin.sh
  C:/users/alag/_bazel_alag/x34iiuoj/execroot/nodejs_issue/bazel-out/x64_windows-fastbuild/bin/rollup_test
  C:/users/alag/_bazel_alag/x34iiuoj/execroot/nodejs_issue/bazel-out/x64_windows-fastbuild/bin/rollup_test.exe
INFO: Elapsed time: 301.302s, Critical Path: 300.16s
INFO: 1 process: 1 local.
INFO: Build completed, 1 test FAILED, 4 total actions
//:rollup_test                                                          TIMEOUT in 300.1s
  C:/users/alag/_bazel_alag/x34iiuoj/execroot/nodejs_issue/bazel-out/x64_windows-fastbuild/testlogs/rollup_test/test.log

INFO: Build completed, 1 test FAILED, 4 total actions

The log file contents are

exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //:rollup_test
-----------------------------------------------------------------------------
'schema' is not recognized as an internal or external command,
operable program or batch file.

I have put together a minimal reproduction https://github.com/alan-agius4/rules_nodejs_error_no_such_file

The same thing seems to be running fine on Mac, Rollup will eventually throw an exception Error: Could not resolve entry (^(json|schema|something)$) because it doesn't support a RegExp. But I used this as a small and quick reproduction of the root error.

@gregmagolan
Copy link
Collaborator

gregmagolan commented Sep 14, 2018

It looks like bazel bash emulator on Windows (which node_launcher.sh runs in) gets confused by the argument ^(json|schema|something)$ as it thinks that the | character is a pipe

I tried the variations "^(json|schema|something)$" and "^\(json\|schema\|something\)$" with the same result.

Which nodejs_binary takes a regular expression its argument?

@alan-agius4
Copy link
Contributor Author

alan-agius4 commented Sep 14, 2018

@filipesilva
Copy link
Contributor

I tested on Bazel 0.16.1, 0.17.1, executing from gitbash and from cmd, and got the same result as @alan-agius4's original report.

@filipesilva
Copy link
Contributor

I did a simpler test to figure out what's going on.

First I used a local repository for rules_nodejs and printed what the command really was:

"C:/users/kamik/_bazel_kamik/tyc5x3fl/external/nodejs/bin/node.cmd" "--preserve-symlinks" "C:/users/kamik/_bazel_kamik/tyc5x3fl/execroot/__main__/bazel-out/x64_windows-fastbuild/bin/rollup_test_bin_loader.js" "^(json|schema|something)$"

Then tried to make a simpler version of that, with a test.js file containing console.log(process.argv), and ran some variations on gitbash:

kamik@RED-X1C6 MINGW64 /d/sandbox/rules_nodejs_error_no_such_file (master)
$ node test.js ^(json|schema|something)$
bash: syntax error near unexpected token `('

kamik@RED-X1C6 MINGW64 /d/sandbox/rules_nodejs_error_no_such_file (master)
$ node test.js "^(json|schema|something)$"
[ 'C:\\Program Files\\nodejs\\node.exe',
  'D:\\sandbox\\rules_nodejs_error_no_such_file\\test.js',
  '^(json|schema|something)$' ]

kamik@RED-X1C6 MINGW64 /d/sandbox/rules_nodejs_error_no_such_file (master)
$ C:/users/kamik/_bazel_kamik/tyc5x3fl/external/nodejs/bin/node.cmd test.js "^(json|schema|something)$"
'schema' is not recognized as an internal or external command,
operable program or batch file.

Also tried the same through cmd instead:

D:\sandbox\rules_nodejs_error_no_such_file>node test.js ^(json|schema|something)$
'schema' is not recognized as an internal or external command,
operable program or batch file.

D:\sandbox\rules_nodejs_error_no_such_file>node test.js "^(json|schema|something)$"
[ 'C:\\Users\\kamik\\_bazel_kamik\\tyc5x3fl\\external\\nodejs\\bin\\nodejs\\node.exe',
  'D:\\sandbox\\rules_nodejs_error_no_such_file\\test.js',
  '^^(json|schema|something)$' ]

D:\sandbox\rules_nodejs_error_no_such_file>C:/users/kamik/_bazel_kamik/tyc5x3fl/external/nodejs/bin/node.cmd test.js "^(json|schema|something)$"
[ 'C:\\Users\\kamik\\_bazel_kamik\\tyc5x3fl\\external\\nodejs\\bin\\nodejs\\node.exe',
  'D:\\sandbox\\rules_nodejs_error_no_such_file\\test.js',
  '^^(json|schema|something)$' ]

Noteworthy findings:

  • gitbash (and thus msys) is perfectly ok with "^(json|schema|something)$", which is what the current command already uses
  • cmd shows the error when quotes aren't used
  • cmd adds another ^ for some reason
  • node doesn't seem to care either way
  • using gitbash/msys to call the node.cmd installed by bazel with "^(json|schema|something)$" errors out

Knowing this I went to check the binary folders and tired not using the cmd but rather the .exe:

kamik@RED-X1C6 MINGW64 /d/sandbox/rules_nodejs_error_no_such_file (master)
$ C:/users/kamik/_bazel_kamik/tyc5x3fl/external/nodejs/bin/nodejs/node test.js "^(json|schema|something)$"
[ 'C:\\users\\kamik\\_bazel_kamik\\tyc5x3fl\\external\\nodejs\\bin\\nodejs\\node.exe',
  'D:\\sandbox\\rules_nodejs_error_no_such_file\\test.js',
  '^(json|schema|something)$' ]

This seems fine.

I also tried changing the call below to use several types of quotes, and found that "${node}" "${NODE_OPTIONS[@]}" "${script}" \"\"${ARGS[@]}\"\" <&0 & works (double escaped quotes).

https://github.com/bazelbuild/rules_nodejs/blob/6b3f96ff47e027ef8b2af1953b2bec20c3fc22b0/internal/node/node_launcher.sh#L143

This makes me think that calling a .cmd file from msys might have weird semantics regarding arguments and quotes that are not present when calling a .exe. Using double escaped quotes helps but surely going that route is to invite madness upon our work.

That's under our control so maybe we could change it to something else and bypass those problems.
https://github.com/bazelbuild/rules_nodejs/blob/6b3f96ff47e027ef8b2af1953b2bec20c3fc22b0/internal/node/node_repositories.bzl#L232-L238

@alexeagle
Copy link
Collaborator

I think it's the same root cause as bazelbuild/bazel#4778

petebacondarwin pushed a commit to petebacondarwin/angular that referenced this issue Sep 27, 2018
alxhub pushed a commit to angular/angular that referenced this issue Sep 27, 2018
FrederikSchlemmer pushed a commit to FrederikSchlemmer/angular that referenced this issue Jan 3, 2019
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had any activity for 90 days. It will be closed if no further activity occurs in two weeks. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs!

@github-actions github-actions bot added the Can Close? We will close this in 30 days if there is no further activity label Nov 18, 2020
@github-actions
Copy link

github-actions bot commented Dec 2, 2020

This issue was automatically closed because it went two weeks without a reply since it was labeled "Can Close?"

@github-actions github-actions bot closed this as completed Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Can Close? We will close this in 30 days if there is no further activity
Projects
None yet
Development

No branches or pull requests

4 participants