diff --git a/compiler/Build/Utils.hs b/compiler/Build/Utils.hs index 655e262..05fe161 100644 --- a/compiler/Build/Utils.hs +++ b/compiler/Build/Utils.hs @@ -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) diff --git a/compiler/Elm/Internal/Paths.hs b/compiler/Elm/Internal/Paths.hs index 3441691..0fb9ad0 100644 --- a/compiler/Elm/Internal/Paths.hs +++ b/compiler/Elm/Internal/Paths.hs @@ -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) diff --git a/compiler/Metadata/Prelude.hs b/compiler/Metadata/Prelude.hs index e78c1a4..7a6239b 100644 --- a/compiler/Metadata/Prelude.hs +++ b/compiler/Metadata/Prelude.hs @@ -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 =