Skip to content

fix: make tests pass with --incompatible_windows_native_test_wrapper - #1034

Merged
alexeagle merged 5 commits into
bazel-contrib:masterfrom
meteorcloudy:win_launcher
Aug 28, 2019
Merged

alexeagle merged 5 commits into
bazel-contrib:masterfrom
meteorcloudy:win_launcher

Conversation

@meteorcloudy

@meteorcloudy meteorcloudy commented Aug 19, 2019 •

Copy link
Copy Markdown
Collaborator

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #947

What is the new behavior?

A .bat script will be generated to launch the shell script.
For example

bazel build //internal/rollup:test
...
INFO: Found 1 target...
Target //internal/rollup:test up-to-date:
  dist/bin/internal/rollup/test_loader.js
  dist/bin/internal/rollup/test.sh
  dist/bin/internal/rollup/test.bat
INFO: Elapsed time: 3.664s, Critical Path: 0.06s

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@meteorcloudy meteorcloudy changed the title Use .bat file to launch binary on Windows WIP: Use .bat file to launch binary on Windows Aug 19, 2019
Comment thread internal/common/windows_utils.bzl Outdated
# limitations under the License.

def is_windows(ctx):
return ctx.configuration.host_path_separator == ';'

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an ugly hack, the reason is that we don't have a proper way to tell the target platform in Starlark rule implementation.

There is another way to distinguish the platform,
https://github.com/bazelbuild/bazel-skylib/blob/master/rules/diff_test.bzl#L143
Maybe it's a litter better.

@meteorcloudy

meteorcloudy commented Aug 20, 2019 •

Copy link
Copy Markdown
Collaborator Author

After this change, only two tests are still failing with --incompatible_windows_native_test_wrapper

//packages/protractor/test/protractor:test_chromium-local
//packages/protractor/test/protractor-2:devserver_test_chromium-local

They need to be fixed from rules_webtesting.

@meteorcloudy meteorcloudy changed the title WIP: Use .bat file to launch binary on Windows Use .bat file to launch binary on Windows Aug 20, 2019
@buildsize

buildsize Bot commented Aug 20, 2019 •

Copy link
Copy Markdown
File name Previous Size New Size Change
release.tar.gz 1.01 MB 1.02 MB 1.3 KB (0%)

@alexeagle

Copy link
Copy Markdown
Collaborator

I think this is the wrong long-term fix because we shouldn't need bash at all to run a nodejs program on Windows.
But I suppose it's more important to first unblock the --incompatible_windows_native_test_wrapper migration.

Could you add --incompatible_windows_native_test_wrapper to the .bazelrc in this change so it doesn't regress, and the green CI proves that the fix works?

