module Coolbal.Target.Class where import Coolbal.Options (Flags) class IsTarget a where -- | The name of the target. targetName :: a -> String -- | The cabal-style prefix indicating the kind of target (e.g. 'exe' for an executable target). targetPrefix :: a -> String -- | The name of the target, qualified with a cabal-style prefix indicating the kind of target. targetNameQualified :: a -> String targetNameQualified tg = buildQualifiedName (targetPrefix tg) (targetName tg) -- | The name of the target, qualified with a cabal-style prefix indicating -- the kind of target, except that the ':' is rendered as a '-'. targetNameQualifiedFilename :: a -> FilePath targetNameQualifiedFilename = qualifiedToQualifiedFilename . targetNameQualified -- | Check whether the target must be recompiled due to changes on disk. -- Argument is the root directory of the project. targetCheckOld :: FilePath -> a -> IO Bool -- | Recompile the target. targetBuild :: Flags -> a -> IO () -- | If the target is an executable target, return an IO action that runs -- the executable with the specified arguments. The 'FilePath' is the root -- directory of the project. targetExecute :: Flags -> a -> Maybe ([String] -> IO ()) -- | Remove the build artifacts for this target. targetRemoveBuildArtifacts :: FilePath -> a -> IO () data RestoreEnv = RestoreEnv { reProjDir :: FilePath } qualifiedToQualifiedFilename :: String -> FilePath qualifiedToQualifiedFilename qual = case break (== ':') qual of (pre, ':' : post) -> pre ++ '-' : post _ -> error "qualifiedToQualifiedFilename: unexpected form of targetNameQualified" buildQualifiedName :: String -> String -> String buildQualifiedName prefix name = prefix ++ ":" ++ name