Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes shake build and cache Shakefiles by using shake itself to rebui… #525

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
25 changes: 23 additions & 2 deletions src/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module Run(main) where

import Development.Ninja.All
import Development.Shake.Util
import System.Environment
import Development.Shake
import Development.Shake.FilePath
Expand All @@ -24,8 +25,7 @@ main = do
,"Shakefile.hs","Shakefile.lhs"]
case hsExe of
Just file -> do
(prog,args) <- return $
if takeExtension file `elem` [".hs",".lhs"] then ("runhaskell", file:args) else (toNative file, args)
prog <- selectProg file
e <- rawSystem prog args
when (e /= ExitSuccess) $ exitWith e
Nothing ->
Expand All @@ -51,3 +51,24 @@ flags = [Option "f" ["file","makefile"] (ReqArg (Right . UseMakefile) "FILE") "R

findFile :: [FilePath] -> IO (Maybe FilePath)
findFile = findM (fmap (either (const False) id) . try_ . IO.doesFileExist)

selectProg :: FilePath -> IO FilePath
selectProg file = if takeExtension file `elem` [".hs",".lhs"]
then buildShakefile file
else return $ toNative file

buildShakefile :: FilePath -> IO FilePath
buildShakefile shakefile = do
let shakefileBin = ".shake" </> shakefile -<.> exe
() <- doBuild shakefile shakefileBin
return $ toNative shakefileBin

doBuild :: FilePath -> FilePath -> IO ()
doBuild file target = shake shakeOptions { shakeFiles = ".shake" } $ do
want [target]

target %> \out -> do
let makefile = ".shake" </> "Makefile"
() <- cmd ["ghc", "-M", "-dep-makefile", makefile, "-dep-suffix=.", file]
needMakefileDependencies makefile
cmd ["ghc", "--make", file, "-o", target, "-outputdir", ".shake"]