Problem/Motivation

Functions like t() are not bad and working around the availability for unit tests is a pain. We can include bootstrap.inc using composer and then tests etc will work without having to fake t().

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new9.78 KB

Something like this...

After applying the patch you need to rebuild your autoloader... removing vendor and running composer install should be enough.

andypost’s picture

This way we can load/define requirement constants too!
Nice idea and easy to get rid of when bootstrap.inc will be purged

alexpott’s picture

StatusFileSize
new13.74 KB
new23.52 KB

@andypost if it is purged. functions are okay. Application wide constants are too.

jungle’s picture

+++ b/core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php
@@ -1,195 +1,183 @@
+      'www.blackhat.com',
+      'www.example.com',

One thing out of scope here. Should blackhat.com be changed?

alexpott’s picture

StatusFileSize
new423 bytes
new23.93 KB

Fixing a test.

The last submitted patch, 2: 3151118-2.patch, failed testing. View results

The last submitted patch, 4: 3151118-4.patch, failed testing. View results

alexpott’s picture

+++ b/core/tests/Drupal/Tests/Core/Extension/ExtensionSerializationTest.php
@@ -45,7 +45,8 @@ protected function setUp(): void {
-    $this->assertFalse(defined('DRUPAL_ROOT'), 'Constant DRUPAL_ROOT is defined.');
+    // @todo think about this.
+    // $this->assertFalse(defined('DRUPAL_ROOT'), 'Constant DRUPAL_ROOT is defined.');

This is amusing in a way. We really should have made this change ages ago. Would have saved ourselves quite a bit of work which does not add a tonne of value. Note in some places where we cache extension objects we're changing approach - see #3116858: Don't cache whole extension objects in FileCache

heddn’s picture

Issue tags: +Needs change record

Tagging. I also ponder what this means for contrib testing. Does this break anything for contrib unit tests, if they wrote them poorly?

alexpott’s picture

@heddn potentially... but if you do it properly then no... for example:

+++ b/core/tests/Drupal/Tests/Core/Render/Element/MachineNameTest.php
@@ -111,13 +111,3 @@ public function testProcessMachineName() {
-
-namespace Drupal\Core\Render\Element;
-
-if (!function_exists('t')) {
-
-  function t($string, array $args = []) {
-    return strtr($string, $args);
-  }
-
-}

This wouldn't cause a break. If contrib did that.

heddn’s picture

re #11: that's my concern. If someone does it poorly, which isn't all that hard to do. But if we write up a good CR and do this in a new minor, the benefit from this change is really, really high.

alexpott’s picture

I had a crack at the CR - https://www.drupal.org/node/3151229

heddn’s picture

This is looking really nice. Leaving in NR to get some more feedback from others.

jungle’s picture

BTW, updated CR that added "After" (section) to pair with "Before", or looks incomplete at the first glimpse. See
https://www.drupal.org/node/3151229/revisions/view/11942291/11942414

alexpott’s picture

Issue tags: -Needs change record
StatusFileSize
new1.51 KB
new24.54 KB

We need to resolve #9. I think we can do this by removing the check and improving the test to show that a different app root is used after serialising and unserialising.

mile23’s picture

+2 on removing all the require 'bootstrap.inc'; type lines from everywhere in the codebase.

-1 on leaving bootstrap.inc the way it is, because the constants should be moved out from it, and the functions need to be rolled somewhere else, as per some issues in #3097045: [META] Provide modern replacements for and deprecate the legacy include files.

So that's a net positive. :-)

For other include files that have lots of require statements like this, maybe we should do the same thing with them. I can't think of which ones those would be offhand, though.

Tempted to add the 'Kill includes' tag, but this doesn't really do that.

alexpott’s picture

because the constants should be moved out from it

I think we should consider whether this is true. Functions and constants are not bad. We now only have two usages of \Drupal in bootstrap.inc - I agree those should be refactored but somethings feel like change for changes sake.

mile23’s picture

It's out of scope here but I've always maintained that the constants should be in a different file from the functions in bootstrap.inc, so that we can use constants without the overhead of the functions.

The big problem has been tests that need those constants but which also shouldn't load the functions in bootstrap.inc for whatever reason. Like more strict unit tests. I haven't been neck-deep in that code for a while, so if that's not an issue any more then, uh, it's not an issue. :-)

Anyway, +1 on using composer to autoload this file and removing a bunch of extraneous require stuff. It just feels a little hacky rather than architected, and we'll probably eventually circle back to undoing this as things progress.

alexpott’s picture

The big problem has been tests that need those constants but which also shouldn't load the functions in bootstrap.inc for whatever reason.

...so if that's not an issue any more then, uh, it's not an issue. :-)

