From 54bb83e972d3a020a25cdfc57ddf2d4e68d9318c Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Sat, 21 Sep 2013 16:08:45 +0200 Subject: [PATCH] Must explicitly find the full path for an exe target --- Language/Haskell/GhcMod/CabalApi.hs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Language/Haskell/GhcMod/CabalApi.hs b/Language/Haskell/GhcMod/CabalApi.hs index f39a00c..8d88f98 100644 --- a/Language/Haskell/GhcMod/CabalApi.hs +++ b/Language/Haskell/GhcMod/CabalApi.hs @@ -11,6 +11,8 @@ module Language.Haskell.GhcMod.CabalApi ( import Control.Applicative ((<$>)) import Control.Exception (throwIO) +import Control.Monad (filterM) +import CoreMonad (liftIO) import Data.Maybe (maybeToList) import Data.Set (fromList, toList) import Distribution.ModuleName (ModuleName,toFilePath) @@ -165,18 +167,18 @@ getGHC = do -- | Extracting all 'Module' 'FilePath's for libraries, executables, -- tests and benchmarks. -cabalAllTargets :: PackageDescription -> ([String],[String],[String],[String]) -cabalAllTargets pd = targets +cabalAllTargets :: PackageDescription -> IO ([String],[String],[String],[String]) +cabalAllTargets pd = do + exeTargets <- mapM getExecutableTarget $ executables pd + return (libTargets,concat exeTargets,testTargets,benchTargets) where lib = case library pd of Nothing -> [] Just l -> libModules l - targets = (map toModuleString $ lib, - map (fromFilePath . modulePath) $ executables pd, - -- map toModuleString $ concatMap testModules $ testSuites pd, - concatMap getTestTargets $ map testInterface $ testSuites pd, - map toModuleString $ concatMap benchmarkModules $ benchmarks pd) + libTargets = map toModuleString $ lib + testTargets = concatMap getTestTargets $ map testInterface $ testSuites pd + benchTargets = map toModuleString $ concatMap benchmarkModules $ benchmarks pd toModuleString :: ModuleName -> String toModuleString mn = fromFilePath $ toFilePath mn @@ -188,3 +190,9 @@ cabalAllTargets pd = targets getTestTargets (TestSuiteExeV10 _ filePath) = [fromFilePath filePath] getTestTargets (TestSuiteLibV09 _ moduleName) = [toModuleString moduleName] getTestTargets (TestSuiteUnsupported _) = [] + + getExecutableTarget :: Executable -> IO [String] + getExecutableTarget exe = do + let maybeExes = [p e | p <- hsSourceDirs $ buildInfo exe, e <- [modulePath exe]] + liftIO $ filterM doesFileExist maybeExes +