Repository: spack/spack

Issue:
Installation issue: Julia
### Steps to reproduce the issue

```console
$ spack spec -I julia@1.7.2
Input spec
--------------------------------
 -   julia@1.7.2

Concretized
--------------------------------
 -   julia@1.7.2%gcc@8.4.0+openlibm+precompile patches=8b993a2 arch=linux-centos7-skylake_avx512
[+]      ^curl@7.78.0%gcc@8.4.0~gssapi~ldap~libidn2~librtmp~libssh+libssh2+nghttp2 tls=mbedtls,openssl arch=linux-centos7-skylake_avx512
[+]          ^libssh2@1.10.0%gcc@8.4.0~ipo+shared build_type=RelWithDebInfo crypto=mbedtls arch=linux-centos7-skylake_avx512
[+]              ^cmake@3.22.3%gcc@8.4.0~doc+ncurses+openssl+ownlibs~qt build_type=Release arch=linux-centos7-skylake_avx512
[+]                  ^ncurses@6.2%gcc@8.4.0~symlinks+termlib abi=none arch=linux-centos7-skylake_avx512
[+]                      ^pkgconf@1.8.0%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                  ^openssl@1.1.1n%gcc@8.4.0~docs~shared certs=system arch=linux-centos7-skylake_avx512
[+]                      ^perl@5.34.0%gcc@8.4.0+cpanm+shared+threads arch=linux-centos7-skylake_avx512
[+]                          ^berkeley-db@18.1.40%gcc@8.4.0+cxx~docs+stl patches=b231fcc arch=linux-centos7-skylake_avx512
[+]                          ^bzip2@1.0.8%gcc@8.4.0~debug~pic+shared arch=linux-centos7-skylake_avx512
[+]                              ^diffutils@3.8%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                                  ^libiconv@1.16%gcc@8.4.0 libs=shared,static arch=linux-centos7-skylake_avx512
[+]                          ^gdbm@1.19%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                              ^readline@8.1%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                          ^zlib@1.2.11%gcc@8.4.0+optimize+pic+shared arch=linux-centos7-skylake_avx512
[+]              ^mbedtls@2.24.0%gcc@8.4.0+pic build_type=Release libs=shared,static patches=ab3db2c arch=linux-centos7-skylake_avx512
[+]              ^xz@5.2.5%gcc@8.4.0~pic libs=shared,static arch=linux-centos7-skylake_avx512
[+]          ^nghttp2@1.44.0%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]      ^dsfmt@2.2.5%gcc@8.4.0 patches=b79624c arch=linux-centos7-skylake_avx512
[+]      ^gmp@6.2.1%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^autoconf@2.69%gcc@8.4.0 patches=35c4492,7793209,a49dd5b arch=linux-centos7-skylake_avx512
[+]              ^m4@1.4.19%gcc@8.4.0+sigsegv patches=9dc5fbd,bfdffa7 arch=linux-centos7-skylake_avx512
[+]                  ^libsigsegv@2.13%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^automake@1.16.5%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^libtool@2.4.6%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]      ^libblastrampoline@3.1.0%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]      ^libgit2@1.4.2%gcc@8.4.0~curl~ipo+mmap+ssh build_type=RelWithDebInfo https=system arch=linux-centos7-skylake_avx512
[+]      ^libunwind@1.5.0%gcc@8.4.0~block_signals~conservative_checks~cxx_exceptions~debug~debug_frame+docs~pic+tests+weak_backtrace~xz~zlib components=none libs=shared,static arch=linux-centos7-skylake_avx512
[+]      ^libuv@1.42.0%gcc@8.4.0 patches=d9252fb arch=linux-centos7-skylake_avx512
[+]      ^libwhich@1.1.0%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]      ^llvm@12.0.1%gcc@8.4.0+clang~code_signing+compiler-rt~cuda~flang+gold~internal_unwind~ipo+libcxx+link_llvm_dylib+lld+lldb+llvm_dylib~mlir+omp_as_runtime~omp_debug~omp_tsan+polly~python~shared_libs~split_dwarf~z3 build_type=Release patches=10cb42f,88ae104 targets=amdgpu,bpf,nvptx,webassembly version_suffix=jl arch=linux-centos7-skylake_avx512
[+]          ^binutils@2.38%gcc@8.4.0~gas+gold~headers~interwork+ld~libiberty~lto+nls+plugins libs=shared,static arch=linux-centos7-skylake_avx512
[+]              ^gettext@0.21%gcc@8.4.0+bzip2+curses+git~libunistring+libxml2+tar+xz arch=linux-centos7-skylake_avx512
[+]                  ^libxml2@2.9.12%gcc@8.4.0~python arch=linux-centos7-skylake_avx512
[+]                  ^tar@1.34%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^hwloc@2.7.0%gcc@8.4.0~cairo~cuda~gl~libudev+libxml2~netloc~nvml~opencl+pci~rocm+shared arch=linux-centos7-skylake_avx512
[+]              ^libpciaccess@0.16%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                  ^util-macros@1.19.3%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^libedit@3.1-20210216%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^ninja@1.10.2%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]              ^python@3.9.10%gcc@8.4.0+bz2+ctypes+dbm~debug+ensurepip+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tix~tkinter~ucs4+uuid+zlib patches=0d98e93,4c24573,f2fd060 arch=linux-centos7-skylake_avx512
[+]                  ^expat@2.4.6%gcc@8.4.0+libbsd arch=linux-centos7-skylake_avx512
[+]                      ^libbsd@0.11.5%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                          ^libmd@1.0.4%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                  ^libffi@3.4.2%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                  ^sqlite@3.37.2%gcc@8.4.0+column_metadata+dynamic_extensions+fts~functions+rtree arch=linux-centos7-skylake_avx512
[+]                  ^util-linux-uuid@2.37.4%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^perl-data-dumper@2.173%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^swig@4.0.2%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]              ^pcre@8.45%gcc@8.4.0~jit+multibyte+utf arch=linux-centos7-skylake_avx512
[+]      ^mpfr@4.1.0%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^autoconf-archive@2019.01.06%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^texinfo@6.5%gcc@8.4.0 patches=12f6edb,1732115 arch=linux-centos7-skylake_avx512
[+]      ^openblas@0.3.20%gcc@8.4.0~bignuma~consistent_fpcsr+ilp64+locking+pic+shared symbol_suffix=64_ threads=none arch=linux-centos7-skylake_avx512
[+]      ^openlibm@0.7.5%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]      ^p7zip@16.02%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]      ^patchelf@0.14.5%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]      ^pcre2@10.39%gcc@8.4.0~jit+multibyte arch=linux-centos7-skylake_avx512
[+]      ^suite-sparse@5.10.1%gcc@8.4.0~cuda~graphblas~openmp+pic~tbb arch=linux-centos7-skylake_avx512
[+]          ^metis@5.1.0%gcc@8.4.0~gdb~int64~real64+shared build_type=Release patches=4991da9,b1225da arch=linux-centos7-skylake_avx512
[+]      ^utf8proc@2.6.1%gcc@8.4.0~ipo build_type=RelWithDebInfo arch=linux-centos7-skylake_avx512
```


