[commit: ghc] wip/angerman/llvmng: Adds -ghc-version flag to ghc. (b3321a3)

git at git.haskell.org git at git.haskell.org
Sat Nov 11 08:34:57 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/angerman/llvmng
Link       : http://ghc.haskell.org/trac/ghc/changeset/b3321a31d7c986f21bbe9fbc86ee26a290919f63/ghc

>---------------------------------------------------------------

commit b3321a31d7c986f21bbe9fbc86ee26a290919f63
Author: Moritz Angermann <moritz.angermann at gmail.com>
Date:   Sun Oct 29 14:24:50 2017 +0800

    Adds -ghc-version flag to ghc.
    
    Summary:
    When building the rts with ghc (e.g. using ghc as a c compiler), ghc's
    Added Value includes adding `-include /path/to/ghcversion.h`.  For
    this it looksup the rts package in the package database, which--if
    empty--fails.  Thus to allow compiling C files with GHC, we add the
    `-ghc-version` flag, which takes the path to the `ghcversion.h` file.
    
    A `-no-ghc-version` flag was omitted, as at that point it becomes
    questionable why one would use ghc to compile c if one doesn't
    any of the added value.
    
    Reviewers: bgamari, geekosaur, austin
    
    Subscribers: rwbarton, thomie
    
    Differential Revision: https://phabricator.haskell.org/D4135


>---------------------------------------------------------------

b3321a31d7c986f21bbe9fbc86ee26a290919f63
 compiler/main/DriverPipeline.hs | 11 ++++++++---
 compiler/main/DynFlags.hs       |  6 ++++++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index fab7fad..4f7bfbd 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -2204,11 +2204,16 @@ touchObjectFile dflags path = do
 -- | Find out path to @ghcversion.h@ file
 getGhcVersionPathName :: DynFlags -> IO FilePath
 getGhcVersionPathName dflags = do
-  dirs <- getPackageIncludePath dflags [toInstalledUnitId rtsUnitId]
+  candidates <- case ghcVersion dflags of
+    Just path -> return [path]
+    Nothing -> (map (</> "ghcversion.h")) <$>
+               (getPackageIncludePath dflags [toInstalledUnitId rtsUnitId])
 
-  found <- filterM doesFileExist (map (</> "ghcversion.h") dirs)
+  found <- filterM doesFileExist candidates
   case found of
-      []    -> throwGhcExceptionIO (InstallationError ("ghcversion.h missing"))
+      []    -> throwGhcExceptionIO (InstallationError
+                                    ("ghcversion.h missing; tried: "
+                                      ++ intercalate ", " candidates))
       (x:_) -> return x
 
 -- Note [-fPIC for assembler]
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index 0e6310e..bd7b768 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -531,6 +531,7 @@ data GeneralFlag
    | Opt_ExternalInterpreter
    | Opt_OptimalApplicativeDo
    | Opt_VersionMacros
+   | Opt_GhcVersion
    | Opt_WholeArchiveHsLibs
 
    -- PreInlining is on by default. The option is there just to see how
@@ -914,6 +915,7 @@ data DynFlags = DynFlags {
   flushOut              :: FlushOut,
   flushErr              :: FlushErr,
 
+  ghcVersion            :: Maybe FilePath,
   haddockOptions        :: Maybe String,
 
   -- | GHCi scripts specified by -ghci-script, in reverse order
@@ -1678,6 +1680,7 @@ defaultDynFlags mySettings myLlvmTargets =
         filesToClean   = panic "defaultDynFlags: No filesToClean",
         dirsToClean    = panic "defaultDynFlags: No dirsToClean",
         generatedDumps = panic "defaultDynFlags: No generatedDumps",
+        ghcVersion     = Nothing,
         haddockOptions = Nothing,
         dumpFlags = EnumSet.empty,
         generalFlags = EnumSet.fromList (defaultFlags mySettings),
@@ -2334,6 +2337,8 @@ addDepSuffix s d = d { depSuffixes = s : depSuffixes d }
 
 addCmdlineFramework f d = d { cmdlineFrameworks = f : cmdlineFrameworks d}
 
+addGhcVersion f d = d { ghcVersion = Just f }
+
 addHaddockOpts f d = d { haddockOptions = Just f}
 
 addGhciScript f d = d { ghciScripts = f : ghciScripts d}
@@ -2861,6 +2866,7 @@ dynamic_flags_deps = [
   , make_ord_flag defGhcFlag "no-rtsopts-suggestions"
       (noArg (\d -> d {rtsOptsSuggestions = False}))
 
+  , make_ord_flag defGhcFlag "ghc-version"          (hasArg addGhcVersion)
   , make_ord_flag defGhcFlag "main-is"              (SepArg setMainIs)
   , make_ord_flag defGhcFlag "haddock"              (NoArg (setGeneralFlag Opt_Haddock))
   , make_ord_flag defGhcFlag "haddock-opts"         (hasArg addHaddockOpts)



More information about the ghc-commits mailing list