on master help sign in
Move getDataFile function so that it is not exposed to the outside world
commit2cfb343e9361fccff9b3a1fae29717561ef1dbdb authorEvan Czaplicki <info@elm-lang.org> dateThu 13 Feb 2014, 09:31 (13 years ago) parentefdc7a7
3 files changed+17−17
compiler/Build/Utils.hs+14 compiler/Elm/Internal/Paths.hs+1−15 compiler/Metadata/Prelude.hs+2−2
compiler/Build/Utils.hs+14
@@ -1,8 +1,11 @@
11{-# OPTIONS_GHC -W #-}
22module Build.Utils where
33
4+import System.Directory (doesFileExist)
5+import System.Environment (getEnv)
46import System.FilePath ((</>), replaceExtension)
57import qualified Build.Flags as Flag
8+import qualified Paths_Elm as This
69
710buildPath :: Flag.Flags -> FilePath -> String -> FilePath
811buildPath flags filePath ext =
@@ -19,3 +22,14 @@ elmo flags filePath =
1922elmi :: Flag.Flags -> FilePath -> FilePath
2023elmi flags filePath =
2124 cachePath flags filePath "elmi"
25+
26+-- |The absolute path to a data file
27+getDataFile :: FilePath -> IO FilePath
28+getDataFile name = do
29+ path <- This.getDataFileName name
30+ exists <- doesFileExist path
31+ if exists
32+ then return path
33+ else do
34+ env <- getEnv "ELM_HOME"
35+ return (env </> name)
compiler/Elm/Internal/Paths.hs+1−15
@@ -1,11 +1,8 @@
11{-# OPTIONS_GHC -Wall #-}
22module Elm.Internal.Paths where
33
4−import System.Directory (doesFileExist)
5−import System.Environment (getEnv)
6−import System.FilePath ((</>))
4+import Build.Utils (getDataFile)
75import System.IO.Unsafe (unsafePerformIO)
8−import qualified Paths_Elm as This
96
107-- |Name of directory for all of a project's dependencies.
118dependencyDirectory :: FilePath
@@ -25,14 +22,3 @@ runtime = unsafePerformIO $ getDataFile "elm-runtime.js"
2522-- |The absolute path to Elm's core library documentation.
2623docs :: FilePath
2724docs = 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 <- doesFileExist path
34− if exists
35− then return path
36− else do
37− env <- getEnv "ELM_HOME"
38− return (env </> name)
compiler/Metadata/Prelude.hs+2−2
@@ -3,11 +3,11 @@ module Metadata.Prelude (interfaces, add) where
33
44import qualified Data.Map as Map
55import qualified Control.Exception as E
6−import qualified Elm.Internal.Paths as Path
76import System.Exit
87import System.IO
98import SourceSyntax.Module
109import qualified Build.Interface as Interface
10+import Build.Utils (getDataFile)
1111
1212add :: Bool -> Module def -> Module def
1313add noPrelude (Module name exs ims decls) = Module name exs (customIms ++ ims) decls
@@ -31,7 +31,7 @@ interfaces :: Bool -> IO Interfaces
3131interfaces noPrelude =
3232 if noPrelude
3333 then return Map.empty
34− else safeReadDocs =<< Path.getDataFile "interfaces.data"
34+ else safeReadDocs =<< getDataFile "interfaces.data"
3535
3636safeReadDocs :: FilePath -> IO Interfaces
3737safeReadDocs name =