Skip to content
Snippets Groups Projects
Commit 747c518f authored by Wim Leers's avatar Wim Leers Committed by Adam G-H
Browse files

Issue #3363259 by Wim Leers, tedbow, phenaproxima, omkar.podey: Compatibility with Composer 2.5.7

parent 8a8cbe83
No related branches found
No related tags found
2 merge requests!989Issue #3356804 by phenaproxima: Flag a warning during status check if the...,!891Issue #3363259: Follow-up for #3350568: install latest version of composer, not 2.5.5, now that 2.5.7 is out and fixed the broken 2.5.6
...@@ -11,8 +11,8 @@ build: ...@@ -11,8 +11,8 @@ build:
commands: commands:
# Install rsync. # Install rsync.
- DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y rsync - DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y rsync
# Update to Composer 2.5.5. # Update to latest Composer.
- composer self-update 2.5.5 - composer self-update
# @todo Replace in favor of commit-code-check.sh once https://www.drupal.org/project/drupal/issues/3314100 lands. # @todo Replace in favor of commit-code-check.sh once https://www.drupal.org/project/drupal/issues/3314100 lands.
- modules/contrib/automatic_updates/scripts/commit-code-check.sh --drupalci - modules/contrib/automatic_updates/scripts/commit-code-check.sh --drupalci
halt-on-fail: true halt-on-fail: true
......
...@@ -317,23 +317,35 @@ class ComposerInspector implements LoggerAwareInterface { ...@@ -317,23 +317,35 @@ class ComposerInspector implements LoggerAwareInterface {
$packages_data = $this->getPackageTypes($packages_data, $working_dir); $packages_data = $this->getPackageTypes($packages_data, $working_dir);
foreach ($packages_data as $name => $package) { foreach ($packages_data as $name => $package) {
$path = realpath($package['path']); $path = $package['path'];
// We expect Composer to report that metapackages' install paths are the // We expect Composer to report that metapackages' install paths are the
// same as the working directory, in which case InstalledPackage::$path // same as the working directory, in which case InstalledPackage::$path
// should be NULL. For all other package types, we consider it invalid // should be NULL. For all other package types, we consider it invalid
// if the install path is the same as the working directory. // if the install path is the same as the working directory.
if ($package['type'] === 'metapackage') { // @todo Remove this handling of metapackage paths when Composer 2.5.7 or
if ($path === $working_dir) { // later is required, in https://drupal.org/i/3365133.
$packages_data[$name]['path'] = NULL; if (isset($package['type']) && $package['type'] === 'metapackage') {
// TRICKY: until Composer 2.5.6, metapackages returned the current
// working directory instead of NULL.
// @see https://github.com/composer/composer/commit/3a48e393756e8b0387925aa327f45a30128b4556
$packages_data[$name]['path'] = NULL;
// @todo Remove the if-branch when the minimum Composer version is raised to >=2.5.6.
if (Semver::satisfies($this->getVersion(), '<2.5.6')) {
if ($path !== $working_dir) {
throw new \UnexpectedValueException("Metapackage '$name' is installed at unexpected path: '$path', expected '$working_dir'");
}
} }
else { elseif ($path !== NULL) {
throw new \UnexpectedValueException("Metapackage '$name' is installed at unexpected path: '$path', expected '$working_dir'"); throw new \UnexpectedValueException("Metapackage '$name' is installed at unexpected path: '$path', expected NULL");
} }
} }
elseif ($path === $working_dir) { elseif ($path === $working_dir) {
throw new \UnexpectedValueException("Package '$name' cannot be installed at path: '$path'"); throw new \UnexpectedValueException("Package '$name' cannot be installed at path: '$path'");
} }
else {
$packages_data[$name]['path'] = realpath($path);
}
} }
$packages_data = array_map(InstalledPackage::createFromArray(...), $packages_data); $packages_data = array_map(InstalledPackage::createFromArray(...), $packages_data);
......
...@@ -40,9 +40,12 @@ final class InstalledPackage { ...@@ -40,9 +40,12 @@ final class InstalledPackage {
*/ */
public static function createFromArray(array $data): static { public static function createFromArray(array $data): static {
$path = isset($data['path']) ? realpath($data['path']) : NULL; $path = isset($data['path']) ? realpath($data['path']) : NULL;
assert(($data['type'] === 'metapackage') === is_null($path), 'Metapackage install path must be NULL.'); // Fall back to `library`.
// @see https://getcomposer.org/doc/04-schema.md#type
$type = $data['type'] ?? 'library';
assert(($type === 'metapackage') === is_null($path), 'Metapackage install path must be NULL.');
return new static($data['name'], $data['version'], $path, $data['type']); return new static($data['name'], $data['version'], $path, $type);
} }
/** /**
......
...@@ -348,8 +348,8 @@ class ComposerInspectorTest extends PackageManagerKernelTestBase { ...@@ -348,8 +348,8 @@ class ComposerInspectorTest extends PackageManagerKernelTestBase {
* *
* @covers ::getInstalledPackagesList * @covers ::getInstalledPackagesList
* *
* @testWith [true, "<PROJECT_ROOT>", null] * @testWith [true, null, null]
* [true, "<PROJECT_ROOT>/another/directory", "Metapackage 'test/package' is installed at unexpected path: '<PROJECT_ROOT>/another/directory', expected '<PROJECT_ROOT>'"] * [true, "<PROJECT_ROOT>/another/directory", "Metapackage 'test/package' is installed at unexpected path: '<PROJECT_ROOT>/another/directory', expected NULL"]
* [false, null, null] * [false, null, null]
* [false, "<PROJECT_ROOT>", "Package 'test/package' cannot be installed at path: '<PROJECT_ROOT>'"] * [false, "<PROJECT_ROOT>", "Package 'test/package' cannot be installed at path: '<PROJECT_ROOT>'"]
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment