Repository: spack/spack

Issue:
Installation issue: fpm
### Steps to reproduce the issue

```console
$ spack spec -I fpm
Input spec
--------------------------------
 -   fpm

Concretized
--------------------------------
 -   fpm@0.4.0%gcc@10.2.0+openmp arch=linux-centos7-broadwell
[+]      ^curl@7.79.0%gcc@10.2.0~gssapi~ldap~libidn2~librtmp~libssh~libssh2~nghttp2 tls=openssl arch=linux-centos7-broadwell
[+]          ^openssl@1.1.1l%gcc@10.2.0~docs certs=system arch=linux-centos7-broadwell
[+]              ^perl@5.34.0%gcc@10.2.0+cpanm+shared+threads arch=linux-centos7-broadwell
[+]                  ^berkeley-db@18.1.40%gcc@10.2.0+cxx~docs+stl patches=b231fcc4d5cff05e5c3a4814f6a5af0e9a966428dc2176540d2c05aff4
1de522 arch=linux-centos7-broadwell
[+]                  ^bzip2@1.0.8%gcc@10.2.0~debug~pic+shared arch=linux-centos7-broadwell
[+]                      ^diffutils@3.8%gcc@10.2.0 arch=linux-centos7-broadwell
[+]                          ^libiconv@1.16%gcc@10.2.0 libs=shared,static arch=linux-centos7-broadwell
[+]                  ^gdbm@1.19%gcc@10.2.0 arch=linux-centos7-broadwell
[+]                      ^readline@8.1%gcc@10.2.0 arch=linux-centos7-broadwell
[+]                          ^ncurses@6.2%gcc@10.2.0~symlinks+termlib abi=none arch=linux-centos7-broadwell
[+]                              ^pkgconf@1.8.0%gcc@10.2.0 arch=linux-centos7-broadwell
[+]                  ^zlib@1.2.11%gcc@10.2.0+optimize+pic+shared arch=linux-centos7-broadwell

$ spack install fpm
```


### Error message

<details><summary>Error message</summary><pre>
Initialized empty Git repository in /tmp/wyphan/spack-stage/spack-stage-fpm-0.4.0-6b7dpcrdo55u42qb4bqgsv5n3yp2w3lv/spack-src/build/d
ependencies/toml-f/.git/
Unknown option: -C
usage: git [--version] [--help] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]
[Error] Error while fetching git repository for remote dependency
ERROR STOP 1

Error termination. Backtrace:
#0  0x41dde3 in ???
#1  0x4925ba in ???
#2  0x494c7f in ???
#3  0x401c2c in ???
#4  0x7f72e2135554 in __libc_start_main
        at ../csu/libc-start.c:266
#5  0x401c5c in ???
#6  0xffffffffffffffff in ???
</pre></details>


### Information on your system

* **Spack:** 0.17.1
* **Python:** 3.7.3
* **Platform:** linux-centos7-broadwell
* **Concretizer:** clingo

My wild guess is `git` on this system is _too old_ not to have the `-C` flag. It's running CentOS 7, after all...

```console
$ cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
$ git --version
git version 1.8.3.1
```

