From 405b81472658964e988a98bd088b7a523bf178b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Sat, 7 Feb 2015 23:43:56 +0100 Subject: [PATCH] Add cabal-helper for decoding Cabal-1.22 setup-configs .. without having to worry about Cabal version conflicts --- ghc-mod.cabal | 15 +++++++++++++++ src/GHCModCabal.hs | 28 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/GHCModCabal.hs diff --git a/ghc-mod.cabal b/ghc-mod.cabal index 65ce6ff..1fe41be 100644 --- a/ghc-mod.cabal +++ b/ghc-mod.cabal @@ -186,6 +186,21 @@ Executable ghc-modi , ghc , ghc-mod +Executable cabal-helper + Default-Language: Haskell2010 + Main-Is: GHCModCabal.hs + GHC-Options: -Wall + HS-Source-Dirs: src + X-Install-Target: $libexecdir + Build-Depends: base >= 4.0 && < 5 + , bytestring + , binary + , directory + if flag(cabal-122) + Build-Depends: Cabal >= 1.22 + else + Buildable: False + Test-Suite doctest Type: exitcode-stdio-1.0 Default-Language: Haskell2010 diff --git a/src/GHCModCabal.hs b/src/GHCModCabal.hs new file mode 100644 index 0000000..5aec6d9 --- /dev/null +++ b/src/GHCModCabal.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE BangPatterns #-} +module Main where + +import Control.Applicative + +import Distribution.Simple.Utils (cabalVersion) +import Distribution.Simple.Configure +import Distribution.Text ( display ) +import System.Environment +import System.Directory + +main :: IO () +main = do + args <- getArgs + case args of + "version":[] -> do + putStrLn $ "using version " ++ display cabalVersion ++ " of the Cabal library" + "print-setup-config":args' -> do + mfile <- findFile ["dist"] "setup-config" + + let file = case mfile of + Just f -> f + Nothing -> let !(f:[]) = args' in f + + putStrLn =<< show <$> getConfigStateFile file + + cmd:_ -> error $ "Unknown command: " ++ cmd + [] -> error "No command given"