Repository: spack/spack

Issue:
Installation issue: expect
### Steps to reproduce the issue

```console
$ spack install expect
...
configure: error: could not find source file 'pty_.c'
```

### Information on your system

* **Spack:** 0.15.4-1827-dcd514c321
* **Python:** 3.8.6
* **Platform:** darwin-catalina-ivybridge

### Additional information

* [spack-build-out.txt](https://github.com/spack/spack/files/5497786/spack-build-out.txt)
* [spack-build-env.txt](https://github.com/spack/spack/files/5497788/spack-build-env.txt)

Seems related to http://expect.sourceforge.net/FAQ.html#q42

Don't see any special hacks in https://github.com/Homebrew/homebrew-core/blob/master/Formula/expect.rb

### 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:
From reading the `configure` script, it seems like the problem is that the build is looking for `pty_${PTY_TYPE}.c`, but `PTY_TYPE` isn't being detected correctly. If I manually set `PTY_TYPE` to `termios` or `sgttyb`, I can get past this issue, but then I encounter other build problems with Apple Clang 12:
```
     337        if (!interruptible) {
     338        ^~~~~~~~~~~~~~~~~~~~
     339    exp_inter.c:440:11: note: initialize the variable 'cc' to silence this warning
     340        int cc;
     341              ^
     342               = 0
  >> 343    exp_inter.c:763:13: error: variable has incomplete type 'exp_tty' (aka 'struct TERMINAL')
     344        exp_tty tty_old;
     345                ^
     346    ./exp_tty_in.h:93:16: note: forward declaration of 'struct TERMINAL'
     347    typedef struct TERMINAL exp_tty;
     348                   ^
  >> 349    exp_tty.c:106:14: error: incomplete definition of type 'struct TERMINAL'
     350                    tty_current.sg_flags |= ECHO;
     351                    ~~~~~~~~~~~^
     352    ./exp_tty_in.h:93:16: note: forward declaration of 'struct TERMINAL'
     353    typedef struct TERMINAL exp_tty;
     354                   ^
  >> 355    exp_tty.c:106:27: error: use of undeclared identifier 'ECHO'
     356                    tty_current.sg_flags |= ECHO;
     357                                            ^
  >> 358    exp_tty.c:108:14: error: incomplete definition of type 'struct TERMINAL'
     359                    tty_current.sg_flags &= ~ECHO;
     360                    ~~~~~~~~~~~^
     361    ./exp_tty_in.h:93:16: note: forward declaration of 'struct TERMINAL'
     362    typedef struct TERMINAL exp_tty;
     363                   ^
  >> 364    exp_tty.c:108:28: error: use of undeclared identifier 'ECHO'
     365                    tty_current.sg_flags &= ~ECHO;
     366                                             ^
  >> 367    exp_tty.c:118:9: error: implicit declaration of function 'tcsetattr' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
     368            return(tcsetattr(exp_dev_tty, TCSADRAIN,tty));
     369                   ^
  >> 370    exp_tty.c:118:32: error: use of undeclared identifier 'TCSADRAIN'
     371            return(tcsetattr(exp_dev_tty, TCSADRAIN,tty));
     372                                          ^
  >> 373    exp_tty.c:128:9: error: implicit declaration of function 'tcgetattr' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
     374            return(tcgetattr(exp_dev_tty,         tty));
     375                   ^
  >> 376    exp_tty.c:147:11: error: incomplete type 'exp_tty' (aka 'struct TERMINAL') is not assignable
     377            *tty_old = tty_current;         /* save old parameters */
     378            ~~~~~~~~ ^
     379    ./exp_tty_in.h:93:16: note: forward declaration of 'struct TERMINAL'
     380    typedef struct TERMINAL exp_tty;
     381                   ^
  >> 382    exp_tty.c:183:11: error: incomplete type 'exp_tty' (aka 'struct TERMINAL') is not assignable
     383            *tty_old = tty_current;         /* save old parameters */
     384            ~~~~~~~~ ^
     385    ./exp_tty_in.h:93:16: note: forward declaration of 'struct TERMINAL'
     386    typedef struct TERMINAL exp_tty;
     387                   ^
  >> 388    exp_tty.c:225:14: error: incomplete type 'exp_tty' (aka 'struct TERMINAL') is not assignable
     389            tty_current = *tty;
     390            ~~~~~~~~~~~ ^
     391    ./exp_tty_in.h:93:16: note: forward declaration of 'struct TERMINAL'
     392    typedef struct TERMINAL exp_tty;
     393                   ^
  >> 394    exp_tty.c:264:2: error: implicit declaration of function 'tcsendbreak' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
     395            tcsendbreak(fd,0);
     396            ^
  >> 397    exp_tty.c:484:16: error: incomplete type 'exp_tty' (aka 'struct TERMINAL') is not assignable
     398                                    tty_cooked = tty_current;
     399                                    ~~~~~~~~~~ ^
     400    ./exp_tty_in.h:93:16: note: forward declaration of 'struct TERMINAL'
     401    typedef struct TERMINAL exp_tty;
     402                   ^
  >> 403    exp_tty.c:624:3: error: implicit declaration of function 'tcsetattr' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
     404                    tcsetattr(exp_dev_tty,TCSADRAIN, &tty_current) == -1
     405                    ^
  >> 406    exp_tty.c:624:25: error: use of undeclared identifier 'TCSADRAIN'
     407                    tcsetattr(exp_dev_tty,TCSADRAIN, &tty_current) == -1
     408                                          ^
  >> 409    exp_tty.c:681:6: error: implicit declaration of function 'tcgetattr' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
     410                tcgetattr(exp_dev_tty, &tty_current) == -1
     411                ^
  >> 412    exp_tty.c:697:15: error: incomplete type 'exp_tty' (aka 'struct TERMINAL') is not assignable
     413                            tty_cooked = tty_current;
     414                            ~~~~~~~~~~ ^
     415    ./exp_tty_in.h:93:16: note: forward declaration of 'struct TERMINAL'
     416    typedef struct TERMINAL exp_tty;
     417                   ^
     418    1 warning and 16 errors generated.
  >> 419    make: *** [exp_tty.o] Error 1
     420    make: *** Waiting for unfinished jobs....
     421    4 warnings and 1 error generated.
  >> 422    make: *** [exp_inter.o] Error 1
     423    In file included from expect.c:44:
     424    ./retoglob.c:522:20: warning: promoted type 'int' of K&R function parameter is not compatible with the parameter type 'Tcl_UniChar' (aka 'unsigned short') de
            clared in a previous prototype [-Wknr-promoted-parameter]
     425         Tcl_UniChar   open;
     426                       ^
     427    ./retoglob.c:13:22: note: previous declaration is here
     428                                Tcl_UniChar   open,
```
Build works fine without any modifications with GCC 10, so I think this package just can't be built with Apple Clang 12. I'll keep an eye on Homebrew and see if they add any patches.
Didn't find any relevant patches at https://github.com/macports/macports-ports/tree/master/devel/expect/files or https://sourceforge.net/p/expect/patches/ either.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/expect/package.py b/var/spack/repos/builtin/packages/expect/package.py
--- a/var/spack/repos/builtin/packages/expect/package.py
+++ b/var/spack/repos/builtin/packages/expect/package.py
@@ -13,9 +13,11 @@ class Expect(AutotoolsPackage):
     telnet, ftp, passwd, fsck, rlogin, tip, etc."""
 
     homepage = "http://expect.sourceforge.net/"
-    url      = "https://sourceforge.net/projects/expect/files/Expect/5.45/expect5.45.tar.gz/download"
+    url      = "https://sourceforge.net/projects/expect/files/Expect/5.45.4/expect5.45.4.tar.gz/download"
 
-    version('5.45', sha256='b28dca90428a3b30e650525cdc16255d76bb6ccd65d448be53e620d95d5cc040')
+    version('5.45.4', sha256='49a7da83b0bdd9f46d04a04deec19c7767bb9a323e40c4781f89caf760b92c34')
+    version('5.45.3', sha256='c520717b7195944a69ce1492ec82ca0ac3f3baf060804e6c5ee6d505ea512be9')
+    version('5.45',   sha256='b28dca90428a3b30e650525cdc16255d76bb6ccd65d448be53e620d95d5cc040')
 
     depends_on('tcl')
 
@@ -24,12 +26,10 @@ class Expect(AutotoolsPackage):
     depends_on('libtool',  type='build')
     depends_on('m4',       type='build')
 
-    # https://github.com/spack/spack/issues/19767
-    conflicts('%apple-clang@12:')
-
     force_autoreconf = True
 
-    patch('expect_detect_tcl_private_header_os_x_mountain_lion.patch', when='@5.45')
+    patch('xcode_12.patch', when='%apple-clang@12:')
+    patch('expect_detect_tcl_private_header_os_x_mountain_lion.patch', when='@5.45:5.45.0')
 
     def configure_args(self):
         spec = self.spec


Test patch: