on master help sign in
Check environment variable ELM_HOME if the files were not placed by cabal
33bd016Evan Czaplicki
compiler/Elm/Internal/Paths.hs+18−3
@@ -1,6 +1,10 @@
1+{-# OPTIONS_GHC -Wall #-}
1module Elm.Internal.Paths where
2module Elm.Internal.Paths where
2
3
3−import System.IO.Unsafe
4+import System.Directory (doesDirectoryExist)
5+import System.Environment (getEnv)
6+import System.FilePath ((</>))
7+import System.IO.Unsafe (unsafePerformIO)
4import qualified Paths_Elm as This
8import qualified Paths_Elm as This
5
9
6-- |Name of directory for all of a project's dependencies.
10-- |Name of directory for all of a project's dependencies.
@@ -15,9 +19,20 @@ dependencyFile = "elm_dependencies.json"
15{-# NOINLINE runtime #-}
19{-# NOINLINE runtime #-}
16-- |The absolute path to Elm's runtime system.
20-- |The absolute path to Elm's runtime system.
17runtime :: FilePath
21runtime :: FilePath
18−runtime = unsafePerformIO $ This.getDataFileName "elm-runtime.js"
22+runtime = unsafePerformIO $ getDataFile "elm-runtime.js"
19
23
20{-# NOINLINE docs #-}
24{-# NOINLINE docs #-}
21-- |The absolute path to Elm's core library documentation.
25-- |The absolute path to Elm's core library documentation.
22docs :: FilePath
26docs :: FilePath
27+docs = unsafePerformIO $ getDataFile "docs.json"
28+
29+-- |The absolute path to a data file
30+getDataFile :: FilePath -> IO FilePath
31+getDataFile name = do
23−docs = unsafePerformIO $ This.getDataFileName "docs.json"
32+ path <- This.getDataFileName name
33+ exists <- doesDirectoryExist path
34+ if exists
35+ then return path
36+ else do
37+ env <- getEnv "ELM_HOME"
38+ return (env </> name)
compiler/Metadata/Prelude.hs+3−3
@@ -3,7 +3,7 @@ module Metadata.Prelude (interfaces, add) where
3
3
4import qualified Data.Map as Map
4import qualified Data.Map as Map
5import qualified Control.Exception as E
5import qualified Control.Exception as E
6−import qualified Paths_Elm as Path
6+import qualified Elm.Internal.Paths as Path
7import System.Exit
7import System.Exit
8import System.IO
8import System.IO
9import SourceSyntax.Module
9import SourceSyntax.Module
@@ -30,8 +30,8 @@ prelude = string : text ++ map (\n -> (n, Hiding [])) modules
30interfaces :: Bool -> IO Interfaces
30interfaces :: Bool -> IO Interfaces
31interfaces noPrelude =
31interfaces noPrelude =
32 if noPrelude
32 if noPrelude
33− then return $ Map.empty
33+ then return Map.empty
34− else safeReadDocs =<< Path.getDataFileName "interfaces.data"
34+ else safeReadDocs =<< Path.getDataFile "interfaces.data"
35
35
36safeReadDocs :: FilePath -> IO Interfaces
36safeReadDocs :: FilePath -> IO Interfaces
37safeReadDocs name =
37safeReadDocs name =