From ceb9dbfa820e340c5117380e36b4b26a6f610bda Mon Sep 17 00:00:00 2001 From: Shayne Fletcher Date: Wed, 31 Jul 2024 22:51:53 -0400 Subject: [PATCH] ormolu check workflow --- .github/workflows/ormolu-check.yml | 25 + CI.hs | 872 +++++++++++++++-------------- ghc-lib-gen/src/GhclibgenFlavor.hs | 97 ++-- ghc-lib-gen/src/GhclibgenOpts.hs | 208 +++---- ghc-lib-gen/src/Main.hs | 53 +- 5 files changed, 679 insertions(+), 576 deletions(-) create mode 100644 .github/workflows/ormolu-check.yml diff --git a/.github/workflows/ormolu-check.yml b/.github/workflows/ormolu-check.yml new file mode 100644 index 00000000..da27778f --- /dev/null +++ b/.github/workflows/ormolu-check.yml @@ -0,0 +1,25 @@ +name: ormolu-check +on: + push: + pull_request: +jobs: + ormolu: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # - uses: haskell-actions/setup@v2 + # id: setup-haskell + # with: + # cabal-version: 'latest' + # - run: |- + # cabal install ormolu + # echo "$HOME/.cabal/bin" >> $GITHUB_PATH + - uses: haskell-actions/run-ormolu@v16 + with: + pattern: | + CI.hs + ghc-lib-gen/src/*.hs + examples/ghc-lib-test/ghc-lib-test-utils/src/*.hs + examples/ghc-lib-test/ghc-lib-test-mini-hlint/src/*.hs + examples/ghc-lib-test/ghc-lib-test-mini-compile/src/*.hs + mode: check diff --git a/CI.hs b/CI.hs index cf6162b1..9e5cf27b 100755 --- a/CI.hs +++ b/CI.hs @@ -1,11 +1,11 @@ +{-# LANGUAGE CPP #-} -- Copyright (c) 2019-2024 Digital Asset (Switzerland) GmbH and/or -- its affiliates. All rights reserved. SPDX-License-Identifier: -- (Apache-2.0 OR BSD-3-Clause) - -- CI script, compatible with all of Travis, Appveyor and Azure. {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} -{-# LANGUAGE CPP #-} + import Control.Monad.Extra import Data.Foldable import Data.List.Extra @@ -23,41 +23,74 @@ import System.Time.Extra main :: IO () main = do - let opts = - Opts.info (parseOptions Opts.<**> Opts.helper) + let opts = + Opts.info + (parseOptions Opts.<**> Opts.helper) ( Opts.fullDesc - <> Opts.progDesc "Build ghc-lib and ghc-lib-parser tarballs." - <> Opts.header "CI - CI script for ghc-lib" + <> Opts.progDesc "Build ghc-lib and ghc-lib-parser tarballs." + <> Opts.header "CI - CI script for ghc-lib" ) - Options { ghcFlavor, noGhcCheckout, noBuilds, versionSuffix } <- Opts.execParser opts - version <- buildDists ghcFlavor noGhcCheckout noBuilds versionSuffix - putStrLn version + Options {ghcFlavor, noGhcCheckout, noBuilds, versionSuffix} <- Opts.execParser opts + version <- buildDists ghcFlavor noGhcCheckout noBuilds versionSuffix + putStrLn version data Options = Options - { ghcFlavor :: GhcFlavor - , noGhcCheckout :: Bool - , noBuilds :: Bool - , versionSuffix :: Maybe String - } deriving (Show) - -data GhcFlavor = Da DaFlavor - | GhcMaster String - | Ghc9101 - | Ghc982 | Ghc981 - | Ghc966 | Ghc965 | Ghc964 | Ghc963 | Ghc962 | Ghc961 - | Ghc948 | Ghc947 | Ghc946 | Ghc945 | Ghc944 | Ghc943 | Ghc942 | Ghc941 - | Ghc928 | Ghc927 | Ghc926 | Ghc925 | Ghc924 | Ghc923 | Ghc922 | Ghc921 - | Ghc902 | Ghc901 - | Ghc8107 | Ghc8106 | Ghc8105 | Ghc8104 | Ghc8103 | Ghc8102 | Ghc8101 | Ghc881 - | Ghc884 | Ghc883 | Ghc882 + { ghcFlavor :: GhcFlavor, + noGhcCheckout :: Bool, + noBuilds :: Bool, + versionSuffix :: Maybe String + } + deriving (Show) + +data GhcFlavor + = Da DaFlavor + | GhcMaster String + | Ghc9101 + | Ghc982 + | Ghc981 + | Ghc966 + | Ghc965 + | Ghc964 + | Ghc963 + | Ghc962 + | Ghc961 + | Ghc948 + | Ghc947 + | Ghc946 + | Ghc945 + | Ghc944 + | Ghc943 + | Ghc942 + | Ghc941 + | Ghc928 + | Ghc927 + | Ghc926 + | Ghc925 + | Ghc924 + | Ghc923 + | Ghc922 + | Ghc921 + | Ghc902 + | Ghc901 + | Ghc8107 + | Ghc8106 + | Ghc8105 + | Ghc8104 + | Ghc8103 + | Ghc8102 + | Ghc8101 + | Ghc881 + | Ghc884 + | Ghc883 + | Ghc882 deriving (Eq, Show) data DaFlavor = DaFlavor - { mergeBaseSha :: String - , patches :: [String] - , cpp :: [String] - , flavor :: String - , upstream :: String + { mergeBaseSha :: String, + patches :: [String], + cpp :: [String], + flavor :: String, + upstream :: String } deriving (Eq, Show) @@ -67,47 +100,48 @@ current = "23f50640e705c132f1a0689d4850866d0f0d76a6" -- 2024-07-29 ghcFlavorOpt :: GhcFlavor -> String ghcFlavorOpt = \case - Ghc9101 -> "--ghc-flavor ghc-9.10.1" - Ghc982 -> "--ghc-flavor ghc-9.8.2" - Ghc981 -> "--ghc-flavor ghc-9.8.1" - Ghc966 -> "--ghc-flavor ghc-9.6.6" - Ghc965 -> "--ghc-flavor ghc-9.6.5" - Ghc964 -> "--ghc-flavor ghc-9.6.4" - Ghc963 -> "--ghc-flavor ghc-9.6.3" - Ghc962 -> "--ghc-flavor ghc-9.6.2" - Ghc961 -> "--ghc-flavor ghc-9.6.1" - Ghc948 -> "--ghc-flavor ghc-9.4.8" - Ghc947 -> "--ghc-flavor ghc-9.4.7" - Ghc946 -> "--ghc-flavor ghc-9.4.6" - Ghc945 -> "--ghc-flavor ghc-9.4.5" - Ghc944 -> "--ghc-flavor ghc-9.4.4" - Ghc943 -> "--ghc-flavor ghc-9.4.3" - Ghc942 -> "--ghc-flavor ghc-9.4.2" - Ghc941 -> "--ghc-flavor ghc-9.4.1" - Ghc928 -> "--ghc-flavor ghc-9.2.8" - Ghc927 -> "--ghc-flavor ghc-9.2.7" - Ghc926 -> "--ghc-flavor ghc-9.2.6" - Ghc925 -> "--ghc-flavor ghc-9.2.5" - Ghc924 -> "--ghc-flavor ghc-9.2.4" - Ghc923 -> "--ghc-flavor ghc-9.2.3" - Ghc922 -> "--ghc-flavor ghc-9.2.2" - Ghc921 -> "--ghc-flavor ghc-9.2.1" - Ghc901 -> "--ghc-flavor ghc-9.0.1" - Ghc902 -> "--ghc-flavor ghc-9.0.2" - Ghc8101 -> "--ghc-flavor ghc-8.10.1" - Ghc8102 -> "--ghc-flavor ghc-8.10.2" - Ghc8103 -> "--ghc-flavor ghc-8.10.3" - Ghc8104 -> "--ghc-flavor ghc-8.10.4" - Ghc8105 -> "--ghc-flavor ghc-8.10.5" - Ghc8106 -> "--ghc-flavor ghc-8.10.6" - Ghc8107 -> "--ghc-flavor ghc-8.10.7" - Ghc881 -> "--ghc-flavor ghc-8.8.1" - Ghc882 -> "--ghc-flavor ghc-8.8.2" - Ghc883 -> "--ghc-flavor ghc-8.8.3" - Ghc884 -> "--ghc-flavor ghc-8.8.4" - Da DaFlavor {flavor} -> "--ghc-flavor " <> flavor - GhcMaster _hash -> "--ghc-flavor ghc-master" - -- The git SHA1 hash is not passed to ghc-lib-gen at this time. + Ghc9101 -> "--ghc-flavor ghc-9.10.1" + Ghc982 -> "--ghc-flavor ghc-9.8.2" + Ghc981 -> "--ghc-flavor ghc-9.8.1" + Ghc966 -> "--ghc-flavor ghc-9.6.6" + Ghc965 -> "--ghc-flavor ghc-9.6.5" + Ghc964 -> "--ghc-flavor ghc-9.6.4" + Ghc963 -> "--ghc-flavor ghc-9.6.3" + Ghc962 -> "--ghc-flavor ghc-9.6.2" + Ghc961 -> "--ghc-flavor ghc-9.6.1" + Ghc948 -> "--ghc-flavor ghc-9.4.8" + Ghc947 -> "--ghc-flavor ghc-9.4.7" + Ghc946 -> "--ghc-flavor ghc-9.4.6" + Ghc945 -> "--ghc-flavor ghc-9.4.5" + Ghc944 -> "--ghc-flavor ghc-9.4.4" + Ghc943 -> "--ghc-flavor ghc-9.4.3" + Ghc942 -> "--ghc-flavor ghc-9.4.2" + Ghc941 -> "--ghc-flavor ghc-9.4.1" + Ghc928 -> "--ghc-flavor ghc-9.2.8" + Ghc927 -> "--ghc-flavor ghc-9.2.7" + Ghc926 -> "--ghc-flavor ghc-9.2.6" + Ghc925 -> "--ghc-flavor ghc-9.2.5" + Ghc924 -> "--ghc-flavor ghc-9.2.4" + Ghc923 -> "--ghc-flavor ghc-9.2.3" + Ghc922 -> "--ghc-flavor ghc-9.2.2" + Ghc921 -> "--ghc-flavor ghc-9.2.1" + Ghc901 -> "--ghc-flavor ghc-9.0.1" + Ghc902 -> "--ghc-flavor ghc-9.0.2" + Ghc8101 -> "--ghc-flavor ghc-8.10.1" + Ghc8102 -> "--ghc-flavor ghc-8.10.2" + Ghc8103 -> "--ghc-flavor ghc-8.10.3" + Ghc8104 -> "--ghc-flavor ghc-8.10.4" + Ghc8105 -> "--ghc-flavor ghc-8.10.5" + Ghc8106 -> "--ghc-flavor ghc-8.10.6" + Ghc8107 -> "--ghc-flavor ghc-8.10.7" + Ghc881 -> "--ghc-flavor ghc-8.8.1" + Ghc882 -> "--ghc-flavor ghc-8.8.2" + Ghc883 -> "--ghc-flavor ghc-8.8.3" + Ghc884 -> "--ghc-flavor ghc-8.8.4" + Da DaFlavor {flavor} -> "--ghc-flavor " <> flavor + GhcMaster _hash -> "--ghc-flavor ghc-master" + +-- The git SHA1 hash is not passed to ghc-lib-gen at this time. cppOpts :: GhcFlavor -> String cppOpts (Da DaFlavor {cpp}) = unwords $ concat [["--cpp", v] | v <- cpp] @@ -126,367 +160,377 @@ genVersionStr flavor suffix = _ -> "." <> suffix where base = case flavor of - Da {} -> "8.8.1" + Da {} -> "8.8.1" GhcMaster _ -> "0" - Ghc9101 -> "9.10.1" - Ghc982 -> "9.8.2" - Ghc981 -> "9.8.1" - Ghc966 -> "9.6.6" - Ghc965 -> "9.6.5" - Ghc964 -> "9.6.4" - Ghc963 -> "9.6.3" - Ghc962 -> "9.6.2" - Ghc961 -> "9.6.1" - Ghc948 -> "9.4.8" - Ghc947 -> "9.4.7" - Ghc946 -> "9.4.6" - Ghc945 -> "9.4.5" - Ghc944 -> "9.4.4" - Ghc943 -> "9.4.3" - Ghc942 -> "9.4.2" - Ghc941 -> "9.4.1" - Ghc928 -> "9.2.8" - Ghc927 -> "9.2.7" - Ghc926 -> "9.2.6" - Ghc925 -> "9.2.5" - Ghc924 -> "9.2.4" - Ghc923 -> "9.2.3" - Ghc922 -> "9.2.2" - Ghc921 -> "9.2.1" - Ghc901 -> "9.0.1" - Ghc902 -> "9.0.2" - Ghc8101 -> "8.10.1" - Ghc8102 -> "8.10.2" - Ghc8103 -> "8.10.3" - Ghc8104 -> "8.10.4" - Ghc8105 -> "8.10.5" - Ghc8106 -> "8.10.6" - Ghc8107 -> "8.10.7" - Ghc881 -> "8.8.1" - Ghc882 -> "8.8.2" - Ghc883 -> "8.8.3" - Ghc884 -> "8.8.4" + Ghc9101 -> "9.10.1" + Ghc982 -> "9.8.2" + Ghc981 -> "9.8.1" + Ghc966 -> "9.6.6" + Ghc965 -> "9.6.5" + Ghc964 -> "9.6.4" + Ghc963 -> "9.6.3" + Ghc962 -> "9.6.2" + Ghc961 -> "9.6.1" + Ghc948 -> "9.4.8" + Ghc947 -> "9.4.7" + Ghc946 -> "9.4.6" + Ghc945 -> "9.4.5" + Ghc944 -> "9.4.4" + Ghc943 -> "9.4.3" + Ghc942 -> "9.4.2" + Ghc941 -> "9.4.1" + Ghc928 -> "9.2.8" + Ghc927 -> "9.2.7" + Ghc926 -> "9.2.6" + Ghc925 -> "9.2.5" + Ghc924 -> "9.2.4" + Ghc923 -> "9.2.3" + Ghc922 -> "9.2.2" + Ghc921 -> "9.2.1" + Ghc901 -> "9.0.1" + Ghc902 -> "9.0.2" + Ghc8101 -> "8.10.1" + Ghc8102 -> "8.10.2" + Ghc8103 -> "8.10.3" + Ghc8104 -> "8.10.4" + Ghc8105 -> "8.10.5" + Ghc8106 -> "8.10.6" + Ghc8107 -> "8.10.7" + Ghc881 -> "8.8.1" + Ghc882 -> "8.8.2" + Ghc883 -> "8.8.3" + Ghc884 -> "8.8.4" parseOptions :: Opts.Parser Options -parseOptions = Options - <$> ((Da <$> parseDaOptions) - Opts.<|> - Opts.option readFlavor - ( Opts.long "ghc-flavor" - <> Opts.help "The ghc-flavor to test against" - ) +parseOptions = + Options + <$> ( (Da <$> parseDaOptions) + Opts.<|> Opts.option + readFlavor + ( Opts.long "ghc-flavor" + <> Opts.help "The ghc-flavor to test against" + ) ) <*> Opts.switch - ( Opts.long "no-checkout" + ( Opts.long "no-checkout" <> Opts.help "If enabled, don't perform a GHC checkout" - ) + ) <*> Opts.switch - ( Opts.long "no-builds" + ( Opts.long "no-builds" <> Opts.help "If enabled, don't build & test packages & examples" - ) + ) <*> Opts.optional - ( Opts.strOption - ( Opts.long "version-suffix" - <> Opts.help "If specified, append to version string for generated ghc-lib. Otherwise use current date." + ( Opts.strOption + ( Opts.long "version-suffix" + <> Opts.help "If specified, append to version string for generated ghc-lib. Otherwise use current date." + ) + ) + where + readFlavor :: Opts.ReadM GhcFlavor + readFlavor = Opts.eitherReader $ \case + "ghc-9.10.1" -> Right Ghc9101 + "ghc-9.8.2" -> Right Ghc982 + "ghc-9.8.1" -> Right Ghc981 + "ghc-9.6.6" -> Right Ghc966 + "ghc-9.6.5" -> Right Ghc965 + "ghc-9.6.4" -> Right Ghc964 + "ghc-9.6.3" -> Right Ghc963 + "ghc-9.6.2" -> Right Ghc962 + "ghc-9.6.1" -> Right Ghc961 + "ghc-9.4.8" -> Right Ghc948 + "ghc-9.4.7" -> Right Ghc947 + "ghc-9.4.6" -> Right Ghc946 + "ghc-9.4.5" -> Right Ghc945 + "ghc-9.4.4" -> Right Ghc944 + "ghc-9.4.3" -> Right Ghc943 + "ghc-9.4.2" -> Right Ghc942 + "ghc-9.4.1" -> Right Ghc941 + "ghc-9.2.8" -> Right Ghc928 + "ghc-9.2.7" -> Right Ghc927 + "ghc-9.2.6" -> Right Ghc926 + "ghc-9.2.5" -> Right Ghc925 + "ghc-9.2.4" -> Right Ghc924 + "ghc-9.2.3" -> Right Ghc923 + "ghc-9.2.2" -> Right Ghc922 + "ghc-9.2.1" -> Right Ghc921 + "ghc-9.0.1" -> Right Ghc901 + "ghc-9.0.2" -> Right Ghc902 + "ghc-8.10.1" -> Right Ghc8101 + "ghc-8.10.2" -> Right Ghc8102 + "ghc-8.10.3" -> Right Ghc8103 + "ghc-8.10.4" -> Right Ghc8104 + "ghc-8.10.5" -> Right Ghc8105 + "ghc-8.10.6" -> Right Ghc8106 + "ghc-8.10.7" -> Right Ghc8107 + "ghc-8.8.1" -> Right Ghc881 + "ghc-8.8.2" -> Right Ghc882 + "ghc-8.8.3" -> Right Ghc883 + "ghc-8.8.4" -> Right Ghc884 + "ghc-master" -> Right (GhcMaster current) + hash -> Right (GhcMaster hash) + parseDaOptions :: Opts.Parser DaFlavor + parseDaOptions = + Opts.flag' DaFlavor (Opts.long "da" <> Opts.help "Enables DA custom build.") + <*> Opts.strOption + ( Opts.long "merge-base-sha" + <> Opts.help "DA flavor only. Base commit to use from the GHC repo." + <> Opts.showDefault + <> Opts.value "ghc-8.8.1-release" + ) + <*> ( Opts.some + ( Opts.strOption + ( Opts.long "patch" + <> Opts.help "DA flavor only. Commits to merge in from the DA GHC fork, referenced as 'upstream'. Can be specified multiple times. If no patch is specified, default will be equivalent to `--patch upstream/da-master-8.8.1`. Specifying any patch will overwrite the default (i.e. replace, not add)." + ) + ) + Opts.<|> pure ["upstream/da-master-8.8.1"] + ) + <*> ( Opts.some + ( Opts.strOption + ( Opts.long "cpp" + <> Opts.help "DA flavor only. CPP flags to pass on to ghc-lib-gen. Can be specified multiple times. If no flags are specified, default will be equivalent to `--cpp -DDAML_PRIM`. Specifying any flag will overwrite the default (i.e. replace, not add)." + ) + ) + Opts.<|> pure ["-DDAML_PRIM"] ) + <*> Opts.strOption + ( Opts.long "gen-flavor" + <> Opts.help "DA flavor only. Flavor to pass on to ghc-lib-gen." + <> Opts.showDefault + <> Opts.value "da-ghc-8.8.1" + ) + <*> Opts.strOption + ( Opts.long "upstream" + <> Opts.help "DA flavor only. URL for the git remote add command." + <> Opts.showDefault + <> Opts.value "https://github.com/digital-asset/ghc.git" ) - where - readFlavor :: Opts.ReadM GhcFlavor - readFlavor = Opts.eitherReader $ \case - "ghc-9.10.1" -> Right Ghc9101 - "ghc-9.8.2" -> Right Ghc982 - "ghc-9.8.1" -> Right Ghc981 - "ghc-9.6.6" -> Right Ghc966 - "ghc-9.6.5" -> Right Ghc965 - "ghc-9.6.4" -> Right Ghc964 - "ghc-9.6.3" -> Right Ghc963 - "ghc-9.6.2" -> Right Ghc962 - "ghc-9.6.1" -> Right Ghc961 - "ghc-9.4.8" -> Right Ghc948 - "ghc-9.4.7" -> Right Ghc947 - "ghc-9.4.6" -> Right Ghc946 - "ghc-9.4.5" -> Right Ghc945 - "ghc-9.4.4" -> Right Ghc944 - "ghc-9.4.3" -> Right Ghc943 - "ghc-9.4.2" -> Right Ghc942 - "ghc-9.4.1" -> Right Ghc941 - "ghc-9.2.8" -> Right Ghc928 - "ghc-9.2.7" -> Right Ghc927 - "ghc-9.2.6" -> Right Ghc926 - "ghc-9.2.5" -> Right Ghc925 - "ghc-9.2.4" -> Right Ghc924 - "ghc-9.2.3" -> Right Ghc923 - "ghc-9.2.2" -> Right Ghc922 - "ghc-9.2.1" -> Right Ghc921 - "ghc-9.0.1" -> Right Ghc901 - "ghc-9.0.2" -> Right Ghc902 - "ghc-8.10.1" -> Right Ghc8101 - "ghc-8.10.2" -> Right Ghc8102 - "ghc-8.10.3" -> Right Ghc8103 - "ghc-8.10.4" -> Right Ghc8104 - "ghc-8.10.5" -> Right Ghc8105 - "ghc-8.10.6" -> Right Ghc8106 - "ghc-8.10.7" -> Right Ghc8107 - "ghc-8.8.1" -> Right Ghc881 - "ghc-8.8.2" -> Right Ghc882 - "ghc-8.8.3" -> Right Ghc883 - "ghc-8.8.4" -> Right Ghc884 - "ghc-master" -> Right (GhcMaster current) - hash -> Right (GhcMaster hash) - parseDaOptions :: Opts.Parser DaFlavor - parseDaOptions = - Opts.flag' DaFlavor ( Opts.long "da" <> Opts.help "Enables DA custom build." ) - <*> Opts.strOption - ( Opts.long "merge-base-sha" - <> Opts.help "DA flavor only. Base commit to use from the GHC repo." - <> Opts.showDefault - <> Opts.value "ghc-8.8.1-release" - ) - <*> (Opts.some - (Opts.strOption - ( Opts.long "patch" - <> Opts.help "DA flavor only. Commits to merge in from the DA GHC fork, referenced as 'upstream'. Can be specified multiple times. If no patch is specified, default will be equivalent to `--patch upstream/da-master-8.8.1`. Specifying any patch will overwrite the default (i.e. replace, not add)." - )) - Opts.<|> - pure ["upstream/da-master-8.8.1"]) - <*> (Opts.some - (Opts.strOption - ( Opts.long "cpp" - <> Opts.help "DA flavor only. CPP flags to pass on to ghc-lib-gen. Can be specified multiple times. If no flags are specified, default will be equivalent to `--cpp -DDAML_PRIM`. Specifying any flag will overwrite the default (i.e. replace, not add)." - )) - Opts.<|> - pure ["-DDAML_PRIM"]) - <*> Opts.strOption - ( Opts.long "gen-flavor" - <> Opts.help "DA flavor only. Flavor to pass on to ghc-lib-gen." - <> Opts.showDefault - <> Opts.value "da-ghc-8.8.1") - <*> Opts.strOption - ( Opts.long "upstream" - <> Opts.help "DA flavor only. URL for the git remote add command." - <> Opts.showDefault - <> Opts.value "https://github.com/digital-asset/ghc.git") buildDists :: GhcFlavor -> Bool -> Bool -> Maybe String -> IO String buildDists ghcFlavor noGhcCheckout noBuilds versionSuffix = do - filesInDot <- getDirectoryContents "." - let lockFiles = filter (isExtensionOf ".lock") filesInDot - tarBalls = filter (isExtensionOf ".tar.gz") filesInDot - ghcDirs = ["ghc" | not noGhcCheckout] ++ [ "ghc-lib", "ghc-lib-parser" ] - toDelete = ghcDirs ++ tarBalls ++ lockFiles - forM_ toDelete removePath - system_ "rm -f cabal.project" - system_ "git checkout ghc-lib-gen.cabal examples" - - -- If '--no-checkout' is given, it's on the caller to get the GHC - -- clone with e.g. - -- git clone https://gitlab.haskell.org/ghc/ghc.git && \ - -- git fetch --tags && git submodule update --init --recursive - -- and it won't be deleted between runs. - if noGhcCheckout then do + filesInDot <- getDirectoryContents "." + let lockFiles = filter (isExtensionOf ".lock") filesInDot + tarBalls = filter (isExtensionOf ".tar.gz") filesInDot + ghcDirs = ["ghc" | not noGhcCheckout] ++ ["ghc-lib", "ghc-lib-parser"] + toDelete = ghcDirs ++ tarBalls ++ lockFiles + forM_ toDelete removePath + system_ "rm -f cabal.project" + system_ "git checkout ghc-lib-gen.cabal examples" + + -- If '--no-checkout' is given, it's on the caller to get the GHC + -- clone with e.g. + -- git clone https://gitlab.haskell.org/ghc/ghc.git && \ + -- git fetch --tags && git submodule update --init --recursive + -- and it won't be deleted between runs. + if noGhcCheckout + then do system_ "{ cd ghc; git remote remove upstream || true; }" system_ "cd ghc && git clean -xdf && git submodule foreach git clean -xdf && git submodule foreach git checkout . && git checkout ." else do system_ "git clone https://gitlab.haskell.org/ghc/ghc.git" system_ "cd ghc && git fetch --tags" - gitCheckout ghcFlavor - system_ "cd ghc && git checkout ." - - version <- tag - let pkg_ghclib = "ghc-lib-" ++ version - pkg_ghclib_parser = "ghc-lib-parser-" ++ version - ghcFlavorArg = ghcFlavorOpt ghcFlavor - - system_ "cabal build exe:ghc-lib-gen" - system_ $ "cabal run exe:ghc-lib-gen -- ghc ../patches --ghc-lib-parser " ++ ghcFlavorArg ++ " " ++ cppOpts ghcFlavor - patchVersion version "ghc/ghc-lib-parser.cabal" - mkTarball pkg_ghclib_parser - renameDirectory pkg_ghclib_parser "ghc-lib-parser" - removeFile "ghc/ghc-lib-parser.cabal" - system_ $ "cabal run exe:ghc-lib-gen -- ghc ../patches --ghc-lib " ++ ghcFlavorArg ++ " " ++ cppOpts ghcFlavor ++ " --skip-init" - patchVersion version "ghc/ghc-lib.cabal" - patchConstraints version "ghc/ghc-lib.cabal" - mkTarball pkg_ghclib - renameDirectory pkg_ghclib "ghc-lib" - removeFile "ghc/ghc-lib.cabal" - - copyDirectoryRecursive - "ghc-lib-gen/ghc-lib-parser" - "examples/ghc-lib-test-mini-hlint/extra-source-files" - copyDirectoryRecursive - "ghc-lib-gen/ghc-lib-parser" - "examples/ghc-lib-test-mini-compile/extra-source-files/ghc-lib-parser" - copyDirectoryRecursive - "ghc-lib-gen/ghc-lib" - "examples/ghc-lib-test-mini-compile/extra-source-files/ghc-lib" - - patchVersion version "ghc-lib-gen.cabal" - patchVersion version "examples/ghc-lib-test-utils/ghc-lib-test-utils.cabal" - patchConstraints version "examples/ghc-lib-test-utils/ghc-lib-test-utils.cabal" - patchVersion version "examples/ghc-lib-test-mini-hlint/ghc-lib-test-mini-hlint.cabal" - patchConstraints version "examples/ghc-lib-test-mini-hlint/ghc-lib-test-mini-hlint.cabal" - patchVersion version "examples/ghc-lib-test-mini-compile/ghc-lib-test-mini-compile.cabal" - patchConstraints version "examples/ghc-lib-test-mini-compile/ghc-lib-test-mini-compile.cabal" - - verifyConstraint "ghc-lib-parser == " version "ghc-lib/ghc-lib.cabal" - verifyConstraint "ghc-lib-parser == " version "examples/ghc-lib-test-mini-hlint/ghc-lib-test-mini-hlint.cabal" - verifyConstraint "ghc-lib-test-utils == " version "examples/ghc-lib-test-mini-hlint/ghc-lib-test-mini-hlint.cabal" - verifyConstraint "ghc-lib-parser == " version "examples/ghc-lib-test-mini-compile/ghc-lib-test-mini-compile.cabal" - verifyConstraint "ghc-lib == " version "examples/ghc-lib-test-mini-compile/ghc-lib-test-mini-compile.cabal" - - system_ "cabal sdist -o ." - system_ "(cd examples/ghc-lib-test-utils && cabal sdist -o ../..)" - system_ "(cd examples/ghc-lib-test-mini-hlint && cabal sdist -o ../..)" - system_ "(cd examples/ghc-lib-test-mini-compile && cabal sdist -o ../..)" - - when noBuilds exitSuccess - - writeFile "cabal.project" ( unlines $ - [ "packages: " - , " ghc-lib-parser/ghc-lib-parser.cabal" - , " ghc-lib/ghc-lib.cabal" - , " examples/ghc-lib-test-utils/ghc-lib-test-utils.cabal" - , " examples/ghc-lib-test-mini-hlint/ghc-lib-test-mini-hlint.cabal" - , " examples/ghc-lib-test-mini-compile/ghc-lib-test-mini-compile.cabal" - ] ++ - [ "constraints: ghc-lib-test-mini-compile +daml-unit-ids" | Da {} <- [ghcFlavor] ] - ) - - writeCabalCmdFile "ghc-lib-test-mini-hlint" - writeCabalCmdFile "ghc-lib-test-mini-compile" - - cmd "cabal build --ghc-options=-j all" - - system_ $ "cd examples/ghc-lib-test-mini-hlint && cabal test --project-dir ../.. --test-show-details direct --test-options \"--color always --test-command ../../ghc-lib-test-mini-hlint " ++ ghcFlavorArg ++ "\"" - system_ $ "cd examples/ghc-lib-test-mini-compile && cabal test --project-dir ../.. --test-show-details direct --test-options \"--color always --test-command ../../ghc-lib-test-mini-compile " ++ ghcFlavorArg ++ "\"" - system_ "cabal exec -- ghc -ignore-dot-ghci -package=ghc-lib-parser -e \"print 1\"" - system_ "cabal exec -- ghc -ignore-dot-ghci -package=ghc-lib -e \"print 1\"" - - -- Something like, "8.8.1.20190828". - tag -- The return value of type 'IO string'. - - where - - writeCabalCmdFile :: String -> IO () - writeCabalCmdFile exe = do - let filename = exe - cmd = "cabal run exe:" ++ exe ++ " --project-dir ../.. -- " - writeFile filename cmd - - cmd :: String -> IO () - cmd x = do - putStrLn $ "\n\n# Running: " ++ x - hFlush stdout - (t, _) <- duration $ system_ x - putStrLn $ "# Completed in " ++ showDuration t ++ ": " ++ x ++ "\n" - hFlush stdout - - mkTarball :: String -> IO () - mkTarball target = do - system_ "(cd ghc && cabal sdist -o ..)" - system_ $ "tar -xvf " ++ target ++ ".tar.gz" - - tag :: IO String - tag = do - suffix <- maybe genDateSuffix pure versionSuffix - return $ genVersionStr ghcFlavor suffix - - patchVersion :: String -> FilePath -> IO () - patchVersion version file = - writeFile file . - -- ghc-lib, ghc-lib-parser - replace "version: 0.1.0" ("version: " ++ version) . - -- ghc-lib-test-mini-hlint, ghc-lib-test-mini-compile - replace "version: 0.1.0.0" ("version: " ++ version) - =<< readFile' file - - patchConstraints :: String -> FilePath -> IO () - patchConstraints version file = - writeFile file . - -- affects ghc-lib.cabal - replace " ghc-lib-parser\n" (" ghc-lib-parser == " ++ version ++ "\n") . - -- affects ghc-lib-test-utils, ghc-lib-test-mini-hlint, ghc-lib-test-mini-compile - replace ", ghc-lib-test-utils" (", ghc-lib-test-utils == " ++ version ++ "\n") . - replace ", ghc-lib\n" (", ghc-lib == " ++ version ++ "\n") . - replace ", ghc-lib-parser\n" (", ghc-lib-parser == " ++ version ++ "\n") - =<< readFile' file - - verifyConstraint :: String -> String -> String -> IO () - verifyConstraint constraint version file = do - res <- stripInfix constraint <$> readFile' file - case res of - Just (_, r) -> do - case words r of - v : _ -> unless (v == version) exitError - _ -> exitError - Nothing -> exitError - where - exitError = die $ file ++ ": " ++ constraint ++ version ++ " not satisfied" - - removePath :: FilePath -> IO () - removePath p = - whenM (doesPathExist p) $ do - putStrLn $ "# Removing " ++ p - removePathForcibly p - - gitCheckout :: GhcFlavor -> IO () - gitCheckout ghcFlavor = do - system_ $ "cd ghc && git checkout -f " <> branch ghcFlavor - case ghcFlavor of - Da DaFlavor { patches, upstream } -> do - system_ $ "cd ghc && git remote add upstream " <> upstream - system_ "cd ghc && git fetch upstream" - system_ $ "cd ghc && git -c user.name=\"Cookie Monster\" -c user.email=cookie.monster@seasame-street.com merge --no-edit " <> unwords patches - _ -> pure () - system_ "cd ghc && git submodule update --init --recursive" - - branch :: GhcFlavor -> String - branch = \case - Ghc9101 -> "ghc-9.10.1-release" - Ghc982 -> "ghc-9.8.2-release" - Ghc981 -> "ghc-9.8.1-release" - Ghc966 -> "ghc-9.6.6-release" - Ghc965 -> "ghc-9.6.5-release" - Ghc964 -> "ghc-9.6.4-release" - Ghc963 -> "ghc-9.6.3-release" - Ghc962 -> "ghc-9.6.2-release" - Ghc961 -> "ghc-9.6.1-release" - Ghc948 -> "ghc-9.4.8-release" - Ghc947 -> "ghc-9.4.7-release" - Ghc946 -> "ghc-9.4.6-release" - Ghc945 -> "ghc-9.4.5-release" - Ghc944 -> "ghc-9.4.4-release" - Ghc943 -> "ghc-9.4.3-release" - Ghc942 -> "ghc-9.4.2-release" - Ghc941 -> "ghc-9.4.1-release" - Ghc928 -> "ghc-9.2.8-release" - Ghc927 -> "ghc-9.2.7-release" - Ghc926 -> "ghc-9.2.6-release" - Ghc925 -> "ghc-9.2.5-release" - Ghc924 -> "ghc-9.2.4-release" - Ghc923 -> "ghc-9.2.3-release" - Ghc922 -> "ghc-9.2.2-release" - Ghc921 -> "ghc-9.2.1-release" - Ghc901 -> "ghc-9.0.1-release" - Ghc902 -> "ghc-9.0.2-release" - Ghc8101 -> "ghc-8.10.1-release" - Ghc8102 -> "ghc-8.10.2-release" - Ghc8103 -> "ghc-8.10.3-release" - Ghc8104 -> "ghc-8.10.4-release" - Ghc8105 -> "ghc-8.10.5-release" - Ghc8106 -> "ghc-8.10.6-release" - Ghc8107 -> "ghc-8.10.7-release" - Ghc881 -> "ghc-8.8.1-release" - Ghc882 -> "ghc-8.8.2-release" - Ghc883 -> "ghc-8.8.3-release" - Ghc884 -> "ghc-8.8.4-release" - Da DaFlavor { mergeBaseSha } -> mergeBaseSha - GhcMaster hash -> hash + gitCheckout ghcFlavor + system_ "cd ghc && git checkout ." + + version <- tag + let pkg_ghclib = "ghc-lib-" ++ version + pkg_ghclib_parser = "ghc-lib-parser-" ++ version + ghcFlavorArg = ghcFlavorOpt ghcFlavor + + system_ "cabal build exe:ghc-lib-gen" + system_ $ "cabal run exe:ghc-lib-gen -- ghc ../patches --ghc-lib-parser " ++ ghcFlavorArg ++ " " ++ cppOpts ghcFlavor + patchVersion version "ghc/ghc-lib-parser.cabal" + mkTarball pkg_ghclib_parser + renameDirectory pkg_ghclib_parser "ghc-lib-parser" + removeFile "ghc/ghc-lib-parser.cabal" + system_ $ "cabal run exe:ghc-lib-gen -- ghc ../patches --ghc-lib " ++ ghcFlavorArg ++ " " ++ cppOpts ghcFlavor ++ " --skip-init" + patchVersion version "ghc/ghc-lib.cabal" + patchConstraints version "ghc/ghc-lib.cabal" + mkTarball pkg_ghclib + renameDirectory pkg_ghclib "ghc-lib" + removeFile "ghc/ghc-lib.cabal" + + copyDirectoryRecursive + "ghc-lib-gen/ghc-lib-parser" + "examples/ghc-lib-test-mini-hlint/extra-source-files" + copyDirectoryRecursive + "ghc-lib-gen/ghc-lib-parser" + "examples/ghc-lib-test-mini-compile/extra-source-files/ghc-lib-parser" + copyDirectoryRecursive + "ghc-lib-gen/ghc-lib" + "examples/ghc-lib-test-mini-compile/extra-source-files/ghc-lib" + + patchVersion version "ghc-lib-gen.cabal" + patchVersion version "examples/ghc-lib-test-utils/ghc-lib-test-utils.cabal" + patchConstraints version "examples/ghc-lib-test-utils/ghc-lib-test-utils.cabal" + patchVersion version "examples/ghc-lib-test-mini-hlint/ghc-lib-test-mini-hlint.cabal" + patchConstraints version "examples/ghc-lib-test-mini-hlint/ghc-lib-test-mini-hlint.cabal" + patchVersion version "examples/ghc-lib-test-mini-compile/ghc-lib-test-mini-compile.cabal" + patchConstraints version "examples/ghc-lib-test-mini-compile/ghc-lib-test-mini-compile.cabal" + + verifyConstraint "ghc-lib-parser == " version "ghc-lib/ghc-lib.cabal" + verifyConstraint "ghc-lib-parser == " version "examples/ghc-lib-test-mini-hlint/ghc-lib-test-mini-hlint.cabal" + verifyConstraint "ghc-lib-test-utils == " version "examples/ghc-lib-test-mini-hlint/ghc-lib-test-mini-hlint.cabal" + verifyConstraint "ghc-lib-parser == " version "examples/ghc-lib-test-mini-compile/ghc-lib-test-mini-compile.cabal" + verifyConstraint "ghc-lib == " version "examples/ghc-lib-test-mini-compile/ghc-lib-test-mini-compile.cabal" + + system_ "cabal sdist -o ." + system_ "(cd examples/ghc-lib-test-utils && cabal sdist -o ../..)" + system_ "(cd examples/ghc-lib-test-mini-hlint && cabal sdist -o ../..)" + system_ "(cd examples/ghc-lib-test-mini-compile && cabal sdist -o ../..)" + + when noBuilds exitSuccess + + writeFile + "cabal.project" + ( unlines $ + [ "packages: ", + " ghc-lib-parser/ghc-lib-parser.cabal", + " ghc-lib/ghc-lib.cabal", + " examples/ghc-lib-test-utils/ghc-lib-test-utils.cabal", + " examples/ghc-lib-test-mini-hlint/ghc-lib-test-mini-hlint.cabal", + " examples/ghc-lib-test-mini-compile/ghc-lib-test-mini-compile.cabal" + ] + ++ ["constraints: ghc-lib-test-mini-compile +daml-unit-ids" | Da {} <- [ghcFlavor]] + ) + + writeCabalCmdFile "ghc-lib-test-mini-hlint" + writeCabalCmdFile "ghc-lib-test-mini-compile" + + cmd "cabal build --ghc-options=-j all" + + system_ $ "cd examples/ghc-lib-test-mini-hlint && cabal test --project-dir ../.. --test-show-details direct --test-options \"--color always --test-command ../../ghc-lib-test-mini-hlint " ++ ghcFlavorArg ++ "\"" + system_ $ "cd examples/ghc-lib-test-mini-compile && cabal test --project-dir ../.. --test-show-details direct --test-options \"--color always --test-command ../../ghc-lib-test-mini-compile " ++ ghcFlavorArg ++ "\"" + system_ "cabal exec -- ghc -ignore-dot-ghci -package=ghc-lib-parser -e \"print 1\"" + system_ "cabal exec -- ghc -ignore-dot-ghci -package=ghc-lib -e \"print 1\"" + + -- Something like, "8.8.1.20190828". + tag -- The return value of type 'IO string'. + where + writeCabalCmdFile :: String -> IO () + writeCabalCmdFile exe = do + let filename = exe + cmd = "cabal run exe:" ++ exe ++ " --project-dir ../.. -- " + writeFile filename cmd + + cmd :: String -> IO () + cmd x = do + putStrLn $ "\n\n# Running: " ++ x + hFlush stdout + (t, _) <- duration $ system_ x + putStrLn $ "# Completed in " ++ showDuration t ++ ": " ++ x ++ "\n" + hFlush stdout + + mkTarball :: String -> IO () + mkTarball target = do + system_ "(cd ghc && cabal sdist -o ..)" + system_ $ "tar -xvf " ++ target ++ ".tar.gz" + + tag :: IO String + tag = do + suffix <- maybe genDateSuffix pure versionSuffix + return $ genVersionStr ghcFlavor suffix + + patchVersion :: String -> FilePath -> IO () + patchVersion version file = + writeFile file + . + -- ghc-lib, ghc-lib-parser + replace "version: 0.1.0" ("version: " ++ version) + . + -- ghc-lib-test-mini-hlint, ghc-lib-test-mini-compile + replace "version: 0.1.0.0" ("version: " ++ version) + =<< readFile' file + + patchConstraints :: String -> FilePath -> IO () + patchConstraints version file = + writeFile file + . + -- affects ghc-lib.cabal + replace " ghc-lib-parser\n" (" ghc-lib-parser == " ++ version ++ "\n") + . + -- affects ghc-lib-test-utils, ghc-lib-test-mini-hlint, ghc-lib-test-mini-compile + replace ", ghc-lib-test-utils" (", ghc-lib-test-utils == " ++ version ++ "\n") + . replace ", ghc-lib\n" (", ghc-lib == " ++ version ++ "\n") + . replace ", ghc-lib-parser\n" (", ghc-lib-parser == " ++ version ++ "\n") + =<< readFile' file + + verifyConstraint :: String -> String -> String -> IO () + verifyConstraint constraint version file = do + res <- stripInfix constraint <$> readFile' file + case res of + Just (_, r) -> do + case words r of + v : _ -> unless (v == version) exitError + _ -> exitError + Nothing -> exitError + where + exitError = die $ file ++ ": " ++ constraint ++ version ++ " not satisfied" + + removePath :: FilePath -> IO () + removePath p = + whenM (doesPathExist p) $ do + putStrLn $ "# Removing " ++ p + removePathForcibly p + + gitCheckout :: GhcFlavor -> IO () + gitCheckout ghcFlavor = do + system_ $ "cd ghc && git checkout -f " <> branch ghcFlavor + case ghcFlavor of + Da DaFlavor {patches, upstream} -> do + system_ $ "cd ghc && git remote add upstream " <> upstream + system_ "cd ghc && git fetch upstream" + system_ $ "cd ghc && git -c user.name=\"Cookie Monster\" -c user.email=cookie.monster@seasame-street.com merge --no-edit " <> unwords patches + _ -> pure () + system_ "cd ghc && git submodule update --init --recursive" + + branch :: GhcFlavor -> String + branch = \case + Ghc9101 -> "ghc-9.10.1-release" + Ghc982 -> "ghc-9.8.2-release" + Ghc981 -> "ghc-9.8.1-release" + Ghc966 -> "ghc-9.6.6-release" + Ghc965 -> "ghc-9.6.5-release" + Ghc964 -> "ghc-9.6.4-release" + Ghc963 -> "ghc-9.6.3-release" + Ghc962 -> "ghc-9.6.2-release" + Ghc961 -> "ghc-9.6.1-release" + Ghc948 -> "ghc-9.4.8-release" + Ghc947 -> "ghc-9.4.7-release" + Ghc946 -> "ghc-9.4.6-release" + Ghc945 -> "ghc-9.4.5-release" + Ghc944 -> "ghc-9.4.4-release" + Ghc943 -> "ghc-9.4.3-release" + Ghc942 -> "ghc-9.4.2-release" + Ghc941 -> "ghc-9.4.1-release" + Ghc928 -> "ghc-9.2.8-release" + Ghc927 -> "ghc-9.2.7-release" + Ghc926 -> "ghc-9.2.6-release" + Ghc925 -> "ghc-9.2.5-release" + Ghc924 -> "ghc-9.2.4-release" + Ghc923 -> "ghc-9.2.3-release" + Ghc922 -> "ghc-9.2.2-release" + Ghc921 -> "ghc-9.2.1-release" + Ghc901 -> "ghc-9.0.1-release" + Ghc902 -> "ghc-9.0.2-release" + Ghc8101 -> "ghc-8.10.1-release" + Ghc8102 -> "ghc-8.10.2-release" + Ghc8103 -> "ghc-8.10.3-release" + Ghc8104 -> "ghc-8.10.4-release" + Ghc8105 -> "ghc-8.10.5-release" + Ghc8106 -> "ghc-8.10.6-release" + Ghc8107 -> "ghc-8.10.7-release" + Ghc881 -> "ghc-8.8.1-release" + Ghc882 -> "ghc-8.8.2-release" + Ghc883 -> "ghc-8.8.3-release" + Ghc884 -> "ghc-8.8.4-release" + Da DaFlavor {mergeBaseSha} -> mergeBaseSha + GhcMaster hash -> hash copyDirectoryRecursive :: FilePath -> FilePath -> IO () copyDirectoryRecursive srcDir destDir = withFrozenCallStack $ do srcFiles <- getDirectoryContentsRecursive srcDir - copyFilesWith copyFile destDir [ (srcDir, f) | f <- srcFiles ] + copyFilesWith copyFile destDir [(srcDir, f) | f <- srcFiles] getDirectoryContentsRecursive :: FilePath -> IO [FilePath] getDirectoryContentsRecursive topdir = recurseDirectories [""] @@ -510,7 +554,9 @@ copyFilesWith :: (FilePath -> FilePath -> IO ()) -> FilePath -> [(FilePath, File copyFilesWith doCopy targetDir srcFiles = withFrozenCallStack $ do let dirs = map (targetDir ) . nub . map (takeDirectory . snd) $ srcFiles traverse_ (createDirectoryIfMissing True) dirs - sequence_ [ let src = srcBase srcFile - dest = targetDir srcFile - in doCopy src dest - | (srcBase, srcFile) <- srcFiles ] + sequence_ + [ let src = srcBase srcFile + dest = targetDir srcFile + in doCopy src dest + | (srcBase, srcFile) <- srcFiles + ] diff --git a/ghc-lib-gen/src/GhclibgenFlavor.hs b/ghc-lib-gen/src/GhclibgenFlavor.hs index 871bfbb5..8717b3da 100644 --- a/ghc-lib-gen/src/GhclibgenFlavor.hs +++ b/ghc-lib-gen/src/GhclibgenFlavor.hs @@ -1,23 +1,56 @@ -- Copyright (c) 2019 - 2023 Digital Asset (Switzerland) GmbH and/or -- its affiliates. All rights reserved. SPDX-License-Identifier: -- (Apache-2.0 OR BSD-3-Clause) - {-# LANGUAGE LambdaCase #-} -module GhclibgenFlavor( - GhcFlavor(..), GhcSeries(..), ghcSeries -) where +module GhclibgenFlavor + ( GhcFlavor (..), + GhcSeries (..), + ghcSeries, + ) +where -data GhcFlavor = DaGhc881 - | Ghc881 | Ghc882 | Ghc883 | Ghc884 - | Ghc8101 | Ghc8102 | Ghc8103 | Ghc8104 | Ghc8105 | Ghc8106 | Ghc8107 - | Ghc901 | Ghc902 - | Ghc921 | Ghc922 | Ghc923 | Ghc924 | Ghc925 | Ghc926 | Ghc927 | Ghc928 - | Ghc941 | Ghc942 | Ghc943 | Ghc944 | Ghc945 | Ghc946 | Ghc947 | Ghc948 - | Ghc961 | Ghc962 | Ghc963 | Ghc964 | Ghc965 | Ghc966 - | Ghc981 | Ghc982 - | Ghc9101 - | GhcMaster +data GhcFlavor + = DaGhc881 + | Ghc881 + | Ghc882 + | Ghc883 + | Ghc884 + | Ghc8101 + | Ghc8102 + | Ghc8103 + | Ghc8104 + | Ghc8105 + | Ghc8106 + | Ghc8107 + | Ghc901 + | Ghc902 + | Ghc921 + | Ghc922 + | Ghc923 + | Ghc924 + | Ghc925 + | Ghc926 + | Ghc927 + | Ghc928 + | Ghc941 + | Ghc942 + | Ghc943 + | Ghc944 + | Ghc945 + | Ghc946 + | Ghc947 + | Ghc948 + | Ghc961 + | Ghc962 + | Ghc963 + | Ghc964 + | Ghc965 + | Ghc966 + | Ghc981 + | Ghc982 + | Ghc9101 + | GhcMaster deriving (Show, Eq, Ord) data GhcSeries = GHC_8_8 | GHC_8_10 | GHC_9_0 | GHC_9_2 | GHC_9_4 | GHC_9_6 | GHC_9_8 | GHC_9_10 | GHC_9_12 @@ -25,25 +58,25 @@ data GhcSeries = GHC_8_8 | GHC_8_10 | GHC_9_0 | GHC_9_2 | GHC_9_4 | GHC_9_6 | GH instance Show GhcSeries where show = \case - GHC_9_12 -> "ghc-9.12" - GHC_9_10 -> "ghc-9.10" - GHC_9_8 -> "ghc-9.8" - GHC_9_6 -> "ghc-9.6" - GHC_9_4 -> "ghc-9.4" - GHC_9_2 -> "ghc-9.2" - GHC_9_0 -> "ghc-9.0" + GHC_9_12 -> "ghc-9.12" + GHC_9_10 -> "ghc-9.10" + GHC_9_8 -> "ghc-9.8" + GHC_9_6 -> "ghc-9.6" + GHC_9_4 -> "ghc-9.4" + GHC_9_2 -> "ghc-9.2" + GHC_9_0 -> "ghc-9.0" GHC_8_10 -> "ghc-8.10" - GHC_8_8 -> "ghc-8.8" + GHC_8_8 -> "ghc-8.8" ghcSeries :: GhcFlavor -> GhcSeries ghcSeries = \case - f | DaGhc881 <= f && f < Ghc8101 -> GHC_8_8 - f | Ghc8101 <= f && f < Ghc901 -> GHC_8_10 - f | Ghc901 <= f && f < Ghc921 -> GHC_9_0 - f | Ghc921 <= f && f < Ghc941 -> GHC_9_2 - f | Ghc941 <= f && f < Ghc961 -> GHC_9_4 - f | Ghc961 <= f && f < Ghc981 -> GHC_9_6 - f | Ghc981 <= f && f < Ghc9101 -> GHC_9_8 - f | Ghc9101 <= f && f < GhcMaster -> GHC_9_10 - GhcMaster -> GHC_9_12 - _ -> error "ghcSeries: impossible case" + f | DaGhc881 <= f && f < Ghc8101 -> GHC_8_8 + f | Ghc8101 <= f && f < Ghc901 -> GHC_8_10 + f | Ghc901 <= f && f < Ghc921 -> GHC_9_0 + f | Ghc921 <= f && f < Ghc941 -> GHC_9_2 + f | Ghc941 <= f && f < Ghc961 -> GHC_9_4 + f | Ghc961 <= f && f < Ghc981 -> GHC_9_6 + f | Ghc981 <= f && f < Ghc9101 -> GHC_9_8 + f | Ghc9101 <= f && f < GhcMaster -> GHC_9_10 + GhcMaster -> GHC_9_12 + _ -> error "ghcSeries: impossible case" diff --git a/ghc-lib-gen/src/GhclibgenOpts.hs b/ghc-lib-gen/src/GhclibgenOpts.hs index 7bf25671..a9ec77cc 100644 --- a/ghc-lib-gen/src/GhclibgenOpts.hs +++ b/ghc-lib-gen/src/GhclibgenOpts.hs @@ -1,58 +1,64 @@ -- Copyright (c) 2019 - 2023 Digital Asset (Switzerland) GmbH and/or -- its affiliates. All rights reserved. SPDX-License-Identifier: -- (Apache-2.0 OR BSD-3-Clause) - {-# LANGUAGE LambdaCase #-} -module GhclibgenOpts( - GhclibgenTarget(..) - , GhclibgenOpts(..) - , module GhclibgenFlavor - , ghclibgenVersion - , ghclibgenOpts -) where + +module GhclibgenOpts + ( GhclibgenTarget (..), + GhclibgenOpts (..), + module GhclibgenFlavor, + ghclibgenVersion, + ghclibgenOpts, + ) +where import Control.Applicative -import Options.Applicative import Data.Maybe import Data.Version (showVersion) -import Paths_ghc_lib_gen (version) - import GhclibgenFlavor +import Options.Applicative +import Paths_ghc_lib_gen (version) -- | A ghc-lib-gen target. data GhclibgenTarget = GhclibParser | Ghclib -- | The type of ghc-lib-gen options. -data GhclibgenOpts = GhclibgenOpts { - ghclibgenOpts_root :: !FilePath -- ^ Path to a GHC git repository. - , ghclibgenOpts_patches :: !FilePath -- ^ Path to a directory of patches. - , ghclibgenOpts_target :: !GhclibgenTarget - , ghclibgenOpts_ghcFlavor :: !GhcFlavor - , ghclibgenOpts_skipInit :: !Bool - , ghclibgenOpts_customCppFlags :: ![String] - , ghclibgenOpts_stackResolver :: !(Maybe String) - } +data GhclibgenOpts = GhclibgenOpts + { -- | Path to a GHC git repository. + ghclibgenOpts_root :: !FilePath, + -- | Path to a directory of patches. + ghclibgenOpts_patches :: !FilePath, + ghclibgenOpts_target :: !GhclibgenTarget, + ghclibgenOpts_ghcFlavor :: !GhcFlavor, + ghclibgenOpts_skipInit :: !Bool, + ghclibgenOpts_customCppFlags :: ![String], + ghclibgenOpts_stackResolver :: !(Maybe String) + } -- | A parser of the "--ghc-lib" target. ghclib :: Parser GhclibgenTarget -ghclib = flag' Ghclib - ( long "ghc-lib" - <> help "Generate a ghc-lib.cabal" - ) +ghclib = + flag' + Ghclib + ( long "ghc-lib" + <> help "Generate a ghc-lib.cabal" + ) -- | A parser of the "--ghc-lib-parser" target. ghclibParser :: Parser GhclibgenTarget -ghclibParser = flag' GhclibParser - ( long "ghc-lib-parser" - <> help "Generate a ghc-lib-parser.cabal" - ) +ghclibParser = + flag' + GhclibParser + ( long "ghc-lib-parser" + <> help "Generate a ghc-lib-parser.cabal" + ) -- | A parser of "--version". ghclibgenVersion :: Parser (a -> a) ghclibgenVersion = infoOption - (showVersion version) - (long "version" <> help "Show version") + (showVersion version) + (long "version" <> help "Show version") -- | A parser of a ghc-lib-gen target: `target := | "--ghc-lib-parser" -- | "--ghc-lib" | /* nothing */`. @@ -62,92 +68,86 @@ ghclibgenTarget = -- | A parser of ghc-lib-gen options: `opts := STRING target`. ghclibgenOpts :: Parser GhclibgenOpts -ghclibgenOpts = GhclibgenOpts - <$> argument str (metavar "GHC_ROOT") - <*> argument str (metavar "PATCHES_DIR") - <*> ghclibgenTarget - <*> ghcFlavorOpt - <*> switch - ( long "skip-init" - <> help "If enabled, skip initialization steps" - ) - <*> cppCustomFlagsOpt - <*> stackResolverOpt +ghclibgenOpts = + GhclibgenOpts + <$> argument str (metavar "GHC_ROOT") + <*> argument str (metavar "PATCHES_DIR") + <*> ghclibgenTarget + <*> ghcFlavorOpt + <*> switch + ( long "skip-init" + <> help "If enabled, skip initialization steps" + ) + <*> cppCustomFlagsOpt + <*> stackResolverOpt ghcFlavorOpt :: Parser GhcFlavor -ghcFlavorOpt = option readFlavor +ghcFlavorOpt = + option + readFlavor ( long "ghc-flavor" - <> help "The ghc-flavor to test against" + <> help "The ghc-flavor to test against" ) readFlavor :: ReadM GhcFlavor readFlavor = eitherReader $ \case - -- HEAD - "ghc-master" -> Right GhcMaster - - -- ghc-9.10 - "ghc-9.10.1" -> Right Ghc9101 - - -- ghc-9.8 - "ghc-9.8.2" -> Right Ghc982 - "ghc-9.8.1" -> Right Ghc981 - - -- ghc-9.6 - "ghc-9.6.6" -> Right Ghc966 - "ghc-9.6.5" -> Right Ghc965 - "ghc-9.6.4" -> Right Ghc964 - "ghc-9.6.3" -> Right Ghc963 - "ghc-9.6.2" -> Right Ghc962 - "ghc-9.6.1" -> Right Ghc961 - - -- ghc-9.4 - "ghc-9.4.8" -> Right Ghc948 - "ghc-9.4.7" -> Right Ghc947 - "ghc-9.4.6" -> Right Ghc946 - "ghc-9.4.5" -> Right Ghc945 - "ghc-9.4.4" -> Right Ghc944 - "ghc-9.4.3" -> Right Ghc943 - "ghc-9.4.2" -> Right Ghc942 - "ghc-9.4.1" -> Right Ghc941 - - -- ghc-9.2 - "ghc-9.2.8" -> Right Ghc928 - "ghc-9.2.7" -> Right Ghc927 - "ghc-9.2.6" -> Right Ghc926 - "ghc-9.2.5" -> Right Ghc925 - "ghc-9.2.4" -> Right Ghc924 - "ghc-9.2.3" -> Right Ghc923 - "ghc-9.2.2" -> Right Ghc922 - "ghc-9.2.1" -> Right Ghc921 - - -- ghc-9.0 - "ghc-9.0.2" -> Right Ghc902 - "ghc-9.0.1" -> Right Ghc901 - - -- ghc-8.10 - "ghc-8.10.7" -> Right Ghc8107 - "ghc-8.10.6" -> Right Ghc8106 - "ghc-8.10.5" -> Right Ghc8105 - "ghc-8.10.4" -> Right Ghc8104 - "ghc-8.10.3" -> Right Ghc8103 - "ghc-8.10.2" -> Right Ghc8102 - "ghc-8.10.1" -> Right Ghc8101 - - -- ghc-8.8 - "ghc-8.8.4" -> Right Ghc884 - "ghc-8.8.3" -> Right Ghc883 - "ghc-8.8.2" -> Right Ghc882 - "ghc-8.8.1" -> Right Ghc881 - "da-ghc-8.8.1" -> Right DaGhc881 - - flavor -> Left $ "Unknown or unsupported flavor \"" ++ flavor ++ "\"" + -- HEAD + "ghc-master" -> Right GhcMaster + -- ghc-9.10 + "ghc-9.10.1" -> Right Ghc9101 + -- ghc-9.8 + "ghc-9.8.2" -> Right Ghc982 + "ghc-9.8.1" -> Right Ghc981 + -- ghc-9.6 + "ghc-9.6.6" -> Right Ghc966 + "ghc-9.6.5" -> Right Ghc965 + "ghc-9.6.4" -> Right Ghc964 + "ghc-9.6.3" -> Right Ghc963 + "ghc-9.6.2" -> Right Ghc962 + "ghc-9.6.1" -> Right Ghc961 + -- ghc-9.4 + "ghc-9.4.8" -> Right Ghc948 + "ghc-9.4.7" -> Right Ghc947 + "ghc-9.4.6" -> Right Ghc946 + "ghc-9.4.5" -> Right Ghc945 + "ghc-9.4.4" -> Right Ghc944 + "ghc-9.4.3" -> Right Ghc943 + "ghc-9.4.2" -> Right Ghc942 + "ghc-9.4.1" -> Right Ghc941 + -- ghc-9.2 + "ghc-9.2.8" -> Right Ghc928 + "ghc-9.2.7" -> Right Ghc927 + "ghc-9.2.6" -> Right Ghc926 + "ghc-9.2.5" -> Right Ghc925 + "ghc-9.2.4" -> Right Ghc924 + "ghc-9.2.3" -> Right Ghc923 + "ghc-9.2.2" -> Right Ghc922 + "ghc-9.2.1" -> Right Ghc921 + -- ghc-9.0 + "ghc-9.0.2" -> Right Ghc902 + "ghc-9.0.1" -> Right Ghc901 + -- ghc-8.10 + "ghc-8.10.7" -> Right Ghc8107 + "ghc-8.10.6" -> Right Ghc8106 + "ghc-8.10.5" -> Right Ghc8105 + "ghc-8.10.4" -> Right Ghc8104 + "ghc-8.10.3" -> Right Ghc8103 + "ghc-8.10.2" -> Right Ghc8102 + "ghc-8.10.1" -> Right Ghc8101 + -- ghc-8.8 + "ghc-8.8.4" -> Right Ghc884 + "ghc-8.8.3" -> Right Ghc883 + "ghc-8.8.2" -> Right Ghc882 + "ghc-8.8.1" -> Right Ghc881 + "da-ghc-8.8.1" -> Right DaGhc881 + flavor -> Left $ "Unknown or unsupported flavor \"" ++ flavor ++ "\"" cppCustomFlagsOpt :: Parser [String] cppCustomFlagsOpt = many $ strOption ( long "cpp" - <> help "CPP options to include in the generated cabal file" + <> help "CPP options to include in the generated cabal file" ) stackResolverOpt :: Parser (Maybe String) @@ -155,5 +155,5 @@ stackResolverOpt = optional $ strOption ( long "resolver" - <> help "the prevailing stack resolver" + <> help "the prevailing stack resolver" ) diff --git a/ghc-lib-gen/src/Main.hs b/ghc-lib-gen/src/Main.hs index d920aabe..6c0ec0e6 100755 --- a/ghc-lib-gen/src/Main.hs +++ b/ghc-lib-gen/src/Main.hs @@ -2,25 +2,24 @@ -- affiliates. All rights reserved. SPDX-License-Identifier: -- (Apache-2.0 OR BSD-3-Clause) -module Main(main) where +module Main (main) where +import Control.Monad import Ghclibgen import GhclibgenOpts - -import System.Directory import Options.Applicative -import Control.Monad +import System.Directory main :: IO () main = ghclibgen =<< execParser opts where opts = info - (helper <*> ghclibgenVersion <*> ghclibgenOpts) - (fullDesc - <> header "ghc-lib-gen - ghc-lib cabal file generator" - <> progDesc "Generate a ghc-lib target Cabal file" - ) + (helper <*> ghclibgenVersion <*> ghclibgenOpts) + ( fullDesc + <> header "ghc-lib-gen - ghc-lib cabal file generator" + <> progDesc "Generate a ghc-lib target Cabal file" + ) ghclibgen :: GhclibgenOpts -> IO () ghclibgen (GhclibgenOpts root _patches target ghcFlavor skipInit cppOpts _resolver) = do @@ -46,21 +45,21 @@ ghclibgen (GhclibgenOpts root _patches target ghcFlavor skipInit cppOpts _resolv init :: GhcFlavor -> IO () init ghcFlavor = do - applyPatchTemplateHaskellCabal ghcFlavor - applyPatchHadrianCabalProject ghcFlavor - applyPatchHeapClosures ghcFlavor - applyPatchRtsIncludePaths ghcFlavor - applyPatchGhcPrim ghcFlavor - applyPatchDisableCompileTimeOptimizations ghcFlavor - -- These lines must come before 'generatePrerequisites': - applyPatchAclocal ghcFlavor -- Do before ./boot && ./configure - applyPatchFptoolsAlex ghcFlavor - applyPatchFpFindCxxStdLib ghcFlavor - generatePrerequisites ghcFlavor - -- Renamings come after 'generatePrerequisites': - applyPatchDerivedConstants ghcFlavor -- Needs DerivedConstants.h - applyPatchHsVersions ghcFlavor - applyPatchGHCiMessage ghcFlavor -- Needs ghcversion.h - -- Before placeholder module generation - applyPatchGhcInternalEventWindowsHsc ghcFlavor - setupModuleDepsPlaceholders ghcFlavor + applyPatchTemplateHaskellCabal ghcFlavor + applyPatchHadrianCabalProject ghcFlavor + applyPatchHeapClosures ghcFlavor + applyPatchRtsIncludePaths ghcFlavor + applyPatchGhcPrim ghcFlavor + applyPatchDisableCompileTimeOptimizations ghcFlavor + -- These lines must come before 'generatePrerequisites': + applyPatchAclocal ghcFlavor -- Do before ./boot && ./configure + applyPatchFptoolsAlex ghcFlavor + applyPatchFpFindCxxStdLib ghcFlavor + generatePrerequisites ghcFlavor + -- Renamings come after 'generatePrerequisites': + applyPatchDerivedConstants ghcFlavor -- Needs DerivedConstants.h + applyPatchHsVersions ghcFlavor + applyPatchGHCiMessage ghcFlavor -- Needs ghcversion.h + -- Before placeholder module generation + applyPatchGhcInternalEventWindowsHsc ghcFlavor + setupModuleDepsPlaceholders ghcFlavor