Change installs into updates if there is no lock file, simplify some code, fixes #5034
parent
653326e215
commit
55b0ed8c8b
|
@ -171,6 +171,11 @@ class Installer
|
|||
gc_collect_cycles();
|
||||
gc_disable();
|
||||
|
||||
// Force update if there is no lock file present
|
||||
if (!$this->update && !$this->locker->isLocked()) {
|
||||
$this->update = true;
|
||||
}
|
||||
|
||||
if ($this->dryRun) {
|
||||
$this->verbose = true;
|
||||
$this->runScripts = false;
|
||||
|
@ -196,10 +201,10 @@ class Installer
|
|||
|
||||
// create installed repo, this contains all local packages + platform packages (php & extensions)
|
||||
$localRepo = $this->repositoryManager->getLocalRepository();
|
||||
if (!$this->update && $this->locker->isLocked()) {
|
||||
$platformOverrides = $this->locker->getPlatformOverrides();
|
||||
} else {
|
||||
if ($this->update) {
|
||||
$platformOverrides = $this->config->get('platform') ?: array();
|
||||
} else {
|
||||
$platformOverrides = $this->locker->getPlatformOverrides();
|
||||
}
|
||||
$platformRepo = new PlatformRepository(array(), $platformOverrides);
|
||||
$repos = array(
|
||||
|
@ -261,7 +266,7 @@ class Installer
|
|||
|
||||
if (!$this->dryRun) {
|
||||
// write lock
|
||||
if ($this->update || !$this->locker->isLocked()) {
|
||||
if ($this->update) {
|
||||
$localRepo->reload();
|
||||
|
||||
// if this is not run in dev mode and the root has dev requires, the lock must
|
||||
|
@ -362,13 +367,10 @@ class Installer
|
|||
$lockedRepository = null;
|
||||
$repositories = null;
|
||||
|
||||
// initialize locker to create aliased packages
|
||||
$installFromLock = !$this->update && $this->locker->isLocked();
|
||||
|
||||
// initialize locked repo if we are installing from lock or in a partial update
|
||||
// and a lock file is present as we need to force install non-whitelisted lock file
|
||||
// packages in that case
|
||||
if ($installFromLock || (!empty($this->updateWhitelist) && $this->locker->isLocked())) {
|
||||
if (!$this->update || (!empty($this->updateWhitelist) && $this->locker->isLocked())) {
|
||||
try {
|
||||
$lockedRepository = $this->locker->getLockedRepository($withDevReqs);
|
||||
} catch (\RuntimeException $e) {
|
||||
|
@ -392,9 +394,9 @@ class Installer
|
|||
|
||||
// creating repository pool
|
||||
$policy = $this->createPolicy();
|
||||
$pool = $this->createPool($withDevReqs, $installFromLock ? $lockedRepository : null);
|
||||
$pool = $this->createPool($withDevReqs, $this->update ? null : $lockedRepository);
|
||||
$pool->addRepository($installedRepo, $aliases);
|
||||
if (!$installFromLock) {
|
||||
if ($this->update) {
|
||||
$repositories = $this->repositoryManager->getRepositories();
|
||||
foreach ($repositories as $repository) {
|
||||
$pool->addRepository($repository, $aliases);
|
||||
|
@ -410,7 +412,7 @@ class Installer
|
|||
// creating requirements request
|
||||
$request = $this->createRequest($this->package, $platformRepo);
|
||||
|
||||
if (!$installFromLock) {
|
||||
if ($this->update) {
|
||||
// remove unstable packages from the localRepo if they don't match the current stability settings
|
||||
$removedUnstablePackages = array();
|
||||
foreach ($localRepo->getPackages() as $package) {
|
||||
|
@ -422,9 +424,7 @@ class Installer
|
|||
$request->remove($package->getName(), new Constraint('=', $package->getVersion()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->update) {
|
||||
$this->io->writeError('<info>Updating dependencies'.($withDevReqs ? ' (including require-dev)' : '').'</info>');
|
||||
|
||||
$request->updateAll();
|
||||
|
@ -466,7 +466,7 @@ class Installer
|
|||
}
|
||||
}
|
||||
}
|
||||
} elseif ($installFromLock) {
|
||||
} else {
|
||||
$this->io->writeError('<info>Installing dependencies'.($withDevReqs ? ' (including require-dev)' : '').' from lock file</info>');
|
||||
|
||||
if (!$this->locker->isFresh()) {
|
||||
|
@ -486,22 +486,10 @@ class Installer
|
|||
foreach ($this->locker->getPlatformRequirements($withDevReqs) as $link) {
|
||||
$request->install($link->getTarget(), $link->getConstraint());
|
||||
}
|
||||
} else {
|
||||
$this->io->writeError('<info>Installing dependencies'.($withDevReqs ? ' (including require-dev)' : '').'</info>');
|
||||
|
||||
if ($withDevReqs) {
|
||||
$links = array_merge($this->package->getRequires(), $this->package->getDevRequires());
|
||||
} else {
|
||||
$links = $this->package->getRequires();
|
||||
}
|
||||
|
||||
foreach ($links as $link) {
|
||||
$request->install($link->getTarget(), $link->getConstraint());
|
||||
}
|
||||
}
|
||||
|
||||
// force dev packages to have the latest links if we update or install from a (potentially new) lock
|
||||
$this->processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, $installFromLock, $withDevReqs, 'force-links');
|
||||
$this->processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, $withDevReqs, 'force-links');
|
||||
|
||||
// solve dependencies
|
||||
$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $pool, $installedRepo, $request);
|
||||
|
@ -520,7 +508,7 @@ class Installer
|
|||
$this->io->writeError("Analyzed ".$solver->getRuleSetSize()." rules to resolve dependencies", true, IOInterface::VERBOSE);
|
||||
|
||||
// force dev packages to be updated if we update or install from a (potentially new) lock
|
||||
$operations = $this->processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, $installFromLock, $withDevReqs, 'force-updates', $operations);
|
||||
$operations = $this->processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, $withDevReqs, 'force-updates', $operations);
|
||||
|
||||
// execute operations
|
||||
if (!$operations) {
|
||||
|
@ -536,8 +524,8 @@ class Installer
|
|||
$this->suggestedPackagesReporter->addSuggestionsFromPackage($operation->getPackage());
|
||||
}
|
||||
|
||||
// not installing from lock, force dev packages' references if they're in root package refs
|
||||
if (!$installFromLock) {
|
||||
// updating, force dev packages' references if they're in root package refs
|
||||
if ($this->update) {
|
||||
$package = null;
|
||||
if ('update' === $operation->getJobType()) {
|
||||
$package = $operation->getTargetPackage();
|
||||
|
@ -687,7 +675,15 @@ class Installer
|
|||
*/
|
||||
private function createPool($withDevReqs, RepositoryInterface $lockedRepository = null)
|
||||
{
|
||||
if (!$this->update && $this->locker->isLocked()) { // install from lock
|
||||
if ($this->update) {
|
||||
$minimumStability = $this->package->getMinimumStability();
|
||||
$stabilityFlags = $this->package->getStabilityFlags();
|
||||
|
||||
$requires = $this->package->getRequires();
|
||||
if ($withDevReqs) {
|
||||
$requires = array_merge($requires, $this->package->getDevRequires());
|
||||
}
|
||||
} else {
|
||||
$minimumStability = $this->locker->getMinimumStability();
|
||||
$stabilityFlags = $this->locker->getStabilityFlags();
|
||||
|
||||
|
@ -697,14 +693,6 @@ class Installer
|
|||
$constraint->setPrettyString($package->getPrettyVersion());
|
||||
$requires[$package->getName()] = $constraint;
|
||||
}
|
||||
} else {
|
||||
$minimumStability = $this->package->getMinimumStability();
|
||||
$stabilityFlags = $this->package->getStabilityFlags();
|
||||
|
||||
$requires = $this->package->getRequires();
|
||||
if ($withDevReqs) {
|
||||
$requires = array_merge($requires, $this->package->getDevRequires());
|
||||
}
|
||||
}
|
||||
|
||||
$rootConstraints = array();
|
||||
|
@ -730,7 +718,7 @@ class Installer
|
|||
{
|
||||
$preferStable = null;
|
||||
$preferLowest = null;
|
||||
if (!$this->update && $this->locker->isLocked()) {
|
||||
if (!$this->update) {
|
||||
$preferStable = $this->locker->getPreferStable();
|
||||
$preferLowest = $this->locker->getPreferLowest();
|
||||
}
|
||||
|
@ -791,13 +779,12 @@ class Installer
|
|||
* @param array $repositories
|
||||
* @param RepositoryInterface $installedRepo
|
||||
* @param RepositoryInterface $lockedRepository
|
||||
* @param bool $installFromLock
|
||||
* @param bool $withDevReqs
|
||||
* @param string $task
|
||||
* @param array|null $operations
|
||||
* @return array
|
||||
*/
|
||||
private function processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, $installFromLock, $withDevReqs, $task, array $operations = null)
|
||||
private function processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, $withDevReqs, $task, array $operations = null)
|
||||
{
|
||||
if ($task === 'force-updates' && null === $operations) {
|
||||
throw new \InvalidArgumentException('Missing operations argument');
|
||||
|
@ -806,7 +793,7 @@ class Installer
|
|||
$operations = array();
|
||||
}
|
||||
|
||||
if (!$installFromLock && $this->updateWhitelist) {
|
||||
if ($this->update && $this->updateWhitelist) {
|
||||
$currentPackages = $this->getCurrentPackages($withDevReqs, $installedRepo);
|
||||
}
|
||||
|
||||
|
@ -825,28 +812,6 @@ class Installer
|
|||
}
|
||||
}
|
||||
|
||||
// force update to locked version if it does not match the installed version
|
||||
if ($installFromLock) {
|
||||
foreach ($lockedRepository->findPackages($package->getName()) as $lockedPackage) {
|
||||
if ($lockedPackage->isDev() && $lockedPackage->getVersion() === $package->getVersion()) {
|
||||
if ($task === 'force-links') {
|
||||
$package->setRequires($lockedPackage->getRequires());
|
||||
$package->setConflicts($lockedPackage->getConflicts());
|
||||
$package->setProvides($lockedPackage->getProvides());
|
||||
$package->setReplaces($lockedPackage->getReplaces());
|
||||
} elseif ($task === 'force-updates') {
|
||||
if (($lockedPackage->getSourceReference() && $lockedPackage->getSourceReference() !== $package->getSourceReference())
|
||||
|| ($lockedPackage->getDistReference() && $lockedPackage->getDistReference() !== $package->getDistReference())
|
||||
) {
|
||||
$operations[] = new UpdateOperation($package, $lockedPackage);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// force update to latest on update
|
||||
if ($this->update) {
|
||||
// skip package if the whitelist is enabled and it is not in it
|
||||
if ($this->updateWhitelist && !$this->isUpdateable($package)) {
|
||||
|
@ -910,7 +875,6 @@ class Installer
|
|||
$operations[] = new UpdateOperation($package, $newPackage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($task === 'force-updates') {
|
||||
// force installed package to update to referenced version in root package if it does not match the installed version
|
||||
|
@ -921,6 +885,26 @@ class Installer
|
|||
$operations[] = new UpdateOperation($package, clone $package);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// force update to locked version if it does not match the installed version
|
||||
foreach ($lockedRepository->findPackages($package->getName()) as $lockedPackage) {
|
||||
if ($lockedPackage->isDev() && $lockedPackage->getVersion() === $package->getVersion()) {
|
||||
if ($task === 'force-links') {
|
||||
$package->setRequires($lockedPackage->getRequires());
|
||||
$package->setConflicts($lockedPackage->getConflicts());
|
||||
$package->setProvides($lockedPackage->getProvides());
|
||||
$package->setReplaces($lockedPackage->getReplaces());
|
||||
} elseif ($task === 'force-updates') {
|
||||
if (($lockedPackage->getSourceReference() && $lockedPackage->getSourceReference() !== $package->getSourceReference())
|
||||
|| ($lockedPackage->getDistReference() && $lockedPackage->getDistReference() !== $package->getDistReference())
|
||||
) {
|
||||
$operations[] = new UpdateOperation($package, $lockedPackage);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -952,10 +936,10 @@ class Installer
|
|||
*/
|
||||
private function getRootAliases()
|
||||
{
|
||||
if (!$this->update && $this->locker->isLocked()) {
|
||||
$aliases = $this->locker->getAliases();
|
||||
} else {
|
||||
if ($this->update) {
|
||||
$aliases = $this->package->getAliases();
|
||||
} else {
|
||||
$aliases = $this->locker->getAliases();
|
||||
}
|
||||
|
||||
$normalizedAliases = array();
|
||||
|
|
|
@ -7,7 +7,7 @@ Installing seld/jsonlint (1.0.0)
|
|||
|
||||
Created project in %testDir%
|
||||
Loading composer repositories with package information
|
||||
Installing dependencies (including require-dev)
|
||||
Updating dependencies (including require-dev)
|
||||
Nothing to install or update
|
||||
Writing lock file
|
||||
Generating autoload files
|
||||
|
|
|
@ -25,7 +25,7 @@ Abandoned packages are flagged
|
|||
install
|
||||
--EXPECT-OUTPUT--
|
||||
Loading composer repositories with package information
|
||||
Installing dependencies (including require-dev)
|
||||
Updating dependencies (including require-dev)
|
||||
<warning>Package a/a is abandoned, you should avoid using it. No replacement was suggested.</warning>
|
||||
<warning>Package c/c is abandoned, you should avoid using it. Use b/b instead.</warning>
|
||||
Writing lock file
|
||||
|
|
|
@ -22,7 +22,7 @@ Broken dependencies should not lead to a replacer being installed which is not m
|
|||
install
|
||||
--EXPECT-OUTPUT--
|
||||
Loading composer repositories with package information
|
||||
Installing dependencies (including require-dev)
|
||||
Updating dependencies (including require-dev)
|
||||
Your requirements could not be resolved to an installable set of packages.
|
||||
|
||||
Problem 1
|
||||
|
|
|
@ -32,7 +32,7 @@ install
|
|||
|
||||
--EXPECT-OUTPUT--
|
||||
Loading composer repositories with package information
|
||||
Installing dependencies (including require-dev)
|
||||
Updating dependencies (including require-dev)
|
||||
Your requirements could not be resolved to an installable set of packages.
|
||||
|
||||
Problem 1
|
||||
|
|
|
@ -20,7 +20,7 @@ Suggestions are not displayed for installed packages
|
|||
install
|
||||
--EXPECT-OUTPUT--
|
||||
Loading composer repositories with package information
|
||||
Installing dependencies (including require-dev)
|
||||
Updating dependencies (including require-dev)
|
||||
Writing lock file
|
||||
Generating autoload files
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ Suggestions are not displayed in non-dev mode
|
|||
install --no-dev
|
||||
--EXPECT-OUTPUT--
|
||||
Loading composer repositories with package information
|
||||
Installing dependencies
|
||||
Updating dependencies
|
||||
Writing lock file
|
||||
Generating autoload files
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ Suggestions are not displayed for packages if they are replaced
|
|||
install
|
||||
--EXPECT-OUTPUT--
|
||||
Loading composer repositories with package information
|
||||
Installing dependencies (including require-dev)
|
||||
Updating dependencies (including require-dev)
|
||||
Writing lock file
|
||||
Generating autoload files
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ Suggestions are displayed
|
|||
install
|
||||
--EXPECT-OUTPUT--
|
||||
Loading composer repositories with package information
|
||||
Installing dependencies (including require-dev)
|
||||
Updating dependencies (including require-dev)
|
||||
a/a suggests installing b/b (an obscure reason)
|
||||
Writing lock file
|
||||
Generating autoload files
|
||||
|
|
Loading…
Reference in New Issue