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

Add executable as a direct dependency #1082

Merged
merged 2 commits into from
Aug 14, 2020

Conversation

cocreature
Copy link
Contributor

This PR fixes a bug where rootpath on a scala_binary resolved to the JAR instead of the wrapper binary.

This fixes a bug introduced by
#958. Before #958,
rootpath on a Scala binary resolved to the wrapper binary so other
rules could treat it as an opaque executable. After that PR rootpath
now resolves to the JAR instead of the wrapper binary.

Adding the executable back as a direct dependency fixes that.

Happy to try and add a test for this but I need some guidance how and where to test this.

Description

Motivation

@cocreature cocreature requested a review from ittaiz as a code owner July 27, 2020 18:41
@googlebot
Copy link

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

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@cocreature
Copy link
Contributor Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

This fixes a bug introduced by
bazelbuild#958. Before bazelbuild#958,
`rootpath` on a Scala binary resolved to the wrapper binary so other
rules could treat it as an opaque executable. After that PR `rootpath`
now resolves to the JAR instead of the wrapper binary.

Adding the executable back as a direct dependency fixes that.
# TODO:
# Per Bazel documentation, we should avoid using collect_data. The core phases need to be updated
# before we can make the adjustment.
runfiles = ctx.runfiles(transitive_files = depset(transitive = runfiles), collect_data = True),
runfiles = ctx.runfiles(transitive_files = depset(direct = direct, transitive = runfiles), collect_data = True),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ittaiz ittaiz closed this Jul 29, 2020
@ittaiz ittaiz reopened this Jul 29, 2020
@ittaiz
Copy link
Member

ittaiz commented Jul 29, 2020

Thanks!
What were you trying to do and failed? That's usually the test we want :)
If the bug means you can't run scala binaries then it sounds we roughly have two options here:

  1. We add an sh_test that depends on a scala_binary and tries to run that. I think that will work but not 100% sure and might require some tweaking. The plus side of this is that this test is part of bazel.
  2. We add an e2e bash test (see our bash tests in the root of the repo) which can call bazel run on a binary and see that it printed something you expect.

If it's something else (because you mention something about other rules) then this again relates to my first sentence.

I want us to merge this with a test.

@cocreature
Copy link
Contributor Author

sh_test should be good enough. That roughly mirrors what we were trying to do. I’ll see if I can get something working.

@cocreature
Copy link
Contributor Author

I added a testcase. It is slightly convoluted since rootpath in a sh_test has some special treatment in Bazel so we need to call it in a genrule to observe the difference. Without this patch you will only get the JAR in the rootpaths which was also the behavior before the PR I linked to.

@simuons
Copy link
Collaborator

simuons commented Aug 6, 2020

Hi @cocreature, could you run lint (ci is failing on that)?

@cocreature
Copy link
Contributor Author

Done, sorry I missed the failure.

@simuons
Copy link
Collaborator

simuons commented Aug 7, 2020

@ittaiz I think this is ready to be merged.

@ittaiz ittaiz merged commit 3b51ba7 into bazelbuild:master Aug 14, 2020
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.

4 participants