incremental android builds with the EvilSplicer
This commit is contained in:
parent
553d9d661a
commit
dd7e35ed97
4 changed files with 60 additions and 17 deletions
|
@ -4,11 +4,12 @@
|
||||||
- and the splices dumped to a log. For example:
|
- and the splices dumped to a log. For example:
|
||||||
- cabal build --ghc-options=-ddump-splices 2>&1 | tee log
|
- 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.
|
- additional imports needed by the template haskell code.
|
||||||
-
|
-
|
||||||
- This program will parse the log, and expand all splices therein,
|
- 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.
|
- time, with a ghc that does not support TH.
|
||||||
-
|
-
|
||||||
- Note that template haskell code may refer to symbols that are not
|
- Note that template haskell code may refer to symbols that are not
|
||||||
|
@ -31,10 +32,14 @@ import Data.Either
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.String.Utils
|
import Data.String.Utils
|
||||||
import Data.Char
|
import Data.Char
|
||||||
|
import System.Environment
|
||||||
|
import System.FilePath
|
||||||
|
import System.Directory
|
||||||
|
|
||||||
import Utility.Monad
|
import Utility.Monad
|
||||||
import Utility.Misc
|
import Utility.Misc
|
||||||
import Utility.Exception
|
import Utility.Exception
|
||||||
|
import Utility.Path
|
||||||
|
|
||||||
data Coord = Coord
|
data Coord = Coord
|
||||||
{ coordLine :: Int
|
{ coordLine :: Int
|
||||||
|
@ -150,7 +155,7 @@ splicesExtractor = rights <$> many extract
|
||||||
compilerJunkLine = restOfLine
|
compilerJunkLine = restOfLine
|
||||||
|
|
||||||
{- Modifies the source file, expanding the splices, which all must
|
{- 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,
|
- Each splice's Coords refer to the original position in the file,
|
||||||
- and not to its position after any previous splices may have inserted
|
- 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
|
- file. These are put right before the first line in the file that
|
||||||
- starts with "import "
|
- starts with "import "
|
||||||
-}
|
-}
|
||||||
applySplices :: Maybe String -> [Splice] -> IO ()
|
applySplices :: FilePath -> Maybe String -> [Splice] -> IO ()
|
||||||
applySplices imports l@(first:_) = do
|
applySplices destdir imports l@(first:_) = do
|
||||||
let f = splicedFile first
|
let f = splicedFile first
|
||||||
|
let dest = (destdir </> f)
|
||||||
putStrLn $ "splicing " ++ f
|
putStrLn $ "splicing " ++ f
|
||||||
lls <- map (++ "\n") . lines <$> readFileStrict 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
|
where
|
||||||
expand lls [] = lls
|
expand lls [] = lls
|
||||||
expand lls (s:rest) = expand (expandSplice s lls) rest
|
expand lls (s:rest) = expand (expandSplice s lls) rest
|
||||||
|
@ -273,11 +280,18 @@ mangleCode = fix_bad_escape . remove_package_version
|
||||||
mangleSymbol "GHC.Types." = ""
|
mangleSymbol "GHC.Types." = ""
|
||||||
mangleSymbol s = s
|
mangleSymbol s = s
|
||||||
|
|
||||||
main = do
|
main :: IO ()
|
||||||
r <- parseFromFile splicesExtractor "log"
|
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
|
case r of
|
||||||
Left e -> error $ show e
|
Left e -> error $ show e
|
||||||
Right splices -> do
|
Right splices -> do
|
||||||
let groups = groupBy (\a b -> splicedFile a == splicedFile b) splices
|
let groups = groupBy (\a b -> splicedFile a == splicedFile b) splices
|
||||||
imports <- catchMaybeIO $ readFile "imports"
|
imports <- maybe (return Nothing) (catchMaybeIO . readFile) mheader
|
||||||
mapM_ (applySplices imports) groups
|
mapM_ (applySplices destdir imports) groups
|
||||||
|
|
16
Makefile
16
Makefile
|
@ -149,12 +149,24 @@ osxapp:
|
||||||
# Cross compile for Android.
|
# Cross compile for Android.
|
||||||
# Uses https://github.com/neurocyte/ghc-android
|
# Uses https://github.com/neurocyte/ghc-android
|
||||||
android:
|
android:
|
||||||
$(CABAL) configure
|
echo "Native build, to get TH splices.."
|
||||||
|
$(CABAL) configure -f"-Production" -O0
|
||||||
|
$(CABAL) build -v2 --ghc-options=-ddump-splices 2>&1 | tee dist/caballog
|
||||||
|
mkdir -p tmp
|
||||||
|
rsync -az --delete --exclude tmp . tmp/androidtree
|
||||||
|
cd tmp/androidtree && $(MAKE) android-stage2
|
||||||
|
|
||||||
|
android-stage2:
|
||||||
|
runghc Build/EvilSplicer.hs tmp/splices dist/caballog standalone/android/evilsplicer-headers.hs
|
||||||
|
# Copy the files with expanded splices to the source tree, but
|
||||||
|
# only if the existing source file is not newer. (So, if a file
|
||||||
|
# used to have TH splices but they were removed, it will be newer,
|
||||||
|
# and not overwritten.)
|
||||||
|
cp -uR tmp/splices/* .
|
||||||
# cabal cannot cross compile with custom build type, so workaround
|
# cabal cannot cross compile with custom build type, so workaround
|
||||||
sed -i 's/Build-type: Custom/Build-type: Simple/' git-annex.cabal
|
sed -i 's/Build-type: Custom/Build-type: Simple/' git-annex.cabal
|
||||||
$$HOME/.ghc/android-14/arm-linux-androideabi-4.7/arm-linux-androideabi/bin/cabal configure -f'Android Assistant -Pairing -Webapp'
|
$$HOME/.ghc/android-14/arm-linux-androideabi-4.7/arm-linux-androideabi/bin/cabal configure -f'Android Assistant -Pairing -Webapp'
|
||||||
$(MAKE) git-annex
|
$(MAKE) git-annex
|
||||||
sed -i 's/Build-type: Simple/Build-type: Custom/' git-annex.cabal
|
|
||||||
|
|
||||||
androidapp:
|
androidapp:
|
||||||
$(MAKE) android
|
$(MAKE) android
|
||||||
|
|
|
@ -32,7 +32,7 @@ build: start
|
||||||
# Install executables as pseudo-libraries so they will be
|
# Install executables as pseudo-libraries so they will be
|
||||||
# unpacked from the .apk.
|
# unpacked from the .apk.
|
||||||
mkdir -p $(GIT_ANNEX_ANDROID_SOURCETREE)/term/libs/armeabi
|
mkdir -p $(GIT_ANNEX_ANDROID_SOURCETREE)/term/libs/armeabi
|
||||||
cp ../../git-annex $(GIT_ANNEX_ANDROID_SOURCETREE)/term/libs/armeabi/lib.git-annex.so
|
cp ../../tmp/androidtree/git-annex $(GIT_ANNEX_ANDROID_SOURCETREE)/term/libs/armeabi/lib.git-annex.so
|
||||||
cp $(GIT_ANNEX_ANDROID_SOURCETREE)/busybox/busybox $(GIT_ANNEX_ANDROID_SOURCETREE)/term/libs/armeabi/lib.busybox.so
|
cp $(GIT_ANNEX_ANDROID_SOURCETREE)/busybox/busybox $(GIT_ANNEX_ANDROID_SOURCETREE)/term/libs/armeabi/lib.busybox.so
|
||||||
cp $(GIT_ANNEX_ANDROID_SOURCETREE)/openssh/ssh $(GIT_ANNEX_ANDROID_SOURCETREE)/term/libs/armeabi/lib.ssh.so
|
cp $(GIT_ANNEX_ANDROID_SOURCETREE)/openssh/ssh $(GIT_ANNEX_ANDROID_SOURCETREE)/term/libs/armeabi/lib.ssh.so
|
||||||
cp $(GIT_ANNEX_ANDROID_SOURCETREE)/openssh/ssh-keygen $(GIT_ANNEX_ANDROID_SOURCETREE)/term/libs/armeabi/lib.ssh-keygen.so
|
cp $(GIT_ANNEX_ANDROID_SOURCETREE)/openssh/ssh-keygen $(GIT_ANNEX_ANDROID_SOURCETREE)/term/libs/armeabi/lib.ssh-keygen.so
|
||||||
|
|
17
standalone/android/evilsplicer-headers.hs
Normal file
17
standalone/android/evilsplicer-headers.hs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
|
||||||
|
{- This file was modified by the EvilSplicer, adding these headers,
|
||||||
|
- and expanding Template Haskell.
|
||||||
|
-
|
||||||
|
- ** DO NOT COMMIT **
|
||||||
|
-}
|
||||||
|
import qualified Data.Text.Lazy.Builder
|
||||||
|
import qualified Text.Shakespeare
|
||||||
|
import qualified Text.Hamlet
|
||||||
|
import qualified Text.Julius
|
||||||
|
import qualified "blaze-markup" Text.Blaze.Internal
|
||||||
|
import qualified Data.Monoid
|
||||||
|
import qualified Yesod.Widget
|
||||||
|
{- End EvilSplicer headers. -}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue