on master help sign in
command: Pull staticWhich to one module
commit1737bfc49b36e9c722f110d8db7256ff64f8ac3b authorElliot Cameron <eacameron@gmail.com> dateFri 17 Jan 2020, 17:06 (7 years ago) parentd6c894d
3 files changed+20−14
lib/command/src/Obelisk/Command/Project.hs+2−4 lib/command/src/Obelisk/Command/Run.hs+6−10 lib/command/src/Obelisk/Command/Utils.hs+12
lib/command/src/Obelisk/Command/Project.hs+2−4
@@ -1,7 +1,6 @@
11{-# LANGUAGE FlexibleContexts #-}
22{-# LANGUAGE LambdaCase #-}
33{-# LANGUAGE OverloadedStrings #-}
4−{-# LANGUAGE TemplateHaskell #-}
54module Obelisk.Command.Project
65 ( InitSource (..)
76 , initProject
@@ -31,7 +30,6 @@ import System.IO.Unsafe (unsafePerformIO)
3130import System.Posix (FileStatus, FileMode, CMode (..), UserID, deviceID, fileID, fileMode, fileOwner, getFileStatus, getRealUserID)
3231import System.Posix.Files
3332import System.Process (waitForProcess)
34−import System.Which (staticWhich)
3533
3634import GitHub.Data.GitData (Branch)
3735import GitHub.Data.Name (Name)
@@ -39,6 +37,7 @@ import GitHub.Data.Name (Name)
3937import Obelisk.App (MonadObelisk)
4038import Obelisk.CliApp
4139import Obelisk.Command.Thunk
40+import Obelisk.Command.Utils (nixExePath)
4241
4342--TODO: Make this module resilient to random exceptions
4443
@@ -245,8 +244,7 @@ inImpureProjectShell shellName command = withProjectRoot "." $ \root ->
245244
246245projectShell :: MonadObelisk m => FilePath -> Bool -> String -> Maybe String -> m ()
247246projectShell root isPure shellName command = do
248− let nixPath = $(staticWhich "nix")
249− nixpkgsPath <- fmap T.strip $ readProcessAndLogStderr Debug $ setCwd (Just root) $ proc nixPath ["eval", "(import .obelisk/impl {}).nixpkgs.path"]
247+ nixpkgsPath <- fmap T.strip $ readProcessAndLogStderr Debug $ setCwd (Just root) $ proc nixExePath ["eval", "(import .obelisk/impl {}).nixpkgs.path"]
250248 nixRemote <- liftIO $ lookupEnv "NIX_REMOTE"
251249 (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setDelegateCtlc True $ setCwd (Just root) $ proc "nix-shell" $
252250 [ "default.nix"] <>
lib/command/src/Obelisk/Command/Run.hs+6−10
@@ -41,11 +41,11 @@ import System.Directory
4141import System.FilePath
4242import qualified System.Info
4343import System.IO.Temp (withSystemTempDirectory)
44−import System.Which (staticWhich)
4544
4645import Obelisk.App (MonadObelisk, ObeliskT)
4746import Obelisk.CliApp (Severity (..) , callCommand, failWith, putLog, proc, readCreateProcessWithExitCode, readProcessAndLogStderr)
4847import Obelisk.Command.Project (inProjectShell, withProjectRoot)
48+import Obelisk.Command.Utils (findExePath, ghcidExePath, nixBuildExePath, nixExePath)
4949
5050data CabalPackageInfo = CabalPackageInfo
5151 { _cabalPackageInfo_packageFile :: FilePath
@@ -72,7 +72,7 @@ run = withProjectRoot "." $ \root -> do
7272 assets <- do
7373 let importableRoot = toNixPath root
7474 isDerivation <- readProcessAndLogStderr Debug $
75− proc nixPath
75+ proc nixExePath
7676 [ "eval"
7777 , "-f"
7878 , root
@@ -84,12 +84,12 @@ run = withProjectRoot "." $ \root -> do
8484 -- Check whether the impure static files are a derivation (and so must be built)
8585 if isDerivation == "1"
8686 then fmap T.strip $ readProcessAndLogStderr Debug $ -- Strip whitespace here because nix-build has no --raw option
87− proc nixBuildPath
87+ proc nixBuildExePath
8888 [ "--no-out-link"
8989 , "-E", "(import " <> importableRoot <> "{}).passthru.staticFilesImpure"
9090 ]
9191 else readProcessAndLogStderr Debug $
92− proc nixPath ["eval", "-f", root, "passthru.staticFilesImpure", "--raw"]
92+ proc nixExePath ["eval", "-f", root, "passthru.staticFilesImpure", "--raw"]
9393 putLog Debug $ "Assets impurely loaded from: " <> assets
9494 runGhcid dotGhciPath $ Just $ unwords
9595 [ "Obelisk.Run.run"
@@ -125,12 +125,8 @@ runWatch = do
125125getLocalPkgs :: (MonadObelisk m, MonadIO m) => FilePath -> m [FilePath]
126126getLocalPkgs root = do
127127 rootAbs <- liftIO $ makeAbsolute root
128− let findPath = $(staticWhich "find")
129− (_exitCode, out, err') <- readCreateProcessWithExitCode $
130− proc findPath ["-L", rootAbs, "(", "-name", "*.cabal", "-o", "-name", Hpack.packageConfig, ")", "-a", "-type", "f"]
131− case T.strip $ T.pack err' of
132− err | T.null err -> pure ()
133− | otherwise -> putLog Debug err
128+ proc findExePath ["-L", root, "(", "-name", "*.cabal", "-o", "-name", Hpack.packageConfig, ")", "-a", "-type", "f"]
129+ putLog Debug $ T.strip $ T.pack err
134130
135131 let packagePaths = filter (not . isIgnored) $ T.lines $ T.strip $ T.pack out
136132 obeliskImplDir = ".obelisk/impl/"
lib/command/src/Obelisk/Command/Utils.hs+12
@@ -37,6 +37,18 @@ getObeliskExe = getExecutablePath >>= canonicalizePath
3737cp :: FilePath
3838cp = $(staticWhich "cp")
3939
40+ghcidExePath :: FilePath
41+ghcidExePath = $(staticWhich "ghcid")
42+
43+findExePath :: FilePath
44+findExePath = $(staticWhich "find")
45+
46+nixExePath :: FilePath
47+nixExePath = $(staticWhich "nix")
48+
49+nixBuildExePath :: FilePath
50+nixBuildExePath = $(staticWhich "nix-build")
51+
4052-- Check whether the working directory is clean
4153checkGitCleanStatus :: MonadObelisk m => FilePath -> Bool -> m Bool
4254checkGitCleanStatus repo withIgnored = do