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

Classes from root package not available during ScriptEvents::PRE_AUTOLOAD_DUMP plugin event #9530

Closed
WyriHaximus opened this issue Nov 28, 2020 · 6 comments
Labels
Milestone

Comments

@WyriHaximus
Copy link
Contributor

My composer.json:

Please see a reproducable set up at: https://github.com/WyriHaximus/composer-plugin-reproc

Output of composer diagnose:

Checking composer.json: WARNING
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com oauth access: OK
Checking disk free space: OK
Checking pubkeys: 
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 2.0.7
PHP version: 7.4.7 - Package overridden via config.platform, actual: 7.4.12
PHP binary path: /usr/bin/php7.4
OpenSSL version: OpenSSL 1.1.1g  21 Apr 2020
cURL version: 7.68.0 libz 1.2.11 ssl OpenSSL/1.1.1g
zip extension: not loaded

When I run this command:

composer install

I get the following output:


Reading ./composer.json                                                                                                                                                                                    
Loading config file /home/wyrihaximus/.config/composer/config.json                                                                                                                                         
Loading config file /home/wyrihaximus/.config/composer/auth.json                                                                                                                                           
Loading config file ./composer.json                                                                                                                                                                        
Checked CA file /etc/ssl/certs/ca-certificates.crt: valid                                                                                                                                                  
Executing command (/home/wyrihaximus/Projects/WyriHaximus/composer-plugin-reproc/package): git branch -a --no-color --no-abbrev -v                                                                         
Reading /home/wyrihaximus/.config/composer/composer.json                                                                                                                                                   
Loading config file /home/wyrihaximus/.config/composer/config.json                                                                                                                                         
Loading config file /home/wyrihaximus/.config/composer/auth.json                                                                                                                                           
Loading config file /home/wyrihaximus/.config/composer/composer.json                                                                                                                                       
Loading config file /home/wyrihaximus/.config/composer/auth.json                                                                                                                                           
Reading /home/wyrihaximus/.config/composer/auth.json                                                                                                                                                       
Reading /home/wyrihaximus/.config/composer/vendor/composer/installed.json                                                                                                                                  
Running 2.0.7 (2020-11-13 17:31:06) with PHP 7.4.12 on Linux / 5.4.0-53-generic                                                                                                                            
Reading ./composer.lock                                                                                                                                                                                    
Installing dependencies from lock file (including require-dev)                                                                                                                                             
Verifying lock file contents can be installed on current platform.                                                                                                                                         
Reading ./composer.lock                                                                                                                                                                                    
Generating rules                                                                                                                                                                                           
Resolving dependencies through SAT                                                                                                                                                                         
Looking at all rules.                                                                                                                                                                                      
                                                                                                                                                                                                           
Dependency resolution completed in 0.000 seconds                                                                                                                                                           
Package operations: 1 install, 0 updates, 0 removals                                                                                                                                                       
Installs: fake/dependency:dev-main                                                                                                                                                                         
  - Installing fake/dependency (dev-main): Symlinking from ../dependency                                                                                                                                   
Loading plugin Fake\Dependency\Composer\Installer                                                                                                                                                          
Generating autoload files                                                                                                                                                                                  
> pre-autoload-dump: Fake\Dependency\Composer\Installer->handleEvent                                                                                                                                       
Fake\Dependency\SomeOtherClass                                                                                                                                                                             
PHP Fatal error:  Uncaught Error: Class 'Fake\Package\SomeClass' not found in /home/wyrihaximus/Projects/WyriHaximus/composer-plugin-reproc/dependency/src/Composer/Installer.php:48                       
Stack trace:                                                                                                                                                                                               
#0 [internal function]: Fake\Dependency\Composer\Installer::handleEvent()                                                                                                                                  
#1 phar:///usr/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(173): call_user_func()                                                                                                        
#2 phar:///usr/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(101): Composer\EventDispatcher\EventDispatcher->doDispatch()                                                                  
#3 phar:///usr/bin/composer/src/Composer/Autoload/AutoloadGenerator.php(148): Composer\EventDispatcher\EventDispatcher->dispatchScript()                                                                   
#4 phar:///usr/bin/composer/src/Composer/Installer.php(314): Composer\Autoload\AutoloadGenerator->dump()                                                                                                   
#5 phar:///usr/bin/composer/src/Composer/Command/InstallCommand.php(131): Composer\Installer->run()                                                                                                        
#6 phar:///usr/bin/composer/vendor/symfony/console/Command/Command.php(245): Composer\Command\InstallCommand->execute()                                                                                    
#7 phar:///usr/bin/composer/vendor/symfony/console/Application.php(835): S in /home/wyrihaximus/Projects/WyriHaximus/composer-plugin-reproc/dependency/src/Composer/Installer.php on line 48               
                                                                                                                                                                                                           
