Modular conversion

This commit is contained in:
Daniil Gentili 2019-12-26 19:47:24 +01:00
parent 97c1003e6b
commit b9f3acfaa6
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
8 changed files with 61 additions and 73 deletions

View File

@ -76,7 +76,6 @@
"@cs",
"@test"
],
"prepare-convert": "rm -rf tempConv && mkdir tempConv",
"test-php7": "tests/test-conversion.sh 70",
"test-php56": "tests/test-conversion.sh 5",
"cs": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --diff --dry-run",

20
tests/conversion/after-5.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
sed 's/^Loop::set.*;//g' -i vendor/amphp/amp/lib/Loop.php
echo 'Loop::set((new DriverFactory())->create());' >> vendor/amphp/amp/lib/Loop.php
cp $(dirname $0)/../random.php vendor/paragonie/random_compat/lib/random.php
cp vendor/danog/madelineproto/src/danog/MadelineProto/Coroutine.php vendor/amphp/amp/lib/Coroutine.php
sed 's/namespace danog\\MadelineProto;/namespace Amp;/g' -i vendor/amphp/amp/lib/Coroutine.php
sed 's/public static function echo/public static function echo_/g' -i vendor/danog/madelineproto/src/danog/MadelineProto/Tools.php
sed 's/use Kelunik\\Certificate\\Certificate/use Kelunik\Certificate\Certificate as _Certificate/g;s/new Certificate/new _Certificate/g;s/empty[(]\$metadata[)] [?] null : //g' -i vendor/amphp/socket/src/TlsInfo.php
echo "<?php
namespace League\Uri\Contracts;
interface UriException
{
}" > vendor/league/uri-interfaces/src/Contracts/UriException.php
find vendor/amphp -type f -name '*.php' -exec sed "s/extension_loaded[(]'zlib'[)]/false/g;s/new[(]/new_(/g;s/clone[(]/clone_(/g" -i {} +

4
tests/conversion/after-70.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
find vendor/danog/madelineproto -type f -name '*.php' -exec sed 's/: EncryptableSocket/: \\Amp\\Socket\\Socket/g' -i {} +

10
tests/conversion/prepare-5.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
rm -rf vendor/danog/madelineproto/docs
sed -re 's/\?(\w*) (\$\w+)/\2 = NULL/g;s/= null = null/=null/ig;s/: self//g' -i vendor/league/uri-interfaces/src/Contracts/UriInterface.php
while IFS= read -r line; do l=$(echo "$line" | sed 's/[(].*//g'); sed -i "s/$l.*/$line/g" vendor/league/uri/src/Uri.php; done <<< $(grep 'public function' vendor/league/uri-interfaces/src/Contracts/UriInterface.php | sed 's/;//g;s/: self//g')
sed -i 's/handleConnectionWindowIncrement[(]\$windowSize[)]/handleConnectionWindowIncrement(int $windowSize)/g' vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php
sed -ri 's/^\{/{ use \\MyCallableMaker;/g;s/\\Closure::fromCallable[(]\[(.+), (.+)\][)]/\1->callableFromInstanceMethod(\2)/g' vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php vendor/amphp/http-client/src/Connection/Http{2,1}Connection.php

View File

@ -0,0 +1 @@
prepare-5.sh

View File

@ -56,35 +56,15 @@ cd ..
[ -f $HOME/.composer/vendor/bin/php7to5 ] && php7to5=$HOME/.composer/vendor/bin/php7to5
[ -f $HOME/.config/composer/vendor/bin/php7to5 ] && php7to5=$HOME/.config/composer/vendor/bin/php7to5
sed -re 's/\?(\w*) (\$\w+)/\2 = NULL/g;s/= null = null/=null/ig;s/: self//g' -i phar7/vendor/league/uri-interfaces/src/Contracts/UriInterface.php
while IFS= read -r line; do l=$(echo "$line" | sed 's/[(].*//g'); sed -i "s/$l.*/$line/g" phar7/vendor/league/uri/src/Uri.php; done <<< $(grep 'public function' phar7/vendor/league/uri-interfaces/src/Contracts/UriInterface.php | sed 's/;//g;s/: self//g')
sed -i 's/handleConnectionWindowIncrement[(]\$windowSize[)]/handleConnectionWindowIncrement(int $windowSize)/g' phar7/vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php
sed -ri 's/^\{/{ use \\MyCallableMaker;/g;s/\\Closure::fromCallable[(]\[(.+), (.+)\][)]/\1->callableFromInstanceMethod(\2)/g' phar7/vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php phar7/vendor/amphp/http-client/src/Connection/Http{2,1}Connection.php
cd phar7
$madelinePath/tests/conversion/before-5.sh
cd ..
php7.3 $php7to5 convert --copy-all phar7 phar5 >/dev/null
sed 's/^Loop::set.*;//g' -i phar5/vendor/amphp/amp/lib/Loop.php
echo 'Loop::set((new DriverFactory())->create());' >> phar5/vendor/amphp/amp/lib/Loop.php
cp $madelinePath/tests/random.php phar5/vendor/paragonie/random_compat/lib/random.php
cp phar5/vendor/danog/madelineproto/src/danog/MadelineProto/Coroutine.php phar5/vendor/amphp/amp/lib/Coroutine.php
sed 's/namespace danog\\MadelineProto;/namespace Amp;/g' -i phar5/vendor/amphp/amp/lib/Coroutine.php
sed 's/public static function echo/public static function echo_/g' -i phar5/vendor/danog/madelineproto/src/danog/MadelineProto/Tools.php
find phar5/vendor/amphp -type f -name '*.php' -exec sed "s/extension_loaded[(]'zlib'[)]/false/g;s/new[(]/new_(/g;s/clone[(]/clone_(/g" -i {} +
find phar5/vendor/danog/madelineproto -type f -name '*.php' -exec sed 's/: EncryptableSocket/: \\Amp\\Socket\\Socket/g' -i {} +
sed 's/use Kelunik\\Certificate\\Certificate/use Kelunik\Certificate\Certificate as _Certificate/g;s/new Certificate/new _Certificate/g' -i phar5/vendor/amphp/socket/src/TlsInfo.php
echo "<?php
namespace League\Uri\Contracts;
interface UriException
{
}" > phar5/vendor/league/uri-interfaces/src/Contracts/UriException.php
cd phar5
$madelinePath/tests/conversion/after-5.sh
cd ..
php -v
@ -96,17 +76,16 @@ interface UriException
[ -f $HOME/.composer/vendor/bin/php7to70 ] && php7to70=$HOME/.composer/vendor/bin/php7to70
[ -f $HOME/.config/composer/vendor/bin/php7to70 ] && php7to70=$HOME/.config/composer/vendor/bin/php7to70
sed -re 's/\?(\w*) (\$\w+)/\2 = NULL/g;s/= null = null/=null/ig;s/: self//g' -i phar7/vendor/league/uri-interfaces/src/Contracts/UriInterface.php
while IFS= read -r line; do l=$(echo "$line" | sed 's/[(].*//g'); sed -i "s/$l.*/$line/g" phar7/vendor/league/uri/src/Uri.php; done <<< $(grep 'public function' phar7/vendor/league/uri-interfaces/src/Contracts/UriInterface.php | sed 's/;//g;s/: self//g')
cd phar7
$madelinePath/tests/conversion/before-70.sh
cd ..
sed -i 's/handleConnectionWindowIncrement[(]\$windowSize[)]/handleConnectionWindowIncrement(int $windowSize)/g' phar7/vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php
sed -ri 's/^\{/{ use \\MyCallableMaker;/g;s/\\Closure::fromCallable[(]\[(.+), (.+)\][)]/\1->callableFromInstanceMethod(\2)/g' phar7/vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php phar7/vendor/amphp/http-client/src/Connection/Http{2,1}Connection.php
$php7to70 convert --copy-all phar7 phar5 >/dev/null
find phar5/vendor/danog/madelineproto -type f -name '*.php' -exec sed 's/: EncryptableSocket/: \\Amp\\Socket\\Socket/g' -i {} +
cd phar5
$madelinePath/tests/conversion/after-70.sh
cd ..
php=70
} || {
cp -a phar7 phar5

View File

@ -2,9 +2,13 @@
madelinePath=$PWD
rm -rf /tmp/tempConv
mkdir /tmp/tempConv
cd /tmp/tempConv
tempDir=/tmp/tempConv$1
rm -rf $tempDir
mkdir $tempDir
cd $tempDir
pwd
echo '{
"name": "danog/madelineprototests",
@ -34,48 +38,19 @@ echo '{
}' > composer.json
composer update
rm -rf vendor/danog/madelineproto/docs
sed -re 's/\?(\w*) (\$\w+)/\2 = NULL/g;s/= null = null/=null/ig;s/: self//g' -i vendor/league/uri-interfaces/src/Contracts/UriInterface.php
while IFS= read -r line; do l=$(echo "$line" | sed 's/[(].*//g'); sed -i "s/$l.*/$line/g" vendor/league/uri/src/Uri.php; done <<< $(grep 'public function' vendor/league/uri-interfaces/src/Contracts/UriInterface.php | sed 's/;//g;s/: self//g')
sed -i 's/handleConnectionWindowIncrement[(]\$windowSize[)]/handleConnectionWindowIncrement(int $windowSize)/g' vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php
sed -ri 's/^\{/{ use \\MyCallableMaker;/g;s/\\Closure::fromCallable[(]\[(.+), (.+)\][)]/\1->callableFromInstanceMethod(\2)/g' vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php vendor/amphp/http-client/src/Connection/Http{2,1}Connection.php
$madelinePath/tests/conversion/prepare-$1.sh
$madelinePath/vendor/bin/php7to$1 convert --copy-all vendor newVendor
rm -rf vendor
mv newVendor vendor
[ $1 -eq 5 ] && {
sed 's/^Loop::set.*;//g' -i vendor/amphp/amp/lib/Loop.php
echo 'Loop::set((new DriverFactory())->create());' >> vendor/amphp/amp/lib/Loop.php
cp $madelinePath/tests/random.php vendor/paragonie/random_compat/lib/random.php
cp vendor/danog/madelineproto/src/danog/MadelineProto/Coroutine.php vendor/amphp/amp/lib/Coroutine.php
sed 's/namespace danog\\MadelineProto;/namespace Amp;/g' -i vendor/amphp/amp/lib/Coroutine.php
sed 's/public static function echo/public static function echo_/g' -i vendor/danog/madelineproto/src/danog/MadelineProto/Tools.php
sed 's/use Kelunik\\Certificate\\Certificate/use Kelunik\Certificate\Certificate as _Certificate/g;s/new Certificate/new _Certificate/g;s/empty[(]\$metadata[)] [?] null : //g' -i vendor/amphp/socket/src/TlsInfo.php
echo "<?php
namespace League\Uri\Contracts;
interface UriException
{
}" > vendor/league/uri-interfaces/src/Contracts/UriException.php
}
find vendor/amphp -type f -name '*.php' -exec sed "s/extension_loaded[(]'zlib'[)]/false/g;s/new[(]/new_(/g;s/clone[(]/clone_(/g" -i {} +
find vendor/danog/madelineproto -type f -name '*.php' -exec sed 's/: EncryptableSocket/: \\Amp\\Socket\\Socket/g' -i {} +
$madelinePath/tests/conversion/after-$1.sh
composer dumpautoload --optimize
cd $madelinePath
if [ $1 -eq 5 ];then
php5.6 tests/testing.php
php5.6 tests/testing.php $1
else
php7.0 tests/testing.php
php7.0 tests/testing.php $1
fi

View File

@ -27,9 +27,9 @@ if (!\file_exists(__DIR__.'/../vendor/autoload.php')) {
}
include 'madeline.php';
}
} elseif (\file_exists('/tmp/tempConv/vendor/autoload.php')) {
} elseif (isset($argv[1]) && \file_exists("/tmp/tempConv{$argv[1]}/vendor/autoload.php")) {
\define('TESTING_VERSIONS', 1);
$loader = require_once('/tmp/tempConv/vendor/autoload.php');
$loader = require_once("/tmp/tempConv{$argv[1]}/vendor/autoload.php");
} else {
require_once 'vendor/autoload.php';
}