Resolve job packages after whitelist generation
parent
bc7008270f
commit
5b80144ad0
|
@ -80,7 +80,13 @@ class Problem
|
||||||
$rule = $reason['rule'];
|
$rule = $reason['rule'];
|
||||||
$job = $reason['job'];
|
$job = $reason['job'];
|
||||||
|
|
||||||
if ($job && $job['cmd'] === 'install' && empty($job['packages'])) {
|
if (isset($job['constraint'])) {
|
||||||
|
$packages = $this->pool->whatProvides($job['packageName'], $job['constraint']);
|
||||||
|
} else {
|
||||||
|
$packages = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($job && $job['cmd'] === 'install' && empty($packages)) {
|
||||||
// handle php extensions
|
// handle php extensions
|
||||||
if (0 === stripos($job['packageName'], 'ext-')) {
|
if (0 === stripos($job['packageName'], 'ext-')) {
|
||||||
$ext = substr($job['packageName'], 4);
|
$ext = substr($job['packageName'], 4);
|
||||||
|
@ -161,18 +167,25 @@ class Problem
|
||||||
{
|
{
|
||||||
switch ($job['cmd']) {
|
switch ($job['cmd']) {
|
||||||
case 'install':
|
case 'install':
|
||||||
if (!$job['packages']) {
|
$packages = $this->pool->whatProvides($job['packageName'], $job['constraint']);
|
||||||
|
if (!$packages) {
|
||||||
return 'No package found to satisfy install request for '.$job['packageName'].$this->constraintToText($job['constraint']);
|
return 'No package found to satisfy install request for '.$job['packageName'].$this->constraintToText($job['constraint']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'Installation request for '.$job['packageName'].$this->constraintToText($job['constraint']).' -> satisfiable by '.$this->getPackageList($job['packages']).'.';
|
return 'Installation request for '.$job['packageName'].$this->constraintToText($job['constraint']).' -> satisfiable by '.$this->getPackageList($packages).'.';
|
||||||
case 'update':
|
case 'update':
|
||||||
return 'Update request for '.$job['packageName'].$this->constraintToText($job['constraint']).'.';
|
return 'Update request for '.$job['packageName'].$this->constraintToText($job['constraint']).'.';
|
||||||
case 'remove':
|
case 'remove':
|
||||||
return 'Removal request for '.$job['packageName'].$this->constraintToText($job['constraint']).'';
|
return 'Removal request for '.$job['packageName'].$this->constraintToText($job['constraint']).'';
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'Job(cmd='.$job['cmd'].', target='.$job['packageName'].', packages=['.$this->getPackageList($job['packages']).'])';
|
if (isset($job['constraint'])) {
|
||||||
|
$packages = $this->pool->whatProvides($job['packageName'], $job['constraint']);
|
||||||
|
} else {
|
||||||
|
$packages = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'Job(cmd='.$job['cmd'].', target='.$job['packageName'].', packages=['.$this->getPackageList($packages).'])';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getPackageList($packages)
|
protected function getPackageList($packages)
|
||||||
|
|
|
@ -46,10 +46,8 @@ class Request
|
||||||
protected function addJob($packageName, $cmd, LinkConstraintInterface $constraint = null)
|
protected function addJob($packageName, $cmd, LinkConstraintInterface $constraint = null)
|
||||||
{
|
{
|
||||||
$packageName = strtolower($packageName);
|
$packageName = strtolower($packageName);
|
||||||
$packages = $this->pool->whatProvides($packageName, $constraint, true);
|
|
||||||
|
|
||||||
$this->jobs[] = array(
|
$this->jobs[] = array(
|
||||||
'packages' => $packages,
|
|
||||||
'cmd' => $cmd,
|
'cmd' => $cmd,
|
||||||
'packageName' => $packageName,
|
'packageName' => $packageName,
|
||||||
'constraint' => $constraint,
|
'constraint' => $constraint,
|
||||||
|
@ -58,7 +56,7 @@ class Request
|
||||||
|
|
||||||
public function updateAll()
|
public function updateAll()
|
||||||
{
|
{
|
||||||
$this->jobs[] = array('cmd' => 'update-all', 'packages' => array());
|
$this->jobs[] = array('cmd' => 'update-all');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getJobs()
|
public function getJobs()
|
||||||
|
|
|
@ -287,10 +287,9 @@ class RuleSetGenerator
|
||||||
foreach ($this->jobs as $job) {
|
foreach ($this->jobs as $job) {
|
||||||
switch ($job['cmd']) {
|
switch ($job['cmd']) {
|
||||||
case 'install':
|
case 'install':
|
||||||
if ($job['packages']) {
|
$packages = $this->pool->whatProvides($job['packageName'], $job['constraint'], true);
|
||||||
foreach ($job['packages'] as $package) {
|
foreach ($packages as $package) {
|
||||||
$this->whitelistFromPackage($package);
|
$this->whitelistFromPackage($package);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -302,21 +301,23 @@ class RuleSetGenerator
|
||||||
foreach ($this->jobs as $job) {
|
foreach ($this->jobs as $job) {
|
||||||
switch ($job['cmd']) {
|
switch ($job['cmd']) {
|
||||||
case 'install':
|
case 'install':
|
||||||
if ($job['packages']) {
|
$packages = $this->pool->whatProvides($job['packageName'], $job['constraint']);
|
||||||
foreach ($job['packages'] as $package) {
|
if ($packages) {
|
||||||
|
foreach ($packages as $package) {
|
||||||
if (!isset($this->installedMap[$package->getId()])) {
|
if (!isset($this->installedMap[$package->getId()])) {
|
||||||
$this->addRulesForPackage($package);
|
$this->addRulesForPackage($package);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$rule = $this->createInstallOneOfRule($job['packages'], Rule::RULE_JOB_INSTALL, $job);
|
$rule = $this->createInstallOneOfRule($packages, Rule::RULE_JOB_INSTALL, $job);
|
||||||
$this->addRule(RuleSet::TYPE_JOB, $rule);
|
$this->addRule(RuleSet::TYPE_JOB, $rule);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'remove':
|
case 'remove':
|
||||||
// remove all packages with this name including uninstalled
|
// remove all packages with this name including uninstalled
|
||||||
// ones to make sure none of them are picked as replacements
|
// ones to make sure none of them are picked as replacements
|
||||||
foreach ($job['packages'] as $package) {
|
$packages = $this->pool->whatProvides($job['packageName'], $job['constraint']);
|
||||||
|
foreach ($packages as $package) {
|
||||||
$rule = $this->createRemoveRule($package, Rule::RULE_JOB_REMOVE, $job);
|
$rule = $this->createRemoveRule($package, Rule::RULE_JOB_REMOVE, $job);
|
||||||
$this->addRule(RuleSet::TYPE_JOB, $rule);
|
$this->addRule(RuleSet::TYPE_JOB, $rule);
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,8 @@ class Solver
|
||||||
foreach ($this->jobs as $job) {
|
foreach ($this->jobs as $job) {
|
||||||
switch ($job['cmd']) {
|
switch ($job['cmd']) {
|
||||||
case 'update':
|
case 'update':
|
||||||
foreach ($job['packages'] as $package) {
|
$packages = $this->pool->whatProvides($job['packageName'], $job['constraint']);
|
||||||
|
foreach ($packages as $package) {
|
||||||
if (isset($this->installedMap[$package->getId()])) {
|
if (isset($this->installedMap[$package->getId()])) {
|
||||||
$this->updateMap[$package->getId()] = true;
|
$this->updateMap[$package->getId()] = true;
|
||||||
}
|
}
|
||||||
|
@ -145,7 +146,7 @@ class Solver
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'install':
|
case 'install':
|
||||||
if (!$job['packages']) {
|
if (!$this->pool->whatProvides($job['packageName'], $job['constraint'])) {
|
||||||
$problem = new Problem($this->pool);
|
$problem = new Problem($this->pool);
|
||||||
$problem->addRule(new Rule($this->pool, array(), null, null, $job));
|
$problem->addRule(new Rule($this->pool, array(), null, null, $job));
|
||||||
$this->problems[] = $problem;
|
$this->problems[] = $problem;
|
||||||
|
|
|
@ -39,9 +39,9 @@ class RequestTest extends TestCase
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
array(
|
||||||
array('packages' => array($foo), 'cmd' => 'install', 'packageName' => 'foo', 'constraint' => null),
|
array('cmd' => 'install', 'packageName' => 'foo', 'constraint' => null),
|
||||||
array('packages' => array($bar), 'cmd' => 'install', 'packageName' => 'bar', 'constraint' => null),
|
array('cmd' => 'install', 'packageName' => 'bar', 'constraint' => null),
|
||||||
array('packages' => array($foobar), 'cmd' => 'remove', 'packageName' => 'foobar', 'constraint' => null),
|
array('cmd' => 'remove', 'packageName' => 'foobar', 'constraint' => null),
|
||||||
),
|
),
|
||||||
$request->getJobs());
|
$request->getJobs());
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ class RequestTest extends TestCase
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
array(
|
||||||
array('packages' => array($foo1, $foo2), 'cmd' => 'install', 'packageName' => 'foo', 'constraint' => $constraint),
|
array('cmd' => 'install', 'packageName' => 'foo', 'constraint' => $constraint),
|
||||||
),
|
),
|
||||||
$request->getJobs()
|
$request->getJobs()
|
||||||
);
|
);
|
||||||
|
@ -80,7 +80,7 @@ class RequestTest extends TestCase
|
||||||
$request->updateAll();
|
$request->updateAll();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(array('cmd' => 'update-all', 'packages' => array())),
|
array(array('cmd' => 'update-all')),
|
||||||
$request->getJobs());
|
$request->getJobs());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -464,7 +464,7 @@ class SolverTest extends TestCase
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInstallReplacerOfMissingPackage()
|
public function testNoInstallReplacerOfMissingPackage()
|
||||||
{
|
{
|
||||||
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
|
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
|
||||||
$this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
|
$this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
|
||||||
|
@ -475,10 +475,8 @@ class SolverTest extends TestCase
|
||||||
|
|
||||||
$this->request->install('A');
|
$this->request->install('A');
|
||||||
|
|
||||||
$this->checkSolverResult(array(
|
$this->setExpectedException('Composer\DependencyResolver\SolverProblemsException');
|
||||||
array('job' => 'install', 'package' => $packageQ),
|
$this->solver->solve($this->request);
|
||||||
array('job' => 'install', 'package' => $packageA),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSkipReplacedPackageIfReplacerIsSelected()
|
public function testSkipReplacedPackageIfReplacerIsSelected()
|
||||||
|
@ -611,6 +609,7 @@ class SolverTest extends TestCase
|
||||||
$this->reposComplete();
|
$this->reposComplete();
|
||||||
|
|
||||||
$this->request->install('A');
|
$this->request->install('A');
|
||||||
|
$this->request->install('D');
|
||||||
|
|
||||||
$this->checkSolverResult(array(
|
$this->checkSolverResult(array(
|
||||||
array('job' => 'install', 'package' => $packageD2),
|
array('job' => 'install', 'package' => $packageD2),
|
||||||
|
|
|
@ -250,7 +250,7 @@ class InstallerTest extends TestCase
|
||||||
$tests = array();
|
$tests = array();
|
||||||
|
|
||||||
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($fixturesDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
|
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($fixturesDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
|
||||||
if (!preg_match('/replace-root-require\.test$/', $file)) {
|
if (!preg_match('/\.test$/', $file)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ class InstallerTest extends TestCase
|
||||||
}
|
}
|
||||||
$expectOutput = $match['expectOutput'];
|
$expectOutput = $match['expectOutput'];
|
||||||
$expect = $match['expect'];
|
$expect = $match['expect'];
|
||||||
$expectExitCode = $match['expectExitCode'];
|
$expectExitCode = (int) $match['expectExitCode'];
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
die(sprintf('Test "%s" is not valid: '.$e->getMessage(), str_replace($fixturesDir.'/', '', $file)));
|
die(sprintf('Test "%s" is not valid: '.$e->getMessage(), str_replace($fixturesDir.'/', '', $file)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue