Skip to content

Commit 6b93bf2

Browse files
reddevillgdengbo11
authored andcommitted
fix: resolve extension definitions from config
If a matching definition is found, use its metadata directly. Fall back to manual construction only when no match exists.
1 parent 5c29d92 commit 6b93bf2

2 files changed

Lines changed: 33 additions & 14 deletions

File tree

libs/linglong/src/linglong/cli/cli.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -654,14 +654,6 @@ int Cli::run(const RunOptions &options)
654654
opts.cdiDevices = std::move(*autoDetectedCdiDevices);
655655
}
656656

657-
// 调整日志输出,打印扩展列表(用逗号拼接)
658-
std::string extStr =
659-
opts.extensionRefs ? linglong::common::strings::join(*opts.extensionRefs, ',') : "null";
660-
LogD("start resolve run context with base {}, runtime {}, extensions {}",
661-
opts.baseRef.value_or("null"),
662-
opts.runtimeRef.value_or("null"),
663-
extStr);
664-
665657
auto res = runContext.resolve(*curAppRef, opts);
666658
if (!res) {
667659
handleCommonError(res.error());

libs/linglong/src/linglong/runtime/run_context.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,39 @@ utils::error::Result<void> RunContext::resolve(const api::types::v1::RunContextC
443443
if (extLayer.getCachedItem().info.kind != "extension") {
444444
return LINGLONG_ERR("invalid extension kind in config.extensions");
445445
}
446+
447+
api::types::v1::ExtensionDefine extDef;
448+
const auto &targetInfo = targetLayer->get().getCachedItem().info;
449+
const auto *matchedDef = [&]() -> const api::types::v1::ExtensionDefine * {
450+
if (!targetInfo.extensions) {
451+
return nullptr;
452+
}
453+
for (const auto &def : *targetInfo.extensions) {
454+
std::string name = def.name;
455+
auto ext = extension::ExtensionFactory::makeExtension(name);
456+
if (ext->shouldEnable(name) && name == extLayer.getReference().id) {
457+
return &def;
458+
}
459+
}
460+
return nullptr;
461+
}();
462+
463+
if (matchedDef) {
464+
extDef = *matchedDef;
465+
} else {
466+
LogW("extension {} not found in target layer {}'s extensions, "
467+
"using manual extension define",
468+
extLayer.getReference().toString(),
469+
targetLayer->get().getReference().toString());
470+
auto manualDefs = makeManualExtensionDefine({ extensionRefStr });
471+
if (!manualDefs) {
472+
return LINGLONG_ERR(manualDefs);
473+
}
474+
extDef = std::move(manualDefs->front());
475+
}
476+
446477
extLayer.setExtensionInfo(RuntimeLayer::ExtensionRuntimeLayerInfo{
447-
.extensionInfo =
448-
api::types::v1::ExtensionDefine{
449-
.directory = "/opt/extensions/" + extLayer.getReference().id,
450-
.name = extLayer.getReference().id,
451-
.version = extLayer.getReference().version.toString(),
452-
},
478+
.extensionInfo = std::move(extDef),
453479
.extensionLayer = std::ref(extLayer),
454480
.forRef = targetRefStr,
455481
});
@@ -545,6 +571,7 @@ utils::error::Result<void> RunContext::resolveLayer(bool depsBinaryOnly,
545571

546572
const auto &extensionOf = ext.getExtensionInfo();
547573
if (!extensionOf) {
574+
LogW("failed getExtensionInfo, skip");
548575
continue;
549576
}
550577

0 commit comments

Comments
 (0)