82bb0090c0
This turned out to be quite involved but save for this huge commit it's actually quite awesome and squashes quite a few bugs and nasty problems (hopefully). Most importantly we now have native cabal component support without the user having to do anything to get it! To do this we traverse imports starting from each component's entrypoints (library modules or Main source file for executables) and use this information to find which component's options each module will build with. Under the assumption that these modules have to build with every component they're used in we can now just pick one. Quite a few internal assumptions have been invalidated by this change. Most importantly the runGhcModT* family of cuntions now change the current working directory to `cradleRootDir`.
37 lines
843 B
Haskell
37 lines
843 B
Haskell
{-# LANGUAGE CPP #-}
|
|
module Utils where
|
|
|
|
import Control.Monad
|
|
import Control.Applicative
|
|
import Data.Traversable
|
|
import System.Directory
|
|
|
|
#if MIN_VERSION_directory(1,2,0)
|
|
import Data.Time (UTCTime)
|
|
#else
|
|
import System.Time (ClockTime)
|
|
#endif
|
|
|
|
#if MIN_VERSION_directory(1,2,0)
|
|
type ModTime = UTCTime
|
|
#else
|
|
type ModTime = ClockTime
|
|
#endif
|
|
|
|
data TimedFile = TimedFile FilePath ModTime deriving (Eq, Show)
|
|
|
|
instance Ord TimedFile where
|
|
compare (TimedFile _ a) (TimedFile _ b) = compare a b
|
|
|
|
timeFile :: FilePath -> IO TimedFile
|
|
timeFile f = TimedFile <$> pure f <*> getModificationTime f
|
|
|
|
mightExist :: FilePath -> IO (Maybe FilePath)
|
|
mightExist f = do
|
|
exists <- doesFileExist f
|
|
return $ if exists then (Just f) else (Nothing)
|
|
|
|
timeMaybe :: FilePath -> IO (Maybe TimedFile)
|
|
timeMaybe f = do
|
|
join $ (timeFile `traverse`) <$> mightExist f
|