Browse Source

Add composer-runtime-api platform package

Jordi Boggiano 4 years ago
parent
commit
0ab48a1773

+ 11 - 0
src/Composer/Composer.php

@@ -55,6 +55,17 @@ class Composer
     const RELEASE_DATE = '@release_date@';
     const SOURCE_VERSION = '2.0-dev+source';
 
+    /**
+     * Version number of the internal composer-runtime-api package
+     *
+     * This is used to version features available to projects at runtime
+     * like the platform-check file, the Composer\InstalledVersions class
+     * and possibly others in the future.
+     *
+     * @var string
+     */
+    const RUNTIME_API_VERSION = '2.0.0';
+
     public static function getVersion()
     {
         // no replacement done, this must be a source checkout

+ 2 - 2
src/Composer/DependencyResolver/Transaction.php

@@ -261,9 +261,9 @@ class Transaction
 
             // is this a plugin or a dependency of a plugin?
             if ($isPlugin || count(array_intersect($package->getNames(), $pluginRequires))) {
-                // get the package's requires, but filter out any platform requirements or 'composer-plugin-api'
+                // get the package's requires, but filter out any platform requirements
                 $requires = array_filter(array_keys($package->getRequires()), function ($req) {
-                    return $req !== 'composer-plugin-api' && !preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $req);
+                    return !preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $req);
                 });
 
                 // is this a plugin with no meaningful dependencies?

+ 5 - 0
src/Composer/Plugin/PluginInterface.php

@@ -25,6 +25,11 @@ interface PluginInterface
     /**
      * Version number of the internal composer-plugin-api package
      *
+     * This is used to denote the API version of Plugin specific
+     * features, but is also bumped to a new major if Composer
+     * includes a major break in internal APIs which are susceptible
+     * to be used by plugins.
+     *
      * @var string
      */
     const PLUGIN_API_VERSION = '2.0.0';

+ 2 - 2
src/Composer/Plugin/PluginManager.php

@@ -134,8 +134,8 @@ class PluginManager
             $currentPluginApiVersion = $this->getPluginApiVersion();
             $currentPluginApiConstraint = new Constraint('==', $this->versionParser->normalize($currentPluginApiVersion));
 
-            if ($requiresComposer->getPrettyString() === '1.0.0' && $this->getPluginApiVersion() === '1.0.0') {
-                $this->io->writeError('<warning>The "' . $package->getName() . '" plugin requires composer-plugin-api 1.0.0, this *WILL* break in the future and it should be fixed ASAP (require ^1.0 for example).</warning>');
+            if ($requiresComposer->getPrettyString() === $this->getPluginApiVersion()) {
+                $this->io->writeError('<warning>The "' . $package->getName() . '" plugin requires composer-plugin-api '.$this->getPluginApiVersion().', this *WILL* break in the future and it should be fixed ASAP (require ^'.$this->getPluginApiVersion().' instead for example).</warning>');
             } elseif (!$requiresComposer->matches($currentPluginApiConstraint)) {
                 $this->io->writeError('<warning>The "' . $package->getName() . '" plugin was skipped because it requires a Plugin API version ("' . $requiresComposer->getPrettyString() . '") that does not match your Composer installation ("' . $currentPluginApiVersion . '"). You may need to run composer update with the "--no-plugins" option.</warning>');
 

+ 2 - 2
src/Composer/Repository/ComposerRepository.php

@@ -502,7 +502,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
     {
         if (!$this->hasPartialPackages() || !isset($this->partialPackagesByName[$name])) {
             // skip platform packages, root package and composer-plugin-api
-            if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $name) || '__root__' === $name || 'composer-plugin-api' === $name) {
+            if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $name) || '__root__' === $name) {
                 return array();
             }
 
@@ -672,7 +672,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
 
             $realName = preg_replace('{~dev$}', '', $name);
             // skip platform packages, root package and composer-plugin-api
-            if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $realName) || '__root__' === $realName || 'composer-plugin-api' === $realName) {
+            if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $realName) || '__root__' === $realName) {
                 continue;
             }
 

+ 8 - 1
src/Composer/Repository/PlatformRepository.php

@@ -20,6 +20,7 @@ use Composer\Util\ProcessExecutor;
 use Composer\Util\Silencer;
 use Composer\Util\Platform;
 use Composer\XdebugHandler\XdebugHandler;
+use Composer\Composer;
 use Symfony\Component\Process\ExecutableFinder;
 
 /**
@@ -27,7 +28,7 @@ use Symfony\Component\Process\ExecutableFinder;
  */
 class PlatformRepository extends ArrayRepository
 {
-    const PLATFORM_PACKAGE_REGEX = '{^(?:php(?:-64bit|-ipv6|-zts|-debug)?|hhvm|(?:ext|lib)-[a-z0-9](?:[_.-]?[a-z0-9]+)*|composer-plugin-api)$}iD';
+    const PLATFORM_PACKAGE_REGEX = '{^(?:php(?:-64bit|-ipv6|-zts|-debug)?|hhvm|(?:ext|lib)-[a-z0-9](?:[_.-]?[a-z0-9]+)*|composer-(?:plugin|runtime)-api)$}iD';
 
     private $versionParser;
 
@@ -79,6 +80,12 @@ class PlatformRepository extends ArrayRepository
         $composerPluginApi->setDescription('The Composer Plugin API');
         $this->addPackage($composerPluginApi);
 
+        $prettyVersion = Composer::RUNTIME_API_VERSION;
+        $version = $this->versionParser->normalize($prettyVersion);
+        $composerRuntimeApi = new CompletePackage('composer-runtime-api', $version, $prettyVersion);
+        $composerRuntimeApi->setDescription('The Composer Runtime API');
+        $this->addPackage($composerRuntimeApi);
+
         try {
             $prettyVersion = PHP_VERSION;
             $version = $this->versionParser->normalize($prettyVersion);