{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Language.ATS.Package.Generic ( GenericPackage (..)
, InstallDirs (..)
, Package (..)
, CacheValid
, atsInstallDirs
) where
import Control.Monad.Reader (ReaderT)
import Data.Hashable (Hashable (..))
import Quaalude
type CacheValid a = a -> a -> Bool
data InstallDirs a = InstallDirs { binDir :: a -> FilePath
, libDir :: a -> String -> FilePath
, includeDir :: a -> String -> FilePath
, includeDeps :: a -> [FilePath]
, libDeps :: a -> [FilePath]
}
atsInstallDirs :: Hashable a => IO (InstallDirs a)
atsInstallDirs = do
h <- getEnv "HOME"
let binDir' = h ++ "/.local/bin"
includeDir' = h ++ "/.atspkg/include"
libDeps' = ["/.atspkg/lib"]
includeDeps' = ["/.atspkg/include"]
pure $ InstallDirs (pure binDir') (\pkg n -> "/.atspkg/lib/" ++ n ++ "/" ++ hex (hash pkg)) (\_ _ -> includeDir') (pure includeDeps') (pure libDeps')
newtype Package a b = Package { unPack :: ReaderT (InstallDirs a) IO b }
deriving (Functor, Applicative, Monad)
class Hashable a => GenericPackage a where
binRules :: a -> Package a ()
libRules :: a -> Package a ()
includeRules :: a -> Package a ()