Repository: spack/spack

Issue:
Bazel Java requirement
I was trying to build py-tensorflow and it was failing along the way when trying to build bazel. I was getting a java out of memory error:

The system is out of resources.
Consult the following stack trace for details.
java.lang.OutOfMemoryError: Java heap space
	at com.sun.tools.javac.code.Scope$ImportScope.makeEntry(Scope.java:530)
	at com.sun.tools.javac.code.Scope.enter(Scope.java:220)
	at com.sun.tools.javac.comp.MemberEnter$4.importFrom(MemberEnter.java:326)
	at com.sun.tools.javac.comp.MemberEnter$4.run(MemberEnter.java:334)
	at com.sun.tools.javac.comp.Annotate.flush(Annotate.java:143)
	at com.sun.tools.javac.comp.Annotate.enterDone(Annotate.java:129)
	at com.sun.tools.javac.comp.Enter.complete(Enter.java:512)
	at com.sun.tools.javac.comp.Enter.main(Enter.java:471)
	at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:982)
	at com.sun.tools.javac.main.JavaCompiler.enterTreesIfNeeded(JavaCompiler.java:965)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1242)
	at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
	at com.sun.tools.javac.main.Main.compile(Main.java:523)
	at com.sun.tools.javac.main.Main.compile(Main.java:381)
	at com.sun.tools.javac.main.Main.compile(Main.java:370)
	at com.sun.tools.javac.main.Main.compile(Main.java:361)
	at com.sun.tools.javac.Main.compile(Main.java:56)
	at com.sun.tools.javac.Main.main(Main.java:42)


This happened when trying to build against openjdk@1.8.0. I did some tinkering and found that if I removed the restriction of depending on java@8, that I was able to get bazel@0.26.1 to build with openjdk@11.0.2. I can submit a PR to such effect, but I would rather consult with folks to see if there really is a java@8 dependency or if that dependency is isolated to particular versions of bazel.


Discussion:
The reason for the `java@8` dependency is https://docs.bazel.build/versions/master/install-compile-source.html#bootstrap-unix-prereq:

> JDK 8. You must install version 8 of the JDK. Versions other than 8 are not supported.

I agree, I've managed to install Bazel with newer versions of JDK as well. I would open an issue with the Bazel developers to better understand the OOM error, @healther encountered the exact same problem: https://github.com/bazelbuild/bazel/issues/new

Personally, I've had better luck with `jdk` than `openjdk` if that helps.
If unrestricting the java dependency works for both oracle and openjdk, I'd propose we do that. Reality should beat documentation if both are in disagreement. I didn't find the time to dig deeper but when I'm getting back to it I'll try that one out.

@adamjstewart did you test with oracle's JDK? I'm not sure if I even have access to it
I only got Oracle JDK working. JDK is no longer available for download with the hacks we have in the JDK package, I had to create an account, log in, manually download the tarball, and place it in my mirror.
> Reality should beat documentation if both are in disagreement.

:slightly_smiling_face:

AFAICT the docs are out of date.  Unclear, it seems they support Java 10 and 11 [as of `bazel@0.28.0`](https://github.com/bazelbuild/bazel/issues/6245#issuecomment-501649882)?  I don't understand enough about bazel or java to really know what the different components they were asking for were.  

But is there a way to make this `depends_on('java', type=('build', 'run'))`?  I don't get the version number ranges for `spack providers java`, but right now `bazel` has a hard dependency on `jdk`.  It seems like the default provider for `java` is `openjdk` (???), so for things like `py-tensorflow` the `jdk` thing is an unnecessary road block.  I was able to get `0.26.1` to build for tensorflow using `java` rather than `jdk`, it ended up using `openjdk` 11.

So I guess if there's no way to get valid virtual dependency version numbers for `java` in order, I'd rather just make `depends_on('java', ...)` be the thing in bazel.  It seems to be successful with later `openjdk` for people (myself included).

**Edit**: after skimming some related issues, it seems maybe this one is on hold because of #14234

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/bazel/package.py b/var/spack/repos/builtin/packages/bazel/package.py
--- a/var/spack/repos/builtin/packages/bazel/package.py
+++ b/var/spack/repos/builtin/packages/bazel/package.py
@@ -3,9 +3,6 @@
 #
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
 
-from spack import *
-import platform
-
 
 class Bazel(Package):
     """Bazel is an open-source build and test tool similar to Make, Maven, and
@@ -96,14 +93,7 @@ class Bazel(Package):
 
     variant('nodepfail', default=True, description='Disable failing dependency checks due to injected absolute paths - required for most builds using bazel with spack')
 
-    # https://docs.bazel.build/versions/master/install-compile-source.html#bootstrap-bazel
-    # Until https://github.com/spack/spack/issues/14058 is fixed, use jdk to build bazel
-    # Strict dependency on java@8 as per
-    # https://docs.bazel.build/versions/master/install-compile-source.html#bootstrap-unix-prereq
-    if platform.machine() == 'aarch64':
-        depends_on('java@8:8.999', type=('build', 'run'))
-    else:
-        depends_on('jdk@1.8.0:1.8.999', type=('build', 'run'))
+    depends_on('java', type=('build', 'run'))
     depends_on('python', type=('build', 'run'))
     depends_on('zip', type=('build', 'run'))
 


Test patch: