1
0
Fork 0

Make sure platform requirements of the root package are enforced when installing from lock, fixes #1611

pull/1654/head
Jordi Boggiano 2013-03-03 20:05:46 +01:00
parent 06026d6b93
commit ea7d79ab03
6 changed files with 75 additions and 6 deletions

View File

@ -250,9 +250,14 @@ class Installer
} }
} }
$platformReqs = $this->extractPlatformRequirements($this->package->getRequires());
$platformDevReqs = $this->devMode ? $this->extractPlatformRequirements($this->package->getDevRequires()) : array();
$updatedLock = $this->locker->setLockData( $updatedLock = $this->locker->setLockData(
array_diff($localRepo->getPackages(), (array) $devPackages), array_diff($localRepo->getPackages(), (array) $devPackages),
$devPackages, $devPackages,
$platformReqs,
$platformDevReqs,
$aliases, $aliases,
$this->package->getMinimumStability(), $this->package->getMinimumStability(),
$this->package->getStabilityFlags() $this->package->getStabilityFlags()
@ -350,6 +355,10 @@ class Installer
$constraint->setPrettyString($package->getPrettyVersion()); $constraint->setPrettyString($package->getPrettyVersion());
$request->install($package->getName(), $constraint); $request->install($package->getName(), $constraint);
} }
foreach ($this->locker->getPlatformRequirements($withDevReqs) as $link) {
$request->install($link->getTarget(), $link->getConstraint());
}
} else { } else {
$this->io->write('<info>Installing dependencies'.($withDevReqs?' (including require-dev)':'').'</info>'); $this->io->write('<info>Installing dependencies'.($withDevReqs?' (including require-dev)':'').'</info>');
@ -675,6 +684,17 @@ class Installer
return false; return false;
} }
private function extractPlatformRequirements($links) {
$platformReqs = array();
foreach ($links as $link) {
if (preg_match('{^(?:php(?:-64bit)?|(?:ext|lib)-[^/]+)$}i', $link->getTarget())) {
$platformReqs[$link->getTarget()] = $link->getPrettyConstraint();
}
}
return $platformReqs;
}
/** /**
* Adds all dependencies of the update whitelist to the whitelist, too. * Adds all dependencies of the update whitelist to the whitelist, too.
* *

View File

@ -20,6 +20,7 @@ use Composer\Package\AliasPackage;
use Composer\Repository\ArrayRepository; use Composer\Repository\ArrayRepository;
use Composer\Package\Dumper\ArrayDumper; use Composer\Package\Dumper\ArrayDumper;
use Composer\Package\Loader\ArrayLoader; use Composer\Package\Loader\ArrayLoader;
use Composer\Package\Version\VersionParser;
/** /**
* Reads/writes project lockfile (composer.lock). * Reads/writes project lockfile (composer.lock).
@ -178,6 +179,41 @@ class Locker
return $packages; return $packages;
} }
/**
* Returns the platform requirements stored in the lock file
*
* @param bool $withDevReqs if true, the platform requirements from the require-dev block are also returned
* @return \Composer\Package\Link[]
*/
public function getPlatformRequirements($withDevReqs = false)
{
$lockData = $this->getLockData();
$versionParser = new VersionParser();
$requirements = array();
if (!empty($lockData['platform'])) {
$requirements = $versionParser->parseLinks(
'__ROOT__',
'1.0.0',
'requires',
isset($lockData['platform']) ? $lockData['platform'] : array()
);
}
if ($withDevReqs && !empty($lockData['platform-dev'])) {
$devRequirements = $versionParser->parseLinks(
'__ROOT__',
'1.0.0',
'requires',
isset($lockData['platform-dev']) ? $lockData['platform-dev'] : array()
);
$requirements = array_merge($requirements, $devRequirements);
}
return $requirements;
}
public function getMinimumStability() public function getMinimumStability()
{ {
$lockData = $this->getLockData(); $lockData = $this->getLockData();
@ -217,13 +253,15 @@ class Locker
* *
* @param array $packages array of packages * @param array $packages array of packages
* @param mixed $devPackages array of dev packages or null if installed without --dev * @param mixed $devPackages array of dev packages or null if installed without --dev
* @param array $platformReqs array of package name => constraint for required platform packages
* @param mixed $platformDevReqs array of package name => constraint for dev-required platform packages
* @param array $aliases array of aliases * @param array $aliases array of aliases
* @param string $minimumStability * @param string $minimumStability
* @param array $stabilityFlags * @param array $stabilityFlags
* *
* @return bool * @return bool
*/ */
public function setLockData(array $packages, $devPackages, array $aliases, $minimumStability, array $stabilityFlags) public function setLockData(array $packages, $devPackages, array $platformReqs, $platformDevReqs, array $aliases, $minimumStability, array $stabilityFlags)
{ {
$lock = array( $lock = array(
'hash' => $this->hash, 'hash' => $this->hash,
@ -258,6 +296,9 @@ class Locker
return false; return false;
} }
$lock['platform'] = $platformReqs;
$lock['platform-dev'] = $platformDevReqs;
if (!$this->isLocked() || $lock !== $this->getLockData()) { if (!$this->isLocked() || $lock !== $this->getLockData()) {
$this->lockFile->write($lock); $this->lockFile->write($lock);
$this->lockDataCache = null; $this->lockDataCache = null;

View File

@ -46,7 +46,9 @@ install --prefer-dist
"minimum-stability": "dev", "minimum-stability": "dev",
"stability-flags": { "stability-flags": {
"a/a": 20 "a/a": 20
} },
"platform": [],
"platform-dev": []
} }
--EXPECT-- --EXPECT--
Installing a/a (dev-master) Installing a/a (dev-master)

View File

@ -63,7 +63,9 @@ update
"packages-dev": null, "packages-dev": null,
"aliases": [], "aliases": [],
"minimum-stability": "dev", "minimum-stability": "dev",
"stability-flags": [] "stability-flags": [],
"platform": [],
"platform-dev": []
} }
--EXPECT-- --EXPECT--
Updating a/a (dev-master 1234) to a/a (dev-master master) Updating a/a (dev-master 1234) to a/a (dev-master master)

View File

@ -56,7 +56,9 @@ update
"packages-dev": null, "packages-dev": null,
"aliases": [], "aliases": [],
"minimum-stability": "dev", "minimum-stability": "dev",
"stability-flags": {"a/a":20} "stability-flags": {"a/a":20},
"platform": [],
"platform-dev": []
} }
--EXPECT-- --EXPECT--
Updating a/a (dev-master oldref) to a/a (dev-master newref) Updating a/a (dev-master oldref) to a/a (dev-master newref)

View File

@ -171,9 +171,11 @@ class LockerTest extends \PHPUnit_Framework_TestCase
'aliases' => array(), 'aliases' => array(),
'minimum-stability' => 'dev', 'minimum-stability' => 'dev',
'stability-flags' => array(), 'stability-flags' => array(),
'platform' => array(),
'platform-dev' => array(),
)); ));
$locker->setLockData(array($package1, $package2), array(), array(), 'dev', array()); $locker->setLockData(array($package1, $package2), array(), array(), array(), array(), 'dev', array());
} }
public function testLockBadPackages() public function testLockBadPackages()
@ -192,7 +194,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase
$this->setExpectedException('LogicException'); $this->setExpectedException('LogicException');
$locker->setLockData(array($package1), array(), array(), 'dev', array()); $locker->setLockData(array($package1), array(), array(), array(), array(), 'dev', array());
} }
public function testIsFresh() public function testIsFresh()