@@ -1,73 +0,0 @@
1−{-# OPTIONS_GHC -W #-}
2−module Build.Utils where
3−
4−import Control.Monad.Error
5−import System.Directory (doesFileExist)
6−import System.Environment (getEnv)
7−import System.FilePath ((</>), replaceExtension)
8−import System.IO.Error (tryIOError)
9−import System.IO.Unsafe (unsafePerformIO)
10−import qualified Build.Flags as Flag
11−import qualified Build.Print as Print
12−import qualified Paths_Elm as This
13−
14−buildPath :: Flag.Flags -> FilePath -> String -> FilePath
15−buildPath flags filePath ext =
16− Flag.build_dir flags </> replaceExtension filePath ext
17−
18−cachePath :: Flag.Flags -> FilePath -> String -> FilePath
19−cachePath flags filePath ext =
20− Flag.cache_dir flags </> replaceExtension filePath ext
21−
22−elmo :: Flag.Flags -> FilePath -> FilePath
23−elmo flags filePath =
24− cachePath flags filePath "elmo"
25−
26−elmi :: Flag.Flags -> FilePath -> FilePath
27−elmi flags filePath =
28− cachePath flags filePath "elmi"
29−
30−
31−{-# NOINLINE runtime #-}
32−-- |The absolute path to Elm's runtime system.
33−runtime :: FilePath
34−runtime =
35− unsafePerformIO $ getDataFile "elm-runtime.js"
36−
37−
38−-- |The absolute path to a data file
39−getDataFile :: FilePath -> IO FilePath
40−getDataFile name = do
41− path <- This.getDataFileName name
42− exists <- doesFileExist path
43− if exists
44− then return path
45− else do
46− environment <- tryIOError (getEnv "ELM_HOME")
47− case environment of
48− Right env -> return (env </> "compiler" </> name)
49− Left _ ->
50− fail $ unlines
51− [ "Unable to find the ELM_HOME environment variable when searching"
52− , "for the " ++ name ++ " file."
53− , ""
54− , "If you installed Elm Platform with the Mac or Windows installer, it looks like"
55− , "ELM_HOME was not set automatically. Look up how to set environment variables"
56− , "on your platform and set ELM_HOME to the directory that contains Elm's static"
57− , "files:"
58− , ""
59− , " * On Mac it is /usr/local/share/elm"
60− , " * On Windows it is one of the following:"
61− , " C:/Program Files/Elm Platform/0.13/share"
62− , " C:/Program Files (x86)/Elm Platform/0.13/share"
63− , ""
64− , "If it seems like a more complex issue, please report it here:"
65− , " <https://github.com/elm-lang/elm-platform/issues>"
66− ]
67−
68−run :: ErrorT String IO a -> IO a
69−run command = do
70− either <- runErrorT command
71− case either of
72− Left err -> Print.failure err
73− Right result -> return result