Review main Merged

86184[TASK] Use ClassMapGenerator from composer/class-map-generator

Christian Kuhn CR +2 V +2 Hard +160 −353 updated 09/20/24, 09:20

Commit message

This patch looks simple, but isn't in detail, and requires
a bit of background knowledge.

Here is the story:

Back in 2015, during early works to make TYPO3 composer ready,
the custom TYPO3 class autoloader approach has been removed
and substituted with the composer based autoloader in #67212.

TYPO3 supports composer based instances, as well as non-composer
"legacy" instances, where a .tar.gz with all "core" extensions
is downloaded that can be enriched with additional extensions
from TER, typically using the extension manager. Note the core
monorepo and functional tests are "legacy" instances, too.

Legacy instances need an additional quirk for PHP class discovery:
The .tar.gz is build from a checkout of the monorepo and calling
'composer install', which creates the composer autoload file for
all extensions, that is then shipped within the .tar.gz. When
legacy instances add local extensions (in typo3conf/ext), those
need autoload information as well. This is done by "overloading"
the default shipped autoload file with a dynamically created one,
triggered when changing the extensions list.

The implementation of this dynamically created file happens in
ext:core Core/ClassLoadingInformationGenerator, the main find
and lookup magic is in ext:core Resources/PHP/ClassMapGenerator.

With #67212, Resources/PHP/ClassMapGenerator has been copied from
upstream composer/composer in 2015 and put into Resources/PHP with
the same namespace. This has been done to not require the full
composer package when just this single class was needed.

While ClassMapGenerator has been well maintained in upstream over
the years, our copy did not receive much love and has not been
kept in sync, leading to patches like #102498. Also - and that's
the good thing - ClassMapGenerator plus a few other classes has
been extracted from composer/composer to the dedicated package
composer/class-map-generator.

The patch now finally aligns this:

Core monorepo now requires composer/class-map-generator:
> composer req composer/class-map-generator:^1.3.4"

This allows us to use Composer\ClassMapGenerator\ClassMapGenerator
instead of our copy, which is removed. Since this requirement is
needed for "legacy" mode only, it is *not* added to ext:core
composer.json.

The patch uses the new implementation and needs to takes care of
one additional detail: With [1] in composer/composer, before the
class has been extracted to composer/class-map-generator, a call
to realpath() has been optimized away, which, when used by us,
leads to an issue in makePathRelative(). We may clean this up
later, but add the realpath locally again, for now.

The fact that both local monorepo instances and functional tests
still work are a good proof the patch is ok.

Note the patch also resolves a warning when calling
"composer install --optimize-autoload" on monorepo, which mumbled
about class Composer\Autoload\ClassMapGenerator being found in
two different locations before, due to our copy using the same
namespace.

[1] https://github.com/composer/composer/commit/5822b58c1f9118aecf5d07be0fb7664e0fde1477

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Benjamin Franzke +1
    • Garvin Hicking +1
    • Stefan Bürk +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Garvin Hicking +1
    • Stefan Bürk +1
    • core-ci +1 CI

Issues 3

Files 5

