aboutsummaryrefslogtreecommitdiff
path: root/CabalHelper
diff options
context:
space:
mode:
Diffstat (limited to 'CabalHelper')
-rw-r--r--CabalHelper/Main.hs10
-rw-r--r--CabalHelper/Types.hs2
-rw-r--r--CabalHelper/Wrapper.hs27
3 files changed, 20 insertions, 19 deletions
diff --git a/CabalHelper/Main.hs b/CabalHelper/Main.hs
index 62fe729..043e57c 100644
--- a/CabalHelper/Main.hs
+++ b/CabalHelper/Main.hs
@@ -52,8 +52,9 @@ import Distribution.Simple.Program.GHC (GhcOptions(..), renderGhcOptions)
import Distribution.Simple.Setup (ConfigFlags(..),Flag(..))
import Distribution.Simple.Build (initialBuildSteps)
import Distribution.Simple.BuildPaths (autogenModuleName, cppHeaderName, exeExtension)
-import Distribution.Simple.Compiler (PackageDB(..))
+import Distribution.Simple.Compiler (PackageDB(..), compilerId)
+import Distribution.Compiler (CompilerId(..))
import Distribution.ModuleName (components)
import qualified Distribution.ModuleName as C (ModuleName)
import Distribution.Text (display)
@@ -89,6 +90,7 @@ usage = do
++"DIST_DIR ( version\n"
++" | print-lbi\n"
++" | write-autogen-files\n"
+ ++" | compiler-version"
++" | ghc-options [--with-inplace]\n"
++" | ghc-src-options [--with-inplace]\n"
++" | ghc-pkg-options [--with-inplace]\n"
@@ -100,7 +102,7 @@ usage = do
commands :: [String]
commands = [ "print-bli"
, "write-autogen-files"
- , "component-from-file"
+ , "compiler-version"
, "ghc-options"
, "ghc-src-options"
, "ghc-pkg-options"
@@ -157,6 +159,10 @@ main = do
initialBuildSteps distdir pd lbi v
return Nothing
+ "compiler-version":[] -> do
+ let CompilerId comp ver = compilerId $ compiler lbi
+ return $ Just $ ChResponseVersion (show comp) ver
+
"ghc-options":flags -> do
res <- componentsMap lbi v distdir $ \c clbi bi -> let
outdir = componentOutDir lbi c
diff --git a/CabalHelper/Types.hs b/CabalHelper/Types.hs
index add6dc1..0c1ebbe 100644
--- a/CabalHelper/Types.hs
+++ b/CabalHelper/Types.hs
@@ -18,6 +18,7 @@
module CabalHelper.Types where
import GHC.Generics
+import Data.Version
newtype ChModuleName = ChModuleName String
deriving (Eq, Ord, Read, Show, Generic)
@@ -33,6 +34,7 @@ data ChResponse
= ChResponseStrings [(ChComponentName, [String])]
| ChResponseEntrypoints [(ChComponentName, ChEntrypoint)]
| ChResponseLbi String
+ | ChResponseVersion String Version
deriving (Eq, Ord, Read, Show, Generic)
data ChEntrypoint = ChSetupEntrypoint -- ^ Almost like 'ChExeEntrypoint' but
diff --git a/CabalHelper/Wrapper.hs b/CabalHelper/Wrapper.hs
index 04a9971..f14ae6a 100644
--- a/CabalHelper/Wrapper.hs
+++ b/CabalHelper/Wrapper.hs
@@ -119,23 +119,16 @@ main = handlePanic $ do
\Could not read Cabal's persistent setup configuration header\n\
\- Check first line of: %s\n\
\- Maybe try: $ cabal configure" cfgf
- Just (hdrCabalVersion, (_compilerName, hdrCompilerVersion)) -> do
- ghcVer <- ghcVersion opts
- if not $ ghcVer `sameMajorVersionAs` hdrCompilerVersion
- then panic $ printf "\
-\GHC major version changed! (was %s, now %s)\n\
-\- Reconfigure the project: $ cabal clean && cabal configure\
-\ " (showVersion hdrCompilerVersion) (showVersion ghcVer)
- else do
- eexe <- compileHelper opts hdrCabalVersion distdir
- case eexe of
- Left e -> exitWith e
- Right exe ->
- case args' of
- "print-exe":_ -> putStrLn exe
- _ -> do
- (_,_,_,h) <- createProcess $ proc exe args
- exitWith =<< waitForProcess h
+ Just (hdrCabalVersion, _) -> do
+ eexe <- compileHelper opts hdrCabalVersion distdir
+ case eexe of
+ Left e -> exitWith e
+ Right exe ->
+ case args' of
+ "print-exe":_ -> putStrLn exe
+ _ -> do
+ (_,_,_,h) <- createProcess $ proc exe args
+ exitWith =<< waitForProcess h
appDataDir :: IO FilePath
appDataDir = (</> "cabal-helper") <$> getAppUserDataDirectory "ghc-mod"