Skip to content

Detect when sh cannot handle Windows short paths #3487

Closed

Description

@acfoltzer

Summary by @ezyang: In a misconfigured msys installation, the default sh in the path may come from cygwin which cannot handle Windows short paths. Unfortunately, Cabal 1.24 switched to using short paths, so using an sh which can handle this is important.

./Setup configure should verify that sh can handle short paths. It's not currently clear what the best way to do this is. It's also possible that cabal-install needs a check too.

Below is the original bug report.


I was having trouble with the configure step for old-time, and decided to compare the behavior of 1.22 and 1.24. 1.22 works fine, but it appears that while 1.24 successfully finds the correct path to gcc, it mangles it when setting CC and invoking the configure script.

...
Using gcc version 5.2.0 found on system at:
C:\Users\hudson\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.1\mingw\bin\gcc.exe
...
"C:\cygwin\bin\sh.exe" "./configure" "--with-compiler=ghc" "--prefix=C:\cygwin\tmp\old-time-1.1.0.3\.cabal-sandbox" "--bindir=$prefix\bin" "--libdir=$prefix" "--libexecdir=$prefix\$libname" "--datadir=$prefix" "--sysconfdir=$prefix\etc" "CC=C:\Users\hudson\AppData\Local\Programs\stack\X86_64~1\GHC-80~1.1\mingw\bin\gcc.exe"

