From b5d9b52f38958644bf13c43a0b57be1d30c76967 Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Fri, 29 May 2026 23:58:24 +0100 Subject: [PATCH] Fix #6920 Don't ignore deps with same name as sub/foreign lib --- ChangeLog.md | 2 ++ src/Stack/Package.hs | 21 ++++--------------- .../6920-dep-name-clash/files/.gitignore | 2 ++ .../tests/6920-dep-name-clash/files/Main.hs | 11 ++++++++++ .../files/myPackageA/int/Internal.hs | 5 +++++ .../files/myPackageA/package.yaml | 17 +++++++++++++++ .../files/myPackageB/package.yaml | 20 ++++++++++++++++++ .../files/myPackageB/src-foreign/Foreign.hs | 5 +++++ .../6920-dep-name-clash/files/stack.yaml | 8 +++++++ 9 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 tests/integration/tests/6920-dep-name-clash/files/.gitignore create mode 100644 tests/integration/tests/6920-dep-name-clash/files/Main.hs create mode 100644 tests/integration/tests/6920-dep-name-clash/files/myPackageA/int/Internal.hs create mode 100644 tests/integration/tests/6920-dep-name-clash/files/myPackageA/package.yaml create mode 100644 tests/integration/tests/6920-dep-name-clash/files/myPackageB/package.yaml create mode 100644 tests/integration/tests/6920-dep-name-clash/files/myPackageB/src-foreign/Foreign.hs create mode 100644 tests/integration/tests/6920-dep-name-clash/files/stack.yaml diff --git a/ChangeLog.md b/ChangeLog.md index 9e4433a23c..1b564d0b52 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -63,6 +63,8 @@ Bug fixes: * The output of Stack's `path --bin-path` command is now consistent with the Stack environment in Stack's `exec` command and includes the `bin` directory of Stack's local install root directory. +* Stack now builds packages that depend directly on packages with the same name + as a sublibrary or foreign library of the package. ## v3.9.3 - 2026-02-19 diff --git a/src/Stack/Package.hs b/src/Stack/Package.hs index 119f5bfebc..aac9443d09 100644 --- a/src/Stack/Package.hs +++ b/src/Stack/Package.hs @@ -38,12 +38,10 @@ module Stack.Package import qualified Data.Map.Strict as M import qualified Data.Set as S -import qualified Data.Text as T import Distribution.CabalSpecVersion ( cabalSpecToVersionDigits ) import Distribution.Compiler ( CompilerFlavor (..), PerCompilerFlavor (..) ) import Distribution.ModuleName ( ModuleName ) -import Distribution.Package ( mkPackageName ) import Distribution.PackageDescription ( Benchmark (..), BuildInfo (..), BuildType (..) , CondTree (..), Condition (..), ConfVar (..) @@ -87,7 +85,6 @@ import Stack.Types.BuildConfig ( HasBuildConfig (..), getWorkDir ) import Stack.Types.CompCollection ( CompCollection, collectionLookup, foldAndMakeCollection , foldComponentToAnotherCollection, getBuildableSet - , getBuildableSetText ) import Stack.Types.Compiler ( ActualCompiler (..) ) import Stack.Types.CompilerPaths ( cabalVersionL ) @@ -762,21 +759,11 @@ processPackageDeps pkg combineResults fn = where iterator :: PackageName -> DepValue -> m a -> m a iterator depPackageName depValue acc - | shouldIgnoreDep = acc + -- If the name of the dependency package is the same as the package, we + -- ignore the former. It is possible for a dependency package to have the + -- same name as a named sublibrary or a named foreign library. + | depPackageName == pkg.name = acc | otherwise = combineResults <$> fn depPackageName depValue <*> acc - where - shouldIgnoreDep - | depPackageName == pkg.name = True - | depPackageName `S.member` subLibNames = True - | depPackageName `S.member` foreignLibNames = True - | otherwise = False - where - !subLibNames = asPackageNameSet (.subLibraries) - !foreignLibNames = asPackageNameSet (.foreignLibraries) - asPackageNameSet :: - (Package -> CompCollection component) -> Set PackageName - asPackageNameSet accessor = - S.map (mkPackageName . T.unpack) $ getBuildableSetText $ accessor pkg -- | This is a function to iterate in a monad over all of a package's -- dependencies (including any custom-setup ones), and yield a list of diff --git a/tests/integration/tests/6920-dep-name-clash/files/.gitignore b/tests/integration/tests/6920-dep-name-clash/files/.gitignore new file mode 100644 index 0000000000..f9a6e152d2 --- /dev/null +++ b/tests/integration/tests/6920-dep-name-clash/files/.gitignore @@ -0,0 +1,2 @@ +myPackageA.cabal +myPackageB.cabal diff --git a/tests/integration/tests/6920-dep-name-clash/files/Main.hs b/tests/integration/tests/6920-dep-name-clash/files/Main.hs new file mode 100644 index 0000000000..e9a59d0346 --- /dev/null +++ b/tests/integration/tests/6920-dep-name-clash/files/Main.hs @@ -0,0 +1,11 @@ +-- | Stack builds a package which depends directly on a package with the same +-- name as a sublibrary or foreign library of that package. +-- +-- See: https://github.com/commercialhaskell/stack/issues/6920 + +import StackTest + +main :: IO () +main = do + stack ["build", "myPackageA"] + stack ["build", "myPackageB"] diff --git a/tests/integration/tests/6920-dep-name-clash/files/myPackageA/int/Internal.hs b/tests/integration/tests/6920-dep-name-clash/files/myPackageA/int/Internal.hs new file mode 100644 index 0000000000..9f7c4a2680 --- /dev/null +++ b/tests/integration/tests/6920-dep-name-clash/files/myPackageA/int/Internal.hs @@ -0,0 +1,5 @@ +module Internal + ( launchMissiles + ) where + +import Acme.Missiles ( launchMissiles ) diff --git a/tests/integration/tests/6920-dep-name-clash/files/myPackageA/package.yaml b/tests/integration/tests/6920-dep-name-clash/files/myPackageA/package.yaml new file mode 100644 index 0000000000..8680aff1a6 --- /dev/null +++ b/tests/integration/tests/6920-dep-name-clash/files/myPackageA/package.yaml @@ -0,0 +1,17 @@ +spec-version: 0.36.0 + +# Required, otherwise Hpack picks cabal-version: 3.0 and the dependency on +# acme-missiles is assumed to refer to the name of the internal-library. +verbatim: + cabal-version: 3.4 + +name: myPackageA + +dependencies: +- base + +internal-libraries: + acme-missiles: + source-dirs: int + dependencies: + - acme-missiles diff --git a/tests/integration/tests/6920-dep-name-clash/files/myPackageB/package.yaml b/tests/integration/tests/6920-dep-name-clash/files/myPackageB/package.yaml new file mode 100644 index 0000000000..7cda1d93a6 --- /dev/null +++ b/tests/integration/tests/6920-dep-name-clash/files/myPackageB/package.yaml @@ -0,0 +1,20 @@ +spec-version: 0.36.0 + +name: myPackageB + +dependencies: +- base + +verbatim: | + foreign-library acme-missiles + type: native-shared + other-modules: + Foreign + build-depends: + base + , acme-missiles + hs-source-dirs: + src-foreign + default-language: Haskell2010 + if os(Windows) + options: standalone diff --git a/tests/integration/tests/6920-dep-name-clash/files/myPackageB/src-foreign/Foreign.hs b/tests/integration/tests/6920-dep-name-clash/files/myPackageB/src-foreign/Foreign.hs new file mode 100644 index 0000000000..449a04a061 --- /dev/null +++ b/tests/integration/tests/6920-dep-name-clash/files/myPackageB/src-foreign/Foreign.hs @@ -0,0 +1,5 @@ +module Foreign + ( launchMissiles + ) where + +import Acme.Missiles ( launchMissiles ) diff --git a/tests/integration/tests/6920-dep-name-clash/files/stack.yaml b/tests/integration/tests/6920-dep-name-clash/files/stack.yaml new file mode 100644 index 0000000000..8933f7a96d --- /dev/null +++ b/tests/integration/tests/6920-dep-name-clash/files/stack.yaml @@ -0,0 +1,8 @@ +snapshot: ghc-9.10.3 + +packages: +- myPackageA +- myPackageB + +extra-deps: +- acme-missiles-0.3