From 2d3e10b372eefb44f7a3a9738d45fb093449ee80 Mon Sep 17 00:00:00 2001 From: Luite Stegeman Date: Sat, 11 Feb 2012 04:26:26 +0100 Subject: [PATCH] Check cabal build exit code, don't try to start application if build failed --- yesod/Devel.hs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/yesod/Devel.hs b/yesod/Devel.hs index 984c8917..c8fcdced 100644 --- a/yesod/Devel.hs +++ b/yesod/Devel.hs @@ -24,7 +24,7 @@ import qualified Data.Map as Map import qualified Data.Set as Set import System.Directory -import System.Exit (exitFailure, exitSuccess) +import System.Exit (exitFailure, exitSuccess, ExitCode (..)) import System.FilePath (splitDirectories, dropExtension, takeExtension) import System.Posix.Types (EpochTime) import System.PosixCompat.Files (modificationTime, getFileStatus) @@ -87,25 +87,28 @@ mainLoop isCabalDev = do recompDeps list <- getFileList - _ <- if isCabalDev - then rawSystem "cabal-dev" ["build"] - else rawSystem "cabal" ["build"] + exit <- if isCabalDev + then rawSystem "cabal-dev" ["build"] + else rawSystem "cabal" ["build"] - removeLock - let pkg = pkgConfigs isCabalDev ghcVer - let start = concat ["runghc ", pkg, " devel.hs"] - putStrLn $ "Starting development server: " ++ start - ph <- runCommand start - watchTid <- forkIO . try_ $ do + case exit of + ExitFailure _ -> putStrLn "Build failure, pausing..." + _ -> do + removeLock + let pkg = pkgConfigs isCabalDev ghcVer + let start = concat ["runghc ", pkg, " devel.hs"] + putStrLn $ "Starting development server: " ++ start + ph <- runCommand start + watchTid <- forkIO . try_ $ do watchForChanges list putStrLn "Stopping development server..." writeLock threadDelay 1000000 putStrLn "Terminating development server..." terminateProcess ph - ec <- waitForProcess ph - putStrLn $ "Exit code: " ++ show ec - Ex.throwTo watchTid (userError "process finished") + ec <- waitForProcess ph + putStrLn $ "Exit code: " ++ show ec + Ex.throwTo watchTid (userError "process finished") watchForChanges list try_ :: forall a. IO a -> IO () @@ -157,16 +160,12 @@ checkCabalFile gpd = case D.condLibrary gpd of putStrLn $ "WARNING: yesod devel may not work correctly with " ++ "custom hs-source-dirs" fl <- getFileList - print (allModules dLib) let unlisted = checkFileList fl dLib - print fl when (not . null $ unlisted) $ do putStrLn "WARNING: the following source files are not listed in exposed-modules or other-modules:" mapM_ putStrLn unlisted when (D.fromString "Application" `notElem` D.exposedModules dLib) $ do putStrLn "WARNING: no exposed module Application" - print (D.exposedModules dLib) - print dLib failWith :: String -> IO a failWith msg = do