diff options
Diffstat (limited to 'hadrian')
-rwxr-xr-x | hadrian/ghci-cabal.in | 5 | ||||
-rwxr-xr-x | hadrian/ghci-stack.in | 5 | ||||
-rwxr-xr-x | hadrian/hie-bios | 2 | ||||
-rw-r--r-- | hadrian/hie-bios.bat | 3 | ||||
-rw-r--r-- | hadrian/src/Rules/ToolArgs.hs | 78 |
5 files changed, 32 insertions, 61 deletions
diff --git a/hadrian/ghci-cabal.in b/hadrian/ghci-cabal.in index 2a97b37180..0245ed6b09 100755 --- a/hadrian/ghci-cabal.in +++ b/hadrian/ghci-cabal.in @@ -3,7 +3,8 @@ # This file is generated by configure from ghci-cabal.in set -e - +export TOOL_OUTPUT=.hadrian_ghci/ghci_args # Replace newlines with spaces, as these otherwise break the ghci invocation on windows. -GHC_FLAGS="$GHC_FLAGS $(TERM=dumb CABFLAGS=-v0 "hadrian/build-cabal" tool:ghc/Main.hs -q --build-root=.hadrian_ghci --flavour=ghc-in-ghci $HADRIAN_ARGS | tr '\n\r' ' ')" +CABFLAGS=-v0 "hadrian/build-cabal" tool:compiler/GHC.hs --build-root=.hadrian_ghci --flavour=ghc-in-ghci $HADRIAN_ARGS +GHC_FLAGS="$GHC_FLAGS $(cat $TOOL_OUTPUT | tr '\n\r' ' ')" @WithGhc@ --interactive $GHC_FLAGS $@ -fno-code -fwrite-interface -hidir=.hadrian_ghci/interface -O0 +RTS -A128m diff --git a/hadrian/ghci-stack.in b/hadrian/ghci-stack.in index ef95552b64..12f3888205 100755 --- a/hadrian/ghci-stack.in +++ b/hadrian/ghci-stack.in @@ -4,6 +4,9 @@ set -e +export TOOL_OUTPUT=.hadrian_ghci/ghci_args +TERM=dumb CABFLAGS=-v0 "hadrian/build-cabal" tool:compiler/GHC.hs -q --build-root=.hadrian_ghci --flavour=ghc-in-ghci $HADRIAN_ARGS + # Replace newlines with spaces, as these otherwise break the ghci invocation on windows. -GHC_FLAGS="$GHC_FLAGS $(TERM=dumb CABFLAGS=-v0 "hadrian/build-stack" tool-args -q --build-root=.hadrian_ghci --flavour=ghc-in-ghci $HADRIAN_ARGS | tr '\n\r' ' ')" +GHC_FLAGS="$GHC_FLAGS $(cat $TOOL_OUTPUT | tr '\n\r' ' ')" stack exec -- @WithGhc@ --interactive $GHC_FLAGS "$@" -fno-code -fwrite-interface -hidir=.hadrian_ghci/interface -O0 +RTS -A128m diff --git a/hadrian/hie-bios b/hadrian/hie-bios index 4def2e8823..49224253b8 100755 --- a/hadrian/hie-bios +++ b/hadrian/hie-bios @@ -3,5 +3,5 @@ # When run, this program will output a list of arguments which are necessary to # load the GHC library component into GHCi. The program is used by `ghcide` in # order to automatically set up the correct GHC API session for a project. -TERM=dumb CABFLAGS=-v0 $PWD/hadrian/build-cabal tool:$1 -q --build-root=.hie-bios --flavour=ghc-in-ghci > $HIE_BIOS_OUTPUT +TERM=dumb CABFLAGS=-v0 TOOL_OUTPUT=$HIE_BIOS_OUTPUT $PWD/hadrian/build-cabal tool:$1 -q --build-root=.hie-bios --flavour=ghc-in-ghci diff --git a/hadrian/hie-bios.bat b/hadrian/hie-bios.bat index fda322af58..73bbea82be 100644 --- a/hadrian/hie-bios.bat +++ b/hadrian/hie-bios.bat @@ -1,3 +1,4 @@ set TERM=dumb set CABFLAGS=-v0 -%CD%\hadrian\build-cabal.bat tool:%1 -q --build-root=_hie-bios --flavour=ghc-in-ghci > %HIE_BIOS_OUTPUT% +set TOOL_OUTPUT=%HIE_BIOS_OUTPUT% +%CD%\hadrian\build-cabal.bat tool:%1 --build-root=_hie-bios --flavour=ghc-in-ghci diff --git a/hadrian/src/Rules/ToolArgs.hs b/hadrian/src/Rules/ToolArgs.hs index 1ed15d8f05..fcb78a824b 100644 --- a/hadrian/src/Rules/ToolArgs.hs +++ b/hadrian/src/Rules/ToolArgs.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE LambdaCase #-} module Rules.ToolArgs(toolArgsTarget) where import qualified Rules.Generate @@ -12,6 +13,7 @@ import Settings import Hadrian.Oracles.Cabal import Hadrian.Haskell.Cabal.Type import System.Directory (canonicalizePath) +import System.Environment (lookupEnv) -- | @tool:@ 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 @@ -41,18 +43,28 @@ toolRuleBody fp = do mm <- dirMap cfp <- liftIO $ canonicalizePath fp case find (flip isPrefixOf cfp . fst) mm of - Just (_, (p, extra)) -> mkToolTarget extra p + Just (_, p) -> mkToolTarget p Nothing -> fail $ "No prefixes matched " ++ show fp ++ " IN\n " ++ show mm -mkToolTarget :: [String] -> Package -> Action () -mkToolTarget es p = do +mkToolTarget :: Package -> Action () +mkToolTarget p = do -- This builds automatically generated dependencies. Not sure how to do -- this generically yet. allDeps - let fake_target = target (Context Stage0 p (if windowsHost then vanilla else dynamic)) + setupConfig <- pkgSetupConfigFile (Context Stage0 p (if windowsHost then vanilla else dynamic)) + need [setupConfig] + let ctx = Context Stage0 p (if windowsHost then vanilla else dynamic) + fake_target = target ctx (Ghc ToolArgs Stage0) [] ["ignored"] + + cd <- readContextData ctx + let es = modules cd ++ otherModules cd + arg_list <- interpret fake_target getArgs - liftIO $ putStrLn (intercalate "\n" (arg_list ++ es)) + liftIO $ lookupEnv "TOOL_OUTPUT" >>= \case + Nothing -> putStrLn (intercalate "\n" (arg_list ++ es)) + Just out -> writeFile out (intercalate "\n" (arg_list ++ es)) + allDeps :: Action () allDeps = do do @@ -67,61 +79,15 @@ allDeps = do root <- buildRoot let dir = buildDir (vanillaContext Stage0 compiler) - need [ root -/- dir -/- "GHC" -/- "Settings" -/- "Config.hs" ] need [ root -/- dir -/- "GHC" -/- "Parser.hs" ] need [ root -/- dir -/- "GHC" -/- "Parser" -/- "Lexer.hs" ] need [ root -/- dir -/- "GHC" -/- "Cmm" -/- "Parser.hs" ] need [ root -/- dir -/- "GHC" -/- "Cmm" -/- "Lexer.hs" ] --- This list is quite a lot like stage0packages but doesn't include --- critically the `exe:ghc` component as that depends on the GHC library --- which takes a while to compile. -toolTargets :: [Package] -toolTargets = [ array - , bytestring - , templateHaskell - , containers - , deepseq - , directory - , exceptions - , filepath - , compiler - , ghcCompact - , ghcPrim - --, haskeline - , hp2ps - , hsc2hs - , pretty - , process - , rts - , stm - , time - , unlit - , xhtml ] - -- | Create a mapping from files to which component it belongs to. -dirMap :: Action [(FilePath, (Package, [String]))] +dirMap :: Action [(FilePath, Package)] dirMap = do - auto <- concatMapM go toolTargets - -- Mush the ghc executable into the compiler component so the whole of ghc is not built when - -- configuring - ghc_exe <- mkGhc - return (auto ++ [ghc_exe]) - - where - -- Make a separate target for the exe:ghc target because otherwise - -- configuring would build the whole GHC library which we probably - -- don't want to do. - mkGhc = do - let c = (Context Stage0 compiler (if windowsHost then vanilla else dynamic)) - cd <- readContextData c - fp <- liftIO $ canonicalizePath "ghc/" - return (fp, (compiler, "-ighc" : modules cd ++ otherModules cd ++ ["ghc/Main.hs"])) - go p = do - let c = (Context Stage0 p (if windowsHost then vanilla else dynamic)) - -- readContextData has the effect of configuring the package so all - -- dependent packages will also be built. - cd <- readContextData c - ids <- liftIO $ mapM canonicalizePath [pkgPath p </> i | i <- srcDirs cd] - return $ map (,(p, modules cd ++ otherModules cd)) ids - + targets <- stagePackages Stage0 + forM [(pkgPath p, p) | p <- targets] $ \(path, p) -> liftIO $ do + path' <- canonicalizePath path + pure (path', p) |