on master help sign in
Move getDataFile function so that it is not exposed to the outside world
2cfb343Evan Czaplicki
compiler/Build/Utils.hs+14
@@ -1,8 +1,11 @@
1{-# OPTIONS_GHC -W #-}
1{-# OPTIONS_GHC -W #-}
2module Build.Utils where
2module Build.Utils where
3
3
4+import System.Directory (doesFileExist)
5+import System.Environment (getEnv)
4import System.FilePath ((</>), replaceExtension)
6import System.FilePath ((</>), replaceExtension)
5import qualified Build.Flags as Flag
7import qualified Build.Flags as Flag
8+import qualified Paths_Elm as This
6
9
7buildPath :: Flag.Flags -> FilePath -> String -> FilePath
10buildPath :: Flag.Flags -> FilePath -> String -> FilePath
8buildPath flags filePath ext =
11buildPath flags filePath ext =
@@ -19,3 +22,14 @@ elmo flags filePath =
19elmi :: Flag.Flags -> FilePath -> FilePath
22elmi :: Flag.Flags -> FilePath -> FilePath
20elmi flags filePath =
23elmi flags filePath =
21 cachePath flags filePath "elmi"
24 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 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2module Elm.Internal.Paths where
2module Elm.Internal.Paths where
3
3
4−import System.Directory (doesFileExist)
4+import Build.Utils (getDataFile)
5−import System.Environment (getEnv)
6−import System.FilePath ((</>))
7import System.IO.Unsafe (unsafePerformIO)
5import System.IO.Unsafe (unsafePerformIO)
8−import qualified Paths_Elm as This
9
6
10-- |Name of directory for all of a project's dependencies.
7-- |Name of directory for all of a project's dependencies.
11dependencyDirectory :: FilePath
8dependencyDirectory :: FilePath
@@ -25,14 +22,3 @@ runtime = unsafePerformIO $ getDataFile "elm-runtime.js"
25-- |The absolute path to Elm's core library documentation.
22-- |The absolute path to Elm's core library documentation.
26docs :: FilePath
23docs :: FilePath
27docs = unsafePerformIO $ getDataFile "docs.json"
24docs = 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
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 Elm.Internal.Paths as Path
7import System.Exit
6import System.Exit
8import System.IO
7import System.IO
9import SourceSyntax.Module
8import SourceSyntax.Module
10import qualified Build.Interface as Interface
9import qualified Build.Interface as Interface
10+import Build.Utils (getDataFile)
11
11
12add :: Bool -> Module def -> Module def
12add :: Bool -> Module def -> Module def
13add noPrelude (Module name exs ims decls) = Module name exs (customIms ++ ims) decls
13add noPrelude (Module name exs ims decls) = Module name exs (customIms ++ ims) decls
@@ -31,7 +31,7 @@ interfaces :: 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.getDataFile "interfaces.data"
34+ else safeReadDocs =<< getDataFile "interfaces.data"
35
35
36safeReadDocs :: FilePath -> IO Interfaces
36safeReadDocs :: FilePath -> IO Interfaces
37safeReadDocs name =
37safeReadDocs name =