Make platform-check only check non-dev requires, refs #9412

main
Jordi Boggiano 4 years ago
parent 8c1355f448
commit 56c65a58e2
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -192,6 +192,7 @@ return array(
EOF;
// Collect information from all packages.
$devPackageNames = $localRepo->getDevPackageNames();
$packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getCanonicalPackages());
$autoloads = $this->parseAutoloads($packageMap, $mainPackage, $this->devMode === false);
@ -350,7 +351,7 @@ EOF;
$checkPlatform = $config->get('platform-check') && $this->ignorePlatformReqs !== true;
$platformCheckContent = null;
if ($checkPlatform) {
$platformCheckContent = $this->getPlatformCheck($packageMap, $this->ignorePlatformReqs ?: array(), $config->get('platform-check'));
$platformCheckContent = $this->getPlatformCheck($packageMap, $this->ignorePlatformReqs ?: array(), $config->get('platform-check'), $devPackageNames);
if (null === $platformCheckContent) {
$checkPlatform = false;
}
@ -609,7 +610,7 @@ EOF;
return $baseDir . (($path !== false) ? var_export($path, true) : "");
}
protected function getPlatformCheck($packageMap, array $ignorePlatformReqs, $checkPlatform)
protected function getPlatformCheck(array $packageMap, array $ignorePlatformReqs, $checkPlatform, array $devPackageNames)
{
$lowestPhpVersion = Bound::zero();
$requiredExtensions = array();
@ -626,6 +627,11 @@ EOF;
foreach ($packageMap as $item) {
$package = $item[0];
// skip dev dependencies platform requirements as platform-check really should only be a production safeguard
if (in_array($package->getName(), $devPackageNames, true)) {
continue;
}
foreach ($package->getRequires() as $link) {
if (in_array($link->getTarget(), $ignorePlatformReqs, true)) {
continue;

@ -708,6 +708,9 @@ class Installer
}
if ($this->executeOperations) {
if ($localRepo instanceof WritableRepositoryInterface) {
$localRepo->setDevPackageNames($this->locker->getDevPackageNames());
}
$this->installationManager->execute($localRepo, $localRepoTransaction->getOperations(), $this->devMode, $this->runScripts);
} else {
foreach ($localRepoTransaction->getOperations() as $operation) {

@ -198,6 +198,22 @@ class Locker
throw new \RuntimeException('Your composer.lock is invalid. Run "composer update" to generate a new one.');
}
/**
* @return string[] Names of dependencies installed through require-dev
*/
public function getDevPackageNames()
{
$names = array();
$lockData = $this->getLockData();
if (isset($lockData['packages-dev'])) {
foreach ($lockData['packages-dev'] as $package) {
$names[] = strtolower($package['name']);
}
}
return $names;
}
/**
* Returns the platform requirements stored in the lock file
*

@ -69,9 +69,8 @@ class FilesystemRepository extends WritableArrayRepository
$packages = $data;
}
// forward compatibility for composer v2 installed.json
if (isset($packages['packages'])) {
$packages = $packages['packages'];
if (isset($data['dev-package-names'])) {
$this->setDevPackageNames($data['dev-package-names']);
}
if (!is_array($packages)) {
@ -99,7 +98,7 @@ class FilesystemRepository extends WritableArrayRepository
*/
public function write($devMode, InstallationManager $installationManager)
{
$data = array('packages' => array(), 'dev' => $devMode);
$data = array('packages' => array(), 'dev' => $devMode, 'dev-package-names' => array());
$dumper = new ArrayDumper();
$fs = new Filesystem();
$repoDir = dirname($fs->normalizePath($this->file->getPath()));
@ -109,8 +108,15 @@ class FilesystemRepository extends WritableArrayRepository
$path = $installationManager->getInstallPath($package);
$pkgArray['install-path'] = ('' !== $path && null !== $path) ? $fs->findShortestPath($repoDir, $fs->isAbsolutePath($path) ? $path : getcwd() . '/' . $path, true) : null;
$data['packages'][] = $pkgArray;
// only write to the files the names which are really installed, as we receive the full list
// of dev package names before they get installed during composer install
if (in_array($package->getName(), $this->devPackageNames, true)) {
$data['dev-package-names'][] = $package->getName();
}
}
sort($data['dev-package-names']);
usort($data['packages'], function ($a, $b) {
return strcmp($a['name'], $b['name']);
});

@ -22,6 +22,27 @@ use Composer\Installer\InstallationManager;
*/
class WritableArrayRepository extends ArrayRepository implements WritableRepositoryInterface
{
/**
* @var string[]
*/
protected $devPackageNames = array();
/**
* {@inheritDoc}
*/
public function setDevPackageNames(array $devPackageNames)
{
$this->devPackageNames = $devPackageNames;
}
/**
* {@inheritDoc}
*/
public function getDevPackageNames()
{
return $this->devPackageNames;
}
/**
* {@inheritDoc}
*/

@ -54,4 +54,14 @@ interface WritableRepositoryInterface extends RepositoryInterface
* Forces a reload of all packages.
*/
public function reload();
/**
* @param string[] $devPackageNames
*/
public function setDevPackageNames(array $devPackageNames);
/**
* @return string[] Names of dependencies installed through require-dev
*/
public function getDevPackageNames();
}

@ -135,6 +135,9 @@ class AutoloadGeneratorTest extends TestCase
return $that->vendorDir.'/'.$package->getName() . ($targetDir ? '/'.$targetDir : '');
}));
$this->repository = $this->getMockBuilder('Composer\Repository\InstalledRepositoryInterface')->getMock();
$this->repository->expects($this->any())
->method('getDevPackageNames')
->willReturn(array());
$this->eventDispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
@ -952,15 +955,15 @@ EOF;
$notAutoloadPackages[] = $b = new Package('b/b', '1.0', '1.0');
$notAutoloadPackages[] = $c = new Package('c/c', '1.0', '1.0');
$this->repository->expects($this->at(0))
$this->repository->expects($this->at(1))
->method('getCanonicalPackages')
->will($this->returnValue($autoloadPackages));
$this->repository->expects($this->at(1))
$this->repository->expects($this->at(3))
->method('getCanonicalPackages')
->will($this->returnValue($notAutoloadPackages));
$this->repository->expects($this->at(2))
$this->repository->expects($this->at(5))
->method('getCanonicalPackages')
->will($this->returnValue($notAutoloadPackages));

@ -84,7 +84,7 @@ class FilesystemRepositoryTest extends TestCase
$im = $this->getMockBuilder('Composer\Installer\InstallationManager')
->disableOriginalConstructor()
->getMock();
$im->expects($this->once())
$im->expects($this->exactly(2))
->method('getInstallPath')
->will($this->returnValue('/foo/bar/vendor/woop/woop'));
@ -104,10 +104,16 @@ class FilesystemRepositoryTest extends TestCase
->expects($this->once())
->method('write')
->with(array(
'packages' => array(array('name' => 'mypkg', 'type' => 'library', 'version' => '0.1.10', 'version_normalized' => '0.1.10.0', 'install-path' => '../woop/woop')),
'packages' => array(
array('name' => 'mypkg', 'type' => 'library', 'version' => '0.1.10', 'version_normalized' => '0.1.10.0', 'install-path' => '../woop/woop'),
array('name' => 'mypkg2', 'type' => 'library', 'version' => '1.2.3', 'version_normalized' => '1.2.3.0', 'install-path' => '../woop/woop'),
),
'dev' => true,
'dev-package-names' => array('mypkg2'),
));
$repository->setDevPackageNames(array('mypkg2'));
$repository->addPackage($this->getPackage('mypkg2', '1.2.3'));
$repository->addPackage($this->getPackage('mypkg', '0.1.10'));
$repository->write(true, $im);
}

Loading…
Cancel
Save