summaryrefslogtreecommitdiff
path: root/Build
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-04-14 13:25:06 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-04-14 13:43:36 -0400
commit7a1165bc3ac8c9069ed6fd5043227d284dc6b83b (patch)
tree3977f9271e88f720f292f9f5bab352ebbe7efcb0 /Build
parent7f84f433afb11245f875e279a20ae0748b92ba1a (diff)
incremental android builds with the EvilSplicer
Diffstat (limited to 'Build')
-rw-r--r--Build/EvilSplicer.hs42
1 files changed, 28 insertions, 14 deletions
diff --git a/Build/EvilSplicer.hs b/Build/EvilSplicer.hs
index 216b818d5..3927fcc5a 100644
--- a/Build/EvilSplicer.hs
+++ b/Build/EvilSplicer.hs
@@ -4,11 +4,12 @@
- and the splices dumped to a log. For example:
- cabal build --ghc-options=-ddump-splices 2>&1 | tee log
-
- - Along with the log, a "headers" file may also be provided, containing
+ - Along with the log, a headers file may also be provided, containing
- additional imports needed by the template haskell code.
-
- This program will parse the log, and expand all splices therein,
- - modifying files in the source tree. They can then be built a second
+ - writing files to the specified destdir (which can be "." to modify
+ - the source tree directly). They can then be built a second
- time, with a ghc that does not support TH.
-
- Note that template haskell code may refer to symbols that are not
@@ -31,10 +32,14 @@ import Data.Either
import Data.List
import Data.String.Utils
import Data.Char
+import System.Environment
+import System.FilePath
+import System.Directory
import Utility.Monad
import Utility.Misc
import Utility.Exception
+import Utility.Path
data Coord = Coord
{ coordLine :: Int
@@ -150,7 +155,7 @@ splicesExtractor = rights <$> many extract
compilerJunkLine = restOfLine
{- Modifies the source file, expanding the splices, which all must
- - have the same splicedFile.
+ - have the same splicedFile. Writes the new file to the destdir.
-
- Each splice's Coords refer to the original position in the file,
- and not to its position after any previous splices may have inserted
@@ -167,12 +172,14 @@ splicesExtractor = rights <$> many extract
- file. These are put right before the first line in the file that
- starts with "import "
-}
-applySplices :: Maybe String -> [Splice] -> IO ()
-applySplices imports l@(first:_) = do
+applySplices :: FilePath -> Maybe String -> [Splice] -> IO ()
+applySplices destdir imports l@(first:_) = do
let f = splicedFile first
+ let dest = (destdir </> f)
putStrLn $ "splicing " ++ f
lls <- map (++ "\n") . lines <$> readFileStrict f
- writeFile f $ concat $ addimports $ expand lls l
+ createDirectoryIfMissing True (parentDir dest)
+ writeFile dest $ concat $ addimports $ expand lls l
where
expand lls [] = lls
expand lls (s:rest) = expand (expandSplice s lls) rest
@@ -273,11 +280,18 @@ mangleCode = fix_bad_escape . remove_package_version
mangleSymbol "GHC.Types." = ""
mangleSymbol s = s
-main = do
- r <- parseFromFile splicesExtractor "log"
- case r of
- Left e -> error $ show e
- Right splices -> do
- let groups = groupBy (\a b -> splicedFile a == splicedFile b) splices
- imports <- catchMaybeIO $ readFile "imports"
- mapM_ (applySplices imports) groups
+main :: IO ()
+main = go =<< getArgs
+ where
+ go (destdir:log:header:[]) = run destdir log (Just header)
+ go (destdir:log:[]) = run destdir log Nothing
+ go _ = error "usage: EvilSplicer destdir logfile [headerfile]"
+
+ run destdir log mheader = do
+ r <- parseFromFile splicesExtractor log
+ case r of
+ Left e -> error $ show e
+ Right splices -> do
+ let groups = groupBy (\a b -> splicedFile a == splicedFile b) splices
+ imports <- maybe (return Nothing) (catchMaybeIO . readFile) mheader
+ mapM_ (applySplices destdir imports) groups