Skip to content

Commit

Permalink
Less repetition in the Cabal file
Browse files Browse the repository at this point in the history
  • Loading branch information
mmhat committed Aug 10, 2024
1 parent 9d374b7 commit 1e47820
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 39 deletions.
63 changes: 24 additions & 39 deletions print-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ common ghc-options
common rts-options
ghc-options: -rtsopts -threaded "-with-rtsopts=-N -T"

common print-api-common
import: extensions
import: ghc-options
import: rts-options
hs-source-dirs: app/print-api

-- For some mysterious reason Cabal doesn't like it when there is no `main-is` in the executable section;
-- Importing it doesn't work.
-- main-is: Main.hs
build-depends:
, base
, ghc
, ghc-paths
, optparse-applicative
, print-api

default-language: Haskell2010

library
import: extensions
import: ghc-options
Expand Down Expand Up @@ -91,19 +109,8 @@ executable print-api
default-language: GHC2021

executable print-api-9.6.6
import: extensions
import: ghc-options
import: rts-options
hs-source-dirs: app/print-api
main-is: Main.hs
build-depends:
, base
, ghc
, ghc-paths
, optparse-applicative
, print-api

default-language: Haskell2010
import: print-api-common
main-is: Main.hs

if impl(ghc ==9.6.6)
buildable: True
Expand All @@ -112,19 +119,8 @@ executable print-api-9.6.6
buildable: False

executable print-api-9.8.2
import: extensions
import: ghc-options
import: rts-options
hs-source-dirs: app/print-api
main-is: Main.hs
build-depends:
, base
, ghc
, ghc-paths
, optparse-applicative
, print-api

default-language: Haskell2010
import: print-api-common
main-is: Main.hs

if impl(ghc ==9.8.2)
buildable: True
Expand All @@ -133,19 +129,8 @@ executable print-api-9.8.2
buildable: False

executable print-api-9.10.1
import: extensions
import: ghc-options
import: rts-options
hs-source-dirs: app/print-api
main-is: Main.hs
build-depends:
, base
, ghc
, ghc-paths
, optparse-applicative
, print-api

default-language: Haskell2010
import: print-api-common
main-is: Main.hs

if impl(ghc ==9.10.1)
buildable: True
Expand Down
3 changes: 3 additions & 0 deletions src/PrintApi/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ cabalizedProc
-> [String]
-> IO (ProcessConfig () () ())
cabalizedProc ghcVersion exe args =
-- If there is a GHC_ENVIRONMENT environment variable set, assume that we got
-- called using `cabal exec`.
-- Hopefully some day someone comes up with a saner way to test this.
lookupEnv "GHC_ENVIRONMENT" <&> \case
Just{} -> Process.proc exe args
Nothing ->
Expand Down

0 comments on commit 1e47820

Please sign in to comment.