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

For Windows: Fix to enable scala_test and scala_binary outputs to be executed on Windows #1502

Merged
merged 3 commits into from
Jul 3, 2023

Conversation

crt-31
Copy link
Contributor

@crt-31 crt-31 commented Jun 23, 2023

Description

For Windows, this PR fixes issue where outputs of scala_test and scala_binary are failing when ran with 'bazel run' and 'bazel test'. When trying to do run or test, Bazel shows error like:

LAUNCHER ERROR: rlocation failed on “external\localjdk\bin\java.exe not found in MANIFEST”.

The Fix: On Windows, Bazel’s Java Launcher was being passed paths in the wrong ‘form’. The launcher expects rpathlocation form for some paths and rootpath form for others. Fix is to pass the right forms of the paths to the LauncherFileWriter which in turn passes correct paths into the Launcher.

Motivation

scala_test and scala_binary should work properly on Windows

Seems to have been caused by #1313
Should also fix #1497

Test/Reproduction

The following can be used as a demonstration test on windows (will fail before this PR):

bazel test //test/RunScalaBinary --enable_runfiles --extra_toolchains=//scala:minimal_direct_source_deps

Note that: 'bazel test' requires --enable_runfiles to be set on Windows.
Also note that many other tests fail in Windows, but fixes for those are for a separate PR.

@crt-31 crt-31 requested review from liucijus and simuons as code owners June 23, 2023 05:54
@google-cla
Copy link

google-cla bot commented Jun 23, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

crt-31 added 2 commits June 22, 2023 23:15
Passing the correct path forms (i.e. rpathlocation vs rootpath) to Windows Launcher.
This enables running scala_test and scala_binary outputs through bazel on windows.
@crt-31 crt-31 force-pushed the launcherPathFix branch from 562cd19 to aeae8f7 Compare June 23, 2023 06:39
Copy link
Collaborator

@liucijus liucijus left a comment

Choose a reason for hiding this comment

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

Thanks, @crt-31! LGTM (assuming I have no Windows environment to test), please address the nits.

#generates rpathlocation that should be used with the rlocation() at runtime. (rpathlocations start with repo name)
#rootpath arg expects "rootpath" format (i.e. relative to runfilesDir/workspacename). Rootpath can be obtained by $rootpath macro or File.short_path
def rpathlocation_from_rootpath(ctx, rootpath):
p = paths.normalize(ctx.workspace_name + "/" + rootpath)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: please inline p

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


cpfile = ctx.actions.declare_file("%s.classpath" % ctx.label.name)
ctx.actions.write(cpfile, classpath)

specifiedEnv = {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add code comment explaining this change. Also, please consider using https://bazel.build/rules/lib/globals/all#getattr with a default value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

- Added comment on use of env in _write_executable_windows()
- Removed unecessary var in rpathlocation_from_rootpath()
@crt-31 crt-31 force-pushed the launcherPathFix branch from 005a907 to a44746b Compare June 28, 2023 00:22
@simuons simuons merged commit 76ee19f into bazelbuild:master Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@io_bazel_rules_scala//twitter_scrooge:twitter_scrooge.bzl can't find java.exe on windows
3 participants