fix dependency sort

This commit is contained in:
crazywhalecc 2024-01-07 00:39:36 +08:00 committed by Jerry Ma
parent bff1a6168f
commit daf0d2eb32
2 changed files with 11 additions and 13 deletions

View File

@ -327,12 +327,12 @@
"libxml2" "libxml2"
], ],
"lib-depends": [ "lib-depends": [
"libiconv", "libiconv"
"zlib"
], ],
"lib-suggests": [ "lib-suggests": [
"xz", "xz",
"icu" "icu",
"zlib"
] ]
}, },
"libxslt": { "libxslt": {

View File

@ -33,12 +33,12 @@ abstract class BuilderBase
/** /**
* Build libraries * Build libraries
* *
* @param array<string> $libraries Libraries to build * @param array<string> $sorted_libraries Libraries to build (if not empty, must sort first)
* @throws FileSystemException * @throws FileSystemException
* @throws RuntimeException * @throws RuntimeException
* @throws WrongUsageException * @throws WrongUsageException
*/ */
public function buildLibs(array $libraries): void public function buildLibs(array $sorted_libraries): void
{ {
// search all supported libs // search all supported libs
$support_lib_list = []; $support_lib_list = [];
@ -53,20 +53,18 @@ abstract class BuilderBase
} }
// if no libs specified, compile all supported libs // if no libs specified, compile all supported libs
if ($libraries === [] && $this->isLibsOnly()) { if ($sorted_libraries === [] && $this->isLibsOnly()) {
$libraries = array_keys($support_lib_list); $libraries = array_keys($support_lib_list);
$sorted_libraries = DependencyUtil::getLibsByDeps($libraries);
} }
// pkg-config must be compiled first, whether it is specified or not // pkg-config must be compiled first, whether it is specified or not
if (!in_array('pkg-config', $libraries)) { if (!in_array('pkg-config', $sorted_libraries)) {
array_unshift($libraries, 'pkg-config'); array_unshift($sorted_libraries, 'pkg-config');
} }
// append dependencies
$libraries = DependencyUtil::getLibsByDeps($libraries);
// add lib object for builder // add lib object for builder
foreach ($libraries as $library) { foreach ($sorted_libraries as $library) {
// if some libs are not supported (but in config "lib.json", throw exception) // if some libs are not supported (but in config "lib.json", throw exception)
if (!isset($support_lib_list[$library])) { if (!isset($support_lib_list[$library])) {
throw new WrongUsageException('library [' . $library . '] is in the lib.json list but not supported to compile, but in the future I will support it!'); throw new WrongUsageException('library [' . $library . '] is in the lib.json list but not supported to compile, but in the future I will support it!');
@ -81,7 +79,7 @@ abstract class BuilderBase
} }
// extract sources // extract sources
SourceExtractor::initSource(libs: $libraries); SourceExtractor::initSource(libs: $sorted_libraries);
// build all libs // build all libs
foreach ($this->libs as $lib) { foreach ($this->libs as $lib) {