executable-path 0.0.2 → 0.0.3
raw patch · 2 files changed
+65/−9 lines, 2 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
+ System.Environment.Executable: Executable :: FilePath -> ScriptPath
+ System.Environment.Executable: Interactive :: ScriptPath
+ System.Environment.Executable: RunGHC :: FilePath -> ScriptPath
+ System.Environment.Executable: data ScriptPath
+ System.Environment.Executable: getScriptPath :: IO ScriptPath
+ System.Environment.Executable: instance Show ScriptPath
Files
System/Environment/Executable.hs view
@@ -42,13 +42,25 @@ #ifdef darwin_HOST_OS , getApplicationBundlePath #endif++#ifdef WE_HAVE_GHC+ , ScriptPath(..)+ , getScriptPath+#endif ) where import Control.Monad (liftM) import System.FilePath (splitFileName)+import System.Directory (canonicalizePath)+import Data.Char (toLower)+import Data.List (find,findIndex) +#ifdef WE_HAVE_GHC+import GHC.Environment+#endif+ -------------------------------------------------------------------------------- #ifdef mingw32_HOST_OS@@ -97,6 +109,52 @@ {-# WARNING getExecutablePath "the host OS is not supported!" #-} getExecutablePath :: IO String getExecutablePath = error "host OS not supported"+#endif++--------------------------------------------------------------------------------++#ifdef WE_HAVE_GHC++-- | An experimental hack which tries to figure out if the program+-- was run with @runghc@ or @runhaskell@ or @ghci@, and then tries to find +-- out the directory of the /source/ (or object file).+--+-- GHC only.+getScriptPath :: IO ScriptPath+getScriptPath = do+ fargs <- getFullArgs+ exec <- getExecutablePath+ let (pt,fn) = splitFileName exec+ case fargs of+ [] -> return (Executable exec)+ _ -> case map toLower fn of+#ifdef mingw32_HOST_OS+ "ghc.exe" -> do+#else+ "ghc" -> do+#endif+ case find f1 fargs of + Just s -> do+ path <- canonicalizePath $ init (drop n1 s)+ return $ RunGHC path + Nothing -> case findIndex f2 fargs of+ Just i -> return Interactive+ Nothing -> return (Executable exec)+ _ -> return (Executable exec)++ where+ f1 xs = take n1 xs == s1+ s1 = ":set prog \""+ n1 = length s1++ f2 xs = xs == "--interactive"+ +data ScriptPath+ = Executable FilePath -- ^ it was (probably) a proper compiled executable+ | RunGHC FilePath -- ^ it was a script run by runghc/runhaskell+ | Interactive -- ^ we are in GHCi+ deriving Show+ #endif --------------------------------------------------------------------------------
executable-path.cabal view
@@ -1,5 +1,5 @@ Name: executable-path-Version: 0.0.2+Version: 0.0.3 Synopsis: Finding out the full path of the executable. Description: The documentation of "System.Environment.getProgName" says that@@ -17,18 +17,16 @@ Homepage: http://code.haskell.org/~bkomuves/ Stability: Experimental Category: System-Tested-With: GHC == 6.10.1 +Tested-With: GHC == 6.12.3 Cabal-Version: >= 1.2 Build-Type: Simple -Flag splitBase- Description: Choose the new smaller, split-up base package.- Library- if flag(splitBase)- Build-Depends: base >= 3 && < 5 , filepath - else- Build-Depends: base >= 2 && < 3+ Build-Depends: base >= 3 && < 5 , filepath + + if impl(ghc)+ cpp-options: -DWE_HAVE_GHC+ build-depends: directory Exposed-Modules: System.Environment.Executable Extensions: ForeignFunctionInterface, CPP, EmptyDataDecls