@@ -27,6 +27,7 @@ module Stack.Package
2727 ,findOrGenerateCabalFile
2828 ,hpack
2929 ,Package (.. )
30+ ,PackageDescriptionPair (.. )
3031 ,GetPackageFiles (.. )
3132 ,GetPackageOpts (.. )
3233 ,PackageConfig (.. )
@@ -153,7 +154,7 @@ readPackageBS packageConfig loc bs =
153154readPackageDescriptionDir :: (MonadLogger m , MonadIO m , MonadThrow m )
154155 => PackageConfig
155156 -> Path Abs Dir
156- -> m (GenericPackageDescription , PackageDescription )
157+ -> m (GenericPackageDescription , PackageDescriptionPair )
157158readPackageDescriptionDir config pkgDir = do
158159 cabalfp <- findOrGenerateCabalFile pkgDir
159160 gdesc <- liftM snd (readPackageUnresolved cabalfp)
@@ -212,9 +213,9 @@ resolvePackage packageConfig gpkg =
212213
213214packageFromPackageDescription :: PackageConfig
214215 -> [D. Flag ]
215- -> PackageDescription
216+ -> PackageDescriptionPair
216217 -> Package
217- packageFromPackageDescription packageConfig pkgFlags pkg =
218+ packageFromPackageDescription packageConfig pkgFlags ( PackageDescriptionPair pkgNoMod pkg) =
218219 Package
219220 { packageName = name
220221 , packageVersion = fromCabalVersion (pkgVersion pkgId)
@@ -229,16 +230,15 @@ packageFromPackageDescription packageConfig pkgFlags pkg =
229230 , packageAllDeps = S. fromList (M. keys deps)
230231 , packageHasLibrary = maybe False (buildable . libBuildInfo) (library pkg)
231232 , packageTests = M. fromList
232- [(T. pack (Cabal. unUnqualComponentName $ testName t), testInterface t) | t <- testSuites pkg]
233- -- FIXME: Previously, we only included buildable components
234- -- here. Since Cabal 2.0, this ended up disabling test running
235- -- in all cases. Need to investigate if that's a change in
236- -- Cabal behavior or how we're piping data through the system
237- -- in response to Cabal data type changes. A cleanup of the
238- -- PackageConfig datatype (which will probably happen for
239- -- componentized builds) will likely make all of this clearer.
233+ [(T. pack (Cabal. unUnqualComponentName $ testName t), testInterface t)
234+ | t <- testSuites pkgNoMod
235+ , buildable (testBuildInfo t)
236+ ]
240237 , packageBenchmarks = S. fromList
241- [T. pack (Cabal. unUnqualComponentName $ benchmarkName biBuildInfo) | biBuildInfo <- benchmarks pkg]
238+ [T. pack (Cabal. unUnqualComponentName $ benchmarkName b)
239+ | b <- benchmarks pkgNoMod
240+ , buildable (benchmarkBuildInfo b)
241+ ]
242242 -- Same comment about buildable applies here too.
243243 , packageExes = S. fromList
244244 [T. pack (Cabal. unUnqualComponentName $ exeName biBuildInfo)
@@ -773,24 +773,53 @@ buildOtherSources build =
773773targetJsSources :: BuildInfo -> [FilePath ]
774774targetJsSources = jsSources
775775
776+ -- | A pair of package descriptions: one which modified the buildable
777+ -- values of test suites and benchmarks depending on whether they are
778+ -- enabled, and one which does not.
779+ --
780+ -- Fields are intentionally lazy, we may only need one or the other
781+ -- value.
782+ --
783+ -- MSS 2017-08-29: The very presence of this data type is terribly
784+ -- ugly, it represents the fact that the Cabal 2.0 upgrade did _not_
785+ -- go well. Specifically, we used to have a field to indicate whether
786+ -- a component was enabled in addition to buildable, but that's gone
787+ -- now, and this is an ugly proxy. We should at some point clean up
788+ -- the mess of Package, LocalPackage, etc, and probably pull in the
789+ -- definition of PackageDescription from Cabal with our additionally
790+ -- needed metadata. But this is a good enough hack for the
791+ -- moment. Odds are, you're reading this in the year 2024 and thinking
792+ -- "wtf?"
793+ data PackageDescriptionPair = PackageDescriptionPair
794+ { pdpOrigBuildable :: PackageDescription
795+ , pdpModifiedBuildable :: PackageDescription
796+ }
797+
776798-- | Evaluates the conditions of a 'GenericPackageDescription', yielding
777799-- a resolved 'PackageDescription'.
778800resolvePackageDescription :: PackageConfig
779801 -> GenericPackageDescription
780- -> PackageDescription
802+ -> PackageDescriptionPair
781803resolvePackageDescription packageConfig (GenericPackageDescription desc defaultFlags mlib _subLibs _foreignLibs exes tests benches) =
782- desc {library =
783- fmap (resolveConditions rc updateLibDeps) mlib
784- ,executables =
785- map (\ (n, v) -> (resolveConditions rc updateExeDeps v){exeName= n})
786- exes
787- ,testSuites =
788- map (\ (n,v) -> (resolveConditions rc updateTestDeps v){testName= n})
789- tests
790- ,benchmarks =
791- map (\ (n,v) -> (resolveConditions rc updateBenchmarkDeps v){benchmarkName= n})
792- benches}
793- where flags =
804+ PackageDescriptionPair
805+ { pdpOrigBuildable = go False
806+ , pdpModifiedBuildable = go True
807+ }
808+ where
809+ go modBuildable =
810+ desc {library =
811+ fmap (resolveConditions rc updateLibDeps) mlib
812+ ,executables =
813+ map (\ (n, v) -> (resolveConditions rc updateExeDeps v){exeName= n})
814+ exes
815+ ,testSuites =
816+ map (\ (n,v) -> (resolveConditions rc (updateTestDeps modBuildable) v){testName= n})
817+ tests
818+ ,benchmarks =
819+ map (\ (n,v) -> (resolveConditions rc (updateBenchmarkDeps modBuildable) v){benchmarkName= n})
820+ benches}
821+
822+ flags =
794823 M. union (packageConfigFlags packageConfig)
795824 (flagMap defaultFlags)
796825
@@ -817,18 +846,18 @@ resolvePackageDescription packageConfig (GenericPackageDescription desc defaultF
817846 -- is working fine, and that this comment can be completely
818847 -- ignored. I'm leaving the comment anyway in case something
819848 -- breaks and you, poor reader, are investigating.
820- updateTestDeps test deps =
849+ updateTestDeps modBuildable test deps =
821850 let bi = testBuildInfo test
822851 bi' = bi
823852 { targetBuildDepends = deps
824- , buildable = buildable bi && packageConfigEnableTests packageConfig
853+ , buildable = buildable bi && ( if modBuildable then packageConfigEnableTests packageConfig else True )
825854 }
826855 in test { testBuildInfo = bi' }
827- updateBenchmarkDeps benchmark deps =
856+ updateBenchmarkDeps modBuildable benchmark deps =
828857 let bi = benchmarkBuildInfo benchmark
829858 bi' = bi
830859 { targetBuildDepends = deps
831- , buildable = buildable bi && packageConfigEnableBenchmarks packageConfig
860+ , buildable = buildable bi && ( if modBuildable then packageConfigEnableBenchmarks packageConfig else True )
832861 }
833862 in benchmark { benchmarkBuildInfo = bi' }
834863
0 commit comments