{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}

-- | Copyright: (c) 2021-2022 berberman
-- SPDX-License-Identifier: MIT
-- Maintainer: berberman <berberman@yandex.com>
-- Stability: experimental
-- Portability: portable
--
-- This module is about global information we use in rules.
module NvFetcher.Types.ShakeExtras
  ( -- * Types
    ShakeExtras (..),
    initShakeExtras,
    getShakeExtras,

    -- * Packages
    lookupPackage,
    getAllPackageKeys,
    isPackageKeyTarget,

    -- * Version changes
    recordVersionChange,
    getVersionChanges,

    -- * Retry
    withRetry,

    -- * Build dir
    getBuildDir,

    -- * Last versions
    getLastVersionOnDisk,
    getRecentLastVersion,
    updateLastVersion,
    getAllOnDiskVersions,
    getLastVersionUpdated,

    -- * Cache nvchecker
    nvcheckerCacheEnabled,
  )
where

import Control.Concurrent.Extra
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Development.Shake
import NvFetcher.Config
import NvFetcher.Types

data LastVersion
  = OnDisk Version
  | Updated
      (Maybe Version)
      -- ^ on disk if has
      Version

-- | Values we use during the build. It's stored in 'shakeExtra'
data ShakeExtras = ShakeExtras
  { ShakeExtras -> Config
config :: Config,
    ShakeExtras -> Var [VersionChange]
versionChanges :: Var [VersionChange],
    ShakeExtras -> Map PackageKey Package
targetPackages :: Map PackageKey Package,
    ShakeExtras -> Var (Map PackageKey LastVersion)
lastVersions :: Var (Map PackageKey LastVersion)
  }

-- | Get our values from shake
getShakeExtras :: Action ShakeExtras
getShakeExtras :: Action ShakeExtras
getShakeExtras =
  Typeable ShakeExtras => Action (Maybe ShakeExtras)
forall a. Typeable a => Action (Maybe a)
getShakeExtra @ShakeExtras Action (Maybe ShakeExtras)
-> (Maybe ShakeExtras -> Action ShakeExtras) -> Action ShakeExtras
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    Just ShakeExtras
x -> ShakeExtras -> Action ShakeExtras
forall (f :: * -> *) a. Applicative f => a -> f a
pure ShakeExtras
x
    Maybe ShakeExtras
_ -> String -> Action ShakeExtras
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"ShakeExtras is missing!"

-- | Create an empty 'ShakeExtras' from packages to build, times to retry for each rule,
-- build dir, and on disk versions
initShakeExtras :: Config -> Map PackageKey Package -> Map PackageKey Version -> IO ShakeExtras
initShakeExtras :: Config
-> Map PackageKey Package
-> Map PackageKey Version
-> IO ShakeExtras
initShakeExtras Config
config Map PackageKey Package
targetPackages Map PackageKey Version
lv = do
  Var [VersionChange]
versionChanges <- [VersionChange] -> IO (Var [VersionChange])
forall a. a -> IO (Var a)
newVar [VersionChange]
forall a. Monoid a => a
mempty
  Var (Map PackageKey LastVersion)
lastVersions <- Map PackageKey LastVersion -> IO (Var (Map PackageKey LastVersion))
forall a. a -> IO (Var a)
newVar (Map PackageKey LastVersion
 -> IO (Var (Map PackageKey LastVersion)))
-> Map PackageKey LastVersion
-> IO (Var (Map PackageKey LastVersion))
forall a b. (a -> b) -> a -> b
$ (Version -> LastVersion)
-> Map PackageKey Version -> Map PackageKey LastVersion
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map Version -> LastVersion
OnDisk Map PackageKey Version
lv
  ShakeExtras -> IO ShakeExtras
forall (f :: * -> *) a. Applicative f => a -> f a
pure ShakeExtras :: Config
-> Var [VersionChange]
-> Map PackageKey Package
-> Var (Map PackageKey LastVersion)
-> ShakeExtras
ShakeExtras {Map PackageKey Package
Var [VersionChange]
Var (Map PackageKey LastVersion)
Config
lastVersions :: Var (Map PackageKey LastVersion)
versionChanges :: Var [VersionChange]
targetPackages :: Map PackageKey Package
config :: Config
lastVersions :: Var (Map PackageKey LastVersion)
targetPackages :: Map PackageKey Package
versionChanges :: Var [VersionChange]
config :: Config
..}

-- | Get keys of all packages to build
getAllPackageKeys :: Action [PackageKey]
getAllPackageKeys :: Action [PackageKey]
getAllPackageKeys = do
  ShakeExtras {Map PackageKey Package
Var [VersionChange]
Var (Map PackageKey LastVersion)
Config
lastVersions :: Var (Map PackageKey LastVersion)
targetPackages :: Map PackageKey Package
versionChanges :: Var [VersionChange]
config :: Config
lastVersions :: ShakeExtras -> Var (Map PackageKey LastVersion)
targetPackages :: ShakeExtras -> Map PackageKey Package
versionChanges :: ShakeExtras -> Var [VersionChange]
config :: ShakeExtras -> Config
..} <- Action ShakeExtras
getShakeExtras
  [PackageKey] -> Action [PackageKey]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([PackageKey] -> Action [PackageKey])
-> [PackageKey] -> Action [PackageKey]
forall a b. (a -> b) -> a -> b
$ Map PackageKey Package -> [PackageKey]
forall k a. Map k a -> [k]
Map.keys Map PackageKey Package
targetPackages

-- | Find a package given its key
lookupPackage :: PackageKey -> Action (Maybe Package)
lookupPackage :: PackageKey -> Action (Maybe Package)
lookupPackage PackageKey
key = do
  ShakeExtras {Map PackageKey Package
Var [VersionChange]
Var (Map PackageKey LastVersion)
Config
lastVersions :: Var (Map PackageKey LastVersion)
targetPackages :: Map PackageKey Package
versionChanges :: Var [VersionChange]
config :: Config
lastVersions :: ShakeExtras -> Var (Map PackageKey LastVersion)
targetPackages :: ShakeExtras -> Map PackageKey Package
versionChanges :: ShakeExtras -> Var [VersionChange]
config :: ShakeExtras -> Config
..} <- Action ShakeExtras
getShakeExtras
  Maybe Package -> Action (Maybe Package)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Package -> Action (Maybe Package))
-> Maybe Package -> Action (Maybe Package)
forall a b. (a -> b) -> a -> b
$ PackageKey -> Map PackageKey Package -> Maybe Package
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup PackageKey
key Map PackageKey Package
targetPackages

-- | Check if we need build this package
isPackageKeyTarget :: PackageKey -> Action Bool
isPackageKeyTarget :: PackageKey -> Action Bool
isPackageKeyTarget PackageKey
k = PackageKey -> Map PackageKey Package -> Bool
forall k a. Ord k => k -> Map k a -> Bool
Map.member PackageKey
k (Map PackageKey Package -> Bool)
-> (ShakeExtras -> Map PackageKey Package) -> ShakeExtras -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShakeExtras -> Map PackageKey Package
targetPackages (ShakeExtras -> Bool) -> Action ShakeExtras -> Action Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Action ShakeExtras
getShakeExtras

-- | Record version change of a package
recordVersionChange :: PackageName -> Maybe Version -> Version -> Action ()
recordVersionChange :: PackageName -> Maybe Version -> Version -> Action ()
recordVersionChange PackageName
vcName Maybe Version
vcOld Version
vcNew = do
  ShakeExtras {Map PackageKey Package
Var [VersionChange]
Var (Map PackageKey LastVersion)
Config
lastVersions :: Var (Map PackageKey LastVersion)
targetPackages :: Map PackageKey Package
versionChanges :: Var [VersionChange]
config :: Config
lastVersions :: ShakeExtras -> Var (Map PackageKey LastVersion)
targetPackages :: ShakeExtras -> Map PackageKey Package
versionChanges :: ShakeExtras -> Var [VersionChange]
config :: ShakeExtras -> Config
..} <- Action ShakeExtras
getShakeExtras
  IO () -> Action ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Action ()) -> IO () -> Action ()
