Skip to content

Commit

Permalink
Fix commercialhaskell#4778: autorun autoreconf on Windows too
Browse files Browse the repository at this point in the history
In module `Stack.Setup`, `pacman` is used to add the `perl` and `autoconf` packages to stack's MSYS2.

In module `Stack.Build.Execute`, the code uses command `sh autoreconf -i` for Windows, instead of just `autoreconf -i`.

The implementation involves two hacks:

1. `pacman` and `sh autoreconf -i` seem to clear and not restore ANSI capability on native Windows terminals. A hack restores the ANSI capability (using the same hack that was once used for `git clone` - fix commercialhaskell#4121).
2. MSYS2's current `perl` package (5.28.1-2) is broken. So the `perl` installed by stack is downgraded to 5.28.0-1, which works. This will need to be revisited once `perl` is fixed on MSYS2.

This has been tested on Windows 10 (only) by deleting stack's MSYS2 (so that stack reinstalls it) and by then building the `process` package (which makes use of `configure`) using stack.
  • Loading branch information
mpilgrem committed Apr 28, 2019
1 parent dfbf85a commit 09c22d7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import Stack.Config
import Stack.Constants
import Stack.Constants.Config
import Stack.Coverage
import Stack.DefaultColorWhen (defaultColorWhen)
import Stack.GhcPkg
import Stack.Package
import Stack.PackageDump
Expand Down Expand Up @@ -911,8 +912,15 @@ ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp task =
exists <- doesFileExist fp
unless exists $ do
logInfo $ "Trying to generate configure with autoreconf in " <> fromString (toFilePath pkgDir)
withWorkingDir (toFilePath pkgDir) $ readProcessNull "autoreconf" ["-i"] `catchAny` \ex ->
let cmd = if osIsWindows then "sh" else "autoreconf"
args = if osIsWindows then ["autoreconf", "-i"] else ["-i"]
withWorkingDir (toFilePath pkgDir) $ readProcessNull cmd args `catchAny` \ex ->
logWarn $ "Unable to run autoreconf: " <> displayShow ex
-- On Windows 10, an upstream issue with the `sh autoreconf -i` command
-- means that command clears, but does not then restore, the
-- ENABLE_VIRTUAL_TERMINAL_PROCESSING flag for native terminals. The
-- folowing hack re-enables the lost ANSI-capability.
when osIsWindows (void $ liftIO defaultColorWhen)

-- | Make a padded prefix for log messages
packageNamePrefix :: ExecuteEnv -> PackageName -> Utf8Builder
Expand Down
23 changes: 23 additions & 0 deletions src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import Stack.Build.Source (loadSourceMap, hashSourceMapData)
import Stack.Build.Target (NeedTargets(..), parseTargets)
import Stack.Constants
import Stack.Constants.Config (distRelativeDir)
import Stack.DefaultColorWhen (defaultColorWhen)
import Stack.GhcPkg (createDatabase, getGlobalDB, mkGhcPackagePath, ghcPkgPathEnvVar)
import Stack.Prelude hiding (Display (..))
import Stack.SourceMap
Expand Down Expand Up @@ -1483,6 +1484,28 @@ installMsys2Windows osKey si archiveFile archiveType _tempDir destDir = do
menv <- mkProcessContext newEnv
withWorkingDir (toFilePath destDir) $ withProcessContext menv
$ proc "sh" ["--login", "-c", "true"] runProcess_
-- Install MSYS2 package perl. Used by the autoreconf shell script file.
-- perl 5.28.1-2 is broken (see
-- https://github.com/msys2/MSYS2-packages/issues/1611). perl 5.28.0-1
-- works, so downgrading to that version, in the alternative.
withWorkingDir (toFilePath destDir) $ withProcessContext menv
-- $ proc "pacman" ["-Sy", "--noconfirm", "perl"] runProcess_
$ proc
"pacman"
[ "-U"
, "--noconfirm"
, "http://repo.msys2.org/msys/x86_64/perl-5.28.0-1-x86_64.pkg.tar.xz"
]
runProcess_
-- Install MSYS2 package autoconf. Provides the autoreconf shell script
-- file.
withWorkingDir (toFilePath destDir) $ withProcessContext menv
$ proc "pacman" ["-Sy", "--noconfirm", "autoconf"] runProcess_
-- On Windows 10, an upstream issue with the `pacman` command means that
-- command clears, but does not then restore, the
-- ENABLE_VIRTUAL_TERMINAL_PROCESSING flag for native terminals. The
-- folowing hack re-enables the lost ANSI-capability.
void $ liftIO defaultColorWhen

-- No longer installing git, it's unreliable
-- (https://github.com/commercialhaskell/stack/issues/1046) and the
Expand Down

0 comments on commit 09c22d7

Please sign in to comment.