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

Another attempt to add Compiler + upgrade to PHPStan 0.12 #2373

Merged
merged 12 commits into from Dec 9, 2019
Merged

Conversation

@TomasVotruba
Copy link
Member

TomasVotruba commented Nov 30, 2019

  • Reference #177 - still needs lot of testing in the wild
  • Closes #2385

Inspiration

@TomasVotruba TomasVotruba mentioned this pull request Nov 30, 2019
18 of 28 tasks complete
@TomasVotruba

This comment has been minimized.

Copy link
Member Author

TomasVotruba commented Nov 30, 2019

Fuckups

Symfony not phar friend for excluded in PSR-4 autodiscovery

 services:
     Rector\TypeDeclaration\:
         resource: '../src'
         exclude:
-         	- '../src/ValueObject/SpecificFile.php'
+         	- '../src/ValueObject/*'

✔️

Symfony autodsicovery hates slash

 services:
     Rector\TypeDeclaration\:
-        resource: '../src/'
+        resource: '../src'

✔️

SHA1 cannot be verified

  • Error: atal error: Uncaught PharException: phar "/home/travis/build/rectorphp/rector/compiler/build/box.phar" SHA1 signature could not be verified: broken signature in /home/travis/build/rectorphp/rector/compiler/build/box.phar on line 14
  • Possible bug: lf/crlf line endings on push to githbu
  • Solution?
    • download new phar first: https://github.com/humbug/box/tree/3.8.3
    • .gitattibutes and keep original line-endings of the file
    • THEN commit, because git will change line endings on first file appearance only

Solution remove this from .gitattributes:

-# Set default behavior, in case users don't have core.autocrlf set.
-* text=auto
-* text eol=lf

✔️

Box is not compatible with multipes bins

Before:

  • bin/rector
  • bin/autoload.php
  • bin/container.php

Why? To separate logic to standalone functions by file.

Now:

  • bin/rector

With strict typed classes written on the bottom of file and used above.

✔️

@TomasVotruba

This comment has been minimized.

Copy link
Member Author

TomasVotruba commented Nov 30, 2019

~~Fuckup post is comming :D ~~

Done: How to Box Symfony App to PHAR without Killing Yourself

@TomasVotruba TomasVotruba force-pushed the compiler branch 8 times, most recently from 709e2d5 to c0d4598 Dec 1, 2019
@TomasVotruba TomasVotruba force-pushed the compiler branch 6 times, most recently from 8441a32 to 3b917e6 Dec 1, 2019
@gnutix

This comment has been minimized.

Copy link
Collaborator

gnutix commented Dec 5, 2019

Hey @TomasVotruba ! Just discovered this PR, awesome work! :D Is it already testable somehow ? I've cd ~/dev/oss/rector && git fetch && git checkout compiler && cd compiler && bin/compile, which gave me tmp/rector.phar.

Now when I cd into our project and run php ~/dev/oss/rector/tmp/rector.phar, it gives :

PHP Fatal error:  Uncaught _HumbugBox24440d0b0be5\Nette\FileNotFoundException: File '/composer/vendor/phpstan/phpstan-symfony/extension.neon' is missing or is not readable. in phar:///home/gnutix/dev/oss/rector/tmp/rector.phar/vendor/nette/di/src/DI/Config/Loader.php:29
Stack trace:
#0 phar:///home/gnutix/dev/oss/rector/tmp/rector.phar/vendor/nette/di/src/DI/Config/Loader.php(43): _HumbugBox24440d0b0be5\Nette\DI\Config\Loader->load('/composer/vendo...', false)
#1 phar:///home/gnutix/dev/oss/rector/tmp/rector.phar/vendor/nette/di/src/DI/Compiler.php(98): _HumbugBox24440d0b0be5\Nette\DI\Config\Loader->load('/home/gnutix/de...', false)
#2 phar:///home/gnutix/dev/oss/rector/tmp/rector.phar/vendor/nette/bootstrap/src/Bootstrap/Configurator.php(186): _HumbugBox24440d0b0be5\Nette\DI\Compiler->loadConfig('/home/gnutix/de...', Object(_HumbugBox24440d0b0be5\Nette\DI\Config\Loader))
#3 phar:///home/gnutix/dev/oss/rector/tmp/rector.phar/vendor/nette/di/src/DI/ContainerLoader.php(101): _HumbugBox24440d0b0be5\Nette\Configurator->generateCon in phar:///home/gnutix/dev/oss/rector/tmp/rector.phar/vendor/nette/di/src/DI/Config/Loader.php on line 29