Fatal error: Uncaught Error: Class 'Fake\Package\SomeClass' not found in /home/wyrihaximus/Projects/WyriHaximus/composer-plugin-reproc/dependency/src/Composer/Installer.php:48                            
Stack trace:                                                                                                                                                                                               
#0 [internal function]: Fake\Dependency\Composer\Installer::handleEvent()                                                                                                                                  
#1 phar:///usr/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(173): call_user_func()                                                                                                        
#2 phar:///usr/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(101): Composer\EventDispatcher\EventDispatcher->doDispatch()                                                                  
#3 phar:///usr/bin/composer/src/Composer/Autoload/AutoloadGenerator.php(148): Composer\EventDispatcher\EventDispatcher->dispatchScript()                                                                   
#4 phar:///usr/bin/composer/src/Composer/Installer.php(314): Composer\Autoload\AutoloadGenerator->dump()
#5 phar:///usr/bin/composer/src/Composer/Command/InstallCommand.php(131): Composer\Installer->run()
#6 phar:///usr/bin/composer/vendor/symfony/console/Command/Command.php(245): Composer\Command\InstallCommand->execute()
#7 phar:///usr/bin/composer/vendor/symfony/console/Application.php(835): S in /home/wyrihaximus/Projects/WyriHaximus/composer-plugin-reproc/dependency/src/Composer/Installer.php on line 48

And I expected this to happen:


Reading ./composer.json                                                                                                                                                                                    
Loading config file /home/wyrihaximus/.config/composer/config.json                                                                                                                                         
Loading config file /home/wyrihaximus/.config/composer/auth.json                                                                                                                                           
Loading config file ./composer.json                                                                                                                                                                        
Checked CA file /etc/ssl/certs/ca-certificates.crt: valid                                                                                                                                                  
Executing command (/home/wyrihaximus/Projects/WyriHaximus/composer-plugin-reproc/package): git branch -a --no-color --no-abbrev -v                                                                         
Reading /home/wyrihaximus/.config/composer/composer.json                                                                                                                                                   
Loading config file /home/wyrihaximus/.config/composer/config.json                                                                                                                                         
Loading config file /home/wyrihaximus/.config/composer/auth.json                                                                                                                                           
Loading config file /home/wyrihaximus/.config/composer/composer.json                                                                                                                                       
Loading config file /home/wyrihaximus/.config/composer/auth.json                                                                                                                                           
Reading /home/wyrihaximus/.config/composer/auth.json                                                                                                                                                       
Reading /home/wyrihaximus/.config/composer/vendor/composer/installed.json                                                                                                                                  
Running 2.0.7 (2020-11-13 17:31:06) with PHP 7.4.12 on Linux / 5.4.0-53-generic                                                                                                                            
Reading ./composer.lock                                                                                                                                                                                    
Installing dependencies from lock file (including require-dev)                                                                                                                                             
Verifying lock file contents can be installed on current platform.                                                                                                                                         
Reading ./composer.lock                                                                                                                                                                                    
Generating rules                                                                                                                                                                                           
Resolving dependencies through SAT                                                                                                                                                                         
Looking at all rules.                                                                                                                                                                                      
                                                                                                                                                                                                           
Dependency resolution completed in 0.000 seconds                                                                                                                                                           
Package operations: 1 install, 0 updates, 0 removals                                                                                                                                                       
Installs: fake/dependency:dev-main                                                                                                                                                                         
  - Installing fake/dependency (dev-main): Symlinking from ../dependency                                                                                                                                   
Loading plugin Fake\Dependency\Composer\Installer                                                                                                                                                          
Generating autoload files                                                                                                                                                                                  
> pre-autoload-dump: Fake\Dependency\Composer\Installer->handleEvent                                                                                                                                       
Fake\Dependency\SomeOtherClass                                                                                                                                                                             
Fake\Package\SomeClass                                                                                                                                                                             
@WyriHaximus
Copy link
Contributor Author

The goal I'm trying achieve is to generate classes and have those included in the (optimized) autoloader before the autoloader is dumped. And I know it kinda sounds funny because I'm expecting the autoloader to be available before it is dumped, but assuming this is not the first run everything runs smoothly, except for any classes in the root package not being available.

If this isn't reasonable to expect from composer that's fine by me, I'm trying to create the best DX for uses of packages using this construction.

@Seldaek Seldaek added the Bug label Dec 3, 2020
@Seldaek Seldaek added this to the 2.0 milestone Dec 3, 2020
Seldaek added a commit that referenced this issue Jan 12, 2021
@Seldaek
Copy link
Member

Seldaek commented Jan 12, 2021

94076c0 fixes it for the cases where the plugin requires the root package, as plugin dependencies are autoloaded. This was an edge case which we did not cover correctly.

If you need autoloading of the root package even tho the plugin does not require it, please explain why.

@WyriHaximus
Copy link
Contributor Author

94076c0 fixes it for the cases where the plugin requires the root package, as plugin dependencies are autoloaded. This was an edge case which we did not cover correctly.

Awesome work 👍 !

If you need autoloading of the root package even tho the plugin does not require it, please explain why.

I'm getting annotations from the root package with the plugin and generating compiled code based on that. Possibly I can look at a different way of reading those annotations without the need for autoloading to do this.

@Seldaek
Copy link
Member

Seldaek commented Jan 13, 2021

Hm ok, it doesn't sound completely unreasonable to me to make the root package classes always autoloadable during plugin execution. @naderman any objection to this?

@naderman
Copy link
Member

@Seldaek Seems fine to me!

@WyriHaximus
Copy link
Contributor Author

Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants