|
4 | 4 | #include "ssLogger/ssLog.hpp" |
5 | 5 | #include "System2.h" |
6 | 6 |
|
7 | | -bool runcpp2::IsProfileAvailableOnSystem(const CompilerProfile& profile) |
| 7 | +namespace |
8 | 8 | { |
9 | | - //Check compiler |
10 | | - std::string command = profile.Compiler.Executable + " -v"; |
11 | | - |
12 | | - System2CommandInfo compilerCommandInfo; |
13 | | - SYSTEM2_RESULT sys2Result = System2Run(command.c_str(), &compilerCommandInfo); |
14 | | - |
15 | | - if(sys2Result != SYSTEM2_RESULT_SUCCESS) |
16 | | - { |
17 | | - ssLOG_ERROR("System2Run failed with result: " << sys2Result); |
18 | | - return false; |
19 | | - } |
20 | | - |
21 | | - int returnCode = 0; |
22 | | - sys2Result = System2GetCommandReturnValueSync(&compilerCommandInfo, &returnCode); |
23 | | - if(sys2Result != SYSTEM2_RESULT_SUCCESS) |
24 | | - { |
25 | | - ssLOG_ERROR("System2GetCommandReturnValueSync failed with result: " << sys2Result); |
26 | | - return false; |
27 | | - } |
28 | | - |
29 | | - if(returnCode != 0) |
30 | | - return false; |
31 | | - |
32 | | - //Check linker |
33 | | - command = profile.Linker.Executable + " -v"; |
34 | | - |
35 | | - System2CommandInfo linkerCommandInfo; |
36 | | - sys2Result = System2Run(command.c_str(), &linkerCommandInfo); |
37 | | - |
38 | | - if(sys2Result != SYSTEM2_RESULT_SUCCESS) |
39 | | - { |
40 | | - ssLOG_ERROR("System2Run failed with result: " << sys2Result); |
41 | | - return false; |
42 | | - } |
43 | | - |
44 | | - returnCode = 0; |
45 | | - sys2Result = System2GetCommandReturnValueSync(&linkerCommandInfo, &returnCode); |
46 | | - if(sys2Result != SYSTEM2_RESULT_SUCCESS) |
47 | | - { |
48 | | - ssLOG_ERROR("System2GetCommandReturnValueSync failed with result: " << sys2Result); |
49 | | - return false; |
50 | | - } |
51 | | - |
52 | | - if(returnCode != 0) |
53 | | - return false; |
54 | 9 |
|
55 | | - return true; |
56 | | -} |
57 | | - |
58 | | -bool runcpp2::IsProfileValidForScript( const CompilerProfile& profile, |
59 | | - const ScriptInfo& scriptInfo, |
60 | | - const std::string& scriptPath) |
61 | | -{ |
62 | | - std::string scriptExtension = ghc::filesystem::path(scriptPath).extension().string(); |
63 | | - |
64 | | - if(profile.FileExtensions.find(scriptExtension.substr(1)) == profile.FileExtensions.end()) |
65 | | - return false; |
66 | | - |
67 | | - if(!scriptInfo.Language.empty()) |
| 10 | + bool IsProfileAvailableOnSystem(const runcpp2::CompilerProfile& profile) |
68 | 11 | { |
69 | | - if(profile.Languages.find(scriptInfo.Language) == profile.Languages.end()) |
| 12 | + //Check compiler |
| 13 | + std::string command = profile.Compiler.Executable + " -v"; |
| 14 | + |
| 15 | + System2CommandInfo compilerCommandInfo; |
| 16 | + SYSTEM2_RESULT sys2Result = System2Run(command.c_str(), &compilerCommandInfo); |
| 17 | + |
| 18 | + if(sys2Result != SYSTEM2_RESULT_SUCCESS) |
| 19 | + { |
| 20 | + ssLOG_ERROR("System2Run failed with result: " << sys2Result); |
70 | 21 | return false; |
| 22 | + } |
| 23 | + |
| 24 | + int returnCode = 0; |
| 25 | + sys2Result = System2GetCommandReturnValueSync(&compilerCommandInfo, &returnCode); |
| 26 | + if(sys2Result != SYSTEM2_RESULT_SUCCESS) |
| 27 | + { |
| 28 | + ssLOG_ERROR("System2GetCommandReturnValueSync failed with result: " << sys2Result); |
| 29 | + return false; |
| 30 | + } |
| 31 | + |
| 32 | + if(returnCode != 0) |
| 33 | + return false; |
| 34 | + |
| 35 | + //Check linker |
| 36 | + command = profile.Linker.Executable + " -v"; |
| 37 | + |
| 38 | + System2CommandInfo linkerCommandInfo; |
| 39 | + sys2Result = System2Run(command.c_str(), &linkerCommandInfo); |
| 40 | + |
| 41 | + if(sys2Result != SYSTEM2_RESULT_SUCCESS) |
| 42 | + { |
| 43 | + ssLOG_ERROR("System2Run failed with result: " << sys2Result); |
| 44 | + return false; |
| 45 | + } |
| 46 | + |
| 47 | + returnCode = 0; |
| 48 | + sys2Result = System2GetCommandReturnValueSync(&linkerCommandInfo, &returnCode); |
| 49 | + if(sys2Result != SYSTEM2_RESULT_SUCCESS) |
| 50 | + { |
| 51 | + ssLOG_ERROR("System2GetCommandReturnValueSync failed with result: " << sys2Result); |
| 52 | + return false; |
| 53 | + } |
| 54 | + |
| 55 | + if(returnCode != 0) |
| 56 | + return false; |
| 57 | + |
| 58 | + return true; |
71 | 59 | } |
72 | | - |
73 | | - if(!scriptInfo.RequiredProfiles.empty()) |
| 60 | + |
| 61 | + bool IsProfileValidForScript( const runcpp2::CompilerProfile& profile, |
| 62 | + const runcpp2::ScriptInfo& scriptInfo, |
| 63 | + const std::string& scriptPath) |
74 | 64 | { |
75 | | - std::vector<PlatformName> platformNames = Internal::GetPlatformNames(); |
| 65 | + std::string scriptExtension = ghc::filesystem::path(scriptPath).extension().string(); |
76 | 66 |
|
77 | | - for(int i = 0; i < platformNames.size(); ++i) |
| 67 | + if(profile.FileExtensions.find(scriptExtension.substr(1)) == profile.FileExtensions.end()) |
| 68 | + return false; |
| 69 | + |
| 70 | + if(!scriptInfo.Language.empty()) |
78 | 71 | { |
79 | | - if(scriptInfo.RequiredProfiles.find(platformNames.at(i)) == scriptInfo.RequiredProfiles.end()) |
80 | | - continue; |
| 72 | + if(profile.Languages.find(scriptInfo.Language) == profile.Languages.end()) |
| 73 | + return false; |
| 74 | + } |
| 75 | + |
| 76 | + if(!scriptInfo.RequiredProfiles.empty()) |
| 77 | + { |
| 78 | + std::vector<PlatformName> platformNames = runcpp2::GetPlatformNames(); |
81 | 79 |
|
82 | | - const std::vector<ProfileName> allowedProfileNames = scriptInfo .RequiredProfiles |
83 | | - .at(platformNames.at(i)); |
84 | | - |
85 | | - for(int j = 0; j < allowedProfileNames.size(); ++j) |
| 80 | + for(int i = 0; i < platformNames.size(); ++i) |
86 | 81 | { |
87 | | - if(allowedProfileNames.at(j) == profile.Name) |
88 | | - return true; |
| 82 | + if(scriptInfo.RequiredProfiles.find(platformNames.at(i)) == scriptInfo.RequiredProfiles.end()) |
| 83 | + continue; |
| 84 | + |
| 85 | + const std::vector<ProfileName> allowedProfileNames = scriptInfo .RequiredProfiles |
| 86 | + .at(platformNames.at(i)); |
| 87 | + |
| 88 | + for(int j = 0; j < allowedProfileNames.size(); ++j) |
| 89 | + { |
| 90 | + if(allowedProfileNames.at(j) == profile.Name) |
| 91 | + return true; |
| 92 | + } |
| 93 | + |
| 94 | + //If we went through all the specified profile names, exit |
| 95 | + return false; |
89 | 96 | } |
90 | 97 |
|
91 | | - //If we went through all the specified profile names, exit |
| 98 | + //If we went through all the specified platform names for required profiles, exit |
92 | 99 | return false; |
93 | 100 | } |
94 | 101 |
|
95 | | - //If we went through all the specified platform names for required profiles, exit |
96 | | - return false; |
| 102 | + return true; |
97 | 103 | } |
98 | | - |
99 | | - return true; |
100 | | -} |
101 | 104 |
|
102 | | -std::vector<ProfileName> runcpp2::GetAvailableProfiles( const std::vector<CompilerProfile>& profiles, |
103 | | - const ScriptInfo& scriptInfo, |
104 | | - const std::string& scriptPath) |
105 | | -{ |
106 | | - //Check which compiler is available |
107 | | - std::vector<ProfileName> availableProfiles; |
108 | | - |
109 | | - for(int i = 0; i < profiles.size(); ++i) |
| 105 | + std::vector<ProfileName> GetAvailableProfiles( const std::vector<runcpp2::CompilerProfile>& profiles, |
| 106 | + const runcpp2::ScriptInfo& scriptInfo, |
| 107 | + const std::string& scriptPath) |
110 | 108 | { |
111 | | - if(IsProfileAvailableOnSystem(profiles.at(i)) && IsProfileValidForScript( profiles.at(i), |
112 | | - scriptInfo, |
113 | | - scriptPath)) |
| 109 | + //Check which compiler is available |
| 110 | + std::vector<ProfileName> availableProfiles; |
| 111 | + |
| 112 | + for(int i = 0; i < profiles.size(); ++i) |
114 | 113 | { |
115 | | - availableProfiles.push_back(profiles.at(i).Name); |
| 114 | + if(IsProfileAvailableOnSystem(profiles.at(i)) && IsProfileValidForScript( profiles.at(i), |
| 115 | + scriptInfo, |
| 116 | + scriptPath)) |
| 117 | + { |
| 118 | + availableProfiles.push_back(profiles.at(i).Name); |
| 119 | + } |
116 | 120 | } |
| 121 | + |
| 122 | + return availableProfiles; |
117 | 123 | } |
118 | | - |
119 | | - return availableProfiles; |
120 | 124 | } |
121 | 125 |
|
122 | 126 |
|
|
0 commit comments