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

Support Composer v2 #488

Closed
jakzal opened this issue Oct 28, 2020 · 20 comments
Closed

Support Composer v2 #488

jakzal opened this issue Oct 28, 2020 · 20 comments
Labels

Comments

@jakzal
Copy link

jakzal commented Oct 28, 2020

Feature Request

Currently, phars created by box with Composer 2 are broken.

Example box configuration: https://github.com/jakzal/toolbox/blob/master/box.json.dist

Trying to execute the phar throws a fatal error:

PHP Fatal error:  Uncaught Error: Class '_HumbugBoxa72d156a3837\Symfony\Component\Console\Application' not found in phar:///Users/kuba/Projects/toolbox/build/toolbox.phar/src/Cli/Application.php:16
Stack trace:
#0 phar:///Users/kuba/Projects/toolbox/build/toolbox.phar/vendor/composer/ClassLoader.php(444): include()
#1 phar:///Users/kuba/Projects/toolbox/build/toolbox.phar/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile('phar:///Users/k...')
#2 [internal function]: Composer\Autoload\ClassLoader->loadClass('_HumbugBoxa72d1...')
#3 phar:///Users/kuba/Projects/toolbox/build/toolbox.phar/bin/toolbox.php(6): spl_autoload_call('_HumbugBoxa72d1...')
#4 /Users/kuba/Projects/toolbox/build/toolbox.phar(12): require('phar:///Users/k...')
#5 {main}
  thrown in phar:///Users/kuba/Projects/toolbox/build/toolbox.phar/src/Cli/Application.php on line 16

There are some differences in Composer autoload files between v1 and v2.

Composer 1, autoload_psr4.php:

return array(
    '_HumbugBox359b8a3155dc\\Zalas\\Toolbox\\' => array($baseDir . '/src'),
    '_HumbugBox359b8a3155dc\\Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'),
    '_HumbugBox359b8a3155dc\\Symfony\\Polyfill\\Php73\\' => array($vendorDir . '/symfony/polyfill-php73'),
    '_HumbugBox359b8a3155dc\\Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
    '_HumbugBox359b8a3155dc\\Symfony\\Contracts\\Service\\' => array($vendorDir . '/symfony/service-contracts'),
    '_HumbugBox359b8a3155dc\\Symfony\\Component\\Console\\' => array($vendorDir . '/symfony/console'),
    '_HumbugBox359b8a3155dc\\Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
);

Composer 2, autoload_psr4.php:

return array(
    '_HumbugBoxa72d156a3837\\Zalas\\Toolbox\\' => array($baseDir . '/src'),
    'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'),
    'Symfony\\Polyfill\\Php73\\' => array($vendorDir . '/symfony/polyfill-php73'),
    'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
    'Symfony\\Contracts\\Service\\' => array($vendorDir . '/symfony/service-contracts'),
    'Symfony\\Component\\Console\\' => array($vendorDir . '/symfony/console'),
    'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
);

Similar differences can be found in autoload_static.php.

@smoench
Copy link
Contributor

smoench commented Oct 28, 2020

I think this has already been fixed on master #467. A new release might be needed

@jakzal
Copy link
Author

jakzal commented Oct 28, 2020

@smoench oh, that's great!

@theofidry
Copy link
Member

@smoench @villfa did a lot of work regarding the composer2 & PHP8 support. IIRC we are waiting on a few dependencies to be able to release php-scoper & box

@villfa
Copy link
Contributor

villfa commented Oct 29, 2020

@theofidry regarding Composer 2 box is ready. We just need a new release.

@theofidry
Copy link
Member

https://github.com/box-project/box/releases/tag/3.9.0 is out then! Thanks a lot again @villfa for all of this work 👏

jakzal added a commit to jakzal/toolbox that referenced this issue Oct 29, 2020
@jakzal
Copy link
Author

jakzal commented Oct 29, 2020

@theofidry phar is missing from the release

@owenvoke
Copy link
Contributor

@jakzal, Yeah, it looks like Travis failed the deployment. 🤔

https://travis-ci.org/github/box-project/box/builds/739857907

@villfa
Copy link
Contributor

villfa commented Oct 29, 2020

The build passed before for the same commit: https://travis-ci.org/github/box-project/box/builds/731398066
I think it fails now because of a change in a dependency :/

@smoench
Copy link
Contributor

smoench commented Oct 29, 2020

Was there a reason not to commit the composer.lock-file? I'm just wondering as this is a project not library (IMHO). I mean it works so far for deptrac ;-)

@smoench
Copy link
Contributor

smoench commented Oct 29, 2020

Here is the diff about dependencies changes:

3c3
< - Installing opis/closure (3.5.7)
---
> - Installing opis/closure (3.6.0)
13c13
< - Installing paragonie/random_compat (v9.99.99)
---
> - Installing paragonie/random_compat (v9.99.100)
18c18
< - Installing composer/semver (3.2.1)
---
> - Installing composer/semver (3.2.2)
20c20
< - Installing composer/xdebug-handler (1.4.3)
---
> - Installing composer/xdebug-handler (1.4.4)
34,36c34,36
< - Installing symfony/finder (v4.4.14)
< - Installing symfony/polyfill-ctype (v1.18.1)
< - Installing symfony/filesystem (v4.4.14)
---
> - Installing symfony/finder (v4.4.16)
> - Installing symfony/polyfill-ctype (v1.20.0)
> - Installing symfony/filesystem (v4.4.16)
39,42c39,42
< - Installing symfony/polyfill-php80 (v1.18.1)
< - Installing symfony/polyfill-php73 (v1.18.1)
< - Installing symfony/polyfill-mbstring (v1.18.1)
< - Installing symfony/console (v4.4.14)
---
> - Installing symfony/polyfill-php80 (v1.20.0)
> - Installing symfony/polyfill-php73 (v1.20.0)
> - Installing symfony/polyfill-mbstring (v1.20.0)
> - Installing symfony/console (v4.4.16)
45c45
< - Installing humbug/php-scoper (0.13.5)
---
> - Installing humbug/php-scoper (0.13.7)
49,51c49,51
< - Installing symfony/process (v4.4.14)
< - Installing symfony/polyfill-php72 (v1.18.1)
< - Installing symfony/var-dumper (v4.4.14)
---
> - Installing symfony/process (v4.4.16)
> - Installing symfony/polyfill-php72 (v1.20.0)
> - Installing symfony/var-dumper (v4.4.16)
82c82
< - Installing symfony/phpunit-bridge (v5.1.6)
---
> - Installing symfony/phpunit-bridge (v5.1.8)

@theofidry
Copy link
Member

I'm just wondering as this is a project not library (IMHO). I mean it works so far for deptrac ;-)

It is a library if you install it via Composer but for a PHAR this is an application deployed in a read-only environment. Otherwise you might end up with 2 PHARs with different dependencies depending on when you built it

@theofidry
Copy link
Member

Hm actually the composer.lock was removed at some point I kinda missed that, it should be added back IMO

@greg0ire
Copy link

greg0ire commented Oct 30, 2020

It was removed in 0f73bd5 , deliberately since that is mentioned in the commit message. The corresponding PR is #414

@theofidry
Copy link
Member

I don't think it makes sense, I probably left it out by mistake and didn't realize the issue as I was editing the PR comment

@villfa
Copy link
Contributor

villfa commented Oct 30, 2020

Here is the diff about dependencies changes:
[...]

I think this is related to php-scoper.

Compare the error below with this: https://github.com/humbug/php-scoper/pull/417/files#diff-6a469b93b8c29a7e5511acffc3aefee95a6c16a38b40de71564b6e562b9a23ab

1) KevinGH\Box\Composer\ComposerOrchestratorTest::test_it_can_dump_the_autoloader_with_an_empty_composer_json with data set #3 (Humbug\PhpScoper\Whitelist Object (...), '_Box', '<?php\n\n// @generated by Hum...der;\n')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
 
 // Aliases for the whitelisted classes. For more information see:
 // https://github.com/humbug/php-scoper/blob/master/README.md#class-whitelisting
