Skip to content

Commit

Permalink
[projmgr] Check created-for: with version number
Browse files Browse the repository at this point in the history
  • Loading branch information
grasci-arm authored Jun 13, 2024
1 parent d989870 commit 17b2ab1
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 3 deletions.
1 change: 1 addition & 0 deletions tools/projmgr/include/ProjMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class ProjMgr {
bool RunListEnvironment();
bool PopulateContexts();
bool SetLoadPacksPolicy();
bool ValidateCreatedFor(const std::string& createdFor);

bool Configure();
bool GenerateYMLConfigurationFiles();
Expand Down
4 changes: 3 additions & 1 deletion tools/projmgr/include/ProjMgrParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,9 @@ struct CdefaultItem {
* @brief solution item containing
* csolution name,
* csolution path,
* csolution directory,
* csolution description,
* csolution directory,
* created-for string,
* output directories,
* build types,
* target types,
Expand All @@ -403,6 +404,7 @@ struct CsolutionItem {
std::string path;
std::string description;
std::string directory;
std::string createdFor;
DirectoriesItem directories;
std::map<std::string, BuildType> buildTypes;
std::map<std::string, TargetType> targetTypes;
Expand Down
30 changes: 30 additions & 0 deletions tools/projmgr/src/ProjMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ bool ProjMgr::PopulateContexts(void) {
if (!m_parser.ParseCsolution(m_csolutionFile, m_checkSchema, m_frozenPacks)) {
return false;
}
// Check created-for requirement
if (!ValidateCreatedFor(m_parser.GetCsolution().createdFor)) {
return false;
}
// Parse cdefault
if (m_parser.GetCsolution().enableCdefault && GetCdefaultFile()) {
if (!m_parser.ParseCdefault(m_cdefaultFile, m_checkSchema)) {
Expand Down Expand Up @@ -1015,3 +1019,29 @@ bool ProjMgr::GetCdefaultFile(void) {
m_cdefaultFile = cdefaultFile;
return true;
}

bool ProjMgr::ValidateCreatedFor(const string& createdFor) {
if (!createdFor.empty()) {
map<string, map<string, string>> registeredToolchains;
static const regex regEx = regex("(.*)@(\\d+)\\.(\\d+)\\.(\\d+)");
smatch sm;
if (regex_match(createdFor, sm, regEx)) {
string toolName = string(sm[1]);
transform(toolName.begin(), toolName.end(), toolName.begin(), [](unsigned char c) {
return std::tolower(c);
});
if (toolName == "cmsis-toolbox") {
const string version = string(sm[2]) + '.' + string(sm[3]) + '.' + string(sm[4]);
const string currentVersion = string(VERSION_STRING) + ':' + string(VERSION_STRING);
if (VersionCmp::RangeCompare(version, currentVersion) <= 0) {
return true;
} else {
ProjMgrLogger::Error(m_csolutionFile, "solution requires newer CMSIS-Toolbox version " + version);
return false;
}
}
}
ProjMgrLogger::Warn(m_csolutionFile, "solution created for unknown tool: " + createdFor);
}
return true;
}
1 change: 1 addition & 0 deletions tools/projmgr/src/ProjMgrYamlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ bool ProjMgrYamlParser::ParseCsolution(const string& input,

const YAML::Node& solutionNode = root[YAML_SOLUTION];
ParseString(solutionNode, YAML_DESCRIPTION, csolution.description);
ParseString(solutionNode, YAML_CREATED_FOR, csolution.createdFor);
if (!ParseContexts(solutionNode, csolution)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json

solution:
created-for: CMSIS-Toolbox@2.2.1
created-for: CMSIS-Toolbox@0.0.0
cdefault:

packs:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json

solution:
created-for: CMSIS-Toolbox@2.2.1
created-for: CMSIS-Toolbox@0.0.0
cdefault:

packs:
Expand Down
14 changes: 14 additions & 0 deletions tools/projmgr/test/data/TestSolution/created-for.csolution.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json

solution:
created-for: [email protected]

target-types:
- type: CM0
device: RteTest_ARMCM0

packs:
- pack: ARM::[email protected]

projects:
- project: ./TestProject1/test1.cproject.yml
35 changes: 35 additions & 0 deletions tools/projmgr/test/src/ProjMgrUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5763,3 +5763,38 @@ TEST_F(ProjMgrUnitTests, TestRestrictedContextsWithContextSet_Pass) {

EXPECT_EQ(0, RunProjMgr(10, argv, m_envp));
}

TEST_F(ProjMgrUnitTests, ValidateCreatedFor) {
const vector<tuple<string, string, bool>> testData = {
{ "[email protected]", "error" , false },
{ "[email protected]", "warning", true },
{ "[email protected]", "" , true },
{ "" , "" , true },
{ "Unknown" , "warning", true },
};
StdStreamRedirect streamRedirect;
for (const auto& [createdFor, expectedMsg, expectedReturn] : testData) {
streamRedirect.ClearStringStreams();
EXPECT_EQ(expectedReturn, ValidateCreatedFor(createdFor));
auto errMsg = streamRedirect.GetErrorString();
if (expectedMsg.empty()) {
EXPECT_EQ(RteUtils::EMPTY_STRING, errMsg);
} else {
EXPECT_NE(string::npos, errMsg.find(expectedMsg));
}
}
}

TEST_F(ProjMgrUnitTests, FailCreatedFor) {
char* argv[5];
StdStreamRedirect streamRedirect;
const string& csolution = testinput_folder + "/TestSolution/created-for.csolution.yml";
const string& expectedErrMsg = "error csolution: solution requires newer CMSIS-Toolbox version 9.9.9";
argv[1] = (char*)"convert";
argv[2] = (char*)csolution.c_str();
argv[3] = (char*)"--output";
argv[4] = (char*)testoutput_folder.c_str();
EXPECT_EQ(1, RunProjMgr(5, argv, 0));
auto errMsg = streamRedirect.GetErrorString();
EXPECT_NE(string::npos, errMsg.find(expectedErrMsg));
}

0 comments on commit 17b2ab1

Please sign in to comment.