Skip to content

Commit dd369a3

Browse files
Running global setup and cleanup when checking existence for profile
1 parent 80592f0 commit dd369a3

File tree

1 file changed

+59
-12
lines changed

1 file changed

+59
-12
lines changed

Src/runcpp2/ProfileHelper.cpp

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,60 @@ namespace
77
{
88
bool IsProfileAvailableOnSystem(const runcpp2::Data::Profile& profile)
99
{
10+
if(!runcpp2::HasValueFromPlatformMap(profile.Compiler.CheckExistence))
11+
{
12+
ssLOG_INFO( "Compiler for profile " << profile.Name <<
13+
" does not have CheckExistence for current platform");
14+
return false;
15+
}
16+
17+
if(!runcpp2::HasValueFromPlatformMap(profile.Linker.CheckExistence))
18+
{
19+
ssLOG_INFO( "Linker for profile " << profile.Name <<
20+
" does not have CheckExistence for current platform");
21+
return false;
22+
}
23+
24+
//Global cleanup
25+
auto runCleanup = [&profile]() -> bool
26+
{
27+
if(runcpp2::HasValueFromPlatformMap(profile.Cleanup))
28+
{
29+
const std::vector<std::string>& cleanupSteps =
30+
*runcpp2::GetValueFromPlatformMap(profile.Cleanup);
31+
32+
for(int i = 0; i < cleanupSteps.size(); ++i)
33+
{
34+
std::string output;
35+
if(!runcpp2::RunCommandAndGetOutput(cleanupSteps.at(i), output))
36+
{
37+
ssLOG_INFO("Failed to run cleanup for " << profile.Name);
38+
return false;
39+
}
40+
}
41+
}
42+
43+
return true;
44+
};
45+
46+
//Global setup
47+
if(runcpp2::HasValueFromPlatformMap(profile.Setup))
48+
{
49+
const std::vector<std::string>& setupSteps =
50+
*runcpp2::GetValueFromPlatformMap(profile.Setup);
51+
52+
for(int i = 0; i < setupSteps.size(); ++i)
53+
{
54+
std::string output;
55+
if(!runcpp2::RunCommandAndGetOutput(setupSteps.at(i), output))
56+
{
57+
ssLOG_INFO("Failed to run setup for " << profile.Name);
58+
runCleanup();
59+
return false;
60+
}
61+
}
62+
}
63+
1064
//Check compiler
1165
{
1266
//Getting PreRun command
@@ -19,18 +73,13 @@ namespace
1973
command += " && ";
2074
}
2175

22-
if(!runcpp2::HasValueFromPlatformMap(profile.Compiler.CheckExistence))
23-
{
24-
ssLOG_INFO( "Compiler for profile " << profile.Name <<
25-
" does not have CheckExistence for current platform");
26-
return false;
27-
}
2876
command += *runcpp2::GetValueFromPlatformMap(profile.Compiler.CheckExistence);
2977

3078
std::string output;
3179
if(!runcpp2::RunCommandAndGetOutput(command, output))
3280
{
3381
ssLOG_INFO("Failed to find compiler for profile " << profile.Name);
82+
runCleanup();
3483
return false;
3584
}
3685
}
@@ -47,22 +96,20 @@ namespace
4796
command += " && ";
4897
}
4998

50-
if(!runcpp2::HasValueFromPlatformMap(profile.Linker.CheckExistence))
51-
{
52-
ssLOG_INFO( "Linker for profile " << profile.Name <<
53-
" does not have CheckExistence for current platform");
54-
return false;
55-
}
5699
command += *runcpp2::GetValueFromPlatformMap(profile.Linker.CheckExistence);
57100

58101
std::string output;
59102
if(!runcpp2::RunCommandAndGetOutput(command, output))
60103
{
61104
ssLOG_INFO("Failed to find linker for profile " << profile.Name);
105+
runCleanup();
62106
return false;
63107
}
64108
}
65109

110+
if(!runCleanup())
111+
return false;
112+
66113
return true;
67114
}
68115

0 commit comments

Comments
 (0)