diff options
author | Cheng Shao <astrohavoc@gmail.com> | 2022-11-06 17:27:17 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-11-11 00:26:55 -0500 |
commit | d8262fdcc2a1be32b7e41fd8c550a53d54d3c821 (patch) | |
tree | 2e47fa7ee517c9d2031a0bb5d0641ca3f3cc8957 | |
parent | 435f42ea0c8f0a9cfe865ec5011c2a5d1f3aaec7 (diff) | |
download | haskell-d8262fdcc2a1be32b7e41fd8c550a53d54d3c821.tar.gz |
ci: add a stronger test for cross bindists
This commit adds a simple GHC API program that parses and reprints the
original hello world program used for basic testing of cross bindists.
Before there's full cross-compilation support in the test suite
driver, this provides better coverage than the original test.
-rwxr-xr-x | .gitlab/ci.sh | 5 | ||||
-rw-r--r-- | .gitlab/hello.hs | 45 |
2 files changed, 47 insertions, 3 deletions
diff --git a/.gitlab/ci.sh b/.gitlab/ci.sh index 1200e883e4..217440bbaf 100755 --- a/.gitlab/ci.sh +++ b/.gitlab/ci.sh @@ -580,9 +580,8 @@ function test_hadrian() { local instdir="$TOP/_build/install" local test_compiler="$instdir/bin/${cross_prefix}ghc$exe" install_bindist _build/bindist/ghc-*/ "$instdir" - echo 'main = putStrLn "hello world"' > hello.hs - echo "hello world" > expected - run "$test_compiler" hello.hs + echo 'main = putStrLn "hello world"' > expected + run "$test_compiler" -package ghc "$TOP/.gitlab/hello.hs" -o hello $CROSS_EMULATOR ./hello > actual run diff expected actual else diff --git a/.gitlab/hello.hs b/.gitlab/hello.hs new file mode 100644 index 0000000000..2837cac62d --- /dev/null +++ b/.gitlab/hello.hs @@ -0,0 +1,45 @@ +{-# OPTIONS_GHC -Wno-missing-fields #-} + +import GHC hiding (parseModule) +import GHC.Data.StringBuffer +import GHC.Driver.Config.Parser +import GHC.Parser +import GHC.Parser.Lexer +import GHC.Platform +import GHC.Plugins +import GHC.Settings +import GHC.Settings.Config + +fakeSettings :: Settings +fakeSettings = + Settings + { sGhcNameVersion = + GhcNameVersion + { ghcNameVersion_programName = + "ghc", + ghcNameVersion_projectVersion = + cProjectVersion + }, + sFileSettings = + FileSettings {}, + sToolSettings = ToolSettings {}, + sTargetPlatform = + genericPlatform, + sPlatformMisc = PlatformMisc {} + } + +fakeDynFlags :: DynFlags +fakeDynFlags = defaultDynFlags fakeSettings + +parse :: DynFlags -> String -> IO (Located (HsModule GhcPs)) +parse dflags src = do + let buf = stringToStringBuffer src + let loc = mkRealSrcLoc (mkFastString "Main.hs") 1 1 + case unP parseModule (initParserState (initParserOpts dflags) buf loc) of + PFailed _ -> fail "parseModule failed" + POk _ rdr_module -> pure rdr_module + +main :: IO () +main = do + m <- parse fakeDynFlags "main = putStrLn \"hello world\"" + putStrLn $ showSDoc fakeDynFlags $ ppr m |