on master help sign in
Introduce cache/ and build/ directories

Switch from using --output-directory for all generated files, to using --cache-dir for .elmo and .elmi files and using --build-dir for .html and .js files.

commit43b604e0ca8ea62ec350d44a7f16279144a3289e authorEvan Czaplicki <info@elm-lang.org> dateTue 6 Aug 2013, 18:34 (13 years ago) parent2e38f7b
2 files changed+19−11
Setup.hs+2−1 compiler/Compiler.hs+17−10
Setup.hs+2−1
@@ -113,7 +113,8 @@ compileLibraries lbi = do
113113 -- replace 'system' call with 'runProcess' which handles args better
114114 -- and allows env variable "Elm_datadir" which is used by LoadLibraries
115115 -- to find docs.json
116− let args = ["--only-js","--make","--no-prelude","--output-directory="++out_c,file]
116+ let args = [ "--only-js", "--make", "--no-prelude"
117+ , "--cache-dir="++out_c, "--build-dir="++out_c, file ]
117118 arg = Just [("Elm_datadir", rtd_c)]
118119 handle <- runProcess elm_c args Nothing arg Nothing Nothing Nothing
119120 exitCode <- waitForProcess handle
compiler/Compiler.hs+17−10
@@ -42,7 +42,8 @@ data Flags =
4242 , scripts :: [FilePath]
4343 , no_prelude :: Bool
4444 , minify :: Bool
45− , output_directory :: FilePath
45+ , cache_dir :: FilePath
46+ , build_dir :: FilePath
4647 }
4748 deriving (Data,Typeable,Show,Eq)
4849
@@ -64,8 +65,10 @@ flags = Flags
6465 &= help "Do not import Prelude by default, used only when compiling standard libraries."
6566 , minify = False
6667 &= help "Minify generated JavaScript and HTML"
67− , output_directory = "ElmFiles" &= typFile
68− &= help "Output files to directory specified. Defaults to ElmFiles/ directory."
68+ , cache_dir = "cache" &= typFile
69+ &= help "Directory for files cached to make builds faster. Defaults to cache/ directory."
70+ , build_dir = "build" &= typFile
71+ &= help "Directory for generated HTML and JS files. Defaults to build/ directory."
6972 } &= help "Compile Elm programs to HTML, CSS, and JavaScript."
7073 &= summary ("The Elm Compiler " ++ showVersion version ++ ", (c) Evan Czaplicki")
7174
@@ -80,14 +83,17 @@ compileArgs flags =
8083 fs -> mapM_ (build flags) fs
8184
8285
83−file :: Flags -> FilePath -> String -> FilePath
84−file flags filePath ext = output_directory flags </> replaceExtension filePath ext
86+buildPath :: Flags -> FilePath -> String -> FilePath
87+buildPath flags filePath ext = build_dir flags </> replaceExtension filePath ext
88+
89+cachePath :: Flags -> FilePath -> String -> FilePath
90+cachePath flags filePath ext = cache_dir flags </> replaceExtension filePath ext
8591
8692elmo :: Flags -> FilePath -> FilePath
87−elmo flags filePath = file flags filePath "elmo"
93+elmo flags filePath = cachePath flags filePath "elmo"
8894
8995elmi :: Flags -> FilePath -> FilePath
90−elmi flags filePath = file flags filePath "elmi"
96+elmi flags filePath = cachePath flags filePath "elmi"
9197
9298
9399buildFile :: Flags -> Int -> Int -> Interfaces -> FilePath -> IO ModuleInterface
@@ -127,7 +133,8 @@ buildFile flags moduleNum numModules interfaces filePath =
127133 , replicate (max 1 (20 - length name)) ' '
128134 , "( " ++ filePath ++ " )" ]
129135 source <- readFile filePath
130− createDirectoryIfMissing True (output_directory flags)
136+ createDirectoryIfMissing True (cache_dir flags)
137+ createDirectoryIfMissing True (build_dir flags)
131138 metaModule <-
132139 case buildFromSource (no_prelude flags) interfaces source of
133140 Left errors -> do
@@ -176,13 +183,13 @@ build flags rootFile = do
176183 case only_js flags of
177184 True -> do
178185 putStr "Generating JavaScript ... "
179− writeFile (file flags rootFile "js") (genJs js)
186+ writeFile (buildPath flags rootFile "js") (genJs js)
180187 putStrLn "Done"
181188 False -> do
182189 putStr "Generating HTML ... "
183190 runtime <- getRuntime flags
184191 let html = genHtml $ createHtml runtime (takeBaseName rootFile) (sources js) moduleName ""
185− writeFile (file flags rootFile "html") html
192+ writeFile (buildPath flags rootFile "html") html
186193 putStrLn "Done"
187194
188195 where