summaryrefslogtreecommitdiff
path: root/hadrian/src/Rules.hs
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2019-03-10 17:43:10 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-03-12 09:04:52 -0400
commit2d7dd0285bbc364f89d4d97928674f7ea73ed2c8 (patch)
tree64afbe9484037925efe0575e77971f532ac155fd /hadrian/src/Rules.hs
parent4cf2160afe0e08fe29576895a1eced863d3a521d (diff)
downloadhaskell-2d7dd0285bbc364f89d4d97928674f7ea73ed2c8.tar.gz
Hadrian: Add ./hadrian/ghci.sh script for fast development feedback
Running the `./hadrian/ghci` target will load the main compiler into a ghci session. This is intended for fast development feedback, modules are only typechecked so it isn't possible to run any functions in the repl. You can also use this target with `ghcid`. The first time this command is run hadrian will need to compile a few dependencies which will take 1-2 minutes. Loading GHC into GHCi itself takes about 30 seconds. Internally this works by calling a new hadrian target called `tool-args`. This target prints out the package and include flags which are necessary to load files into ghci. The same target is intended to be used by other tooling which uses the GHC API in order to set up the correct GHC API session. For example, using this target it is also possible to use HIE when developing on GHC.
Diffstat (limited to 'hadrian/src/Rules.hs')
-rw-r--r--hadrian/src/Rules.hs35
1 files changed, 34 insertions, 1 deletions
diff --git a/hadrian/src/Rules.hs b/hadrian/src/Rules.hs
index c5be5a7ff9..e4de23f34d 100644
--- a/hadrian/src/Rules.hs
+++ b/hadrian/src/Rules.hs
@@ -1,4 +1,5 @@
-module Rules (buildRules, oracleRules, packageTargets, topLevelTargets) where
+module Rules (buildRules, oracleRules, packageTargets, topLevelTargets
+ , toolArgsTarget ) where
import qualified Hadrian.Oracles.ArgsHash
import qualified Hadrian.Oracles.Cabal.Rules
@@ -26,6 +27,38 @@ import Target
import UserSettings
import Utilities
+
+-- | @tool-args@ is used by tooling in order to get the arguments necessary
+-- to set up a GHC API session which can compile modules from GHC. When
+-- run, the target prints out the arguments that would be passed to @ghc@
+-- during normal compilation to @stdout@.
+--
+-- This target is called by the `ghci.sh` script in order to load all of GHC's
+-- modules into GHCi.
+toolArgsTarget :: Rules ()
+toolArgsTarget = do
+ "tool-args" ~> do
+ let fake_target = target (Context Stage0 compiler dynamic)
+ (Ghc ToolArgs Stage0) [] ["ignored"]
+
+ -- need the autogenerated files so that they are precompiled
+ generatedGhcDependencies Stage0 >>= need
+ interpret fake_target Rules.Generate.compilerDependencies >>= need
+
+ root <- buildRoot
+ let dir = buildDir (vanillaContext Stage0 compiler)
+ need [ root <//> dir -/- "Config.hs" ]
+ need [ root <//> dir -/- "Fingerprint.hs" ]
+ need [ root <//> dir -/- "Parser.hs" ]
+ need [ root <//> dir -/- "Lexer.hs" ]
+ need [ root <//> dir -/- "CmmParse.hs" ]
+ need [ root <//> dir -/- "CmmLex.hs" ]
+
+ -- Find out the arguments that are needed to load a module into the
+ -- session
+ arg_list <- interpret fake_target getArgs
+ liftIO $ putStrLn (intercalate " " arg_list)
+
allStages :: [Stage]
allStages = [minBound .. maxBound]