{-# language RecordWildCards #-}
{-|
Description : Build related types
Maintainer  : srk <srk@48.io>
|-}
module System.Nix.Build
  ( BuildMode(..)
  , BuildStatus(..)
  , BuildResult(..)
  , buildSuccess
  )
where

import           Data.Time                      ( UTCTime )

-- keep the order of these Enums to match enums from reference implementations
-- src/libstore/store-api.hh
data BuildMode = Normal | Repair | Check
  deriving (BuildMode -> BuildMode -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BuildMode -> BuildMode -> Bool
$c/= :: BuildMode -> BuildMode -> Bool
== :: BuildMode -> BuildMode -> Bool
$c== :: BuildMode -> BuildMode -> Bool
Eq, Eq BuildMode
BuildMode -> BuildMode -> Bool
BuildMode -> BuildMode -> Ordering
BuildMode -> BuildMode -> BuildMode
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: BuildMode -> BuildMode -> BuildMode
$cmin :: BuildMode -> BuildMode -> BuildMode
max :: BuildMode -> BuildMode -> BuildMode
$cmax :: BuildMode -> BuildMode -> BuildMode
>= :: BuildMode -> BuildMode -> Bool
$c>= :: BuildMode -> BuildMode -> Bool
> :: BuildMode -> BuildMode -> Bool
$c> :: BuildMode -> BuildMode -> Bool
<= :: BuildMode -> BuildMode -> Bool
$c<= :: BuildMode -> BuildMode -> Bool
< :: BuildMode -> BuildMode -> Bool
$c< :: BuildMode -> BuildMode -> Bool
compare :: BuildMode -> BuildMode -> Ordering
$ccompare :: BuildMode -> BuildMode -> Ordering
Ord, Int -> BuildMode
BuildMode -> Int
BuildMode -> [BuildMode]
BuildMode -> BuildMode
BuildMode -> BuildMode -> [BuildMode]
BuildMode -> BuildMode -> BuildMode -> [BuildMode]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: BuildMode -> BuildMode -> BuildMode -> [BuildMode]
$cenumFromThenTo :: BuildMode -> BuildMode -> BuildMode -> [BuildMode]
enumFromTo :: BuildMode -> BuildMode -> [BuildMode]
$cenumFromTo :: BuildMode -> BuildMode -> [BuildMode]
enumFromThen :: BuildMode -> BuildMode -> [BuildMode]
$cenumFromThen :: BuildMode -> BuildMode -> [BuildMode]
enumFrom :: BuildMode -> [BuildMode]
$cenumFrom :: BuildMode -> [BuildMode]
fromEnum :: BuildMode -> Int
$cfromEnum :: BuildMode -> Int
toEnum :: Int -> BuildMode
$ctoEnum :: Int -> BuildMode
pred :: BuildMode -> BuildMode
$cpred :: BuildMode -> BuildMode
succ :: BuildMode -> BuildMode
$csucc :: BuildMode -> BuildMode
Enum, Int -> BuildMode -> ShowS
[BuildMode] -> ShowS
BuildMode -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [BuildMode] -> ShowS
$cshowList :: [BuildMode] -> ShowS
show :: BuildMode -> [Char]
$cshow :: BuildMode -> [Char]
showsPrec :: Int -> BuildMode -> ShowS
$cshowsPrec :: Int -> BuildMode -> ShowS
Show)

data BuildStatus =
    Built
  | Substituted
  | AlreadyValid
  | PermanentFailure
  | InputRejected
  | OutputRejected
  | TransientFailure -- possibly transient
  | CachedFailure    -- no longer used
  | TimedOut
  | MiscFailure
  | DependencyFailed
  | LogLimitExceeded
  | NotDeterministic
  deriving (BuildStatus -> BuildStatus -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BuildStatus -> BuildStatus -> Bool
$c/= :: BuildStatus -> BuildStatus -> Bool
== :: BuildStatus -> BuildStatus -> Bool
$c== :: BuildStatus -> BuildStatus -> Bool
Eq, Eq BuildStatus
BuildStatus -> BuildStatus -> Bool
BuildStatus -> BuildStatus -> Ordering
BuildStatus -> BuildStatus -> BuildStatus
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: BuildStatus -> BuildStatus -> BuildStatus
$cmin :: BuildStatus -> BuildStatus -> BuildStatus
max :: BuildStatus -> BuildStatus -> BuildStatus
$cmax :: BuildStatus -> BuildStatus -> BuildStatus
>= :: BuildStatus -> BuildStatus -> Bool
$c>= :: BuildStatus -> BuildStatus -> Bool
> :: BuildStatus -> BuildStatus -> Bool
$c> :: BuildStatus -> BuildStatus -> Bool
<= :: BuildStatus -> BuildStatus -> Bool
$c<= :: BuildStatus -> BuildStatus -> Bool
< :: BuildStatus -> BuildStatus -> Bool
$c< :: BuildStatus -> BuildStatus -> Bool
compare :: BuildStatus -> BuildStatus -> Ordering
$ccompare :: BuildStatus -> BuildStatus -> Ordering
Ord, Int -> BuildStatus
BuildStatus -> Int
BuildStatus -> [BuildStatus]
BuildStatus -> BuildStatus
BuildStatus -> BuildStatus -> [BuildStatus]
BuildStatus -> BuildStatus -> BuildStatus -> [BuildStatus]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: BuildStatus -> BuildStatus -> BuildStatus -> [BuildStatus]
$cenumFromThenTo :: BuildStatus -> BuildStatus -> BuildStatus -> [BuildStatus]
enumFromTo :: BuildStatus -> BuildStatus -> [BuildStatus]
$cenumFromTo :: BuildStatus -> BuildStatus -> [BuildStatus]
enumFromThen :: BuildStatus -> BuildStatus -> [BuildStatus]
$cenumFromThen :: BuildStatus -> BuildStatus -> [BuildStatus]
enumFrom :: BuildStatus -> [BuildStatus]
$cenumFrom :: BuildStatus -> [BuildStatus]
fromEnum :: BuildStatus -> Int
$cfromEnum :: BuildStatus -> Int
toEnum :: Int -> BuildStatus
$ctoEnum :: Int -> BuildStatus
pred :: BuildStatus -> BuildStatus
$cpred :: BuildStatus -> BuildStatus
succ :: BuildStatus -> BuildStatus
$csucc :: BuildStatus -> BuildStatus
Enum, Int -> BuildStatus -> ShowS
[BuildStatus] -> ShowS
BuildStatus -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [BuildStatus] -> ShowS
$cshowList :: [BuildStatus] -> ShowS
show :: BuildStatus -> [Char]
$cshow :: BuildStatus -> [Char]
showsPrec :: Int -> BuildStatus -> ShowS
$cshowsPrec :: Int -> BuildStatus -> ShowS
Show)


-- | Result of the build
data BuildResult = BuildResult
  { -- | build status, MiscFailure should be default
    BuildResult -> BuildStatus
status             :: !BuildStatus
  , -- | possible build error message
    BuildResult -> Maybe Text
errorMessage       :: !(Maybe Text)
  , -- | How many times this build was performed
    BuildResult -> Integer
timesBuilt         :: !Integer
  , -- | If timesBuilt > 1, whether some builds did not produce the same result
    BuildResult -> Bool
isNonDeterministic :: !Bool
  ,  -- Start time of this build
    BuildResult -> UTCTime
startTime          :: !UTCTime
  ,  -- Stop time of this build
    BuildResult -> UTCTime
stopTime           :: !UTCTime
  }
  deriving (BuildResult -> BuildResult -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BuildResult -> BuildResult -> Bool
$c/= :: BuildResult -> BuildResult -> Bool
== :: BuildResult -> BuildResult -> Bool
$c== :: BuildResult -> BuildResult -> Bool
Eq, Eq BuildResult
BuildResult -> BuildResult -> Bool
BuildResult -> BuildResult -> Ordering
BuildResult -> BuildResult -> BuildResult
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: BuildResult -> BuildResult -> BuildResult
$cmin :: BuildResult -> BuildResult -> BuildResult
max :: BuildResult -> BuildResult -> BuildResult
$cmax :: BuildResult -> BuildResult -> BuildResult
>= :: BuildResult -> BuildResult -> Bool
$c>= :: BuildResult -> BuildResult -> Bool
> :: BuildResult -> BuildResult -> Bool
$c> :: BuildResult -> BuildResult -> Bool
<= :: BuildResult -> BuildResult -> Bool
$c<= :: BuildResult -> BuildResult -> Bool
< :: BuildResult -> BuildResult -> Bool
$c< :: BuildResult -> BuildResult -> Bool
compare :: BuildResult -> BuildResult -> Ordering
$ccompare :: BuildResult -> BuildResult -> Ordering
Ord, Int -> BuildResult -> ShowS
[BuildResult] -> ShowS
BuildResult -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [BuildResult] -> ShowS
$cshowList :: [BuildResult] -> ShowS
show :: BuildResult -> [Char]
$cshow :: BuildResult -> [Char]
showsPrec :: Int -> BuildResult -> ShowS
$cshowsPrec :: Int -> BuildResult -> ShowS
Show)

buildSuccess :: BuildResult -> Bool
buildSuccess :: BuildResult -> Bool
buildSuccess BuildResult {Bool
Integer
Maybe Text
UTCTime
BuildStatus
stopTime :: UTCTime
startTime :: UTCTime
isNonDeterministic :: Bool
timesBuilt :: Integer
errorMessage :: Maybe Text
status :: BuildStatus
stopTime :: BuildResult -> UTCTime
startTime :: BuildResult -> UTCTime
isNonDeterministic :: BuildResult -> Bool
timesBuilt :: BuildResult -> Integer
errorMessage :: BuildResult -> Maybe Text
status :: BuildResult -> BuildStatus
..} =
  BuildStatus
status forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` [BuildStatus
Built, BuildStatus
Substituted, BuildStatus
AlreadyValid]