-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove dual autoloader feature from global Drush installs #5521
Conversation
…upal; only bootstrap Drupal sites with a shared vendor.
Thanks for getting this going again. The simplification looks great. I'm uneasy with blessing drush as a launcher. We achieved a lot of hard fought clarity in our install docs which now read "Drush only supports one install method. It requires that your Drupal site be built with Composer and Drush be listed as a dependency.". They also say "To be able to call drush from anywhere, install the Drush Launcher.". The problem with the old way is that bug reporters had no idea which drush was giving an error (launcher or site). They also had mismatched versions between launcher and site. I am loathe to going back to those days. I can tolerate if Drush happens to work as a launcher. |
I am reluctant to remove all of the launcher stuff primarily due to the handling of remote site aliases. Perhaps we could remove the launcher-related code that was not related to remote sites. We could also consider moving remote site aliases to the Drush launcher, and remove all of the launcher code from Drush core. Failures here are due to some situations that weren't quite right in the 11.x version of this PR, and are now being caught by strict type checking in the 12.x branch. Looking into those now. |
Another thing about remote dispatches: in 11.x, we run:
In 12.x, we should probably change this to:
|
I spent some time considering the user journeys related to remote dispatch and site aliases that are and are not important to me. Important use cases:
Unimportant use cases:
I think I am holding on to the Drush launcher because I am concerned about harming use cases 3 and 4. Proposal:
If we did those two things, then I think we could completely remove What do you think? |
Sounds good to me.
Would we obsolete the HandleRemoteCommands attribute because there would be no such thing as remote dispatches? The only way would to remote dispatch would be via |
I'm not sure if we should maintain the syntax There's another important use-case I forgot about. Drush 11.x should be able to use |
Use case: Running Drush when there is no Drupal site at the cwd. Drush 11.x:
Drush 12.x:
I am running into a variation of this situation with the failing tests in this PR. While I am reluctant to move forward and remove too much functionality without the replacement behavior described above, I think I am going to go one step further in this PR and remove more of the bootstrap capabilities:
Removing |
Changed bootstrapping only slightly, only broke one test. Onward to make more changes. |
The archive restore test is failing, because archive dump, when run on the Drush project, captures the SUT without an embedded Drush. This PR makes it impossible to bootstrap the restored archive. To fix this test, I'll have to inject Drush into the restored site. I think this is reasonable. Injecting Drush into the SUT so that the archive restores cleanly seems undesirable. If I do it post restore, I can use a path repository to include Drush from source. |
…sh command on a Drupal site at a different location than the SUT, use the copy of Drush that's in that Drupal site.
src/Preflight/Preflight.php
Outdated
$root = $this->preferredSite(); | ||
|
||
// TODO: We might redispatch to some other site later, but THROW | ||
// now if there is no root. Drush 12.x won't run if it is in a vendor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UNLESS
Almost done; a few more adjustments to do.
Were you referring specifically to the long comment that explained how the Drush preflight worked? I interpreted your comment to refer to the functionality of the launcher itself. I removed mention of the launcher from that comment. We can continue towards the deprecation and removal of the launcher as follow-on work as described above. I'm still a little leery to remove the launcher until Drush launcher supports remote aliases, but we can at least do the pre-req work I described above before we decide what our Drush 12 strategy will be. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I was referring to that long comment. Your plan sounds good.
src/Preflight/Preflight.php
Outdated
@@ -313,6 +334,7 @@ public function preflight($argv): bool | |||
// redispatch to a site-local Drush, then we cannot continue. | |||
// This can happen when using Drush 9 to call a site-local Drush 8 | |||
// using an alias record that is only defined in a Drush 8 format. | |||
// TODO: We can remove this when we drop support for Drush 8 aliases (already done?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, already done afaik
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment appears to be incorrect; we get here any time the user tries to use an alias that cannot be found.
// any site other than the one it shares its vendor directory with. We | ||
// must therefore add Drush via a Composer PATH repository in the site | ||
// created via archive restore before we can run Drush commands on it. | ||
$this->execOnRestoredSite(['composer', 'config', 'repositories.drush', 'path', dirname(self::getDrush())]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is editing the composer.json in our root? If so does the test reliably undo the changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is editing the composer.json on a copy / fixture Drupal site, not the SUT. The fixture is thrown away after the test.
@@ -109,16 +109,6 @@ public function getComposerRoot(): string | |||
return $this->drupalFinder()->getComposerRoot(); | |||
} | |||
|
|||
public function locateRoot($root, $start_path = null): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function was unused.
I think this is ready to merge, after review comments, if any, are resolved. Follow-on PRs:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clone Drush 12.x and rename it drush-launcher. Remove bootstrapping. Keep preflight, alias handling and redispatch. Keep a few select commands (drush browse, drush uli, etc) that operate primarily by making remote calls to another instance of Drush.
Benefits of the current launcher:
- rarely has an SA that it needs to respond
- It likely that the launcher and the site-local Drush get out of sync. We need to keep reliably launching in this scenario.
- We need to get @webflo on board with major changes to the launcher.
Make remote dispatches launch PROJECT_ROOT/vendor/bin/drush instead of the drush in the PATH when drush_script is not specified.
FYI composer config bin-dir
gets you the configured bin dir. This is surely available in PHP as well.
drush.php
Outdated
* └── drush | ||
* └── drush.php | ||
* | ||
* Drush project: (Only used when developing Drush; `composer install --dev`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove composer install --dev
? I'm not sure how it distinguishes from a regular site.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This differentiated this use case from the one below, which used to say composer install --no-dev
before it was removed. We can remove this modifier here now.
|
||
// Now that we have our final Drupal root, check to see if there is | ||
// a site-local Drush. If there is, we will redispatch to it. | ||
// NOTE: termination handlers have not been set yet, so it is okay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get rid of ther Drush termination handlers (in a separate issue). I refer to the unusual exit code checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe; need to check and see what role they are still playing. Would be simpler to not have them.
$fallBackPath = $this->preflightArgs->selectedSite($this->config()->get('runtime.drush-script')); | ||
return $this->setSelectedSite($selectedRoot, $fallBackPath); | ||
} | ||
$projectRoot = dirname($this->environment->vendorPath()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Composer has a configurable location for vendor https://getcomposer.org/doc/06-config.md#vendor-dir
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no API to determine the project root from the vendor directory. Two options:
$a = include $vendor/composer/installed.php; $project_root = $a['root']['installed_path'];
- Walk up from
$vendor
until we find a composer.json file.
The problem with 1. is that it breaks if Composer changes its internal implementation of what it writes to the vendor directory; installed.php is not guaranteed to exist, and not guaranteed to have the same contents.
The problem with 2. is that there's nothing preventing a user from putting vendor
outside the project root, or deep inside a directory that might encounter some other composer.json before it gets to the root.
It's pretty rare for Drupal sites to relocate the vendor directory at all; maybe option 2 is good enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'll try option 1
and fall back to 2
if $installed.php doesn't return recognizable data. That would mean that the code path in 2
would be seldom-exercised, although we could cover it in the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neither 1 nor 2 look appetizing to me. I say leave it as is.
Co-authored-by: Moshe Weitzman <weitzman@tejasa.com>
We can't check the configured Composer bin dir for remote sites. We'll have to assume |
Right. But we could assume that the composer codebase is the same for remote and local. Thats quite a safe assumption in the modern era. It would be slightly better than assuming vendor/bin. Happy to defer this to another day. |
Oh, good point. |
Removed the comment about |
Do not allow Drush to combine autoload files from a non-site-local Drupal; only bootstrap Drupal sites with a shared vendor.
Continuation of #5138. No changes yet, just rebased on 12.x branch.
c.f. #5138 (comment)