Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/178739

Change subject: Add script to conslidate composer dependencies
......................................................................

Add script to conslidate composer dependencies

The main goal of this script is to make easy to manage
core and extension dependencies together, and basically
scripts the process currently used to manage the
mediawiki/vendor repository for Wikimedia deployment.

The script, conslidateComposerDependencies.php, takes
filenames of individual composer.json files, merges
all the dependencies from the various files and core's own file,
and writes to a composer.json file in $IP/vendor.
"composer install" should then be run in that directory to fetch
and install the various dependencies.

Change-Id: Iff0fc1a6946e3693360f094d3a780d5c75cd6587
---
M autoload.php
A maintenance/consolidateComposerDependencies.php
2 files changed, 75 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/39/178739/1

diff --git a/autoload.php b/autoload.php
index 9de57b8..9ae2296 100644
--- a/autoload.php
+++ b/autoload.php
@@ -238,6 +238,7 @@
        'Config' => __DIR__ . '/includes/config/Config.php',
        'ConfigException' => __DIR__ . '/includes/config/ConfigException.php',
        'ConfigFactory' => __DIR__ . '/includes/config/ConfigFactory.php',
+       'ConsolidateComposerDependencies' => __DIR__ . 
'/maintenance/consolidateComposerDependencies.php',
        'ConstantDependency' => __DIR__ . '/includes/cache/CacheDependency.php',
        'Content' => __DIR__ . '/includes/content/Content.php',
        'ContentHandler' => __DIR__ . '/includes/content/ContentHandler.php',
diff --git a/maintenance/consolidateComposerDependencies.php 
b/maintenance/consolidateComposerDependencies.php
new file mode 100644
index 0000000..1af8824
--- /dev/null
+++ b/maintenance/consolidateComposerDependencies.php
@@ -0,0 +1,74 @@
+<?php
+
+require_once __DIR__ . '/Maintenance.php';
+
+/**
+ * Allows consolidating composer dependencies into one composer.json file
+ * so extension and core dependencies can be managed together.
+ *
+ * Usage:
+ *  php consolidateComposerDependencies.php extensions/FooBar/composer.json 
extensions/Baz/composer.json ...
+ *
+ * It will create a composer.json file at "$IP/vendor/composer.json", which 
you should then manually
+ * run `composer install` on.
+ */
+class ConsolidateComposerDependencies extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Combines multiple composer.json into one 
so a central set of dependencies can be installed";
+       }
+
+       public function execute() {
+               global $IP;
+               $paths = $this->mArgs;
+               $paths[] = "$IP/composer.json";
+               $vendor = "$IP/vendor/composer.json";
+               if ( file_exists( $vendor ) ) {
+                       $vendorContents = FormatJson::decode( 
file_get_contents( $vendor ), true );
+                       if ( !isset( $vendorContents['extra']['consolidated'] ) 
) {
+                               $this->error( "A non-autogenerated 
composer.json already exists at $vendor. Please move it somewhere else before 
running this script.", 1 );
+                       }
+               }
+
+               $deps = array();
+               $skip = array();
+               foreach ( $paths as $path ) {
+                       $contents = new ComposerJsonParser( $path );
+                       foreach ( $contents->getRequiredDependencies() as $name 
=> $version ) {
+                               if ( isset( $deps[$name] ) && $version !== 
$deps[$name] ) {
+                                       // TODO: We should use some of 
compser's version comparer stuff to check if
+                                       // stuff like 2.0.* and 2.0.10 are 
compatible, but just fail for now.
+                                       $this->error( "Error: multiple versions 
wanted for $name: $version and {$deps[$name]}. Please reconcile this manually, 
skipping." );
+                                       $skip[] = $name;
+                               } else {
+                                       $deps[$name] = $version;
+                               }
+                       }
+               }
+
+               $composerjson = array(
+                       'require' => array(),
+                       'extra' => array(
+                               'consolidated' => $paths,
+                       ),
+                       'config' => array(
+                               'vendor-dir' => '.',
+                               'prepend-autoloader' => false,
+                               'optimize-autoloader' => true,
+                       ),
+               );
+               // Build the composer.json file now
+               foreach ( $deps as $name => $version ) {
+                       if ( !in_array( $name, $skip ) ) {
+                               $composerjson['require'][$name] = $version;
+                               $this->output( "Dependency: $name $version\n" );
+                       }
+               }
+
+               file_put_contents( $vendor, FormatJson::encode( $composerjson, 
true ) );
+               $this->output( "Wrote to $vendor.\n" );
+       }
+}
+
+$maintClass = 'ConsolidateComposerDependencies';
+require_once RUN_MAINTENANCE_IF_MAIN;
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/178739
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iff0fc1a6946e3693360f094d3a780d5c75cd6587
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to