on master help sign in
Make ob profile work in subdirectories
commit795fd9d3b0949e2f55531d22205cb480aaf512f9 authorElliot Cameron <eacameron@gmail.com> dateMon 24 Feb 2020, 13:07 (7 years ago) parentee5b42e
2 files changed+43−20
lib/command/src/Obelisk/Command/Nix.hs+21−11 lib/command/src/Obelisk/Command/Run.hs+22−9
lib/command/src/Obelisk/Command/Nix.hs+21−11
@@ -32,6 +32,8 @@ module Obelisk.Command.Nix
3232
3333 , boolArg
3434 , nixCmd
35+ , nixCmdProc
36+ , nixCmdProc'
3537 , rawArg
3638 , runNixShellConfig
3739 , strArg
@@ -188,27 +190,35 @@ runNixShellConfig cfg = mconcat
188190 ["--run", run] | run <- maybeToList $ cfg ^. nixShellConfig_run
189191 ]
190192
191−nixCmd :: MonadObelisk m => NixCmd -> m FilePath
192−nixCmd cmdCfg = withSpinner' ("Running " <> cmd <> desc) (Just $ const $ "Built " <> desc) $ do
193− output <- readProcessAndLogStderr Debug $ proc (T.unpack cmd) options
194− -- Remove final newline that Nix appends
195− Just (outPath, '\n') <- pure $ T.unsnoc output
196− pure $ T.unpack outPath
193+nixCmdProc :: NixCmd -> ProcessSpec
194+nixCmdProc = fst . nixCmdProc'
195+
196+nixCmdProc' :: NixCmd -> (ProcessSpec, T.Text)
197+nixCmdProc' cmdCfg = (proc (T.unpack cmd) options, cmd)
197198 where
198− (cmd, options, commonCfg) = case cmdCfg of
199+ (cmd, options) = case cmdCfg of
199200 NixCmd_Build cfg' ->
200201 ( "nix-build"
201202 , runNixBuildConfig cfg'
202− , cfg' ^. nixCommonConfig
203203 )
204204 NixCmd_Instantiate cfg' ->
205205 ( "nix-instantiate"
206206 , runNixInstantiateConfig cfg'
207− , cfg' ^. nixCommonConfig
208207 )
208+
209+nixCmd :: MonadObelisk m => NixCmd -> m FilePath
210+nixCmd cmdCfg = withSpinner' ("Running " <> cmd <> desc) (Just $ const $ "Built " <> desc) $ do
211+ output <- readProcessAndLogStderr Debug cmdProc
212+ -- Remove final newline that Nix appends
213+ Just (outPath, '\n') <- pure $ T.unsnoc output
214+ pure $ T.unpack outPath
215+ where
216+ (cmdProc, cmd) = nixCmdProc' cmdCfg
217+ commonCfg = case cmdCfg of
218+ NixCmd_Build cfg' -> cfg' ^. nixCommonConfig
219+ NixCmd_Instantiate cfg' -> cfg' ^. nixCommonConfig
209220 path = commonCfg ^. nixCmdConfig_target . target_path
210221 desc = T.pack $ mconcat $ catMaybes
211− [ (" on " <>) <$> path
222+ [ ("on " <>) <$> path
212223 , (\a -> " [" <> a <> "]") <$> (commonCfg ^. nixCmdConfig_target . target_attr)
213224 ]
214−
lib/command/src/Obelisk/Command/Run.hs+22−9
@@ -51,9 +51,19 @@ import qualified System.Info
5151import System.IO.Temp (withSystemTempDirectory)
5252
5353import Obelisk.App (MonadObelisk)
54−import Obelisk.CliApp (Severity (..),
55− failWith, putLog, proc, readCreateProcessWithExitCode,
56− setCwd, setDelegateCtlc, createProcess_, waitForProcess)
54+import Obelisk.CliApp (
55+ Severity (..),
56+ createProcess_,
57+ failWith,
58+ proc,
59+ putLog,
60+ readCreateProcessWithExitCode,
61+ readProcessAndLogStderr,
62+ setCwd,
63+ setDelegateCtlc,
64+ waitForProcess,
65+ withSpinner,
66+ )
5767import Obelisk.Command.Nix
5868import Obelisk.Command.Project (nixShellWithPkgs, toImplDir, withProjectRoot, findProjectAssets)
5969import Obelisk.Command.Thunk (attrCacheFileName)
@@ -93,12 +103,15 @@ profile profileBasePattern rtsFlags = withProjectRoot "." $ \root -> do
93103
94104 liftIO $ createDirectoryIfMissing True $ takeDirectory profileBaseName
95105
96− outPath <- nixCmd $ NixCmd_Build $ def
97− & nixBuildConfig_outLink .~ OutLink_None
98− & nixCmdConfig_target .~ Target
99− { _target_path = Just "."
100− , _target_attr = Just "__unstable__.profiledObRun"
101− , _target_expr = Nothing }
106+ outPath <- withSpinner "Building profiled executable" $
107+ fmap (T.unpack . T.strip) $ readProcessAndLogStderr Debug $ setCwd (Just root) $ nixCmdProc $
108+ NixCmd_Build $ def
109+ & nixBuildConfig_outLink .~ OutLink_None
110+ & nixCmdConfig_target .~ Target
111+ { _target_path = Just "."
112+ , _target_attr = Just "__unstable__.profiledObRun"
113+ , _target_expr = Nothing
114+ }
102115 assets <- findProjectAssets root
103116 putLog Debug $ "Assets impurely loaded from: " <> assets
104117 freePort <- getFreePort