Target.hs 1.76 KB
Newer Older
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 48 49 50 51 52 53 54 55 56 57
{-# LANGUAGE DeriveGeneric #-}
module Target (
    Target (..), stageTarget, stagePackageTarget
    ) where

import Base
import Ways
import Oracles
import Package
import GHC.Generics
import Development.Shake.Classes

-- Target captures parameters relevant to the current build target: Stage and
-- Package being built, Builder that is to be invoked, file(s) that are to
-- be built and the Way they are to be built.
data Target = Target
     {
        getStage   :: Stage,
        getPackage :: Package,
        getBuilder :: Builder,
        getFile    :: FilePath, -- TODO: handle multple files?
        getWay     :: Way
     }
     deriving (Eq, Generic)

-- Shows a target as "package:file@stage (builder, way)"
instance Show Target where
    show target = show (getPackage target)
                  ++ ":" ++ show (getFile target)
                  ++ "@" ++ show (getStage target)
                  ++ " (" ++ show (getBuilder target)
                  ++ ", " ++ show (getWay target) ++ ")"

stageTarget :: Stage -> Target
stageTarget stage = Target
    {
        getStage   = stage,
        getPackage = error "stageTarget: Package not set",
        getBuilder = error "stageTarget: Builder not set",
        getFile    = error "stageTarget: File not set",
        getWay     = error "stageTarget: Way not set"
    }

stagePackageTarget :: Stage -> Package -> Target
stagePackageTarget stage package = Target
    {
        getStage   = stage,
        getPackage = package,
        getBuilder = error "stagePackageTarget: Builder not set",
        getFile    = error "stagePackageTarget: File not set",
        getWay     = error "stagePackageTarget: Way not set"
    }

-- Instances for storing Target in the Shake database
instance Binary Target
instance NFData Target
instance Hashable Target