diff --git a/libs/rtemodel/include/RteInstance.h b/libs/rtemodel/include/RteInstance.h index c48aeae26..dcbd81fcf 100644 --- a/libs/rtemodel/include/RteInstance.h +++ b/libs/rtemodel/include/RteInstance.h @@ -440,7 +440,7 @@ class RteItemInstance : public RteItem * @brief get pointer to RteComponent * @return pointer to RteComponent, nullptr by default */ - RteComponent* GetComponent() const override { return nullptr;} + RteComponent* GetComponent() const override { return GetComponent(EMPTY_STRING);} /** * @brief get resolved component, even if this item is not filtered by specified target @@ -861,7 +861,7 @@ class RteComponentInstance : public RteItemInstance * @brief constructor * @param parent pointer to RteItem parent */ - RteComponentInstance(RteItem* parent); + RteComponentInstance(RteItem* parent = 0); /** * @brief virtual destructor @@ -1057,6 +1057,9 @@ class RteComponentInstance : public RteItemInstance */ RteComponent* GetComponent(const std::string& targetName) const override { return GetResolvedComponent(targetName); } + + using RteItemInstance::GetComponent; // returns first resolved + /** * @brief get resolved component for specified target * @param targetName target name to resolve component diff --git a/libs/rtemodel/src/RteInstance.cpp b/libs/rtemodel/src/RteInstance.cpp index e4e8393dd..e8ffb36ac 100644 --- a/libs/rtemodel/src/RteInstance.cpp +++ b/libs/rtemodel/src/RteInstance.cpp @@ -242,7 +242,7 @@ void RteItemInstance::InitInstance(RteItem* item) if (!item) return; SetTag(item->GetTag()); - SetAttributes(item->GetAttributes()); + AddAttributes(item->GetAttributes(), true); } void RteItemInstance::Clear() @@ -1567,10 +1567,14 @@ RteItem* RteComponentInstance::GetEffectiveItem(const string& targetName) const RteComponent* RteComponentInstance::GetResolvedComponent(const string& targetName) const { - auto it = m_resolvedComponents.find(targetName); - if (it != m_resolvedComponents.end()) + auto it = m_resolvedComponents.begin(); + if(!targetName.empty()) { + it = m_resolvedComponents.find(targetName); + } + if(it != m_resolvedComponents.end()) { return it->second; - return NULL; + } + return nullptr; } RteComponent* RteComponentInstance::GetPotentialComponent(const string& targetName) const diff --git a/tools/projmgr/include/ProjMgrWorker.h b/tools/projmgr/include/ProjMgrWorker.h index 067d6b216..1cbb1da0f 100644 --- a/tools/projmgr/include/ProjMgrWorker.h +++ b/tools/projmgr/include/ProjMgrWorker.h @@ -998,7 +998,8 @@ class ProjMgrWorker { bool ProcessToolchain(ContextItem& context); bool ProcessPackages(ContextItem& context, const std::string& packRoot); bool ProcessComponents(ContextItem& context); - RteComponent* ProcessComponent(ContextItem& context, ComponentItem& item, RteComponentMap& componentMap, std::string& hint); + RteComponentInstance* ProcessComponent(ContextItem& context, ComponentItem& item, RteComponentMap& componentMap, std::string& hint); + RteComponent* ResolveComponent(RteComponentInstance* ci, ContextItem& context, ComponentItem& item, RteComponentMap& componentMap, std::string& hint); bool ProcessGpdsc(ContextItem& context); bool ProcessConfigFiles(ContextItem& context); bool ProcessComponentFiles(ContextItem& context); diff --git a/tools/projmgr/src/ProjMgrCbuild.cpp b/tools/projmgr/src/ProjMgrCbuild.cpp index 5af673bab..398f15b0f 100644 --- a/tools/projmgr/src/ProjMgrCbuild.cpp +++ b/tools/projmgr/src/ProjMgrCbuild.cpp @@ -115,7 +115,10 @@ void ProjMgrCbuild::SetContextNode(YAML::Node contextNode, const ContextItem* co void ProjMgrCbuild::SetComponentsNode(YAML::Node node, const ContextItem* context) { for (const auto& [componentId, component] : context->components) { - const RteComponent* rteComponent = component.instance->GetParent()->GetComponent(); + const RteComponent* rteComponent = component.instance->GetComponent(); + if(!rteComponent) { + continue; + } const ComponentItem* componentItem = component.item; YAML::Node componentNode; SetNodeValue(componentNode[YAML_COMPONENT], componentId); diff --git a/tools/projmgr/src/ProjMgrWorker.cpp b/tools/projmgr/src/ProjMgrWorker.cpp index aa1f234e7..f744efb11 100644 --- a/tools/projmgr/src/ProjMgrWorker.cpp +++ b/tools/projmgr/src/ProjMgrWorker.cpp @@ -1813,20 +1813,23 @@ bool ProjMgrWorker::ProcessComponents(ContextItem& context) { continue; } string hint; - RteComponent* matchedComponent = ProcessComponent(context, item, componentMap, hint); + RteComponentInstance* matchedComponentInstance = ProcessComponent(context, item, componentMap, hint); + RteComponent* matchedComponent = matchedComponentInstance->GetComponent(); if (!matchedComponent) { // No match ProjMgrLogger::Get().Error("no component was found with identifier '" + item.component + "'" + (!hint.empty() ? "\n did you mean '" + hint + "'?" : ""), context.name); error = true; - continue; + if(!m_rpcMode) { + delete matchedComponentInstance; + continue; // no need it unresolved instance in command line mode + } } + const auto componentId = matchedComponentInstance->GetComponentID(true); + auto aggCompId = matchedComponentInstance->GetComponentAggregateID(); UpdateMisc(item.build.misc, context.toolchain.name); - const auto& componentId = matchedComponent->GetComponentID(true); - auto aggCompId = matchedComponent->GetComponentAggregateID(); - auto itr = std::find_if(processedComponents.begin(), processedComponents.end(), [aggCompId](const auto& pair) { return pair.first.compare(aggCompId) == 0; }); @@ -1835,16 +1838,6 @@ bool ProjMgrWorker::ProcessComponents(ContextItem& context) { error = true; } - // Init matched component instance - RteComponentInstance* matchedComponentInstance = new RteComponentInstance(matchedComponent); - matchedComponentInstance->InitInstance(matchedComponent); - if (!item.condition.empty()) { - auto ti = matchedComponentInstance->EnsureTargetInfo(context.rteActiveTarget->GetName()); - ti->SetVersionMatchMode(VersionCmp::MatchMode::ENFORCED_VERSION); - matchedComponentInstance->AddAttribute("versionMatchMode", - VersionCmp::MatchModeToString(VersionCmp::MatchMode::ENFORCED_VERSION)); - } - // Set layer's rtePath attribute if (!layer.empty()) { error_code ec; @@ -1853,36 +1846,6 @@ bool ProjMgrWorker::ProcessComponents(ContextItem& context) { matchedComponentInstance->AddAttribute("layer", layer); } - // Get generator - string generatorId = matchedComponent->GetGeneratorName(); - RteGenerator* generator = matchedComponent->GetGenerator(); - if (generator && !generator->IsExternal()) { - context.generators.insert({ generatorId, generator }); - string genDir; - if (!GetGeneratorDir(generator, context, layer, genDir)) { - return false; - } - matchedComponentInstance->AddAttribute("gendir", genDir); - const string gpdsc = RteFsUtils::MakePathCanonical(generator->GetExpandedGpdsc(context.rteActiveTarget, genDir)); - context.gpdscs.insert({ gpdsc, {componentId, generatorId, genDir} }); - context.bootstrapComponents.insert({ componentId, { matchedComponentInstance, &item, generatorId } }); - } else { - // Get external generator id - if (!generatorId.empty()) { - // check if required global generator is registered - if (!m_extGenerator->CheckGeneratorId(generatorId, componentId)) { - return false; - } - GeneratorOptionsItem options = { generatorId }; - if (!GetExtGeneratorOptions(context, layer, options)) { - return false; - } - // keep track of used generators - m_extGenerator->AddUsedGenerator(options, context.name); - context.extGen[options.id] = options; - } - } - // Component instances if (item.instances > matchedComponentInstance->GetMaxInstances()) { ProjMgrLogger::Get().Error("component '" + item.component + "' does not accept more than " + @@ -1892,6 +1855,53 @@ bool ProjMgrWorker::ProcessComponents(ContextItem& context) { matchedComponentInstance->AddAttribute("instances", to_string(item.instances)); } + + // Get generator + string generatorId; + if(matchedComponent) { + generatorId = matchedComponent->GetGeneratorName(); + RteGenerator* generator = matchedComponent->GetGenerator(); + if(generator && !generator->IsExternal()) { + context.generators.insert({generatorId, generator}); + string genDir; + if(!GetGeneratorDir(generator, context, layer, genDir)) { + return false; + } + matchedComponentInstance->AddAttribute("gendir", genDir); + const string gpdsc = RteFsUtils::MakePathCanonical(generator->GetExpandedGpdsc(context.rteActiveTarget, genDir)); + context.gpdscs.insert({gpdsc, {componentId, generatorId, genDir}}); + context.bootstrapComponents.insert({componentId, { matchedComponentInstance, &item, generatorId }}); + } else { + // Get external generator id + if(!generatorId.empty()) { + // check if required global generator is registered + if(!m_extGenerator->CheckGeneratorId(generatorId, componentId)) { + return false; + } + GeneratorOptionsItem options = {generatorId}; + if(!GetExtGeneratorOptions(context, layer, options)) { + return false; + } + // keep track of used generators + m_extGenerator->AddUsedGenerator(options, context.name); + context.extGen[options.id] = options; + } + } + const auto componentPackage = matchedComponent->GetPackage(); + if(componentPackage) { + context.packages.insert({componentPackage->GetID(), componentPackage}); + } + if(matchedComponent->HasApi(context.rteActiveTarget)) { + const auto& api = matchedComponent->GetApi(context.rteActiveTarget, false); + if(api) { + const auto& apiPackage = api->GetPackage(); + if(apiPackage) { + context.packages.insert({apiPackage->GetID(), apiPackage}); + } + } + } + } + // Insert matched component into context list context.components.insert({ componentId, { matchedComponentInstance, &item, generatorId } }); @@ -1903,20 +1913,6 @@ bool ProjMgrWorker::ProcessComponents(ContextItem& context) { it = processedComponents.find(aggCompId); } it->second.push_back(item.component); - - const auto& componentPackage = matchedComponent->GetPackage(); - if (componentPackage) { - context.packages.insert({ componentPackage->GetID(), componentPackage }); - } - if (matchedComponent->HasApi(context.rteActiveTarget)) { - const auto& api = matchedComponent->GetApi(context.rteActiveTarget, false); - if (api) { - const auto& apiPackage = api->GetPackage(); - if (apiPackage) { - context.packages.insert({ apiPackage->GetID(), apiPackage }); - } - } - } } if (error) { @@ -1934,37 +1930,53 @@ bool ProjMgrWorker::ProcessComponents(ContextItem& context) { // Add required components into RTE if (!AddRequiredComponents(context)) { - return false; - } - - if (!CheckRteErrors()) { - return false; + error = true; + } else if (!CheckRteErrors()) { + error = true; } // tolerate component selection errors when in rpc mode - if (m_rpcMode) { + if (error && m_rpcMode) { error = false; } return !error; } -RteComponent* ProjMgrWorker::ProcessComponent(ContextItem& context, ComponentItem& item, RteComponentMap& componentMap, string& hint) -{ - if (!item.condition.empty()) { - RteComponentInstance ci(nullptr); - ci.SetTag("component"); - ci.SetAttributesFomComponentId(item.component); - ci.AddAttribute("condition", item.condition); - auto ti = ci.EnsureTargetInfo(context.rteActiveTarget->GetName()); +RteComponentInstance* ProjMgrWorker::ProcessComponent(ContextItem& context, ComponentItem& item, RteComponentMap& componentMap, string& hint) +{ + RteComponentInstance* ci = new RteComponentInstance(nullptr); + ci->SetTag("component"); + ci->SetAttributesFomComponentId(item.component); + ci->AddAttribute("id", item.component); + bool bEnforced = !item.condition.empty(); + if(bEnforced) { + ci->AddAttribute("condition", item.condition); + ci->AddAttribute("versionMatchMode", VersionCmp::MatchModeToString(VersionCmp::MatchMode::ENFORCED_VERSION)); + auto ti = ci->EnsureTargetInfo(context.rteActiveTarget->GetName()); ti->SetVersionMatchMode(VersionCmp::MatchMode::ENFORCED_VERSION); RtePackageInstanceInfo packInfo(nullptr, item.fromPack); - ci.SetPackageAttributes(packInfo); + ci->SetPackageAttributes(packInfo); + } + auto c = ResolveComponent(ci, context, item, componentMap, hint); + if(c) { + ci->InitInstance(c); + ci->SetResolvedComponent(c, context.rteActiveTarget->GetName()); + } + ci->ConstructID(); + return ci; +} + +RteComponent* ProjMgrWorker::ResolveComponent(RteComponentInstance* ci, ContextItem& context, ComponentItem& item, RteComponentMap& componentMap, string& hint) +{ + + bool bEnforced = !item.condition.empty(); + if(bEnforced) { list components; - RteComponent* enforced = context.rteActiveTarget->GetFilteredModel()->FindComponents(ci, components); - if (enforced) { - return enforced; + RteComponent* rteComponent = context.rteActiveTarget->GetFilteredModel()->FindComponents(*ci, components); + if(rteComponent) { + return rteComponent; } } @@ -2261,7 +2273,10 @@ bool ProjMgrWorker::ProcessComponentFiles(ContextItem& context) { } // iterate over components for (const auto& [componentId, component] : context.components) { - RteComponent* rteComponent = component.instance->GetParent()->GetComponent(); + RteComponent* rteComponent = component.instance->GetComponent(); + if(!rteComponent) { + continue; + } // component based API files const auto& api = rteComponent->GetApi(context.rteActiveTarget, true); if (api) { @@ -2341,8 +2356,8 @@ bool ProjMgrWorker::ProcessComponentFiles(ContextItem& context) { RteComponentInstance* rteBootstrapInstance = context.bootstrapComponents.find(componentId) != context.bootstrapComponents.end() ? context.bootstrapMap.find(componentId) != context.bootstrapMap.end() ? context.bootstrapComponents.at(context.bootstrapMap.at(componentId)).instance : context.bootstrapComponents.at(componentId).instance : nullptr; - if (rteBootstrapInstance != nullptr) { - RteComponent* rteBootstrapComponent = rteBootstrapInstance->GetParent()->GetComponent(); + RteComponent* rteBootstrapComponent = rteBootstrapInstance ? rteBootstrapInstance->GetComponent() : nullptr; + if (rteBootstrapComponent != nullptr) { const auto& files = rteBootstrapComponent->GetFileContainer() ? rteBootstrapComponent->GetFileContainer()->GetChildren() : Collection(); for (const RteItem* rteFile : files) { const auto& category = rteFile->GetAttribute("category"); @@ -2408,7 +2423,7 @@ void ProjMgrWorker::ValidateComponentSources(ContextItem& context) { for (auto& file : files) { if (file.category.compare(0, 6, "source") == 0 && file.name == filename) { msg += "\n - component: " + componentID; - msg += "\n from-pack: " + context.components[componentID].instance->GetParent()->GetComponent()->GetPackageID(); + msg += "\n from-pack: " + context.components[componentID].instance->GetComponent()->GetPackageID(); if (erase) { files.erase(it); } else { @@ -2663,7 +2678,11 @@ bool ProjMgrWorker::ProcessGpdsc(ContextItem& context) { } else if (gpdscComponent->GetTag() == "bundle") { components = gpdscComponent->GetChildren(); } - for (const auto component : components) { + for (const auto c : components) { + auto component = c->GetComponent(); + if(!component) { + continue; + } if (bootstrap.instance->GetComponentID(false) == component->GetComponentID(false)) { if (VersionCmp::Compare(bootstrap.instance->GetVersionString(), component->GetVersionString()) > 0) { // bootstrap has greater version, do not replace it @@ -2673,8 +2692,9 @@ bool ProjMgrWorker::ProcessGpdsc(ContextItem& context) { } } const auto& componentId = component->GetComponentID(true); - RteComponentInstance* componentInstance = new RteComponentInstance(component); + RteComponentInstance* componentInstance = new RteComponentInstance(); componentInstance->InitInstance(component); + componentInstance->SetResolvedComponent(component, context.rteActiveTarget->GetName()); componentInstance->AddAttribute("gendir", bootstrap.instance->GetAttribute("gendir")); componentInstance->AddAttribute("rtedir", bootstrap.instance->GetAttribute("rtedir")); context.components[componentId] = { componentInstance, bootstrap.item, component->GetGeneratorName() }; @@ -2701,16 +2721,33 @@ bool ProjMgrWorker::ProcessGpdsc(ContextItem& context) { } } } - if (!gpdscInfos.empty() && !context.gpdscs.empty()) { + + bool error = false; + if(!gpdscInfos.empty() && !context.gpdscs.empty()) { // Update target with gpdsc model - if (!SetTargetAttributes(context, context.targetAttributes)) { - return false; + if(!SetTargetAttributes(context, context.targetAttributes)) { + error = true; } // Re-add required components into RTE - if (!AddRequiredComponents(context)) { - return false; + if(!AddRequiredComponents(context)) { + error = true; } } + + if (!error && !CheckRteErrors()) { + error = true; + } + + // tolerate component selection errors when in rpc mode + if (error && m_rpcMode) { + error = false; + } + + return !error; + + + + return CheckRteErrors(); } diff --git a/tools/projmgr/test/src/ProjMgrWorkerUnitTests.cpp b/tools/projmgr/test/src/ProjMgrWorkerUnitTests.cpp index 7a5eb04b4..2b30161b6 100644 --- a/tools/projmgr/test/src/ProjMgrWorkerUnitTests.cpp +++ b/tools/projmgr/test/src/ProjMgrWorkerUnitTests.cpp @@ -973,8 +973,9 @@ TEST_F(ProjMgrWorkerUnitTests, ProcessComponentFilesEmpty) { InitializeTarget(context); RtePackage* pack = new RtePackage(NULL); RteComponent* c = new RteComponent(pack); - RteComponentInstance* ci = new RteComponentInstance(c); + RteComponentInstance* ci = new RteComponentInstance(); ci->InitInstance(c); + ci->SetResolvedComponent(c, context.rteActiveTarget->GetName()); ci->SetAttributes({ {"Cclass" , "Class"}, {"Cgroup" , "Group"} }); context.components.insert({ "Class:Group", { ci } }); EXPECT_TRUE(ProcessComponentFiles(context));