Skip to content

Commit e4db588

Browse files
Log if there are multiple local packages with the same ID in a project
Co-authored-by: Hécate Kleidukos <Kleidukos@users.noreply.github.com>
1 parent c6526ae commit e4db588

5 files changed

Lines changed: 45 additions & 37 deletions

File tree

cabal-install/src/Distribution/Client/ProjectPlanning.hs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ import Distribution.Client.SetupWrapper
137137
import Distribution.Client.Store
138138
import Distribution.Client.Targets (userToPackageConstraint)
139139
import Distribution.Client.Types
140-
import Distribution.Client.Utils (concatMapM, incVersion)
140+
import Distribution.Client.Utils (concatMapM, incVersion, duplicatesBy)
141141

142142
import qualified Distribution.Client.BuildReports.Storage as BuildReports
143143
import qualified Distribution.Client.IndexUtils as IndexUtils
@@ -451,14 +451,28 @@ rebuildProjectConfig
451451
createDirectoryIfMissingVerbose verbosity True distDirectory
452452
createDirectoryIfMissingVerbose verbosity True distProjectCacheDirectory
453453

454-
fetchAndReadSourcePackages
454+
sourcePackages <- fetchAndReadSourcePackages
455455
verbosity
456456
distDirLayout
457457
compiler
458458
projectConfigShared
459459
projectConfigBuildOnly
460460
pkgLocations
461461

462+
case duplicatesBy (comparing srcpkgPackageId) [ pkg | SpecificSourcePackage pkg <- sourcePackages ] of
463+
[] -> return ()
464+
duplicateSourcePkgs ->
465+
liftIO $ noticeDoc verbosity
466+
$ vcat
467+
[ text "cabal project has multiple sources for"
468+
<+> (pretty (srcpkgPackageId (head dupeGroup)) <> text ":")
469+
Disp.$+$ Disp.nest 2 (vcat [pretty (srcpkgSource srcpkg) | srcpkg <- toList dupeGroup ])
470+
Disp.$+$ text "the choice of source that will be used is undefined."
471+
| dupeGroup <- duplicateSourcePkgs
472+
]
473+
474+
return sourcePackages
475+
462476
informAboutConfigFiles projectConfig = do
463477
cwd <- getCurrentDirectory
464478
let out -- output mode is verbose ('notice') if we build outside the project root

cabal-install/src/Distribution/Client/Types/PackageLocation.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import Network.URI (URI)
1616
import Distribution.Types.PackageId (PackageId)
1717

1818
import Distribution.Client.Types.Repo
19-
import Distribution.Client.Types.SourceRepo (SourceRepoMaybe)
19+
import Distribution.Client.Types.SourceRepo (SourceRepoMaybe, SourceRepositoryPackage(..))
2020
import Distribution.Solver.Types.SourcePackage (SourcePackage)
21+
import Distribution.Pretty
2122

2223
type UnresolvedPkgLoc = PackageLocation (Maybe FilePath)
2324

@@ -39,6 +40,14 @@ data PackageLocation local
3940
RemoteSourceRepoPackage SourceRepoMaybe local
4041
deriving (Show, Functor, Eq, Ord, Generic)
4142

43+
instance Pretty (PackageLocation local) where
44+
pretty (LocalUnpackedPackage fp) = showFilePath fp
45+
pretty (LocalTarballPackage fp) = showFilePath fp
46+
pretty (RemoteTarballPackage uri _) = showToken $ show uri
47+
pretty (RepoTarballPackage repo pid _) = pretty pid <> showToken "@" <> pretty (repoName repo)
48+
pretty (RemoteSourceRepoPackage sourceRepo _) =
49+
pretty (srpType sourceRepo) <+> showToken (srpLocation sourceRepo)
50+
4251
instance Binary local => Binary (PackageLocation local)
4352
instance Structured local => Structured (PackageLocation local)
4453

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +0,0 @@
1-
# checking repl command with a 'cabal.project' and no project options
2-
# cabal repl
3-
Resolving dependencies...
4-
Build profile: -w ghc-<GHCVER> -O1
5-
In order, the following will be built:
6-
- pkg-one-0.1 (interactive) (first run)
7-
Configuring pkg-one-0.1...
8-
Preprocessing library for pkg-one-0.1...
9-
# checking repl command with the 'all' target
10-
# cabal repl
11-
Build profile: -w ghc-<GHCVER> -O1
12-
In order, the following will be built:
13-
- pkg-one-0.1 (interactive) (first run)
14-
Preprocessing library for pkg-one-0.1...
Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
import Test.Cabal.Prelude
22
import Data.List (isInfixOf)
33

4-
main = cabalTest . recordMode RecordMarked $ do
5-
liftIO $ skipIfWindows "I'm seeing extra newlines in the output on Windows"
6-
let log = recordHeader . pure
7-
8-
-- If there is only one package in the project then the target could be inferred.
9-
log "checking repl command with a 'cabal.project' and no project options"
10-
defaultProject <- cabal' "repl" ["pkg-one"]
11-
assertOutputContains "the following will be built" defaultProject
12-
assertOutputContains "pkg-one-0.1" defaultProject
13-
-- Foo is a module in one of the packages pkg-one-0.1
14-
-- assertOutputContains "Compiling Foo" defaultProject
15-
assertOutputContains "Compiling Bar" defaultProject
16-
17-
log "checking repl command with the 'all' target"
18-
allTarget <- cabal' "repl" ["all"]
19-
assertOutputContains "the following will be built" allTarget
20-
assertOutputContains "pkg-one-0.1" allTarget
21-
-- Foo is a module in one of the packages pkg-one-0.1
22-
-- assertOutputContains "Compiling Foo" allTarget
23-
assertOutputContains "Compiling Bar" allTarget
4+
-- output contains filepaths into /tmp, so we only match parts of the output
5+
main = cabalTest . recordMode DoNotRecord $ do
6+
normal <- cabal' "configure" ["-v1", "pkg-one"]
7+
let msg = unlines
8+
[ "cabal project has multiple sources for pkg-one-0.1:"
9+
, " .*/pkg-one"
10+
, " .*/pkg-two"
11+
, "the choice of source that will be used is undefined."
12+
]
13+
assertOutputMatches msg normal
14+
quiet <- cabal' "configure" ["-v0", "pkg-one"]
15+
assertOutputDoesNotMatch msg quiet
2416

2517
return ()

changelog.d/pr-11487

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
synopsis: Log if there are multiple local packages with the same ID in a project
3+
packages: [cabal-install]
4+
prs: 11487
5+
---
6+
7+
Log duplicate local packages with the same package identifier, so that the user knows that only one will be picked.

0 commit comments

Comments
 (0)