Skip to content

Commit 987ad4b

Browse files
committed
Use diff to detect and deploy-patch new shared extensions that built with php
1 parent f4b03ae commit 987ad4b

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use SPC\exception\PatchException;
99
use SPC\exception\WrongUsageException;
1010
use SPC\store\Config;
11+
use SPC\store\DirDiff;
1112
use SPC\store\FileSystem;
1213
use SPC\store\SourcePatcher;
1314
use SPC\util\GlobalEnvManager;
@@ -270,6 +271,9 @@ protected function buildEmbed(): void
270271
return Config::getExt($ext->getName(), 'build-with-php') === true;
271272
});
272273
$install_modules = $sharedExts ? 'install-modules' : '';
274+
275+
// detect changes in module path
276+
$diff = new DirDiff(BUILD_MODULES_PATH, true);
273277
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
274278
$concurrency = getenv('SPC_CONCURRENCY') ? '-j' . getenv('SPC_CONCURRENCY') : '';
275279
shell()->cd(SOURCE_PATH . '/php-src')
@@ -286,6 +290,12 @@ protected function buildEmbed(): void
286290
$this->processLibphpSoFile($libphpSo);
287291
}
288292

293+
// process shared extensions build-with-php
294+
$increment_files = $diff->getChangedFiles();
295+
foreach ($increment_files as $increment_file) {
296+
$this->deployBinary($increment_file, $increment_file, false);
297+
}
298+
289299
// process libphp.a for static embed
290300
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'static') {
291301
$AR = getenv('AR') ?: 'ar';

src/SPC/builder/macos/MacOSBuilder.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use SPC\builder\unix\UnixBuilderBase;
99
use SPC\exception\WrongUsageException;
1010
use SPC\store\Config;
11+
use SPC\store\DirDiff;
1112
use SPC\store\FileSystem;
1213
use SPC\store\SourcePatcher;
1314
use SPC\util\GlobalEnvManager;
@@ -262,9 +263,25 @@ protected function buildEmbed(): void
262263
$install_modules = $sharedExts ? 'install-modules' : '';
263264
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
264265
$concurrency = getenv('SPC_CONCURRENCY') ? '-j' . getenv('SPC_CONCURRENCY') : '';
266+
267+
$diff = new DirDiff(BUILD_MODULES_PATH, true);
268+
265269
shell()->cd(SOURCE_PATH . '/php-src')
270+
->exec('sed -i "" "s|^EXTENSION_DIR = .*|EXTENSION_DIR = /' . basename(BUILD_MODULES_PATH) . '|" Makefile')
266271
->exec("make {$concurrency} INSTALL_ROOT=" . BUILD_ROOT_PATH . " {$vars} install-sapi {$install_modules} install-build install-headers install-programs");
267272

273+
$libphp = BUILD_LIB_PATH . '/libphp.dylib';
274+
if (file_exists($libphp)) {
275+
$this->deployBinary($libphp, $libphp, false);
276+
// macOS currently have no -release option for dylib, so we just rename it here
277+
}
278+
279+
// process shared extensions build-with-php
280+
$increment_files = $diff->getChangedFiles();
281+
foreach ($increment_files as $increment_file) {
282+
$this->deployBinary($increment_file, $increment_file, false);
283+
}
284+
268285
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'static') {
269286
$AR = getenv('AR') ?: 'ar';
270287
f_passthru("{$AR} -t " . BUILD_LIB_PATH . "/libphp.a | grep '\\.a$' | xargs -n1 {$AR} d " . BUILD_LIB_PATH . '/libphp.a');

src/SPC/builder/unix/UnixBuilderBase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ public function extractDebugInfo(string $binary_path): string
118118
*/
119119
public function deployBinary(string $src, string $dst, bool $executable = true): string
120120
{
121+
logger()->debug('Deploying binary from ' . $src . ' to ' . $dst);
122+
121123
// UPX for linux
122124
$upx_option = (bool) $this->getOption('with-upx-pack', false);
123125

0 commit comments

Comments
 (0)