From dfccf8c0912e7f60e4c11f92453b13d7a2e7b732 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 19 May 2020 13:41:10 +0200 Subject: [PATCH 1/3] Add failing test reproducing the problem of #8902 --- .../installer/github-issues-8902.test | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/Composer/Test/Fixtures/installer/github-issues-8902.test diff --git a/tests/Composer/Test/Fixtures/installer/github-issues-8902.test b/tests/Composer/Test/Fixtures/installer/github-issues-8902.test new file mode 100644 index 000000000..c92dda83b --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/github-issues-8902.test @@ -0,0 +1,46 @@ +--TEST-- + +See Github issue #8902 ( https://github.com/composer/composer/issues/8902 ). + +Avoid installing packages twice if they are required in different versions and one is matched by a dev package. + +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { "name": "beyondcode/laravel-dump-server", "version": "1.4.0", "require": { "symfony/var-dumper": "^5.0" } }, + { "name": "laravel/framework", "version": "6.8.14", "require": { "symfony/var-dumper": "^4.3.4" } }, + { "name": "symfony/var-dumper", "version": "4.4.0" }, + { "name": "symfony/var-dumper", "version": "dev-master", "extra": { "branch-alias": {"dev-master": "5.2-dev"} } } + ] + } + ], + "require": { + "beyondcode/laravel-dump-server": "^1.3", + "laravel/framework": "^6.8" + }, + "minimum-stability": "dev" +} + +--RUN-- +update + +--EXPECT-OUTPUT-- +Loading composer repositories with package information +Updating dependencies +Your requirements could not be resolved to an installable set of packages. + + Problem 1 + - Root composer.json requires beyondcode/laravel-dump-server ^1.3 -> satisfiable by beyondcode/laravel-dump-server[1.4.0]. + - beyondcode/laravel-dump-server 1.4.0 requires symfony/var-dumper ^5.0 -> satisfiable by symfony/var-dumper[dev-master]. + - Root composer.json requires laravel/framework ^6.8 -> satisfiable by laravel/framework[6.8.14]. + - laravel/framework 6.8.14 requires symfony/var-dumper ^4.3.4 -> satisfiable by symfony/var-dumper[4.4.0]. + etc... + + +--EXPECT-- + +--EXPECT-EXIT-CODE-- +2 From 0ea9eafcafda3ead6b385673c62c78a2cf38cd17 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 2 Jun 2020 10:01:02 +0200 Subject: [PATCH 2/3] Add rules for aliased packages when an alias is added, fixes #8902 --- src/Composer/DependencyResolver/RuleSetGenerator.php | 1 + .../Test/Fixtures/installer/github-issues-8902.test | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Composer/DependencyResolver/RuleSetGenerator.php b/src/Composer/DependencyResolver/RuleSetGenerator.php index ffb88d56c..12bd17783 100644 --- a/src/Composer/DependencyResolver/RuleSetGenerator.php +++ b/src/Composer/DependencyResolver/RuleSetGenerator.php @@ -165,6 +165,7 @@ class RuleSetGenerator $this->addedPackagesByNames[$name][] = $package; } } else { + $workQueue->enqueue($package->getAliasOf()); $this->addRule(RuleSet::TYPE_PACKAGE, $this->createRequireRule($package, array($package->getAliasOf()), Rule::RULE_PACKAGE_ALIAS, $package)); } diff --git a/tests/Composer/Test/Fixtures/installer/github-issues-8902.test b/tests/Composer/Test/Fixtures/installer/github-issues-8902.test index c92dda83b..407dff3af 100644 --- a/tests/Composer/Test/Fixtures/installer/github-issues-8902.test +++ b/tests/Composer/Test/Fixtures/installer/github-issues-8902.test @@ -34,11 +34,11 @@ Your requirements could not be resolved to an installable set of packages. Problem 1 - Root composer.json requires beyondcode/laravel-dump-server ^1.3 -> satisfiable by beyondcode/laravel-dump-server[1.4.0]. - - beyondcode/laravel-dump-server 1.4.0 requires symfony/var-dumper ^5.0 -> satisfiable by symfony/var-dumper[dev-master]. - - Root composer.json requires laravel/framework ^6.8 -> satisfiable by laravel/framework[6.8.14]. + - You can only install one version of a package, so only one of these can be installed: symfony/var-dumper[dev-master, 4.4.0]. + - don't install symfony/var-dumper 5.2.x-dev|install symfony/var-dumper dev-master - laravel/framework 6.8.14 requires symfony/var-dumper ^4.3.4 -> satisfiable by symfony/var-dumper[4.4.0]. - etc... - + - beyondcode/laravel-dump-server 1.4.0 requires symfony/var-dumper ^5.0 -> satisfiable by symfony/var-dumper[5.2.x-dev (alias of dev-master)]. + - Root composer.json requires laravel/framework ^6.8 -> satisfiable by laravel/framework[6.8.14]. --EXPECT-- From 2ddf4346ef6a82eca251c78dc40bf8af56a4b776 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 2 Jun 2020 10:35:04 +0200 Subject: [PATCH 3/3] Improve error reporting for RULE_PACKAGE_ALIAS --- src/Composer/DependencyResolver/Rule.php | 5 ++++- .../Composer/Test/Fixtures/installer/github-issues-8902.test | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index 0a106c854..fafc8bda8 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -288,7 +288,10 @@ abstract class Rule return 'Conclusion: '.$ruleText.$learnedString; case self::RULE_PACKAGE_ALIAS: - return $ruleText; + $aliasPackage = $this->deduplicateMasterAlias($pool->literalToPackage($literals[0])); + $package = $this->deduplicateMasterAlias($pool->literalToPackage($literals[1])); + + return $aliasPackage->getPrettyString() .' is an alias of '.$package->getPrettyString().' and thus requires it to be installed too.'; default: return '('.$ruleText.')'; } diff --git a/tests/Composer/Test/Fixtures/installer/github-issues-8902.test b/tests/Composer/Test/Fixtures/installer/github-issues-8902.test index 407dff3af..53fc1275b 100644 --- a/tests/Composer/Test/Fixtures/installer/github-issues-8902.test +++ b/tests/Composer/Test/Fixtures/installer/github-issues-8902.test @@ -35,7 +35,7 @@ Your requirements could not be resolved to an installable set of packages. Problem 1 - Root composer.json requires beyondcode/laravel-dump-server ^1.3 -> satisfiable by beyondcode/laravel-dump-server[1.4.0]. - You can only install one version of a package, so only one of these can be installed: symfony/var-dumper[dev-master, 4.4.0]. - - don't install symfony/var-dumper 5.2.x-dev|install symfony/var-dumper dev-master + - symfony/var-dumper 5.2.x-dev is an alias of symfony/var-dumper dev-master and thus requires it to be installed too. - laravel/framework 6.8.14 requires symfony/var-dumper ^4.3.4 -> satisfiable by symfony/var-dumper[4.4.0]. - beyondcode/laravel-dump-server 1.4.0 requires symfony/var-dumper ^5.0 -> satisfiable by symfony/var-dumper[5.2.x-dev (alias of dev-master)]. - Root composer.json requires laravel/framework ^6.8 -> satisfiable by laravel/framework[6.8.14].