Skip to content

Commit

Permalink
Use ghc instead of ghc-lib-parser when possible
Browse files Browse the repository at this point in the history
This significantly reduces the build time with recent version of GHC.
  • Loading branch information
sol committed Dec 26, 2022
1 parent 0bcf31c commit 1879045
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
9 changes: 8 additions & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ optsParserInfo =
$gitBranch,
$gitHash
],
"using ghc-lib-parser " ++ VERSION_ghc_lib_parser
ghcApiVersion
]
exts :: Parser (a -> a)
exts =
Expand All @@ -240,6 +240,13 @@ optsParserInfo =
]
displayExts = unlines $ sort (showOutputable <$> manualExts)

ghcApiVersion :: String
#ifdef VERSION_ghc_lib_parser
ghcApiVersion = "using ghc-lib-parser " ++ VERSION_ghc_lib_parser
#else
ghcApiVersion = "using ghc " ++ VERSION_ghc
#endif

optsParser :: Parser Opts
optsParser =
Opts
Expand Down
30 changes: 26 additions & 4 deletions ormolu.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,23 @@ library
dlist >=0.8 && <2.0,
exceptions >=0.6 && <0.11,
filepath >=1.2 && <1.5,
ghc-lib-parser >=9.4 && <9.5,
megaparsec >=9.0,
mtl >=2.0 && <3.0,
syb >=0.7 && <0.8,
template-haskell,
text >=0.2 && <3.0,
th-lift-instances >=0.1 && <0.2

mixins: ghc-lib-parser hiding (Language.Haskell.TH.Syntax)
if impl(ghc >=9.4 && <9.5)
build-depends:
ghc,
ghc-boot-th

mixins: ghc hiding (Language.Haskell.TH.Syntax)

else
build-depends: ghc-lib-parser >=9.4 && <9.5
mixins: ghc-lib-parser hiding (Language.Haskell.TH.Syntax)

if (flag(fixity-th) && impl(ghc <9.4))
cpp-options: -DFIXITY_TH
Expand All @@ -140,12 +148,19 @@ executable ormolu
base >=4.12 && <5.0,
containers >=0.5 && <0.7,
filepath >=1.2 && <1.5,
ghc-lib-parser >=9.4 && <9.5,
gitrev >=1.3 && <1.4,
optparse-applicative >=0.14 && <0.18,
ormolu,
text >=0.2 && <3.0

if impl(ghc >=9.4 && <9.5)
build-depends:
ghc,
ghc-boot-th

else
build-depends: ghc-lib-parser >=9.4 && <9.5

if flag(dev)
ghc-options:
-Wall -Werror -Wcompat -Wincomplete-record-updates
Expand Down Expand Up @@ -179,7 +194,6 @@ test-suite tests
containers >=0.5 && <0.7,
directory ^>=1.3,
filepath >=1.2 && <1.5,
ghc-lib-parser >=9.4 && <9.5,
hspec >=2.0 && <3.0,
hspec-megaparsec >=2.2,
megaparsec >=9.0,
Expand All @@ -189,6 +203,14 @@ test-suite tests
temporary ^>=1.3,
text >=0.2 && <3.0

if impl(ghc >=9.4 && <9.5)
build-depends:
ghc,
ghc-boot-th

else
build-depends: ghc-lib-parser >=9.4 && <9.5

if flag(dev)
ghc-options: -Wall -Werror

Expand Down
4 changes: 2 additions & 2 deletions tests/Ormolu/CabalInfoSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ spec = do
ciDynOpts `shouldBe` [DynOption "-XHaskell2010"]
it "extracts correct dependencies from ormolu.cabal (src/Ormolu/Config.hs)" $ do
CabalInfo {..} <- parseCabalInfo "ormolu.cabal" "src/Ormolu/Config.hs"
ciDependencies `shouldBe` Set.fromList ["Cabal-syntax", "Diff", "MemoTrie", "aeson", "ansi-terminal", "array", "base", "bytestring", "containers", "directory", "dlist", "exceptions", "file-embed", "filepath", "ghc-lib-parser", "megaparsec", "mtl", "syb", "template-haskell", "text", "th-lift-instances"]
ciDependencies `shouldBe` Set.fromList ["Cabal-syntax", "Diff", "MemoTrie", "aeson", "ansi-terminal", "array", "base", "bytestring", "containers", "directory", "dlist", "exceptions", "file-embed", "filepath", "ghc", "ghc-boot-th", "ghc-lib-parser", "megaparsec", "mtl", "syb", "template-haskell", "text", "th-lift-instances"]
it "extracts correct dependencies from ormolu.cabal (tests/Ormolu/PrinterSpec.hs)" $ do
CabalInfo {..} <- parseCabalInfo "ormolu.cabal" "tests/Ormolu/PrinterSpec.hs"
ciDependencies `shouldBe` Set.fromList ["QuickCheck", "base", "containers", "directory", "filepath", "ghc-lib-parser", "hspec", "hspec-megaparsec", "megaparsec", "ormolu", "path", "path-io", "temporary", "text"]
ciDependencies `shouldBe` Set.fromList ["QuickCheck", "base", "containers", "directory", "filepath", "ghc", "ghc-boot-th", "ghc-lib-parser", "hspec", "hspec-megaparsec", "megaparsec", "ormolu", "path", "path-io", "temporary", "text"]

it "handles `hs-source-dirs: .`" $ do
CabalInfo {..} <- parseTestCabalInfo "Foo.hs"
Expand Down

0 comments on commit 1879045

Please sign in to comment.