{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}
module Distribution.MacOSX.Internal (
getMacAppsForBuildableExecutors,
osxIncantations
) where
#if MIN_VERSION_Cabal(2,0,0)
import Data.String (fromString)
import Distribution.Text (display)
import Distribution.Types.UnqualComponentName (unUnqualComponentName)
#endif
import Prelude hiding ( catch )
import System.Cmd ( system )
import System.Exit
import System.FilePath
import Control.Monad (filterM)
import System.Directory (doesDirectoryExist)
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
#if MIN_VERSION_Cabal(2,0,0)
mkDefault x = MacApp (unUnqualComponentName $ exeName x) Nothing Nothing [] [] DoNotChase
#else
mkDefault x = MacApp (exeName x) Nothing Nothing [] [] DoNotChase
#endif
buildableApp :: MacApp -> Bool
#if MIN_VERSION_Cabal(2,0,0)
buildableApp app = any (\e -> exeName e == fromString (appName app)) buildables
#else
buildableApp app = any (\e -> exeName e == appName app) buildables
#endif
buildables :: [Executable]
buildables = filter (buildable . buildInfo) executables
osxIncantations ::
FilePath
-> MacApp -> IO ()
osxIncantations appPath app =
do writeFile (appPath </> "PkgInfo") "APPL????"
return ()