1
0
Fork 0

Allow disabling execution of operations and lock writing independently from dryRun, closes #5787

pull/5873/merge
Jordi Boggiano 2016-12-06 22:40:47 +01:00
parent cd21d7e7d4
commit 3c1300bcaf
1 changed files with 87 additions and 47 deletions

View File

@ -115,6 +115,9 @@ class Installer
protected $preferStable = false; protected $preferStable = false;
protected $preferLowest = false; protected $preferLowest = false;
protected $skipSuggest = false; protected $skipSuggest = false;
protected $writeLock = true;
protected $executeOperations = true;
/** /**
* Array of package names/globs flagged for update * Array of package names/globs flagged for update
* *
@ -182,6 +185,9 @@ class Installer
if ($this->dryRun) { if ($this->dryRun) {
$this->verbose = true; $this->verbose = true;
$this->runScripts = false; $this->runScripts = false;
$this->executeOperations = false;
$this->writeLock = false;
$this->dumpAutoloader = false;
$this->installationManager->addInstaller(new NoopInstaller); $this->installationManager->addInstaller(new NoopInstaller);
$this->mockLocalRepositories($this->repositoryManager); $this->mockLocalRepositories($this->repositoryManager);
} }
@ -218,13 +224,13 @@ class Installer
return $res; return $res;
} }
} catch (\Exception $e) { } catch (\Exception $e) {
if (!$this->dryRun) { if ($this->executeOperations) {
$this->installationManager->notifyInstalls($this->io); $this->installationManager->notifyInstalls($this->io);
} }
throw $e; throw $e;
} }
if (!$this->dryRun) { if ($this->executeOperations) {
$this->installationManager->notifyInstalls($this->io); $this->installationManager->notifyInstalls($this->io);
} }
@ -252,54 +258,54 @@ class Installer
); );
} }
if (!$this->dryRun) { // write lock
// write lock if ($this->update && $this->writeLock) {
if ($this->update) { $localRepo->reload();
$localRepo->reload();
$platformReqs = $this->extractPlatformRequirements($this->package->getRequires()); $platformReqs = $this->extractPlatformRequirements($this->package->getRequires());
$platformDevReqs = $this->extractPlatformRequirements($this->package->getDevRequires()); $platformDevReqs = $this->extractPlatformRequirements($this->package->getDevRequires());
$updatedLock = $this->locker->setLockData( $updatedLock = $this->locker->setLockData(
array_diff($localRepo->getCanonicalPackages(), $devPackages), array_diff($localRepo->getCanonicalPackages(), $devPackages),
$devPackages, $devPackages,
$platformReqs, $platformReqs,
$platformDevReqs, $platformDevReqs,
$aliases, $aliases,
$this->package->getMinimumStability(), $this->package->getMinimumStability(),
$this->package->getStabilityFlags(), $this->package->getStabilityFlags(),
$this->preferStable || $this->package->getPreferStable(), $this->preferStable || $this->package->getPreferStable(),
$this->preferLowest, $this->preferLowest,
$this->config->get('platform') ?: array() $this->config->get('platform') ?: array()
); );
if ($updatedLock) { if ($updatedLock) {
$this->io->writeError('<info>Writing lock file</info>'); $this->io->writeError('<info>Writing lock file</info>');
} }
}
if ($this->dumpAutoloader) {
// write autoloader
if ($this->optimizeAutoloader) {
$this->io->writeError('<info>Generating optimized autoload files</info>');
} else {
$this->io->writeError('<info>Generating autoload files</info>');
} }
if ($this->dumpAutoloader) { $this->autoloadGenerator->setDevMode($this->devMode);
// write autoloader $this->autoloadGenerator->setClassMapAuthoritative($this->classMapAuthoritative);
if ($this->optimizeAutoloader) { $this->autoloadGenerator->setRunScripts($this->runScripts);
$this->io->writeError('<info>Generating optimized autoload files</info>'); $this->autoloadGenerator->dump($this->config, $localRepo, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloader);
} else { }
$this->io->writeError('<info>Generating autoload files</info>');
}
$this->autoloadGenerator->setDevMode($this->devMode); if ($this->runScripts) {
$this->autoloadGenerator->setClassMapAuthoritative($this->classMapAuthoritative); $devMode = (int) $this->devMode;
$this->autoloadGenerator->setRunScripts($this->runScripts); putenv("COMPOSER_DEV_MODE=$devMode");
$this->autoloadGenerator->dump($this->config, $localRepo, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloader);
}
if ($this->runScripts) { // dispatch post event
$devMode = (int) $this->devMode; $eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
putenv("COMPOSER_DEV_MODE=$devMode"); $this->eventDispatcher->dispatchScript($eventName, $this->devMode);
}
// dispatch post event
$eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
$this->eventDispatcher->dispatchScript($eventName, $this->devMode);
}
if ($this->executeOperations) {
// force binaries re-generation in case they are missing // force binaries re-generation in case they are missing
foreach ($localRepo->getPackages() as $package) { foreach ($localRepo->getPackages() as $package) {
$this->installationManager->ensureBinariesPresence($package); $this->installationManager->ensureBinariesPresence($package);
@ -566,8 +572,8 @@ class Installer
$this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation); $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
} }
// output non-alias ops in dry run, output alias ops in debug verbosity // output non-alias ops when not executing operations (i.e. dry run), output alias ops in debug verbosity
if ($this->dryRun && false === strpos($operation->getJobType(), 'Alias')) { if (!$this->executeOperations && false === strpos($operation->getJobType(), 'Alias')) {
$this->io->writeError(' - ' . $operation); $this->io->writeError(' - ' . $operation);
$this->io->writeError(''); $this->io->writeError('');
} elseif ($this->io->isDebug() && false !== strpos($operation->getJobType(), 'Alias')) { } elseif ($this->io->isDebug() && false !== strpos($operation->getJobType(), 'Alias')) {
@ -599,12 +605,12 @@ class Installer
$this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation); $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
} }
if (!$this->dryRun) { if ($this->executeOperations) {
$localRepo->write(); $localRepo->write();
} }
} }
if (!$this->dryRun) { if ($this->executeOperations) {
// force source/dist urls to be updated for all packages // force source/dist urls to be updated for all packages
$this->processPackageUrls($pool, $policy, $localRepo, $repositories); $this->processPackageUrls($pool, $policy, $localRepo, $repositories);
$localRepo->write(); $localRepo->write();
@ -1521,6 +1527,8 @@ class Installer
/** /**
* set whether to run autoloader or not * set whether to run autoloader or not
* *
* This is disabled implicitly when enabling dryRun
*
* @param bool $dumpAutoloader * @param bool $dumpAutoloader
* @return Installer * @return Installer
*/ */
@ -1534,6 +1542,8 @@ class Installer
/** /**
* set whether to run scripts or not * set whether to run scripts or not
* *
* This is disabled implicitly when enabling dryRun
*
* @param bool $runScripts * @param bool $runScripts
* @return Installer * @return Installer
*/ */
@ -1646,6 +1656,36 @@ class Installer
return $this; return $this;
} }
/**
* Should the lock file be updated when updating?
*
* This is disabled implicitly when enabling dryRun
*
* @param bool $writeLock
* @return Installer
*/
public function setWriteLock($writeLock = true)
{
$this->writeLock = (boolean) $writeLock;
return $this;
}
/**
* Should the operations (packge install, update and removal) be executed on disk?
*
* This is disabled implicitly when enabling dryRun
*
* @param bool $executeOperations
* @return Installer
*/
public function setExecuteOperations($executeOperations = true)
{
$this->executeOperations = (boolean) $executeOperations;
return $this;
}
/** /**
* Should suggestions be skipped? * Should suggestions be skipped?
* *