summaryrefslogtreecommitdiff
path: root/hadrian/src/Rules/Generate.hs
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-05-12 10:59:15 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-11-23 12:46:35 -0500
commitb5c714545abc5f75a1ffdcc39b4bfdc7cd5e64b4 (patch)
tree46721c2ca167a8295fb70600b102ccc26aac7b02 /hadrian/src/Rules/Generate.hs
parente153851650bbba631f3a6926ba42422f9f1fa0cd (diff)
downloadhaskell-b5c714545abc5f75a1ffdcc39b4bfdc7cd5e64b4.tar.gz
Don't let configure perform trivial substitutions (#21846)
Hadrian now performs substitutions, especially to generate .cabal files from .cabal.in files. Two benefits: 1. We won't have to re-configure when we modify thing.cabal.in. Hadrian will take care of this for us. 2. It paves the way to allow the same package to be configured differently by Hadrian in the same session. This will be useful to fix #19174: we want to build a stage2 cross-compiler for the host platform and a stage1 compiler for the cross target platform in the same Hadrian session.
Diffstat (limited to 'hadrian/src/Rules/Generate.hs')
-rw-r--r--hadrian/src/Rules/Generate.hs71
1 files changed, 69 insertions, 2 deletions
diff --git a/hadrian/src/Rules/Generate.hs b/hadrian/src/Rules/Generate.hs
index c41b6eed8f..a44ca510d2 100644
--- a/hadrian/src/Rules/Generate.hs
+++ b/hadrian/src/Rules/Generate.hs
@@ -1,7 +1,8 @@
module Rules.Generate (
isGeneratedCmmFile, compilerDependencies, generatePackageCode,
generateRules, copyRules, generatedDependencies,
- ghcPrimDependencies
+ ghcPrimDependencies,
+ templateRules
) where
import qualified Data.Set as Set
@@ -225,6 +226,72 @@ emptyTarget :: Context
emptyTarget = vanillaContext (error "Rules.Generate.emptyTarget: unknown stage")
(error "Rules.Generate.emptyTarget: unknown package")
+-- | Files generated by query-replace from a template
+templateResults :: [FilePath]
+templateResults =
+ [ "compiler/ghc.cabal"
+ , "rts/rts.cabal"
+ , "driver/ghci/ghci-wrapper.cabal"
+ , "ghc/ghc-bin.cabal"
+ , "utils/iserv/iserv.cabal"
+ , "utils/iserv-proxy/iserv-proxy.cabal"
+ , "utils/remote-iserv/remote-iserv.cabal"
+ , "utils/runghc/runghc.cabal"
+ , "libraries/ghc-boot/ghc-boot.cabal"
+ , "libraries/ghc-boot-th/ghc-boot-th.cabal"
+ , "libraries/ghci/ghci.cabal"
+ , "libraries/ghc-heap/ghc-heap.cabal"
+ , "utils/ghc-pkg/ghc-pkg.cabal"
+ , "libraries/libiserv/libiserv.cabal"
+ , "libraries/template-haskell/template-haskell.cabal"
+ , "libraries/prologue.txt"
+ ]
+
+templateRules :: Rules ()
+templateRules = do
+ templateResults |%> \out -> do
+ let settingWord :: Setting -> Action Word
+ settingWord s = read <$> setting s
+
+ project_version <- setting ProjectVersion
+ project_version_munged <- setting ProjectVersionMunged
+ target_word_size <- settingWord TargetWordSize
+ lib_dw <- flag UseLibdw
+ lib_numa <- flag UseLibnuma
+ lib_mingwex <- flag UseLibmingwex
+ lib_m <- flag UseLibm
+ lib_rt <- flag UseLibrt
+ lib_dl <- flag UseLibdl
+ lib_ffi <- flag UseSystemFfi
+ lib_ffi_adjustors <- flag UseLibffiForAdjustors
+ lib_bfd <- flag UseLibbfd
+ lib_pthread <- flag UseLibpthread
+ leading_underscore <- flag LeadingUnderscore
+ need_libatomic <- flag NeedLibatomic
+
+ let cabal_bool True = "True"
+ cabal_bool False = "False"
+
+ subst = replace "@ProjectVersion@" project_version
+ . replace "@ProjectVersionMunged@" project_version_munged
+ . replace "@Cabal64bit@" (cabal_bool (target_word_size == 8))
+ . replace "@CabalMingwex@" (cabal_bool lib_mingwex)
+ . replace "@CabalHaveLibdw@" (cabal_bool lib_dw)
+ . replace "@CabalHaveLibm@" (cabal_bool lib_m)
+ . replace "@CabalHaveLibrt@" (cabal_bool lib_rt)
+ . replace "@CabalHaveLibdl@" (cabal_bool lib_dl)
+ . replace "@CabalUseSystemLibFFI@" (cabal_bool lib_ffi)
+ . replace "@CabalLibffiAdjustors@" (cabal_bool lib_ffi_adjustors)
+ . replace "@CabalNeedLibpthread@" (cabal_bool lib_pthread)
+ . replace "@CabalHaveLibbfd@" (cabal_bool lib_bfd)
+ . replace "@CabalHaveLibNuma@" (cabal_bool lib_numa)
+ . replace "@CabalLeadingUnderscore@" (cabal_bool leading_underscore)
+ . replace "@CabalNeedLibatomic@" (cabal_bool need_libatomic)
+
+ s <- readFile' (out <.> "in")
+ writeFile' out (subst s)
+ putSuccess ("| Successfully generated " ++ out ++ " from its template")
+
-- Generators
-- | GHC wrapper scripts used for passing the path to the right package database
@@ -353,7 +420,7 @@ generateSettings = do
, ("Tables next to code", expr $ yesNo <$> flag TablesNextToCode)
, ("Leading underscore", expr $ yesNo <$> flag LeadingUnderscore)
, ("Use LibFFI", expr $ yesNo <$> useLibffiForAdjustors)
- , ("RTS expects libdw", yesNo <$> getFlag WithLibdw)
+ , ("RTS expects libdw", yesNo <$> getFlag UseLibdw)
]
let showTuple (k, v) = "(" ++ show k ++ ", " ++ show v ++ ")"
pure $ case settings of