Fatal error: Uncaught _HumbugBox24440d0b0be5\Nette\FileNotFoundException: File '/composer/vendor/phpstan/phpstan-symfony/extension.neon' is missing or is not readable. in phar:///home/gnutix/dev/oss/rector/tmp/rector.phar/vendor/nette/di/src/DI/Config/Loader.php:29
Stack trace:
#0 phar:///home/gnutix/dev/oss/rector/tmp/rector.phar/vendor/nette/di/src/DI/Config/Loader.php(43): _HumbugBox24440d0b0be5\Nette\DI\Config\Loader->load('/composer/vendo...', false)
#1 phar:///home/gnutix/dev/oss/rector/tmp/rector.phar/vendor/nette/di/src/DI/Compiler.php(98): _HumbugBox24440d0b0be5\Nette\DI\Config\Loader->load('/home/gnutix/de...', false)
#2 phar:///home/gnutix/dev/oss/rector/tmp/rector.phar/vendor/nette/bootstrap/src/Bootstrap/Configurator.php(186): _HumbugBox24440d0b0be5\Nette\DI\Compiler->loadConfig('/home/gnutix/de...', Object(_HumbugBox24440d0b0be5\Nette\DI\Config\Loader))
#3 phar:///home/gnutix/dev/oss/rector/tmp/rector.phar/vendor/nette/di/src/DI/ContainerLoader.php(101): _HumbugBox24440d0b0be5\Nette\Configurator->generateCon in phar:///home/gnutix/dev/oss/rector/tmp/rector.phar/vendor/nette/di/src/DI/Config/Loader.php on line 29

We use PHPStan (0.11, not updated to 0.12 yet) inside a Docker container (because of PHP 7.2 clash), and we load extensions with "internal" paths (in the container) like so :

# phpstan.neon
includes:
    # These paths are within the Docker container
    - '/composer/vendor/phpstan/phpstan-symfony/extension.neon'
    - '/composer/vendor/phpstan/phpstan-phpunit/extension.neon'
    - '/composer/vendor/phpstan/phpstan-doctrine/extension.neon'
    - '/composer/vendor/phpstan/phpstan-webmozart-assert/extension.neon'
    - '/composer/vendor/jangregor/phpstan-prophecy/src/extension.neon'

I guess that's the culprit ? I can't use PHPStan 0.12 as a phar, because installation requires "nikic/php-parser": "^4.3.0" which conflicts with my project requiring "ocramius/generated-hydrator": "^2.2" (as ^3.0 only supports PHP 7.3), itself only supporting nikic/php-parser: ~2.0|~3.0. So am I stuck until I can upgrade our project to PHP 7.3+ ?

@TomasVotruba

This comment has been minimized.

Copy link
Member Author

TomasVotruba commented Dec 5, 2019

Check Travis job, there is steps to test it.
I know it fails on autoloader, but your issue should be fixed

@gnutix

This comment has been minimized.

Copy link
Collaborator

gnutix commented Dec 5, 2019

I'm not really sure what you mean I'm supposed to look at inside .travis.yml : it contains tons of stuff, I'm a bit lost. What do you mean by "your issue should be fixed" ? (I'm using the latest compiler branch version... is there another, more up-to-date ? This branch hasn't been merged yet, right ?)

@escopecz

This comment has been minimized.

Copy link
Contributor

escopecz commented Dec 5, 2019

@gnutix check these lines: https://github.com/rectorphp/rector/pull/2373/files#diff-354f30a63fb0907d4ad57269548329e3R39-R49

To sum them up, the phar is being built automatically and the result is in the https://github.com/rectorphp/rector-prefixed repo. However, there are still issues with the final phar as Tomas noted.

@gnutix

This comment has been minimized.

Copy link
Collaborator

gnutix commented Dec 5, 2019

Thanks @escopecz. I've downloaded the .phar from rectorphp/rector-prefixed, same error because of PHPStan's extension within the Docker image. Should I create a separate issue about this ?

@escopecz

This comment has been minimized.

Copy link
Contributor

escopecz commented Dec 5, 2019

That's odd. I'm getting ".phar://rector.phar/vendor/autoload.php", "phar://rector.phar/../../../vendor/autoload.phpHave you ran "composer update"? when I run that. Anyway, I don't think it makes sense to create new issues about features that haven't been merged to the core yet. Let's just help Tomas to get it working.

@TomasVotruba

This comment has been minimized.

Copy link
Member Author

TomasVotruba commented Dec 5, 2019

@gnutix These lines are used to build phar:

https://github.com/rectorphp/rector/pull/2373/files#diff-354f30a63fb0907d4ad57269548329e3R27-R31

Any help with fixing/testing is appreciated

@TomasVotruba TomasVotruba force-pushed the compiler branch 3 times, most recently from 278ca13 to 5463ca8 Dec 8, 2019
@TomasVotruba TomasVotruba force-pushed the compiler branch 3 times, most recently from 0ebcd9e to 55d8de0 Dec 8, 2019
@TomasVotruba TomasVotruba changed the title Another attempt to add Compiler Another attempt to add Compiler + upgrade to PHPStan 0.12 Dec 8, 2019
@TomasVotruba TomasVotruba force-pushed the compiler branch from 47c9eb3 to 9075363 Dec 8, 2019
@TomasVotruba TomasVotruba force-pushed the compiler branch from ac00919 to e4e73b3 Dec 9, 2019
@TomasVotruba

This comment has been minimized.

Copy link
Member Author

TomasVotruba commented Dec 9, 2019

Still not 100 % stable, but good enought to 🚢 it and test it in the wil.
Let's roll 👍

Thank you all for feedback and testing so far, much appreciated

@TomasVotruba TomasVotruba merged commit 08eb92d into master Dec 9, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@TomasVotruba TomasVotruba deleted the compiler branch Dec 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.