Tweak check-platform-reqs command to check all constraints and output more information about what requires failed, refs #6709
parent
edf561d602
commit
b579884e15
|
@ -5,6 +5,7 @@ namespace Composer\Command;
|
||||||
use Composer\Package\Link;
|
use Composer\Package\Link;
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
use Composer\Semver\Constraint\Constraint;
|
use Composer\Semver\Constraint\Constraint;
|
||||||
|
use Composer\Semver\Constraint\MultiConstraint;
|
||||||
use Symfony\Component\Console\Helper\Table;
|
use Symfony\Component\Console\Helper\Table;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
@ -28,20 +29,24 @@ EOT
|
||||||
|
|
||||||
$repos = $composer->getRepositoryManager()->getLocalRepository();
|
$repos = $composer->getRepositoryManager()->getLocalRepository();
|
||||||
|
|
||||||
$allPackages = array_merge($repos->getPackages(), array($composer->getPackage()));
|
$allPackages = array_merge(array($composer->getPackage()), $repos->getPackages());
|
||||||
$requires = array();
|
$requires = $composer->getPackage()->getDevRequires();
|
||||||
|
foreach ($requires as $require => $link) {
|
||||||
|
$requires[$require] = array($link);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var PackageInterface $package
|
* @var PackageInterface $package
|
||||||
*/
|
*/
|
||||||
foreach ($allPackages as $package) {
|
foreach ($allPackages as $package) {
|
||||||
$requires = array_merge($requires, $package->getRequires());
|
foreach ($package->getRequires() as $require => $link) {
|
||||||
|
$requires[$require][] = $link;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
ksort($requires);
|
||||||
|
|
||||||
$platformRepo = new PlatformRepository(array(), array());
|
$platformRepo = new PlatformRepository(array(), array());
|
||||||
|
|
||||||
$currentPlatformPackages = $platformRepo->getPackages();
|
$currentPlatformPackages = $platformRepo->getPackages();
|
||||||
|
|
||||||
$currentPlatformPackageMap = array();
|
$currentPlatformPackageMap = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,39 +58,55 @@ EOT
|
||||||
|
|
||||||
$results = array();
|
$results = array();
|
||||||
|
|
||||||
|
$exitCode = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Link $require
|
* @var Link $require
|
||||||
*/
|
*/
|
||||||
foreach ($requires as $key => $require) {
|
foreach ($requires as $require => $links) {
|
||||||
if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $key)) {
|
if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $require)) {
|
||||||
if (isset($currentPlatformPackageMap[$key])) {
|
if (isset($currentPlatformPackageMap[$require])) {
|
||||||
// 检查版本
|
$pass = true;
|
||||||
$version = $currentPlatformPackageMap[$key]->getVersion();
|
$version = $currentPlatformPackageMap[$require]->getVersion();
|
||||||
if (!$require->getConstraint()->matches(new Constraint('<=', $version))) {
|
|
||||||
|
foreach ($links as $link) {
|
||||||
|
if (!$link->getConstraint()->matches(new Constraint('<=', $version))) {
|
||||||
|
$results[] = array(
|
||||||
|
$currentPlatformPackageMap[$require]->getPrettyName(),
|
||||||
|
$currentPlatformPackageMap[$require]->getPrettyVersion(),
|
||||||
|
$link,
|
||||||
|
'<error>failed</error>',
|
||||||
|
);
|
||||||
|
$pass = false;
|
||||||
|
|
||||||
|
$exitCode = max($exitCode, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($pass) {
|
||||||
$results[] = array(
|
$results[] = array(
|
||||||
$require,
|
$currentPlatformPackageMap[$require]->getPrettyName(),
|
||||||
$currentPlatformPackageMap[$key],
|
$currentPlatformPackageMap[$require]->getPrettyVersion(),
|
||||||
'failed',
|
null,
|
||||||
);
|
'<info>success</info>',
|
||||||
} else {
|
|
||||||
$results[] = array(
|
|
||||||
$require,
|
|
||||||
$currentPlatformPackageMap[$key],
|
|
||||||
'success',
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$results[] = array(
|
$results[] = array(
|
||||||
$require,
|
$require,
|
||||||
null,
|
'n/a',
|
||||||
'miss',
|
$links[0],
|
||||||
|
'<error>missing</error>',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$exitCode = max($exitCode, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->printTable($output, $results);
|
$this->printTable($output, $results);
|
||||||
|
|
||||||
|
return $exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function printTable(OutputInterface $output, $results)
|
protected function printTable(OutputInterface $output, $results)
|
||||||
|
@ -94,17 +115,14 @@ EOT
|
||||||
$rows = array();
|
$rows = array();
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
/**
|
/**
|
||||||
* @var PackageInterface $platformPackage
|
* @var Link|null $link
|
||||||
* @var Link $require
|
|
||||||
*/
|
*/
|
||||||
list($require, $platformPackage, $reason) = $result;
|
list($platformPackage, $version, $link, $status) = $result;
|
||||||
$version = (strpos($platformPackage->getPrettyVersion(), 'No version set') === 0) ? '-' : $platformPackage->getPrettyVersion();
|
|
||||||
$rows[] = array(
|
$rows[] = array(
|
||||||
$platformPackage->getPrettyName(),
|
$platformPackage,
|
||||||
$version,
|
$version,
|
||||||
$require->getDescription(),
|
$link ? sprintf('%s %s %s (%s)', $link->getSource(), $link->getDescription(), $link->getTarget(), $link->getPrettyConstraint()) : '',
|
||||||
sprintf('%s (%s)', $require->getTarget(), $require->getPrettyConstraint()),
|
$status
|
||||||
$reason
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$table = array_merge($rows, $table);
|
$table = array_merge($rows, $table);
|
||||||
|
|
Loading…
Reference in New Issue