(full log at https://gist.github.com/acfoltzer/01fc8238acaafbb99e557f7320fcc318)

It seems that x86_64-windows is getting mangled into X86_64~1, and ghc-8.0.1 into GHC-80~1.1. I'm honestly baffled; any thoughts?

Activity

  1. ezyang commented on Jun 9, 2016

    @ezyang
    Contributor

    Those look like short path names to me. See b946c05

  2. 23Skidoo commented on Jun 9, 2016

    @23Skidoo
    Member

    Yes, that's on purpose, to work around the issues that Autoconf has with paths that contain spaces. See #3185.

  3. acfoltzer commented on Jun 9, 2016

    @acfoltzer
    CollaboratorAuthor

    From config.log for old-time:

    configure:2256: checking for gcc
    configure:2283: result: C:\Users\hudson\AppData\Local\Programs\stack\X86_64~1\GHC-80~1.1\mingw\bin\gcc.exe
    configure:2512: checking for C compiler version
    configure:2521: C:\Users\hudson\AppData\Local\Programs\stack\X86_64~1\GHC-80~1.1\mingw\bin\gcc.exe --version >&5
    ./configure: line 2523: C:\Users\hudson\AppData\Local\Programs\stack\X86_64~1\GHC-80~1.1\mingw\bin\gcc.exe: command not found
    configure:2532: $? = 127
    configure:2521: C:\Users\hudson\AppData\Local\Programs\stack\X86_64~1\GHC-80~1.1\mingw\bin\gcc.exe -v >&5
    ./configure: line 2523: C:\Users\hudson\AppData\Local\Programs\stack\X86_64~1\GHC-80~1.1\mingw\bin\gcc.exe: command not found
    configure:2532: $? = 127
    configure:2521: C:\Users\hudson\AppData\Local\Programs\stack\X86_64~1\GHC-80~1.1\mingw\bin\gcc.exe -V >&5
    ./configure: line 2523: C:\Users\hudson\AppData\Local\Programs\stack\X86_64~1\GHC-80~1.1\mingw\bin\gcc.exe: command not found
    configure:2532: $? = 127
    configure:2521: C:\Users\hudson\AppData\Local\Programs\stack\X86_64~1\GHC-80~1.1\mingw\bin\gcc.exe -qversion >&5
    ./configure: line 2523: C:\Users\hudson\AppData\Local\Programs\stack\X86_64~1\GHC-80~1.1\mingw\bin\gcc.exe: command not found
    configure:2532: $? = 127
    configure:2552: checking whether the C compiler works
    configure:2574: C:\Users\hudson\AppData\Local\Programs\stack\X86_64~1\GHC-80~1.1\mingw\bin\gcc.exe -fno-stack-protector   conftest.c  >&5
    ./configure: line 2576: C:\Users\hudson\AppData\Local\Programs\stack\X86_64~1\GHC-80~1.1\mingw\bin\gcc.exe: command not found
    configure:2578: $? = 127
    configure:2616: result: no
    

    So cabal is taking a path that does exist and work, and is turning it into one that does not. Is that cabal's fault or is our Windows 10 system configured incorrectly?

  4. gbaz commented on Jun 9, 2016

    @gbaz
    Collaborator

    The question is why those paths do not work -- i.e. are they not valid short path names or is there a broader issue using short path names, i.e. maybe that the configure script itself can't handle short names for some reason?

  5. gbaz commented on Jun 9, 2016

    @gbaz
    Collaborator

    Here's a related problem I'm seeing -- as per #2840 we should be using the msys sh, even with cygwin. But somehow the cygwin sh is still being called even though I have "C:\Program Files\Haskell Platform\8.0.1\msys\usr\bin," set as an extra-prog-path in my cabal config file. Was there a regression here?

  6. gbaz commented on Jun 9, 2016

    @gbaz
    Collaborator

    Aha, I had

    extra-prog-path: C:\Program Files\Haskell Platform\8.0.1\msys\usr\bin,
    C:\Users\gbazerman\AppData\Roaming\cabal\bin

    And apparently that format was silently bad.

    If we remove the comma and the second element it works and builds for me. @acfoltzer try building with these three lines in your cabal config:

    extra-prog-path: C:\Program Files\Haskell Platform\8.0.1\msys\usr\bin
    extra-lib-dirs: C:\Program Files\Haskell Platform\8.0.1\mingw\lib
    extra-include-dirs: C:\Program Files\Haskell Platform\8.0.1\mingw\include
    

    (or the appropriate modifications if your mysys and mingw folders are elsewhere)

  7. acfoltzer commented on Jun 9, 2016

    @acfoltzer
    CollaboratorAuthor

    The same problem arises, alas. It still tries to shorten the path, which on my system doesn't resolve correctly. I also tried with network with the same results, even with the usual --configure-option --host=x86_64-unknown-mingw32 that I have to throw in for successful builds over a Cygwin ssh shell.

    I should note that I'm only using Cygwin for the ssh capabilities; the path is configured so that the GHC-bundled mingw tools shadow Cygwin's.

  8. gbaz commented on Jun 9, 2016

    @gbaz
    Collaborator

    @acfoltzer I see in your paste above

    "C:\cygwin\bin\sh.exe" "./configure" "--with-compiler=ghc" "--prefix=C:\cygwin\tmp\old-time-1.1.0.3\.cabal-sandbox" "--bindir=$prefix\bin" "--libdir=$prefix" "--libexecdir=$prefix\$libname" "--datadir=$prefix" "--sysconfdir=$prefix\etc" "CC=C:\Users\hudson\AppData\Local\Programs\stack\X86_64~1\GHC-80~1.1\mingw\bin\gcc.exe"
    

    I.e. an invocation of the sh from cygwin. I got the error you described with that. When I ensured I was using the msys sh instead, then the build ran successfully....

  9. 23Skidoo commented on Jun 9, 2016

    @23Skidoo
    Member

    Can confirm that using Cygwin tools can lead to breakage. We should perhaps add a warning about it...

  10. gbaz commented on Jun 9, 2016

    @gbaz
    Collaborator

    I like the idea of auto-detecting wrong tools and emitting a warning and a suggestion of how to configure things to use the right tools.

  11. acfoltzer commented on Jun 9, 2016

    @acfoltzer
    CollaboratorAuthor

    Ah, I see what you mean now. I added the /usr/bin subdirectory of Stack's msys installation, and it appears to be using the right sh.exe, although with the same results:

    "C:\Users\hudson\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\usr\bin\sh.exe" "./configure" "--with-compiler=ghc" "--prefix=C:\cygwin\tmp\old-time-1.1.0.3\.cabal-sandbox" "--bindir=$prefix\bin" "--libdir=$prefix" "--libexecdir=$prefix\$libname" "--datadir=$prefix" "--sysconfdir=$prefix\etc" "CC=C:\Users\hudson\AppData\Local\Programs\stack\X86_64~1\GHC-80~1.1\mingw\bin\gcc.exe"
    configure: WARNING: unrecognized options: --with-compiler
    checking for gcc... C:\Users\hudson\AppData\Local\Programs\stack\X86_64~1\GHC-80~1.1\mingw\bin\gcc.exe
    checking whether the C compiler works... no
    

    I don't have graphical access to this machine, but I'll put in a ticket to install the new HP and see if the problem persists with that installation.

  12. acfoltzer commented on Jun 10, 2016

    @acfoltzer
    CollaboratorAuthor

    Okay, using the Haskell Platform and with the suggested modifications to the cabal config, this is now resolved for me. It appears that the short path is still being passed to sh, but the sh bundled with the platform seems to agree with it. I'm fine with closing this ticket unless y'all think there might be some improvements to be made to help people reach a solution.

  13. 23Skidoo commented on Jun 11, 2016

    @23Skidoo
    Member

    So I can think of two enhancements:

    1. Shortening path names only when they contain spaces.
    2. Detecting broken versions of sh and printing a warning.
  14. gbaz commented on Jun 11, 2016

    @gbaz
    Collaborator

    I don't think the former is very wise, as users should be encouraged to have a proper version of sh lying around (and indeed one comes with the msys tools). The latter seems like a great idea.

  15. FPtje commented on Jul 11, 2016

    @FPtje

    I had tried installing msys2 (it was using Git's sh before), the cabal options described by @gbaz and nothing worked. When I changed my PATH back to ghc-7.10.3 everything worked again. Then change to ghc-8.0.1 and everything breaks again.

    My solution is even simpler: something, whether it be cabal, ghc, sh or whatever cannot deal with . or - in folder names. Change ghc-8.0.1 to something else (I changed it to just 8), and this incompetence will no longer bother you.

    Make sure to change PATH accordingly.

    I should not have to go through this effort to get a simple compiler to work.

  16. changed the title [-]Mangled path to gcc on Windows[/-] [+]Detect when sh cannot handle Windows short paths[/+] on Jul 12, 2016
  17. ezyang commented on Aug 1, 2016

    @ezyang
    Contributor

    We've realized that actually there was an unrelated bug in short path computation, reported at #3649. @FPtje I think this was precisely your bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions