Skip to content

Commit ab1dcdb

Browse files
committed
Allow installing php extensions from .tar.gz archives
1 parent 25a2829 commit ab1dcdb

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

php/docker/build-scripts/install-php-extensions

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,26 @@ function install_extension($name, $buildArgs = array()) {
6060
run(...$cmd);
6161
}
6262

63-
function install_pecl_extension(string $ext, string $name, string $version, string $priority, $buildArgs = array()) {
63+
function install_pecl_extension(string $ext, string $name, string $version, string $priority, $buildArgs = array(), $source = "") {
6464
global $dryRun;
6565
$cwd = getcwd();
66-
$extDir = pecl_temp_dir() . "/$ext";
66+
$peclTempDir = pecl_temp_dir();
67+
$extDir = $peclTempDir . "/$ext";
68+
$extArchive = $peclTempDir . DIRECTORY_SEPARATOR . basename($source);
6769

68-
run("pecl", "install", "--onlyreqdeps", "--nobuild", "$ext-$version");
70+
if ( ! is_dir( $peclTempDir ) ) {
71+
run("mkdir", $peclTempDir);
72+
}
73+
74+
if (empty($source)) {
75+
run("pecl", "install", "--onlyreqdeps", "--nobuild", "$ext-$version");
76+
} else {
77+
run("curl", "-sL", "-o", $extArchive, $source);
78+
if ( ! is_dir( $extDir ) ) {
79+
run("mkdir", $extDir);
80+
}
81+
run("tar", "-C", $extDir, "--strip-components=1", "-zxf", $extArchive);
82+
}
6983
changeDir($extDir);
7084
run("phpize");
7185
run("./configure", ...$buildArgs);
@@ -78,6 +92,7 @@ function install_pecl_extension(string $ext, string $name, string $version, stri
7892
function cleanup($buildDeps) {
7993
$libs = run('find', PHP_EXTENSION_DIR,'-type', 'f', '-name', '*.so');
8094
$pkgs = array();
95+
$peclTempDir = pecl_temp_dir();
8196

8297
$libFiles = array();
8398
foreach ( $libs as $lib ) {
@@ -101,6 +116,7 @@ function cleanup($buildDeps) {
101116

102117
run('apt-mark', 'manual', ...$pkgs);
103118
run('apt-get', 'autoremove', '-y', '--purge', ...$buildDeps);
119+
run('rm', '-rf', $peclTempDir);
104120
}
105121

106122
function main() {
@@ -152,7 +168,8 @@ function main() {
152168
$peclName = @$extension["pecl_name"] ?: $name;
153169
$peclVersion = @$extension["version"] ?: "stable";
154170
$priority = @$extension["priority"] ?: "50";
155-
install_pecl_extension($peclName, $name, $peclVersion, $priority, $buildArgs);
171+
$source = @$extension["src"] ?: "";
172+
install_pecl_extension($peclName, $name, $peclVersion, $priority, $buildArgs, $source);
156173
break;
157174
default:
158175
install_extension($name, $buildArgs);

0 commit comments

Comments
 (0)