Move getDataFile function so that it is not exposed to the outside world
This commit is contained in:
parent
efdc7a7744
commit
2cfb343e93
3 changed files with 17 additions and 17 deletions
|
@ -1,8 +1,11 @@
|
|||
{-# OPTIONS_GHC -W #-}
|
||||
module Build.Utils where
|
||||
|
||||
import System.Directory (doesFileExist)
|
||||
import System.Environment (getEnv)
|
||||
import System.FilePath ((</>), replaceExtension)
|
||||
import qualified Build.Flags as Flag
|
||||
import qualified Paths_Elm as This
|
||||
|
||||
buildPath :: Flag.Flags -> FilePath -> String -> FilePath
|
||||
buildPath flags filePath ext =
|
||||
|
@ -19,3 +22,14 @@ elmo flags filePath =
|
|||
elmi :: Flag.Flags -> FilePath -> FilePath
|
||||
elmi flags filePath =
|
||||
cachePath flags filePath "elmi"
|
||||
|
||||
-- |The absolute path to a data file
|
||||
getDataFile :: FilePath -> IO FilePath
|
||||
getDataFile name = do
|
||||
path <- This.getDataFileName name
|
||||
exists <- doesFileExist path
|
||||
if exists
|
||||
then return path
|
||||
else do
|
||||
env <- getEnv "ELM_HOME"
|
||||
return (env </> name)
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
{-# OPTIONS_GHC -Wall #-}
|
||||
module Elm.Internal.Paths where
|
||||
|
||||
import System.Directory (doesFileExist)
|
||||
import System.Environment (getEnv)
|
||||
import System.FilePath ((</>))
|
||||
import Build.Utils (getDataFile)
|
||||
import System.IO.Unsafe (unsafePerformIO)
|
||||
import qualified Paths_Elm as This
|
||||
|
||||
-- |Name of directory for all of a project's dependencies.
|
||||
dependencyDirectory :: FilePath
|
||||
|
@ -25,14 +22,3 @@ runtime = unsafePerformIO $ getDataFile "elm-runtime.js"
|
|||
-- |The absolute path to Elm's core library documentation.
|
||||
docs :: FilePath
|
||||
docs = unsafePerformIO $ getDataFile "docs.json"
|
||||
|
||||
-- |The absolute path to a data file
|
||||
getDataFile :: FilePath -> IO FilePath
|
||||
getDataFile name = do
|
||||
path <- This.getDataFileName name
|
||||
exists <- doesFileExist path
|
||||
if exists
|
||||
then return path
|
||||
else do
|
||||
env <- getEnv "ELM_HOME"
|
||||
return (env </> name)
|
||||
|
|
|
@ -3,11 +3,11 @@ module Metadata.Prelude (interfaces, add) where
|
|||
|
||||
import qualified Data.Map as Map
|
||||
import qualified Control.Exception as E
|
||||
import qualified Elm.Internal.Paths as Path
|
||||
import System.Exit
|
||||
import System.IO
|
||||
import SourceSyntax.Module
|
||||
import qualified Build.Interface as Interface
|
||||
import Build.Utils (getDataFile)
|
||||
|
||||
add :: Bool -> Module def -> Module def
|
||||
add noPrelude (Module name exs ims decls) = Module name exs (customIms ++ ims) decls
|
||||
|
@ -31,7 +31,7 @@ interfaces :: Bool -> IO Interfaces
|
|||
interfaces noPrelude =
|
||||
if noPrelude
|
||||
then return Map.empty
|
||||
else safeReadDocs =<< Path.getDataFile "interfaces.data"
|
||||
else safeReadDocs =<< getDataFile "interfaces.data"
|
||||
|
||||
safeReadDocs :: FilePath -> IO Interfaces
|
||||
safeReadDocs name =
|
||||
|
|
Loading…
Reference in a new issue