Yeah that's the thing - there really is not a good reason to not have a function like t()... yes DRUPAL_ROOT is a bit of an issue because it makes it tricky to test... but we have a service to replace that so we're most of the way there. And just because we autoload bootstrap.inc doesn't mean we can't deprecate DRUPAL_ROOT. It probably would have been great to put all the constants in a constants.php a long long time ago and not do the refactors we've done. But what's done is done. But tldr; none of this is not a reason to not go forward here.

voleger’s picture

+1 for this issue

That would be great if we have only two files for load by Composer in Drupal 10: constants.php and functions.php.
No more *.inc files. No more include files handled by the Kernel. Maybe fill a followup to address that before drupal:10.0.0-alpha1? Until then there would be the only bootstrap.inc file loaded by the Composer. So good so far.

#18 +1 for moving or deprecating of drupal_get_filename and watchdog_exception functions. I'm not sure that some code will use those function before Kernel initialization but small chance exist that situation may happen.

For reference, there are some issues to address the replacement of some functions in bootstrap.inc file:

daffie’s picture

Status: Needs review » Reviewed & tested by the community

The patch adds the autoloading of includes/bootstrap.inc
All occurrences of requiring the loading of includes/bootstrap.inc by "hand" are removed.
All code changes look good to me.
For me it is RTBC.

I am for continue to deprecated the contents of the file includes/bootstrap.inc. Hopefully someday we can remove the autoloading of the file from composer.json.

jungle’s picture

After applying the patch you need to rebuild your autoloader... removing vendor and running composer install should be enough.

BTW, tested:

  • Running composer dump-autoload or composer dumpautoload is not enough
  • Running composer install works without removing vendor.
andypost’s picture

Nice to see remains of st() are gone)

+++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php
@@ -1195,24 +1195,3 @@ public function setKey($key, $value) {
-if (!function_exists('t')) {
...
-  function t($string, array $args = []) {
-    return strtr($string, $args);
...
-if (!function_exists('t')) {
...
-  function t($string, array $args = []) {
-    return strtr($string, $args);

+++ b/core/tests/Drupal/Tests/Core/Render/Element/MachineNameTest.php
@@ -111,13 +111,3 @@ public function testProcessMachineName() {
-if (!function_exists('t')) {
...
-  function t($string, array $args = []) {
-    return strtr($string, $args);

It makes t() to work properly in tests

alexpott’s picture

StatusFileSize
new22.5 KB

Rerolled as #2908079: Move some of the bootstrap.inc PHP-related constants to \Drupal and deprecate the old versions landed. I still think this is worth doing to make t() available and to not need to require bootstrap.inc when build a script to boot drupal.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 25: 3151118-25.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

JS random fails..

xjm’s picture

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 25: 3151118-25.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

JS random fails..

beakerboy’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new22.15 KB

Patch no longer applies. I removed the section from the patch that has already been removed in core.

beakerboy’s picture

StatusFileSize
new785 bytes

Forgot the interdiff...

jungle’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new386 bytes

Checked with $ git grep 'bootstrap.inc' and $ COMPOSER_ROOT_VERSION=9.1.x-dev composer update --lock -vvv, #31 looks good.

But the inter-diff file attached in #32 is incorrect. attaching a raw-interdiff file.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 31: 3151118-31.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

Random JS test fail

mondrake’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll
kapilv’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new22.15 KB
new856 bytes

re-roll patch.

kapilv’s picture

Status: Needs review » Needs work

The last submitted patch, 37: 3151118-37.patch, failed testing. View results

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

anmolgoyal74’s picture

Status: Needs work » Needs review
StatusFileSize
new22.15 KB
new421 bytes

Updated the hash.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

The patch adds the autoloading of includes/bootstrap.inc
All occurrences of requiring the loading of includes/bootstrap.inc by "hand" are removed.
All code changes look good to me.
Reroll looks good to me.
For me it is RTBC.

alexpott’s picture

StatusFileSize
new829 bytes
new22.96 KB

Rerolled and found one more small thing we can remove in a test...

  • catch committed b72fe50 on 9.2.x
    Issue #3151118 by alexpott, Beakerboy, kapilkumar0324, anmolgoyal74,...

  • catch committed 1167ce5 on 9.1.x
    Issue #3151118 by alexpott, Beakerboy, kapilkumar0324, anmolgoyal74,...
catch’s picture

Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs framework manager review

Only thing that makes me hesitant here is we should have done it pre-8.0.0, but better late than never. Committed/pushed to 9.2.x and 9.1.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.