diff options
| author | Tom Smeding <tom@tomsmeding.com> | 2021-02-19 12:26:19 +0100 | 
|---|---|---|
| committer | Tom Smeding <tom@tomsmeding.com> | 2021-02-19 12:26:19 +0100 | 
| commit | 317f1e27688a082926f39ec897f5a38d01a07ce7 (patch) | |
| tree | 19417d35e7b2a606fb9a831e7ad505113ba7d696 | |
| parent | 08f53feceb1edb10f8b3a816021fb580b27e5b4c (diff) | |
Rebuild
| -rw-r--r-- | Coolbal/Options.hs | 3 | ||||
| -rw-r--r-- | Coolbal/Target.hs | 10 | ||||
| -rw-r--r-- | Main.hs | 9 | 
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 @@ -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  | 
