on master help sign in
Use cp from Nix instead of the system one
commit85f0babae55d0580b9759ccf30743a247eb804e3 authorAriel Nunez <ingenieroariel@gmail.com> dateTue 7 Jan 2020, 14:33 (7 years ago) parente02675e
5 files changed+21−8
lib/command/src/Obelisk/Command/Deploy.hs+2−1 lib/command/src/Obelisk/Command/Thunk.hs+3−3 lib/command/src/Obelisk/Command/Utils.hs+6−1 lib/selftest/obelisk-selftest.cabal+1 lib/selftest/src/Obelisk/SelfTest.hs+9−3
lib/command/src/Obelisk/Command/Deploy.hs+2−1
@@ -41,6 +41,7 @@ import Obelisk.Command.Project
4141import Obelisk.Command.Thunk
4242import Obelisk.Command.Utils
4343
44+
4445deployInit
4546 :: MonadObelisk m
4647 => ThunkPtr
@@ -57,7 +58,7 @@ deployInit thunkPtr deployDir sshKeyPath hostnames route adminEmail enableHttps
5758 False -> failWith $ T.pack $ "ob deploy init: file does not exist: " <> sshKeyPath
5859 True -> pure $ deployDir </> "ssh_key"
5960 callProcessAndLogOutput (Notice, Error) $
60− proc "cp" [sshKeyPath, localKey]
61+ proc cp [sshKeyPath, localKey]
6162 liftIO $ setFileMode localKey $ ownerReadMode .|. ownerWriteMode
6263 return localKey
6364 withSpinner "Validating configuration" $ do
lib/command/src/Obelisk/Command/Thunk.hs+3−3
@@ -635,13 +635,13 @@ updateThunk p f = withSystemTempDirectory "obelisk-thunkptr-" $ \tmpDir -> do
635635 Right (ThunkData_Packed _) -> do
636636 let tmpThunk = tmpDir </> "thunk"
637637 callProcessAndLogOutput (Notice, Error) $
638− proc "cp" ["-r", "-T", thunkDir, tmpThunk]
638+ proc cp ["-r", "-T", thunkDir, tmpThunk]
639639 return tmpThunk
640640 Right _ -> failWith "Thunk is not packed"
641641 updateThunkFromTmp p' = do
642642 _ <- packThunk' True (ThunkPackConfig False (ThunkConfig Nothing)) p'
643643 callProcessAndLogOutput (Notice, Error) $
644− proc "cp" ["-r", "-T", p', p]
644+ proc cp ["-r", "-T", p', p]
645645
646646finalMsg :: Bool -> (a -> Text) -> Maybe (a -> Text)
647647finalMsg noTrail s = if noTrail then Nothing else Just s
@@ -682,7 +682,7 @@ unpackThunk' noTrail thunkDir = checkThunkDirectory "Can't pack/unpack from with
682682
683683 liftIO $ createDirectory obGitDir
684684 callProcessAndLogOutput (Notice, Error) $
685− proc "cp" ["-r", "-T", thunkDir </> ".", obGitDir </> "orig-thunk"]
685+ proc cp ["-r", "-T", thunkDir </> ".", obGitDir </> "orig-thunk"]
686686 callProcessAndLogOutput (Notice, Error) $
687687 proc "rm" ["-r", thunkDir]
688688 callProcessAndLogOutput (Notice, Error) $
lib/command/src/Obelisk/Command/Utils.hs+6−1
@@ -4,6 +4,7 @@
44{-# LANGUAGE ScopedTypeVariables #-}
55{-# LANGUAGE OverloadedStrings #-}
66{-# LANGUAGE PatternGuards #-}
7+{-# LANGUAGE TemplateHaskell #-}
78module Obelisk.Command.Utils where
89
910import Control.Applicative hiding (many)
@@ -23,6 +24,7 @@ import Data.Void (Void)
2324import System.Directory (canonicalizePath)
2425import System.Environment (getExecutablePath)
2526import System.Exit (ExitCode)
27+import System.Which (staticWhich)
2628import Text.Megaparsec as MP
2729import Text.Megaparsec.Char as MP
2830
@@ -32,6 +34,9 @@ import Obelisk.CliApp
3234getObeliskExe :: IO FilePath
3335getObeliskExe = getExecutablePath >>= canonicalizePath
3436
37+cp :: FilePath
38+cp = $(staticWhich "cp")
39+
3540-- Check whether the working directory is clean
3641checkGitCleanStatus :: MonadObelisk m => FilePath -> Bool -> m Bool
3742checkGitCleanStatus repo withIgnored = do
@@ -83,7 +88,7 @@ isolateGitProc = setEnvOverride (overrides <>)
8388-- | Recursively copy a directory using `cp -a` -- TODO: Should use -rT instead of -a
8489copyDir :: FilePath -> FilePath -> ProcessSpec
8590copyDir src dest =
86− setCwd (Just src) $ proc "cp" ["-a", ".", dest] -- TODO: This will break if dest is relative since we change cwd
91+ setCwd (Just src) $ proc cp ["-a", ".", dest] -- TODO: This will break if dest is relative since we change cwd
8792
8893readGitProcess :: MonadObelisk m => FilePath -> [String] -> m Text
8994readGitProcess repo = readProcessAndLogOutput (Debug, Notice) . gitProc repo
lib/selftest/obelisk-selftest.cabal+1
@@ -20,6 +20,7 @@ library
2020 , obelisk-cliapp
2121 , obelisk-executable-config-lookup
2222 , obelisk-run
23+ , which
2324 , process
2425 , shelly >= 1.9.0
2526 , temporary
lib/selftest/src/Obelisk/SelfTest.hs+9−3
@@ -4,6 +4,7 @@
44{-# LANGUAGE PatternGuards #-}
55{-# LANGUAGE ScopedTypeVariables #-}
66{-# LANGUAGE ViewPatterns #-}
7+{-# LANGUAGE TemplateHaskell #-}
78module Obelisk.SelfTest where
89
910import Control.Exception (bracket, throw)
@@ -21,11 +22,12 @@ import qualified Data.Text.IO as T
2122import qualified Network.HTTP.Client as HTTP
2223import qualified Network.HTTP.Types as HTTP
2324import qualified Network.Socket as Socket
24−import Shelly
25+import Shelly hiding (cp)
2526import System.Directory (withCurrentDirectory, getDirectoryContents)
2627import System.Environment
2728import System.Exit (ExitCode (..))
2829import System.FilePath (replaceBaseName, takeBaseName)
30+import System.Which (staticWhich)
2931import qualified System.Info
3032import System.IO (Handle, hClose)
3133import System.IO.Temp
@@ -44,6 +46,9 @@ data ObRunState
4446 | ObRunState_BackendStarted
4547 deriving (Eq, Show)
4648
49+cp :: FilePath
50+cp = $(staticWhich "cp")
51+
4752doubleQuotes :: (IsString a, Semigroup a) => a -> a
4853doubleQuotes s = "\"" <> s <> "\""
4954
@@ -69,6 +74,7 @@ tshow = T.pack . show
6974shellyOb :: MonadIO m => (Sh a -> Sh a) -> Sh a -> m a
7075shellyOb f obTest = shelly $ f obTest
7176
77+
7278main :: IO ()
7379main = do
7480 -- Note: you can pass hspec arguments as well, eg: `-m <pattern>`
@@ -83,7 +89,7 @@ main = do
8389 withSystemTempDirectory "obelisk-impl-copy" $ \(fromString -> obeliskImpl) -> do
8490 void . shellyOb verbosity $ chdir obeliskImpl $ do
8591 user <- T.strip <$> run "whoami" []
86− run_ "cp" ["-rT", toTextIgnore obeliskImplRaw, toTextIgnore obeliskImpl]
92+ run_ cp ["-rT", toTextIgnore obeliskImplRaw, toTextIgnore obeliskImpl]
8793 run_ "chown" ["-R", user, toTextIgnore obeliskImpl]
8894 run_ "chmod" ["-R", "g-rw,o-rw", toTextIgnore obeliskImpl]
8995 f obeliskImpl
@@ -112,7 +118,7 @@ main = do
112118 withTmp f = shelly_ . withSystemTempDirectory "test λ" $ f . fromString
113119
114120 inTmpObInit f = inTmp $ \dir -> do
115− run_ "cp" ["-rT", fromString initCache, toTextIgnore dir]
121+ run_ cp ["-rT", fromString initCache, toTextIgnore dir]
116122 f dir
117123
118124 -- To be used in tests that change the obelisk impl directory