These functions help making rules work on Windows.
"""

def is_windows(ctx):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion!

The implementation in node_repositories.bzl is for repository rule only (requires repository_ctx), the repository_ctx.os.name API is not available in rule context (ctx). So we cannot use that.

The implementation in copy_file_private.bzl looks more reasonable. But it requires us to add is_windows attribute to every rule that wants to distinguish platforms and a macro to provide default value for that attribute. But essentially, it will give us the same result. Considering we are not going to do cross-platform build between Windows and Unix systems in near future, I think the current way is fine.

@meteorcloudy

Copy link
Copy Markdown
Collaborator Author

I think this is the wrong long-term fix because we shouldn't need bash at all to run a nodejs program on Windows.

Agree, I can think of two options to make the launcher bashless on Windows:

  1. Implement the logic of node_launcher.sh in Windows Batch or Powershell. But the logic is not simple, implementing this in Batch will be very error prone and not maintainable.

  2. Implement the logic of node_launcher.sh in Nodejs, then we use a simple shell script to execute this node_launcher.js on Linux/macOS and a simple batch script to execute it on Windows.

WDYT?

@meteorcloudy

meteorcloudy commented Aug 23, 2019 •

Copy link
Copy Markdown
Collaborator Author

All tests passed on Windows with --incompatible_windows_native_test_wrapper!
But we still need to wait for a new rules_webtesting release for correct Starlark documentation generation.

@meteorcloudy
meteorcloudy requested a review from soldair as a code owner August 26, 2019 07:57
@alexeagle
alexeagle force-pushed the win_launcher branch 4 times, most recently from 06547b0 to c959f42 Compare August 27, 2019 00:31
@meteorcloudy

Copy link
Copy Markdown
Collaborator Author

I'm still getting a runfile failure on Windows even after the latest commit.

I turned on debug mode and the log is here: log

@alexeagle Can you help debug a bit?

node_loader: resolve io_bazel_rules_webtesting/third_party/chromium/chromium.out from D:\b\si3nycvr\execroot\build_bazel_rules_nodejs\bazel-out\x64_windows-fastbuild\bin\packages\protractor\test\protractor-2\devserver_test_wrapped_test.conf.js
node_loader: try to resolve in runfiles manifest io_bazel_rules_webtesting/third_party/chromium/chromium.out
node_loader: resolved manifest file D:/b/si3nycvr/execroot/build_bazel_rules_nodejs/bazel-out/x64_windows-fastbuild/bin/external/io_bazel_rules_webtesting/third_party/chromium/chromium.out
node_loader: try to resolve in runfiles manifest npm/node_modules/io_bazel_rules_webtesting/third_party/chromium/chromium.out

Looks like it still tries to resolve from npm modules even after resolving from manifest succeeded. Note that io_bazel_rules_webtesting/third_party/chromium/chromium.out is a directory, could that be a problem?

@meteorcloudy
meteorcloudy force-pushed the win_launcher branch 2 times, most recently from e700da7 to 481c214 Compare August 27, 2019 15:16
@meteorcloudy
meteorcloudy force-pushed the win_launcher branch 2 times, most recently from a75903d to 66fc165 Compare August 28, 2019 07:54
@meteorcloudy
meteorcloudy force-pushed the win_launcher branch 5 times, most recently from 60a184d to d36e293 Compare August 28, 2019 09:07
@meteorcloudy

meteorcloudy commented Aug 28, 2019 •

Copy link
Copy Markdown
Collaborator Author

@alexeagle I finally got most of tests passing except //e2e:e2e_karma_stack_trace, it is failing on all three platforms but with different error messages:

Linux: log
Windows: log
macOS: log

Can you help debug this?

@meteorcloudy meteorcloudy changed the title Use .bat file to launch binary on Windows fix: make tests pass with --incompatible_windows_native_test_wrapper Aug 28, 2019
@alexeagle

Copy link
Copy Markdown
Collaborator

Inside e2e_karma_stack_trace, the targets //:karma_test_chromium-local and //:karma_test_firefox-local are expected to fail - the remaining targets assert things about those failures.
See https://github.com/bazelbuild/rules_nodejs/blob/master/e2e/karma_stack_trace/BUILD.bazel#L31-L33

They are marked tags=['manual'] to prevent them being matched by the //... pattern - but I saw a similar problem yesterday where changing the other tags on the target made this break. Maybe Bazel syntactically looks for the ["manual"] value in tags, rather than check if "manual" is among the tags?

I added a commit with --test_tag_filters=-manual to prevent those getting included, watching CI...

@meteorcloudy

meteorcloudy commented Aug 28, 2019 •

Copy link
Copy Markdown
Collaborator Author

Thanks for pointing that out!

Running 'bazel test //... --test_tag_filters=-manual --local_resources=13288,7.0,1.0 --test_tag_filters=-no-bazelci,-no-bazelci-ubuntu'

You fix didn't work because the second --test_tag_filters flag override the first one, so we need to add this somewhere else.

But I also tested Bazel, it should recognize manual even there are multiple tags. Maybe something went wrong when passing the manual tag through the macros?

@alexeagle
alexeagle force-pushed the win_launcher branch 2 times, most recently from 2eccecc to 8523345 Compare August 28, 2019 16:13
@alexeagle

Copy link
Copy Markdown
Collaborator

I did bazel query --output=build and the manual label does appear on the target. I don't understand it either. But it's green now, do you want to merge like this?

It seems that Bazel doesn't filter manual-tagged targets when other tags
are also present.
@alexeagle
alexeagle merged commit d4686a8 into bazel-contrib:master Aug 28, 2019
@meteorcloudy

Copy link
Copy Markdown
Collaborator Author

Nice, thanks for merging this! When can we have a new release? rules_typescript still needs to be fixed, I guess upgrading rules_nodejs should do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants