Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List available API versions (#696) #1141

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libs/rtemodel/include/RteModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ class RteModel : public RteItem
*/
RteApi* GetLatestApi(const std::string& id) const;

/**
* @brief get available API versions for given common ID
* @param id API ID (version is ignored)
* @return list of available RteApi objects
*/
std::list<RteApi*> GetAvailableApis(const std::string& id) const;

/**
* @brief getter for collection of APIs
Expand Down
11 changes: 11 additions & 0 deletions libs/rtemodel/src/RteModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,17 @@ RteApi* RteModel::GetLatestApi(const string& id) const
return nullptr;
}

std::list<RteApi*> RteModel::GetAvailableApis(const std::string& id) const
{
std::list<RteApi*> apis;
string commonId = RteUtils::GetPrefix(id, RteConstants::PREFIX_CVERSION_CHAR);
for (auto [key, api] : m_apiList) {
if (RteUtils::GetPrefix(key, RteConstants::PREFIX_CVERSION_CHAR) == commonId) {
apis.push_back(api);
}
}
return apis;
}

RteBundle* RteModel::GetBundle(const string& id) const
{
Expand Down
19 changes: 12 additions & 7 deletions libs/rtemodel/src/RteProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2094,6 +2094,8 @@ bool RteProject::Validate()
RteTarget* target = GetActiveTarget();
if (!target)
return true; // nothing to do
RteModel* rteModel = target->GetFilteredModel();

target->ClearMissingPacks();

// check if all required gpdsc files are available
Expand Down Expand Up @@ -2236,18 +2238,21 @@ bool RteProject::Validate()
msg += "': API version '";
msg += apiVer;
msg += "' or compatible is required.";
RteApi* availableApi = c->GetApi(target, false);
if (availableApi) {
m_errors.push_back(msg);
list<RteApi*> availableApis = rteModel->GetAvailableApis(c->GetApiID(false));
for(RteApi* availableApi : availableApis) {
string availableApiVer = availableApi->GetApiVersionString();
msg += " (Version '";
msg = " Version '";
msg += availableApiVer;
msg += "' is found in pack '";
msg += availableApi->GetPackageID(true);
msg += "', install ";
msg += VersionCmp::Compare(apiVer, availableApiVer) < 0 ? "previous" : "next";
msg += " pack version).";
if (availableApis.size() == 1) {
msg += "', install ";
msg += VersionCmp::Compare(apiVer, availableApiVer) < 0 ? "previous" : "next";
msg += " pack version.";
}
m_errors.push_back(msg);
}
m_errors.push_back(msg);
} else if (apiResult == RteItem::CONFLICT) {
bValid = false;
RteApi* api = c->GetApi(target, true);
Expand Down
2 changes: 2 additions & 0 deletions libs/rtemodel/test/src/RteConditionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ TEST_F(RteConditionTest, MissingIgnoredFulfilledSelectable) {
{"Csub", "MissingApiVersion"} });
c = rteModel->FindFirstComponent(item);
ASSERT_NE(c, nullptr);
auto apis = rteModel->GetAvailableApis(c->GetApiID(true));
EXPECT_EQ(apis.size(), 3);
EXPECT_EQ(c->GetConditionResult(depSolver), RteItem::MISSING_API_VERSION);
activeTarget->SelectComponent(c, 1, true);
loadedCprjProject->Apply();
Expand Down
4 changes: 2 additions & 2 deletions libs/xmltree/src/XmlItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ bool XmlItem::RemoveAttribute(const char* name)
bool XmlItem::EraseAttributes(const std::string& pattern)
{
set<string> attributesToErase;
for (const auto [key, _] : m_attributes) {
for ( auto [key, _] : m_attributes) {
if (WildCards::Match(pattern, key)) {
attributesToErase.insert(key);
}
}
if (attributesToErase.empty()) {
return false;
}
for (const auto& key : attributesToErase) {
for ( auto& key : attributesToErase) {
RemoveAttribute(key);
}
return true;
Expand Down
Loading