From 873b65d7d9d3f7954f34179ec5335a63620f4399 Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Sun, 28 Apr 2019 23:16:53 +0100 Subject: [PATCH] Fix #4778: autorun `autoreconf` on Windows too 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. --- src/Stack/Build/Execute.hs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Stack/Build/Execute.hs b/src/Stack/Build/Execute.hs index 9b38ebf3bf..5074c76cf3 100644 --- a/src/Stack/Build/Execute.hs +++ b/src/Stack/Build/Execute.hs @@ -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 @@ -913,8 +914,41 @@ 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 and " <> + "https://github.com/commercialhaskell/stack/pull/4781. 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