Merge pull request #116 from ngunn/dev
Fix Elm.cabal missing elm-runtime.js
This commit is contained in:
commit
39fcc823be
3 changed files with 74 additions and 50 deletions
46
Build.hs
46
Build.hs
|
@ -1,46 +0,0 @@
|
|||
-- This file compiles all library and runtime code
|
||||
-- into compiler/elm-runtime.js. It then rebuilds the compiler.
|
||||
-- Run it with the command "runHaskell Build.hs".
|
||||
|
||||
import System.Cmd
|
||||
import System.Directory
|
||||
import System.Exit
|
||||
import System.FilePath
|
||||
import System.IO
|
||||
import Language.Elm
|
||||
|
||||
rts = "compiler" </> "elm-runtime.js"
|
||||
types = "compiler" </> "types.json"
|
||||
|
||||
getFiles ext dir = do
|
||||
contents <- map (dir </>) `fmap` getDirectoryContents dir
|
||||
let files = filter (\f -> takeExtension f == ext) contents
|
||||
dirs = filter (not . hasExtension) contents
|
||||
filess <- mapM (getFiles ext) dirs
|
||||
return (files ++ concat filess)
|
||||
|
||||
appendJS file = do
|
||||
putStrLn (dropExtension file)
|
||||
str <- readFile file
|
||||
length str `seq` return ()
|
||||
appendFile rts str
|
||||
|
||||
appendElm file = do
|
||||
system ("elm --only-js " ++ file)
|
||||
let jsFile = replaceExtension file ".js"
|
||||
appendJS jsFile
|
||||
removeFile jsFile
|
||||
|
||||
main = do
|
||||
writeFile rts "Elm = {}; Elm.Native = {}; Elm.Native.Graphics = {};\n\
|
||||
\Elm.Graphics = {}; ElmRuntime = {}; ElmRuntime.Render = {}\n"
|
||||
mapM_ appendJS =<< getFiles ".js" "libraries"
|
||||
files <- getFiles ".elm" "libraries"
|
||||
mapM_ appendElm files
|
||||
mapM_ appendJS =<< getFiles ".js" "runtime"
|
||||
putStrLn "\n+------------------------------------------+\
|
||||
\\n| Success building runtime and libraries! |\
|
||||
\\n+------------------------------------------+\n"
|
||||
system ("elm-doc " ++ unwords files ++ " > " ++ types)
|
||||
system ("cabal install compiler" </> "Elm.cabal")
|
||||
exitSuccess
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
Name: Elm
|
||||
Version: 0.8
|
||||
Synopsis: The Elm language module.
|
||||
|
@ -19,10 +18,11 @@ Copyright: Copyright: (c) 2011-2012 Evan Czaplicki
|
|||
|
||||
Category: Compiler, Language
|
||||
|
||||
Build-type: Simple
|
||||
Build-type: Custom
|
||||
|
||||
Extra-source-files: changelog.txt
|
||||
Data-files: elm-runtime.js
|
||||
Data-dir: dist/data
|
||||
Data-files: elm-runtime.js types.json
|
||||
Cabal-version: >=1.8
|
||||
|
||||
source-repository head
|
||||
|
|
|
@ -1,2 +1,72 @@
|
|||
import Distribution.Simple
|
||||
main = defaultMain
|
||||
import Distribution.Simple.LocalBuildInfo
|
||||
import Distribution.Simple.Setup
|
||||
import Distribution.PackageDescription
|
||||
|
||||
import System.Cmd
|
||||
import System.Directory
|
||||
import System.FilePath
|
||||
import System.IO
|
||||
|
||||
-- Add a post-build callout.
|
||||
-- We need to build the runtime.js after we've built elm,
|
||||
-- but before cabal does the install file copy step
|
||||
|
||||
main :: IO ()
|
||||
main = defaultMainWithHooks simpleUserHooks { postBuild = myPostBuild }
|
||||
|
||||
-- Care! This appears to be based on an unstable API
|
||||
-- See: http://www.haskell.org/cabal/release/cabal-latest/doc/API/Cabal/Distribution-Simple.html#2
|
||||
|
||||
myPostBuild :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
|
||||
myPostBuild as bfs pd lbi = do
|
||||
putStrLn "Custom build step started"
|
||||
buildRuntime lbi
|
||||
buildTypes lbi
|
||||
postBuild simpleUserHooks as bfs pd lbi
|
||||
|
||||
-- put js file in dist folder so git doesn't notice
|
||||
rtsDir = "dist" </> "data"
|
||||
|
||||
rts = rtsDir </> "elm-runtime.js"
|
||||
types = rtsDir </> "types.json"
|
||||
|
||||
-- buildDir with LocalBuildInfo points to "dist/build" (usually)
|
||||
elm lbi = (buildDir lbi) </> "elm" </> "elm"
|
||||
elm_doc lbi = (buildDir lbi) </> "elm-doc" </> "elm-doc"
|
||||
|
||||
|
||||
getFiles ext dir = do
|
||||
contents <- map (dir </>) `fmap` getDirectoryContents dir
|
||||
let files = filter (\f -> takeExtension f == ext) contents
|
||||
dirs = filter (not . hasExtension) contents
|
||||
filess <- mapM (getFiles ext) dirs
|
||||
return (files ++ concat filess)
|
||||
|
||||
appendJS file = do
|
||||
putStrLn (dropExtension file)
|
||||
str <- readFile file
|
||||
length str `seq` return ()
|
||||
appendFile rts str
|
||||
|
||||
appendElm lbi file = do
|
||||
system ((show $ elm lbi) ++ " --only-js " ++ file)
|
||||
let jsFile = replaceExtension file ".js"
|
||||
appendJS jsFile
|
||||
removeFile jsFile
|
||||
|
||||
buildRuntime lbi = do
|
||||
createDirectoryIfMissing False rtsDir -- dist should already exist
|
||||
writeFile rts "Elm = {}; Elm.Native = {}; Elm.Native.Graphics = {};\n\
|
||||
\Elm.Graphics = {}; ElmRuntime = {}; ElmRuntime.Render = {}\n"
|
||||
mapM_ appendJS =<< getFiles ".js" "../libraries"
|
||||
mapM_ (appendElm lbi) =<< getFiles ".elm" "../libraries"
|
||||
mapM_ appendJS =<< getFiles ".js" "../runtime"
|
||||
putStrLn "\n+------------------------------------------+\
|
||||
\\n| Success building runtime and libraries! |\
|
||||
\\n+------------------------------------------+\n"
|
||||
|
||||
buildTypes lbi = do
|
||||
files <- getFiles ".elm" "../libraries"
|
||||
system ((show $ elm_doc lbi) ++ " " ++ unwords files ++ " > " ++ types)
|
||||
putStrLn "Custom build step completed: elm-doc"
|
||||
|
|
Loading…
Reference in a new issue