forked from swoole/swoole-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsync-source-code.php
137 lines (115 loc) · 4.22 KB
/
sync-source-code.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
declare(strict_types=1);
$project_dir = __DIR__;
$php_version_tag = trim(file_get_contents(__DIR__ . '/sapi/PHP-VERSION.conf'));
$sync_dest_dir = $project_dir . '/var/sync-source-code-tmp/';
# command
# php sync-source-code.php --action run
$action = 'dry_run';
$longopts = array(
"action:"
);
$options = getopt('', $longopts);
if (!empty($options['action']) && $options['action'] == 'run') {
$action = 'run';
$sync_dest_dir = $project_dir;
}
$php_source_folder = $project_dir . "/var/php-{$php_version_tag}";
$php_file = $project_dir . "/pool/lib/php-{$php_version_tag}.tar.gz";
$download_dir = dirname($php_file);
`test -d {$sync_dest_dir} || mkdir -p {$sync_dest_dir}`;
$cmd = "curl -L https://github.com/php/php-src/archive/refs/tags/php-{$php_version_tag}.tar.gz -o {$php_file}";
echo $cmd . PHP_EOL;
if (!file_exists($php_file)) {
`test -d {$download_dir} || mkdir -p {$download_dir}`;
`{$cmd}`;
}
# tar -zxvf 文件名.tar.gz --strip-components=1 -C 指定解压目录
$cmd = <<<EOF
test -d {$php_source_folder} && rm -rf {$php_source_folder}
mkdir -p {$php_source_folder}
tar -zxvf {$php_file} --strip-components=1 -C {$php_source_folder}
EOF;
$cmd .= PHP_EOL . <<<EOF
SRC={$php_source_folder}
# 默认同步到测试验证目录:
# 正式同步,请执行命令: php sync-source-code.php --action run
cd {$sync_dest_dir}
EOF;
$cmd .= PHP_EOL . <<<'EOF'
echo "sync"
# ZendVM
cp -r $SRC/Zend ./
# Extension
cp -r $SRC/ext/bcmath/ ./ext
cp -r $SRC/ext/bz2/ ./ext
cp -r $SRC/ext/calendar/ ./ext
cp -r $SRC/ext/ctype/ ./ext
cp -r $SRC/ext/curl/ ./ext
cp -r $SRC/ext/date/ ./ext
cp -r $SRC/ext/dom/ ./ext
cp -r $SRC/ext/exif/ ./ext
cp -r $SRC/ext/fileinfo/ ./ext
cp -r $SRC/ext/filter/ ./ext
cp -r $SRC/ext/gd/ ./ext
cp -r $SRC/ext/gettext/ ./ext
cp -r $SRC/ext/gmp/ ./ext
cp -r $SRC/ext/hash/ ./ext
cp -r $SRC/ext/iconv/ ./ext
cp -r $SRC/ext/intl/ ./ext
cp -r $SRC/ext/json/ ./ext
cp -r $SRC/ext/libxml/ ./ext
cp -r $SRC/ext/mbstring/ ./ext
cp -r $SRC/ext/mysqli/ ./ext
cp -r $SRC/ext/mysqlnd/ ./ext
cp -r $SRC/ext/opcache/ ./ext
sed -i.backup 's/ext_shared=yes/ext_shared=no/g' ext/opcache/config.m4 && sed -i.backup 's/shared,,/$ext_shared,,/g' ext/opcache/config.m4
echo '#include "php.h"\n\nextern zend_module_entry opcache_module_entry;\n#define phpext_opcache_ptr &opcache_module_entry\n' > ext/opcache/php_opcache.h
cp -r $SRC/ext/openssl/ ./ext
cp -r $SRC/ext/pcntl/ ./ext
cp -r $SRC/ext/pcre/ ./ext
cp -r $SRC/ext/pdo/ ./ext
cp -r $SRC/ext/pdo_mysql/ ./ext
cp -r $SRC/ext/phar/ ./ext
echo '\n#include "sapi/cli/sfx/hook_stream.h"' >> ext/phar/phar_internal.h
cp -r $SRC/ext/posix/ ./ext
cp -r $SRC/ext/readline/ ./ext
cp -r $SRC/ext/reflection/ ./ext
cp -r $SRC/ext/session/ ./ext
cp -r $SRC/ext/simplexml/ ./ext
cp -r $SRC/ext/soap/ ./ext
cp -r $SRC/ext/sockets/ ./ext
cp -r $SRC/ext/sodium/ ./ext
cp -r $SRC/ext/spl/ ./ext
cp -r $SRC/ext/sqlite3/ ./ext
cp -r $SRC/ext/standard/ ./ext
cp -r $SRC/ext/sysvshm/ ./ext
cp -r $SRC/ext/tokenizer/ ./ext
cp -r $SRC/ext/xml/ ./ext
cp -r $SRC/ext/xmlreader/ ./ext
cp -r $SRC/ext/xmlwriter/ ./ext
cp -r $SRC/ext/xsl/ ./ext
cp -r $SRC/ext/zip/ ./ext
cp -r $SRC/ext/zlib/ ./ext
# main
cp -r $SRC/main ./
sed -i.backup 's/\/\* start Zend extensions \*\//\/\* start Zend extensions \*\/\n#ifdef PHP_ENABLE_OPCACHE\n\textern zend_extension zend_extension_entry;\n\tzend_register_extension(\&zend_extension_entry, NULL);\n#endif/g' main/main.c
# build
cp -r $SRC/build ./
# TSRM
cp -r ./TSRM/TSRM.h main/TSRM.h
cp -r $SRC/configure.ac ./
# fpm
cp -r $SRC/sapi/fpm/fpm ./sapi/cli
sed 's/int main(int argc, char *argv[])/int fpm_main(int argc, char *argv[])/g' ./sapi/cli/fpm/main.c
sed 's/{'-', 0, NULL}/{'P', 0, "fpm"},\n {'-', 0, NULL}/g' ./sapi/cli/fpm/main.c
exit 0
# cli
cp -r $SRC/sapi/cli/ps_title.c ./sapi/cli
cp -r $SRC/sapi/cli/generate_mime_type_map.php ./sapi/cli
cp -r $SRC/sapi/cli/php.1.in ./sapi/cli
EOF;
echo $cmd . PHP_EOL;
`$cmd`;
echo PHP_EOL;
echo "action : " . $action . ' done !' . PHP_EOL;