Skip to content

Commit 408e79a

Browse files
committed
Unbuildable tests are not built (fixes commercialhaskell#3390)
See comment on the PackageDescriptionPair datatype. This is an ugly hack.
1 parent d4fc213 commit 408e79a

5 files changed

Lines changed: 75 additions & 35 deletions

File tree

src/Stack/BuildPlan.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ gpdPackageDeps gpd cv platform flags =
208208
Map.filterWithKey (const . (/= name)) (packageDependencies pkgDesc)
209209
where
210210
name = gpdPackageName gpd
211-
pkgDesc = resolvePackageDescription pkgConfig gpd
211+
-- Since tests and benchmarks are both enabled, doesn't matter
212+
-- if we choose modified or unmodified
213+
pkgDesc = pdpModifiedBuildable $ resolvePackageDescription pkgConfig gpd
212214
pkgConfig = PackageConfig
213215
{ packageConfigEnableTests = True
214216
, packageConfigEnableBenchmarks = True

src/Stack/Ghci.hs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,17 @@ makeGhciPkgInfo buildOptsCLI sourceMap installedMap locals addPkgs mfileTargets
550550
| hasDotBuildinfo = Just (parent cabalfp </> buildinfofp)
551551
| otherwise = Nothing
552552
mbuildinfo <- forM mbuildinfofp readDotBuildinfo
553-
let pkg =
553+
let pdp = resolvePackageDescription config gpkgdesc
554+
pkg =
554555
packageFromPackageDescription config (C.genPackageFlags gpkgdesc) $
555-
maybe id C.updatePackageDescription mbuildinfo $
556-
resolvePackageDescription config gpkgdesc
556+
maybe
557+
pdp
558+
(\bi ->
559+
let PackageDescriptionPair x y = pdp
560+
in PackageDescriptionPair
561+
(C.updatePackageDescription bi x)
562+
(C.updatePackageDescription bi y))
563+
mbuildinfo
557564

558565
mapM_ (printCabalFileWarning cabalfp) warnings
559566
(mods,files,opts) <- getPackageOpts (packageOpts pkg) sourceMap installedMap locals addPkgs cabalfp

src/Stack/Package.hs

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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 =
153154
readPackageDescriptionDir :: (MonadLogger m, MonadIO m, MonadThrow m)
154155
=> PackageConfig
155156
-> Path Abs Dir
156-
-> m (GenericPackageDescription, PackageDescription)
157+
-> m (GenericPackageDescription, PackageDescriptionPair)
157158
readPackageDescriptionDir config pkgDir = do
158159
cabalfp <- findOrGenerateCabalFile pkgDir
159160
gdesc <- liftM snd (readPackageUnresolved cabalfp)
@@ -212,9 +213,9 @@ resolvePackage packageConfig gpkg =
212213

213214
packageFromPackageDescription :: 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 =
773773
targetJsSources :: BuildInfo -> [FilePath]
774774
targetJsSources = 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'.
778800
resolvePackageDescription :: PackageConfig
779801
-> GenericPackageDescription
780-
-> PackageDescription
802+
-> PackageDescriptionPair
781803
resolvePackageDescription 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

src/Stack/SDist.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ checkPackageInExtractedTarball pkgDir = do
346346
cabalfp <- findOrGenerateCabalFile pkgDir
347347
name <- parsePackageNameFromFilePath cabalfp
348348
config <- getDefaultPackageConfig
349-
(gdesc, pkgDesc) <- readPackageDescriptionDir config pkgDir
349+
(gdesc, PackageDescriptionPair pkgDesc _) <- readPackageDescriptionDir config pkgDir
350350
logInfo $
351351
"Checking package '" <> packageNameText name <> "' for common mistakes"
352352
let pkgChecks = Check.checkPackage gdesc (Just pkgDesc)

src/Stack/Snapshot.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,9 @@ calculate gpd platform compilerVersion loc flags hide options =
778778
, packageConfigCompilerVersion = compilerVersion
779779
, packageConfigPlatform = platform
780780
}
781-
pd = resolvePackageDescription pconfig gpd
781+
-- We want to ignore test suites and benchmarks, therefore choose
782+
-- the package description which modifies buildable
783+
pd = pdpModifiedBuildable $ resolvePackageDescription pconfig gpd
782784
PackageIdentifier name version = fromCabalPackageIdentifier $ C.package pd
783785
lpi = LoadedPackageInfo
784786
{ lpiVersion = version

0 commit comments

Comments
 (0)