Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • changelog.d/pp-set-ghc-version
    1
    +section: compiler
    
    2
    +synopsis:
    
    3
    +  Set the environment variable `GHC_VERSION` to the current GHC version when
    
    4
    +  invoking custom pre-processors, so that pre-processors can emit
    
    5
    +  backward-compatible code.
    
    6
    +issues: #25952
    
    7
    +mrs: !16224

  • compiler/GHC/SysTools/Tasks.hs
    ... ... @@ -45,6 +45,7 @@ import GHC.ForeignSrcLang
    45 45
     
    
    46 46
     import GHC.CmmToLlvm.Version (LlvmVersion, llvmVersionStr, supportedLlvmVersionUpperBound, parseLlvmVersion, supportedLlvmVersionLowerBound)
    
    47 47
     
    
    48
    +import GHC.Version
    
    48 49
     import GHC.Settings
    
    49 50
     
    
    50 51
     import GHC.SysTools.Process
    
    ... ... @@ -63,6 +64,7 @@ import Data.List (tails, isPrefixOf)
    63 64
     import Data.Maybe (fromMaybe)
    
    64 65
     import System.IO
    
    65 66
     import System.Process
    
    67
    +import System.Environment
    
    66 68
     import GHC.Driver.Config.Diagnostic
    
    67 69
     import GHC.Driver.Errors
    
    68 70
     import GHC.Driver.Errors.Types (GhcMessage(..), DriverMessage (DriverNoConfiguredLLVMToolchain))
    
    ... ... @@ -217,7 +219,8 @@ runPp :: Logger -> DynFlags -> [Option] -> IO ()
    217 219
     runPp logger dflags args = traceSystoolCommand logger "pp" $ do
    
    218 220
       let prog = pgm_F dflags
    
    219 221
           opts = map Option (getOpts dflags opt_F)
    
    220
    -  runSomething logger "Haskell pre-processor" prog (args ++ opts)
    
    222
    +  env <- (("GHC_VERSION", cProjectVersion) :) <$> getEnvironment
    
    223
    +  runSomethingFiltered logger id "Haskell pre-processor" prog (args ++ opts) Nothing (Just env)
    
    221 224
     
    
    222 225
     data CcConfig = CcConfig
    
    223 226
       { ccProg :: String
    

  • docs/users_guide/phases.rst
    ... ... @@ -603,7 +603,7 @@ Options affecting a Haskell pre-processor
    603 603
         appropriate and useful. The ``-F`` option lets you run a
    
    604 604
         pre-processor as part of the overall GHC compilation pipeline, which
    
    605 605
         has the advantage over running a Haskell pre-processor separately in
    
    606
    -    that it works in interpreted mode and you can continue to take reap
    
    606
    +    that it works in interpreted mode and you can continue to reap
    
    607 607
         the benefits of GHC's recompilation checker.
    
    608 608
     
    
    609 609
         The pre-processor is run just before the Haskell compiler proper
    
    ... ... @@ -622,6 +622,10 @@ Options affecting a Haskell pre-processor
    622 622
         :ghc-flag:`-optF ⟨option⟩` option. These are fed to ⟨cmd⟩ on the command
    
    623 623
         line after the three standard input and output arguments.
    
    624 624
     
    
    625
    +    GHC sets the environment variable `GHC_VERSION` to the current GHC version
    
    626
    +    when invoking a pre-processor.  The pre-processor can use this to emit
    
    627
    +    backward-compatible code.
    
    628
    +
    
    625 629
         An example of a pre-processor is to convert your source files to the
    
    626 630
         input encoding that GHC expects, i.e. create a script ``convert.sh``
    
    627 631
         containing the lines: