@@ -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