### Error message

The build error occurs Julia's generation of precompile statements.  It seems to be related to [this Julia build issue ](https://github.com/JuliaLang/julia/pull/43250) where upgrading `libgit2` also required upgrading `libssh2`, `mbedtls` and `libcurl`.  Checking the above spec shows that the version of `libgit2` has been upgraded but not the other libraries.  Further, this build issue is not present when installing julia with the spec `julia@1.7.2^libgit2@1.1.1`.

<details><summary>Error message</summary><pre>
Generating REPL precompile statements... 26/36ERROR: LoadError: IOError: stream is closed or unusable
Stacktrace:
  [1] check_open
    @ ./stream.jl:386 [inlined]
  [2] uv_write_async(s::Base.TTY, p::Ptr{UInt8}, n::UInt64)
    @ Base ./stream.jl:1018
  [3] uv_write(s::Base.TTY, p::Ptr{UInt8}, n::UInt64)
    @ Base ./stream.jl:981
  [4] unsafe_write(s::Base.TTY, p::Ptr{UInt8}, n::UInt64)
    @ Base ./stream.jl:1064
  [5] write
    @ ./strings/io.jl:244 [inlined]
  [6] write
    @ ./io.jl:639 [inlined]
  [7] (::Main.anonymous.var"#2#6"{Set{String}, String, Base.DevNull})(precompile_file::String, precompile_file_h::IOStream)
    @ Main.anonymous /tmp/jmaack/spack-stage/spack-stage-julia-1.7.2-khiri6lxjuy73jrd5ophehgjormqogcz/spack-src/contrib/generate_precompile.jl:326
  [8] mktemp(fn::Main.anonymous.var"#2#6"{Set{String}, String, Base.DevNull}, parent::String)
    @ Base.Filesystem ./file.jl:722
  [9] mktemp
    @ ./file.jl:720 [inlined]
 [10] generate_precompile_statements()
    @ Main.anonymous /tmp/jmaack/spack-stage/spack-stage-julia-1.7.2-khiri6lxjuy73jrd5ophehgjormqogcz/spack-src/contrib/generate_precompile.jl:270
 [11] top-level scope
    @ /tmp/jmaack/spack-stage/spack-stage-julia-1.7.2-khiri6lxjuy73jrd5ophehgjormqogcz/spack-src/contrib/generate_precompile.jl:416
 [12] eval(m::Module, e::Any)
    @ Core ./boot.jl:373
 [13] top-level scope
    @ /tmp/jmaack/spack-stage/spack-stage-julia-1.7.2-khiri6lxjuy73jrd5ophehgjormqogcz/spack-src/contrib/generate_precompile.jl:6
