Skip to content
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

Upgrade to drupal-code-generator v3 #5371

Merged
merged 32 commits into from
Mar 14, 2023
Merged

Upgrade to drupal-code-generator v3 #5371

merged 32 commits into from
Mar 14, 2023

Conversation

Chi-teck
Copy link
Collaborator

@Chi-teck Chi-teck commented Jan 30, 2023

Drush currently uses DCG 2 to generate code.

Remaining tasks

  • Update drush generate command to use PHP attributes instead of annotations
  • Update drush:command-file generator
  • Figure out a way to register third-party generators
  • Update Drush tests
  • Implement completion for generator names

The big question is how to deliver this change. Here are a couple complications.

  1. DCG 3 is not API compatible with DCG 2.
  2. DCG 3 requires PHP 8.1 and Drupal 10.

Basically there are two options.

  1. Wait for a new major Drush release that would only support Drupal 10.
  2. Make drush generate compatible with both DCG versions.

@Chi-teck
Copy link
Collaborator Author

This kind of critical, because Drupal 10 has been already released and code generated by DCG 2 is not fully compatible with it. In order to support multiple Drupal versions DCG would have to generate code with deprecations .

@weitzman
Copy link
Member

I dont feel strongly about it, but I think 1. is the best way forward. We could branch for Drush 12 now, with a target release date just before Drupalcon Pittsburgh (early June). Drush 12 would be Drupal 10 minimum. Here is the todo list for Drush 12 https://github.com/drush-ops/drush/milestone/7

@Chi-teck Chi-teck added this to the drush12 milestone Jan 31, 2023
@weitzman weitzman changed the base branch from 11.x to 12.x February 24, 2023 15:23
@weitzman
Copy link
Member

weitzman commented Feb 24, 2023

Update: ignore below. I had merged composer changes into 11.x by accident.

I changed the base of this PR to 12.x It says it has no merge conflicts but I dont see how composer.lock could not conflict. Please reroll if needed when you get a chance.

@Chi-teck
Copy link
Collaborator Author

Chi-teck commented Feb 25, 2023

Figure out a way to register third-party generators

Modules can subscribe to generator info event and register their generators. I am not sure if this is enough to resolve this task.

Copy link
Member

@weitzman weitzman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does a global generator subscribe to the event? Here is what we say about authoring global generators today https://www.drush.org/11.x/generators/#global-generators

src/Commands/generate/GenerateCommands.php Outdated Show resolved Hide resolved
@Chi-teck
Copy link
Collaborator Author

How does a global generator subscribe to the event? Here is what we say about authoring global generators today https://www.drush.org/11.x/generators/#global-generators

Those need to be registered in the generate command before $application->run();

@weitzman
Copy link
Member

weitzman commented Mar 6, 2023

I updated the dcf generator a bit in #5442. Still needs port to DCG3.

@weitzman
Copy link
Member

For global generators, is there any reason we can't keep using the code in discoverPsr4Generators - https://github.com/drush-ops/drush/pull/5371/files#diff-14a8581695da2d03094b84103528a480af8e2891e0590de222aa9b04a8d4d7f2L137-L144. That can be called right from the command method.

@Chi-teck
Copy link
Collaborator Author

I updated the dcf generator a bit in #5442. Still needs port to DCG3.

The dcf command has been updated to DCG3. Needs review.

@Chi-teck
Copy link
Collaborator Author

For global generators, is there any reason we can't keep using the code in discoverPsr4Generators - https://github.com/drush-ops/drush/pull/5371/files#diff-14a8581695da2d03094b84103528a480af8e2891e0590de222aa9b04a8d4d7f2L137-L144. That can be called right from the command method.

The link seems broken. Anyway we can use any discovery method as long as it can ignore DCG 2 generators. I would prefer something less magic, something that does not rely on reflection API and loading generator classes. That would allow to avoid difficulties in future major updates of DCG and symfony/console.

@weitzman
Copy link
Member

The diff wont show because it is inside the file thats deleted in the PR.

IMO we should merge this without major changes to generator discovery in drush (both global and module). Then we work on those in #4685

@Chi-teck
Copy link
Collaborator Author

I've removed discoverDrushGenerators. I don't think it's worth implementing a discovery method for just a couple of generators. Also replaced adjustDCGGenerators with event subscriber.

@weitzman weitzman merged commit 5edeefa into 12.x Mar 14, 2023
@weitzman weitzman deleted the dcg-3 branch March 14, 2023 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants