From 9ecbaab52fbcf153f8ca5942395be5f175ac7fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 8 Apr 2018 18:36:29 +0200 Subject: [PATCH 1/2] Simplify the PHAR build script --- .gitignore | 20 +++++++++++--------- bin/build-phar.sh | 32 +++----------------------------- box.json.dist | 21 +++++++++------------ composer.json | 3 ++- scoper.inc.php | 28 ---------------------------- vendor-bin/box/composer.json | 7 +++++++ 6 files changed, 32 insertions(+), 79 deletions(-) create mode 100644 vendor-bin/box/composer.json diff --git a/.gitignore b/.gitignore index 5ef76e560d7..1ca53917d24 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,11 @@ -vendor/ -.DS_Store -phpunit.xml -composer.lock -.php_cs.cache -.php_cs -.*.swp -.*.swo -/build/logs/ +/bin/psalm.phar +/vendor/ +/.DS_Store +/.php_cs.cache +/.php_cs +/.*.swp +/.*.swo +/composer.lock +/phpunit.xml +/vendor-bin/*/composer.lock +/vendor-bin/*/vendor/ diff --git a/bin/build-phar.sh b/bin/build-phar.sh index c1a50468df1..493f93a201a 100755 --- a/bin/build-phar.sh +++ b/bin/build-phar.sh @@ -4,34 +4,8 @@ if ! php -r 'extension_loaded("bz2") or exit(1);' ; then exit 1 fi -composer global require 'humbug/php-scoper:^1.0@dev' -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 +composer bin box install -rm -f bin/psalm.phar +vendor/bin/box compile -# Prefixes the code to be bundled -php -d memory_limit=-1 `which php-scoper` add-prefix --prefix='PsalmPhar' --output-dir=build/psalm --force - -# Re-dump the loader to account for the prefixing -# and optimize the loader -composer dump-autoload --working-dir=build/psalm --classmap-authoritative --no-dev - -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 - -# clean up build -rm -Rf build/psalm - -# reinstall deps (to regenerate autoloader and bring back dev deps) -rm -Rf vendor/* -composer install +bin/psalm.phar --config=bin/phar.psalm.xml --root=src diff --git a/box.json.dist b/box.json.dist index 227fbd1490f..1077461acde 100644 --- a/box.json.dist +++ b/box.json.dist @@ -1,23 +1,20 @@ { - "alias": "psalm.phar", - "base-path": "build/psalm", - "main" : "./psalm", - "output" : "../../build/psalm.phar", + "main" : "psalm", + "output" : "bin/psalm.phar", "directories" : [ "assets", + "src", "vendor" ], - "finder": [ - { - "in" : "src" - } - ], "files" : [ + "composer.json", + "composer.lock", "config.xsd" ], "intercept" : false, - "compactors" : [], + "compactors" : [ + "KevinGH\\Box\\Compactor\\PhpScoper" + ], "chmod" : "0755", - "shebang" : "#!/usr/bin/env php", - "stub" : true + "compression": "GZ" } diff --git a/composer.json b/composer.json index 72bc7f79da5..2c6d674c116 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,8 @@ "phpunit/phpunit": "^5.7.4", "friendsofphp/php-cs-fixer": "^2.3|^2.4|^2.5|^2.6|^2.7|^2.8|^2.9", "squizlabs/php_codesniffer": "^3.0", - "php-coveralls/php-coveralls": "^2.0" + "php-coveralls/php-coveralls": "^2.0", + "bamarni/composer-bin-plugin": "^1.2" }, "suggest": { "ext-igbinary": "^2.0.5" diff --git a/scoper.inc.php b/scoper.inc.php index c2891800cf0..677dae19b90 100644 --- a/scoper.inc.php +++ b/scoper.inc.php @@ -1,34 +1,6 @@ [ - 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) { // diff --git a/vendor-bin/box/composer.json b/vendor-bin/box/composer.json new file mode 100644 index 00000000000..52a61a8257b --- /dev/null +++ b/vendor-bin/box/composer.json @@ -0,0 +1,7 @@ +{ + "minimum-stability": "dev", + "prefer-stable": true, + "require": { + "humbug/box": "dev-master" + } +} From 2df9d2d94be150bc119686f2af2761d9c32b2929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 5 May 2018 01:43:43 +0100 Subject: [PATCH 2/2] Update Box --- .gitignore | 2 +- bin/build-phar.sh | 7 +------ box.json.dist | 18 +++++++----------- scoper.inc.php | 10 ++++++++++ 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 1ca53917d24..a44c25f7b2d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/bin/psalm.phar +/build/ /vendor/ /.DS_Store /.php_cs.cache diff --git a/bin/build-phar.sh b/bin/build-phar.sh index 493f93a201a..15dbaca2050 100755 --- a/bin/build-phar.sh +++ b/bin/build-phar.sh @@ -1,11 +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 vendor/bin/box compile -bin/psalm.phar --config=bin/phar.psalm.xml --root=src +build/psalm.phar --config=bin/phar.psalm.xml diff --git a/box.json.dist b/box.json.dist index 1077461acde..c927932ff62 100644 --- a/box.json.dist +++ b/box.json.dist @@ -1,16 +1,12 @@ { - "main" : "psalm", - "output" : "bin/psalm.phar", - "directories" : [ - "assets", - "src", - "vendor" - ], - "files" : [ - "composer.json", - "composer.lock", - "config.xsd" + "output" : "build/psalm.phar", + "files": [ + "src/command_functions.php", + "src/psalm.php", + "src/psalter.php" ], + "files-bin": ["config.xsd"], + "directories-bin" : ["assets"], "intercept" : false, "compactors" : [ "KevinGH\\Box\\Compactor\\PhpScoper" diff --git a/scoper.inc.php b/scoper.inc.php index 677dae19b90..dedd86dc95a 100644 --- a/scoper.inc.php +++ b/scoper.inc.php @@ -18,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( @@ -108,4 +115,7 @@ function ($filePath, $prefix, $contents) { return $contents; }, ], + 'whitelist' => [ + \Composer\Autoload\ClassLoader::class, + ] ];