Skip to content

Commit

Permalink
Fix #4778: autorun autoreconf on Windows too
Browse files Browse the repository at this point in the history
In module `Stack.Build.Execute`, the code uses command `sh autoreconf -i` for Windows, instead of just `autoreconf -i`. A comprehensive help message is added if `sh autoreconf -i` throws an exception on Windows.

The implementation involves a hack: `sh autoreconf -i` seems 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 #4121).

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 29, 2019
1 parent 8c2f6d5 commit a405be6
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 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,40 @@ 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 autoreconf = if osIsWindows
then readProcessNull "sh" ["autoreconf", "-i"]
else readProcessNull "autoreconf" ["-i"]
-- 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.
fixupOnWindows = when osIsWindows (void $ liftIO defaultColorWhen)
withWorkingDir (toFilePath pkgDir) $ autoreconf `catchAny` \ex -> do
fixupOnWindows
logWarn $ "Unable to run autoreconf: " <> displayShow ex
when osIsWindows $ do
logInfo $ "Check that executable perl is on the path in stack's " <>
"MSYS2 \\usr\\bin folder, and working, and that script file " <>
"autoreconf is on the path in that location. To check that " <>
"perl or autoreconf are on the path in the required location, " <>
"run commands:"
logInfo ""
logInfo " stack exec where -- perl"
logInfo " stack exec where -- autoreconf"
logInfo ""
logInfo $ "If perl or autoreconf is not on the path in the " <>
"required location, add them with command (note that the " <>
"relevant package name is 'autoconf' not 'autoreconf'):"
logInfo ""
logInfo " stack exec pacman -- --sync --refresh autoconf"
logInfo ""
logInfo $ "Some versions of perl from MYSY2 are broken. See " <>
"https://github.com/msys2/MSYS2-packages/issues/1611. To test " <>
"if perl in the required location is working, try command:"
logInfo ""
logInfo " stack exec perl -- --version"
logInfo ""
fixupOnWindows

-- | Make a padded prefix for log messages
packageNamePrefix :: ExecuteEnv -> PackageName -> Utf8Builder
Expand Down

0 comments on commit a405be6

Please sign in to comment.