@@ -25,6 +25,17 @@ namespace {
2525
2626constexpr const char *runContextConfigVersion = " 1" ;
2727
28+ bool isExtensionBelongTo (const std::string &defName, const std::string &id)
29+ {
30+ if (defName == id) {
31+ return true ;
32+ }
33+ if (common::strings::starts_with (id, defName + " ." )) {
34+ return true ;
35+ }
36+ return false ;
37+ }
38+
2839void ensureMountSrcType (std::vector<api::types::v1::Mount> &mounts)
2940{
3041 for (auto &m : mounts) {
@@ -443,13 +454,40 @@ utils::error::Result<void> RunContext::resolve(const api::types::v1::RunContextC
443454 if (extLayer.getCachedItem ().info .kind != " extension" ) {
444455 return LINGLONG_ERR (" invalid extension kind in config.extensions" );
445456 }
457+
458+ api::types::v1::ExtensionDefine extDef;
459+ const auto &targetInfo = targetLayer->get ().getCachedItem ().info ;
460+ const auto *matchedDef = [&]() -> const api::types::v1::ExtensionDefine * {
461+ if (!targetInfo.extensions ) {
462+ return nullptr ;
463+ }
464+ for (const auto &def : *targetInfo.extensions ) {
465+ std::string name = def.name ;
466+ auto ext = extension::ExtensionFactory::makeExtension (name);
467+ if (ext->shouldEnable (name)
468+ && isExtensionBelongTo (def.name , extLayer.getReference ().id )) {
469+ return &def;
470+ }
471+ }
472+ return nullptr ;
473+ }();
474+
475+ if (matchedDef) {
476+ extDef = *matchedDef;
477+ } else {
478+ LogW (" extension {} not found in target layer {}'s extensions, "
479+ " using manual extension define" ,
480+ extLayer.getReference ().toString (),
481+ targetLayer->get ().getReference ().toString ());
482+ auto manualDefs = makeManualExtensionDefine ({ extensionRefStr });
483+ if (!manualDefs) {
484+ return LINGLONG_ERR (manualDefs);
485+ }
486+ extDef = std::move (manualDefs->front ());
487+ }
488+
446489 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- },
490+ .extensionInfo = std::move (extDef),
453491 .extensionLayer = std::ref (extLayer),
454492 .forRef = targetRefStr,
455493 });
@@ -545,6 +583,7 @@ utils::error::Result<void> RunContext::resolveLayer(bool depsBinaryOnly,
545583
546584 const auto &extensionOf = ext.getExtensionInfo ();
547585 if (!extensionOf) {
586+ LogW (" failed getExtensionInfo, skip" );
548587 continue ;
549588 }
550589
0 commit comments