diff --git a/cabal-install/Distribution/Client/Dependency.hs b/cabal-install/Distribution/Client/Dependency.hs index a779daaedf0..c987ee91b2d 100644 --- a/cabal-install/Distribution/Client/Dependency.hs +++ b/cabal-install/Distribution/Client/Dependency.hs @@ -91,8 +91,6 @@ import qualified Distribution.PackageDescription as PD import qualified Distribution.PackageDescription.Configuration as PD import Distribution.PackageDescription.Configuration ( finalizePD ) -import Distribution.Client.PackageUtils - ( externalBuildDepends ) import Distribution.Compiler ( CompilerInfo(..) ) import Distribution.System @@ -890,22 +888,27 @@ showPackageProblem (InvalidDep dep pkgid) = configuredPackageProblems :: Platform -> CompilerInfo -> SolverPackage UnresolvedPkgLoc -> [PackageProblem] configuredPackageProblems platform cinfo - (SolverPackage pkg specifiedFlags stanzas specifiedDeps' _specifiedExeDeps') = + (SolverPackage pkg specifiedFlags stanzas specifiedDeps0 _specifiedExeDeps') = [ DuplicateFlag flag | flag <- PD.findDuplicateFlagAssignments specifiedFlags ] ++ [ MissingFlag flag | OnlyInLeft flag <- mergedFlags ] ++ [ ExtraFlag flag | OnlyInRight flag <- mergedFlags ] ++ [ DuplicateDeps pkgs | pkgs <- CD.nonSetupDeps (fmap (duplicatesBy (comparing packageName)) - specifiedDeps) ] + specifiedDeps1) ] ++ [ MissingDep dep | OnlyInLeft dep <- mergedDeps ] ++ [ ExtraDep pkgid | OnlyInRight pkgid <- mergedDeps ] ++ [ InvalidDep dep pkgid | InBoth dep pkgid <- mergedDeps , not (packageSatisfiesDependency pkgid dep) ] -- TODO: sanity tests on executable deps where - specifiedDeps :: ComponentDeps [PackageId] - specifiedDeps = fmap (map solverSrcId) specifiedDeps' + thisPkgName = packageName (packageDescription pkg) + + specifiedDeps1 :: ComponentDeps [PackageId] + specifiedDeps1 = fmap (map solverSrcId) specifiedDeps0 + + specifiedDeps :: [PackageId] + specifiedDeps = CD.flatDeps specifiedDeps1 mergedFlags = mergeBy compare (sort $ map PD.flagName (PD.genPackageFlags (packageDescription pkg))) @@ -919,7 +922,7 @@ configuredPackageProblems platform cinfo dependencyName (Dependency name _ _) = name mergedDeps :: [MergeResult Dependency PackageId] - mergedDeps = mergeDeps requiredDeps (CD.flatDeps specifiedDeps) + mergedDeps = mergeDeps requiredDeps specifiedDeps mergeDeps :: [Dependency] -> [PackageId] -> [MergeResult Dependency PackageId] @@ -939,6 +942,15 @@ configuredPackageProblems platform cinfo -- `mergeDeps`. requiredDeps :: [Dependency] requiredDeps = + -- we filter self/internal dependencies. They are still there. + -- This is INCORRECT. + -- + -- If we had per-component solver, it would make this unnecessary, + -- but no finalizePDs picks components we are not building, eg. exes. + -- See #3775 + -- + filter ((/= thisPkgName) . dependencyName) $ + --TODO: use something lower level than finalizePD case finalizePD specifiedFlags compSpec @@ -947,7 +959,7 @@ configuredPackageProblems platform cinfo [] (packageDescription pkg) of Right (resolvedPkg, _) -> - externalBuildDepends resolvedPkg compSpec + PD.enabledBuildDepends resolvedPkg compSpec ++ maybe [] PD.setupDepends (PD.setupBuildInfo resolvedPkg) Left _ -> error "configuredPackageInvalidDeps internal error" diff --git a/cabal-install/Distribution/Client/PackageUtils.hs b/cabal-install/Distribution/Client/PackageUtils.hs deleted file mode 100644 index 2a491f36212..00000000000 --- a/cabal-install/Distribution/Client/PackageUtils.hs +++ /dev/null @@ -1,41 +0,0 @@ ------------------------------------------------------------------------------ --- | --- Module : Distribution.Client.PackageUtils --- Copyright : (c) Duncan Coutts 2010 --- License : BSD-like --- --- Maintainer : cabal-devel@gmail.com --- Stability : provisional --- Portability : portable --- --- Various package description utils that should be in the Cabal lib ------------------------------------------------------------------------------ -module Distribution.Client.PackageUtils ( - externalBuildDepends, - ) where - -import Distribution.Client.Compat.Prelude -import Prelude () - -import Distribution.Package (packageName, packageVersion) -import Distribution.PackageDescription - (PackageDescription (..), enabledBuildDepends, libName) -import Distribution.Types.ComponentRequestedSpec (ComponentRequestedSpec) -import Distribution.Types.Dependency -import Distribution.Types.LibraryName -import Distribution.Types.UnqualComponentName -import Distribution.Version (isAnyVersion, withinRange) - --- | The list of dependencies that refer to external packages --- rather than internal package components. --- -externalBuildDepends :: PackageDescription -> ComponentRequestedSpec -> [Dependency] -externalBuildDepends pkg spec = filter (not . internal) (enabledBuildDepends pkg spec) - where - -- True if this dependency is an internal one (depends on a library - -- defined in the same package). - internal (Dependency depName versionRange _) = - (depName == packageName pkg && - packageVersion pkg `withinRange` versionRange) || - (LSubLibName (packageNameToUnqualComponentName depName) `elem` map libName (subLibraries pkg) && - isAnyVersion versionRange) diff --git a/cabal-install/Distribution/Solver/Modular/IndexConversion.hs b/cabal-install/Distribution/Solver/Modular/IndexConversion.hs index b072e191a7d..c16aa665b07 100644 --- a/cabal-install/Distribution/Solver/Modular/IndexConversion.hs +++ b/cabal-install/Distribution/Solver/Modular/IndexConversion.hs @@ -17,7 +17,6 @@ import Distribution.Simple.BuildToolDepends -- from Cabal import Distribution.Types.ExeDependency -- from Cabal import Distribution.Types.PkgconfigDependency -- from Cabal import Distribution.Types.ComponentName -- from Cabal -import Distribution.Types.UnqualComponentName -- from Cabal import Distribution.Types.CondTree -- from Cabal import Distribution.Types.MungedPackageId -- from Cabal import Distribution.Types.MungedPackageName -- from Cabal @@ -181,19 +180,11 @@ convGPD os arch cinfo constraints strfl solveExes pn let fds = flagInfo strfl flags - -- | We have to be careful to filter out dependencies on - -- internal libraries, since they don't refer to real packages - -- and thus cannot actually be solved over. We'll do this - -- by creating a set of package names which are "internal" - -- and dropping them as we convert. - - ipns = S.fromList $ [ unqualComponentNameToPackageName nm - | (nm, _) <- sub_libs ] conv :: Monoid a => Component -> (a -> BuildInfo) -> DependencyReason PN -> CondTree ConfVar [Dependency] a -> FlaggedDeps PN conv comp getInfo dr = - convCondTree M.empty dr pkg os arch cinfo pn fds comp getInfo ipns solveExes . + convCondTree M.empty dr pkg os arch cinfo pn fds comp getInfo solveExes . addBuildableCondition getInfo initDR = DependencyReason pn M.empty S.empty @@ -331,27 +322,15 @@ flagInfo (StrongFlags strfl) = weak m = WeakOrTrivial $ not (strfl || m) flagType m = if m then Manual else Automatic --- | Internal package names, which should not be interpreted as true --- dependencies. -type IPNs = S.Set PN - --- | Convenience function to delete a 'Dependency' if it's --- for a 'PN' that isn't actually real. -filterIPNs :: IPNs -> Dependency -> Maybe Dependency -filterIPNs ipns d@(Dependency pn _ _) - | S.notMember pn ipns = Just d - | otherwise = Nothing - -- | Convert condition trees to flagged dependencies. Mutually -- recursive with 'convBranch'. See 'convBranch' for an explanation -- of all arguments preceding the input 'CondTree'. convCondTree :: Map FlagName Bool -> DependencyReason PN -> PackageDescription -> OS -> Arch -> CompilerInfo -> PN -> FlagInfo -> Component -> (a -> BuildInfo) -> - IPNs -> SolveExecutables -> CondTree ConfVar [Dependency] a -> FlaggedDeps PN -convCondTree flags dr pkg os arch cinfo pn fds comp getInfo ipns solveExes@(SolveExecutables solveExes') (CondNode info ds branches) = +convCondTree flags dr pkg os arch cinfo pn fds comp getInfo solveExes@(SolveExecutables solveExes') (CondNode info ds branches) = -- Merge all library and build-tool dependencies at every level in -- the tree of flagged dependencies. Otherwise 'extractCommon' -- could create duplicate dependencies, and the number of @@ -359,13 +338,13 @@ convCondTree flags dr pkg os arch cinfo pn fds comp getInfo ipns solveExes@(Solv -- of the tree. mergeSimpleDeps $ [ D.Simple singleDep comp - | dep <- mapMaybe (filterIPNs ipns) ds + | dep <- ds , singleDep <- convLibDeps dr dep ] -- unconditional package dependencies ++ L.map (\e -> D.Simple (LDep dr (Ext e)) comp) (allExtensions bi) -- unconditional extension dependencies ++ L.map (\l -> D.Simple (LDep dr (Lang l)) comp) (allLanguages bi) -- unconditional language dependencies ++ L.map (\(PkgconfigDependency pkn vr) -> D.Simple (LDep dr (Pkg pkn vr)) comp) (pkgconfigDepends bi) -- unconditional pkg-config dependencies - ++ concatMap (convBranch flags dr pkg os arch cinfo pn fds comp getInfo ipns solveExes) branches + ++ concatMap (convBranch flags dr pkg os arch cinfo pn fds comp getInfo solveExes) branches -- build-tools dependencies -- NB: Only include these dependencies if SolveExecutables -- is True. It might be false in the legacy solver @@ -481,14 +460,13 @@ convBranch :: Map FlagName Bool -> FlagInfo -> Component -> (a -> BuildInfo) - -> IPNs -> SolveExecutables -> CondBranch ConfVar [Dependency] a -> FlaggedDeps PN -convBranch flags dr pkg os arch cinfo pn fds comp getInfo ipns solveExes (CondBranch c' t' mf') = +convBranch flags dr pkg os arch cinfo pn fds comp getInfo solveExes (CondBranch c' t' mf') = go c' - (\flags' dr' -> convCondTree flags' dr' pkg os arch cinfo pn fds comp getInfo ipns solveExes t') - (\flags' dr' -> maybe [] (convCondTree flags' dr' pkg os arch cinfo pn fds comp getInfo ipns solveExes) mf') + (\flags' dr' -> convCondTree flags' dr' pkg os arch cinfo pn fds comp getInfo solveExes t') + (\flags' dr' -> maybe [] (convCondTree flags' dr' pkg os arch cinfo pn fds comp getInfo solveExes) mf') flags dr where go :: Condition ConfVar diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index dd722f8a8ee..28f79ca6a72 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -225,7 +225,6 @@ executable cabal Distribution.Client.NixStyleOptions Distribution.Client.Outdated Distribution.Client.PackageHash - Distribution.Client.PackageUtils Distribution.Client.ParseUtils Distribution.Client.ProjectBuilding Distribution.Client.ProjectBuilding.Types diff --git a/cabal-install/cabal-install.cabal.dev b/cabal-install/cabal-install.cabal.dev index 9a00a594a31..a6687758a1d 100644 --- a/cabal-install/cabal-install.cabal.dev +++ b/cabal-install/cabal-install.cabal.dev @@ -217,7 +217,6 @@ library cabal-lib-client Distribution.Client.NixStyleOptions Distribution.Client.Outdated Distribution.Client.PackageHash - Distribution.Client.PackageUtils Distribution.Client.ParseUtils Distribution.Client.ProjectBuilding Distribution.Client.ProjectBuilding.Types diff --git a/cabal-install/cabal-install.cabal.prod b/cabal-install/cabal-install.cabal.prod index dd722f8a8ee..28f79ca6a72 100644 --- a/cabal-install/cabal-install.cabal.prod +++ b/cabal-install/cabal-install.cabal.prod @@ -225,7 +225,6 @@ executable cabal Distribution.Client.NixStyleOptions Distribution.Client.Outdated Distribution.Client.PackageHash - Distribution.Client.PackageUtils Distribution.Client.ParseUtils Distribution.Client.ProjectBuilding Distribution.Client.ProjectBuilding.Types diff --git a/cabal-install/cabal-install.cabal.zinza b/cabal-install/cabal-install.cabal.zinza index d1d8a14b3ce..705fbebd2ad 100644 --- a/cabal-install/cabal-install.cabal.zinza +++ b/cabal-install/cabal-install.cabal.zinza @@ -161,7 +161,6 @@ Version: 3.3.0.0 Distribution.Client.NixStyleOptions Distribution.Client.Outdated Distribution.Client.PackageHash - Distribution.Client.PackageUtils Distribution.Client.ParseUtils Distribution.Client.ProjectBuilding Distribution.Client.ProjectBuilding.Types diff --git a/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/cabal.out b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/cabal.out new file mode 100644 index 00000000000..4f0b36fea49 --- /dev/null +++ b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/cabal.out @@ -0,0 +1,15 @@ +# cabal v2-run +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - pkg-def-0.1.0.0 (lib) (first run) + - pkg-abc-0.1.0.0 (exe:program) (first run) +Warning: pkg-def.cabal:13:27: visibility is experimental feature (issue #5660) +Configuring library for pkg-def-0.1.0.0.. +Preprocessing library for pkg-def-0.1.0.0.. +Building library for pkg-def-0.1.0.0.. +Warning: pkg-abc.cabal:19:15: colon specifier is experimental feature (issue #5660) +Configuring executable 'program' for pkg-abc-0.1.0.0.. +Warning: The package has an extraneous version range for a dependency on an internal library: pkg-def >=0 && ==0.1.0.0. This version range includes the current package but isn't needed as the current package's library will always be used. +Preprocessing executable 'program' for pkg-abc-0.1.0.0.. +Building executable 'program' for pkg-abc-0.1.0.0.. diff --git a/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/cabal.project b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/cabal.project new file mode 100644 index 00000000000..9b5dc06cd42 --- /dev/null +++ b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/cabal.project @@ -0,0 +1,4 @@ +packages: + pkg-abc + pkg-def + diff --git a/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/cabal.test.hs b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/cabal.test.hs new file mode 100644 index 00000000000..49ff98d44c8 --- /dev/null +++ b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/cabal.test.hs @@ -0,0 +1,6 @@ +import Test.Cabal.Prelude + +-- https://github.com/haskell/cabal/issues/6083 +-- see pkg-abc.cabal +main = cabalTest $ + cabal' "v2-run" ["pkg-abc:program"] >>= assertOutputContains "pkg-def:pkg-def" diff --git a/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-abc/exe/Main.hs b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-abc/exe/Main.hs new file mode 100644 index 00000000000..b9cf6f41954 --- /dev/null +++ b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-abc/exe/Main.hs @@ -0,0 +1,5 @@ +module Main (main) where +import PkgDef (defValue) + +main :: IO () +main = print defValue diff --git a/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-abc/pkg-abc.cabal b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-abc/pkg-abc.cabal new file mode 100644 index 00000000000..2ca9df20050 --- /dev/null +++ b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-abc/pkg-abc.cabal @@ -0,0 +1,19 @@ +cabal-version: 3.4 +name: pkg-abc +version: 0.1.0.0 + +library pkg-def + default-language: Haskell2010 + hs-source-dirs: pkg-def + build-depends: base + exposed-modules: PkgDef + +executable program + default-language: Haskell2010 + hs-source-dirs: exe + main-is: Main.hs + + -- we want that to resolve to pkg-def main library. + build-depends: + , base + , pkg-def:pkg-def diff --git a/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-abc/pkg-def/PkgDef.hs b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-abc/pkg-def/PkgDef.hs new file mode 100644 index 00000000000..4379d53caa4 --- /dev/null +++ b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-abc/pkg-def/PkgDef.hs @@ -0,0 +1,4 @@ +module PkgDef (defValue) where + +defValue :: String +defValue = "pkg-abc:pkg-def" diff --git a/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-def/pkg-def.cabal b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-def/pkg-def.cabal new file mode 100644 index 00000000000..a4d95cf4a01 --- /dev/null +++ b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-def/pkg-def.cabal @@ -0,0 +1,17 @@ +cabal-version: 3.0 +name: pkg-def +version: 0.1.0.0 + +library + default-language: Haskell2010 + hs-source-dirs: src + build-depends: base + exposed-modules: PkgDef + +library publib + default-language: Haskell2010 + visibility: public + hs-source-dirs: publib + build-depends: base + exposed-modules: PkgDef + diff --git a/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-def/publib/PkgDef.hs b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-def/publib/PkgDef.hs new file mode 100644 index 00000000000..06ad039f434 --- /dev/null +++ b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-def/publib/PkgDef.hs @@ -0,0 +1,4 @@ +module PkgDef (defValue) where + +defValue :: String +defValue = "pkg-def:publib" diff --git a/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-def/src/PkgDef.hs b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-def/src/PkgDef.hs new file mode 100644 index 00000000000..8c7d547cf70 --- /dev/null +++ b/cabal-testsuite/PackageTests/MultipleLibraries/T6083Post/pkg-def/src/PkgDef.hs @@ -0,0 +1,4 @@ +module PkgDef (defValue) where + +defValue :: String +defValue = "pkg-def:pkg-def"