ghcup-hs/test/optparse-test/CompileTest.hs

208 lines
8.9 KiB
Haskell
Raw Normal View History

2023-07-24 15:04:18 +00:00
{-# LANGUAGE OverloadedStrings #-}
2023-07-25 14:58:01 +00:00
{-# LANGUAGE QuasiQuotes #-}
2023-09-02 10:47:42 +00:00
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
2023-07-24 15:04:18 +00:00
module CompileTest where
import Test.Tasty
import GHCup.OptParse
import Utils
import Data.Versions
import GHCup.Types
2023-07-25 14:58:01 +00:00
import URI.ByteString.QQ
import qualified GHCup.OptParse.Compile as GHC (GHCCompileOptions(..))
import qualified GHCup.OptParse.Compile as HLS (HLSCompileOptions(..))
2023-07-28 14:06:16 +00:00
import GHCup.GHC as GHC
import GHCup.HLS as HLS
2023-07-24 15:04:18 +00:00
compileTests :: TestTree
compileTests = testGroup "compile"
$ map (buildTestTree compileParseWith)
[ ("ghc", compileGhcCheckList)
, ("hls", compileHlsCheckList)
]
mkDefaultGHCCompileOptions :: GHCVer -> Either Version FilePath -> GHCCompileOptions
mkDefaultGHCCompileOptions target boot =
GHCCompileOptions
target
boot
Nothing
Nothing
(Just $ Right [])
Nothing
[]
False
Nothing
Nothing
2023-08-05 05:47:51 +00:00
Nothing
2023-07-24 15:04:18 +00:00
Nothing
2023-07-28 14:06:16 +00:00
mkDefaultHLSCompileOptions :: HLSVer -> [ToolVersion] -> HLSCompileOptions
mkDefaultHLSCompileOptions target ghcs =
HLSCompileOptions
target
Nothing
True
False
(Left False)
Nothing
Nothing
Nothing
(Just $ Right [])
ghcs
[]
2023-07-24 15:04:18 +00:00
compileGhcCheckList :: [(String, CompileCommand)]
compileGhcCheckList = mapSecond CompileGHC
2023-07-25 14:58:01 +00:00
[ ("compile ghc -v 9.4.5 -b 9.2.8", baseOptions)
2023-07-24 15:04:18 +00:00
, ("compile ghc -g a32db0b -b 9.2.8", mkDefaultGHCCompileOptions
2023-07-28 14:06:16 +00:00
(GHC.GitDist $ GitBranch "a32db0b" Nothing)
2023-10-13 08:35:39 +00:00
(Left $(versionQ "9.2.8"))
2023-07-24 15:04:18 +00:00
)
, ("compile ghc -g a32db0b -b 9.2.8 -r https://gitlab.haskell.org/ghc/ghc.git",
mkDefaultGHCCompileOptions
2023-07-28 14:06:16 +00:00
(GHC.GitDist $ GitBranch "a32db0b" (Just "https://gitlab.haskell.org/ghc/ghc.git"))
2023-10-13 08:35:39 +00:00
(Left $(versionQ "9.2.8"))
2023-07-24 15:04:18 +00:00
)
, ("compile ghc -g a32db0b -r https://gitlab.haskell.org/ghc/ghc.git -b /usr/bin/ghc-9.2.2",
mkDefaultGHCCompileOptions
2023-07-28 14:06:16 +00:00
(GHC.GitDist $ GitBranch "a32db0b" (Just "https://gitlab.haskell.org/ghc/ghc.git"))
2023-07-24 15:04:18 +00:00
(Right "/usr/bin/ghc-9.2.2")
)
2023-07-25 14:58:01 +00:00
, ("compile ghc --remote-source-dist https://gitlab.haskell.org/ghc/ghc.git -b 9.2.8", mkDefaultGHCCompileOptions
2023-07-28 14:06:16 +00:00
(GHC.RemoteDist [uri|https://gitlab.haskell.org/ghc/ghc.git|])
2023-10-13 08:35:39 +00:00
(Left $(versionQ "9.2.8"))
2023-07-25 14:58:01 +00:00
)
, (baseCmd <> "-j20", baseOptions{GHC.jobs = Just 20})
, (baseCmd <> "--jobs 10", baseOptions{GHC.jobs = Just 10})
, (baseCmd <> "-c build.mk", baseOptions{GHC.buildConfig = Just "build.mk"})
, (baseCmd <> "--config build.mk", baseOptions{GHC.buildConfig = Just "build.mk"})
2024-01-21 06:00:53 +00:00
#ifdef IS_WINDOWS
, (baseCmd <> "--patch file:c:/example.patch", baseOptions{GHC.patches = Just $ Right [[uri|file:c:/example.patch|]]})
#else
2023-07-25 14:58:01 +00:00
, (baseCmd <> "--patch file:///example.patch", baseOptions{GHC.patches = Just $ Right [[uri|file:///example.patch|]]})
2024-01-21 06:00:53 +00:00
#endif
2023-07-25 14:58:01 +00:00
, (baseCmd <> "-p patch_dir", baseOptions{GHC.patches = Just (Left "patch_dir")})
, (baseCmd <> "--patchdir patch_dir", baseOptions{GHC.patches = Just (Left "patch_dir")})
, (baseCmd <> "-x armv7-unknown-linux-gnueabihf", baseOptions{GHC.crossTarget = Just "armv7-unknown-linux-gnueabihf"})
, (baseCmd <> "--cross-target armv7-unknown-linux-gnueabihf", baseOptions{GHC.crossTarget = Just "armv7-unknown-linux-gnueabihf"})
, (baseCmd <> "-- --enable-unregisterised", baseOptions{GHC.addConfArgs = ["--enable-unregisterised"]})
, (baseCmd <> "--set", baseOptions{GHC.setCompile = True})
2023-10-13 08:35:39 +00:00
, (baseCmd <> "-o 9.4.5-p1", baseOptions{GHC.ovewrwiteVer = Just $(versionQ "9.4.5-p1")})
, (baseCmd <> "--overwrite-version 9.4.5-p1", baseOptions{GHC.ovewrwiteVer = Just $(versionQ "9.4.5-p1")})
2023-07-25 14:58:01 +00:00
, (baseCmd <> "-f make", baseOptions{GHC.buildFlavour = Just "make"})
, (baseCmd <> "--flavour make", baseOptions{GHC.buildFlavour = Just "make"})
2023-08-05 05:47:51 +00:00
, (baseCmd <> "--hadrian", baseOptions{GHC.buildSystem = Just Hadrian})
, (baseCmd <> "--make", baseOptions{GHC.buildSystem = Just Make})
2023-09-02 10:47:42 +00:00
#ifdef IS_WINDOWS
, (baseCmd <> "-i C:\\\\tmp\\out_dir", baseOptions{GHC.isolateDir = Just "C:\\\\tmp\\out_dir"})
, (baseCmd <> "--isolate C:\\\\tmp\\out_dir", baseOptions{GHC.isolateDir = Just "C:\\\\tmp\\out_dir"})
#else
2023-07-25 14:58:01 +00:00
, (baseCmd <> "-i /tmp/out_dir", baseOptions{GHC.isolateDir = Just "/tmp/out_dir"})
, (baseCmd <> "--isolate /tmp/out_dir", baseOptions{GHC.isolateDir = Just "/tmp/out_dir"})
2023-09-02 10:47:42 +00:00
#endif
2023-07-24 15:04:18 +00:00
]
2023-07-25 14:58:01 +00:00
where
2023-07-28 14:06:16 +00:00
baseCmd :: String
2023-07-25 14:58:01 +00:00
baseCmd = "compile ghc -v 9.4.5 -b 9.2.8 "
2023-07-28 14:06:16 +00:00
2023-07-25 14:58:01 +00:00
baseOptions :: GHCCompileOptions
baseOptions =
mkDefaultGHCCompileOptions
2023-10-13 08:35:39 +00:00
(GHC.SourceDist $(versionQ "9.4.5"))
(Left $(versionQ "9.2.8"))
2023-07-24 15:04:18 +00:00
compileHlsCheckList :: [(String, CompileCommand)]
2023-07-28 14:06:16 +00:00
compileHlsCheckList = mapSecond CompileHLS
[ ("compile hls -v 2.0.0.0 --ghc 9.2.8", baseOptions)
, ("compile hls --version 2.0.0.0 --ghc 9.2.8", baseOptions)
, ("compile hls -g a32db0b --ghc 9.2.8",
mkDefaultHLSCompileOptions
(HLS.GitDist $ GitBranch {ref = "a32db0b", repo = Nothing})
[ghc928]
)
, ("compile hls --git-ref a32db0b --ghc 9.2.8",
mkDefaultHLSCompileOptions
(HLS.GitDist $ GitBranch {ref = "a32db0b", repo = Nothing})
[ghc928]
)
, ("compile hls -g a32db0b -r https://github.com/haskell/haskell-language-server.git --ghc 9.2.8",
mkDefaultHLSCompileOptions
(HLS.GitDist $ GitBranch {ref = "a32db0b", repo = Just "https://github.com/haskell/haskell-language-server.git"})
[ghc928]
)
, ("compile hls -g a32db0b --repository https://github.com/haskell/haskell-language-server.git --ghc 9.2.8",
mkDefaultHLSCompileOptions
(HLS.GitDist $ GitBranch {ref = "a32db0b", repo = Just "https://github.com/haskell/haskell-language-server.git"})
[ghc928]
)
, ("compile hls --source-dist 2.0.0.0 --ghc 9.2.8",
mkDefaultHLSCompileOptions
2023-10-13 08:35:39 +00:00
(HLS.SourceDist $(versionQ "2.0.0.0"))
2023-07-28 14:06:16 +00:00
[ghc928]
)
, ("compile hls --remote-source-dist https://github.com/haskell/haskell-language-server/archive/refs/tags/2.0.0.1.tar.gz --ghc 9.2.8",
mkDefaultHLSCompileOptions
(HLS.RemoteDist [uri|https://github.com/haskell/haskell-language-server/archive/refs/tags/2.0.0.1.tar.gz|])
[ghc928]
)
, ("compile hls -v 2.0.0.0 --ghc latest",
mkDefaultHLSCompileOptions
2023-10-13 08:35:39 +00:00
(HLS.HackageDist $(versionQ "2.0.0.0"))
2023-07-28 14:06:16 +00:00
[ToolTag Latest]
)
, (baseCmd <> "-j20", baseOptions{HLS.jobs = Just 20})
, (baseCmd <> "--jobs 10", baseOptions{HLS.jobs = Just 10})
, (baseCmd <> "--no-set", baseOptions{HLS.setCompile = False})
, (baseCmd <> "--cabal-update", baseOptions{HLS.updateCabal = True})
2023-10-13 08:35:39 +00:00
, (baseCmd <> "-o 2.0.0.0-p1", baseOptions{HLS.ovewrwiteVer = Right $(versionQ "2.0.0.0-p1")})
, (baseCmd <> "--overwrite-version 2.0.0.0-p1", baseOptions{HLS.ovewrwiteVer = Right $(versionQ "2.0.0.0-p1")})
2023-07-28 14:06:16 +00:00
, (baseCmd <> "--git-describe-version", baseOptions{HLS.ovewrwiteVer = Left True})
2023-09-02 10:47:42 +00:00
#ifdef IS_WINDOWS
, (baseCmd <> "-i C:\\\\tmp\\out_dir", baseOptions{HLS.isolateDir = Just "C:\\\\tmp\\out_dir"})
, (baseCmd <> "--isolate C:\\\\tmp\\out_dir", baseOptions{HLS.isolateDir = Just "C:\\\\tmp\\out_dir"})
#else
2023-07-28 14:06:16 +00:00
, (baseCmd <> "-i /tmp/out_dir", baseOptions{HLS.isolateDir = Just "/tmp/out_dir"})
, (baseCmd <> "--isolate /tmp/out_dir", baseOptions{HLS.isolateDir = Just "/tmp/out_dir"})
2023-09-02 10:47:42 +00:00
#endif
2024-01-21 06:00:53 +00:00
#ifdef IS_WINDOWS
, (baseCmd <> "--cabal-project file:c:/tmp/cabal.project", baseOptions{HLS.cabalProject = Just $ Right [uri|file:c:/tmp/cabal.project|]})
#else
2023-07-28 14:06:16 +00:00
, (baseCmd <> "--cabal-project file:///tmp/cabal.project", baseOptions{HLS.cabalProject = Just $ Right [uri|file:///tmp/cabal.project|]})
2024-01-21 06:00:53 +00:00
#endif
2023-07-28 14:06:16 +00:00
, (baseCmd <> "--cabal-project cabal.ghc8107.project", baseOptions{HLS.cabalProject = Just $ Left "cabal.ghc8107.project"})
2024-01-21 06:00:53 +00:00
#ifdef IS_WINDOWS
, (baseCmd <> "--cabal-project-local file:c:/tmp/cabal.project.local", baseOptions{HLS.cabalProjectLocal = Just [uri|file:c:/tmp/cabal.project.local|]})
#else
2023-07-28 14:06:16 +00:00
, (baseCmd <> "--cabal-project-local file:///tmp/cabal.project.local", baseOptions{HLS.cabalProjectLocal = Just [uri|file:///tmp/cabal.project.local|]})
2024-01-21 06:00:53 +00:00
#endif
#ifdef IS_WINDOWS
, (baseCmd <> "--patch file:c:/example.patch", baseOptions{HLS.patches = Just $ Right [[uri|file:c:/example.patch|]]})
#else
2023-07-28 14:06:16 +00:00
, (baseCmd <> "--patch file:///example.patch", baseOptions{HLS.patches = Just $ Right [[uri|file:///example.patch|]]})
2024-01-21 06:00:53 +00:00
#endif
2023-07-28 14:06:16 +00:00
, (baseCmd <> "-p patch_dir", baseOptions{HLS.patches = Just (Left "patch_dir")})
, (baseCmd <> "--patchdir patch_dir", baseOptions{HLS.patches = Just (Left "patch_dir")})
, (baseCmd <> "-- --enable-tests", baseOptions{HLS.cabalArgs = ["--enable-tests"]})
]
where
baseCmd :: String
baseCmd = "compile hls -v 2.0.0.0 --ghc 9.2.8 "
baseOptions :: HLSCompileOptions
baseOptions =
mkDefaultHLSCompileOptions
2023-10-13 08:35:39 +00:00
(HLS.HackageDist $(versionQ "2.0.0.0"))
2023-07-28 14:06:16 +00:00
[ghc928]
ghc928 :: ToolVersion
2023-10-13 08:35:39 +00:00
ghc928 = GHCVersion $ GHCTargetVersion Nothing $(versionQ "9.2.8")
2023-07-24 15:04:18 +00:00
compileParseWith :: [String] -> IO CompileCommand
compileParseWith args = do
Compile a <- parseWith args
pure a