mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 12:54:52 +08:00
Add packing placeholder
This commit is contained in:
parent
147fd396cf
commit
9f7a7a5703
@ -350,7 +350,27 @@ abstract class LibraryBase
|
|||||||
|
|
||||||
protected function install(): void
|
protected function install(): void
|
||||||
{
|
{
|
||||||
// do something after extracting pre-built files, default do nothing. overwrite this method to do something
|
// replace placeholders if BUILD_ROOT_PATH/.spc-extract-placeholder.json exists
|
||||||
|
$placeholder_file = BUILD_ROOT_PATH . '/.spc-extract-placeholder.json';
|
||||||
|
if (!file_exists($placeholder_file)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$placeholder = json_decode(file_get_contents($placeholder_file), true);
|
||||||
|
if (!is_array($placeholder)) {
|
||||||
|
throw new RuntimeException('Invalid placeholder file: ' . $placeholder_file);
|
||||||
|
}
|
||||||
|
$placeholder = get_pack_placehoder();
|
||||||
|
// replace placeholders in BUILD_ROOT_PATH
|
||||||
|
foreach ($placeholder as $item) {
|
||||||
|
$filepath = BUILD_ROOT_PATH . "/{$item}";
|
||||||
|
FileSystem::replaceFileStr(
|
||||||
|
$filepath,
|
||||||
|
array_values($placeholder),
|
||||||
|
array_keys($placeholder),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// remove placeholder file
|
||||||
|
unlink($placeholder_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -17,6 +17,7 @@ trait icu
|
|||||||
|
|
||||||
protected function install(): void
|
protected function install(): void
|
||||||
{
|
{
|
||||||
|
parent::install();
|
||||||
$icu_config = BUILD_ROOT_PATH . '/bin/icu-config';
|
$icu_config = BUILD_ROOT_PATH . '/bin/icu-config';
|
||||||
FileSystem::replaceFileStr($icu_config, '{BUILD_ROOT_PATH}', BUILD_ROOT_PATH);
|
FileSystem::replaceFileStr($icu_config, '{BUILD_ROOT_PATH}', BUILD_ROOT_PATH);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,6 +68,7 @@ trait libevent
|
|||||||
|
|
||||||
protected function install(): void
|
protected function install(): void
|
||||||
{
|
{
|
||||||
|
parent::install();
|
||||||
FileSystem::replaceFileStr(
|
FileSystem::replaceFileStr(
|
||||||
BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake',
|
BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake',
|
||||||
'{BUILD_ROOT_PATH}',
|
'{BUILD_ROOT_PATH}',
|
||||||
|
|||||||
@ -51,6 +51,10 @@ class PackLibCommand extends BuildCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$origin_files = [];
|
||||||
|
// get pack placehoder defines
|
||||||
|
$placehoder = get_pack_placehoder();
|
||||||
|
|
||||||
foreach ($builder->getLibs() as $lib) {
|
foreach ($builder->getLibs() as $lib) {
|
||||||
if ($lib->getName() !== $lib_name) {
|
if ($lib->getName() !== $lib_name) {
|
||||||
// other dependencies: install or build, both ok
|
// other dependencies: install or build, both ok
|
||||||
@ -73,6 +77,27 @@ class PackLibCommand extends BuildCommand
|
|||||||
// After build: load buildroot/ directory, and calculate increase files
|
// After build: load buildroot/ directory, and calculate increase files
|
||||||
$after_buildroot = FileSystem::scanDirFiles(BUILD_ROOT_PATH, relative: true);
|
$after_buildroot = FileSystem::scanDirFiles(BUILD_ROOT_PATH, relative: true);
|
||||||
$increase_files = array_diff($after_buildroot, $before_buildroot);
|
$increase_files = array_diff($after_buildroot, $before_buildroot);
|
||||||
|
|
||||||
|
// patch pkg-config and la files with absolute path
|
||||||
|
foreach ($increase_files as $file) {
|
||||||
|
if (str_ends_with($file, '.pc') || str_ends_with($file, '.la')) {
|
||||||
|
$content = FileSystem::readFile(BUILD_ROOT_PATH . '/' . $file);
|
||||||
|
$origin_files[$file] = $content;
|
||||||
|
// replace relative paths with absolute paths
|
||||||
|
$content = str_replace(
|
||||||
|
array_keys($placehoder),
|
||||||
|
array_values($placehoder),
|
||||||
|
$content
|
||||||
|
);
|
||||||
|
FileSystem::writeFile(BUILD_ROOT_PATH . '/' . $file, $content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add .spc-extract-placeholder.json in BUILD_ROOT_PATH
|
||||||
|
$placeholder_file = BUILD_ROOT_PATH . '/.spc-extract-placeholder.json';
|
||||||
|
file_put_contents($placeholder_file, json_encode(array_keys($origin_files), JSON_PRETTY_PRINT));
|
||||||
|
$increase_files[] = '.spc-extract-placeholder.json';
|
||||||
|
|
||||||
// every file mapped with BUILD_ROOT_PATH
|
// every file mapped with BUILD_ROOT_PATH
|
||||||
// get BUILD_ROOT_PATH last dir part
|
// get BUILD_ROOT_PATH last dir part
|
||||||
$buildroot_part = basename(BUILD_ROOT_PATH);
|
$buildroot_part = basename(BUILD_ROOT_PATH);
|
||||||
@ -94,6 +119,16 @@ class PackLibCommand extends BuildCommand
|
|||||||
$filename = WORKING_DIR . '/dist/' . $filename;
|
$filename = WORKING_DIR . '/dist/' . $filename;
|
||||||
f_passthru("tar {$tar_option} {$filename} -T " . WORKING_DIR . '/packlib_files.txt');
|
f_passthru("tar {$tar_option} {$filename} -T " . WORKING_DIR . '/packlib_files.txt');
|
||||||
logger()->info('Pack library ' . $lib->getName() . ' to ' . $filename . ' complete.');
|
logger()->info('Pack library ' . $lib->getName() . ' to ' . $filename . ' complete.');
|
||||||
|
|
||||||
|
// remove temp files
|
||||||
|
unlink($placeholder_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($origin_files as $file => $content) {
|
||||||
|
// restore original files
|
||||||
|
if (file_exists(BUILD_ROOT_PATH . '/' . $file)) {
|
||||||
|
FileSystem::writeFile(BUILD_ROOT_PATH . '/' . $file, $content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -232,3 +232,13 @@ function ac_with_args(string $arg_name, bool $use_value = false): array
|
|||||||
{
|
{
|
||||||
return $use_value ? ["--with-{$arg_name}=yes", "--with-{$arg_name}=no"] : ["--with-{$arg_name}", "--without-{$arg_name}"];
|
return $use_value ? ["--with-{$arg_name}=yes", "--with-{$arg_name}=no"] : ["--with-{$arg_name}", "--without-{$arg_name}"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_pack_placehoder(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
BUILD_LIB_PATH => '@build_lib_path@',
|
||||||
|
BUILD_BIN_PATH => '@build_bin_path@',
|
||||||
|
BUILD_INCLUDE_PATH => '@build_include_path@',
|
||||||
|
BUILD_ROOT_PATH => '@build_root_path@',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user