From 317f1e27688a082926f39ec897f5a38d01a07ce7 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 19 Feb 2021 12:26:19 +0100 Subject: Rebuild --- Coolbal/Options.hs | 3 +++ Coolbal/Target.hs | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'Coolbal') 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 -- cgit v1.2.3-70-g09d2