From f7c05db8b0a66d046203faf3c187e319cd211fae Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 24 May 2023 09:14:18 +0200 Subject: [PATCH 1/6] Release 2.5.6 --- src/Composer/Composer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Composer/Composer.php b/src/Composer/Composer.php index 8a870cc47..b2c4ce716 100644 --- a/src/Composer/Composer.php +++ b/src/Composer/Composer.php @@ -51,10 +51,10 @@ class Composer extends PartialComposer * * @see getVersion() */ - public const VERSION = '@package_version@'; - public const BRANCH_ALIAS_VERSION = '@package_branch_alias_version@'; - public const RELEASE_DATE = '@release_date@'; - public const SOURCE_VERSION = '2.5.999-dev+source'; + public const VERSION = '2.5.6'; + public const BRANCH_ALIAS_VERSION = ''; + public const RELEASE_DATE = '2023-05-24 09:14:18'; + public const SOURCE_VERSION = ''; /** * Version number of the internal composer-runtime-api package From 4893b67efaf35337a718129877de907f83f747d8 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 24 May 2023 09:14:24 +0200 Subject: [PATCH 2/6] Reverting release version changes --- src/Composer/Composer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Composer/Composer.php b/src/Composer/Composer.php index b2c4ce716..8a870cc47 100644 --- a/src/Composer/Composer.php +++ b/src/Composer/Composer.php @@ -51,10 +51,10 @@ class Composer extends PartialComposer * * @see getVersion() */ - public const VERSION = '2.5.6'; - public const BRANCH_ALIAS_VERSION = ''; - public const RELEASE_DATE = '2023-05-24 09:14:18'; - public const SOURCE_VERSION = ''; + public const VERSION = '@package_version@'; + public const BRANCH_ALIAS_VERSION = '@package_branch_alias_version@'; + public const RELEASE_DATE = '@release_date@'; + public const SOURCE_VERSION = '2.5.999-dev+source'; /** * Version number of the internal composer-runtime-api package From 33c293aec31843dacbf58f476cdf142f638aaadb Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 24 May 2023 14:58:11 +0200 Subject: [PATCH 3/6] Fix autoload regression with metapackage dependencies (#11481) fixes #11480 introduced by #11455 --- src/Composer/Autoload/AutoloadGenerator.php | 37 +++++++++-------- .../Test/Autoload/AutoloadGeneratorTest.php | 40 ++++++++++++++++++- .../Fixtures/autoload_vendors_meta.php | 10 +++++ 3 files changed, 69 insertions(+), 18 deletions(-) create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_vendors_meta.php diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 0ff95e042..c7ab9ca1f 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -473,7 +473,7 @@ EOF; /** * @param PackageInterface[] $packages - * @return array + * @return non-empty-array */ public function buildPackageMap(InstallationManager $installationManager, PackageInterface $rootPackage, array $packages) { @@ -485,14 +485,9 @@ EOF; continue; } $this->validatePackage($package); - $installPath = $installationManager->getInstallPath($package); - if ($installPath === null) { - continue; - } - $packageMap[] = [ $package, - $installPath, + $installationManager->getInstallPath($package), ]; } @@ -523,7 +518,7 @@ EOF; /** * Compiles an ordered list of namespace => path mappings * - * @param array $packageMap array of array(package, installDir-relative-to-composer.json) + * @param non-empty-array $packageMap array of array(package, installDir-relative-to-composer.json or null for metapackages) * @param RootPackageInterface $rootPackage root package instance * @param bool|string[] $filteredDevPackages If an array, the list of packages that must be removed. If bool, whether to filter out require-dev packages * @return array @@ -613,7 +608,7 @@ EOF; } /** - * @param array $packageMap + * @param array $packageMap * @return ?string */ protected function getIncludePathsFile(array $packageMap, Filesystem $filesystem, string $basePath, string $vendorPath, string $vendorPathCode, string $appBaseDirCode) @@ -623,6 +618,11 @@ EOF; foreach ($packageMap as $item) { [$package, $installPath] = $item; + // packages that are not installed cannot autoload anything + if (null === $installPath) { + continue; + } + if (null !== $package->getTargetDir() && strlen($package->getTargetDir()) > 0) { $installPath = substr($installPath, 0, -strlen('/'.$package->getTargetDir())); } @@ -716,7 +716,7 @@ EOF; } /** - * @param array $packageMap + * @param array $packageMap * @param bool|'php-only' $checkPlatform * @param string[] $devPackageNames * @return ?string @@ -1149,7 +1149,7 @@ INITIALIZER; } /** - * @param array $packageMap + * @param array $packageMap * @param string $type one of: 'psr-0'|'psr-4'|'classmap'|'files' * @return array|array>|array */ @@ -1160,6 +1160,11 @@ INITIALIZER; foreach ($packageMap as $item) { [$package, $installPath] = $item; + // packages that are not installed cannot autoload anything + if (null === $installPath) { + continue; + } + $autoload = $package->getAutoload(); if ($this->devMode && $package === $rootPackage) { $autoload = array_merge_recursive($autoload, $package->getDevAutoload()); @@ -1249,10 +1254,8 @@ INITIALIZER; /** * Filters out dev-dependencies * - * @param array $packageMap - * @return array - * - * @phpstan-param array $packageMap + * @param array $packageMap + * @return array */ protected function filterPackageMap(array $packageMap, RootPackageInterface $rootPackage) { @@ -1305,8 +1308,8 @@ INITIALIZER; * * Packages of equal weight are sorted alphabetically * - * @param array $packageMap - * @return array + * @param array $packageMap + * @return array */ protected function sortPackageMap(array $packageMap) { diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 134bcf222..f1a49b251 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -131,7 +131,11 @@ class AutoloadGeneratorTest extends TestCase ->getMock(); $this->im->expects($this->any()) ->method('getInstallPath') - ->will($this->returnCallback(function ($package): string { + ->will($this->returnCallback(function ($package): ?string { + if ($package->getType() === 'metapackage') { + return null; + } + $targetDir = $package->getTargetDir(); return $this->vendorDir.'/'.$package->getName() . ($targetDir ? '/'.$targetDir : ''); @@ -398,6 +402,40 @@ class AutoloadGeneratorTest extends TestCase $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated, even if empty."); } + public function testVendorsAutoloadingWithMetapackages(): void + { + $package = new RootPackage('root/a', '1.0', '1.0'); + $package->setRequires([ + 'a/a' => new Link('a', 'a/a', new MatchAllConstraint()), + ]); + + $packages = []; + $packages[] = $a = new Package('a/a', '1.0', '1.0'); + $packages[] = $b = new Package('b/b', '1.0', '1.0'); + $packages[] = $c = new AliasPackage($b, '1.2', '1.2'); + $a->setAutoload(['psr-0' => ['A' => 'src/', 'A\\B' => 'lib/']]); + $b->setAutoload(['psr-0' => ['B\\Sub\\Name' => 'src/']]); + $a->setType('metapackage'); + $a->setRequires([ + 'b/b' => new Link('a/a', 'b/b', new MatchAllConstraint()), + ]); + + $this->repository->expects($this->once()) + ->method('getCanonicalPackages') + ->will($this->returnValue($packages)); + + $this->fs->ensureDirectoryExists($this->vendorDir.'/composer'); + $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src'); + // creating a/a files to make sure they would be found by autoloader even tho they are technically not + // needed as the package is a metapackage, but if it fails to be excluded it would find these + $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src'); + $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/lib'); + + $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_5'); + $this->assertAutoloadFiles('vendors_meta', $this->vendorDir.'/composer'); + $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated, even if empty."); + } + public function testNonDevAutoloadExclusionWithRecursion(): void { $package = new RootPackage('root/a', '1.0', '1.0'); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_vendors_meta.php b/tests/Composer/Test/Autoload/Fixtures/autoload_vendors_meta.php new file mode 100644 index 000000000..551e64fb8 --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_vendors_meta.php @@ -0,0 +1,10 @@ + array($vendorDir . '/b/b/src'), +); From b982883e9d9c7b7f2a522f6d45e1b8212f870478 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 24 May 2023 15:00:25 +0200 Subject: [PATCH 4/6] Update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d75a0992..2a96e5d37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### [2.5.7] 2023-05-24 + + * Fixed regression preventing autoloading the dependencies of metapackages when running --no-dev (#11481) + ### [2.5.6] 2023-05-24 * BC Warning: Installers and `InstallationManager::getInstallPath` will now return `null` instead of an empty string for metapackages' paths. This may have adverse effects on plugin code using this expecting always a string but it is unlikely (#11455) @@ -1720,6 +1724,7 @@ * Initial release +[2.5.7]: https://github.com/composer/composer/compare/2.5.6...2.5.7 [2.5.6]: https://github.com/composer/composer/compare/2.5.5...2.5.6 [2.5.5]: https://github.com/composer/composer/compare/2.5.4...2.5.5 [2.5.4]: https://github.com/composer/composer/compare/2.5.3...2.5.4 From d477018d3f2ebd76dede3d3988a0b1a7add4d81e Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 24 May 2023 15:00:40 +0200 Subject: [PATCH 5/6] Release 2.5.7 --- src/Composer/Composer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Composer/Composer.php b/src/Composer/Composer.php index 8a870cc47..0f69d35e1 100644 --- a/src/Composer/Composer.php +++ b/src/Composer/Composer.php @@ -51,10 +51,10 @@ class Composer extends PartialComposer * * @see getVersion() */ - public const VERSION = '@package_version@'; - public const BRANCH_ALIAS_VERSION = '@package_branch_alias_version@'; - public const RELEASE_DATE = '@release_date@'; - public const SOURCE_VERSION = '2.5.999-dev+source'; + public const VERSION = '2.5.7'; + public const BRANCH_ALIAS_VERSION = ''; + public const RELEASE_DATE = '2023-05-24 15:00:39'; + public const SOURCE_VERSION = ''; /** * Version number of the internal composer-runtime-api package From 7d6c76ee790b2f9883f52f8c219cea1c6e47bedb Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 24 May 2023 15:00:43 +0200 Subject: [PATCH 6/6] Reverting release version changes --- src/Composer/Composer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Composer/Composer.php b/src/Composer/Composer.php index 0f69d35e1..8a870cc47 100644 --- a/src/Composer/Composer.php +++ b/src/Composer/Composer.php @@ -51,10 +51,10 @@ class Composer extends PartialComposer * * @see getVersion() */ - public const VERSION = '2.5.7'; - public const BRANCH_ALIAS_VERSION = ''; - public const RELEASE_DATE = '2023-05-24 15:00:39'; - public const SOURCE_VERSION = ''; + public const VERSION = '@package_version@'; + public const BRANCH_ALIAS_VERSION = '@package_branch_alias_version@'; + public const RELEASE_DATE = '@release_date@'; + public const SOURCE_VERSION = '2.5.999-dev+source'; /** * Version number of the internal composer-runtime-api package