Skip to content

Commit d2240ff

Browse files
authored
[projmgr] Add download-url into error reporting for external generator failures
1 parent 95ace1c commit d2240ff

9 files changed

Lines changed: 82 additions & 7 deletions

File tree

libs/rtemodel/test/src/RteChkTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ Generic: 4\n\
3030
DFP: 3\n\
3131
BSP: 1\n\
3232
\n\
33-
Components: 60\n\
33+
Components: 61\n\
3434
From generic packs: 36\n\
35-
From DFP: 24\n\
35+
From DFP: 25\n\
3636
From BSP: 0\n\
3737
\n\
3838
Devices: 10\n\
@@ -51,7 +51,7 @@ completed\n";
5151
int res = rteChk.RunCheckRte();
5252
EXPECT_EQ(res, 0);
5353
EXPECT_EQ(rteChk.GetPackCount(), 8);
54-
EXPECT_EQ(rteChk.GetComponentCount(), 60);
54+
EXPECT_EQ(rteChk.GetComponentCount(), 61);
5555
EXPECT_EQ(rteChk.GetDeviceCount(), 10);
5656
EXPECT_EQ(rteChk.GetBoardCount(), 15);
5757

test/packs/ARM/RteTestGenerator/0.1.0/ARM.RteTestGenerator.pdsc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,17 @@
185185
<description>Configuration via RteTest script</description>
186186
</component>
187187
<component generator="RteTestExternalGenerator" Cclass="RteTestGenerator" Cgroup="Check Global Generator" Cversion="0.9.0">
188-
<description>Component addressing external</description>
188+
<description>Component addressing external generator</description>
189189
<files>
190190
<file category="header" name="Include/RteTestInc.h" version ="1.0.0"/>
191191
<file category="genAsset" name="Templates/RteTest.gpdsc.template" version ="1.0.0"/>
192192
<file category="genHeader" name="Templates/RteTestGen.h.template" version ="1.0.0"/>
193193
<file category="genSource" name="Templates/RteTestGen.c.template" version ="1.0.0"/>
194194
<file category="genParams" name="Generator with spaces/RteTestGen.params" version ="0.9.0" attr="config"/>
195195
</files>
196+
</component>
197+
<component generator="RteTestExternalGeneratorNoUrl" Cclass="RteTestGeneratorNoUrl" Cgroup="Check Global Generator" Cversion="0.9.0">
198+
<description>Component addressing external generator without URL</description>
196199
</component>
197200
<component generator="RteTestGeneratorIdentifier" Cvendor="ARM" Cclass="Device" Cgroup="RteTest Generated Component" Csub="RteTestOverlap" Cversion="1.1.0">
198201
<description>Component with overlaping file lists</description>

tools/projmgr/include/ProjMgrExtGenerator.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ class ProjMgrExtGenerator {
7373
*/
7474
const std::string& GetGlobalGenRunCmd(const std::string& generatorId);
7575

76+
/**
77+
* @brief get URL for generator download
78+
* @param generatorId generator identifier
79+
* @return string with URL for generator download
80+
*/
81+
const std::string& GetGlobalGenUrl(const std::string& generatorId);
82+
7683
/**
7784
* @brief get generator description
7885
* @param generatorId generator identifier

tools/projmgr/src/ProjMgrExtGenerator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ const string& ProjMgrExtGenerator::GetGlobalGenRunCmd(const string& generatorId)
4949
return g ? g->GetRunAttribute() : RteUtils::EMPTY_STRING;
5050
}
5151

52+
const string& ProjMgrExtGenerator::GetGlobalGenUrl(const string& generatorId) {
53+
RteGenerator* g = ProjMgrKernel::Get()->GetExternalGenerator(generatorId);
54+
return g ? g->GetURL() : RteUtils::EMPTY_STRING;
55+
}
56+
5257
const string& ProjMgrExtGenerator::GetGlobalDescription(const string& generatorId) {
5358
RteGenerator* g = ProjMgrKernel::Get()->GetExternalGenerator(generatorId);
5459
return g ? g->GetDescription() : RteUtils::EMPTY_STRING;

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5650,11 +5650,22 @@ bool ProjMgrWorker::ExecuteExtGenerator(std::string& generatorId) {
56505650
fs::current_path(genDir, ec);
56515651
StrIntPair result = CrossPlatformUtils::ExecCommand(runCmd);
56525652
fs::current_path(workingDir, ec);
5653-
ProjMgrLogger::Get().Info("generator '" + generatorId + "' for context '" + selectedContextId + "' reported:\n" + result.first);
56545653
if (result.second) {
5655-
ProjMgrLogger::Get().Error("executing generator '" + generatorId + "' for context '" + selectedContextId + "' failed");
5654+
string errMsg = "executing generator '" + generatorId + "' for context '" + selectedContextId + "' failed:\n";
5655+
errMsg += " " + result.first;
5656+
5657+
const string downloadUrl = m_extGenerator->GetGlobalGenUrl(generatorId);
5658+
if (!downloadUrl.empty()) {
5659+
errMsg += " check the URL for downloading the generator: " + downloadUrl;
5660+
} else {
5661+
errMsg += " download URL is not available for generator '" + generatorId + "' in generator.yml";
5662+
}
5663+
ProjMgrLogger::Get().Error(errMsg);
56565664
return false;
5665+
} else {
5666+
ProjMgrLogger::Get().Info("generator '" + generatorId + "' for context '" + selectedContextId + "' reported:\n " + result.first);
56575667
}
5668+
56585669
return true;
56595670
}
56605671

tools/projmgr/test/data/ExternalGenerator/extgen.csolution.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ solution:
2424
for-context: +CM0
2525
- project: tz_ns/ns.cproject.yml
2626
for-context: +CM0
27+
- project: test-url/test-url.cproject.yml
28+
for-context: +CM0
2729
- project: multi_0/core0.cproject.yml
2830
for-context: +MultiCore
2931
- project: multi_1/core1.cproject.yml

tools/projmgr/test/data/ExternalGenerator/global.generator.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ generator:
44
download-url: https://raw.githubusercontent.com/Open-CMSIS-Pack
55
run: ../bin/bridge tool.sh
66
path: $SolutionDir()$/generated/$TargetType$
7+
- id: RteTestExternalGeneratorNoUrl
8+
description: Global Registered Generator Without Url
9+
run: ../bin/bridge tool.sh
10+
path: $SolutionDir()$/generated/$TargetType$
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/cproject.schema.json
2+
3+
project:
4+
components:
5+
- component: RteTestGeneratorNoUrl:Check Global Generator
6+
7+
generators:
8+
options:
9+
- generator: RteTestExternalGeneratorNoUrl
10+
path: $ProjectDir()$/generated/

tools/projmgr/test/src/ProjMgrUnitTests.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4025,7 +4025,8 @@ TEST_F(ProjMgrUnitTests, ListComponents_MultiplePackSelection) {
40254025
"ARM::Device:RteTest Generated Component:RteTestWithKey@1.1.0 (ARM::RteTestGenerator@0.1.0)",
40264026
"ARM::Device:RteTest Generated Component:RteTestNoExe@1.1.0 (ARM::RteTestGenerator@0.1.0)",
40274027
"ARM::Device:RteTest Generated Component:RteTestOverlap@1.1.0 (ARM::RteTestGenerator@0.1.0)",
4028-
"ARM::RteTestGenerator:Check Global Generator@0.9.0 (ARM::RteTestGenerator@0.1.0)"
4028+
"ARM::RteTestGenerator:Check Global Generator@0.9.0 (ARM::RteTestGenerator@0.1.0)",
4029+
"ARM::RteTestGeneratorNoUrl:Check Global Generator@0.9.0 (ARM::RteTestGenerator@0.1.0)"
40294030
};
40304031
vector<string> components;
40314032
m_csolutionFile = testinput_folder + "/TestSolution/pack_contexts.csolution.yml";
@@ -5704,6 +5705,38 @@ TEST_F(ProjMgrUnitTests, ExternalGenerator_NoCgenFile) {
57045705
RteFsUtils::RemoveFile(dstGlobalGenerator);
57055706
}
57065707

5708+
TEST_F(ProjMgrUnitTests, ExternalGenerator_PrintUrl) {
5709+
const string& srcGlobalGenerator = testinput_folder + "/ExternalGenerator/global.generator.yml";
5710+
const string& dstGlobalGenerator = etc_folder + "/global.generator.yml";
5711+
RteFsUtils::CopyCheckFile(srcGlobalGenerator, dstGlobalGenerator, false);
5712+
5713+
StdStreamRedirect streamRedirect;
5714+
// test case where the URL returns an exit code of 1 (simulated by not copying the 'bridge tool.sh' script)
5715+
char* argv[7];
5716+
const string& csolution = testinput_folder + "/ExternalGenerator/extgen.csolution.yml";
5717+
argv[1] = (char*)csolution.c_str();
5718+
argv[2] = (char*)"run";
5719+
argv[3] = (char*)"-g";
5720+
argv[4] = (char*)"RteTestExternalGenerator";
5721+
argv[5] = (char*)"-c";
5722+
argv[6] = (char*)"single-core.Debug+CM0";
5723+
EXPECT_EQ(1, RunProjMgr(7, argv, m_envp));
5724+
string errStr = streamRedirect.GetErrorString();
5725+
string errExpected = " check the URL for downloading the generator: https://raw.githubusercontent.com/Open-CMSIS-Pack";
5726+
EXPECT_NE(string::npos, errStr.find(errExpected));
5727+
5728+
streamRedirect.ClearStringStreams();
5729+
// test case where the download-url is missing of a generator
5730+
argv[4] = (char*)"RteTestExternalGeneratorNoUrl";
5731+
argv[6] = (char*)"test-url.Debug+CM0";
5732+
EXPECT_EQ(1, RunProjMgr(7, argv, m_envp));
5733+
errStr = streamRedirect.GetErrorString();
5734+
errExpected = " download URL is not available for generator '" + string(argv[4]) + "' in generator.yml";
5735+
EXPECT_NE(string::npos, errStr.find(errExpected));
5736+
5737+
RteFsUtils::RemoveFile(dstGlobalGenerator);
5738+
}
5739+
57075740
TEST_F(ProjMgrUnitTests, ExternalGeneratorBoard) {
57085741
const string& srcGlobalGenerator = testinput_folder + "/ExternalGenerator/global.generator.yml";
57095742
const string& dstGlobalGenerator = etc_folder + "/global.generator.yml";

0 commit comments

Comments
 (0)