Repository: spack/spack

Issue:
Installation issue: bazel fails to build
### Steps to reproduce the issue

```
$ spack install bazel

==> Installing bazel-4.0.0-u3zmjotv372qzjcky26tggyhwic4tscq
==> No binary for bazel-4.0.0-u3zmjotv372qzjcky26tggyhwic4tscq found: installing from source
==> Fetching https://mirror.spack.io/_source-cache/archive/d3/d350f80e70654932db252db380d2ec0144a00e86f8d9f2b4c799ffdb48e9cdd1.zip
==> Applied patch /projects/spack-contrib/spack/var/spack/repos/builtin/packages/bazel/bazelruleclassprovider-0.25.patch
==> Applied patch /projects/spack-contrib/spack/var/spack/repos/builtin/packages/bazel/unix_cc_configure-3.0.patch
==> Applied patch /projects/spack-contrib/spack/var/spack/repos/builtin/packages/bazel/compile-0.29.patch
==> Applied patch /projects/spack-contrib/spack/var/spack/repos/builtin/packages/bazel/disabledepcheck.patch
==> bazel: Executing phase: 'bootstrap'
==> Error: ProcessError: Command exited with status 1:
    '/usr/bin/bash' './compile.sh'

8 errors found in build log:
     13
     14
     15
     16
     17       Loading: 0 packages loaded
     18
  >> 19       DEBUG: /tmp/bazel_rgoLXkjb/out/external/bazel_toolchains/rules/rbe_repo/version_check.bzl:59:14:
     20       Current running Bazel is not a release version and one was not defined explicitly in rbe_autoconfig target. Falling back to '3.1.0'
     21       Loading: 0 packages loaded
     22
  >> 23       DEBUG: /tmp/bazel_rgoLXkjb/out/external/bazel_toolchains/rules/rbe_repo/checked_in.bzl:103:14: rbe_ubuntu1804_java11 not using checked
              in configs as detect_java_home was set to True
     24       Loading: 0 packages loaded
     25
  >> 26       DEBUG: /tmp/bazel_rgoLXkjb/out/external/bazel_toolchains/rules/rbe_repo/version_check.bzl:59:14:
     27       Current running Bazel is not a release version and one was not defined explicitly in rbe_autoconfig target. Falling back to '3.1.0'
     28       Loading: 0 packages loaded
     29
  >> 30       DEBUG: /tmp/bazel_rgoLXkjb/out/external/bazel_toolchains/rules/rbe_repo/checked_in.bzl:103:14: rbe_ubuntu1604_java8 not using checked i
              n configs as detect_java_home was set to True
     31       Loading: 0 packages loaded
     32
     33       Loading: 0 packages loaded
     34           Fetching @io_bazel_skydoc; fetching
     35
     36

     ...

     99727        SPACK_TARGET_ARGS='-march=sandybridge -mtune=sandybridge' \
     99728      /bin/bash \
     99729        -c \
     99730        'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/host/bin/src/create_embedded_tools "bazel-out/k8-opt/bin/src
              /embedded_tools_nojdk.zip" bazel-out/k8-opt/bin/src/embedded_tools_nojdk.params')
     99731    [1,130 / 1,148] [Prepa] Executing genrule //src:embedded_tools_nojdk
     99732
  >> 99733    ERROR: /tmp/mdorier/spack-stage/spack-stage-bazel-4.0.0-u3zmjotv372qzjcky26tggyhwic4tscq/spack-src/src/BUILD:309:9: Executing genrule /
              /src:embedded_tools_nojdk failed: (Exit 127): bash failed: error executing command
     99734      (cd /tmp/bazel_rgoLXkjb/out/execroot/io_bazel && \
     99735      exec env - \
     99736        PATH=/projects/spack-contrib/spack/opt/spack/linux-ubuntu21.04-sandybridge/gcc-10.3.0/zip-3.0-kzoo4t6fwcks5x7zq2ltp6r2ehaha3or/bin:
              /projects/spack-contrib/spack/opt/spack/linux-ubuntu21.04-sandybridge/gcc-10.3.0/openjdk-11.0.12_7-5coywhserbxllsh47bwtgdfwv4kcsp5f/bin
              :/projects/spack-contrib/spack/lib/spack/env/gcc:/projects/spack-contrib/spack/lib/spack/env/case-insensitive:/projects/spack-contrib/s
              pack/lib/spack/env:/projects/spack-contrib/spack/bin:/projects/spack/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/
              usr/games:/usr/local/games:/snap/bin:/home/mdorier/.local/bin \
     99737        SPACK_CC=/usr/bin/gcc \
     99738        SPACK_CC_RPATH_ARG=-Wl,-rpath, \
     99739        SPACK_COMPILER_SPEC=gcc@10.3.0 \

     ...

     99759        SPACK_SYSTEM_DIRS=/bin:/usr/bin:/usr/local/bin:/bin64:/usr/bin64:/usr/local/bin64:/include:/usr/include:/usr/local/include:/lib:/us
              r/lib:/usr/local/lib:/lib64:/usr/lib64:/usr/local/lib64:/:/usr:/usr/local \
     99760        SPACK_TARGET_ARGS='-march=sandybridge -mtune=sandybridge' \
     99761      /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/host/bin/src/create_embedded_tools "bazel-out/k8-
              opt/bin/src/embedded_tools_nojdk.zip" bazel-out/k8-opt/bin/src/embedded_tools_nojdk.params')
     99762    Execution platform: //:default_host_platform
     99763    [1,131 / 1,148] checking cached actions
     99764
  >> 99765    /usr/bin/env: 'python': No such file or directory
     99766    [1,131 / 1,148] checking cached actions
     99767
     99768    [1,131 / 1,148] checking cached actions
     99769
     99770    Target //src:bazel_nojdk failed to build
     99771    [1,131 / 1,148] checking cached actions

     ...

     99773    INFO: Elapsed time: 444.197s, Critical Path: 16.25s
     99774    [1,131 / 1,148] checking cached actions
     99775
     99776    INFO: 1131 processes: 22 internal, 1109 local.
     99777    [1,131 / 1,148] checking cached actions
     99778
  >> 99779    FAILED: Build did NOT complete successfully
     99780
  >> 99781    FAILED: Build did NOT complete successfully
     99782
     99783    ERROR: Could not build Bazel
```

