summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Build/EvilSplicer.hs42
-rw-r--r--Makefile16
-rw-r--r--standalone/android/Makefile2
-rw-r--r--standalone/android/evilsplicer-headers.hs17
4 files changed, 60 insertions, 17 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
diff --git a/Makefile b/Makefile
index 7a6d8c0a5..ca7c49f89 100644
--- a/Makefile
+++ b/Makefile
@@ -149,12 +149,24 @@ osxapp:
# Cross compile for Android.
# Uses https://github.com/neurocyte/ghc-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
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'
$(MAKE) git-annex
- sed -i 's/Build-type: Simple/Build-type: Custom/' git-annex.cabal
androidapp:
$(MAKE) android
diff --git a/standalone/android/Makefile b/standalone/android/Makefile
index 7b70054cf..44a2fc71f 100644
--- a/standalone/android/Makefile
+++ b/standalone/android/Makefile
@@ -32,7 +32,7 @@ build: start
# Install executables as pseudo-libraries so they will be
# unpacked from the .apk.
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)/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
diff --git a/standalone/android/evilsplicer-headers.hs b/standalone/android/evilsplicer-headers.hs
new file mode 100644
index 000000000..bdcb6383c
--- /dev/null
+++ b/standalone/android/evilsplicer-headers.hs
@@ -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. -}
+
+