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 _jdk dependency to binary runfiles and scalac action #172

Merged
merged 1 commit into from
Mar 28, 2017

Conversation

sdtwigg
Copy link
Contributor

@sdtwigg sdtwigg commented Mar 28, 2017

The default @local_jdk just imports _java and _javac as raw binaries
without establishing a dependency on/runfiles of _jdk. Thus, all uses of
those should manually add _jdk as a dependency.

In the scalac execution ation that compiles scala, also added _jdk in
case _scalac ever was replaced by a binary that wasn't a java_binary.

Haven't been able to test locally in a hermetic system with the default local_jdk so should wait until CI green before integrating....

@bazel-io
Copy link
Member

Can one of the admins verify this patch?

@ittaiz
Copy link
Member

ittaiz commented Mar 28, 2017 via email

@ittaiz
Copy link
Member

ittaiz commented Mar 28, 2017

@johnynek @damienmg can one of you please trigger this for ci.bazel.io?
It seems travis doesn't provide confidence since it doesn't run the build sandboxed

@sdtwigg
Copy link
Contributor Author

sdtwigg commented Mar 28, 2017

test this please

@damienmg
Copy link
Contributor

Test this please.

@johnynek
Copy link
Member

is this a bug in bazel? Why do we need to explicitly add this dep? cc @damienmg

scala/scala.bzl Outdated
# compile_jars += [target.java.outputs.ijar]
compile_jars += target.java.transitive_deps
compile_jars += [output.ijar for output in target.java.outputs.jars]
# compile_jars += target.java.transitive_deps
Copy link
Member

Choose a reason for hiding this comment

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

can we remove this comment now?

@@ -362,8 +366,8 @@ def _collect_jars(targets):
# see JavaSkylarkApiProvider.java,
# this is just the compile-time deps
# this should be improved in bazel 0.1.5 to get outputs.ijar
Copy link
Member

Choose a reason for hiding this comment

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

and remove this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted that part of the change. Amended comment.

My fear is that transitive_deps to ijar COULD break code (although technically code that was making incorrect assumptions anyway). However, I was hoping for this PR to strictly decrease number of breakages.

@sdtwigg
Copy link
Contributor Author

sdtwigg commented Mar 28, 2017

retest this please

@damienmg
Copy link
Contributor

Not sure if that's a bug but according to @sdtwigg we don't do it internally so I would say we should just fix the dependencies in Bazel.

@ittaiz
Copy link
Member

ittaiz commented Mar 28, 2017

@sdtwigg why is the last commit needed? ci.bazel.io was green before it, wasn't it?

The default @local_jdk just imports _java and _javac as raw binaries
without establishing a dependency on/runfiles of _jdk. Thus, all uses of
those should manually add _jdk as a dependency.

In the scalac execution ation that compiles scala, also added _jdk in
case _scalac ever was replaced by a binary that wasn't a java_binary.

_jar_bin does not need a _jdk dependency since is itself a java_binary

Note that earlier versions of this PR had a change to use ijars. This
was reverted (although the comment referring to using ijar amended to
the proper line) to keep this PR as a purely bugfix PR that should
strictly increase the chance something compiles
@damienmg
Copy link
Contributor

According to the screen in our office, ci is red on darwin at HEAD: http://ci.bazel.io/job/rules_scala/684/

@sdtwigg
Copy link
Contributor Author

sdtwigg commented Mar 28, 2017

It was not. There was a ctx.action in _build_nosrc_jar that was also invoking _java. The original commit was specifically targeted at fixing up the binary runfiles (and the scalac inputs because I had thought of it).

The second commit was after I realized it was still failing and did an 'audit' (ctrl-f for ctx.action and ctx.runfiles) for what all needed a _jdk.

The third commit was to undo the change to using ijar from java provider. (That was an experimental change that had snuck in on accident since I had done some experiments in my personal tree on switching to java_common stuff). That change did seem to work but I am nervous about using it without more extensive testing.

Finally, the fourth is just the first three all rebased together so the merge commit message makes sense.

@ittaiz
Copy link
Member

