module Haste.Environment (hasteDir, jsmodDir, hasteInstDir, pkgDir, pkgLibDir,
jsDir, hostWordSize, runAndWait, hasteBinary,
hastePkgBinary, hasteInstHisBinary, hasteInstBinary,
hasteCopyPkgBinary, closureCompiler) where
import System.Process
import System.IO.Unsafe
import System.FilePath
import Data.Bits (bitSize)
import Foreign.C.Types (CIntPtr)
import System.Environment.Executable
import System.Directory
import System.Exit
import Paths_haste_compiler
currentBinDir :: FilePath
currentBinDir = dropFileName . unsafePerformIO $ getExecutablePath
#if defined(PORTABLE) || defined(PORTABLE_COMPILER)
hasteBinDir :: FilePath
hasteBinDir = currentBinDir
jsDir :: FilePath
jsDir = hasteBinDir </> "js"
#else
hasteBinDir :: FilePath
hasteBinDir = unsafePerformIO $ getBinDir
jsDir :: FilePath
jsDir = unsafePerformIO $ getDataDir
#endif
#if defined(PORTABLE)
hasteDir :: FilePath
hasteDir = hasteBinDir
#else
hasteDir :: FilePath
hasteDir = unsafePerformIO $ getAppUserDataDirectory "haste"
#endif
jsmodDir :: FilePath
jsmodDir = hasteDir </> "jsmods"
hasteInstDir :: FilePath
hasteInstDir = hasteDir </> "libraries"
pkgDir :: FilePath
pkgDir = hasteDir </> "packages"
hostWordSize :: Int
hostWordSize = bitSize (undefined :: CIntPtr)
pkgLibDir :: FilePath
pkgLibDir = hasteInstDir </> "lib"
runAndWait :: FilePath -> [String] -> Maybe FilePath -> IO ()
runAndWait file args workDir = do
h <- runProcess file args workDir Nothing Nothing Nothing Nothing
ec <- waitForProcess h
case ec of
ExitFailure _ -> exitFailure
_ -> return ()
hasteBinary :: FilePath
hasteBinary = hasteBinDir </> "hastec"
hastePkgBinary :: FilePath
hastePkgBinary = hasteBinDir </> "haste-pkg"
hasteCopyPkgBinary :: FilePath
hasteCopyPkgBinary = hasteBinDir </> "haste-copy-pkg"
hasteInstBinary :: FilePath
hasteInstBinary = hasteBinDir </> "haste-inst"
hasteInstHisBinary :: FilePath
hasteInstHisBinary = hasteBinDir </> "haste-install-his"
closureCompiler :: FilePath
closureCompiler = hasteDir </> "compiler.jar"