summaryrefslogtreecommitdiff
path: root/Coolbal/Target/Class.hs
blob: ea966d6ba7c67af91bc17982a74f7d6027d91e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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