ittaiz commented Mar 28, 2017

@sdtwigg I understand. Are there changes which aren't protected by a test? The reason this troubles me is since it can break without us noticing. I understand the reason for the scalac case future-proofing and that has a comment. Any other cases? And do they have a big red flag comment on them?

@sdtwigg
Copy link
Contributor Author

sdtwigg commented Mar 28, 2017

Are you referring to potential future changes that silently break or changes from #171 that might still be wrong?

Regardless....
Over the weekend, I was able to spend some time actually unpacking how ctx.action found its runfiles as well as what each argument in ctx.runfiles actually meant/where to find runfiles associated with targets. Quick summary of findings:

  • ctx.action will look through all of its inputs and will only add runfiles to those inputs that are coming from attributes marked as executable=True. (This is why I suggest using ctx.executable._whatever in a ctx.action, to ensure that either the action will pickup runfiles or error if the target gets unmarked as an executable).
  • ctx.runfiles files and transitive_files both just add runfiles to the same list. transitive_files is just a 'lazier' flattening (a depset) and so is slightly more efficient way to pass in transitive runfiles from dependencies. Notw that ctx.runfiles itself does not transitive searching (excluding collect_data and collect_default, which would only search deps, srcs, and data attributes anyway).
  • ctx.attr.*.data_runfiles|default_runfiles should have runfiles for 'any labe'l attr (not extensively tested but bazel code seems to confirm), regardless of whether it was marked as executable or not or was created by a rule that returned a runfiles 'provider' . (In the latter case, would just get an empty depset).

Really, _java and _javac threw me a bit for a loop since they are executable but don't actually attach their needed runfiles. (_jar and _jar_bin should be fine since they are the deploy_jar and binary-via-launcher from a java_binary rule, respectively. Thus, they should both setup runfiles, including a JDK.)

@ittaiz
Copy link
Member

ittaiz commented Mar 28, 2017

Concerned about

potential future changes that silently break

@ittaiz
Copy link
Member

ittaiz commented Mar 28, 2017

To be more accurate- about potential future changes that silently break in rules_scala build but loudly break for users which, for some reason, depend on this behavior.

@johnynek johnynek merged commit 21ebd9c into bazelbuild:master Mar 28, 2017
@johnynek
Copy link
Member

Thanks for the fix @sdtwigg

@johnynek
Copy link
Member

johnynek commented Mar 29, 2017 via email

@ittaiz
Copy link
Member

ittaiz commented Mar 29, 2017 via email

@sdtwigg
Copy link
Contributor Author

sdtwigg commented Mar 29, 2017

Nothing immediately comes to mind; however, Bazel/Linux sandboxing isn't my area of expertise.

It is odd that only Darwin/macOS was so sensitive to sandboxing and neither of the Linux-based CI targets. I did test these rules locally with bazel 0.4.5 on my workstation, completely isolated from our regular build environment, although unfortunately it clearly wasn't completely sandboxed. Then, when I tested it in our regular build environment (which is substantially better at ensuring sandboxing), as Damien mentioned, there were a few subtle differences in how the local_jdk equivalent is actually setup causing me not to notice the issue. Fortunately, I should be more aware about checking for this in the future (and added the comments for others who might be similarly tempted to remove those inputs).

That said, I'm hoping that the reliance on knowing that java (and probably javac) has an undeclared dependency on the a jdk is temporary and that the local_jdk workspace is changed to be more honest about setting up runfiles for its executables.

I did try to add tests in a wider range of test scenarios in #171. For example, running a scala_binary in a test or genrule simply did not work for me before. I was also hoping to do some tests, eventually, with a scala_binary calling a java_binary or scala_binary given to it as a data dependency or as a command-line arg in a genrule. This would hopefully expose if exporting JAVA_RUNFILES was good or bad. (Although, would need to start with tests using just java_binary to see what the 'expected' behaviors/patterns are for these scenarios.)

@ittaiz
Copy link
Member

ittaiz commented Mar 29, 2017

Ok. I think since we're aiming for an actual fix in bazel itself we can move on.
Thanks for the explanation.

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.

6 participants