-
Notifications
You must be signed in to change notification settings - Fork 657
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
vendor/ | ||
.DS_Store | ||
phpunit.xml | ||
composer.lock | ||
.php_cs.cache | ||
.php_cs | ||
.*.swp | ||
.*.swo | ||
/build/logs/ | ||
/build/ | ||
/vendor/ | ||
/.DS_Store | ||
/.php_cs.cache | ||
/.php_cs | ||
/.*.swp | ||
/.*.swo | ||
/composer.lock | ||
/phpunit.xml | ||
/vendor-bin/*/composer.lock | ||
/vendor-bin/*/vendor/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,6 @@ | ||
#!/usr/bin/env bash | ||
if ! php -r 'extension_loaded("bz2") or exit(1);' ; then | ||
echo "You need to install (or enable) bz2 php extension" | ||
exit 1 | ||
fi | ||
composer bin box install | ||
|
||
composer global require 'humbug/php-scoper:^1.0@dev' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this has been replaced by |
||
composer global require 'humbug/box:3.0.0-alpha.0' | ||
composer install --no-dev | ||
[ -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 commentThe 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 commentThe 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 commentThe 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 ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in Box now |
||
vendor/bin/box compile | ||
|
||
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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 755 build/psalm/psalm | ||
|
||
cp bin/phar.psalm.xml build/psalm/psalm.xml | ||
|
||
./build/psalm/psalm --config=build/psalm/psalm.xml --root=build/psalm | ||
|
||
php -d memory_limit=-1 -d phar.readonly=0 `which box` compile | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
|
||
# clean up build | ||
rm -Rf build/psalm | ||
|
||
# reinstall deps (to regenerate autoloader and bring back dev deps) | ||
rm -Rf vendor/* | ||
composer install | ||
build/psalm.phar --config=bin/phar.psalm.xml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,16 @@ | ||
{ | ||
"alias": "psalm.phar", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there shouldn't be a need for an alias unless you really want to refer to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this was just added for renaming in #595, but you fixed later. |
||
"base-path": "build/psalm", | ||
"main" : "./psalm", | ||
"output" : "../../build/psalm.phar", | ||
"directories" : [ | ||
"assets", | ||
"vendor" | ||
], | ||
"finder": [ | ||
{ | ||
"in" : "src" | ||
} | ||
], | ||
"files" : [ | ||
"config.xsd" | ||
"output" : "build/psalm.phar", | ||
"files": [ | ||
"src/command_functions.php", | ||
"src/psalm.php", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any reason why those files are not included in the autoload? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They're part of Psalm's command-line startup, and themselves handle autoloading |
||
"src/psalter.php" | ||
], | ||
"files-bin": ["config.xsd"], | ||
"directories-bin" : ["assets"], | ||
"intercept" : false, | ||
"compactors" : [], | ||
"compactors" : [ | ||
"KevinGH\\Box\\Compactor\\PhpScoper" | ||
], | ||
"chmod" : "0755", | ||
"shebang" : "#!/usr/bin/env php", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is already the default shebang |
||
"stub" : true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the default value already |
||
"compression": "GZ" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, definitely on purpose (because |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,6 @@ | ||
<?php | ||
|
||
use Isolated\Symfony\Component\Finder\Finder; | ||
|
||
return [ | ||
'finders' => [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this part (finding the files) is handled by Box |
||
Finder::create()->files()->in('src'), | ||
Finder::create()->files()->in('assets'), | ||
Finder::create() | ||
->files() | ||
->ignoreVCS(true) | ||
->notName('/LICENSE|.*\\.md|.*\\.dist|Makefile|composer\\.json|composer\\.lock/') | ||
->exclude([ | ||
'doc', | ||
'test', | ||
'test_old', | ||
'tests', | ||
'Tests', | ||
'vendor-bin', | ||
]) | ||
->in('vendor'), | ||
Finder::create()->append([ | ||
'composer.json', | ||
'composer.lock', | ||
'config.xsd', | ||
'psalm' | ||
]), | ||
], | ||
'whitelist' => [ | ||
|
||
], | ||
'patchers' => [ | ||
function ($filePath, $prefix, $contents) { | ||
// | ||
|
@@ -46,6 +18,13 @@ function ($filePath, $prefix, $contents) { | |
|
||
return $contents; | ||
}, | ||
function ($filePath, $prefix, $contents) { | ||
return str_replace( | ||
'\\'.$prefix.'\Composer\Autoload\ClassLoader', | ||
'\Composer\Autoload\ClassLoader', | ||
$contents | ||
); | ||
}, | ||
function ($filePath, $prefix, $contents) { | ||
if ($filePath === realpath(__DIR__ . '/src/Psalm/Config.php')) { | ||
return str_replace( | ||
|
@@ -136,4 +115,7 @@ function ($filePath, $prefix, $contents) { | |
return $contents; | ||
}, | ||
], | ||
'whitelist' => [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this whitelist is useless so could be removed |
||
\Composer\Autoload\ClassLoader::class, | ||
] | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"require": { | ||
"humbug/box": "dev-master" | ||
} | ||
} |
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