-if (!class_exists('Acme\Foo', false)) {
-    class_exists('_Box\Acme\Foo');
+if (!class_exists('Acme\Foo', false) && !interface_exists('Acme\Foo', false) && !trait_exists('Acme\Foo', false)) {
+    spl_autoload_call('_Box\Acme\Foo');
 }

jakzal added a commit to jakzal/toolbox that referenced this issue Nov 4, 2020
@sidz
Copy link

sidz commented Nov 9, 2020

It still doesn't work for me @villfa, @theofidry even on 3.9.0. (composer 2.0.6)

<?php

// autoload_psr4.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    '_HumbugBoxea186d538c5e\\Infection\\' => array($baseDir . '/src'),
    'Webmozart\\PathUtil\\' => array($vendorDir . '/webmozart/path-util/src'),
    'Webmozart\\Assert\\' => array($vendorDir . '/webmozart/assert/src'),
    'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'),
    'Symfony\\Polyfill\\Php73\\' => array($vendorDir . '/symfony/polyfill-php73'),
    'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
    'Symfony\\Polyfill\\Intl\\Normalizer\\' => array($vendorDir . '/symfony/polyfill-intl-normalizer'),
    'Symfony\\Polyfill\\Intl\\Grapheme\\' => array($vendorDir . '/symfony/polyfill-intl-grapheme'),
    'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'),
    'Symfony\\Contracts\\Service\\' => array($vendorDir . '/symfony/service-contracts'),
    'Symfony\\Component\\String\\' => array($vendorDir . '/symfony/string'),
    'Symfony\\Component\\Process\\' => array($vendorDir . '/symfony/process'),
    'Symfony\\Component\\Finder\\' => array($vendorDir . '/symfony/finder'),
    'Symfony\\Component\\Filesystem\\' => array($vendorDir . '/symfony/filesystem'),
    'Symfony\\Component\\Console\\' => array($vendorDir . '/symfony/console'),
    'Seld\\JsonLint\\' => array($vendorDir . '/seld/jsonlint/src/Seld/JsonLint'),
    'Safe\\' => array($vendorDir . '/thecodingmachine/safe/lib', $vendorDir . '/thecodingmachine/safe/deprecated', $vendorDir . '/thecodingmachine/safe/generated'),
    'Psr\\Log\\' => array($vendorDir . '/psr/log/Psr/Log'),
    'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
    'Pipeline\\' => array($vendorDir . '/sanmai/pipeline/src'),
    'PhpParser\\' => array($vendorDir . '/nikic/php-parser/lib/PhpParser'),
    'PackageVersions\\' => array($vendorDir . '/composer/package-versions-deprecated/src/PackageVersions'),
    'OndraM\\CiDetector\\' => array($vendorDir . '/ondram/ci-detector/src'),
    'JsonSchema\\' => array($vendorDir . '/justinrainbow/json-schema/src/JsonSchema'),
    'Infection\\StreamWrapper\\' => array($vendorDir . '/infection/include-interceptor/src'),
    'Infection\\AbstractTestFramework\\' => array($vendorDir . '/infection/abstract-testframework-adapter/src'),
    'Composer\\XdebugHandler\\' => array($vendorDir . '/composer/xdebug-handler/src'),
);

How can I help to debug this issue?

@smoench
Copy link
Contributor

smoench commented Nov 11, 2020

@sidz the latest phar file has an old php-scoper version included which has no composer v2 support. #499 will fix this.

@villfa
Copy link
Contributor

villfa commented Nov 11, 2020

@sidz the latest phar file has an old php-scoper version included which has no composer v2 support.

This is right and related to #490: the phar manually uploaded with the 0.13.9 release doesn't contain php-scoper 0.13.5 as it should.
There is no need for a fix though, the phar just need to be regenerated.

@smoench
Copy link
Contributor

smoench commented Nov 17, 2020

A new release https://github.com/box-project/box/releases/tag/3.9.1 has been published with composer v2 support 🤞

@jakzal
Copy link
Author

jakzal commented Nov 18, 2020

I can confirm the problem is gone now 👍

Thanks everyone 🍻

@jakzal jakzal closed this as completed Nov 18, 2020
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

7 participants