14e32add30
See: https://github.com/evancz/Elm/issues/120 Add build-hook to Setup.hs so that elm-doc gets build and executed before library or elm exec gets built. Add preprocessor to Elm.cabal so LoadLibraries.hs can load docs.json from the build folder instead of installed folder Add touch to Setup.hs otherwise LoadLibraries.hs doesn't get recompiled. This is non-portable, but I can't find a portable way (see Setup.hs for details) cabal clean && cabal install now works (tested on ghc 7.4.1)
36 lines
1 KiB
Haskell
36 lines
1 KiB
Haskell
{-# LANGUAGE CPP #-}
|
|
|
|
module LoadLibraries (docs) where
|
|
|
|
import Language.Haskell.TH.Syntax
|
|
import Paths_Elm
|
|
import System.Directory
|
|
import System.FilePath
|
|
|
|
docs :: Q Exp
|
|
docs = liftString =<< qRunIO (readDocs dataDir)
|
|
|
|
-- When compiling elm (library and executable), docs.json isn't (yet) in the standard location
|
|
-- Therefore, Elm.cabal overrides the location.
|
|
-- Since this is only used by the TemplateHaskell, which reads the file at compile time,
|
|
-- this should be ok.
|
|
|
|
dataDir :: IO FilePath
|
|
#if defined ELM_COMPILEDATADIR
|
|
dataDir = canonicalizePath (ELM_COMPILEDATADIR </> "docs.json")
|
|
#else
|
|
dataDir = getDataFileName "docs.json"
|
|
#endif
|
|
|
|
readDocs :: IO FilePath -> IO String
|
|
readDocs path = do
|
|
name <- path
|
|
exists <- doesFileExist name
|
|
if exists then readFile name
|
|
else putStrLn warning >> return "{\"modules\":[]}"
|
|
|
|
warning = "Warning! Types for standard library not loaded properly!\n\
|
|
Run the following commands after compilation:\n\
|
|
\n\
|
|
touch compiler/Model/LoadLibraries.hs\n\
|
|
cabal install\n\n"
|