|
| 1 | +{-| This script builds any version of the Elm Platform from source. |
| 2 | +Before you use it, make sure you have the Haskell Platform with a recent |
| 3 | +version of cabal. |
| 4 | +
|
| 5 | +To install a released version of Elm, you will run something like this: |
| 6 | +
|
| 7 | + runhaskell BuildFromSource.hs 0.15.1 |
| 8 | +
|
| 9 | +Before you do that, in some directory of your choosing, add |
| 10 | +wherever/Elm-Platform/0.15.1/.cabal-sandbox/bin to your PATH. |
| 11 | +
|
| 12 | +Then, run the above. You will now actually have a new directory for the |
| 13 | +Elm Platform, like this: |
| 14 | +
|
| 15 | + Elm-Platform/0.15.1/ |
| 16 | + elm-make/ -- git repo for the build tool, ready to edit |
| 17 | + elm-repl/ -- git repo for the REPL, ready to edit |
| 18 | + ... |
| 19 | + .cabal-sandbox/ -- various build files |
| 20 | +
|
| 21 | +All of the executables you need are in .cabal-sandbox/bin, which is on |
| 22 | +your PATH and thus can be used from anywhere. |
| 23 | +
|
| 24 | +You can build many versions of the Elm Platform, so it is possible to have |
| 25 | +Elm-Platform/0.15.1/ and Elm-Platform/0.13/ with no problems. It is up to you |
| 26 | +to manage your PATH variable or symlinks though. |
| 27 | +
|
| 28 | +To get set up with the master branch of all Elm Platform projects, run this: |
| 29 | +
|
| 30 | + runhaskell BuildFromSource.hs master |
| 31 | +
|
| 32 | +From there you can start developing on any of the projects, switching branches |
| 33 | +and testing interactions between projects. |
| 34 | +-} |
| 35 | +module Main where |
| 36 | + |
| 37 | +import qualified Data.List as List |
| 38 | +import qualified Data.Map as Map |
| 39 | +import System.Directory (createDirectoryIfMissing, |
| 40 | + getCurrentDirectory, setCurrentDirectory) |
| 41 | +import System.Environment (getArgs) |
| 42 | +import System.Exit (ExitCode, exitFailure) |
| 43 | +import System.FilePath ((</>)) |
| 44 | +import System.IO (hPutStrLn, stderr) |
| 45 | +import System.Process (rawSystem) |
| 46 | + |
| 47 | + |
| 48 | +(=:) = (,) |
| 49 | + |
| 50 | +configs :: Map.Map String [(String, String)] |
| 51 | +configs = |
| 52 | + Map.fromList |
| 53 | + [ |
| 54 | + "master" =: |
| 55 | + [ "elm-compiler" =: "master" |
| 56 | + , "elm-package" =: "master" |
| 57 | + , "elm-make" =: "master" |
| 58 | + , "elm-reactor" =: "master" |
| 59 | + , "elm-repl" =: "master" |
| 60 | + ] |
| 61 | + , |
| 62 | + "0.15.1" =: |
| 63 | + [ "elm-compiler" =: "0.15.1" |
| 64 | + , "elm-package" =: "0.5.1" |
| 65 | + , "elm-make" =: "0.2" |
| 66 | + ] |
| 67 | + , |
| 68 | + "0.15" =: |
| 69 | + [ "elm-compiler" =: "0.15" |
| 70 | + , "elm-package" =: "0.5" |
| 71 | + , "elm-make" =: "0.1.2" |
| 72 | + , "elm-reactor" =: "0.3.1" |
| 73 | + , "elm-repl" =: "0.4.1" |
| 74 | + ] |
| 75 | + , |
| 76 | + "0.14.1" =: |
| 77 | + [ "elm-compiler" =: "0.14.1" |
| 78 | + , "elm-package" =: "0.4" |
| 79 | + , "elm-make" =: "0.1.1" |
| 80 | + , "elm-reactor" =: "0.3" |
| 81 | + , "elm-repl" =: "0.4" |
| 82 | + ] |
| 83 | + , |
| 84 | + "0.14" =: |
| 85 | + [ "elm-compiler" =: "0.14" |
| 86 | + , "elm-package" =: "0.2" |
| 87 | + , "elm-make" =: "0.1" |
| 88 | + , "elm-reactor" =: "0.2" |
| 89 | + , "elm-repl" =: "0.4" |
| 90 | + ] |
| 91 | + , |
| 92 | + "0.13" =: |
| 93 | + [ "Elm" =: "0.13" |
| 94 | + , "elm-reactor" =: "0.1" |
| 95 | + , "elm-repl" =: "0.3" |
| 96 | + , "elm-get" =: "0.1.3" |
| 97 | + ] |
| 98 | + , |
| 99 | + "0.12.3" =: |
| 100 | + [ "Elm" =: "0.12.3" |
| 101 | + , "elm-server" =: "0.11.0.1" |
| 102 | + , "elm-repl" =: "0.2.2.1" |
| 103 | + , "elm-get" =: "0.1.2" |
| 104 | + ] |
| 105 | + ] |
| 106 | + |
| 107 | + |
| 108 | +main :: IO () |
| 109 | +main = |
| 110 | + do args <- getArgs |
| 111 | + case args of |
| 112 | + [version] | Map.member version configs -> |
| 113 | + let artifactDirectory = "Elm-Platform" </> version |
| 114 | + repos = configs Map.! version |
| 115 | + in |
| 116 | + makeRepos artifactDirectory version repos |
| 117 | + |
| 118 | + _ -> |
| 119 | + do hPutStrLn stderr $ |
| 120 | + "Expecting one of the following values as an argument:\n" ++ |
| 121 | + " " ++ List.intercalate ", " (Map.keys configs) |
| 122 | + exitFailure |
| 123 | + |
| 124 | + |
| 125 | +makeRepos :: FilePath -> String -> [(String, String)] -> IO () |
| 126 | +makeRepos artifactDirectory version repos = |
| 127 | + do createDirectoryIfMissing True artifactDirectory |
| 128 | + setCurrentDirectory artifactDirectory |
| 129 | + root <- getCurrentDirectory |
| 130 | + mapM_ (uncurry (makeRepo root)) repos |
| 131 | + |
| 132 | + cabal [ "update" ] |
| 133 | + |
| 134 | + -- create a sandbox for installation |
| 135 | + cabal [ "sandbox", "init" ] |
| 136 | + |
| 137 | + -- add each of the sub-directories as a sandbox source |
| 138 | + cabal ([ "sandbox", "add-source" ] ++ map fst repos) |
| 139 | + |
| 140 | + -- install all of the packages together in order to resolve transitive dependencies robustly |
| 141 | + -- (install the dependencies a bit more quietly than the elm packages) |
| 142 | + cabal ([ "install", "-j", "--only-dependencies", "--ghc-options=\"-w\"" ] ++ (if version <= "0.15.1" then [ "--constraint=fsnotify<0.2" ] else []) ++ map fst repos) |
| 143 | + cabal ([ "install", "-j", "--ghc-options=\"-XFlexibleContexts\"" ] ++ filter (/= "elm-reactor") (map fst repos)) |
| 144 | + |
| 145 | + return () |
| 146 | + |
| 147 | +makeRepo :: FilePath -> String -> String -> IO () |
| 148 | +makeRepo root projectName version = |
| 149 | + do -- get the right version of the repo |
| 150 | + git [ "clone", "https://github.com/elm-lang/" ++ projectName ++ ".git" ] |
| 151 | + setCurrentDirectory projectName |
| 152 | + git [ "checkout", version, "--quiet" ] |
| 153 | + |
| 154 | + -- move back into the root |
| 155 | + setCurrentDirectory root |
| 156 | + |
| 157 | + |
| 158 | +-- HELPER FUNCTIONS |
| 159 | + |
| 160 | +cabal :: [String] -> IO ExitCode |
| 161 | +cabal = rawSystem "cabal" |
| 162 | + |
| 163 | +git :: [String] -> IO ExitCode |
| 164 | +git = rawSystem "git" |
0 commit comments