From ccb9d00191a66ce572c17841eb38b7bb393053db Mon Sep 17 00:00:00 2001 From: hirschen Date: Tue, 17 Apr 2012 10:40:04 +0200 Subject: [PATCH 1/3] Add success- and failhook options to cmdline --- yesod/Devel.hs | 10 ++++++---- yesod/Types.hs | 16 ++++++++++++++++ yesod/main.hs | 12 ++++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/yesod/Devel.hs b/yesod/Devel.hs index cc8e1630..1771f00f 100644 --- a/yesod/Devel.hs +++ b/yesod/Devel.hs @@ -63,16 +63,18 @@ removeLock :: IO () removeLock = removeFileIfExists lockFile data DevelOpts = DevelOpts - { isCabalDev :: Bool - , forceCabal :: Bool - , verbose :: Bool + { isCabalDev :: Bool + , forceCabal :: Bool + , verbose :: Bool + , successHook :: Maybe String + , failHook :: Maybe String } deriving (Show, Eq) cabalCommand :: DevelOpts -> FilePath cabalCommand opts | isCabalDev opts = "cabal-dev" | otherwise = "cabal" -defaultDevelOpts = DevelOpts False False False +defaultDevelOpts = DevelOpts False False False Nothing Nothing devel :: DevelOpts -> [String] -> IO () devel opts passThroughArgs = do diff --git a/yesod/Types.hs b/yesod/Types.hs index c0c45bc3..9c066457 100644 --- a/yesod/Types.hs +++ b/yesod/Types.hs @@ -28,6 +28,22 @@ mkOptApi name = option name (\o -> o , optionDescription = "use the GHC API to build (faster, but experimental)" }) +mkOptSuccessHook name = option name (\o -> o + { optionLongFlags = ["success-hook"] + , optionShortFlags = ['s'] + , optionType = optionTypeMaybe optionTypeString + , optionDefault = "" + , optionDescription = "Command to run when compilation succeeds (e.g. 'beep')" + }) + +mkOptFailHook name = option name (\o -> o + { optionLongFlags = ["fail-hook"] + , optionShortFlags = ['f'] + , optionType = optionTypeMaybe optionTypeString + , optionDefault = "" + , optionDescription = "Command to run when compilation fails (e.g. 'beep')" + }) + mkOptVerbose name = option name (\o -> o { optionLongFlags = ["verbose"] , optionShortFlags = ['v'] diff --git a/yesod/main.hs b/yesod/main.hs index 33a4926b..611e4cfb 100755 --- a/yesod/main.hs +++ b/yesod/main.hs @@ -20,10 +20,12 @@ defineOptions "NoOptions" (return ()) defineOptions "DevelOptions" $ do mkOptApi "develOptApi" -- mkOptNoApi "develOptNoApi" -- use this later when flag is enabled by default + mkOptSuccessHook "optSuccessHook" + mkOptFailHook "optFailHook" defineOptions "MainOptions" $ do - mkOptCabalDev "optCabalDev" - mkOptVerbose "optVerbose" + mkOptCabalDev "optCabalDev" + mkOptVerbose "optVerbose" type InitOptions = NoOptions type ConfigureOptions = NoOptions @@ -65,8 +67,10 @@ cmdTouch _ _ _ = touch cmdDevel :: MainOptions -> DevelOptions -> [String] -> IO () cmdDevel mopt opts args = devel dopts args where - dopts = DevelOpts (optCabalDev mopt) forceCabal (optVerbose mopt) - forceCabal = not (develOptApi opts) + dopts = DevelOpts (optCabalDev mopt) forceCabal (optVerbose mopt) successHook failHook + successHook = optSuccessHook opts + failHook = optFailHook opts + forceCabal = not (develOptApi opts) -- forceCabal = develOptNoApi opts cmdVersion :: MainOptions -> VersionOptions -> [String] -> IO () From 204c8cc74475461b7262cb9cbfec197b6607c790 Mon Sep 17 00:00:00 2001 From: hirschen Date: Tue, 17 Apr 2012 14:16:32 +0200 Subject: [PATCH 2/3] Run the buildhook with 'system' --- yesod/Devel.hs | 19 ++++++++++++++++--- yesod/Types.hs | 4 ++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/yesod/Devel.hs b/yesod/Devel.hs index 1771f00f..d9c4cd6f 100644 --- a/yesod/Devel.hs +++ b/yesod/Devel.hs @@ -41,7 +41,8 @@ import System.FilePath (splitDirectories, dropExtension, takeExtension import System.Posix.Types (EpochTime) import System.PosixCompat.Files (modificationTime, getFileStatus) import System.Process (createProcess, proc, terminateProcess, readProcess, ProcessHandle, - getProcessExitCode,waitForProcess, rawSystem, runInteractiveProcess) + getProcessExitCode,waitForProcess, rawSystem, + runInteractiveProcess, system) import System.IO (hClose, hIsEOF, hGetLine, stdout, stderr, hPutStrLn) import System.IO.Error (isDoesNotExistError) @@ -111,8 +112,11 @@ devel opts passThroughArgs = do pkgArgs <- ghcPackageArgs opts ghcVer (D.packageDescription gpd) lib let devArgs = pkgArgs ++ ["devel.hs"] ++ passThroughArgs if not success - then putStrLn "Build failure, pausing..." + then do + putStrLn "Build failure, pausing..." + runBuildHook $ failHook opts else do + runBuildHook $ successHook opts removeLock putStrLn $ if verbose opts then "Starting development server: runghc " ++ L.unwords devArgs else "Starting development server..." @@ -125,10 +129,19 @@ devel opts passThroughArgs = do putStrLn "Terminating development server..." terminateProcess ph ec <- waitForProcess' ph - putStrLn $ "Exit code: " ++ show ec Ex.throwTo watchTid (userError "process finished") watchForChanges hsSourceDirs [cabal] list +runBuildHook :: Maybe String -> IO () +runBuildHook m = case m of + Just s -> do + ret <- system s + case ret of + ExitFailure f -> putStrLn $ "Error executing hook: " ++ s + otherwise -> return () + Nothing -> return () + + {- configure with the built-in Cabal lib for non-cabal-dev, since diff --git a/yesod/Types.hs b/yesod/Types.hs index 9c066457..c1d43cd8 100644 --- a/yesod/Types.hs +++ b/yesod/Types.hs @@ -33,7 +33,7 @@ mkOptSuccessHook name = option name (\o -> o , optionShortFlags = ['s'] , optionType = optionTypeMaybe optionTypeString , optionDefault = "" - , optionDescription = "Command to run when compilation succeeds (e.g. 'beep')" + , optionDescription = "Shell command to run when compilation succeeds (e.g. 'beep')" }) mkOptFailHook name = option name (\o -> o @@ -41,7 +41,7 @@ mkOptFailHook name = option name (\o -> o , optionShortFlags = ['f'] , optionType = optionTypeMaybe optionTypeString , optionDefault = "" - , optionDescription = "Command to run when compilation fails (e.g. 'beep')" + , optionDescription = "Shell command to run when compilation fails (e.g. 'beep')" }) mkOptVerbose name = option name (\o -> o From 101ef2497c949720853273224ef1d59f51278ac4 Mon Sep 17 00:00:00 2001 From: hirschen Date: Wed, 18 Apr 2012 08:59:35 +0200 Subject: [PATCH 3/3] Code cleanup and output exit status of build. --- yesod/Devel.hs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/yesod/Devel.hs b/yesod/Devel.hs index d9c4cd6f..58372c89 100644 --- a/yesod/Devel.hs +++ b/yesod/Devel.hs @@ -129,19 +129,17 @@ devel opts passThroughArgs = do putStrLn "Terminating development server..." terminateProcess ph ec <- waitForProcess' ph + putStrLn $ "Exit code: " ++ show ec Ex.throwTo watchTid (userError "process finished") watchForChanges hsSourceDirs [cabal] list runBuildHook :: Maybe String -> IO () -runBuildHook m = case m of - Just s -> do - ret <- system s - case ret of - ExitFailure f -> putStrLn $ "Error executing hook: " ++ s - otherwise -> return () - Nothing -> return () - - +runBuildHook (Just s) = do + ret <- system s + case ret of + ExitFailure f -> putStrLn $ "Error executing hook: " ++ s + otherwise -> return () +runBuildHook Nothing = return () {- configure with the built-in Cabal lib for non-cabal-dev, since