@@ -51,6 +51,10 @@ public function handle(): int
5151 }
5252 }
5353
54+ $ origin_files = [];
55+ // get pack placehoder defines
56+ $ placehoder = get_pack_placehoder ();
57+
5458 foreach ($ builder ->getLibs () as $ lib ) {
5559 if ($ lib ->getName () !== $ lib_name ) {
5660 // other dependencies: install or build, both ok
@@ -73,6 +77,27 @@ public function handle(): int
7377 // After build: load buildroot/ directory, and calculate increase files
7478 $ after_buildroot = FileSystem::scanDirFiles (BUILD_ROOT_PATH , relative: true );
7579 $ increase_files = array_diff ($ after_buildroot , $ before_buildroot );
80+
81+ // patch pkg-config and la files with absolute path
82+ foreach ($ increase_files as $ file ) {
83+ if (str_ends_with ($ file , '.pc ' ) || str_ends_with ($ file , '.la ' )) {
84+ $ content = FileSystem::readFile (BUILD_ROOT_PATH . '/ ' . $ file );
85+ $ origin_files [$ file ] = $ content ;
86+ // replace relative paths with absolute paths
87+ $ content = str_replace (
88+ array_keys ($ placehoder ),
89+ array_values ($ placehoder ),
90+ $ content
91+ );
92+ FileSystem::writeFile (BUILD_ROOT_PATH . '/ ' . $ file , $ content );
93+ }
94+ }
95+
96+ // add .spc-extract-placeholder.json in BUILD_ROOT_PATH
97+ $ placeholder_file = BUILD_ROOT_PATH . '/.spc-extract-placeholder.json ' ;
98+ file_put_contents ($ placeholder_file , json_encode (array_keys ($ origin_files ), JSON_PRETTY_PRINT ));
99+ $ increase_files [] = '.spc-extract-placeholder.json ' ;
100+
76101 // every file mapped with BUILD_ROOT_PATH
77102 // get BUILD_ROOT_PATH last dir part
78103 $ buildroot_part = basename (BUILD_ROOT_PATH );
@@ -94,6 +119,16 @@ public function handle(): int
94119 $ filename = WORKING_DIR . '/dist/ ' . $ filename ;
95120 f_passthru ("tar {$ tar_option } {$ filename } -T " . WORKING_DIR . '/packlib_files.txt ' );
96121 logger ()->info ('Pack library ' . $ lib ->getName () . ' to ' . $ filename . ' complete. ' );
122+
123+ // remove temp files
124+ unlink ($ placeholder_file );
125+ }
126+ }
127+
128+ foreach ($ origin_files as $ file => $ content ) {
129+ // restore original files
130+ if (file_exists (BUILD_ROOT_PATH . '/ ' . $ file )) {
131+ FileSystem::writeFile (BUILD_ROOT_PATH . '/ ' . $ file , $ content );
97132 }
98133 }
99134
0 commit comments