Problem/Motivation
\Drupal\Core\Command\DrupalApplication::bootstrap() contains the following code:
// We need to not load a cached copy of the container from disk. For
// example, inside Kernel tests, we need to fully build the container so
// we discover and register commands, instead of reusing the container
// from the Kernel test itself. Therefore, we pass `FALSE` for the
// `$allow_dumping` parameter here.
$kernel = new DrupalKernel('prod', $this->classloader, FALSE);
Why should the command line use a ContainerBuilder container? This does not feel correct.
Proposed resolution
The reason why this was necessary for kernel testing is because of the changes made by \Drupal\KernelTests\KernelTestBase::register to the container.
Use the context to be able to set things about the kernel to make testing commands in KernelTestBase simple but still use a regular dumping kernel when not testing.
Remaining tasks
User interface changes
None
Introduced terminology
N/a
API changes
N/a
Data model changes
N/a
Release notes snippet
N/a
Comments
Comment #3
alexpottComment #4
alexpottComment #5
catchPretty sure drush uses container builder, at least this is what it looked like when I profiled a couple of drush commands last week, so this should make cli operations feel a lot snappier across the board.
MR looks very tidy to me.
Comment #6
alexpottComment #7
moshe weitzman commentedI independently came up with the same fix at #3594334: Add a module and theme install command 🙌. So now that issue is blocked by this one
Comment #12
catchCommitted/pushed to main and cherry-picked to 11.x and 11.4.x, thanks!