in expression starting at /tmp/jmaack/spack-stage/spack-stage-julia-1.7.2-khiri6lxjuy73jrd5ophehgjormqogcz/spack-src/contrib/generate_precompile.jl:3
*** This error is usually fixed by running `make clean`. If the error persists, try `make cleanall`. ***
make[1]: *** [/tmp/jmaack/spack-stage/spack-stage-julia-1.7.2-khiri6lxjuy73jrd5ophehgjormqogcz/spack-src/usr/lib/julia/sys-o.a] Error 1
make[1]: Leaving directory `/tmp/jmaack/spack-stage/spack-stage-julia-1.7.2-khiri6lxjuy73jrd5ophehgjormqogcz/spack-src'
make: *** [julia-sysimg-release] Error 2
</pre></details>


### Information on your system

* **Spack:** 0.18.0.dev0 (048a0de35bd791f233d0a6f676d841d85e75aae7)
* **Python:** 3.6.8
* **Platform:** linux-centos7-skylake_avx512
* **Concretizer:** clingo

### Additional information

@glennpj  @haampie  @vchurav
[spack-build-env-mods.txt](https://github.com/spack/spack/files/8352739/spack-build-env-mods.txt)
[spack-build-env.txt](https://github.com/spack/spack/files/8352740/spack-build-env.txt)
[spack-build-out.txt](https://github.com/spack/spack/files/8352741/spack-build-out.txt)


### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have run `spack maintainers <name-of-the-package>` and **@mentioned** any maintainers
- [X] I have uploaded the build log and environment files
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:
Hm, is it a regression in libgit2? The error is not very telling. What's the newest libgit2 that works for you? 1.3.0 works? If so, can you add a `depends_on('libgit2@:1.3.0', when='@:1.7')` or something along these lines and submit a PR?
It works for libgit2@1.1.1.  I haven't tried it with anything later.  The PR [43250](https://github.com/JuliaLang/julia/pull/43250) and issue [43249](https://github.com/JuliaLang/julia/issues/43249) on the Julia github indicate it will also be an issue with libgit2 v1.3.0. The discussion in the PR indicates that mbedtls is a shared dependency between libgit2 and libssh2 and that libgit2 v1.3.0 and higher depend on mbedtls v2.28 (depend may not be the entirely correct word here).

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/julia/package.py b/var/spack/repos/builtin/packages/julia/package.py
--- a/var/spack/repos/builtin/packages/julia/package.py
+++ b/var/spack/repos/builtin/packages/julia/package.py
@@ -54,18 +54,22 @@ class Julia(MakefilePackage):
 
     with when('@1.7.0:1.7'):
         # libssh2.so.1, libpcre2-8.so.0, mbedtls.so.13, mbedcrypto.so.5, mbedx509.so.1
-        # openlibm.so.3, (todo: complete this list for upperbounds...)
-        depends_on('llvm@12.0.1')
+        # openlibm.so.3
+        depends_on('libblastrampoline@3.0.0:3')
+        depends_on('libgit2@1.1.0:1.1')
+        depends_on('libssh2@1.9.0:1.9')
         depends_on('libuv@1.42.0')
+        depends_on('llvm@12.0.1')
         depends_on('mbedtls@2.24.0:2.24')
         depends_on('openlibm@0.7.0:0.7', when='+openlibm')
-        depends_on('libblastrampoline@3.0.0:3')
 
     with when('@1.6.0:1.6'):
         # libssh2.so.1, libpcre2-8.so.0, mbedtls.so.13, mbedcrypto.so.5, mbedx509.so.1
         # openlibm.so.3, (todo: complete this list for upperbounds...)
-        depends_on('llvm@11.0.1')
+        depends_on('libgit2@1.1.0:1.1')
+        depends_on('libssh2@1.9.0:1.9')
         depends_on('libuv@1.39.0')
+        depends_on('llvm@11.0.1')
         depends_on('mbedtls@2.24.0:2.24')
         depends_on('openlibm@0.7.0:0.7', when='+openlibm')
 


Test patch: