1
0
Fork 0

Merge pull request #336 from naderman/solver-only-error-reporting

Errors are now reported solely by the solver without any workarounds
pull/339/merge
Jordi Boggiano 2012-02-20 04:05:55 -08:00
commit 93ac0eb523
3 changed files with 7 additions and 59 deletions

View File

@ -156,34 +156,6 @@ EOT
// solve dependencies // solve dependencies
$operations = $solver->solve($request); $operations = $solver->solve($request);
// check for missing deps
// TODO this belongs in the solver, but this will do for now to report top-level deps missing at least
foreach ($request->getJobs() as $job) {
if ('install' === $job['cmd']) {
foreach ($installedRepo->getPackages() as $package ) {
if ($installedRepo->hasPackage($package) && !$package->isPlatform() && !$installationManager->isPackageInstalled($package)) {
$operations[$job['packageName']] = new InstallOperation($package, Solver::RULE_PACKAGE_NOT_EXIST);
}
if (in_array($job['packageName'], $package->getNames())) {
continue 2;
}
}
foreach ($operations as $operation) {
if ('install' === $operation->getJobType() && in_array($job['packageName'], $operation->getPackage()->getNames())) {
continue 2;
}
if ('update' === $operation->getJobType() && in_array($job['packageName'], $operation->getTargetPackage()->getNames())) {
continue 2;
}
}
if ($pool->whatProvides($job['packageName'])) {
throw new \UnexpectedValueException('Package '.$job['packageName'].' can not be installed, either because its version constraint is incorrect, or because one of its dependencies was not found.');
}
throw new \UnexpectedValueException('Package '.$job['packageName'].' was not found in the package pool, check the name for typos.');
}
}
// execute operations // execute operations
if (!$operations) { if (!$operations) {
$io->write('<info>Nothing to install/update</info>'); $io->write('<info>Nothing to install/update</info>');

View File

@ -147,10 +147,6 @@ class Solver
*/ */
protected function createInstallOneOfRule(array $packages, $reason, $reasonData = null) protected function createInstallOneOfRule(array $packages, $reason, $reasonData = null)
{ {
if (empty($packages)) {
return $this->createImpossibleRule($reason, $reasonData);
}
$literals = array(); $literals = array();
foreach ($packages as $package) { foreach ($packages as $package) {
$literals[] = new Literal($package, true); $literals[] = new Literal($package, true);
@ -200,22 +196,6 @@ class Solver
return new Rule(array(new Literal($issuer, false), new Literal($provider, false)), $reason, $reasonData); return new Rule(array(new Literal($issuer, false), new Literal($provider, false)), $reason, $reasonData);
} }
/**
* Intentionally creates a rule impossible to solve
*
* The rule is an empty one so it can never be satisfied.
*
* @param int $reason A RULE_* constant describing the reason for
* generating this rule
* @param mixed $reasonData Any data, e.g. the package name, that goes with
* the reason
* @return Rule An empty rule
*/
protected function createImpossibleRule($reason, $reasonData = null)
{
return new Rule(array(), $reason, $reasonData);
}
/** /**
* Adds a rule unless it duplicates an existing one of any type * Adds a rule unless it duplicates an existing one of any type
* *
@ -972,12 +952,6 @@ class Solver
foreach ($this->jobs as $job) { foreach ($this->jobs as $job) {
if (empty($job['packages']) && $job['cmd'] == 'install') {
$this->addRule(
RuleSet::TYPE_JOB,
$this->createImpossibleRule(static::RULE_JOB_INSTALL, $job)
);
}
foreach ($job['packages'] as $package) { foreach ($job['packages'] as $package) {
switch ($job['cmd']) { switch ($job['cmd']) {
case 'install': case 'install':
@ -1002,9 +976,13 @@ class Solver
foreach ($this->jobs as $job) { foreach ($this->jobs as $job) {
switch ($job['cmd']) { switch ($job['cmd']) {
case 'install': case 'install':
if (empty($job['packages'])) {
$this->problems[] = array($job);
} else {
$rule = $this->createInstallOneOfRule($job['packages'], self::RULE_JOB_INSTALL, $job['packageName']); $rule = $this->createInstallOneOfRule($job['packages'], self::RULE_JOB_INSTALL, $job['packageName']);
$this->addRule(RuleSet::TYPE_JOB, $rule); $this->addRule(RuleSet::TYPE_JOB, $rule);
$this->ruleToJob[$rule->getId()] = $job; $this->ruleToJob[$rule->getId()] = $job;
}
break; break;
case 'remove': case 'remove':
// remove all packages with this name including uninstalled // remove all packages with this name including uninstalled

View File

@ -57,8 +57,6 @@ class SolverTest extends TestCase
public function testInstallNonExistingPackageFails() public function testInstallNonExistingPackageFails()
{ {
$this->markTestIncomplete('Reporting this failure is not implemented/working yet');
$this->repo->addPackage($this->getPackage('A', '1.0')); $this->repo->addPackage($this->getPackage('A', '1.0'));
$this->reposComplete(); $this->reposComplete();