on master help sign in
Check environment variable ELM_HOME if the files were not placed by cabal
commit33bd016678c6e09664b11bd818c493293a4573e8 authorEvan Czaplicki <info@elm-lang.org> dateMon 10 Feb 2014, 23:03 (13 years ago) parent8971b79
2 files changed+21−6
compiler/Elm/Internal/Paths.hs+18−3 compiler/Metadata/Prelude.hs+3−3
compiler/Elm/Internal/Paths.hs+18−3
@@ -1,6 +1,10 @@
1+{-# OPTIONS_GHC -Wall #-}
12module Elm.Internal.Paths where
23
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)
48import qualified Paths_Elm as This
59
610-- |Name of directory for all of a project's dependencies.
@@ -15,9 +19,20 @@ dependencyFile = "elm_dependencies.json"
1519{-# NOINLINE runtime #-}
1620-- |The absolute path to Elm's runtime system.
1721runtime :: FilePath
18−runtime = unsafePerformIO $ This.getDataFileName "elm-runtime.js"
22+runtime = unsafePerformIO $ getDataFile "elm-runtime.js"
1923
2024{-# NOINLINE docs #-}
2125-- |The absolute path to Elm's core library documentation.
2226docs :: FilePath
23−docs = unsafePerformIO $ This.getDataFileName "docs.json"
27+docs = unsafePerformIO $ getDataFile "docs.json"
28+
29+-- |The absolute path to a data file
30+getDataFile :: FilePath -> IO FilePath
31+getDataFile name = do
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
33
44import qualified Data.Map as Map
55import qualified Control.Exception as E
6−import qualified Paths_Elm as Path
6+import qualified Elm.Internal.Paths as Path
77import System.Exit
88import System.IO
99import SourceSyntax.Module
@@ -30,8 +30,8 @@ prelude = string : text ++ map (\n -> (n, Hiding [])) modules
3030interfaces :: Bool -> IO Interfaces
3131interfaces noPrelude =
3232 if noPrelude
33− then return $ Map.empty
34− else safeReadDocs =<< Path.getDataFileName "interfaces.data"
33+ then return Map.empty
34+ else safeReadDocs =<< Path.getDataFile "interfaces.data"
3535
3636safeReadDocs :: FilePath -> IO Interfaces
3737safeReadDocs name =