|
6 | 6 | module GHC.SysTools.Cpp
|
7 | 7 | ( doCpp
|
8 | 8 | , CppOpts(..)
|
9 |
| - , getGhcVersionPathName |
10 | 9 | , getGhcVersionIncludeFlags
|
11 | 10 | , applyCDefs
|
12 | 11 | , offsetIncludePaths
|
@@ -39,6 +38,7 @@ import Control.Monad
|
39 | 38 |
|
40 | 39 | import System.Directory
|
41 | 40 | import System.FilePath
|
| 41 | +import GHC.Settings.Config (cProjectVersionInt, cProjectPatchLevel1, cProjectVersion, cProjectPatchLevel2) |
42 | 42 |
|
43 | 43 | data CppOpts = CppOpts
|
44 | 44 | { sourceCodePreprocessor :: !SourceCodePreprocessor
|
@@ -125,10 +125,10 @@ doCpp logger tmpfs dflags unit_env opts input_fn output_fn = do
|
125 | 125 | [homeUnitEnv_dflags . ue_findHomeUnitEnv uid $ unit_env | uid <- ue_transitiveHomeDeps (ue_currentUnit unit_env) unit_env]
|
126 | 126 | dep_pkg_extra_inputs = [offsetIncludePaths fs (includePaths fs) | fs <- home_pkg_deps]
|
127 | 127 |
|
128 |
| - let include_paths_global = foldr (\ x xs -> ("-I" ++ x) : xs) [] |
| 128 | + let include_paths_global = map ("-I" ++) |
129 | 129 | (includePathsGlobal cmdline_include_paths ++ pkg_include_dirs
|
130 | 130 | ++ concatMap includePathsGlobal dep_pkg_extra_inputs)
|
131 |
| - let include_paths_quote = foldr (\ x xs -> ("-iquote" ++ x) : xs) [] |
| 131 | + let include_paths_quote = map ("-iquote" ++) |
132 | 132 | (includePathsQuote cmdline_include_paths ++
|
133 | 133 | includePathsQuoteImplicit cmdline_include_paths)
|
134 | 134 | let include_paths = include_paths_quote ++ include_paths_global
|
@@ -176,7 +176,7 @@ doCpp logger tmpfs dflags unit_env opts input_fn output_fn = do
|
176 | 176 | let asserts_def = [ "-D__GLASGOW_HASKELL_ASSERTS_IGNORED__" | gopt Opt_IgnoreAsserts dflags]
|
177 | 177 |
|
178 | 178 | -- Default CPP defines in Haskell source
|
179 |
| - hsSourceCppOpts <- getGhcVersionIncludeFlags dflags unit_env |
| 179 | + hsSourceCppOpts <- getGhcVersionIncludeFlags dflags logger tmpfs |
180 | 180 |
|
181 | 181 | -- MIN_VERSION macros
|
182 | 182 | let uids = explicitUnits unit_state
|
@@ -262,40 +262,41 @@ generateMacros prefix name version =
|
262 | 262 | _ -> error "take3"
|
263 | 263 | (major1,major2,minor) = take3 $ map show (versionBranch version) ++ repeat "0"
|
264 | 264 |
|
265 |
| -getGhcVersionIncludeFlags :: DynFlags -> UnitEnv -> IO [String] |
266 |
| -getGhcVersionIncludeFlags dflags unit_env = do |
267 |
| - mghcversionh <- getGhcVersionPathName dflags unit_env |
268 |
| - pure $ case mghcversionh of |
269 |
| - Nothing -> [] |
270 |
| - Just p -> ["-include", p] |
271 |
| - |
272 |
| --- | Find out path to @ghcversion.h@ file |
273 |
| -getGhcVersionPathName :: DynFlags -> UnitEnv -> IO (Maybe FilePath) |
274 |
| -getGhcVersionPathName dflags unit_env = do |
| 265 | +getGhcVersionIncludeFlags :: DynFlags -> Logger -> TmpFs -> IO [String] |
| 266 | +getGhcVersionIncludeFlags dflags logger tmpfs = do |
275 | 267 | case ghcVersionFile dflags of
|
276 |
| - -- the user has provided an explicit `ghcversion.h` file to use. |
277 |
| - Just path -> doesFileExist path >>= \case |
278 |
| - True -> pure (Just path) |
279 |
| - False -> throwGhcExceptionIO (InstallationError |
280 |
| - ("ghcversion.h missing; tried user-supplied path: " ++ path)) |
281 |
| - -- otherwise, try to find it in the rts' include-dirs. |
282 |
| - -- Note: only in the RTS include-dirs! not all preload units less we may |
283 |
| - -- use a wrong file. See #25106 where a globally installed |
284 |
| - -- /usr/include/ghcversion.h file was used instead of the one provided |
285 |
| - -- by the rts. |
286 |
| - Nothing -> case lookupUnitId (ue_homeUnitState unit_env) rtsUnitId of |
287 |
| - Nothing -> do |
288 |
| - -- print warning and return nothing |
289 |
| - putStrLn "Couldn't find ghcversion.h file: no rts unit available and -ghcversion-file flag not passed" |
290 |
| - pure Nothing |
291 |
| - Just info -> do |
292 |
| - let candidates = (</> "ghcversion.h") <$> collectIncludeDirs [info] |
293 |
| - found <- filterM doesFileExist candidates |
294 |
| - case found of |
295 |
| - [] -> throwGhcExceptionIO (InstallationError |
296 |
| - ("ghcversion.h missing; tried: " |
297 |
| - ++ intercalate ", " candidates)) |
298 |
| - (x:_) -> return (Just x) |
| 268 | + -- the user has provided an explicit `ghcversion.h` file to use. |
| 269 | + Just path -> do |
| 270 | + found <- doesFileExist path |
| 271 | + unless found $ |
| 272 | + throwGhcExceptionIO (InstallationError ("ghcversion.h missing; tried: " ++ path)) |
| 273 | + return ["-include", path] |
| 274 | + Nothing -> do |
| 275 | + macro_stub <- newTempName logger tmpfs (tmpDir dflags) TFL_CurrentModule "h" |
| 276 | + writeFile macro_stub ghcVersionH |
| 277 | + return ["-include", macro_stub] |
| 278 | + |
| 279 | +-- --------------------------------------------------------------------------- |
| 280 | +-- ghcversion.h |
| 281 | + |
| 282 | +ghcVersionH :: String |
| 283 | +ghcVersionH = |
| 284 | + concat |
| 285 | + ["#define __GLASGOW_HASKELL__ ", show cProjectVersionInt, "\n" |
| 286 | + ,"#define __GLASGOW_HASKELL_FULL_VERSION__ ", show cProjectVersion, "\n" |
| 287 | + ,"\n" |
| 288 | + ,"#define __GLASGOW_HASKELL_PATCHLEVEL1__ ", show cProjectPatchLevel1, "\n" |
| 289 | + ,"#define __GLASGOW_HASKELL_PATCHLEVEL2__ ", show cProjectPatchLevel2, "\n" |
| 290 | + ,"\n" |
| 291 | + ,"#define MIN_VERSION_GLASGOW_HASKELL(ma,mi,pl1,pl2) ( \\\n" |
| 292 | + ," ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \\\n" |
| 293 | + ," ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \\\n" |
| 294 | + ," && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \\\n" |
| 295 | + ," ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \\\n" |
| 296 | + ," && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \\\n" |
| 297 | + ," && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ )\n" |
| 298 | + ,"\n\n" |
| 299 | + ] |
299 | 300 |
|
300 | 301 | applyCDefs :: DefunctionalizedCDefs -> Logger -> DynFlags -> IO [String]
|
301 | 302 | applyCDefs NoCDefs _ _ = return []
|
|
0 commit comments