I have tried with bazel@3.4.0 and bazel@4.0.0 (the latest). Both fail (so I suspect other versions in-between will fail as well). Build logs are attached.
@adamjstewart 

[bazel-3.4.0-build-out.txt](https://github.com/spack/spack/files/7822639/bazel-3.4.0-build-out.txt)
[bazel-4.0.0-build-out.txt](https://github.com/spack/spack/files/7822643/bazel-4.0.0-build-out.txt)

### Information on your system

* **Spack:** 0.11.2-16007-88a7774f69
* **Python:** 3.9.5
* **Platform:** linux-ubuntu21.04-sandybridge
* **Concretizer:** clingo

### Additional information

_No response_

### 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:
@aweits 
The missing Python is surprising. Can you try adding a dependency on Python to the package?
There is already `depends_on('python', type=('build', 'run'))`. Note that it seems to be looking for a "python" but when installing a python 3 interpreter, you don't get a "python" executable. You get a "python3" one (here spack installed python 3.9.5 as part of the build).

EDIT: actually spack used my system's python 3.9.5 as told by my packages.yaml file. My system doesn't have a "python" executable, only a "python3". I am not sure whether it's specific to my ubuntu system or whether a spack-installed python would also result in only having a python3 executable.
looking
I don't see a spack python in the PATH, do you have python declared as external or something along those lines?
Yes, Python is my Ubuntu's system python 3.9.5, in /usr/bin, exposed to spack via my packages.yaml file.
Ah I see your edit now. Is that normal for ubuntu to not have a "python" binary? That's probably going to cause lots of other issues...
Yes, that's normal. If `bazel` needs a `python` executable we should change the dependency to `python+pythoncmd`.
It seems that on my Ubuntu I needed to `apt install python-is-python3` to get the `python` command. I'll retry building bazel now...
hm, the 3.4.0 log seems indicate the use of /usr/bin/gcc rather than the spack wrappers...
I can confirm that bazel@4.0.0 now installs fine with the python-is-python3.

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
@@ -110,7 +110,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')
 
     depends_on('java', type=('build', 'run'))
-    depends_on('python', type=('build', 'run'))
+    depends_on('python+pythoncmd', type=('build', 'run'))
     depends_on('zip', when='platform=linux', type=('build', 'run'))
 
     # make work on power9 (2x commits)
diff --git a/var/spack/repos/builtin/packages/python/package.py b/var/spack/repos/builtin/packages/python/package.py
--- a/var/spack/repos/builtin/packages/python/package.py
+++ b/var/spack/repos/builtin/packages/python/package.py
@@ -271,6 +271,13 @@ def determine_variants(cls, exes, version_str):
         python = Executable(exes[0])
 
         variants = ''
+        for exe in exes:
+            if os.path.basename(exe) == 'python':
+                variants += '+pythoncmd'
+                break
+        else:
+            variants += '~pythoncmd'
+
         for module in ['readline', 'sqlite3', 'dbm', 'nis',
                        'zlib', 'bz2', 'lzma', 'ctypes', 'uuid']:
             try:


Test patch: