Created
March 28, 2012 16:30
-
-
Save eagletmt/2227993 to your computer and use it in GitHub Desktop.
cabal build のときに自動的に走る前処理だけを実行する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Control.Applicative ((<$>)) | |
import Data.List (isSuffixOf) | |
import System.Exit (exitFailure) | |
import System.IO (hPutStrLn, stderr) | |
import System.Directory (getDirectoryContents) | |
import System.FilePath (takeDirectory, (</>)) | |
import Distribution.Verbosity (silent) | |
import Distribution.PackageDescription.Parse (readPackageDescription) | |
import Distribution.PackageDescription.Configuration (flattenPackageDescription) | |
import Distribution.Simple.LocalBuildInfo (withComponentsLBI) | |
import Distribution.Simple.Configure (tryGetConfigStateFile, localBuildInfoFile) | |
import Distribution.Simple.Build (initialBuildSteps) | |
import Distribution.Simple.PreProcess (preprocessComponent, knownSuffixHandlers) | |
die :: String -> IO () | |
die msg = do | |
hPutStrLn stderr msg | |
exitFailure | |
main :: IO () | |
main = do | |
files <- filter (".cabal" `isSuffixOf`) <$> getDirectoryContents "." | |
case files of | |
[] -> die "No cabal file found." | |
file:_ -> doPreprocess file | |
doPreprocess :: FilePath -> IO () | |
doPreprocess cabalPath = do | |
pkgDesc <- flattenPackageDescription <$> readPackageDescription silent cabalPath | |
elbi <- tryGetConfigStateFile $ localBuildInfoFile distDir | |
case elbi of | |
Left err -> die err | |
Right lbi -> do | |
initialBuildSteps distDir pkgDesc lbi silent | |
withComponentsLBI pkgDesc lbi $ \comp _ -> do | |
preprocessComponent pkgDesc comp lbi False silent knownSuffixHandlers | |
where | |
distDir = takeDirectory cabalPath </> "dist" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment