Add packing placeholder

This commit is contained in:
crazywhalecc
2025-07-23 11:52:25 +08:00
parent 147fd396cf
commit 9f7a7a5703
5 changed files with 68 additions and 1 deletions

View File

@@ -51,6 +51,10 @@ class PackLibCommand extends BuildCommand
}
}
$origin_files = [];
// get pack placehoder defines
$placehoder = get_pack_placehoder();
foreach ($builder->getLibs() as $lib) {
if ($lib->getName() !== $lib_name) {
// 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_buildroot = FileSystem::scanDirFiles(BUILD_ROOT_PATH, relative: true);
$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
// get BUILD_ROOT_PATH last dir part
$buildroot_part = basename(BUILD_ROOT_PATH);
@@ -94,6 +119,16 @@ class PackLibCommand extends BuildCommand
$filename = WORKING_DIR . '/dist/' . $filename;
f_passthru("tar {$tar_option} {$filename} -T " . WORKING_DIR . '/packlib_files.txt');
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);
}
}