summaryrefslogtreecommitdiff
path: root/Coolbal/Target/Class.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Coolbal/Target/Class.hs')
-rw-r--r--Coolbal/Target/Class.hs47
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