From 50e29a5ed859aebc27ac4d70bc7c7af5090adc7d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 16 Nov 2020 18:54:07 +0000 Subject: [PATCH 1/8] build/make-server: bail when composer dev dependencies are installed these mess up the phar and make it extremely bloated. Almost everyone building for themselves unintentionally includes dev dependencies. --- build/server-phar.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build/server-phar.php b/build/server-phar.php index 3cc3a2c7c..90cf6aec0 100644 --- a/build/server-phar.php +++ b/build/server-phar.php @@ -41,6 +41,7 @@ use function rtrim; use function sprintf; use function str_replace; use function unlink; +use const PHP_EOL; require dirname(__DIR__) . '/vendor/autoload.php'; @@ -129,6 +130,10 @@ function main() : void{ echo "Set phar.readonly to 0 with -dphar.readonly=0" . PHP_EOL; exit(1); } + if(file_exists(dirname(__DIR__) . '/vendor/phpunit')){ + echo "Remove Composer dev dependencies before building (composer install --no-dev)" . PHP_EOL; + exit(1); + } $opts = getopt("", ["out:", "git:"]); if(isset($opts["git"])){ From 95dbb00d4c76482fafbbacdb9b5ccc4924cc3473 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 16 Nov 2020 18:55:23 +0000 Subject: [PATCH 2/8] Added custom composer commands: 'composer make-devtools' and 'composer make-server' --- composer.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/composer.json b/composer.json index ba96ded06..04ce4c5d5 100644 --- a/composer.json +++ b/composer.json @@ -62,5 +62,12 @@ "platform": { "php": "7.3.0" } + }, + "scripts": { + "make-devtools": "@php -dphar.readonly=0 tests/plugins/DevTools/src/DevTools/ConsoleScript.php --make tests/plugins/DevTools --out plugins/DevTools.phar", + "make-server": [ + "@composer install --no-dev --classmap-authoritative", + "@php -dphar.readonly=0 build/server-phar.php" + ] } } From 6e297168c2186ee183b6c415ff517f88e54b477c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 16 Nov 2020 19:00:12 +0000 Subject: [PATCH 3/8] travis.sh: use new composer commands --- tests/travis.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/travis.sh b/tests/travis.sh index 149c1896a..51a8beade 100755 --- a/tests/travis.sh +++ b/tests/travis.sh @@ -16,12 +16,12 @@ PLUGINS_DIR="$DATA_DIR/plugins" rm -rf "$DATA_DIR" rm PocketMine-MP.phar 2> /dev/null +mkdir "$DATA_DIR" +mkdir "$PLUGINS_DIR" -cd tests/plugins/DevTools -php -dphar.readonly=0 ./src/DevTools/ConsoleScript.php --make ./ --relative ./ --out ../../../DevTools.phar -cd ../../.. +composer make-devtools +composer make-server -php -dphar.readonly=0 ./build/server-phar.php ./PocketMine-MP.phar if [ -f PocketMine-MP.phar ]; then echo Server phar created successfully. else @@ -29,9 +29,6 @@ else exit 1 fi -mkdir "$DATA_DIR" -mkdir "$PLUGINS_DIR" -mv DevTools.phar "$PLUGINS_DIR" cp -r tests/plugins/TesterPlugin "$PLUGINS_DIR" echo -e "stop\n" | php PocketMine-MP.phar --no-wizard --disable-ansi --disable-readline --debug.level=2 --data="$DATA_DIR" --plugins="$PLUGINS_DIR" --anonymous-statistics.enabled=0 --settings.async-workers="$PM_WORKERS" --settings.enable-dev-builds=1 From db815360d104d876d6786e23c4caf7ca13acabe4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 16 Nov 2020 19:03:39 +0000 Subject: [PATCH 4/8] [ci skip] BUILDING.md: tell users to use 'composer make-server' instead of the server-phar script directly this takes care of the dev dependencies automatically. --- BUILDING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILDING.md b/BUILDING.md index 6853f5979..f84b83e35 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -30,7 +30,7 @@ If you use a custom binary, you'll need to replace `composer` usages in this gui Preprocessor requires that the `cpp` (c preprocessor) is available in your PATH. ## Building `PocketMine-MP.phar` -Run `build/server-phar.php` using your preferred PHP binary. It'll drop a `PocketMine-MP.phar` into the current working directory. +Run `composer make-server` using your preferred PHP binary. It'll drop a `PocketMine-MP.phar` into the current working directory. You can also use the `--out` option to change the output filename. From 691c49fb3239d250b95449832ee9d63530219f08 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 16 Nov 2020 19:05:04 +0000 Subject: [PATCH 5/8] I don't know how to pass custom arguments to these scripts :< --- tests/travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/travis.sh b/tests/travis.sh index 51a8beade..7df683ae7 100755 --- a/tests/travis.sh +++ b/tests/travis.sh @@ -19,7 +19,7 @@ rm PocketMine-MP.phar 2> /dev/null mkdir "$DATA_DIR" mkdir "$PLUGINS_DIR" -composer make-devtools +php -dphar.readonly=0 ./src/DevTools/ConsoleScript.php --make ./ --relative ./ --out ../../../plugins/DevTools.phar composer make-server if [ -f PocketMine-MP.phar ]; then From 46331df7db597a409eab398eef078f7add6804df Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 16 Nov 2020 19:06:56 +0000 Subject: [PATCH 6/8] fix build --- tests/travis.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/travis.sh b/tests/travis.sh index 7df683ae7..c5488d651 100755 --- a/tests/travis.sh +++ b/tests/travis.sh @@ -19,7 +19,9 @@ rm PocketMine-MP.phar 2> /dev/null mkdir "$DATA_DIR" mkdir "$PLUGINS_DIR" +cd tests/plugins/DevTools php -dphar.readonly=0 ./src/DevTools/ConsoleScript.php --make ./ --relative ./ --out ../../../plugins/DevTools.phar +cd ../../.. composer make-server if [ -f PocketMine-MP.phar ]; then From 6ea01e0dd41a6f6e2aa06a301952ef2903b8327b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 16 Nov 2020 19:21:44 +0000 Subject: [PATCH 7/8] fix build #2 --- tests/travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/travis.sh b/tests/travis.sh index c5488d651..6437aa7c3 100755 --- a/tests/travis.sh +++ b/tests/travis.sh @@ -20,7 +20,7 @@ mkdir "$DATA_DIR" mkdir "$PLUGINS_DIR" cd tests/plugins/DevTools -php -dphar.readonly=0 ./src/DevTools/ConsoleScript.php --make ./ --relative ./ --out ../../../plugins/DevTools.phar +php -dphar.readonly=0 ./src/DevTools/ConsoleScript.php --make ./ --relative ./ --out "$PLUGINS_DIR/DevTools.phar" cd ../../.. composer make-server From 9984b15de6b762d53d2aea721b506b4e6ae7b209 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 16 Nov 2020 19:25:13 +0000 Subject: [PATCH 8/8] fix build #3 --- tests/travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/travis.sh b/tests/travis.sh index 6437aa7c3..e16a28333 100755 --- a/tests/travis.sh +++ b/tests/travis.sh @@ -11,7 +11,7 @@ while getopts "t:" OPTION 2> /dev/null; do done #Run-the-server tests -DATA_DIR="test_data" +DATA_DIR="$(pwd)/test_data" PLUGINS_DIR="$DATA_DIR/plugins" rm -rf "$DATA_DIR"