@@ -74,6 +74,7 @@ import Data.Version (Version)
74
74
#endif
75
75
76
76
#if Cabal2
77
+ import Control.Monad (filterM )
77
78
import Distribution.Package (unPackageName , depPkgName , PackageName )
78
79
import Distribution.PackageDescription.Configuration (finalizePD )
79
80
import Distribution.Types.ComponentRequestedSpec (ComponentRequestedSpec (.. ))
@@ -82,6 +83,7 @@ import Distribution.Types.UnqualComponentName (unUnqualComponentName)
82
83
import qualified Distribution.Version as CabalVersion
83
84
import Distribution.Types.Benchmark (Benchmark (benchmarkName ))
84
85
import Distribution.Types.TestSuite (TestSuite (testName ))
86
+ import System.Directory (doesDirectoryExist )
85
87
#else
86
88
import Control.Arrow (second )
87
89
import Data.Version (showVersion )
@@ -157,30 +159,48 @@ getBuildDirectories
157
159
:: TargetTool
158
160
-> PackageDescription
159
161
-> FilePath
160
- -> IO ([FilePath ], FilePath )
162
+ -> IO ([FilePath ], [ FilePath ] )
161
163
getBuildDirectories tool pkgDesc cabalDir = do
162
164
distDir' <- distDir tool
163
165
let buildDir :: FilePath
164
166
buildDir = cabalDir </> distDir' </> " build"
165
- -- 'dist/bulid/autogen' OR '.stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/autogen/'
166
- autogenDir :: FilePath
167
- autogenDir = buildDir </> " autogen"
168
167
169
- componentBuildDir :: (a -> String ) -> a -> FilePath
170
- componentBuildDir componentName component =
171
- buildDir </> componentName component </> (componentName component ++ " -tmp" )
168
+ componentNames :: [String ]
169
+ componentNames =
170
+ map getExeName (executables pkgDesc) ++
171
+ map getTestName (testSuites pkgDesc) ++
172
+ map getBenchName (benchmarks pkgDesc)
173
+
174
+
175
+ autogenDirs <- getAutogenDirs buildDir componentNames
176
+
177
+ let componentBuildDir :: String -> FilePath
178
+ componentBuildDir componentName =
179
+ buildDir </> componentName </> (componentName ++ " -tmp" )
172
180
173
181
buildDirs :: [FilePath ]
174
182
buildDirs =
175
- autogenDir :
176
- map (componentBuildDir getExeName) (executables pkgDesc) ++
177
- map (componentBuildDir getTestName) (testSuites pkgDesc) ++
178
- map (componentBuildDir getBenchName) (benchmarks pkgDesc)
183
+ autogenDirs ++
184
+ map componentBuildDir componentNames
179
185
180
186
buildDirs' = case library pkgDesc of
181
187
Just _ -> buildDir : buildDirs
182
188
Nothing -> buildDirs
183
- return (buildDirs', autogenDir)
189
+ return (buildDirs', autogenDirs)
190
+
191
+ getAutogenDirs :: FilePath -> [String ] -> IO [FilePath ]
192
+ getAutogenDirs buildDir componentNames =
193
+ fmap (autogenDir : ) $
194
+ #if Cabal2
195
+ filterM doesDirectoryExist $
196
+ map (\ path -> buildDir </> path </> " autogen" ) componentNames
197
+ #else
198
+ const (return [] ) componentNames
199
+ #endif
200
+ where
201
+ -- 'dist/bulid/autogen' OR '.stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/autogen'
202
+ autogenDir :: FilePath
203
+ autogenDir = buildDir </> " autogen"
184
204
185
205
getSourceDirectories :: [BuildInfo ] -> FilePath -> [String ]
186
206
getSourceDirectories buildInfo cabalDir =
@@ -217,10 +237,10 @@ isAllowedOption opt =
217
237
218
238
dumpPackageDescription :: PackageDescription -> FilePath -> IO Sexp
219
239
dumpPackageDescription pkgDesc cabalFile = do
220
- (cabalDirs, autogenDir) <- getBuildDirectories Cabal pkgDesc cabalDir
221
- (stackDirs, autogenDir' ) <- getBuildDirectories Stack pkgDesc cabalDir
240
+ (cabalDirs, cabalAutogen) <- getBuildDirectories Cabal pkgDesc cabalDir
241
+ (stackDirs, stackAutogen ) <- getBuildDirectories Stack pkgDesc cabalDir
222
242
let buildDirs = cabalDirs ++ stackDirs
223
- autogenDirs = [autogenDir, autogenDir']
243
+ autogenDirs = cabalAutogen ++ stackAutogen
224
244
return $
225
245
SList
226
246
[ cons (sym " build-directories" ) (ordNub (map normalise buildDirs))
0 commit comments