From 490e8c750ea23ce8e2b7309e0d514b7d27f231bb Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 10 Nov 2021 19:24:51 +0000 Subject: Generate ghcversion.h with the top-level configure This is, rather unintuitively, part of the goal of making the packages that make of the GHC distribution more freestanding. `ghcversion.h` is very simple, so we easily can move it out of the main build systems (make and Hadrian). By doing so, the RTS becomes less of a special case to those build systems as the header, already existing in the source tree, appears like any other. We could do this with the upcomming RTS configure, but it hardly matters because there is nothing platform-specific here, it is just versioning information like the other files the top-level configure can be responsible for. --- hadrian/src/Base.hs | 7 ++--- hadrian/src/Rules/Generate.hs | 48 +++++----------------------------- hadrian/src/Rules/Register.hs | 2 +- hadrian/src/Settings/Builders/Cabal.hs | 3 ++- hadrian/src/Settings/Builders/Ghc.hs | 4 +-- 5 files changed, 13 insertions(+), 51 deletions(-) (limited to 'hadrian') diff --git a/hadrian/src/Base.hs b/hadrian/src/Base.hs index 205bd7518f..253a436ea9 100644 --- a/hadrian/src/Base.hs +++ b/hadrian/src/Base.hs @@ -21,7 +21,7 @@ module Base ( module Way, -- * Files - configH, ghcVersionH, + configH, -- * Paths hadrianPath, configPath, configFile, sourcePath, shakeFilesDir, @@ -74,9 +74,6 @@ sourcePath = hadrianPath -/- "src" configH :: FilePath configH = "mk/config.h" -ghcVersionH :: Stage -> Action FilePath -ghcVersionH stage = stageLibPath stage <&> (-/- "ghcversion.h") - -- | The directory in 'buildRoot' containing the Shake database and other -- auxiliary files generated by Hadrian. shakeFilesDir :: FilePath @@ -123,7 +120,7 @@ includesDependencies :: Stage -> Action [FilePath] includesDependencies stage = do p <- stageLibPath stage pure $ (p -/-) <$> - [ "ghcautoconf.h", "ghcplatform.h", "ghcversion.h" ] + [ "ghcautoconf.h", "ghcplatform.h" ] -- | Files the `haddock` binary depends on haddockDeps :: Stage -> Action [FilePath] diff --git a/hadrian/src/Rules/Generate.hs b/hadrian/src/Rules/Generate.hs index 13147aeec9..eb7a780d97 100644 --- a/hadrian/src/Rules/Generate.hs +++ b/hadrian/src/Rules/Generate.hs @@ -133,7 +133,6 @@ generatePackageCode context@(Context stage pkg _) = do (root -/- "**" -/- dir -/- "DerivedConstants.h") <~ stageLibPath stage (root -/- "**" -/- dir -/- "ghcautoconf.h") <~ stageLibPath stage (root -/- "**" -/- dir -/- "ghcplatform.h") <~ stageLibPath stage - (root -/- "**" -/- dir -/- "ghcversion.h") <~ stageLibPath stage where pattern <~ mdir = pattern %> \file -> do dir <- mdir @@ -184,7 +183,6 @@ generateRules = do (prefix -/- "ghcplatform.h") %> go generateGhcPlatformH (prefix -/- "settings") %> go generateSettings (prefix -/- "ghcautoconf.h") %> go generateGhcAutoconfH - (prefix -/- "ghcversion.h") %> go generateGhcVersionH -- TODO: simplify, get rid of fake rts context for_ (fst <$> deriveConstantsPairs) $ \constantsFile -> prefix -/- constantsFile %> \file -> do @@ -193,7 +191,6 @@ generateRules = do need [ prefix -/- "ghcplatform.h" , prefix -/- "ghcautoconf.h" - , prefix -/- "ghcversion.h" ] withTempDir $ \dir -> build $ target (rtsContext stage) DeriveConstants [] [file, dir] @@ -395,7 +392,7 @@ generateConfigHs = do generateGhcAutoconfH :: Expr String generateGhcAutoconfH = do trackGenerateHs - configHContents <- expr $ map undefinePackage <$> readFileLines configH + configHContents <- expr $ mapMaybe undefinePackage <$> readFileLines configH return . unlines $ [ "#if !defined(__GHCAUTOCONF_H__)" , "#define __GHCAUTOCONF_H__" ] @@ -404,43 +401,12 @@ generateGhcAutoconfH = do where undefinePackage s | "#define PACKAGE_" `isPrefixOf` s - = "/* #undef " ++ takeWhile (/=' ') (drop 8 s) ++ " */" - | otherwise = s - --- | Generate @ghcversion.h@ header. -generateGhcVersionH :: Expr String -generateGhcVersionH = do - trackGenerateHs - fullVersion <- getSetting ProjectVersion - version <- getSetting ProjectVersionInt - patchLevel1 <- getSetting ProjectPatchLevel1 - patchLevel2 <- getSetting ProjectPatchLevel2 - return . unlines $ - [ "#if !defined(__GHCVERSION_H__)" - , "#define __GHCVERSION_H__" - , "" - , "#if !defined(__GLASGOW_HASKELL__)" - , "#define __GLASGOW_HASKELL__ " ++ version - , "#endif" - , "#if !defined(__GLASGOW_HASKELL_FULL_VERSION__)" - , "#define __GLASGOW_HASKELL_FULL_VERSION__ \"" ++ fullVersion ++ "\"" - , "#endif" - , ""] - ++ - [ "#define __GLASGOW_HASKELL_PATCHLEVEL1__ " ++ patchLevel1 | patchLevel1 /= "" ] - ++ - [ "#define __GLASGOW_HASKELL_PATCHLEVEL2__ " ++ patchLevel2 | patchLevel2 /= "" ] - ++ - [ "" - , "#define MIN_VERSION_GLASGOW_HASKELL(ma,mi,pl1,pl2) (\\" - , " ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \\" - , " ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \\" - , " && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \\" - , " ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \\" - , " && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \\" - , " && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ )" - , "" - , "#endif /* __GHCVERSION_H__ */" ] + = Just $ "/* #undef " ++ takeWhile (/=' ') (drop 8 s) ++ " */" + | "#define __GLASGOW_HASKELL" `isPrefixOf` s + = Nothing + | "/* REMOVE ME */" == s + = Nothing + | otherwise = Just s -- | Generate @Version.hs@ files. generateVersionHs :: Expr String diff --git a/hadrian/src/Rules/Register.hs b/hadrian/src/Rules/Register.hs index 6bbae7e0bd..6b603c6858 100644 --- a/hadrian/src/Rules/Register.hs +++ b/hadrian/src/Rules/Register.hs @@ -128,7 +128,7 @@ buildConf _ context@Context {..} _conf = do need [ path -/- "DerivedConstants.h" , path -/- "ghcautoconf.h" , path -/- "ghcplatform.h" - , path -/- "ghcversion.h" ] + ] -- we need to generate this file for GMP when (package == ghcBignum) $ do diff --git a/hadrian/src/Settings/Builders/Cabal.hs b/hadrian/src/Settings/Builders/Cabal.hs index e3361d3fe9..e38eba1cf0 100644 --- a/hadrian/src/Settings/Builders/Cabal.hs +++ b/hadrian/src/Settings/Builders/Cabal.hs @@ -129,7 +129,8 @@ configureArgs = do , conf "--with-curses-libraries" $ arg =<< getSetting CursesLibDir , conf "--host" $ arg =<< getSetting TargetPlatformFull , conf "--with-cc" $ arg =<< getBuilderPath . (Cc CompileC) =<< getStage - , notStage0 ? (arg =<< ("--ghc-option=-ghcversion-file=" ++) <$> expr ((-/-) <$> topDirectory <*> ghcVersionH stage))] + , notStage0 ? arg "--ghc-option=-ghcversion-file=rts/include/ghcversion.h" + ] bootPackageConstraints :: Args bootPackageConstraints = stage0 ? do diff --git a/hadrian/src/Settings/Builders/Ghc.hs b/hadrian/src/Settings/Builders/Ghc.hs index 3d5a96efe4..b4c129562e 100644 --- a/hadrian/src/Settings/Builders/Ghc.hs +++ b/hadrian/src/Settings/Builders/Ghc.hs @@ -195,9 +195,7 @@ commonGhcArgs :: Args commonGhcArgs = do way <- getWay path <- getBuildPath - stage <- getStage useColor <- shakeColor <$> expr getShakeOptions - ghcVersion <- expr $ ghcVersionH stage mconcat [ arg "-hisuf", arg $ hisuf way , arg "-osuf" , arg $ osuf way , arg "-hcsuf", arg $ hcsuf way @@ -208,7 +206,7 @@ commonGhcArgs = do -- in the package database. We therefore explicitly supply the path -- to the @ghc-version@ file, to prevent GHC from trying to open the -- RTS package in the package database and failing. - , package rts ? notStage0 ? arg ("-ghcversion-file=" ++ ghcVersion) + , package rts ? notStage0 ? arg "-ghcversion-file=rts/include/ghcversion.h" , map ("-optc" ++) <$> getStagedSettingList ConfCcArgs , map ("-optP" ++) <$> getStagedSettingList ConfCppArgs , map ("-optP" ++) <$> getContextData cppOpts -- cgit v1.2.1