diff --git a/includes/environment.inc b/includes/environment.inc index ca53188632..b8847f66c5 100644 --- a/includes/environment.inc +++ b/includes/environment.inc @@ -133,192 +133,6 @@ function drush_cwd() { return $path; } -/** - * Automatically loads a Drush extension's autoload file. - * Does nothing if the autoload file was already included - * (e.g. if this drush extension was installed via the composer.json - * in the current Drupal site's project). - * - * Generally speaking, detecting prior autoloading should - * not be necessary. If the drush extension was installed via - * the project's composer.json file, then the extension should - * be located inside the Drupal project, should not be shared - * by any other Drupal project, and should not have its own - * 'vendor' directory. - * - * If the extension is standalone, on the other hand, then it - * might exist inside a module directory, or in some global - * location (e.g. ~/.drush). If it has its own composer.json, - * then it should also have its own vendor directory and - * autoload.php file. - * - * Scenarios: - * - * 1) Loaded in a global location - * $HOME/.drush/baz/baz.drush.inc - * /usr/share/drush/commands/baz/baz.drush.inc - * - * These extensions will NOT be in project's composer.json - * Must load autoload file if it exists - * It will be at vendor/autoload.php - * - * 2) Included with a module - * $ROOT/sites/all/modules/foo/foo.drush.inc - * $ROOT/sites/all/modules/foo/subfoo/subfoo.drush.inc - * - * These extensions MIGHT be in project's composer.json - * If they are not, there should be a vendor/autoload.php - * - * n.b. In this instance, the vendor/autoload might - * be an arbitrary number of folders above the commandfile - * e.g. if the module foo has sites/all/modules/foo/modules/subfoo/subfoo.drush.inc. - * We need to figure out what composer manager does in - * this instance, though, as modules that have composer.json - * must either use composer manager, or be using a site-local - * Drush. We do not support anything else. - * - * 3) In a Drupal site's 'drush' directory - * $ROOT/drush/baz/baz.drush.inc - * $ROOT/sites/all/drush/baz/baz.drush.inc - * - * These extensions MIGHT be in project's composer.json - * If they are not, there should be a vendor/autoload.php - * - * 4) In a Drupal site's 'vendor' directory - * $ROOT/sites/all/vendor/bar/baz/baz.drush.inc - * $ROOT/core/vendor/bar/baz/baz.drush.inc - * - * These extensions ARE in project's composer.json - * There will NEVER be a local 'vendor' directory. - * - * 5) Installed via composer in a global location - * $HOME/.drush/vendor/bar/baz/baz.drush.inc - * /usr/share/drush/commands/vendor/bar/baz/baz.drush.inc - * ^^^^ - * (configurable part -- defaults to ALLUSERSPROFILE/Drush on Windows) - * - * This is a bit of an odd duck, but folks do this because - * `drush dl` does not support downloading extensions from - * Packagist/GitHub/etc., so `cd ~/.drush && composer require ...` - * is the current workaround. - * - * These extensions will NOT be in project's composer.json. - * Must load autoload file if it exists; however, it might - * be in the same relative location as (4). - * - * Required actions: - * - * a) If a commandfile is in project's 'vendor' directory, - * then we must call drush_add_commandfile(__FILE__). - * If it is anywhere else, it will already have been added. - * - * Actually, if the commandfile is in the project's - * composer.json file, and a custom installer has - * routed it to some location such as ROOT/drush, - * then at drush_autoload() time, it will NOT YET be - * added. drush_add_commandfile() is idempotent; we - * could therefore always call it from drush_autoload(). - * We can even use the result of drush_add_commandfile() - * ('already loaded') as an indicator of whether the - * commandfile is in a Drupal site's project composer.json - * file. - * - * * If a commandfile has NOT been added when - * drush_autoload() is called, then it means that - * this commandfile was included by the Composer - * autoloader, which means that we DO NOT need to - * find and include the vendor/autoload.php file. - * - * b) If a commandfile is NOT in a project's composer.json, - * then we need to load the project's autoload file. - * - * If the autoload file is needed, it will usually be - * found at vendor/autoload.php. If the extension is - * in the project's composer.json file, then we should - * never find the local vendor/autoload.php file. - * - * * Include __DIR__/vendor/autoload.php if it exists - * * Include __DIR__/../../../vendor/autoload.php if it - * - * Performance optimization: - * - * In the case of ../../../vendor/autoload.php, - * AKA ../../autoload.php, then we MIGHT want - * to include it. In case (5), we want it, but in - * case (4) we do not. - * - * Including an autoload file twice is innocuous, - * so we could just invariantly include it. This - * might have some small performance impact, though. - * In case (5), we are guarenteed that the path will - * have /drush/ or /.drush/. In case (4) it should - * not, but this is not guarenteed. In case (4), - * we know where the Drupal root is, though, so we - * can use realpath to determine if our relative - * autoload.php is the project autoload file. - * - * * Do NOT include __DIR__/../../../vendor/autoload.php - * if it is one of: - * - $ROOT/sites/all/vendor/autoload.php - * - $ROOT/core/vendor/autoload.php - * - * Problem, though; we have not determined the - * site root at the time that Drush includes - * vendor/autoload.php, which is when composer - * will start including Drush commandfiles (presuming - * that the 'autoload' section of the Drush - * extension's composer.json file). If we are - * using a site-local Drush, though, then we know - * that the Drupal site's vendor/autoload.php file - * is the same as the Drush vendor/autoload.php - * file. We can therefore note the autoload file - * that Drush includes, and skip including the - * Drush extension's autoload file if it is at the - * same path as the Drush autoload file. - * - * Further Performance optimization: - * - * Some modules or drush extensions might have more than - * one *.drush.inc file, although this is rare. In these - * cases, though, each commandfile will call drush_autoload(__FILE__), - * although only the first one called will need to load - * the autoload.php file. We could just let them be included - * multiple times, which should be innocuous, or we could - * cache the list of locations where we have already included - * autoloaders from, and skip those on subsequent updates. - * - * This is, perhaps, unnecessary, as Drush will not include - * the autoloader for commandfiles that were managed by the - * Drush project's composer.json file, which is our ultimate - * goal for composer-managed sites. - * - * TODO: Test with composer_manager. We might need to no-op - * this function if it is in use. - * - * Usage: - * - * On the last line of any *.drush.inc commandfile, add: - * - * drush_autoload(__FILE__); - * -function drush_autoload($commandfile) { - $already_added = drush_add_commandfile($commandfile); - - if (!$already_added) { - $dir = dirname($commandfile); - $candidates = array("vendor/autoload.php", "../../../vendor/autoload.php"); - $drush_autoload_file = drush_get_context('DRUSH_VENDOR_PATH', ''); - - foreach ($candidates as $candidate) { - $autoload = $dir . '/' . $candidate; - if (file_exists($autoload) && (realpath($autoload) != $drush_autoload_file)) { - include $autoload; - } - } - } -} - */ - /** * Converts a Windows path (dir1\dir2\dir3) into a Unix path (dir1/dir2/dir3). * Also converts a cygwin "drive emulation" path (/cygdrive/c/dir1) into a