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 #-}
|
{-# OPTIONS_GHC -W #-}
|
||||||
module Build.Utils where
|
module Build.Utils where
|
||||||
|
|
||||||
|
import System.Directory (doesFileExist)
|
||||||
|
import System.Environment (getEnv)
|
||||||
import System.FilePath ((</>), replaceExtension)
|
import System.FilePath ((</>), replaceExtension)
|
||||||
import qualified Build.Flags as Flag
|
import qualified Build.Flags as Flag
|
||||||
|
import qualified Paths_Elm as This
|
||||||
|
|
||||||
buildPath :: Flag.Flags -> FilePath -> String -> FilePath
|
buildPath :: Flag.Flags -> FilePath -> String -> FilePath
|
||||||
buildPath flags filePath ext =
|
buildPath flags filePath ext =
|
||||||
|
@ -19,3 +22,14 @@ elmo flags filePath =
|
||||||
elmi :: Flag.Flags -> FilePath -> FilePath
|
elmi :: Flag.Flags -> FilePath -> FilePath
|
||||||
elmi flags filePath =
|
elmi flags filePath =
|
||||||
cachePath flags filePath "elmi"
|
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 #-}
|
{-# OPTIONS_GHC -Wall #-}
|
||||||
module Elm.Internal.Paths where
|
module Elm.Internal.Paths where
|
||||||
|
|
||||||
import System.Directory (doesFileExist)
|
import Build.Utils (getDataFile)
|
||||||
import System.Environment (getEnv)
|
|
||||||
import System.FilePath ((</>))
|
|
||||||
import System.IO.Unsafe (unsafePerformIO)
|
import System.IO.Unsafe (unsafePerformIO)
|
||||||
import qualified Paths_Elm as This
|
|
||||||
|
|
||||||
-- |Name of directory for all of a project's dependencies.
|
-- |Name of directory for all of a project's dependencies.
|
||||||
dependencyDirectory :: FilePath
|
dependencyDirectory :: FilePath
|
||||||
|
@ -25,14 +22,3 @@ runtime = unsafePerformIO $ getDataFile "elm-runtime.js"
|
||||||
-- |The absolute path to Elm's core library documentation.
|
-- |The absolute path to Elm's core library documentation.
|
||||||
docs :: FilePath
|
docs :: FilePath
|
||||||
docs = unsafePerformIO $ getDataFile "docs.json"
|
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 Data.Map as Map
|
||||||
import qualified Control.Exception as E
|
import qualified Control.Exception as E
|
||||||
import qualified Elm.Internal.Paths as Path
|
|
||||||
import System.Exit
|
import System.Exit
|
||||||
import System.IO
|
import System.IO
|
||||||
import SourceSyntax.Module
|
import SourceSyntax.Module
|
||||||
import qualified Build.Interface as Interface
|
import qualified Build.Interface as Interface
|
||||||
|
import Build.Utils (getDataFile)
|
||||||
|
|
||||||
add :: Bool -> Module def -> Module def
|
add :: Bool -> Module def -> Module def
|
||||||
add noPrelude (Module name exs ims decls) = Module name exs (customIms ++ ims) decls
|
add noPrelude (Module name exs ims decls) = Module name exs (customIms ++ ims) decls
|
||||||
|
@ -31,7 +31,7 @@ interfaces :: Bool -> IO Interfaces
|
||||||
interfaces noPrelude =
|
interfaces noPrelude =
|
||||||
if noPrelude
|
if noPrelude
|
||||||
then return Map.empty
|
then return Map.empty
|
||||||
else safeReadDocs =<< Path.getDataFile "interfaces.data"
|
else safeReadDocs =<< getDataFile "interfaces.data"
|
||||||
|
|
||||||
safeReadDocs :: FilePath -> IO Interfaces
|
safeReadDocs :: FilePath -> IO Interfaces
|
||||||
safeReadDocs name =
|
safeReadDocs name =
|
||||||
|
|
Loading…
Reference in a new issue