diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 432277a9d5c..2d8be7f02a3 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -133,7 +133,7 @@ jobs: key: ${{ runner.os }}-${{ matrix.ghc }}-${{ github.sha }} restore-keys: ${{ runner.os }}-${{ matrix.ghc }}- - - name: Work around git problem https://bugs.launchpad.net/ubuntu/+source/git/+bug/1993586 (cabal PR #8546) + - name: "Work around git problem https://bugs.launchpad.net/ubuntu/+source/git/+bug/1993586 (cabal PR #8546)" run: git config --global protocol.file.allow always # The tool is not essential to the rest of the test suite. If @@ -146,10 +146,15 @@ jobs: run: cabal install --ignore-project hackage-repo-tool # Needed by cabal-testsuite/PackageTests/Configure/setup.test.hs - - name: Install Autotools + - name: "MAC: Install Autotools" if: runner.os == 'macOS' run: brew install automake + # Needed by cabal-testsuite/PackageTests/Configure/setup.test.hs + - name: "WIN: Install Autotools" + if: runner.os == 'Windows' + run: /usr/bin/pacman --noconfirm -S autotools + - name: Set validate inputs run: | FLAGS="${{ env.COMMON_FLAGS }}" diff --git a/cabal-testsuite/PackageTests/Configure/cabal.test.hs b/cabal-testsuite/PackageTests/Configure/cabal.test.hs index afcc00cbf7a..cd419e8cee2 100644 --- a/cabal-testsuite/PackageTests/Configure/cabal.test.hs +++ b/cabal-testsuite/PackageTests/Configure/cabal.test.hs @@ -2,9 +2,26 @@ import Test.Cabal.Prelude import Control.Monad.IO.Class import Data.Maybe import System.Directory +import System.Environment +import Data.List (isSuffixOf) + -- Test for 'build-type: Configure' example from the setup manual. main = cabalTest $ do - hasAutoreconf <- liftIO $ fmap isJust $ findExecutable "autoreconf" - skipUnless "no autoreconf" hasAutoreconf - _ <- shell "autoreconf" ["-i"] - cabal "v2-build" [] + if isWindows + then do + (mCI, mSh) <- liftIO $ (,) <$> lookupEnv "CI" <*> lookupEnv "SHELL" + case (mCI, mSh) of + (Nothing, Nothing) -> skip "Missing $SHELL" + (Nothing, Just sh) -> do + env <- getTestEnv + void $ shell sh [ "-l", "-c", "cd $(cygpath -m '" <> testTmpDir env <> "') && autoreconf -i"] + cabal "v2-build" [] + (Just{}, _) -> do + env <- getTestEnv + void $ shell "C:\\msys64\\usr\\bin\\bash.exe" [ "-l", "-c", "cd $(cygpath -m '" <> testTmpDir env <> "') && autoreconf -i"] + cabal "v2-build" [] + else do + hasAutoreconf <- liftIO $ fmap isJust $ findExecutable "autoreconf" + skipUnless "no autoreconf" hasAutoreconf + _ <- shell "autoreconf" ["-i"] + cabal "v2-build" [] diff --git a/cabal-testsuite/PackageTests/Configure/setup.test.hs b/cabal-testsuite/PackageTests/Configure/setup.test.hs index 559b88c6ff2..5eaea387fe6 100644 --- a/cabal-testsuite/PackageTests/Configure/setup.test.hs +++ b/cabal-testsuite/PackageTests/Configure/setup.test.hs @@ -2,9 +2,25 @@ import Test.Cabal.Prelude import Control.Monad.IO.Class import Data.Maybe import System.Directory +import System.Environment + -- Test for 'build-type: Configure' example from the setup manual. -main = setupTest $ do - hasAutoreconf <- liftIO $ fmap isJust $ findExecutable "autoreconf" - skipUnless "no autoreconf" hasAutoreconf - _ <- shell "autoreconf" ["-i"] - setup_build [] +main = setupTest $ + if isWindows + then do + (mCI, mSh) <- liftIO $ (,) <$> lookupEnv "CI" <*> lookupEnv "SHELL" + case (mCI, mSh) of + (Nothing, Nothing) -> skip "Missing $SHELL" + (Nothing, Just sh) -> do + env <- getTestEnv + void $ shell sh [ "-l", "-c", "cd $(cygpath -m '" <> testTmpDir env <> "') && autoreconf -i"] + setup_build [] + (Just{}, _) -> do + env <- getTestEnv + void $ shell "C:\\msys64\\usr\\bin\\bash.exe" [ "-l", "-c", "cd $(cygpath -m '" <> testTmpDir env <> "') && autoreconf -i"] + setup_build [] + else do + hasAutoreconf <- liftIO $ fmap isJust $ findExecutable "autoreconf" + skipUnless "no autoreconf" hasAutoreconf + _ <- shell "autoreconf" ["-i"] + setup_build [] diff --git a/cabal-testsuite/PackageTests/GHCJS/BuildRunner/cabal.test.hs b/cabal-testsuite/PackageTests/GHCJS/BuildRunner/cabal.test.hs index 245901c8bef..da8afae103e 100644 --- a/cabal-testsuite/PackageTests/GHCJS/BuildRunner/cabal.test.hs +++ b/cabal-testsuite/PackageTests/GHCJS/BuildRunner/cabal.test.hs @@ -1,7 +1,7 @@ import Test.Cabal.Prelude main = do - cabalTest . expectBrokenIfWindows 10179 . recordMode DoNotRecord $ do + cabalTest . recordMode DoNotRecord $ do cwd <- fmap testCurrentDir getTestEnv testInvokedWithBuildRunner cwd "test" [] testInvokedWithBuildRunner cwd "run" ["ghcjs-exe"] @@ -14,6 +14,8 @@ testInvokedWithBuildRunner cwd cabalCmd extraArgs = do [ "--ghcjs" , "--with-compiler", cwd fakeGhcjsPath ] + -- On windows point cabal to the right cc + ++ if isWindows then ["--with-gcc", "scripts/cc.bat"] else [] assertOutputContains magicString output where - fakeGhcjsPath = "scripts/fake-ghcjs.sh" + fakeGhcjsPath = if isWindows then "scripts/fake-ghcjs.exe" else "scripts/fake-ghcjs.sh" diff --git a/cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/cc.bat b/cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/cc.bat new file mode 100644 index 00000000000..b2300d2fd6b --- /dev/null +++ b/cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/cc.bat @@ -0,0 +1,45 @@ +@ECHO off + +FOR /f "delims=" %%A in ('call ghc.exe --print-libdir') do set "libdir=%%A" +FOR /f "delims=" %%A in ('call ghc.exe --numeric-version') do set "numVersion=%%A" +setlocal EnableDelayedExpansion + +call :compareVersions 9.4.1 %numVersion% +if %errorlevel% == 1 (set "cc=gcc.exe") else (set "cc=clang.exe") +CALL !libdir:lib=mingw\bin\!%cc% %* +EXIT /B %ERRORLEVEL% + +REM taken from https://stackoverflow.com/questions/15807762/compare-version-numbers-in-batch-file + +:compareVersions version1 version2 +:: +:: Compares two version numbers and returns the result in the ERRORLEVEL +:: +:: Returns 1 if version1 > version2 +:: 0 if version1 = version2 +:: -1 if version1 < version2 +:: +:: The nodes must be delimited by . or , or - +:: +:: Nodes are normally strictly numeric, without a 0 prefix. A letter suffix +:: is treated as a separate node +:: +setlocal enableDelayedExpansion +set "v1=%~1" +set "v2=%~2" +:loop +call :parseNode "%v1%" n1 v1 +call :parseNode "%v2%" n2 v2 +if %n1% gtr %n2% exit /b 1 +if %n1% lss %n2% exit /b -1 +if not defined v1 if not defined v2 exit /b 0 +if not defined v1 exit /b -1 +if not defined v2 exit /b 1 +goto :loop + + +:parseNode version nodeVar remainderVar +for /f "tokens=1* delims=." %%A in ("%~1") do ( + set "%~2=%%A" + set "%~3=%%B" +) diff --git a/cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/fake-ghcjs.exe b/cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/fake-ghcjs.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/fake-ghcjs.exe differ diff --git a/cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/fake-ghcjs.shim b/cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/fake-ghcjs.shim new file mode 100644 index 00000000000..725429e82d7 --- /dev/null +++ b/cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/fake-ghcjs.shim @@ -0,0 +1,2 @@ +path = "sh.exe" +args = "scripts/fake-ghcjs.sh" diff --git a/cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/ghcjs-pkg.exe b/cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/ghcjs-pkg.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/ghcjs-pkg.exe differ diff --git a/cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/ghcjs-pkg.shim b/cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/ghcjs-pkg.shim new file mode 100644 index 00000000000..d330fc23e3e --- /dev/null +++ b/cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/ghcjs-pkg.shim @@ -0,0 +1,2 @@ +path = "sh.exe" +args = "scripts/ghcjs-pkg" diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/ghc-pkg.exe b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/ghc-pkg.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/ghc-pkg.exe differ diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/ghc-pkg.shim b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/ghc-pkg.shim new file mode 100644 index 00000000000..0ec39dd3f09 --- /dev/null +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/ghc-pkg.shim @@ -0,0 +1,2 @@ +path = "FINDSH\sh.exe" +args = "ghc-pkg" diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/ghc.exe b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/ghc.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/ghc.exe differ diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/ghc.shim b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/ghc.shim new file mode 100644 index 00000000000..97596f1c171 --- /dev/null +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/ghc.shim @@ -0,0 +1,2 @@ +path = "FINDSH\sh.exe" +args = "ghc" diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/setup.test.hs b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/setup.test.hs index 86a7cf804ea..805f56abc9c 100644 --- a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/setup.test.hs +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectory/setup.test.hs @@ -1,9 +1,19 @@ import Test.Cabal.Prelude +import System.Directory -main = setupAndCabalTest $ expectBrokenIfWindows 10179 $ do +main = setupAndCabalTest $ do + when isWindows $ do + sh <- fmap takeDirectory <$> liftIO (findExecutable "sh") + case sh of + Nothing -> skip "no sh" + Just sh' -> do + let sh'' = concatMap (\c -> case c of + '\\' -> "\\\\\\\\" + x -> [x]) sh' + void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> sh'' <> "/g", "ghc.shim", "ghc-pkg.shim"] env <- getTestEnv let cwd = testCurrentDir env ghc_path <- programPathM ghcProgram r <- withEnv [("WITH_GHC", Just ghc_path)] - . fails $ setup' "configure" ["-w", cwd "ghc"] + . fails $ setup' "configure" ["-w", cwd if isWindows then "ghc.exe" else "ghc" ] assertOutputContains "is version 9999999" r diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/ghc-7.10.exe b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/ghc-7.10.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/ghc-7.10.exe differ diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/ghc-7.10.shim b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/ghc-7.10.shim new file mode 100644 index 00000000000..16ae1ddead3 --- /dev/null +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/ghc-7.10.shim @@ -0,0 +1,2 @@ +path = "FINDSH\sh.exe" +args = "ghc-7.10" diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/ghc-pkg-ghc-7.10.exe b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/ghc-pkg-ghc-7.10.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/ghc-pkg-ghc-7.10.exe differ diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/ghc-pkg-ghc-7.10.shim b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/ghc-pkg-ghc-7.10.shim new file mode 100644 index 00000000000..9e85ac7f0fb --- /dev/null +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/ghc-pkg-ghc-7.10.shim @@ -0,0 +1,2 @@ +path = "FINDSH\sh.exe" +args = "ghc-pkg-ghc-7.10" diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/setup.test.hs b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/setup.test.hs index 0b0a37413be..e60d3685863 100644 --- a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/setup.test.hs +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryGhcVersion/setup.test.hs @@ -1,9 +1,19 @@ import Test.Cabal.Prelude +import System.Directory -main = setupAndCabalTest $ expectBrokenIfWindows 10179 $ do +main = setupAndCabalTest $ do + when isWindows $ do + sh <- fmap takeDirectory <$> liftIO (findExecutable "sh") + case sh of + Nothing -> skip "no sh" + Just sh' -> do + let sh'' = concatMap (\c -> case c of + '\\' -> "\\\\\\\\" + x -> [x]) sh' + void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> sh'' <> "/g", "ghc-7.10.shim", "ghc-pkg-ghc-7.10.shim"] env <- getTestEnv let cwd = testCurrentDir env ghc_path <- programPathM ghcProgram r <- withEnv [("WITH_GHC", Just ghc_path)] - . fails $ setup' "configure" ["-w", cwd "ghc-7.10"] + . fails $ setup' "configure" ["-w", cwd if isWindows then "ghc-7.10.exe" else "ghc-7.10"] assertOutputContains "is version 9999999" r diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/ghc-7.10.exe b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/ghc-7.10.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/ghc-7.10.exe differ diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/ghc-7.10.shim b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/ghc-7.10.shim new file mode 100644 index 00000000000..16ae1ddead3 --- /dev/null +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/ghc-7.10.shim @@ -0,0 +1,2 @@ +path = "FINDSH\sh.exe" +args = "ghc-7.10" diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/ghc-pkg-7.10.exe b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/ghc-pkg-7.10.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/ghc-pkg-7.10.exe differ diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/ghc-pkg-7.10.shim b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/ghc-pkg-7.10.shim new file mode 100644 index 00000000000..8558f8a0513 --- /dev/null +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/ghc-pkg-7.10.shim @@ -0,0 +1,2 @@ +path = "FINDSH\sh.exe" +args = "ghc-pkg-7.10" diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/setup.test.hs b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/setup.test.hs index 0b0a37413be..b5f6b4c88d6 100644 --- a/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/setup.test.hs +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/SameDirectoryVersion/setup.test.hs @@ -1,9 +1,19 @@ import Test.Cabal.Prelude +import System.Directory -main = setupAndCabalTest $ expectBrokenIfWindows 10179 $ do +main = setupAndCabalTest $ do + when isWindows $ do + sh <- fmap takeDirectory <$> liftIO (findExecutable "sh") + case sh of + Nothing -> skip "no sh" + Just sh' -> do + let sh'' = concatMap (\c -> case c of + '\\' -> "\\\\\\\\" + x -> [x]) sh' + void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> sh'' <> "/g", "ghc-7.10.shim", "ghc-pkg-7.10.shim"] env <- getTestEnv let cwd = testCurrentDir env ghc_path <- programPathM ghcProgram r <- withEnv [("WITH_GHC", Just ghc_path)] - . fails $ setup' "configure" ["-w", cwd "ghc-7.10"] + . fails $ setup' "configure" ["-w", cwd if isWindows then "ghc-7.10.exe" else "ghc-7.10"] assertOutputContains "is version 9999999" r diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/bin/ghc-pkg.exe b/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/bin/ghc-pkg.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/bin/ghc-pkg.exe differ diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/bin/ghc-pkg.shim b/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/bin/ghc-pkg.shim new file mode 100644 index 00000000000..1c68332a0a6 --- /dev/null +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/bin/ghc-pkg.shim @@ -0,0 +1,2 @@ +path = "FINDSH\sh.exe" +args = "bin\ghc-pkg" diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/bin/ghc.exe b/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/bin/ghc.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/bin/ghc.exe differ diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/bin/ghc.shim b/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/bin/ghc.shim new file mode 100644 index 00000000000..97596f1c171 --- /dev/null +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/bin/ghc.shim @@ -0,0 +1,2 @@ +path = "FINDSH\sh.exe" +args = "ghc" diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/setup.test.hs b/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/setup.test.hs index 0b80a76a952..b188acc36d6 100644 --- a/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/setup.test.hs +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/setup.test.hs @@ -1,10 +1,22 @@ import Test.Cabal.Prelude +import System.Directory -main = setupAndCabalTest $ expectBrokenIfWindows 10179 $ do - withSymlink "bin/ghc" "ghc" $ do +main = setupAndCabalTest $ do + when isWindows $ do + sh <- fmap takeDirectory <$> liftIO (findExecutable "sh") + case sh of + Nothing -> skip "no sh" + Just sh' -> do + let sh'' = concatMap (\c -> case c of + '\\' -> "\\\\\\\\" + x -> [x]) sh' + void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> sh'' <> "/g", "bin/ghc.shim", "bin/ghc-pkg.shim"] + (if isWindows + then withSymlink "bin/ghc.exe" "ghc.exe" . withSymlink "bin/ghc.shim" "ghc.shim" . withSymlink "bin/ghc" "ghc" + else withSymlink "bin/ghc" "ghc") $ do env <- getTestEnv let cwd = testCurrentDir env ghc_path <- programPathM ghcProgram r <- withEnv [("WITH_GHC", Just ghc_path)] - . fails $ setup' "configure" ["-w", cwd "ghc"] + . fails $ setup' "configure" ["-w", cwd if isWindows then "ghc.exe" else "ghc"] assertOutputContains "is version 9999999" r diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/bin/ghc-7.10.exe b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/bin/ghc-7.10.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/bin/ghc-7.10.exe differ diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/bin/ghc-7.10.shim b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/bin/ghc-7.10.shim new file mode 100644 index 00000000000..97596f1c171 --- /dev/null +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/bin/ghc-7.10.shim @@ -0,0 +1,2 @@ +path = "FINDSH\sh.exe" +args = "ghc" diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/bin/ghc-pkg-7.10.exe b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/bin/ghc-pkg-7.10.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/bin/ghc-pkg-7.10.exe differ diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/bin/ghc-pkg-7.10.shim b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/bin/ghc-pkg-7.10.shim new file mode 100644 index 00000000000..5c1d58caf88 --- /dev/null +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/bin/ghc-pkg-7.10.shim @@ -0,0 +1,2 @@ +path = "FINDSH\sh.exe" +args = "bin\ghc-pkg-7.10" diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/setup.test.hs b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/setup.test.hs index 150f2bc8739..bf9b16fa195 100644 --- a/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/setup.test.hs +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkGhcVersion/setup.test.hs @@ -1,10 +1,22 @@ import Test.Cabal.Prelude +import System.Directory -main = setupAndCabalTest $ expectBrokenIfWindows 10179 $ do - withSymlink "bin/ghc-7.10" "ghc" $ do +main = setupAndCabalTest $ do + when isWindows $ do + sh <- fmap takeDirectory <$> liftIO (findExecutable "sh") + case sh of + Nothing -> skip "no sh" + Just sh' -> do + let sh'' = concatMap (\c -> case c of + '\\' -> "\\\\\\\\" + x -> [x]) sh' + void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> sh'' <> "/g", "bin/ghc-7.10.shim", "bin/ghc-pkg-7.10.shim"] + (if isWindows + then withSymlink "bin/ghc-7.10.exe" "ghc.exe" . withSymlink "bin/ghc-7.10.shim" "ghc.shim" . withSymlink "bin/ghc-7.10" "ghc" + else withSymlink "bin/ghc-7.10" "ghc") $ do env <- getTestEnv let cwd = testCurrentDir env ghc_path <- programPathM ghcProgram r <- withEnv [("WITH_GHC", Just ghc_path)] - . fails $ setup' "configure" ["-w", cwd "ghc"] + . fails $ setup' "configure" ["-w", cwd if isWindows then "ghc.exe" else "ghc"] assertOutputContains "is version 9999999" r diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/bin/ghc-7.10.exe b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/bin/ghc-7.10.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/bin/ghc-7.10.exe differ diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/bin/ghc-7.10.shim b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/bin/ghc-7.10.shim new file mode 100644 index 00000000000..97596f1c171 --- /dev/null +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/bin/ghc-7.10.shim @@ -0,0 +1,2 @@ +path = "FINDSH\sh.exe" +args = "ghc" diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/bin/ghc-pkg-ghc-7.10.exe b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/bin/ghc-pkg-ghc-7.10.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/bin/ghc-pkg-ghc-7.10.exe differ diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/bin/ghc-pkg-ghc-7.10.shim b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/bin/ghc-pkg-ghc-7.10.shim new file mode 100644 index 00000000000..7e9ba24d98b --- /dev/null +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/bin/ghc-pkg-ghc-7.10.shim @@ -0,0 +1,2 @@ +path = "FINDSH\sh.exe" +args = "bin\ghc-pkg-ghc-7.10" diff --git a/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/setup.test.hs b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/setup.test.hs index 150f2bc8739..2f406ce6226 100644 --- a/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/setup.test.hs +++ b/cabal-testsuite/PackageTests/GhcPkgGuess/SymlinkVersion/setup.test.hs @@ -1,10 +1,22 @@ import Test.Cabal.Prelude +import System.Directory -main = setupAndCabalTest $ expectBrokenIfWindows 10179 $ do - withSymlink "bin/ghc-7.10" "ghc" $ do +main = setupAndCabalTest $ do + when isWindows $ do + sh <- fmap takeDirectory <$> liftIO (findExecutable "sh") + case sh of + Nothing -> skip "no sh" + Just sh' -> do + let sh'' = concatMap (\c -> case c of + '\\' -> "\\\\\\\\" + x -> [x]) sh' + void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> sh'' <> "/g", "bin/ghc-7.10.shim", "bin/ghc-pkg-ghc-7.10.shim"] + (if isWindows + then withSymlink "bin/ghc-7.10.exe" "ghc.exe" . withSymlink "bin/ghc-7.10.shim" "ghc.shim" . withSymlink "bin/ghc-7.10" "ghc" + else withSymlink "bin/ghc-7.10" "ghc") $ do env <- getTestEnv let cwd = testCurrentDir env ghc_path <- programPathM ghcProgram r <- withEnv [("WITH_GHC", Just ghc_path)] - . fails $ setup' "configure" ["-w", cwd "ghc"] + . fails $ setup' "configure" ["-w", cwd if isWindows then "ghc.exe" else "ghc"] assertOutputContains "is version 9999999" r diff --git a/cabal-testsuite/PackageTests/PkgConfigParse/pkg-config.exe b/cabal-testsuite/PackageTests/PkgConfigParse/pkg-config.exe new file mode 100644 index 00000000000..537023174dc Binary files /dev/null and b/cabal-testsuite/PackageTests/PkgConfigParse/pkg-config.exe differ diff --git a/cabal-testsuite/PackageTests/PkgConfigParse/pkg-config.shim b/cabal-testsuite/PackageTests/PkgConfigParse/pkg-config.shim new file mode 100644 index 00000000000..2c187de462e --- /dev/null +++ b/cabal-testsuite/PackageTests/PkgConfigParse/pkg-config.shim @@ -0,0 +1,2 @@ +path = "FINDSH\sh.exe" +args = "pkg-config" \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/PkgConfigParse/setup.test.hs b/cabal-testsuite/PackageTests/PkgConfigParse/setup.test.hs index 2528e7459e5..edebd2d131c 100644 --- a/cabal-testsuite/PackageTests/PkgConfigParse/setup.test.hs +++ b/cabal-testsuite/PackageTests/PkgConfigParse/setup.test.hs @@ -1,7 +1,17 @@ +import System.Directory import Test.Cabal.Prelude -- Test that invalid unicode in pkg-config output doesn't trip up cabal very much -main = cabalTest $ expectBrokenIfWindows 10179 $ do +main = cabalTest $ do + when isWindows $ do + sh <- fmap takeDirectory <$> liftIO (findExecutable "sh") + case sh of + Nothing -> skip "no sh" + Just sh' -> do + let sh'' = concatMap (\c -> case c of + '\\' -> "\\\\\\\\" + x -> [x]) sh' + void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> sh'' <> "/g", "pkg-config.shim"] cdir <- testCurrentDir `fmap` getTestEnv res <- cabal' "v2-build" ["--extra-prog-path="++cdir, "-v2"] assertOutputContains "Some pkg-config packages have names containing invalid unicode: or" res diff --git a/cabal-testsuite/src/Test/Cabal/Prelude.hs b/cabal-testsuite/src/Test/Cabal/Prelude.hs index 7a8fbf651e8..50f9395d74a 100644 --- a/cabal-testsuite/src/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/src/Test/Cabal/Prelude.hs @@ -54,6 +54,7 @@ import Control.Concurrent.Async (withAsync) import qualified Data.Aeson as JSON import qualified Data.ByteString.Lazy as BSL import Control.Monad (unless, when, void, forM_, liftM2, liftM4) +import Control.Monad.Catch ( bracket_ ) import Control.Monad.Trans.Reader (withReaderT, runReaderT) import Control.Monad.IO.Class (MonadIO (..)) import qualified Crypto.Hash.SHA256 as SHA256 @@ -70,10 +71,9 @@ import Control.Retry (exponentialBackoff, limitRetriesByCumulativeDelay) import Network.Wait (waitTcpVerbose) import System.Environment import System.Process +import System.IO #ifndef mingw32_HOST_OS -import Control.Monad.Catch ( bracket_ ) -import System.Posix.Files ( createSymbolicLink ) import System.Posix.Resource #endif @@ -1123,19 +1123,20 @@ withDelay m = do Just _ -> m -- | Create a symlink for the duration of the provided action. If the symlink --- already exists, it is deleted. Does not work on Windows. +-- already exists, it is deleted. withSymlink :: FilePath -> FilePath -> TestM a -> TestM a -#ifdef mingw32_HOST_OS +#if defined(mingw32_HOST_OS) && !MIN_VERSION_directory(1,3,1) withSymlink _oldpath _newpath _act = - error "PackageTests.PackageTester.withSymlink: does not work on Windows!" + error "Test.Cabal.Prelude.withSymlink: does not work on Windows with directory <1.3.1!" #else withSymlink oldpath newpath0 act = do + liftIO $ hPutStrLn stderr $ "Symlinking " <> oldpath <> " <== " <> newpath0 env <- getTestEnv let newpath = testCurrentDir env newpath0 symlinkExists <- liftIO $ doesFileExist newpath when symlinkExists $ liftIO $ removeFile newpath - bracket_ (liftIO $ createSymbolicLink oldpath newpath) - (liftIO $ removeFile newpath) act + bracket_ (liftIO $ createFileLink oldpath newpath) + (liftIO $ pure ()) act #endif writeSourceFile :: FilePath -> String -> TestM ()