@@ -23,23 +23,25 @@ import Distribution.ModuleName (ModuleName,
23
23
toFilePath )
24
24
import Distribution.Package (pkgName ,
25
25
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 ),
28
28
ForeignLib (foreignLibBuildInfo , foreignLibName ),
29
29
Library (libBuildInfo , libName ),
30
30
LibraryName (.. ),
31
31
benchmarkModules ,
32
32
exeModules ,
33
33
explicitLibModules ,
34
- foreignLibModules )
34
+ foreignLibModules , TestSuiteInterface ( TestSuiteExeV10 ), BenchmarkInterface ( BenchmarkExeV10 ) )
35
35
import Distribution.PackageDescription.Configuration
36
36
import Distribution.PackageDescription.Parsec
37
37
import Distribution.Types.BuildInfo
38
38
import Distribution.Types.PackageDescription
39
39
import Distribution.Types.TestSuite
40
40
import Distribution.Types.UnqualComponentName
41
41
import Distribution.Utils.Path (getSymbolicPath )
42
- import System.FilePath ((</>) )
42
+ import System.FilePath ((</>) , (<.>) )
43
+ import GHC.IO (unsafePerformIO )
44
+ import System.Directory (doesFileExist )
43
45
44
46
45
47
type Name = Text
@@ -147,20 +149,35 @@ extractPackage PackageDescription{..} = Package n cc where
147
149
n = T. pack . unPackageName $ pkgName package
148
150
149
151
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
160
162
, srcDir <- map getSymbolicPath $ hsSourceDirs bi
163
+ , let fp = srcDir </> fp0
164
+ , unsafePerformIO $ doesFileExist fp
161
165
]
162
166
163
167
unqName = T. pack . unUnqualComponentName
164
168
libName' x = case libName x of
165
169
LMainLibName -> " "
166
170
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