fix suggested libs dependency order

This commit is contained in:
crazywhalecc 2023-04-07 22:11:41 +08:00
parent 4063b8454b
commit 978b59c0dc
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
3 changed files with 65 additions and 7 deletions

View File

@ -36,9 +36,9 @@
},
"enchant": {
"type": "builtin",
"arg-type": "with",
"arg-type": "custom",
"lib-depends": [
"enchant2"
"enchant"
]
},
"exif": {

View File

@ -49,9 +49,7 @@
"brotli",
"nghttp2",
"zstd",
"openssl",
"idn2",
"psl"
"openssl"
],
"lib-suggests-windows": [
"zlib",
@ -120,6 +118,35 @@
"zlib"
]
},
"enchant": {
"source": "enchant",
"static-libs-unix":[
"libenchant-2.a"
],
"lib-depends": [
"glib"
],
"headers": [
"enchant-2"
]
},
"glib": {
"source": "glib",
"static-libs-unix": [
"libglib-2.0.a",
"libgio-2.0.a",
"libgmodule-2.0.a",
"libgobject-2.0.a",
"libgthread-2.0.a"
],
"bin-depends-unix": [
"meson",
"ninja"
],
"headers": [
"glib-2.0"
]
},
"libssh2": {
"source": "libssh2",
"static-libs-unix": [
@ -158,7 +185,6 @@
"libiconv"
],
"lib-suggests": [
"icu",
"xz",
"zlib"
],

View File

@ -67,7 +67,39 @@ class DependencyUtil
self::visitLibDeps($lib, $visited, $sorted);
}
}
return $sorted;
$sorted_suggests = [];
$visited_suggests = [];
$final = [];
foreach ($libs as $lib) {
if (!isset($visited_suggests[$lib])) {
self::visitLibAllDeps($lib, $visited_suggests, $sorted_suggests);
}
}
foreach ($sorted_suggests as $suggest) {
if (in_array($suggest, $sorted)) {
$final[] = $suggest;
}
}
return $final;
}
/**
* @throws RuntimeException
* @throws FileSystemException
*/
private static function visitLibAllDeps(string $lib_name, array &$visited, array &$sorted): void
{
// 如果已经识别到了,那就不管
if (isset($visited[$lib_name])) {
return;
}
$visited[$lib_name] = true;
// 遍历该依赖的所有依赖(此处的 getLib 如果检测到当前库不存在的话,会抛出异常)
foreach (array_merge(Config::getLib($lib_name, 'lib-depends', []), Config::getLib($lib_name, 'lib-suggests', [])) as $dep) {
self::visitLibDeps($dep, $visited, $sorted);
}
$sorted[] = $lib_name;
}
/**