1
0
Fork 0

On composer install we fix locked packages, but consider them locked for error reporting

pull/9223/head
Nils Adermann 2020-10-14 10:57:23 +02:00
parent 74fb313c39
commit fdde9e5933
5 changed files with 18 additions and 8 deletions

View File

@ -45,6 +45,7 @@ class Request
protected $requires = array(); protected $requires = array();
protected $fixedPackages = array(); protected $fixedPackages = array();
protected $lockedPackages = array(); protected $lockedPackages = array();
protected $fixedLockedPackages = array();
protected $updateAllowList = array(); protected $updateAllowList = array();
protected $updateAllowTransitiveDependencies = false; protected $updateAllowTransitiveDependencies = false;
@ -84,6 +85,15 @@ class Request
$this->lockedPackages[spl_object_hash($package)] = $package; $this->lockedPackages[spl_object_hash($package)] = $package;
} }
/**
* Mark a package fixed, but also keep track it is from the lock file (needed for composer install error reporting)
*/
public function fixLockedPackage(PackageInterface $package)
{
$this->fixedPackages[spl_object_hash($package)] = $package;
$this->fixedLockedPackages[spl_object_hash($package)] = $package;
}
public function unlockPackage(PackageInterface $package) public function unlockPackage(PackageInterface $package)
{ {
unset($this->lockedPackages[spl_object_hash($package)]); unset($this->lockedPackages[spl_object_hash($package)]);
@ -132,7 +142,7 @@ class Request
public function isLockedPackage(PackageInterface $package) public function isLockedPackage(PackageInterface $package)
{ {
return isset($this->lockedPackages[spl_object_hash($package)]); return isset($this->lockedPackages[spl_object_hash($package)]) || isset($this->fixedLockedPackages[spl_object_hash($package)]);
} }
public function getFixedOrLockedPackages() public function getFixedOrLockedPackages()

View File

@ -199,6 +199,10 @@ abstract class Rule
case self::RULE_FIXED: case self::RULE_FIXED:
$package = $this->deduplicateDefaultBranchAlias($this->reasonData['package']); $package = $this->deduplicateDefaultBranchAlias($this->reasonData['package']);
if ($request->isLockedPackage($package)) {
return $package->getPrettyName().' is locked to version '.$package->getPrettyVersion().' and an update of this package was not requested.';
}
return $package->getPrettyName().' is present at version '.$package->getPrettyVersion() . ' and cannot be modified by Composer'; return $package->getPrettyName().' is present at version '.$package->getPrettyVersion() . ' and cannot be modified by Composer';
case self::RULE_PACKAGE_CONFLICT: case self::RULE_PACKAGE_CONFLICT:

View File

@ -633,7 +633,7 @@ class Installer
} }
foreach ($lockedRepository->getPackages() as $package) { foreach ($lockedRepository->getPackages() as $package) {
$request->fixPackage($package); $request->fixLockedPackage($package);
} }
foreach ($this->locker->getPlatformRequirements($this->devMode) as $link) { foreach ($this->locker->getPlatformRequirements($this->devMode) as $link) {
@ -651,7 +651,6 @@ class Installer
// installing the locked packages on this platform resulted in lock modifying operations, there wasn't a conflict, but the lock file as-is seems to not work on this system // installing the locked packages on this platform resulted in lock modifying operations, there wasn't a conflict, but the lock file as-is seems to not work on this system
if (0 !== count($lockTransaction->getOperations())) { if (0 !== count($lockTransaction->getOperations())) {
$this->io->writeError('<error>Your lock file cannot be installed on this system without changes. Please run composer update.</error>', true, IOInterface::QUIET); $this->io->writeError('<error>Your lock file cannot be installed on this system without changes. Please run composer update.</error>', true, IOInterface::QUIET);
// TODO actually display operations to explain what happened?
return 1; return 1;
} }
} catch (SolverProblemsException $e) { } catch (SolverProblemsException $e) {

View File

@ -21,7 +21,8 @@ Partial update from lock file should update everything to the state of the lock,
"require": { "require": {
"a/old": "*", "a/old": "*",
"b/unstable": "*", "b/unstable": "*",
"c/uptodate": "*" "c/uptodate": "*",
"e/newreq": "*"
} }
} }
--LOCK-- --LOCK--
@ -60,7 +61,6 @@ update b/unstable
{ "name": "a/old", "version": "1.0.0", "type": "library" }, { "name": "a/old", "version": "1.0.0", "type": "library" },
{ "name": "b/unstable", "version": "1.0.0", "type": "library", "require": {"f/dependency": "1.*"} }, { "name": "b/unstable", "version": "1.0.0", "type": "library", "require": {"f/dependency": "1.*"} },
{ "name": "c/uptodate", "version": "1.0.0", "type": "library" }, { "name": "c/uptodate", "version": "1.0.0", "type": "library" },
{ "name": "d/removed", "version": "1.0.0", "type": "library" },
{ "name": "e/newreq", "version": "1.0.0", "type": "library" }, { "name": "e/newreq", "version": "1.0.0", "type": "library" },
{ "name": "f/dependency", "version": "1.0.0", "type": "library" } { "name": "f/dependency", "version": "1.0.0", "type": "library" }
], ],
@ -77,5 +77,4 @@ update b/unstable
Upgrading a/old (0.9.0 => 1.0.0) Upgrading a/old (0.9.0 => 1.0.0)
Downgrading b/unstable (1.1.0-alpha => 1.0.0) Downgrading b/unstable (1.1.0-alpha => 1.0.0)
Downgrading c/uptodate (2.0.0 => 1.0.0) Downgrading c/uptodate (2.0.0 => 1.0.0)
Installing d/removed (1.0.0)
Installing e/newreq (1.0.0) Installing e/newreq (1.0.0)

View File

@ -62,6 +62,4 @@ Your lock file does not contain a compatible set of packages. Please run compose
- b/requirer is locked to version 1.0.0 and an update of this package was not requested. - b/requirer is locked to version 1.0.0 and an update of this package was not requested.
- b/requirer 1.0.0 requires root/pkg ^1 -> found root/pkg[2.x-dev] but it does not match the constraint. - b/requirer 1.0.0 requires root/pkg ^1 -> found root/pkg[2.x-dev] but it does not match the constraint.
Use the option --with-all-dependencies to allow upgrades, downgrades and removals for packages currently locked to specific versions.
--EXPECT-- --EXPECT--