{-# 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
(BuildMode -> BuildMode -> Bool)
-> (BuildMode -> BuildMode -> Bool) -> Eq BuildMode
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
Eq BuildMode
-> (BuildMode -> BuildMode -> Ordering)
-> (BuildMode -> BuildMode -> Bool)
-> (BuildMode -> BuildMode -> Bool)
-> (BuildMode -> BuildMode -> Bool)
-> (BuildMode -> BuildMode -> Bool)
-> (BuildMode -> BuildMode -> BuildMode)
-> (BuildMode -> BuildMode -> BuildMode)
-> Ord 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
$cp1Ord :: Eq BuildMode
Ord, Int -> BuildMode
BuildMode -> Int
BuildMode -> [BuildMode]
BuildMode -> BuildMode
BuildMode -> BuildMode -> [BuildMode]
BuildMode -> BuildMode -> BuildMode -> [BuildMode]
(BuildMode -> BuildMode)
-> (BuildMode -> BuildMode)
-> (Int -> BuildMode)
-> (BuildMode -> Int)
-> (BuildMode -> [BuildMode])
-> (BuildMode -> BuildMode -> [BuildMode])
-> (BuildMode -> BuildMode -> [BuildMode])
-> (BuildMode -> BuildMode -> BuildMode -> [BuildMode])
-> Enum 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 -> String
(Int -> BuildMode -> ShowS)
-> (BuildMode -> String)
-> ([BuildMode] -> ShowS)
-> Show BuildMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BuildMode] -> ShowS
$cshowList :: [BuildMode] -> ShowS
show :: BuildMode -> String
$cshow :: BuildMode -> String
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
(BuildStatus -> BuildStatus -> Bool)
-> (BuildStatus -> BuildStatus -> Bool) -> Eq BuildStatus
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
Eq BuildStatus
-> (BuildStatus -> BuildStatus -> Ordering)
-> (BuildStatus -> BuildStatus -> Bool)
-> (BuildStatus -> BuildStatus -> Bool)
-> (BuildStatus -> BuildStatus -> Bool)
-> (BuildStatus -> BuildStatus -> Bool)
-> (BuildStatus -> BuildStatus -> BuildStatus)
-> (BuildStatus -> BuildStatus -> BuildStatus)
-> Ord 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
$cp1Ord :: Eq BuildStatus
Ord, Int -> BuildStatus
BuildStatus -> Int
BuildStatus -> [BuildStatus]
BuildStatus -> BuildStatus
BuildStatus -> BuildStatus -> [BuildStatus]
BuildStatus -> BuildStatus -> BuildStatus -> [BuildStatus]
(BuildStatus -> BuildStatus)
-> (BuildStatus -> BuildStatus)
-> (Int -> BuildStatus)
-> (BuildStatus -> Int)
-> (BuildStatus -> [BuildStatus])
-> (BuildStatus -> BuildStatus -> [BuildStatus])
-> (BuildStatus -> BuildStatus -> [BuildStatus])
-> (BuildStatus -> BuildStatus -> BuildStatus -> [BuildStatus])
-> Enum 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 -> String
(Int -> BuildStatus -> ShowS)
-> (BuildStatus -> String)
-> ([BuildStatus] -> ShowS)
-> Show BuildStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BuildStatus] -> ShowS
$cshowList :: [BuildStatus] -> ShowS
show :: BuildStatus -> String
$cshow :: BuildStatus -> String
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
(BuildResult -> BuildResult -> Bool)
-> (BuildResult -> BuildResult -> Bool) -> Eq BuildResult
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
Eq BuildResult
-> (BuildResult -> BuildResult -> Ordering)
-> (BuildResult -> BuildResult -> Bool)
-> (BuildResult -> BuildResult -> Bool)
-> (BuildResult -> BuildResult -> Bool)
-> (BuildResult -> BuildResult -> Bool)
-> (BuildResult -> BuildResult -> BuildResult)
-> (BuildResult -> BuildResult -> BuildResult)
-> Ord 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
$cp1Ord :: Eq BuildResult
Ord, Int -> BuildResult -> ShowS
[BuildResult] -> ShowS
BuildResult -> String
(Int -> BuildResult -> ShowS)
-> (BuildResult -> String)
-> ([BuildResult] -> ShowS)
-> Show BuildResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BuildResult] -> ShowS
$cshowList :: [BuildResult] -> ShowS
show :: BuildResult -> String
$cshow :: BuildResult -> String
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 BuildStatus -> [BuildStatus] -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` [BuildStatus
Built, BuildStatus
Substituted, BuildStatus
AlreadyValid]