summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Coolbal/Options.hs3
-rw-r--r--Coolbal/Target.hs10
-rw-r--r--Main.hs9
3 files changed, 21 insertions, 1 deletions
diff --git a/Coolbal/Options.hs b/Coolbal/Options.hs
index 8b1f807..7901386 100644
--- a/Coolbal/Options.hs
+++ b/Coolbal/Options.hs
@@ -10,6 +10,7 @@ import Options.Applicative
data Options
= Build BuildOptions
+ | Rebuild BuildOptions
| Clean
| Configure
| Run RunOptions
@@ -38,6 +39,8 @@ root =
hsubparser (
command "build" (info (Build <$> buildOptions)
(progDesc "Build the project"))
+ <> command "rebuild" (info (Rebuild <$> buildOptions)
+ (progDesc "Rebuild after deleting compilation artifacts for this project"))
<> command "run" (info (Run <$> runOptions)
(progDesc "Run an executable from the project"))
<> command "clean" (info (pure Clean)
diff --git a/Coolbal/Target.hs b/Coolbal/Target.hs
index 64a0a16..68ac043 100644
--- a/Coolbal/Target.hs
+++ b/Coolbal/Target.hs
@@ -14,7 +14,7 @@ import Data.List (intercalate)
import Data.Time.Clock (UTCTime)
import GHC.Generics (Generic)
import Numeric (showHex)
-import System.Directory (createDirectoryIfMissing, doesFileExist, getModificationTime)
+import System.Directory (createDirectoryIfMissing, doesFileExist, getModificationTime, removeDirectoryRecursive)
import System.Exit (ExitCode(..), die, exitWith)
import System.FilePath ((</>))
import System.IO.Error (catchIOError)
@@ -49,6 +49,9 @@ class IsTarget a where
-- directory of the project.
targetExecute :: a -> Maybe (FilePath -> [String] -> IO ())
+ -- | Remove the build artifacts for this target.
+ targetRemoveBuildArtifacts :: FilePath -> a -> IO ()
+
data AnyTarget = AnyTargetExe ExeTarget
deriving (Show, Generic)
@@ -118,6 +121,11 @@ instance IsTarget ExeTarget where
rawSystem (projdir </> "dist-coolbal/bin" </> filename) args
>>= exitWith
+ targetRemoveBuildArtifacts projdir tg =
+ removeDirectoryRecursive
+ (projdir </> "dist-coolbal/build"
+ </> escapeFileName (targetNameQualifiedFilename tg))
+
checkExitCode :: ExitCode -> IO ()
checkExitCode ExitSuccess = return ()
checkExitCode c@(ExitFailure _) = exitWith c
diff --git a/Main.hs b/Main.hs
index b696241..463a33b 100644
--- a/Main.hs
+++ b/Main.hs
@@ -88,6 +88,14 @@ doBuild (BuildOptions mtarget) = do
old <- targetCheckOld rootdir tg
when old $ targetBuild rootdir tg
+doRebuild :: BuildOptions -> IO ()
+doRebuild (BuildOptions mtarget) = do
+ (rootdir, targets, targetsForName) <- readCachedTargets (const True)
+ toBuild <- maybe (return targets) (targetsToBuild targetsForName) mtarget
+ forM_ toBuild $ useAnyTarget $ \tg -> do
+ targetRemoveBuildArtifacts rootdir tg
+ targetBuild rootdir tg
+
doRun :: RunOptions -> IO ()
doRun (RunOptions mtarget args) = do
(rootdir, targets, targetsForName) <- readCachedTargets (isJust . useAnyTarget targetExecute)
@@ -110,4 +118,5 @@ main = do
Configure -> doConfigure
Clean -> doClean
Build opts -> doBuild opts
+ Rebuild opts -> doRebuild opts
Run opts -> doRun opts