module Distribution.MacOSX.Internal (
getMacAppsForBuildableExecutors,
osxIncantations
) where
import Prelude hiding ( catch, lookup )
import System.Cmd ( system )
import System.Exit
import System.FilePath
import Control.Monad (filterM)
import System.Directory (doesDirectoryExist)
import Data.Foldable ( foldl )
import Data.Map ( empty, insert, lookup )
import Distribution.PackageDescription (BuildInfo(..), Executable(..))
import Distribution.MacOSX.Common
getMacAppsForBuildableExecutors :: [MacApp] -> [Executable] -> [MacApp]
getMacAppsForBuildableExecutors macApps executables =
case macApps of
[] -> map mkDefault buildables
xs -> filter buildableApp xs
where
mkDefault x = MacApp (exeName x) Nothing Nothing [] [] DoNotChase
buildableApp :: MacApp -> Bool
buildableApp app = any (\e -> exeName e == appName app) buildables
buildables :: [Executable]
buildables = filter (buildable . buildInfo) executables
osxIncantations ::
FilePath
-> MacApp -> IO ()
osxIncantations appPath app =
do dtools <- developerTools
let rezExec = dtools </> "Rez Carbon.r -o " ++ appPath </> pathInApp app (appName app)
runCommand rezExec
writeFile (appPath </> "PkgInfo") "APPL????"
let setFileExec = dtools </> "SetFile -a C " ++ appPath </> "Contents"
runCommand setFileExec
return ()
runCommand :: String -> IO ()
runCommand commandExec =
do putStrLn $ "Running: " ++ commandExec
exitValue <- system commandExec
case exitValue of
ExitSuccess -> return ()
_ -> do putStrLn $ "Warning - Could not run the command \""
++ commandExec ++ "\". Please check your local `XCode` configuration."
exitFailure
developerTools :: IO FilePath
developerTools =
do ds <- filterM doesDirectoryExist cands
case ds of
[] -> do putStrLn $ "Can't find the developer tools directory. Have you installed the Developer tools?\n"
++ "I tried looking for:\n" ++ unlines (map ("* " ++) cands)
exitWith (ExitFailure 1)
(d:_) -> return d
where
cands = [ "/Applications/XCode.app/Contents/Developer/Tools"
, "/Developer/Tools"
]