Skip to content

Commit 599e3b8

Browse files
Using environment setup for checking compiler and linker
1 parent 1fbc29c commit 599e3b8

File tree

1 file changed

+63
-42
lines changed

1 file changed

+63
-42
lines changed

Src/runcpp2/ProfileHelper.cpp

Lines changed: 63 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,79 @@
44
#include "ssLogger/ssLog.hpp"
55
#include "System2.h"
66

7-
namespace
7+
namespace
88
{
9-
109
bool IsProfileAvailableOnSystem(const runcpp2::Data::Profile& profile)
1110
{
1211
//Check compiler
13-
std::string command = profile.Compiler.Executable + " -v";
14-
15-
System2CommandInfo compilerCommandInfo = {};
16-
compilerCommandInfo.RedirectOutput = true;
17-
SYSTEM2_RESULT sys2Result = System2Run(command.c_str(), &compilerCommandInfo);
18-
19-
if(sys2Result != SYSTEM2_RESULT_SUCCESS)
2012
{
21-
ssLOG_ERROR("System2Run failed with result: " << sys2Result);
22-
return false;
23-
}
24-
25-
int returnCode = 0;
26-
sys2Result = System2GetCommandReturnValueSync(&compilerCommandInfo, &returnCode);
27-
if(sys2Result != SYSTEM2_RESULT_SUCCESS)
28-
{
29-
ssLOG_ERROR("System2GetCommandReturnValueSync failed with result: " << sys2Result);
30-
return false;
13+
//Getting EnvironmentSetup command
14+
std::string command;
15+
{
16+
command = runcpp2::HasValueFromPlatformMap(profile.Compiler.EnvironmentSetup) ?
17+
*runcpp2::GetValueFromPlatformMap(profile.Compiler.EnvironmentSetup) : "";
18+
19+
if(!command.empty())
20+
command += " && ";
21+
}
22+
23+
command += profile.Compiler.Executable + " -v";
24+
System2CommandInfo compilerCommandInfo = {};
25+
compilerCommandInfo.RedirectOutput = true;
26+
SYSTEM2_RESULT sys2Result = System2Run(command.c_str(), &compilerCommandInfo);
27+
28+
if(sys2Result != SYSTEM2_RESULT_SUCCESS)
29+
{
30+
ssLOG_ERROR("System2Run failed with result: " << sys2Result);
31+
return false;
32+
}
33+
34+
int returnCode = 0;
35+
sys2Result = System2GetCommandReturnValueSync(&compilerCommandInfo, &returnCode);
36+
if(sys2Result != SYSTEM2_RESULT_SUCCESS)
37+
{
38+
ssLOG_ERROR("System2GetCommandReturnValueSync failed with result: " << sys2Result);
39+
return false;
40+
}
41+
42+
if(returnCode != 0)
43+
return false;
3144
}
3245

33-
if(returnCode != 0)
34-
return false;
35-
3646
//Check linker
37-
command = profile.Linker.Executable + " -v";
38-
39-
System2CommandInfo linkerCommandInfo = {};
40-
linkerCommandInfo.RedirectOutput = true;
41-
sys2Result = System2Run(command.c_str(), &linkerCommandInfo);
42-
43-
if(sys2Result != SYSTEM2_RESULT_SUCCESS)
44-
{
45-
ssLOG_ERROR("System2Run failed with result: " << sys2Result);
46-
return false;
47-
}
48-
49-
returnCode = 0;
50-
sys2Result = System2GetCommandReturnValueSync(&linkerCommandInfo, &returnCode);
51-
if(sys2Result != SYSTEM2_RESULT_SUCCESS)
5247
{
53-
ssLOG_ERROR("System2GetCommandReturnValueSync failed with result: " << sys2Result);
54-
return false;
48+
//Getting EnvironmentSetup command
49+
std::string command;
50+
{
51+
command = runcpp2::HasValueFromPlatformMap(profile.Compiler.EnvironmentSetup) ?
52+
*runcpp2::GetValueFromPlatformMap(profile.Compiler.EnvironmentSetup) : "";
53+
54+
if(!command.empty())
55+
command += " && ";
56+
}
57+
58+
command += profile.Linker.Executable + " -v";
59+
System2CommandInfo linkerCommandInfo = {};
60+
linkerCommandInfo.RedirectOutput = true;
61+
SYSTEM2_RESULT sys2Result = System2Run(command.c_str(), &linkerCommandInfo);
62+
63+
if(sys2Result != SYSTEM2_RESULT_SUCCESS)
64+
{
65+
ssLOG_ERROR("System2Run failed with result: " << sys2Result);
66+
return false;
67+
}
68+
69+
int returnCode = 0;
70+
sys2Result = System2GetCommandReturnValueSync(&linkerCommandInfo, &returnCode);
71+
if(sys2Result != SYSTEM2_RESULT_SUCCESS)
72+
{
73+
ssLOG_ERROR("System2GetCommandReturnValueSync failed with result: " << sys2Result);
74+
return false;
75+
}
76+
77+
if(returnCode != 0)
78+
return false;
5579
}
56-
57-
if(returnCode != 0)
58-
return false;
5980

6081
return true;
6182
}

0 commit comments

Comments
 (0)