on master help sign in
Merge branch 'dev' of https://github.com/evancz/Elm into dev
3d7da56evancz
Build.hsdeleted−46
@@ -1,46 +0,0 @@
1−-- This file compiles all library and runtime code
2−-- into compiler/elm-runtime.js. It then rebuilds the compiler.
3−-- Run it with the command "runHaskell Build.hs".
4−
5−import System.Cmd
6−import System.Directory
7−import System.Exit
8−import System.FilePath
9−import System.IO
10−import Language.Elm
11−
12−rts = "compiler" </> "elm-runtime.js"
13−types = "compiler" </> "types.json"
14−
15−getFiles ext dir = do
16− contents <- map (dir </>) `fmap` getDirectoryContents dir
17− let files = filter (\f -> takeExtension f == ext) contents
18− dirs = filter (not . hasExtension) contents
19− filess <- mapM (getFiles ext) dirs
20− return (files ++ concat filess)
21−
22−appendJS file = do
23− putStrLn (dropExtension file)
24− str <- readFile file
25− length str `seq` return ()
26− appendFile rts str
27−
28−appendElm file = do
29− system ("elm --only-js " ++ file)
30− let jsFile = replaceExtension file ".js"
31− appendJS jsFile
32− removeFile jsFile
33−
34−main = do
35− writeFile rts "Elm = {}; Elm.Native = {}; Elm.Native.Graphics = {};\n\
36− \Elm.Graphics = {}; ElmRuntime = {}; ElmRuntime.Render = {}\n"
37− mapM_ appendJS =<< getFiles ".js" "libraries"
38− files <- getFiles ".elm" "libraries"
39− mapM_ appendElm files
40− mapM_ appendJS =<< getFiles ".js" "runtime"
41− putStrLn "\n+------------------------------------------+\
42− \\n| Success building runtime and libraries! |\
43− \\n+------------------------------------------+\n"
44− system ("elm-doc " ++ unwords files ++ " > " ++ types)
45− system ("cabal install compiler" </> "Elm.cabal")
46− exitSuccess
compiler/Elm.cabal+3−3
@@ -1,4 +1,3 @@
1−
2Name: Elm
1Name: Elm
3Version: 0.8
2Version: 0.8
4Synopsis: The Elm language module.
3Synopsis: The Elm language module.
@@ -19,10 +18,11 @@ Copyright: Copyright: (c) 2011-2012 Evan Czaplicki
19
18
20Category: Compiler, Language
19Category: Compiler, Language
21
20
22−Build-type: Simple
21+Build-type: Custom
23
22
24Extra-source-files: changelog.txt
23Extra-source-files: changelog.txt
24+Data-dir: dist/data
25−Data-files: elm-runtime.js
25+Data-files: elm-runtime.js types.json
26Cabal-version: >=1.8
26Cabal-version: >=1.8
27
27
28source-repository head
28source-repository head
compiler/Setup.hs+71−1
@@ -1,2 +1,72 @@
1import Distribution.Simple
1import Distribution.Simple
2−main = defaultMain
2+import Distribution.Simple.LocalBuildInfo
3+import Distribution.Simple.Setup
4+import Distribution.PackageDescription
5+
6+import System.Cmd
7+import System.Directory
8+import System.FilePath
9+import System.IO
10+
11+-- Add a post-build callout.
12+-- We need to build the runtime.js after we've built elm,
13+-- but before cabal does the install file copy step
14+
15+main :: IO ()
16+main = defaultMainWithHooks simpleUserHooks { postBuild = myPostBuild }
17+
18+-- Care! This appears to be based on an unstable API
19+-- See: http://www.haskell.org/cabal/release/cabal-latest/doc/API/Cabal/Distribution-Simple.html#2
20+
21+myPostBuild :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
22+myPostBuild as bfs pd lbi = do
23+ putStrLn "Custom build step started"
24+ buildRuntime lbi
25+ buildTypes lbi
26+ postBuild simpleUserHooks as bfs pd lbi
27+
28+-- put js file in dist folder so git doesn't notice
29+rtsDir = "dist" </> "data"
30+
31+rts = rtsDir </> "elm-runtime.js"
32+types = rtsDir </> "types.json"
33+
34+-- buildDir with LocalBuildInfo points to "dist/build" (usually)
35+elm lbi = (buildDir lbi) </> "elm" </> "elm"
36+elm_doc lbi = (buildDir lbi) </> "elm-doc" </> "elm-doc"
37+
38+
39+getFiles ext dir = do
40+ contents <- map (dir </>) `fmap` getDirectoryContents dir
41+ let files = filter (\f -> takeExtension f == ext) contents
42+ dirs = filter (not . hasExtension) contents
43+ filess <- mapM (getFiles ext) dirs
44+ return (files ++ concat filess)
45+
46+appendJS file = do
47+ putStrLn (dropExtension file)
48+ str <- readFile file
49+ length str `seq` return ()
50+ appendFile rts str
51+
52+appendElm lbi file = do
53+ system ((show $ elm lbi) ++ " --only-js " ++ file)
54+ let jsFile = replaceExtension file ".js"
55+ appendJS jsFile
56+ removeFile jsFile
57+
58+buildRuntime lbi = do
59+ createDirectoryIfMissing False rtsDir -- dist should already exist
60+ writeFile rts "Elm = {}; Elm.Native = {}; Elm.Native.Graphics = {};\n\
61+ \Elm.Graphics = {}; ElmRuntime = {}; ElmRuntime.Render = {}\n"
62+ mapM_ appendJS =<< getFiles ".js" "../libraries"
63+ mapM_ (appendElm lbi) =<< getFiles ".elm" "../libraries"
64+ mapM_ appendJS =<< getFiles ".js" "../runtime"
65+ putStrLn "\n+------------------------------------------+\
66+ \\n| Success building runtime and libraries! |\
67+ \\n+------------------------------------------+\n"
68+
69+buildTypes lbi = do
70+ files <- getFiles ".elm" "../libraries"
71+ system ((show $ elm_doc lbi) ++ " " ++ unwords files ++ " > " ++ types)
72+ putStrLn "Custom build step completed: elm-doc"