forall a b. (a -> b) -> a -> b
$ Var [VersionChange]
-> ([VersionChange] -> IO [VersionChange]) -> IO ()
forall a. Var a -> (a -> IO a) -> IO ()
modifyVar_ Var [VersionChange]
versionChanges ([VersionChange] -> IO [VersionChange]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([VersionChange] -> IO [VersionChange])
-> ([VersionChange] -> [VersionChange])
-> [VersionChange]
-> IO [VersionChange]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([VersionChange] -> [VersionChange] -> [VersionChange]
forall a. [a] -> [a] -> [a]
++ [VersionChange :: PackageName -> Maybe Version -> Version -> VersionChange
VersionChange {Maybe Version
PackageName
Version
vcNew :: Version
vcOld :: Maybe Version
vcName :: PackageName
vcNew :: Version
vcOld :: Maybe Version
vcName :: PackageName
..}]))

-- | Get version changes since the last run
getVersionChanges :: Action [VersionChange]
getVersionChanges :: Action [VersionChange]
getVersionChanges = do
  ShakeExtras {Map PackageKey Package
Var [VersionChange]
Var (Map PackageKey LastVersion)
Config
lastVersions :: Var (Map PackageKey LastVersion)
targetPackages :: Map PackageKey Package
versionChanges :: Var [VersionChange]
config :: Config
lastVersions :: ShakeExtras -> Var (Map PackageKey LastVersion)
targetPackages :: ShakeExtras -> Map PackageKey Package
versionChanges :: ShakeExtras -> Var [VersionChange]
config :: ShakeExtras -> Config
..} <- Action ShakeExtras
getShakeExtras
  IO [VersionChange] -> Action [VersionChange]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [VersionChange] -> Action [VersionChange])
-> IO [VersionChange] -> Action [VersionChange]
forall a b. (a -> b) -> a -> b
$ Var [VersionChange] -> IO [VersionChange]
forall a. Var a -> IO a
readVar Var [VersionChange]
versionChanges

-- | Run an action, retry at most 'retry' times (defined in config) if it throws an exception
withRetry :: Action a -> Action a
withRetry :: Action a -> Action a
withRetry Action a
a = Action ShakeExtras
getShakeExtras Action ShakeExtras -> (ShakeExtras -> Action a) -> Action a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ShakeExtras {Map PackageKey Package
Var [VersionChange]
Var (Map PackageKey LastVersion)
Config
lastVersions :: Var (Map PackageKey LastVersion)
targetPackages :: Map PackageKey Package
versionChanges :: Var [VersionChange]
config :: Config
lastVersions :: ShakeExtras -> Var (Map PackageKey LastVersion)
targetPackages :: ShakeExtras -> Map PackageKey Package
versionChanges :: ShakeExtras -> Var [VersionChange]
config :: ShakeExtras -> Config
..} -> Int -> Action a -> Action a
forall a. Int -> Action a -> Action a
actionRetry (Config -> Int
retry Config
config) Action a
a

-- | Get build dir
getBuildDir :: Action FilePath
getBuildDir :: Action String
getBuildDir = Config -> String
buildDir (Config -> String)
-> (ShakeExtras -> Config) -> ShakeExtras -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShakeExtras -> Config
config (ShakeExtras -> String) -> Action ShakeExtras -> Action String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Action ShakeExtras
getShakeExtras

-- | Get initial version of a package
getLastVersionOnDisk :: PackageKey -> Action (Maybe Version)
getLastVersionOnDisk :: PackageKey -> Action (Maybe Version)
getLastVersionOnDisk PackageKey
k = do
  ShakeExtras {Map PackageKey Package
Var [VersionChange]
Var (Map PackageKey LastVersion)
Config
lastVersions :: Var (Map PackageKey LastVersion)
targetPackages :: Map PackageKey Package
versionChanges :: Var [VersionChange]
config :: Config
lastVersions :: ShakeExtras -> Var (Map PackageKey LastVersion)
targetPackages :: ShakeExtras -> Map PackageKey Package
versionChanges :: ShakeExtras -> Var [VersionChange]
config :: ShakeExtras -> Config
..} <- Action ShakeExtras
getShakeExtras
  Map PackageKey LastVersion
versions <- IO (Map PackageKey LastVersion)
-> Action (Map PackageKey LastVersion)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Map PackageKey LastVersion)
 -> Action (Map PackageKey LastVersion))
-> IO (Map PackageKey LastVersion)
-> Action (Map PackageKey LastVersion)
forall a b. (a -> b) -> a -> b
$ Var (Map PackageKey LastVersion) -> IO (Map PackageKey LastVersion)
forall a. Var a -> IO a
readVar Var (Map PackageKey LastVersion)
lastVersions
  Maybe Version -> Action (Maybe Version)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Version -> Action (Maybe Version))
-> Maybe Version -> Action (Maybe Version)
forall a b. (a -> b) -> a -> b
$ case Map PackageKey LastVersion
versions Map PackageKey LastVersion -> PackageKey -> Maybe LastVersion
forall k a. Ord k => Map k a -> k -> Maybe a
Map.!? PackageKey
k of
    Just (Updated Maybe Version
v Version
_) -> Maybe Version
v
    Just (OnDisk Version
v) -> Version -> Maybe Version
forall a. a -> Maybe a
Just Version
v
    Maybe LastVersion
_ -> Maybe Version
forall a. Maybe a
Nothing

-- | Get version of a package, no matter it was initial one or rule result
getRecentLastVersion :: PackageKey -> Action (Maybe Version)
getRecentLastVersion :: PackageKey -> Action (Maybe Version)
getRecentLastVersion PackageKey
k = do
  ShakeExtras {Map PackageKey Package
Var [VersionChange]
Var (Map PackageKey LastVersion)
Config
lastVersions :: Var (Map PackageKey LastVersion)
targetPackages :: Map PackageKey Package
versionChanges :: Var [VersionChange]
config :: Config
lastVersions :: ShakeExtras -> Var (Map PackageKey LastVersion)
targetPackages :: ShakeExtras -> Map PackageKey Package
versionChanges :: ShakeExtras -> Var [VersionChange]
config :: ShakeExtras -> Config
..} <- Action ShakeExtras
getShakeExtras
  Map PackageKey LastVersion
versions <- IO (Map PackageKey LastVersion)
-> Action (Map PackageKey LastVersion)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Map PackageKey LastVersion)
 -> Action (Map PackageKey LastVersion))
-> IO (Map PackageKey LastVersion)
-> Action (Map PackageKey LastVersion)
forall a b. (a -> b) -> a -> b
$ Var (Map PackageKey LastVersion) -> IO (Map PackageKey LastVersion)
forall a. Var a -> IO a
readVar Var (Map PackageKey LastVersion)
lastVersions
  Maybe Version -> Action (Maybe Version)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Version -> Action (Maybe Version))
-> Maybe Version -> Action (Maybe Version)
forall a b. (a -> b) -> a -> b
$ case Map PackageKey LastVersion
versions Map PackageKey LastVersion -> PackageKey -> Maybe LastVersion
forall k a. Ord k => Map k a -> k -> Maybe a
Map.!? PackageKey
k of
    Just (Updated Maybe Version
_ Version
v) -> Version -> Maybe Version
forall a. a -> Maybe a
Just Version
v
    Just (OnDisk Version
v) -> Version -> Maybe Version
forall a. a -> Maybe a
Just Version
v
    Maybe LastVersion
_ -> Maybe Version
forall a. Maybe a
Nothing

-- | Get updated version of a package
getLastVersionUpdated :: PackageKey -> Action (Maybe Version)
getLastVersionUpdated :: PackageKey -> Action (Maybe Version)
getLastVersionUpdated PackageKey
k = do
  ShakeExtras {Map PackageKey Package
Var [VersionChange]
Var (Map PackageKey LastVersion)
Config
lastVersions :: Var (Map PackageKey LastVersion)
targetPackages :: Map PackageKey Package
versionChanges :: Var [VersionChange]
config :: Config
lastVersions :: ShakeExtras -> Var (Map PackageKey LastVersion)
targetPackages :: ShakeExtras -> Map PackageKey Package
versionChanges :: ShakeExtras -> Var [VersionChange]
config :: ShakeExtras -> Config
..} <- Action ShakeExtras
getShakeExtras
  Map PackageKey LastVersion
versions <- IO (Map PackageKey LastVersion)
-> Action (Map PackageKey LastVersion)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Map PackageKey LastVersion)
 -> Action (Map PackageKey LastVersion))
-> IO (Map PackageKey LastVersion)
-> Action (Map PackageKey LastVersion)
forall a b. (a -> b) -> a -> b
$ Var (Map PackageKey LastVersion) -> IO (Map PackageKey LastVersion)
forall a. Var a -> IO a
readVar Var (Map PackageKey LastVersion)
lastVersions
  Maybe Version -> Action (Maybe Version)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Version -> Action (Maybe Version))
-> Maybe Version -> Action (Maybe Version)
forall a b. (a -> b) -> a -> b
$ case Map PackageKey LastVersion
versions Map PackageKey LastVersion -> PackageKey -> Maybe LastVersion
forall k a. Ord k => Map k a -> k -> Maybe a
Map.!? PackageKey
k of
    Just (Updated Maybe Version
_ Version
v) -> Version -> Maybe Version
forall a. a -> Maybe a
Just Version
v
    Maybe LastVersion
_ -> Maybe Version
forall a. Maybe a
Nothing

-- | Add nvchecker result of a package
updateLastVersion :: PackageKey -> Version -> Action ()
updateLastVersion :: PackageKey -> Version -> Action ()
updateLastVersion PackageKey
k Version
v = do
  ShakeExtras {Map PackageKey Package
Var [VersionChange]
Var (Map PackageKey LastVersion)
Config
lastVersions :: Var (Map PackageKey LastVersion)
targetPackages :: Map PackageKey Package
versionChanges :: Var [VersionChange]
config :: Config
lastVersions :: ShakeExtras -> Var (Map PackageKey LastVersion)
targetPackages :: ShakeExtras -> Map PackageKey Package
versionChanges :: ShakeExtras -> Var [VersionChange]
config :: ShakeExtras -> Config
..} <- Action ShakeExtras
getShakeExtras
  IO () -> Action ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Action ()) -> IO () -> Action ()
forall a b. (a -> b) -> a -> b
$
    Var (Map PackageKey LastVersion)
-> (Map PackageKey LastVersion -> IO (Map PackageKey LastVersion))
-> IO ()
forall a. Var a -> (a -> IO a) -> IO ()
modifyVar_ Var (Map PackageKey LastVersion)
lastVersions ((Map PackageKey LastVersion -> IO (Map PackageKey LastVersion))
 -> IO ())
-> (Map PackageKey LastVersion -> IO (Map PackageKey LastVersion))
-> IO ()
forall a b. (a -> b) -> a -> b
$ \Map PackageKey LastVersion
versions -> Map PackageKey LastVersion -> IO (Map PackageKey LastVersion)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map PackageKey LastVersion -> IO (Map PackageKey LastVersion))
-> Map PackageKey LastVersion -> IO (Map PackageKey LastVersion)
forall a b. (a -> b) -> a -> b
$ case Map PackageKey LastVersion
versions Map PackageKey LastVersion -> PackageKey -> Maybe LastVersion
forall k a. Ord k => Map k a -> k -> Maybe a
Map.!? PackageKey
k of
      Just (Updated Maybe Version
o Version
_) -> PackageKey
-> LastVersion
-> Map PackageKey LastVersion
-> Map PackageKey LastVersion
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert PackageKey
k (Maybe Version -> Version -> LastVersion
Updated Maybe Version
o Version
v) Map PackageKey LastVersion
versions
      Just (OnDisk Version
lv) -> PackageKey
-> LastVersion
-> Map PackageKey LastVersion
-> Map PackageKey LastVersion
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert PackageKey
k (Maybe Version -> Version -> LastVersion
Updated (Version -> Maybe Version
forall a. a -> Maybe a
Just Version
lv) Version
v) Map PackageKey LastVersion
versions
      Maybe LastVersion
_ -> PackageKey
-> LastVersion
-> Map PackageKey LastVersion
-> Map PackageKey LastVersion
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert PackageKey
k (Maybe Version -> Version -> LastVersion
Updated Maybe Version
forall a. Maybe a
Nothing Version
v) Map PackageKey LastVersion
versions

-- | Get all initial versions
getAllOnDiskVersions :: Action (Map PackageKey Version)
getAllOnDiskVersions :: Action (Map PackageKey Version)
getAllOnDiskVersions = do
  ShakeExtras {Map PackageKey Package
Var [VersionChange]
Var (Map PackageKey LastVersion)
Config
lastVersions :: Var (Map PackageKey LastVersion)
targetPackages :: Map PackageKey Package
versionChanges :: Var [VersionChange]
config :: Config
lastVersions :: ShakeExtras -> Var (Map PackageKey LastVersion)
targetPackages :: ShakeExtras -> Map PackageKey Package
versionChanges :: ShakeExtras -> Var [VersionChange]
config :: ShakeExtras -> Config
..} <- Action ShakeExtras
getShakeExtras
  Map PackageKey LastVersion
versions <- IO (Map PackageKey LastVersion)
-> Action (Map PackageKey LastVersion)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Map PackageKey LastVersion)
 -> Action (Map PackageKey LastVersion))
-> IO (Map PackageKey LastVersion)
-> Action (Map PackageKey LastVersion)
forall a b. (a -> b) -> a -> b
$ Var (Map PackageKey LastVersion) -> IO (Map PackageKey LastVersion)
forall a. Var a -> IO a
readVar Var (Map PackageKey LastVersion)
lastVersions
  let xs :: [(PackageKey, Maybe Version)]
xs = Map PackageKey (Maybe Version) -> [(PackageKey, Maybe Version)]
forall k a. Map k a -> [(k, a)]
Map.toList (Map PackageKey (Maybe Version) -> [(PackageKey, Maybe Version)])
-> Map PackageKey (Maybe Version) -> [(PackageKey, Maybe Version)]
forall a b. (a -> b) -> a -> b
$
        ((LastVersion -> Maybe Version)
 -> Map PackageKey LastVersion -> Map PackageKey (Maybe Version))
-> Map PackageKey LastVersion
-> (LastVersion -> Maybe Version)
-> Map PackageKey (Maybe Version)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (LastVersion -> Maybe Version)
-> Map PackageKey LastVersion -> Map PackageKey (Maybe Version)
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map Map PackageKey LastVersion
versions ((LastVersion -> Maybe Version) -> Map PackageKey (Maybe Version))
-> (LastVersion -> Maybe Version) -> Map PackageKey (Maybe Version)
forall a b. (a -> b) -> a -> b
$ \case
          OnDisk Version
v -> Version -> Maybe Version
forall a. a -> Maybe a
Just Version
v
          Updated Maybe Version
v Version
_ -> Maybe Version
v
  Map PackageKey Version -> Action (Map PackageKey Version)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map PackageKey Version -> Action (Map PackageKey Version))
-> Map PackageKey Version -> Action (Map PackageKey Version)
forall a b. (a -> b) -> a -> b
$ [(PackageKey, Version)] -> Map PackageKey Version
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(PackageKey
k, Version
v) | (PackageKey
k, Just Version
v) <- [(PackageKey, Maybe Version)]
xs]

-- | Get if 'cacheNvchecker' is enabled
nvcheckerCacheEnabled :: Action Bool
nvcheckerCacheEnabled :: Action Bool
nvcheckerCacheEnabled = Config -> Bool
cacheNvchecker (Config -> Bool) -> (ShakeExtras -> Config) -> ShakeExtras -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShakeExtras -> Config
config (ShakeExtras -> Bool) -> Action ShakeExtras -> Action Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Action ShakeExtras
getShakeExtras