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

Commits:

4 changed files:

Changes:

  • compiler/GHC/Driver/Pipeline/Execute.hs
    ... ... @@ -478,7 +478,7 @@ runCcPhase cc_phase pipe_env hsc_env location input_fn = do
    478 478
               -- very weakly typed, being derived from C--.
    
    479 479
               ["-fno-strict-aliasing"]
    
    480 480
     
    
    481
    -  ghcVersionH <- getGhcVersionPathName dflags unit_env
    
    481
    +  ghcVersionH <- getGhcVersionIncludeFlags dflags unit_env
    
    482 482
     
    
    483 483
       withAtomicRename output_fn $ \temp_outputFilename ->
    
    484 484
         GHC.SysTools.runCc (phaseForeignLanguage cc_phase) logger tmpfs dflags (
    
    ... ... @@ -525,7 +525,7 @@ runCcPhase cc_phase pipe_env hsc_env location input_fn = do
    525 525
                            else [])
    
    526 526
                      ++ verbFlags
    
    527 527
                      ++ cc_opt
    
    528
    -                 ++ [ "-include", ghcVersionH ]
    
    528
    +                 ++ ghcVersionH
    
    529 529
                      ++ framework_paths
    
    530 530
                      ++ include_paths
    
    531 531
                      ++ pkg_extra_cc_opts
    

  • compiler/GHC/SysTools/Cpp.hs
    ... ... @@ -7,6 +7,7 @@ module GHC.SysTools.Cpp
    7 7
       ( doCpp
    
    8 8
       , CppOpts(..)
    
    9 9
       , getGhcVersionPathName
    
    10
    +  , getGhcVersionIncludeFlags
    
    10 11
       , applyCDefs
    
    11 12
       , offsetIncludePaths
    
    12 13
       )
    
    ... ... @@ -31,7 +32,6 @@ import GHC.Utils.TmpFs
    31 32
     import GHC.Utils.Panic
    
    32 33
     
    
    33 34
     import Data.Version
    
    34
    -import Data.List (intercalate)
    
    35 35
     import Data.Maybe
    
    36 36
     
    
    37 37
     import Control.Monad
    
    ... ... @@ -124,10 +124,10 @@ doCpp logger tmpfs dflags unit_env opts input_fn output_fn = do
    124 124
              [homeUnitEnv_dflags . ue_findHomeUnitEnv uid $ unit_env | uid <- ue_transitiveHomeDeps (ue_currentUnit unit_env) unit_env]
    
    125 125
             dep_pkg_extra_inputs = [offsetIncludePaths fs (includePaths fs) | fs <- home_pkg_deps]
    
    126 126
     
    
    127
    -    let include_paths_global = foldr (\ x xs -> ("-I" ++ x) : xs) []
    
    127
    +    let include_paths_global = map ("-I" ++)
    
    128 128
               (includePathsGlobal cmdline_include_paths ++ pkg_include_dirs
    
    129 129
                                                         ++ concatMap includePathsGlobal dep_pkg_extra_inputs)
    
    130
    -    let include_paths_quote = foldr (\ x xs -> ("-iquote" ++ x) : xs) []
    
    130
    +    let include_paths_quote = map ("-iquote" ++)
    
    131 131
               (includePathsQuote cmdline_include_paths ++
    
    132 132
                includePathsQuoteImplicit cmdline_include_paths)
    
    133 133
         let include_paths = include_paths_quote ++ include_paths_global
    
    ... ... @@ -178,8 +178,7 @@ doCpp logger tmpfs dflags unit_env opts input_fn output_fn = do
    178 178
         let asserts_def = [ "-D__GLASGOW_HASKELL_ASSERTS_IGNORED__" | gopt Opt_IgnoreAsserts dflags]
    
    179 179
     
    
    180 180
         -- Default CPP defines in Haskell source
    
    181
    -    ghcVersionH <- getGhcVersionPathName dflags unit_env
    
    182
    -    let hsSourceCppOpts = [ "-include", ghcVersionH ]
    
    181
    +    ghcVersionH <- getGhcVersionIncludeFlags dflags unit_env
    
    183 182
     
    
    184 183
         -- MIN_VERSION macros
    
    185 184
         let uids = explicitUnits unit_state
    
    ... ... @@ -202,7 +201,7 @@ doCpp logger tmpfs dflags unit_env opts input_fn output_fn = do
    202 201
     
    
    203 202
         cpp_prog       (   map GHC.SysTools.Option verbFlags
    
    204 203
                         ++ map GHC.SysTools.Option include_paths
    
    205
    -                    ++ map GHC.SysTools.Option hsSourceCppOpts
    
    204
    +                    ++ map GHC.SysTools.Option ghcVersionH
    
    206 205
                         ++ map GHC.SysTools.Option target_defs
    
    207 206
                         ++ map GHC.SysTools.Option backend_defs
    
    208 207
                         ++ map GHC.SysTools.Option th_defs
    
    ... ... @@ -265,28 +264,32 @@ generateMacros prefix name version =
    265 264
           _         -> error "take3"
    
    266 265
         (major1,major2,minor) = take3 $ map show (versionBranch version) ++ repeat "0"
    
    267 266
     
    
    267
    +getGhcVersionIncludeFlags :: DynFlags -> UnitEnv -> IO [String]
    
    268
    +getGhcVersionIncludeFlags dflags unit_env =
    
    269
    +  getGhcVersionPathName dflags unit_env >>= \case
    
    270
    +    Nothing -> pure []
    
    271
    +    Just path -> pure [ "-include", path ]
    
    268 272
     
    
    269 273
     -- | Find out path to @ghcversion.h@ file
    
    270
    -getGhcVersionPathName :: DynFlags -> UnitEnv -> IO FilePath
    
    271
    -getGhcVersionPathName dflags unit_env = do
    
    272
    -  let candidates = case ghcVersionFile dflags of
    
    273
    -        -- the user has provided an explicit `ghcversion.h` file to use.
    
    274
    -        Just path -> [path]
    
    275
    -        -- otherwise, try to find it in the rts' include-dirs.
    
    276
    -        -- Note: only in the RTS include-dirs! not all preload units less we may
    
    277
    -        -- use a wrong file. See #25106 where a globally installed
    
    278
    -        -- /usr/include/ghcversion.h file was used instead of the one provided
    
    279
    -        -- by the rts.
    
    280
    -        Nothing -> case lookupUnitId (ue_homeUnitState unit_env) rtsUnitId of
    
    281
    -          Nothing   -> []
    
    282
    -          Just info -> (</> "ghcversion.h") <$> collectIncludeDirs [info]
    
    283
    -
    
    284
    -  found <- filterM doesFileExist candidates
    
    285
    -  case found of
    
    286
    -      []    -> throwGhcExceptionIO (InstallationError
    
    287
    -                                    ("ghcversion.h missing; tried: "
    
    288
    -                                      ++ intercalate ", " candidates))
    
    289
    -      (x:_) -> return x
    
    274
    +getGhcVersionPathName :: DynFlags -> UnitEnv -> IO (Maybe FilePath)
    
    275
    +getGhcVersionPathName dflags unit_env = case ghcVersionFile dflags of
    
    276
    +  -- the user has provided an explicit `ghcversion.h` file to use.
    
    277
    +  Just path -> doesFileExist path >>= \case
    
    278
    +    True -> return (Just path)
    
    279
    +    False -> throwGhcExceptionIO (InstallationError ("ghcversion.h not found in: " ++ path))
    
    280
    +  -- otherwise, try to find it in the rts' include-dirs.
    
    281
    +  -- Note: only in the RTS include-dirs! not all preload units less we may
    
    282
    +  -- use a wrong file. See #25106 where a globally installed
    
    283
    +  -- /usr/include/ghcversion.h file was used instead of the one provided
    
    284
    +  -- by the rts.
    
    285
    +  Nothing -> case lookupUnitId (ue_homeUnitState unit_env) rtsUnitId of
    
    286
    +    Nothing   -> pure Nothing
    
    287
    +    Just info -> do
    
    288
    +      let candidates = (</> "ghcversion.h") <$> collectIncludeDirs [info]
    
    289
    +      found <- filterM doesFileExist candidates
    
    290
    +      case found of
    
    291
    +        [] -> pure Nothing
    
    292
    +        (x:_) -> pure (Just x)
    
    290 293
     
    
    291 294
     applyCDefs :: DefunctionalizedCDefs -> Logger -> DynFlags -> IO [String]
    
    292 295
     applyCDefs NoCDefs _ _ = return []
    

  • testsuite/tests/driver/Makefile
    ... ... @@ -813,3 +813,8 @@ T23339B:
    813 813
     T25382:
    
    814 814
     	"$(TEST_HC)" $(TEST_HC_OPTS) -c T25382.hs
    
    815 815
     	"$(TEST_HC)" $(TEST_HC_OPTS) T25382.o -o main
    
    816
    +
    
    817
    +# Test we can compile C code with an empty package DB
    
    818
    +T26018:
    
    819
    +	touch foo.c
    
    820
    +	"$(TEST_HC)" $(TEST_HC_OPTS) -c foo.c -clear-package-db

  • testsuite/tests/driver/all.T
    ... ... @@ -331,3 +331,4 @@ test('T24286', [cxx_src, unless(have_profiling(), skip), extra_files(['T24286.cp
    331 331
     test('T24839', [unless(arch('x86_64') or arch('aarch64'), skip), extra_files(["t24839_sub.S"])], compile_and_run, ['t24839_sub.S'])
    
    332 332
     test('t25150', [extra_files(["t25150"])], multimod_compile, ['Main.hs', '-v0 -working-dir t25150/dir a.c'])
    
    333 333
     test('T25382', normal, makefile_test, [])
    
    334
    +test('T26018', req_c, makefile_test, [])