Skip to content

Commit b41415e

Browse files
committed
More compat with buggy Cabal buildable deps #3631
This is a direct continuation of my (now realized to be incorrect) patch in 2a52ac2. This ensures that tests and benchmarks are only switched to `buildable = True` if we're enabling them, otherwise we can end up with cyclic dependency errors.
1 parent 06d14db commit b41415e

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

ChangeLog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Bug fixes:
1414

1515
* For versions of Cabal before 1.24, ensure that the dependencies of
1616
non-buildable components are part of the build plan to work around an old
17-
Cabal bug.
17+
Cabal bug. See [#3631](https://github.com/commercialhaskell/stack/issues/3631).
1818
* Run the Cabal file checking in the `sdist` command more reliably by
1919
allowing the Cabal library to flatten the
2020
`GenericPackageDescription` itself.

src/Stack/BuildPlan.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ gpdPackageDeps
198198
-> Map FlagName Bool
199199
-> Map PackageName VersionRange
200200
gpdPackageDeps gpd cv platform flags =
201-
Map.filterWithKey (const . (/= name)) (packageDependencies cv pkgDesc)
201+
Map.filterWithKey (const . (/= name)) (packageDependencies pkgConfig pkgDesc)
202202
where
203203
name = gpdPackageName gpd
204204
-- Since tests and benchmarks are both enabled, doesn't matter

src/Stack/Package.hs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkg
356356
pkgId = package pkg
357357
name = fromCabalPackageName (pkgName pkgId)
358358
deps = M.filterWithKey (const . not . isMe) (M.union
359-
(packageDependencies (packageConfigCompilerVersion packageConfig) pkg)
359+
(packageDependencies packageConfig pkg)
360360
-- We include all custom-setup deps - if present - in the
361361
-- package deps themselves. Stack always works with the
362362
-- invariant that there will be a single installed package
@@ -610,25 +610,31 @@ getBuildComponentDir (Just name) = parseRelDir (name FilePath.</> (name ++ "-tmp
610610
-- being 7.10 or earlier. This obviously makes our function a lot more
611611
-- fun to write...
612612
packageDependencies
613-
:: CompilerVersion 'CVActual
613+
:: PackageConfig
614614
-> PackageDescription
615615
-> Map PackageName VersionRange
616-
packageDependencies ghcVersion pkg' =
616+
packageDependencies pkgConfig pkg' =
617617
M.fromListWith intersectVersionRanges $
618618
map (depName &&& depRange) $
619619
concatMap targetBuildDepends (allBuildInfo' pkg) ++
620620
maybe [] setupDepends (setupBuildInfo pkg)
621621
where
622622
pkg
623-
| getGhcVersion ghcVersion >= $(mkVersion "8.0") = pkg'
623+
| getGhcVersion (packageConfigCompilerVersion pkgConfig) >= $(mkVersion "8.0") = pkg'
624624
-- Set all components to buildable. Only need to worry about
625625
-- library, exe, test, and bench, since others didn't exist in
626626
-- older Cabal versions
627627
| otherwise = pkg'
628628
{ library = (\c -> c { libBuildInfo = go (libBuildInfo c) }) <$> library pkg'
629629
, executables = (\c -> c { buildInfo = go (buildInfo c) }) <$> executables pkg'
630-
, testSuites = (\c -> c { testBuildInfo = go (testBuildInfo c) }) <$> testSuites pkg'
631-
, benchmarks = (\c -> c { benchmarkBuildInfo = go (benchmarkBuildInfo c) }) <$> benchmarks pkg'
630+
, testSuites =
631+
if packageConfigEnableTests pkgConfig
632+
then (\c -> c { testBuildInfo = go (testBuildInfo c) }) <$> testSuites pkg'
633+
else testSuites pkg'
634+
, benchmarks =
635+
if packageConfigEnableBenchmarks pkgConfig
636+
then (\c -> c { benchmarkBuildInfo = go (benchmarkBuildInfo c) }) <$> benchmarks pkg'
637+
else benchmarks pkg'
632638
}
633639

634640
go bi = bi { buildable = True }

src/Stack/Snapshot.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ calculate gpd platform compilerVersion loc flags hide options =
769769
, lpiGhcOptions = options
770770
, lpiPackageDeps = Map.map fromVersionRange
771771
$ Map.filterWithKey (const . (/= name))
772-
$ packageDependencies compilerVersion pd
772+
$ packageDependencies pconfig pd
773773
, lpiProvidedExes =
774774
Set.fromList
775775
$ map (ExeName . T.pack . C.unUnqualComponentName . C.exeName)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import StackTest
2+
3+
main :: IO ()
4+
main = do
5+
stack ["build", "--resolver=lts-6.35", "--dry-run", "http2"]
6+
stack ["build", "--resolver=lts-6.35", "http2"]

0 commit comments

Comments
 (0)