Repository: spack/spack

Issue:
Julia build fails with "ERROR: Invalid CPU name skylake_avx512."
Trying to `spack install julia` and `spack install julia@1.3.1` result in failures that end something like this:

```
[...]
  /tmp/hartzell/spack-stage/spack-stage-julia-1.4.0-54ipg6rhp7kuc6vd7btj7ikxiue7vq6l/spack-src/src/codegen.cpp: In function 'std::unique_ptr<llvm::Module> emit_function(jl_method_instance_t*, jl_code_info_t*, jl_valu
e_t*, size_t, jl_llvm_functions_t*, const jl_cgparams_t*)':
/tmp/hartzell/spack-stage/spack-stage-julia-1.4.0-54ipg6rhp7kuc6vd7btj7ikxiue7vq6l/spack-src/src/codegen.cpp:6597:34: warning: 'retval' may be used uninitialized in this function [-Wmaybe-uninitialized]
             ctx.builder.CreateRet(retval);
             ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
    LINK usr/lib/libjulia.so.1.4
Warning: git information unavailable; versioning information limited
    CC ui/repl.o
    LINK usr/bin/julia
Warning: git information unavailable; versioning information limited
    JULIA usr/lib/julia/corecompiler.ji
ERROR: Invalid CPU name skylake_avx512.
make[1]: *** [/tmp/hartzell/spack-stage/spack-stage-julia-1.4.0-54ipg6rhp7kuc6vd7btj7ikxiue7vq6l/spack-src/usr/lib/julia/corecompiler.ji] Error 1
make: *** [julia-sysimg-ji] Error 2
```

The discussion in this Julia bug report, https://github.com/JuliaLang/julia/issues/30850, and the linked [discourse thread](https://discourse.julialang.org/t/invalid-cpu-name-x86-64-error-when-building-with-march-x86-64/20115/5) indirectly suggest that Julia's trying to run a C compiler and is picking up my system's `gcc@4.8.5` (CentOS 7) instead of the `gcc@8.4.0` that I'm using.

Here's the spec:

```
[george.hartzell@172-16-193-119 spack-env-experiments]$ spack spec julia
Input spec
--------------------------------
julia

Concretized
--------------------------------
julia@1.4.0%gcc@8.4.0~cxx~mkl arch=linux-centos7-skylake_avx512
    ^cmake@3.17.0%gcc@8.4.0~doc+ncurses+openssl+ownlibs~qt arch=linux-centos7-skylake_avx512
        ^ncurses@6.2%gcc@8.4.0~symlinks+termlib arch=linux-centos7-skylake_avx512
            ^pkgconf@1.6.3%gcc@8.4.0 arch=linux-centos7-skylake_avx512
        ^openssl@1.1.1f%gcc@8.4.0+systemcerts arch=linux-centos7-skylake_avx512
            ^perl@5.30.1%gcc@8.4.0+cpanm+shared+threads arch=linux-centos7-skylake_avx512
                ^gdbm@1.18.1%gcc@8.4.0 arch=linux-centos7-skylake_avx512
                    ^readline@8.0%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
    ^m4@1.4.18%gcc@8.4.0 patches=3877ab548f88597ab2327a2230ee048d2d07ace1062efe81fc92e91b7f39cd00,fc9b61654a3ba1a8d6cd78ce087e7c96366c290bc8d2c299f09828d793b853c8 +sigsegv arch=linux-centos7-skylake_avx512
        ^libsigsegv@2.12%gcc@8.4.0 arch=linux-centos7-skylake_avx512
    ^python@3.7.6%gcc@8.4.0+bz2+ctypes+dbm~debug+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tix~tkinter~ucs4~uuid+zlib arch=linux-centos7-skylake_avx512
        ^bzip2@1.0.8%gcc@8.4.0+shared arch=linux-centos7-skylake_avx512
            ^diffutils@3.7%gcc@8.4.0 arch=linux-centos7-skylake_avx512
                ^libiconv@1.16%gcc@8.4.0 arch=linux-centos7-skylake_avx512
        ^expat@2.2.9%gcc@8.4.0+libbsd arch=linux-centos7-skylake_avx512
            ^libbsd@0.10.0%gcc@8.4.0 arch=linux-centos7-skylake_avx512
        ^gettext@0.20.1%gcc@8.4.0+bzip2+curses+git~libunistring+libxml2+tar+xz arch=linux-centos7-skylake_avx512
            ^libxml2@2.9.9%gcc@8.4.0~python arch=linux-centos7-skylake_avx512
                ^xz@5.2.5%gcc@8.4.0 arch=linux-centos7-skylake_avx512
            ^tar@1.32%gcc@8.4.0 arch=linux-centos7-skylake_avx512
        ^libffi@3.2.1%gcc@8.4.0 arch=linux-centos7-skylake_avx512
        ^sqlite@3.30.1%gcc@8.4.0+column_metadata+fts~functions~rtree arch=linux-centos7-skylake_avx512
```

### Information on your system

```
$ spack debug report
* **Spack:** 0.14.1-711-52a2375dd
* **Python:** 2.7.5
* **Platform:** linux-centos7-skylake_avx512
```

### Additional information

- [x] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [x] I have searched the issues of this repo and believe this is not a duplicate
- [ ] I have run the failing commands in debug mode and reported the output




Discussion:
I ran into this problem as well.  I was able to fix it by changing the JULIA_CPU_TARGET value from `skylake_avx512` to `skylake-avx512`.  Here's the git diff of the julia/package.py file
```
diff --git a/var/spack/repos/builtin/packages/julia/package.py b/var/spack/repos/builtin/packages/julia/package.py
index cd401dd9e..47ff9a5aa 100644
--- a/var/spack/repos/builtin/packages/julia/package.py
+++ b/var/spack/repos/builtin/packages/julia/package.py
@@ -159,8 +159,10 @@ def install(self, spec, prefix):
                     'JULIA_CPU_TARGET=generic'
                 ]
             else:
+                # LLVM is a little picky
+                target_str = str(spec.target).replace('_','-')
                 options += [
-                    'JULIA_CPU_TARGET={0}'.format(spec.target)
+                    'JULIA_CPU_TARGET={0}'.format(target_str)
                 ]
 
         if '%intel' in spec:
```

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
@@ -18,6 +18,9 @@ class Julia(Package):
     maintainers = ['glennpj']
 
     version('master', branch='master')
+    version('1.5.1', sha256='1d0debfccfc7cd07047aa862dd2b1a96f7438932da1f5feff6c1033a63f9b1d4')
+    version('1.5.0', sha256='4a6ffadc8dd04ca0b7fdef6ae203d0af38185e57b78f7c0b972c4707354a6d1b')
+    version('1.4.2', sha256='948c70801d5cce81eeb7f764b51b4bfbb2dc0b1b9effc2cb9fc8f8cf6c90a334')
     version('1.4.1', sha256='b21585db55673ac0668c163678fcf2aad11eb7c64bb2aa03a43046115fab1553')
     version('1.4.0', sha256='880c73a08296ce8d94ad9605149f2a2b2b028e7202a700ef725da899300b8be9')
     version('1.3.1', sha256='053908ec2706eb76cfdc998c077de123ecb1c60c945b4b5057aa3be19147b723')
@@ -159,8 +162,9 @@ def install(self, spec, prefix):
                     'JULIA_CPU_TARGET=generic'
                 ]
             else:
+                target_str = str(spec.target).replace('_', '-')
                 options += [
-                    'JULIA_CPU_TARGET={0}'.format(spec.target)
+                    'JULIA_CPU_TARGET={0}'.format(target_str)
                 ]
 
         if '%intel' in spec:


Test patch: