diff options
| author | Tom Smeding <tom@tomsmeding.com> | 2021-07-11 17:56:34 +0200 | 
|---|---|---|
| committer | Tom Smeding <tom@tomsmeding.com> | 2021-07-11 17:56:34 +0200 | 
| commit | f57e800a1d1a8e9f2bed34428f7f58a375f178fb (patch) | |
| tree | 7164b0a9bcf03703a6a7f44f5fa04e5847d876e5 /Coolbal/Target/Class.hs | |
| parent | 317f1e27688a082926f39ec897f5a38d01a07ce7 (diff) | |
Diffstat (limited to 'Coolbal/Target/Class.hs')
| -rw-r--r-- | Coolbal/Target/Class.hs | 47 | 
1 files changed, 47 insertions, 0 deletions
| diff --git a/Coolbal/Target/Class.hs b/Coolbal/Target/Class.hs new file mode 100644 index 0000000..ea966d6 --- /dev/null +++ b/Coolbal/Target/Class.hs @@ -0,0 +1,47 @@ +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 | 
