Skip to content

Commit a48de33

Browse files
authored
Refactor csolution process components (#1258)
* Refactor csolution process components Enhance RteComponentInstance with GetComponent() always create RteComponentInstance * Refactor csolution process components always create RteComponentInstance, even for missing component keep unresolved RteComponentInstance in rpc mode and insert it into RTE model
1 parent d8089a3 commit a48de33

File tree

6 files changed

+143
-97
lines changed

6 files changed

+143
-97
lines changed

libs/rtemodel/include/RteInstance.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ class RteItemInstance : public RteItem
440440
* @brief get pointer to RteComponent
441441
* @return pointer to RteComponent, nullptr by default
442442
*/
443-
RteComponent* GetComponent() const override { return nullptr;}
443+
RteComponent* GetComponent() const override { return GetComponent(EMPTY_STRING);}
444444

445445
/**
446446
* @brief get resolved component, even if this item is not filtered by specified target
@@ -861,7 +861,7 @@ class RteComponentInstance : public RteItemInstance
861861
* @brief constructor
862862
* @param parent pointer to RteItem parent
863863
*/
864-
RteComponentInstance(RteItem* parent);
864+
RteComponentInstance(RteItem* parent = 0);
865865

866866
/**
867867
* @brief virtual destructor
@@ -1057,6 +1057,9 @@ class RteComponentInstance : public RteItemInstance
10571057
*/
10581058
RteComponent* GetComponent(const std::string& targetName) const override
10591059
{ return GetResolvedComponent(targetName); }
1060+
1061+
using RteItemInstance::GetComponent; // returns first resolved
1062+
10601063
/**
10611064
* @brief get resolved component for specified target
10621065
* @param targetName target name to resolve component

libs/rtemodel/src/RteInstance.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ void RteItemInstance::InitInstance(RteItem* item)
242242
if (!item)
243243
return;
244244
SetTag(item->GetTag());
245-
SetAttributes(item->GetAttributes());
245+
AddAttributes(item->GetAttributes(), true);
246246
}
247247

248248
void RteItemInstance::Clear()
@@ -1567,10 +1567,14 @@ RteItem* RteComponentInstance::GetEffectiveItem(const string& targetName) const
15671567

15681568
RteComponent* RteComponentInstance::GetResolvedComponent(const string& targetName) const
15691569
{
1570-
auto it = m_resolvedComponents.find(targetName);
1571-
if (it != m_resolvedComponents.end())
1570+
auto it = m_resolvedComponents.begin();
1571+
if(!targetName.empty()) {
1572+
it = m_resolvedComponents.find(targetName);
1573+
}
1574+
if(it != m_resolvedComponents.end()) {
15721575
return it->second;
1573-
return NULL;
1576+
}
1577+
return nullptr;
15741578
}
15751579

15761580
RteComponent* RteComponentInstance::GetPotentialComponent(const string& targetName) const

tools/projmgr/include/ProjMgrWorker.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,8 @@ class ProjMgrWorker {
998998
bool ProcessToolchain(ContextItem& context);
999999
bool ProcessPackages(ContextItem& context, const std::string& packRoot);
10001000
bool ProcessComponents(ContextItem& context);
1001-
RteComponent* ProcessComponent(ContextItem& context, ComponentItem& item, RteComponentMap& componentMap, std::string& hint);
1001+
RteComponentInstance* ProcessComponent(ContextItem& context, ComponentItem& item, RteComponentMap& componentMap, std::string& hint);
1002+
RteComponent* ResolveComponent(RteComponentInstance* ci, ContextItem& context, ComponentItem& item, RteComponentMap& componentMap, std::string& hint);
10021003
bool ProcessGpdsc(ContextItem& context);
10031004
bool ProcessConfigFiles(ContextItem& context);
10041005
bool ProcessComponentFiles(ContextItem& context);

tools/projmgr/src/ProjMgrCbuild.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ void ProjMgrCbuild::SetContextNode(YAML::Node contextNode, const ContextItem* co
115115

116116
void ProjMgrCbuild::SetComponentsNode(YAML::Node node, const ContextItem* context) {
117117
for (const auto& [componentId, component] : context->components) {
118-
const RteComponent* rteComponent = component.instance->GetParent()->GetComponent();
118+
const RteComponent* rteComponent = component.instance->GetComponent();
119+
if(!rteComponent) {
120+
continue;
121+
}
119122
const ComponentItem* componentItem = component.item;
120123
YAML::Node componentNode;
121124
SetNodeValue(componentNode[YAML_COMPONENT], componentId);

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 122 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,20 +1813,23 @@ bool ProjMgrWorker::ProcessComponents(ContextItem& context) {
18131813
continue;
18141814
}
18151815
string hint;
1816-
RteComponent* matchedComponent = ProcessComponent(context, item, componentMap, hint);
1816+
RteComponentInstance* matchedComponentInstance = ProcessComponent(context, item, componentMap, hint);
1817+
RteComponent* matchedComponent = matchedComponentInstance->GetComponent();
18171818
if (!matchedComponent) {
18181819
// No match
18191820
ProjMgrLogger::Get().Error("no component was found with identifier '" + item.component + "'" +
18201821
(!hint.empty() ? "\n did you mean '" + hint + "'?" : ""), context.name);
18211822
error = true;
1822-
continue;
1823+
if(!m_rpcMode) {
1824+
delete matchedComponentInstance;
1825+
continue; // no need it unresolved instance in command line mode
1826+
}
18231827
}
1828+
const auto componentId = matchedComponentInstance->GetComponentID(true);
1829+
auto aggCompId = matchedComponentInstance->GetComponentAggregateID();
18241830

18251831
UpdateMisc(item.build.misc, context.toolchain.name);
18261832

1827-
const auto& componentId = matchedComponent->GetComponentID(true);
1828-
auto aggCompId = matchedComponent->GetComponentAggregateID();
1829-
18301833
auto itr = std::find_if(processedComponents.begin(), processedComponents.end(), [aggCompId](const auto& pair) {
18311834
return pair.first.compare(aggCompId) == 0;
18321835
});
@@ -1835,16 +1838,6 @@ bool ProjMgrWorker::ProcessComponents(ContextItem& context) {
18351838
error = true;
18361839
}
18371840

1838-
// Init matched component instance
1839-
RteComponentInstance* matchedComponentInstance = new RteComponentInstance(matchedComponent);
1840-
matchedComponentInstance->InitInstance(matchedComponent);
1841-
if (!item.condition.empty()) {
1842-
auto ti = matchedComponentInstance->EnsureTargetInfo(context.rteActiveTarget->GetName());
1843-
ti->SetVersionMatchMode(VersionCmp::MatchMode::ENFORCED_VERSION);
1844-
matchedComponentInstance->AddAttribute("versionMatchMode",
1845-
VersionCmp::MatchModeToString(VersionCmp::MatchMode::ENFORCED_VERSION));
1846-
}
1847-
18481841
// Set layer's rtePath attribute
18491842
if (!layer.empty()) {
18501843
error_code ec;
@@ -1853,36 +1846,6 @@ bool ProjMgrWorker::ProcessComponents(ContextItem& context) {
18531846
matchedComponentInstance->AddAttribute("layer", layer);
18541847
}
18551848

1856-
// Get generator
1857-
string generatorId = matchedComponent->GetGeneratorName();
1858-
RteGenerator* generator = matchedComponent->GetGenerator();
1859-
if (generator && !generator->IsExternal()) {
1860-
context.generators.insert({ generatorId, generator });
1861-
string genDir;
1862-
if (!GetGeneratorDir(generator, context, layer, genDir)) {
1863-
return false;
1864-
}
1865-
matchedComponentInstance->AddAttribute("gendir", genDir);
1866-
const string gpdsc = RteFsUtils::MakePathCanonical(generator->GetExpandedGpdsc(context.rteActiveTarget, genDir));
1867-
context.gpdscs.insert({ gpdsc, {componentId, generatorId, genDir} });
1868-
context.bootstrapComponents.insert({ componentId, { matchedComponentInstance, &item, generatorId } });
1869-
} else {
1870-
// Get external generator id
1871-
if (!generatorId.empty()) {
1872-
// check if required global generator is registered
1873-
if (!m_extGenerator->CheckGeneratorId(generatorId, componentId)) {
1874-
return false;
1875-
}
1876-
GeneratorOptionsItem options = { generatorId };
1877-
if (!GetExtGeneratorOptions(context, layer, options)) {
1878-
return false;
1879-
}
1880-
// keep track of used generators
1881-
m_extGenerator->AddUsedGenerator(options, context.name);
1882-
context.extGen[options.id] = options;
1883-
}
1884-
}
1885-
18861849
// Component instances
18871850
if (item.instances > matchedComponentInstance->GetMaxInstances()) {
18881851
ProjMgrLogger::Get().Error("component '" + item.component + "' does not accept more than " +
@@ -1892,6 +1855,53 @@ bool ProjMgrWorker::ProcessComponents(ContextItem& context) {
18921855
matchedComponentInstance->AddAttribute("instances", to_string(item.instances));
18931856
}
18941857

1858+
1859+
// Get generator
1860+
string generatorId;
1861+
if(matchedComponent) {
1862+
generatorId = matchedComponent->GetGeneratorName();
1863+
RteGenerator* generator = matchedComponent->GetGenerator();
1864+
if(generator && !generator->IsExternal()) {
1865+
context.generators.insert({generatorId, generator});
1866+
string genDir;
1867+
if(!GetGeneratorDir(generator, context, layer, genDir)) {
1868+
return false;
1869+
}
1870+
matchedComponentInstance->AddAttribute("gendir", genDir);
1871+
const string gpdsc = RteFsUtils::MakePathCanonical(generator->GetExpandedGpdsc(context.rteActiveTarget, genDir));
1872+
context.gpdscs.insert({gpdsc, {componentId, generatorId, genDir}});
1873+
context.bootstrapComponents.insert({componentId, { matchedComponentInstance, &item, generatorId }});
1874+
} else {
1875+
// Get external generator id
1876+
if(!generatorId.empty()) {
1877+
// check if required global generator is registered
1878+
if(!m_extGenerator->CheckGeneratorId(generatorId, componentId)) {
1879+
return false;
1880+
}
1881+
GeneratorOptionsItem options = {generatorId};
1882+
if(!GetExtGeneratorOptions(context, layer, options)) {
1883+
return false;
1884+
}
1885+
// keep track of used generators
1886+
m_extGenerator->AddUsedGenerator(options, context.name);
1887+
context.extGen[options.id] = options;
1888+
}
1889+
}
1890+
const auto componentPackage = matchedComponent->GetPackage();
1891+
if(componentPackage) {
1892+
context.packages.insert({componentPackage->GetID(), componentPackage});
1893+
}
1894+
if(matchedComponent->HasApi(context.rteActiveTarget)) {
1895+
const auto& api = matchedComponent->GetApi(context.rteActiveTarget, false);
1896+
if(api) {
1897+
const auto& apiPackage = api->GetPackage();
1898+
if(apiPackage) {
1899+
context.packages.insert({apiPackage->GetID(), apiPackage});
1900+
}
1901+
}
1902+
}
1903+
}
1904+
18951905
// Insert matched component into context list
18961906
context.components.insert({ componentId, { matchedComponentInstance, &item, generatorId } });
18971907

@@ -1903,20 +1913,6 @@ bool ProjMgrWorker::ProcessComponents(ContextItem& context) {
19031913
it = processedComponents.find(aggCompId);
19041914
}
19051915
it->second.push_back(item.component);
1906-
1907-
const auto& componentPackage = matchedComponent->GetPackage();
1908-
if (componentPackage) {
1909-
context.packages.insert({ componentPackage->GetID(), componentPackage });
1910-
}
1911-
if (matchedComponent->HasApi(context.rteActiveTarget)) {
1912-
const auto& api = matchedComponent->GetApi(context.rteActiveTarget, false);
1913-
if (api) {
1914-
const auto& apiPackage = api->GetPackage();
1915-
if (apiPackage) {
1916-
context.packages.insert({ apiPackage->GetID(), apiPackage });
1917-
}
1918-
}
1919-
}
19201916
}
19211917

19221918
if (error) {
@@ -1934,37 +1930,53 @@ bool ProjMgrWorker::ProcessComponents(ContextItem& context) {
19341930

19351931
// Add required components into RTE
19361932
if (!AddRequiredComponents(context)) {
1937-
return false;
1938-
}
1939-
1940-
if (!CheckRteErrors()) {
1941-
return false;
1933+
error = true;
1934+
} else if (!CheckRteErrors()) {
1935+
error = true;
19421936
}
19431937

19441938
// tolerate component selection errors when in rpc mode
1945-
if (m_rpcMode) {
1939+
if (error && m_rpcMode) {
19461940
error = false;
19471941
}
19481942

19491943
return !error;
19501944
}
19511945

1952-
RteComponent* ProjMgrWorker::ProcessComponent(ContextItem& context, ComponentItem& item, RteComponentMap& componentMap, string& hint)
1953-
{
1954-
if (!item.condition.empty()) {
1955-
RteComponentInstance ci(nullptr);
1956-
ci.SetTag("component");
19571946

1958-
ci.SetAttributesFomComponentId(item.component);
1959-
ci.AddAttribute("condition", item.condition);
1960-
auto ti = ci.EnsureTargetInfo(context.rteActiveTarget->GetName());
1947+
RteComponentInstance* ProjMgrWorker::ProcessComponent(ContextItem& context, ComponentItem& item, RteComponentMap& componentMap, string& hint)
1948+
{
1949+
RteComponentInstance* ci = new RteComponentInstance(nullptr);
1950+
ci->SetTag("component");
1951+
ci->SetAttributesFomComponentId(item.component);
1952+
ci->AddAttribute("id", item.component);
1953+
bool bEnforced = !item.condition.empty();
1954+
if(bEnforced) {
1955+
ci->AddAttribute("condition", item.condition);
1956+
ci->AddAttribute("versionMatchMode", VersionCmp::MatchModeToString(VersionCmp::MatchMode::ENFORCED_VERSION));
1957+
auto ti = ci->EnsureTargetInfo(context.rteActiveTarget->GetName());
19611958
ti->SetVersionMatchMode(VersionCmp::MatchMode::ENFORCED_VERSION);
19621959
RtePackageInstanceInfo packInfo(nullptr, item.fromPack);
1963-
ci.SetPackageAttributes(packInfo);
1960+
ci->SetPackageAttributes(packInfo);
1961+
}
1962+
auto c = ResolveComponent(ci, context, item, componentMap, hint);
1963+
if(c) {
1964+
ci->InitInstance(c);
1965+
ci->SetResolvedComponent(c, context.rteActiveTarget->GetName());
1966+
}
1967+
ci->ConstructID();
1968+
return ci;
1969+
}
1970+
1971+
RteComponent* ProjMgrWorker::ResolveComponent(RteComponentInstance* ci, ContextItem& context, ComponentItem& item, RteComponentMap& componentMap, string& hint)
1972+
{
1973+
1974+
bool bEnforced = !item.condition.empty();
1975+
if(bEnforced) {
19641976
list<RteComponent*> components;
1965-
RteComponent* enforced = context.rteActiveTarget->GetFilteredModel()->FindComponents(ci, components);
1966-
if (enforced) {
1967-
return enforced;
1977+
RteComponent* rteComponent = context.rteActiveTarget->GetFilteredModel()->FindComponents(*ci, components);
1978+
if(rteComponent) {
1979+
return rteComponent;
19681980
}
19691981
}
19701982

@@ -2261,7 +2273,10 @@ bool ProjMgrWorker::ProcessComponentFiles(ContextItem& context) {
22612273
}
22622274
// iterate over components
22632275
for (const auto& [componentId, component] : context.components) {
2264-
RteComponent* rteComponent = component.instance->GetParent()->GetComponent();
2276+
RteComponent* rteComponent = component.instance->GetComponent();
2277+
if(!rteComponent) {
2278+
continue;
2279+
}
22652280
// component based API files
22662281
const auto& api = rteComponent->GetApi(context.rteActiveTarget, true);
22672282
if (api) {
@@ -2341,8 +2356,8 @@ bool ProjMgrWorker::ProcessComponentFiles(ContextItem& context) {
23412356
RteComponentInstance* rteBootstrapInstance = context.bootstrapComponents.find(componentId) != context.bootstrapComponents.end() ?
23422357
context.bootstrapMap.find(componentId) != context.bootstrapMap.end() ? context.bootstrapComponents.at(context.bootstrapMap.at(componentId)).instance :
23432358
context.bootstrapComponents.at(componentId).instance : nullptr;
2344-
if (rteBootstrapInstance != nullptr) {
2345-
RteComponent* rteBootstrapComponent = rteBootstrapInstance->GetParent()->GetComponent();
2359+
RteComponent* rteBootstrapComponent = rteBootstrapInstance ? rteBootstrapInstance->GetComponent() : nullptr;
2360+
if (rteBootstrapComponent != nullptr) {
23462361
const auto& files = rteBootstrapComponent->GetFileContainer() ? rteBootstrapComponent->GetFileContainer()->GetChildren() : Collection<RteItem*>();
23472362
for (const RteItem* rteFile : files) {
23482363
const auto& category = rteFile->GetAttribute("category");
@@ -2408,7 +2423,7 @@ void ProjMgrWorker::ValidateComponentSources(ContextItem& context) {
24082423
for (auto& file : files) {
24092424
if (file.category.compare(0, 6, "source") == 0 && file.name == filename) {
24102425
msg += "\n - component: " + componentID;
2411-
msg += "\n from-pack: " + context.components[componentID].instance->GetParent()->GetComponent()->GetPackageID();
2426+
msg += "\n from-pack: " + context.components[componentID].instance->GetComponent()->GetPackageID();
24122427
if (erase) {
24132428
files.erase(it);
24142429
} else {
@@ -2663,7 +2678,8 @@ bool ProjMgrWorker::ProcessGpdsc(ContextItem& context) {
26632678
} else if (gpdscComponent->GetTag() == "bundle") {
26642679
components = gpdscComponent->GetChildren();
26652680
}
2666-
for (const auto component : components) {
2681+
for (const auto c : components) {
2682+
auto component = c->GetComponent();
26672683
if (bootstrap.instance->GetComponentID(false) == component->GetComponentID(false)) {
26682684
if (VersionCmp::Compare(bootstrap.instance->GetVersionString(), component->GetVersionString()) > 0) {
26692685
// bootstrap has greater version, do not replace it
@@ -2673,8 +2689,9 @@ bool ProjMgrWorker::ProcessGpdsc(ContextItem& context) {
26732689
}
26742690
}
26752691
const auto& componentId = component->GetComponentID(true);
2676-
RteComponentInstance* componentInstance = new RteComponentInstance(component);
2692+
RteComponentInstance* componentInstance = new RteComponentInstance();
26772693
componentInstance->InitInstance(component);
2694+
componentInstance->SetResolvedComponent(component, context.rteActiveTarget->GetName());
26782695
componentInstance->AddAttribute("gendir", bootstrap.instance->GetAttribute("gendir"));
26792696
componentInstance->AddAttribute("rtedir", bootstrap.instance->GetAttribute("rtedir"));
26802697
context.components[componentId] = { componentInstance, bootstrap.item, component->GetGeneratorName() };
@@ -2701,16 +2718,33 @@ bool ProjMgrWorker::ProcessGpdsc(ContextItem& context) {
27012718
}
27022719
}
27032720
}
2704-
if (!gpdscInfos.empty() && !context.gpdscs.empty()) {
2721+
2722+
bool error = false;
2723+
if(!gpdscInfos.empty() && !context.gpdscs.empty()) {
27052724
// Update target with gpdsc model
2706-
if (!SetTargetAttributes(context, context.targetAttributes)) {
2707-
return false;
2725+
if(!SetTargetAttributes(context, context.targetAttributes)) {
2726+
error = true;
27082727
}
27092728
// Re-add required components into RTE
2710-
if (!AddRequiredComponents(context)) {
2711-
return false;
2729+
if(!AddRequiredComponents(context)) {
2730+
error = true;
27122731
}
27132732
}
2733+
2734+
if (!error && !CheckRteErrors()) {
2735+
error = true;
2736+
}
2737+
2738+
// tolerate component selection errors when in rpc mode
2739+
if (error && m_rpcMode) {
2740+
error = false;
2741+
}
2742+
2743+
return !error;
2744+
2745+
2746+
2747+
27142748
return CheckRteErrors();
27152749
}
27162750

0 commit comments

Comments
 (0)