From b7fa302b901fdcf07b488b5be83f688d013562dd Mon Sep 17 00:00:00 2001 From: alu Date: Thu, 2 Oct 2014 14:01:15 +0900 Subject: [PATCH] add ignore-platform-package-requirements for update/install commands. --- src/Composer/Command/InstallCommand.php | 2 ++ src/Composer/Command/UpdateCommand.php | 4 +++- src/Composer/DependencyResolver/Solver.php | 19 ++++++++++++--- src/Composer/Installer.php | 17 +++++++++++-- ...-ignore-platform-package-requirements.test | 20 ++++++++++++++++ ...-ignore-platform-package-requirements.test | 24 +++++++++++++++++++ tests/Composer/Test/InstallerTest.php | 6 +++-- 7 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 tests/Composer/Test/Fixtures/installer/install-ignore-platform-package-requirements.test create mode 100644 tests/Composer/Test/Fixtures/installer/update-ignore-platform-package-requirements.test diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index 4f40837f1..b65e08f0f 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -45,6 +45,7 @@ class InstallCommand extends Command new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'), new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'), new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump'), + new InputOption('ignore-platform-package-requirements', null, InputOption::VALUE_NONE, 'Ignore PHP Extention requirements.'), new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Should not be provided, use composer require instead to add a given package to composer.json.'), )) ->setHelp(<<setDevMode(!$input->getOption('no-dev')) ->setRunScripts(!$input->getOption('no-scripts')) ->setOptimizeAutoloader($optimize) + ->setIgnorePlatformPackage($input->getOption('ignore-platform-package-requirements')); ; if ($input->getOption('no-plugins')) { diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index d45e386ed..131390dd7 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -45,7 +45,8 @@ class UpdateCommand extends Command new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'), new InputOption('with-dependencies', null, InputOption::VALUE_NONE, 'Add also all dependencies of whitelisted packages to the whitelist.'), new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'), - new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump.') + new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump.'), + new InputOption('ignore-platform-package-requirements', null, InputOption::VALUE_NONE, 'Ignore PHP Extention requirements.'), )) ->setHelp(<<update command reads the composer.json file from the @@ -119,6 +120,7 @@ EOT ->setUpdate(true) ->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $input->getArgument('packages')) ->setWhitelistDependencies($input->getOption('with-dependencies')) + ->setIgnorePlatformPackage($input->getOption('ignore-platform-package-requirements')); ; if ($input->getOption('no-plugins')) { diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index 6d6088729..c6ad2b17a 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -13,6 +13,7 @@ namespace Composer\DependencyResolver; use Composer\Repository\RepositoryInterface; +use Composer\Repository\PlatformRepository; /** * @author Nils Adermann @@ -129,7 +130,7 @@ class Solver } } - protected function checkForRootRequireProblems() + protected function checkForRootRequireProblems($ignorePlatformPackageRequirements) { foreach ($this->jobs as $job) { switch ($job['cmd']) { @@ -149,6 +150,10 @@ class Solver break; case 'install': + if ($ignorePlatformPackageRequirements && preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $job['packageName'])) { + break; + } + if (!$this->pool->whatProvides($job['packageName'], $job['constraint'])) { $problem = new Problem($this->pool); $problem->addRule(new Rule($this->pool, array(), null, null, $job)); @@ -159,16 +164,24 @@ class Solver } } - public function solve(Request $request) + public function solve(Request $request, $ignorePlatformPackage = false) { $this->jobs = $request->getJobs(); $this->setupInstalledMap(); $this->rules = $this->ruleSetGenerator->getRulesFor($this->jobs, $this->installedMap); - $this->checkForRootRequireProblems(); + $this->checkForRootRequireProblems($ignorePlatformPackage); $this->decisions = new Decisions($this->pool); $this->watchGraph = new RuleWatchGraph; + if ($ignorePlatformPackage) { + foreach ($this->rules as $rule) { + if ($rule->getReason() === Rule::RULE_PACKAGE_REQUIRES && preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $rule->getRequiredPackage())) { + $rule->disable(); + } + } + } + foreach ($this->rules as $rule) { $this->watchGraph->insert(new RuleWatchNode($rule)); } diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 2899e2bdb..94b8113c4 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -105,6 +105,7 @@ class Installer protected $verbose = false; protected $update = false; protected $runScripts = true; + protected $ignorePlatformPackage = false; /** * Array of package names/globs flagged for update * @@ -263,7 +264,7 @@ class Installer $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $policy, $pool, $installedRepo, $request); $solver = new Solver($policy, $pool, $installedRepo); - $ops = $solver->solve($request); + $ops = $solver->solve($request, $this->ignorePlatformPackage); $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $policy, $pool, $installedRepo, $request, $ops); foreach ($ops as $op) { if ($op->getJobType() === 'uninstall') { @@ -470,7 +471,7 @@ class Installer $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $policy, $pool, $installedRepo, $request); $solver = new Solver($policy, $pool, $installedRepo); try { - $operations = $solver->solve($request); + $operations = $solver->solve($request, $this->ignorePlatformPackage); $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $policy, $pool, $installedRepo, $request, $operations); } catch (SolverProblemsException $e) { $this->io->write('Your requirements could not be resolved to an installable set of packages.'); @@ -1156,6 +1157,18 @@ class Installer return $this; } + /** + * set ignore Platform Package requirements + * + * @param boolean $ignorePlatformPackage + * @return Installer + */ + public function setIgnorePlatformPackage($ignorePlatformPackage = false) { + $this->ignorePlatformPackage = (boolean) $ignorePlatformPackage; + + return $this; + } + /** * restrict the update operation to a few packages, all other packages * that are already installed will be kept at their current version diff --git a/tests/Composer/Test/Fixtures/installer/install-ignore-platform-package-requirements.test b/tests/Composer/Test/Fixtures/installer/install-ignore-platform-package-requirements.test new file mode 100644 index 000000000..88f5d1a5d --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/install-ignore-platform-package-requirements.test @@ -0,0 +1,20 @@ +--TEST-- +Install in ignore-platform-package-requirements mode +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { "name": "a/a", "version": "1.0.0", "require": { "ext-testdummy": "*" } } + ] + } + ], + "require": { + "a/a": "1.0.0" + } +} +--RUN-- +install --ignore-platform-package-requirements +--EXPECT-- +Installing a/a (1.0.0) diff --git a/tests/Composer/Test/Fixtures/installer/update-ignore-platform-package-requirements.test b/tests/Composer/Test/Fixtures/installer/update-ignore-platform-package-requirements.test new file mode 100644 index 000000000..87e4f1297 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/update-ignore-platform-package-requirements.test @@ -0,0 +1,24 @@ +--TEST-- +Update in ignore-platform-package-requirements mode +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { "name": "a/a", "version": "1.0.1", "require": { "ext-testdummy": "*" } } + ] + } + ], + "require": { + "a/a": "1.0.*" + } +} +--INSTALLED-- +[ + { "name": "a/a", "version": "1.0.0" } +] +--RUN-- +update --ignore-platform-package-requirements +--EXPECT-- +Updating a/a (1.0.0) to a/a (1.0.1) diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index a88ce7c21..c31fee0ed 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -204,7 +204,8 @@ class InstallerTest extends TestCase $application->get('install')->setCode(function ($input, $output) use ($installer) { $installer ->setDevMode(!$input->getOption('no-dev')) - ->setDryRun($input->getOption('dry-run')); + ->setDryRun($input->getOption('dry-run')) + ->setIgnorePlatformPackage($input->getOption('ignore-platform-package-requirements')); return $installer->run(); }); @@ -215,7 +216,8 @@ class InstallerTest extends TestCase ->setUpdate(true) ->setDryRun($input->getOption('dry-run')) ->setUpdateWhitelist($input->getArgument('packages')) - ->setWhitelistDependencies($input->getOption('with-dependencies')); + ->setWhitelistDependencies($input->getOption('with-dependencies')) + ->setIgnorePlatformPackage($input->getOption('ignore-platform-package-requirements')); return $installer->run(); });