Review log 1924

  1. Christian Kuhn uploaded patch set 1 09/18/24, 14:24

  2. core-ci voted on patch set 1 V -1 09/18/24, 14:40 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66140

  3. Benjamin Franzke commented on patch set 1 09/18/24, 15:05

    composer.json:36

    This dependency is not needed/used in composer mode. Please only include it in the classic bundle.
  4. Christian Kuhn commented on patch set 1 09/19/24, 08:49

    composer.json:36 Reply

    how to do that?
  5. Christian Kuhn commented on patch set 1 09/19/24, 09:11

    composer.json:36 Reply

    got it: we should leave it out from core/composer.json and have it in monorepo only.
  6. Christian Kuhn uploaded patch set 2 V -1 09/19/24, 10:20

  7. Christian Kuhn uploaded patch set 3 09/19/24, 10:22

  8. core-ci voted on patch set 2 V +1 09/19/24, 10:37 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66196

  9. core-ci voted on patch set 3 V +1 09/19/24, 10:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66197

  10. Christian Kuhn updated the commit message in patch set 4 V +1 09/19/24, 11:27

  11. core-ci voted on patch set 4 V +1 09/19/24, 11:43 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66204

  12. Benjamin Franzke commented on patch set 4 09/19/24, 11:47

    ClassMapGenerator.php:1

    With the removal of this file, ``` "classmap": [ "typo3/sysext/core/Resources/PHP/" ], ``` can be dropped from composer.json and typo3/sysext/core/composer.json
  13. Christian Kuhn uploaded patch set 5 V +1 09/19/24, 11:53

  14. Christian Kuhn commented on patch set 4 09/19/24, 11:53

    ClassMapGenerator.php:1 Reply

    ah. good catch. i kept that due to GlobalDebugFunctions.php, but that one is loaded via 'files'.
  15. Benjamin Franzke commented on patch set 4 09/19/24, 11:55

    Good to migrate!
    Just want to mention: I think we do not test symlinked `typo3_src` or symlinked docroot (think versioned deployments) in functionals/acceptance tests. That's something I'd definitely try manually with custom extensions (that may also be symlinked into typo3conf/ext/) with this patch.
  16. Stefan Bürk commented on patch set 5 09/19/24, 12:01

    Reply

    system extension are symlinked in test instances `.../typo3/sysext/` - just the whole typo3 folder is not symlinked (and the index.php). So I guess that that should nearly test legacy mode correctly. But had the same thoughts too test this at least manually and on it ;)
  17. core-ci voted on patch set 5 V +1 09/19/24, 12:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66206

  18. Stefan Bürk commented on patch set 5 09/19/24, 12:50

    Reply

    Did different tests, but following uses kind of multiple symlinkins: ``` git clone https://github.com/TYPO3/typo3.git ./core-mono \ && cd core-mono \ && git fetch ssh://stefan.buerk@review.typo3.org:29418/Packages/TYPO3.CMS refs/changes/84/86184/5 && git cherry-pick FETCH_HEAD \ && Build/Scripts/runTests.sh -s composerInstall \ && cd .. \ && mkdir ./legacy \ && cd ./legacy \ && ln -s ../core-mono ./typo3_src-X.Y.Z \ && ln -s typo3_src-X.Y.Z typo3_src \ && ln -s typo3_src/index.php index.php \ && ln -s typo3_src/typo3 typo3 \ && touch FIRST_INSTALL \ && cd ../ \ && ln -s legacy ./legacy-project-symlinked ``` configured docroot onto `./legacy-project-symlinked` and run the installer (web) .. first page display a error because the folder is a symlink and must be an folder, but continue with error installs a functional system, and I can log into the backend. Than I symlinked a exenstion with custom backend module to it: ``` cd typo3conf/ext \ && ln -s ../../../test-extensions/test_backend_module ``` headed into the extension manager, activated that module and it worked. Did a similar test having the mono repo as `typo3_src` symlinked first before heading to the described variant above. And also on `./legacy` directly. Reset whole folders (typo3conf, typo3temp, fileadmin, ..) for each test. Legacy functional tests instances symlinks system extension into the typo3/sysext/folder: ``` cd typo3temp/var/tests/functional-0a32f04/typo3/sysext/ \ ls -l ``` which outputs on my system for example: ``` backend -> /var/www/work/t3c/core-main/core-main/typo3/sysext/backend/ core -> /var/www/work/t3c/core-main/core-main/typo3/sysext/core/ extbase -> /var/www/work/t3c/core-main/core-main/typo3/sysext/extbase/ fluid -> /var/www/work/t3c/core-main/core-main/typo3/sysext/fluid/ frontend -> /var/www/work/t3c/core-main/core-main/typo3/sysext/frontend/ redirects -> /var/www/work/t3c/core-main/core-main/typo3/sysext/redirects/ ``` and works pretty fine. From my point of view this change works for legacy mode. Or do you have setup variants which are even more trickier ?
  19. Stefan Bürk voted on patch set 5 CR +1 V +1 09/19/24, 17:22

  20. Christian Kuhn commented on patch set 5 09/19/24, 18:16

    Reply

    this looks good to me, Stefan! Thanks for checking further combinations. Guess that's fine: setting comment to resolved.
  21. Garvin Hicking commented on patch set 5 CR +1 V +1 09/19/24, 18:58

    LGTM. I applied the patch in both my monorepo legacy and a TDK/composer monorepo install, witnout seeing breakage.
  22. Benjamin Franzke voted on patch set 5 CR +1 09/20/24, 09:18

  23. Christian Kuhn voted on patch set 5 CR +2 V +2 09/20/24, 09:20

  24. Christian Kuhn merged patch set 6 09/20/24, 09:20