@@ -10,7 +10,7 @@ module Obelisk.Command.Run where
1010import Control.Arrow ((&&&))
1111import Control.Exception (Exception, bracket)
1212import Control.Lens (ifor, (.~), (&))
13−import Control.Monad (filterM, unless)
13+import Control.Monad (filterM, unless, void)
1414import Control.Monad.Except (runExceptT, throwError)
1515import Control.Monad.IO.Class (liftIO)
1616import Control.Monad.Reader (MonadIO)
@@ -26,7 +26,7 @@ import qualified Data.Set as Set
2626import Data.String.Here (hereLit)
2727import Data.Text (Text)
2828import qualified Data.Text as T
29−import Data.Time.Clock
29+import Data.Time.Clock (getCurrentTime)
3030import Data.Time.Format (formatTime, defaultTimeLocale)
3131import Data.Traversable (for)
3232import Debug.Trace (trace)
@@ -87,14 +87,33 @@ profile
8787profile profileBasePattern rtsFlags = withProjectRoot "." $ \root -> do
8888 putLog Debug "Using profiled build of project."
8989
90− time <- liftIO $ getCurrentTime
90+ time <- liftIO getCurrentTime
9191 let profileBaseName = formatTime defaultTimeLocale profileBasePattern time
9292
9393 putLog Debug $ T.pack $ "Storing profiled data under base name of " <> profileBaseName
9494
9595 liftIO $ createDirectoryIfMissing False $ takeDirectory profileBaseName
9696
97− let nixBuildExpr = [hereLit|
97+ exePath <- nixCmd $ NixCmd_Build $ def
98+ & nixBuildConfig_outLink .~ OutLink_None
99+ & nixCmdConfig_target .~ Target
100+ { _target_path = Nothing
101+ , _target_attr = Nothing
102+ , _target_expr = Just nixBuildExpr }
103+ assets <- findProjectAssets root
104+ putLog Debug $ "Assets impurely loaded from: " <> assets
105+ freePort <- getFreePort
106+ (_, _, _, ph) <- createProcess_ "runProfExe" $ setCwd (Just root) $ setDelegateCtlc True $ proc exePath $
107+ [ show freePort
108+ , T.unpack assets
109+ , profileBaseName
110+ , "+RTS"
111+ , "-po" <> profileBaseName
112+ ] <> rtsFlags
113+ <> [ "-RTS" ]
114+ void $ waitForProcess ph
115+ where
116+ nixBuildExpr = [hereLit|
98117with (import ./. {});
99118let
100119 exeSource = obelisk.nixpkgs.writeText "ob-run" ''
@@ -120,25 +139,6 @@ in obelisk.nixpkgs.runCommand "ob-run" {
120139 buildInputs = [ (profiled.ghc.ghcWithPackages (p: [ p.backend p.frontend])) ];
121140} "ghc -x hs -prof -fno-prof-auto -threaded ${exeSource} -o $out"
122141|]
123− exePath <- nixCmd $ NixCmd_Build $ def
124− & nixBuildConfig_outLink .~ OutLink_None
125− & nixCmdConfig_target .~ Target
126− { _target_path = Nothing
127− , _target_attr = Nothing
128− , _target_expr = Just nixBuildExpr }
129− assets <- findProjectAssets root
130− putLog Debug $ "Assets impurely loaded from: " <> assets
131− freePort <- getFreePort
132− (_, _, _, ph) <- createProcess_ "runProfExe" $ setCwd (Just root) $ setDelegateCtlc True $ proc exePath $
133− [ show freePort
134− , T.unpack assets
135− , profileBaseName
136− , "+RTS"
137− , "-po" <> profileBaseName
138− ] <> rtsFlags
139− <> [ "-RTS" ]
140− _ <- waitForProcess ph
141− pure ()
142142
143143run
144144 :: MonadObelisk m
@@ -336,7 +336,7 @@ withGhciScript packageInfos pathBase f = do
336336 , [ "Backend" | "backend" `Set.member` packageNames ]
337337 , [ "Frontend" | "frontend" `Set.member` packageNames ]
338338 ]
339− dotGhci = unlines $
339+ dotGhci = unlines
340340 -- TODO: Shell escape
341341 [ ":set -F -pgmF " <> selfExe <> " -optF " <> preprocessorIdentifier <> " " <> unwords (map (("-optF " <>) . makeRelative pathBase . _cabalPackageInfo_packageFile) packageInfos)
342342 , ":set -i" <> intercalate ":" (packageInfos >>= rootedSourceDirs)