Skip to content

Commit 25cf518

Browse files
committed
handle executable modules and filter out non-existing paths
1 parent 4a0da1c commit 25cf518

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

src/Hie/Cabal/Parser.hs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,25 @@ import Distribution.ModuleName (ModuleName,
2323
toFilePath)
2424
import Distribution.Package (pkgName,
2525
unPackageName)
26-
import Distribution.PackageDescription (Benchmark (benchmarkBuildInfo, benchmarkName),
27-
Executable (buildInfo, exeName),
26+
import Distribution.PackageDescription (Benchmark (benchmarkBuildInfo, benchmarkName, benchmarkInterface),
27+
Executable (buildInfo, exeName, modulePath),
2828
ForeignLib (foreignLibBuildInfo, foreignLibName),
2929
Library (libBuildInfo, libName),
3030
LibraryName (..),
3131
benchmarkModules,
3232
exeModules,
3333
explicitLibModules,
34-
foreignLibModules)
34+
foreignLibModules, TestSuiteInterface (TestSuiteExeV10), BenchmarkInterface (BenchmarkExeV10))
3535
import Distribution.PackageDescription.Configuration
3636
import Distribution.PackageDescription.Parsec
3737
import Distribution.Types.BuildInfo
3838
import Distribution.Types.PackageDescription
3939
import Distribution.Types.TestSuite
4040
import Distribution.Types.UnqualComponentName
4141
import Distribution.Utils.Path (getSymbolicPath)
42-
import System.FilePath ((</>))
42+
import System.FilePath ((</>), (<.>))
43+
import GHC.IO (unsafePerformIO)
44+
import System.Directory (doesFileExist)
4345

4446

4547
type Name = Text
@@ -147,20 +149,35 @@ extractPackage PackageDescription{..} = Package n cc where
147149
n = T.pack . unPackageName $ pkgName package
148150

149151
cc = concat $
150-
[mkComp Test (unqName $ testName t) (testBuildInfo t) (testModules t) | t <- testSuites] ++
151-
[mkComp Bench (unqName $ benchmarkName b) (benchmarkBuildInfo b) (benchmarkModules b) | b <- benchmarks] ++
152-
[mkComp Exe (unqName $ exeName e) (buildInfo e) (exeModules e) | e <- executables] ++
153-
[mkComp Lib (libName' l) (libBuildInfo l) (explicitLibModules l) | l <- maybeToList library ++ subLibraries ] ++
154-
[mkComp Lib (unqName $ foreignLibName f) (foreignLibBuildInfo f) (foreignLibModules f) | f <- foreignLibs]
155-
156-
mkComp :: CompType -> T.Text -> BuildInfo -> [ModuleName] -> [Component]
157-
mkComp typ name bi mods =
158-
[Comp typ name (T.pack $ srcDir </> m)
159-
| m <- map toFilePath mods
152+
[mkComp Test (unqName $ testName t) (testBuildInfo t) (testExePath t) (testModules t) | t <- testSuites] ++
153+
[mkComp Bench (unqName $ benchmarkName b) (benchmarkBuildInfo b) (benchmarkExePath b) (benchmarkModules b) | b <- benchmarks] ++
154+
[mkComp Exe (unqName $ exeName e) (buildInfo e) [modulePath e] (exeModules e) | e <- executables] ++
155+
[mkComp Lib (libName' l) (libBuildInfo l) [] (explicitLibModules l) | l <- maybeToList library ++ subLibraries ] ++
156+
[mkComp Lib (unqName $ foreignLibName f) (foreignLibBuildInfo f) [] (foreignLibModules f) | f <- foreignLibs]
157+
158+
mkComp :: CompType -> T.Text -> BuildInfo -> [FilePath] -> [ModuleName] -> [Component]
159+
mkComp typ name bi fps mods =
160+
[Comp typ name (T.pack fp)
161+
| fp0 <- fps <> concatMap toFilePath' mods
160162
, srcDir <- map getSymbolicPath $ hsSourceDirs bi
163+
, let fp = srcDir </> fp0
164+
, unsafePerformIO $ doesFileExist fp
161165
]
162166

163167
unqName = T.pack . unUnqualComponentName
164168
libName' x = case libName x of
165169
LMainLibName -> ""
166170
LSubLibName u -> unqName u
171+
172+
benchmarkExePath :: Benchmark -> [FilePath]
173+
benchmarkExePath b = case benchmarkInterface b of
174+
BenchmarkExeV10 _ f -> [f]
175+
_ -> []
176+
177+
toFilePath' :: ModuleName -> [FilePath]
178+
toFilePath' mod = [ toFilePath mod <.> ext | ext <- ["hs", "lhs"]]
179+
180+
testExePath :: TestSuite -> [FilePath]
181+
testExePath t = case testInterface t of
182+
TestSuiteExeV10 _ fp -> [fp]
183+
_ -> []

0 commit comments

Comments
 (0)