From 22fef8c51a807975863b8e60d557e7c768cb3784 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 5 Nov 2020 14:55:06 +0100 Subject: [PATCH] Make sure no files are missing from the phar, fixes #9421 --- src/Composer/Compiler.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Composer/Compiler.php b/src/Composer/Compiler.php index f9f98fa32..846daa4e0 100644 --- a/src/Composer/Compiler.php +++ b/src/Composer/Compiler.php @@ -111,6 +111,7 @@ class Compiler $finder->files() ->ignoreVCS(true) ->notPath('/\/(composer\.(json|lock)|[A-Z]+\.md|\.gitignore|phpunit\.xml\.dist|phpstan\.neon\.dist|phpstan-config\.neon)$/') + ->notPath('/bin\/(jsonlint|validate-json)(\.bat)?$/') ->notPath('symfony/debug/Resources/ext/') ->notPath('justinrainbow/json-schema/demo/') ->notPath('justinrainbow/json-schema/dist/') @@ -119,7 +120,6 @@ class Compiler ->exclude('Tests') ->exclude('tests') ->exclude('docs') - ->exclude('bin') ->in(__DIR__.'/../../vendor/') ->sort($finderSort) ; @@ -131,10 +131,13 @@ class Compiler realpath(__DIR__ . '/../../vendor/symfony/console/Resources/bin/hiddeninput.exe'), realpath(__DIR__ . '/../../vendor/symfony/polyfill-mbstring/Resources/mb_convert_variables.php8'), ); + $unexpectedFiles = array(); foreach ($finder as $file) { - if (!preg_match('{(/LICENSE|\.php)$}', $file) && !in_array(realpath($file), $extraFiles, true)) { - throw new \RuntimeException('Unexpected file should be added to the allow or deny lists: '.$file); + if (in_array(realpath($file), $extraFiles, true)) { + unset($extraFiles[array_search(realpath($file), $extraFiles, true)]); + } elseif (!preg_match('{(/LICENSE|\.php)$}', $file)) { + $unexpectedFiles[] = (string) $file; } if (preg_match('{\.php[\d.]*$}', $file)) { @@ -144,6 +147,13 @@ class Compiler } } + if ($extraFiles) { + throw new \RuntimeException('These files were expected but not added to the phar, they might be excluded or gone from the source package:'.PHP_EOL.implode(PHP_EOL, $extraFiles)); + } + if ($unexpectedFiles) { + throw new \RuntimeException('These files were unexpectedly added to the phar, make sure they are excluded or listed in $extraFiles:'.PHP_EOL.implode(PHP_EOL, $unexpectedFiles)); + } + // Add bin/composer $this->addComposerBin($phar);