[System specs](https://systems.nic.uoregon.edu/internal-wiki/index.php?title=Compute:_Delphi)


### Additional information

Summoning @awvwgk as the `fpm` maintainer.

[spack-build-env.txt](https://github.com/spack/spack/files/8506808/spack-build-env.txt)
[spack-build-out.txt](https://github.com/spack/spack/files/8506809/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:
Looks like git is too old, ~~can you share the git version used here?~~ I don't know the exact lower bound for git to support changing directories with `-C`.
1.8.3.1, yep definitely too old. I can either email the admin or take things into my own hands with `spack install git`, which route should I take?
Checking my notes... https://github.com/fortran-lang/fpm/pull/163, it is git 1.8.5 which implements `-C`, so a close miss.
Maybe we can require a git version in the fpm package file?
@awvwgk That sounds straightforward, do you wanna create the PR or should I do it?
Feel free to submit a patch for this.
Hmm. Looks like "upgrading" `git` is not enough to build `fpm` on this system... Here's the new stdout log:
```console
wyphan@delphi:~$ spack install fpm
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/berkeley-db-18.1.40-hswjnjwwwunnwvzgqyikspnefaqxg47w
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/libiconv-1.16-r6daiabrvwuntzdnmnw2ah5jvwk6qkl5
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/pkgconf-1.8.0-bca7yg54sdt6atfgmyn5geh7x7ff43rj
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/zlib-1.2.12-mov7pdk4gpgobyhudnkcf65eq7lmubqx
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/libsigsegv-2.13-icyih5jycnvn4ggqtukrlqxawryxcyhw
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/libmd-1.0.4-nen3kxugpgzoroaprswcfjbxr5ckkth7
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/xz-5.2.5-zdk3s4dwt3ka2ktkkgcnaqxcyuhiqowq
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/pcre2-10.39-uvvbkkgfbi2lqansoxyijfqv73cleowo
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/tar-1.34-r536onzhlu6mp2o33ldoozf5uklr6v6v
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/diffutils-3.8-zkssnr2mvef3djsavlv4hdudb2qi7jsf
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/libunistring-0.9.10-dlbt7fzv3wpwqthw4qaorkikii566hy2
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/ncurses-6.2-ytenty4jsjxjiceqovigubalb5yvzdlc
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/m4-1.4.19-jmeadgepohuewdv2ccyf4nrqvlvipum2
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/libbsd-0.11.5-snkxiejw2vsi6dv5usoz4twa2xeq4qar
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/libxml2-2.9.12-t5cqvetrrhcaxrc5z4svuoohtk7qcnwz
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/bzip2-1.0.8-ivqelsdsklixapgh7kmvqxe6ahk47wkz
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/libidn2-2.3.0-23ctojn4vz4ernvgwhthhclvecbqnbxg
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/libedit-3.1-20210216-svpaujzsbxdsuhwsomih3ptrexdyefzn
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/readline-8.1-uhypwcr7c4ud7mbs2j4phn6a3uwdwv5j
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/libtool-2.4.7-ri66d3uphmlrk2ww3im4tkj762ywbel7
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/expat-2.4.8-4lklqnkmiw2laonwczhth2adjfbgal3l
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/gettext-0.21-flyzzi54jhkt2f7rgb5k2vd7d7jdukwz
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/gdbm-1.19-hux5ze5etcpfq4zg5cgour3d7nlp4hdx
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/perl-5.34.1-h7mvghav4bsz3qlq7bzijl77yo2sy5kf
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/openssl-1.1.1n-zrdfnvapfp3uthqz7vasvs7jhptcorme
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/autoconf-2.69-5fpank5wlkgjwllxq7tqxgpt2nk7kgas
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/curl-7.82.0-h4rugonkcghilnurnxoe5yopw7bnzkxw
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/openssh-8.9p1-tm4uf77rzchb6xk5b62glwhdlx32p7xy
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/automake-1.16.5-lpjlttlprrh4fniva4yvk544yrsadyix
[+] /storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/git-2.35.1-qm4aee4ten6mftqxm35km4oeg6nci6nt
==> Installing fpm-0.5.0-gjykcxj5pz5vki5jz3pyrqk563d22zl3
==> No binary for fpm-0.5.0-gjykcxj5pz5vki5jz3pyrqk563d22zl3 found: installing from source
==> Using cached archive: /storage/users/wyphan/spack/var/spack/cache/_source-cache/archive/e4/e4a06956d2300f9aa1d06bd3323670480e94
6549617582e32684ded6921a921e.zip
==> No patches needed for fpm
==> fpm: Executing phase: 'install'
==> Error: ProcessError: ./install.sh: Permission denied
    Command: './install.sh' '--prefix=/storage/users/wyphan/spack/opt/spack/linux-centos7-broadwell/gcc-10.2.0/fpm-0.5.0-gjykcxj5pz
5vki5jz3pyrqk563d22zl3'
See build log for details:
  /tmp/wyphan/spack-stage/spack-stage-fpm-0.5.0-gjykcxj5pz5vki5jz3pyrqk563d22zl3/spack-build-out.txt
```
What now, a forgotten `chmod +x`? :joy: 
The install script is for sure marked as executable in the fpm repository, not sure where it could loose this property again.
@alalazo Can you reopen this issue, since it's not fully resolved yet?
From posts I've perused it seems like retaining permissions can be an issue with different fetchers.  As I mentioned in the user meeting, the safest thing to do would be to use `os.chmod` to ensure the script is executable before you try to run it.
PR incoming with `os.chmod`.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/fpm/package.py b/var/spack/repos/builtin/packages/fpm/package.py
--- a/var/spack/repos/builtin/packages/fpm/package.py
+++ b/var/spack/repos/builtin/packages/fpm/package.py
@@ -3,6 +3,9 @@
 #
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
 
+import os
+import stat
+
 from spack import *
 
 
@@ -51,7 +54,12 @@ def install(self, spec, prefix):
         This functionality is provided by the ``install.sh`` script.
         """
 
-        script = Executable("./install.sh")
+        # Perform `chmod +x ./install.sh`
+        script_path = './install.sh'
+        st = os.stat(script_path)
+        os.chmod(script_path, st.st_mode | stat.S_IXUSR)
+
+        script = Executable(script_path)
         script(*self.install_args())
 
     def install_args(self):


Test patch: