module Haste.Environment (
hasteSysDir, jsmodSysDir, hasteCabalSysDir, pkgSysDir, pkgSysLibDir, jsDir,
hasteUserDir, jsmodUserDir, hasteCabalUserDir, pkgUserDir, pkgUserLibDir,
hasteGhcLibDir,
hostWordSize,
ghcPkgBinary, ghcBinary,
hasteBinary, hastePkgBinary, hasteInstHisBinary, hasteCabalBinary,
hasteCopyPkgBinary, closureCompiler, portableHaste,
hasteNeedsReboot, hasteCabalNeedsReboot, bootFile
) where
import System.IO.Unsafe
import Data.Bits
import Foreign.C.Types (CIntPtr)
import Control.Shell hiding (hClose)
import Paths_haste_compiler
import System.IO
import Haste.GHCPaths (ghcPkgBinary, ghcBinary)
import Haste.Version
#if defined(PORTABLE)
import System.Environment (getExecutablePath)
#endif
hasteGhcLibDir :: FilePath
#ifdef mingw32_HOST_OS
hasteGhcLibDir = unsafePerformIO $ do
eout <- shell $ run ghcBinary ["--print-libdir"] ""
case eout of
Right out -> return $ init out
_ -> error $ "This Haste build requires a working " ++
"Haskell Platform install!"
#else
hasteGhcLibDir = hasteSysDir
#endif
#if defined(PORTABLE)
portableHaste :: Bool
portableHaste = True
hasteSysDir :: FilePath
hasteSysDir =
joinPath . init . init . splitPath $ unsafePerformIO getExecutablePath
hasteBinDir :: FilePath
hasteBinDir = hasteSysDir </> "bin"
jsDir :: FilePath
jsDir = hasteSysDir </> "js"
#else
portableHaste :: Bool
portableHaste = False
hasteSysDir :: FilePath
hasteSysDir = hasteUserDir
hasteBinDir :: FilePath
hasteBinDir = unsafePerformIO $ getBinDir
jsDir :: FilePath
jsDir = unsafePerformIO $ getDataDir
#endif
hasteUserDir :: FilePath
Right hasteUserDir =
unsafePerformIO . shell . withAppDirectory "haste" $ \d -> do
return $ d </> showBootVersion bootVersion
jsmodSysDir :: FilePath
jsmodSysDir = hasteSysDir </> "jsmods"
hasteCabalSysDir :: FilePath
hasteCabalSysDir = hasteSysDir </> "libraries"
pkgSysLibDir :: FilePath
pkgSysLibDir = hasteCabalSysDir </> "lib"
pkgSysDir :: FilePath
pkgSysDir = hasteSysDir </> "package.conf.d"
jsmodUserDir :: FilePath
jsmodUserDir = hasteUserDir </> "jsmods"
hasteCabalUserDir :: FilePath
hasteCabalUserDir = hasteUserDir </> "libraries"
pkgUserLibDir :: FilePath
pkgUserLibDir = hasteCabalUserDir </> "lib"
pkgUserDir :: FilePath
pkgUserDir = hasteUserDir </> "package.conf.d"
hostWordSize :: Int
#if __GLASGOW_HASKELL__ >= 708
hostWordSize = finiteBitSize (undefined :: CIntPtr)
#else
hostWordSize = bitSize (undefined :: CIntPtr)
#endif
hasteBinary :: FilePath
hasteBinary = hasteBinDir </> "hastec"
hastePkgBinary :: FilePath
hastePkgBinary = hasteBinDir </> "haste-pkg"
hasteCopyPkgBinary :: FilePath
hasteCopyPkgBinary = hasteBinDir </> "haste-copy-pkg"
hasteCabalBinary :: FilePath
hasteCabalBinary = hasteBinDir </> "haste-cabal"
hasteInstHisBinary :: FilePath
hasteInstHisBinary = hasteBinDir </> "haste-install-his"
closureCompiler :: FilePath
closureCompiler = hasteSysDir </> "compiler.jar"
bootFile :: FilePath
bootFile = hasteUserDir </> "booted"
hasteNeedsReboot :: Bool
#ifdef PORTABLE
hasteNeedsReboot = False
#else
hasteNeedsReboot = hasteCabalNeedsReboot
#endif
hasteCabalNeedsReboot :: Bool
hasteCabalNeedsReboot = unsafePerformIO $ do
exists <- shell $ isFile bootFile
case exists of
Right True -> do
fh <- openFile bootFile ReadMode
bootedVerString <- hGetLine fh
hClose fh
case parseBootVersion bootedVerString of
Just (BootVer hasteVer ghcVer) ->
return $ hasteVer /= hasteVersion || ghcVer /= ghcVersion
_ ->
return True
_ -> do
return True