-
Notifications
You must be signed in to change notification settings - Fork 664
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
Simplify the PHAR build script #656
Conversation
I can't get the Phar to build at all on my work machine (4-year-old Macbook Pro). I get OOM errors. |
I'll try to get it building on my home machine too, maybe a bad config somewhere. |
OOM errors? If possible it would be nice to get a details on them. I’m
trying to make so that box handle the config for you, for example setting
phar.readonly=0. So let’s not rush that PR I would like as much as possible
fix the real underlying issues :) as you already have a working PHAR and
build process, we can take our time for this.
…On Mon 9 Apr 2018 at 20:41, Matthew Brown ***@***.***> wrote:
I'll try to get it building on my home machine too, maybe a bad config
somewhere.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#656 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AE76gSvS6N4F4s0r8wQnXb5alCm597acks5tm7lWgaJpZM4TLm5H>
.
|
[ -d build ] || mkdir build | ||
[ -d build/psalm ] || mkdir build/psalm | ||
# increase FD limit, or Phar compression will fail | ||
ulimit -Sn 4096 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you encounter that failure or it was here for good measure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen that, when building psalm.phar including dev dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I can reproduce it:
$ cd psalm
$ git checkout c13fda4034b33eb859e8810b10b0322fca17b858
$ patch -p1 <<EOM
diff --git a/bin/build-phar.sh b/bin/build-phar.sh
index 1e05c796..7843dd05 100755
--- a/bin/build-phar.sh
+++ b/bin/build-phar.sh
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
composer global require humbug/box:dev-master
-composer install --no-dev
+composer install # --no-dev
[ -d build ] || mkdir build
-box build
+php -dphar.readonly=0 `which box` build
EOM
patching file bin/build-phar.sh
Hunk #1 succeeded at 1 with fuzz 2.
$ bin/build-phar.sh
[......snip......]
Box (repo)
// Loading the configuration file "/home/weirdan/src/psalm/box.json".
Building the PHAR "/home/weirdan/src/psalm/build/psalm.phar"
? Registering compactors
+ KevinGH\Box\Compactor\Php
? Adding main file: /home/weirdan/src/psalm/psalm
? Adding binary files
> No file found
? Adding files
> 4496 file(s)
? Generating new stub
- Using shebang line: #!/usr/bin/env php
- Using banner:
> Generated by Humbug Box.
>
> @link https://github.com/humbug/box
? Compressing with the algorithm "BZ2"
In Compile.php line 415:
unable to create temporary file
build [-c|--config CONFIG] [--debug] [-d|--working-dir WORKING-DIR]
[......snip......]
The box version is 3.0.0-alpha.0 ( f5eec71df2df3a2a1f39a50ba77e8bb4312fef51 )
ulimit -n is set to 1024
Phar version is 2.0.2
PHP version is 7.2.4-1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in Box now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bumped box and added some comments, ready for a first review :)
@@ -1,37 +1,6 @@ | |||
#!/usr/bin/env bash | |||
if ! php -r 'extension_loaded("bz2") or exit(1);' ; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is now handled in Box
|
||
composer global require 'humbug/php-scoper:^1.0@dev' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has been replaced by bamarni/composer-bin-plugin
, up to you if you're cool with that or you prefer the composer global
or maybe switch to a wget
the Box PHAR
[ -d build ] || mkdir build | ||
[ -d build/psalm ] || mkdir build/psalm | ||
# increase FD limit, or Phar compression will fail | ||
ulimit -Sn 4096 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in Box now
rm -f bin/psalm.phar | ||
|
||
# Prefixes the code to be bundled | ||
php -d memory_limit=-1 `which php-scoper` add-prefix --prefix='PsalmPhar' --output-dir=build/psalm --force |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the scoping is done via Box now, the only issue is humbug/php-scoper#178 so right now the prefix is really random
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the memory is also bumped by Box although the number is quite arbitrary so it may need more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deterministic prefix was on purpose to enable better cache re-use, but I don't really mind caches being busted between new phars.
|
||
# Re-dump the loader to account for the prefixing | ||
# and optimize the loader | ||
composer dump-autoload --working-dir=build/psalm --classmap-authoritative --no-dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
including only the non-dev files (and avoiding to scope the dev files) is done by Box
"chmod" : "0755", | ||
"shebang" : "#!/usr/bin/env php", | ||
"stub" : true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the default value already
"chmod" : "0755", | ||
"shebang" : "#!/usr/bin/env php", | ||
"stub" : true | ||
"compression": "GZ" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there was no compression, not sure if that was voluntary because you wanted to avoid your users to have the zlib
extension
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, definitely on purpose (because bzip
was causing issues for users without it). If 99% of PHP installs have zlib
, happy to use that.
return [ | ||
'finders' => [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part (finding the files) is handled by Box
@@ -136,4 +115,7 @@ function ($filePath, $prefix, $contents) { | |||
return $contents; | |||
}, | |||
], | |||
'whitelist' => [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this whitelist is useless so could be removed
src/psalm.php
Outdated
@@ -127,7 +127,7 @@ | |||
$options['r'] = $options['root']; | |||
} | |||
|
|||
$current_dir = (string)getcwd() . DIRECTORY_SEPARATOR; | |||
$current_dir = (string)getcwd(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure why we have the trailing /
. This was making fail the find autoloader since we ended up with //
in the path
@muglug in theory this should be ready. I think however some code changed and maybe the PHP-Scoper config needs to be updated. |
Updated and the builds are green. I may have missed them, but if they is no e2e tests for the PHAR I would recommend to add one (in another PR) |
Thanks a lot! |
I originally wanted to try if I was hitting a too many files open limit when compressing the PHAR. I cant' seem to reproduce it on my machine so I was looking for a real project where this was happening.
I did not hit the issue and simplified the build script:
The last step, running the
psalm.phar
PHAR does not work: I think I'm missing something obvious but can't figure out what.Also not if you wish to see the files added to the PHAR, e.g. to debug the PHP-Scoper effect, you can:
--debug
mode ofcompile
which is going to dump the files added to the PHAR a directory.box