... |
... |
@@ -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 []
|