Skip to content

Commit

Permalink
Fix GHCJS BuildRunner test on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jasagredo committed Aug 1, 2024
1 parent 9d57a07 commit 5abf3d3
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cabal-testsuite/PackageTests/GHCJS/BuildRunner/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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"
45 changes: 45 additions & 0 deletions cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/cc.bat
Original file line number Diff line number Diff line change
@@ -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"
)
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "sh.exe"
args = "scripts/fake-ghcjs.sh"
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "sh.exe"
args = "scripts/ghcjs-pkg"

0 comments on commit 5abf3d3

Please sign in to comment.