Skip to content

Commit 84dcfe9

Browse files
committed
使用PIE 下载扩展
1 parent b21c622 commit 84dcfe9

File tree

12 files changed

+99
-25
lines changed

12 files changed

+99
-25
lines changed

.github/workflows/linux-aarch64.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
mkdir -p bin/
9696
mkdir -p runtime/
9797
test -f runtime/php && rm -f runtime/php
98-
if [ ! -f runtime/php/php ] ; then
98+
if [ ! -f runtime/php/pie ] ; then
9999
bash setup-php-runtime.sh
100100
fi
101101
bash sapi/download-box/download-box-get-archive-from-server.sh

.github/workflows/linux-glibc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
mkdir -p bin/
8686
mkdir -p runtime/
8787
test -f runtime/php && rm -f runtime/php
88-
if [ ! -f runtime/php/php ] ; then
88+
if [ ! -f runtime/php/pie ] ; then
8989
bash setup-php-runtime.sh
9090
fi
9191
bash sapi/download-box/download-box-get-archive-from-server.sh
@@ -99,7 +99,7 @@ jobs:
9999
composer install --no-interaction --no-autoloader --no-scripts --profile
100100
composer dump-autoload --optimize --profile
101101
102-
php prepare.php --with-libavif
102+
php prepare.php --with-libavif --without-docker
103103
104104
sudo apt update
105105
bash ./sapi/scripts/install-deps-on-ubuntu.sh

.github/workflows/linux-x86_64.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
mkdir -p bin/
9696
mkdir -p runtime/
9797
test -f runtime/php && rm -f runtime/php
98-
if [ ! -f runtime/php/php ] ; then
98+
if [ ! -f runtime/php/pie ] ; then
9999
bash setup-php-runtime.sh
100100
fi
101101
bash sapi/download-box/download-box-get-archive-from-server.sh

.github/workflows/macos-aarch64.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
mkdir -p bin/
9191
mkdir -p runtime/
9292
test -f runtime/php && rm -f runtime/php
93-
if [ ! -f runtime/php/php ] ; then
93+
if [ ! -f runtime/php/pie ] ; then
9494
bash setup-php-runtime.sh
9595
fi
9696
bash sapi/download-box/download-box-get-archive-from-server.sh

.github/workflows/macos-x86_64.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
mkdir -p bin/
9191
mkdir -p runtime/
9292
test -f runtime/php && rm -f runtime/php
93-
if [ ! -f runtime/php/php ] ; then
93+
if [ ! -f runtime/php/pie ] ; then
9494
bash setup-php-runtime.sh
9595
fi
9696
bash sapi/download-box/download-box-get-archive-from-server.sh

.github/workflows/windows-msys2.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ jobs:
4747
- name: prepare build environment
4848
shell: msys2 {0}
4949
run: |
50-
bash ./sapi/quickstart/windows/msys2-build/install-msys2.sh
50+
bash sapi/quickstart/windows/msys2-build/install-msys2.sh
51+
bash sapi/download-box/download-box-get-archive-from-server.sh
5152
5253
- name: install deps lib with source code
5354
shell: msys2 {0}

prepare.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727

2828
// Download swoole-src
2929
if (!is_dir(__DIR__ . '/ext/swoole')) {
30-
shell_exec(__DIR__ . '/sapi/scripts/download-swoole-src-archive.sh');
30+
//shell_exec(__DIR__ . '/sapi/scripts/download-swoole-src-archive.sh');
3131
}
3232

3333
// Compile directly on the host machine, not in the docker container
34-
if ($p->getInputOption('without-docker') || ($p->isMacos())) {
34+
if ($p->getInputOption('without-docker') || ($p->isMacos()) || ($p->isLinux() && (!is_file('/.dockerenv')))) {
3535
$p->setWorkDir(__DIR__);
3636
$p->setBuildDir(__DIR__ . '/thirdparty');
3737
}
@@ -46,7 +46,12 @@
4646

4747
if ($p->isMacos()) {
4848
$p->setExtraLdflags('');
49-
$homebrew_prefix = trim(shell_exec('brew --prefix'));
49+
exec("brew --prefix 2>&1", $output, $result_code);
50+
if ($result_code == 0) {
51+
$homebrew_prefix = trim(implode(' ', $output));
52+
} else {
53+
$homebrew_prefix = "";
54+
}
5055
$p->withBinPath($homebrew_prefix . '/opt/flex/bin')
5156
->withBinPath($homebrew_prefix . '/opt/bison/bin')
5257
->withBinPath($homebrew_prefix . '/opt/libtool/bin')

sapi/SWOOLE-VERSION.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v6.1.3
1+
v6.1.6

sapi/src/Extension.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class Extension extends Project
77
public string $options = '';
88
public string $peclVersion = '';
99

10+
public string $pieVersion = '';
11+
public string $pieName = '';
12+
1013
public array $dependentExtensions = [];
1114

1215
public function withOptions(string $options): static
@@ -26,4 +29,17 @@ public function withDependentExtensions(string ...$extensions): static
2629
$this->dependentExtensions += $extensions;
2730
return $this;
2831
}
32+
33+
public function withPieVersion(string $pieVersion): static
34+
{
35+
$this->pieVersion = $pieVersion;
36+
return $this;
37+
}
38+
39+
public function withPieName(string $pieName): static
40+
{
41+
$this->pieName = $pieName;
42+
return $this;
43+
}
44+
2945
}

sapi/src/Preprocessor.php

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,46 @@ protected function downloadFile(string $url, string $file, ?object $project = nu
339339
}
340340
}
341341

342+
public function downloadFileWithPie(string $pieName, string $pieVersion, string $file, string $path, object $project): void
343+
{
344+
$workdir = $this->getWorkDir();
345+
$cmd = <<<EOF
346+
test -f {$workdir}/runtime/php/php && export PATH={$workdir}/runtime/php/:\$PATH ;
347+
export PIE_WORKING_DIRECTORY={$workdir}/var/ext/pie/
348+
test -d \$PIE_WORKING_DIRECTORY || mkdir -p \$PIE_WORKING_DIRECTORY ;
349+
cd {$workdir}/var/ext/
350+
TEMP_FILE=$(mktemp) && echo "TEMP_FILE: \${TEMP_FILE}" ;
351+
{ pie download {$pieName}:{$pieVersion} ; } > \${TEMP_FILE} 2>&1
352+
cat \${TEMP_FILE}
353+
SOURCE_CODE_DIR=\$(cat \${TEMP_FILE} | grep 'source to: ' | awk -F 'source to: ' '{ print $2 }')
354+
rm -f \${TEMP_FILE}
355+
echo "{$pieName}:{$pieVersion} source code: \${SOURCE_CODE_DIR}"
356+
pie info {$pieName}:{$pieVersion};
357+
cd \${SOURCE_CODE_DIR}
358+
tar -czf "{$workdir}/var/ext/{$file}" .
359+
cp -f {$workdir}/var/ext/{$file} {$path}
360+
cd {$workdir}
361+
EOF;
362+
echo $cmd;
363+
echo PHP_EOL;
364+
echo '------------RUNNING START-------------';
365+
echo PHP_EOL;
366+
echo `$cmd`;
367+
echo '------------RUNNING END-------------';
368+
echo PHP_EOL;
369+
$file = $path;
370+
// 下载失败
371+
if (!is_file($file) or filesize($file) == 0) {
372+
throw new Exception("with pie Downloading file[" . basename($file) . "] from failed");
373+
}
374+
// 下载文件的 hash 不一致
375+
if (!$this->skipHashVerify and $project->enableHashVerify) {
376+
if (!$project->hashVerify($file)) {
377+
throw new Exception("The {$project->hashAlgo} of downloaded file[$file] is inconsistent with the configuration");
378+
}
379+
}
380+
}
381+
342382
/**
343383
* @param Library $lib
344384
* @throws Exception
@@ -396,8 +436,10 @@ public function addLibrary(Library $lib): void
396436

397437
public function addExtension(Extension $ext): void
398438
{
399-
if ($ext->peclVersion) {
400-
$ext->file = $ext->name . '-' . $ext->peclVersion . '.tgz';
439+
if ($ext->peclVersion || $ext->pieVersion) {
440+
$extensionVersion = !empty($ext->peclVersion) ? $ext->peclVersion : $ext->pieVersion;
441+
$downloadType = $ext->peclVersion ? 'pecl' : 'pie';
442+
$ext->file = $ext->name . '-' . $extensionVersion . '.tgz';
401443
$ext->path = $this->extensionDir . '/' . $ext->file;
402444
$ext->url = "https://pecl.php.net/get/{$ext->file}";
403445

@@ -411,8 +453,14 @@ public function addExtension(Extension $ext): void
411453
}
412454
if (!$this->getInputOption('skip-download')) {
413455
if (!is_file($ext->path) or filesize($ext->path) === 0) {
414-
echo "[Extension] {$ext->file} not found, downloading: " . $ext->url . PHP_EOL;
415-
$this->downloadFile($ext->url, $ext->path, $ext);
456+
if ($downloadType === 'pecl') {
457+
echo "[Extension] {$ext->file} not found, downloading: " . $ext->url . PHP_EOL;
458+
$this->downloadFile($ext->url, $ext->path, $ext);
459+
} else {
460+
echo "[Extension] {$ext->file} not found, download with pie.phar " . $ext->homePage . PHP_EOL;
461+
$this->downloadFileWithPie($ext->pieName, $ext->pieVersion, $ext->file, $ext->path, $ext);
462+
}
463+
416464
} else {
417465
echo "[Extension] file cached: " . $ext->file . PHP_EOL;
418466
}

0 commit comments

Comments
 (0)