Skip to content

Commit 2ddcb34

Browse files
Updating parsing for OverrideFlags
1 parent 5d960e4 commit 2ddcb34

File tree

7 files changed

+167
-45
lines changed

7 files changed

+167
-45
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ if(RUNCPP2_UPDATE_DEFAULT_YAMLS OR EMBEDDED_FILE_SIZE LESS 1024)
3838
message(WARNING "Please build Embed2C first")
3939
return()
4040
else()
41-
set(FILES_TO_EMBED "${CMAKE_CURRENT_LIST_DIR}/DefaultYAMLs/DefaultCompilerProfiles.yaml"
42-
"DefaultCompilerProfiles"
41+
set(FILES_TO_EMBED "${CMAKE_CURRENT_LIST_DIR}/DefaultYAMLs/DefaultUserConfig.yaml"
42+
"DefaultUserConfig"
4343
"${CMAKE_CURRENT_LIST_DIR}/DefaultYAMLs/DefaultScriptInfo.yaml"
4444
"DefaultScriptInfo"
4545
)
@@ -78,6 +78,7 @@ add_executable(runcpp2 "${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/CompilerInfo
7878
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/DependencySetup.cpp"
7979
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/DependencySource.cpp"
8080
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/FlagsOverrideInfo.cpp"
81+
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/ProfilesFlagsOverride.cpp"
8182
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/LinkerInfo.cpp"
8283
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/ScriptInfo.cpp"
8384
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/CompilerProfileHelper.cpp"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef RUNCPP2_DATA_PROFILES_FLAGS_OVERRIDE_HPP
2+
#define RUNCPP2_DATA_PROFILES_FLAGS_OVERRIDE_HPP
3+
4+
#include "FlagsOverrideInfo.hpp"
5+
#include "runcpp2/Data/ParseCommon.hpp"
6+
#include <unordered_map>
7+
8+
namespace runcpp2
9+
{
10+
namespace Data
11+
{
12+
class ProfilesFlagsOverride
13+
{
14+
public:
15+
std::unordered_map<ProfileName, FlagsOverrideInfo> FlagsOverrides;
16+
17+
bool ParseYAML_Node(ryml::ConstNodeRef& node);
18+
std::string ToString(std::string indentation) const;
19+
};
20+
}
21+
}
22+
23+
#endif

Include/runcpp2/Data/ScriptInfo.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define RUNCPP2_DATA_SCRIPT_INFO_HPP
33

44
#include "runcpp2/Data/DependencyInfo.hpp"
5-
#include "runcpp2/Data/FlagsOverrideInfo.hpp"
5+
#include "runcpp2/Data/ProfilesFlagsOverride.hpp"
66
#include "runcpp2/Data/ParseCommon.hpp"
77

88
#include <string>
@@ -19,8 +19,8 @@ namespace runcpp2
1919
std::string Language;
2020
std::unordered_map<PlatformName, std::vector<ProfileName>> RequiredProfiles;
2121

22-
std::unordered_map<ProfileName, FlagsOverrideInfo> OverrideCompileFlags;
23-
std::unordered_map<ProfileName, FlagsOverrideInfo> OverrideLinkFlags;
22+
std::unordered_map<PlatformName, ProfilesFlagsOverride> OverrideCompileFlags;
23+
std::unordered_map<PlatformName, ProfilesFlagsOverride> OverrideLinkFlags;
2424

2525
std::vector<DependencyInfo> Dependencies;
2626

Src/runcpp2/CompilingLinking.cpp

Lines changed: 80 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,53 @@ namespace
3232
}
3333

3434
//Override the compile flags from the script info
35-
if(scriptInfo.OverrideCompileFlags.find(profile.Name) != scriptInfo.OverrideCompileFlags.end())
3635
{
37-
std::vector<std::string> compileArgsToRemove;
38-
runcpp2::SplitString( scriptInfo.OverrideCompileFlags.at(profile.Name).Remove,
39-
" ",
40-
compileArgsToRemove);
36+
int foundPlatformIndex = -1;
37+
for(int i = 0; i < platformNames.size(); ++i)
38+
{
39+
if( scriptInfo.RequiredProfiles.find(platformNames.at(i)) !=
40+
scriptInfo.RequiredProfiles.end())
41+
{
42+
foundPlatformIndex = i;
43+
break;
44+
}
45+
}
4146

42-
for(int i = 0; i < compileArgsToRemove.size(); ++i)
47+
if(foundPlatformIndex != -1)
4348
{
44-
std::size_t foundIndex = compileArgs.find(compileArgsToRemove.at(i));
49+
using namespace runcpp2::Data;
4550

46-
if(foundIndex != std::string::npos)
51+
const std::unordered_map<ProfileName, FlagsOverrideInfo>&
52+
currentOverrideCompileFlags = scriptInfo.OverrideCompileFlags
53+
.at(platformNames.at(foundPlatformIndex))
54+
.FlagsOverrides;
55+
56+
if( currentOverrideCompileFlags.find(profile.Name) !=
57+
currentOverrideCompileFlags.end())
4758
{
48-
compileArgs.erase(foundIndex, compileArgsToRemove.at(i).size() + 1);
49-
continue;
59+
std::vector<std::string> compileArgsToRemove;
60+
runcpp2::SplitString( currentOverrideCompileFlags.at(profile.Name).Remove,
61+
" ",
62+
compileArgsToRemove);
63+
64+
for(int i = 0; i < compileArgsToRemove.size(); ++i)
65+
{
66+
std::size_t foundIndex = compileArgs.find(compileArgsToRemove.at(i));
67+
68+
if(foundIndex != std::string::npos)
69+
{
70+
compileArgs.erase(foundIndex, compileArgsToRemove.at(i).size() + 1);
71+
continue;
72+
}
73+
74+
ssLOG_WARNING( "Compile flag to remove not found: " <<
75+
compileArgsToRemove.at(i));
76+
}
77+
78+
runcpp2::TrimRight(compileArgs);
79+
compileArgs += " " + currentOverrideCompileFlags.at(profile.Name).Append;
5080
}
51-
52-
ssLOG_WARNING("Compile flag to remove not found: " << compileArgsToRemove.at(i));
5381
}
54-
55-
runcpp2::TrimRight(compileArgs);
56-
compileArgs += " " + scriptInfo.OverrideCompileFlags.at(profile.Name).Append;
5782
}
5883

5984
compileCommand.replace( foundIndex,
@@ -187,6 +212,7 @@ namespace
187212
const std::vector<std::string>& copiedDependenciesBinariesPaths)
188213
{
189214
std::string scriptName = ghc::filesystem::path(scriptPath).stem().string();
215+
std::vector<std::string> platformNames = runcpp2::GetPlatformNames();
190216

191217
//Link the script to the dependencies
192218
std::string linkCommand = profile.Linker.Executable + " ";
@@ -199,29 +225,52 @@ namespace
199225
std::string outputName = scriptName;
200226

201227
//Override the default link flags from the script info
202-
if(scriptInfo.OverrideLinkFlags.find(profile.Name) != scriptInfo.OverrideLinkFlags.end())
203228
{
204-
std::vector<std::string> linkFlagsToRemove;
205-
206-
runcpp2::SplitString( scriptInfo.OverrideLinkFlags.at(profile.Name).Remove,
207-
" ",
208-
linkFlagsToRemove);
229+
int foundPlatformIndex = -1;
230+
for(int i = 0; i < platformNames.size(); ++i)
231+
{
232+
if( scriptInfo.RequiredProfiles.find(platformNames.at(i)) !=
233+
scriptInfo.RequiredProfiles.end())
234+
{
235+
foundPlatformIndex = i;
236+
break;
237+
}
238+
}
209239

210-
for(int i = 0; i < linkFlagsToRemove.size(); ++i)
240+
if(foundPlatformIndex != -1)
211241
{
212-
std::size_t foundIndex = linkFlags.find(linkFlagsToRemove.at(i));
242+
using namespace runcpp2::Data;
213243

214-
if(foundIndex != std::string::npos)
244+
const std::unordered_map<ProfileName, FlagsOverrideInfo>&
245+
currentOverrideLinkFlags = scriptInfo .OverrideLinkFlags
246+
.at(platformNames.at(foundPlatformIndex))
247+
.FlagsOverrides;
248+
249+
if(currentOverrideLinkFlags.find(profile.Name) != currentOverrideLinkFlags.end())
215250
{
216-
linkFlags.erase(foundIndex, linkFlagsToRemove.at(i).size() + 1);
217-
continue;
251+
std::vector<std::string> linkFlagsToRemove;
252+
253+
runcpp2::SplitString( currentOverrideLinkFlags.at(profile.Name).Remove,
254+
" ",
255+
linkFlagsToRemove);
256+
257+
for(int i = 0; i < linkFlagsToRemove.size(); ++i)
258+
{
259+
std::size_t foundIndex = linkFlags.find(linkFlagsToRemove.at(i));
260+
261+
if(foundIndex != std::string::npos)
262+
{
263+
linkFlags.erase(foundIndex, linkFlagsToRemove.at(i).size() + 1);
264+
continue;
265+
}
266+
267+
ssLOG_WARNING("Link flag to remove not found: " << linkFlagsToRemove.at(i));
268+
}
269+
270+
runcpp2::TrimRight(linkFlags);
271+
linkFlags += " " + currentOverrideLinkFlags.at(profile.Name).Append;
218272
}
219-
220-
ssLOG_WARNING("Link flag to remove not found: " << linkFlagsToRemove.at(i));
221273
}
222-
223-
runcpp2::TrimRight(linkFlags);
224-
linkFlags += " " + scriptInfo.OverrideLinkFlags.at(profile.Name).Append;
225274
}
226275

227276
//Add linker flags for the dependencies

Src/runcpp2/ConfigParsing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#include "ssLogger/ssLog.hpp"
88

99

10-
extern "C" const uint8_t DefaultCompilerProfiles[];
11-
extern "C" const size_t DefaultCompilerProfiles_size;
10+
extern "C" const uint8_t DefaultUserConfig[];
11+
extern "C" const size_t DefaultUserConfig_size;
1212
extern "C" const uint8_t DefaultScriptDependencies[];
1313
extern "C" const size_t DefaultScriptDependencies_size;
1414

@@ -140,7 +140,7 @@ bool runcpp2::ReadUserConfig( std::vector<Data::CompilerProfile>& outProfiles,
140140
ssLOG_ERROR("Failed to create default config file: " << compilerConfigFilePaths[0]);
141141
return false;
142142
}
143-
configFile.write((const char*)DefaultCompilerProfiles, DefaultCompilerProfiles_size);
143+
configFile.write((const char*)DefaultUserConfig, DefaultUserConfig_size);
144144
configFile.close();
145145
foundConfigFilePathIndex = 0;
146146
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "runcpp2/Data/ProfilesFlagsOverride.hpp"
2+
#include "ssLogger/ssLog.hpp"
3+
4+
bool runcpp2::Data::ProfilesFlagsOverride::ParseYAML_Node(ryml::ConstNodeRef& node)
5+
{
6+
INTERNAL_RUNCPP2_SAFE_START();
7+
8+
if(!node.is_map())
9+
{
10+
ssLOG_ERROR("ProfilesFlagsOverrides: Not a map type");
11+
return false;
12+
}
13+
14+
for(int i = 0; i < node.num_children(); ++i)
15+
{
16+
if(!(node[i].type().type & ryml::NodeType_e::MAP))
17+
{
18+
ssLOG_ERROR("ProfilesFlagsOverrides: FlagsOverrideInfo type requires a map");
19+
return false;
20+
}
21+
22+
ProfileName profile(node.key().data(), node.key().len);
23+
FlagsOverrideInfo flags;
24+
25+
ryml::ConstNodeRef flagsOverrideNode = node[i];
26+
27+
if(!flags.ParseYAML_Node(flagsOverrideNode))
28+
{
29+
ssLOG_ERROR("ProfilesFlagsOverrides: Unable to parse FlagsOverride.");
30+
return false;
31+
}
32+
33+
FlagsOverrides[profile] = flags;
34+
}
35+
36+
return true;
37+
38+
INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
39+
}
40+
41+
std::string runcpp2::Data::ProfilesFlagsOverride::ToString(std::string indentation) const
42+
{
43+
std::string out;
44+
45+
for(auto it = FlagsOverrides.begin(); it != FlagsOverrides.end(); ++it)
46+
out += indentation + it->first + ":\n" + it->second.ToString(indentation + " ");
47+
48+
return out;
49+
}

Src/runcpp2/Data/ScriptInfo.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ bool runcpp2::Data::ScriptInfo::ParseYAML_Node(ryml::ConstNodeRef& node)
5050

5151
for(int i = 0; i < overrideCompileFlagsNode.num_children(); ++i)
5252
{
53-
ProfileName profile = GetKey(overrideCompileFlagsNode[i]);
54-
FlagsOverrideInfo compileFlags;
53+
PlatformName platform = GetKey(overrideCompileFlagsNode[i]);
54+
ProfilesFlagsOverride compileFlags;
5555
ryml::ConstNodeRef currentCompileFlagsNode = overrideCompileFlagsNode[i];
5656

5757
if(!compileFlags.ParseYAML_Node(currentCompileFlagsNode))
5858
{
5959
ssLOG_ERROR("ScriptInfo: Failed to parse OverrideCompileFlags.");
6060
return false;
6161
}
62-
OverrideCompileFlags[profile] = compileFlags;
62+
OverrideCompileFlags[platform] = compileFlags;
6363
}
6464
}
6565

@@ -69,16 +69,16 @@ bool runcpp2::Data::ScriptInfo::ParseYAML_Node(ryml::ConstNodeRef& node)
6969

7070
for(int i = 0; i < overrideLinkFlagsNode.num_children(); ++i)
7171
{
72-
ProfileName profile = GetKey(overrideLinkFlagsNode[i]);
73-
FlagsOverrideInfo linkFlags;
72+
PlatformName platform = GetKey(overrideLinkFlagsNode[i]);
73+
ProfilesFlagsOverride linkFlags;
7474
ryml::ConstNodeRef currentLinkFlagsNode = overrideLinkFlagsNode[i];
7575

7676
if(!linkFlags.ParseYAML_Node(currentLinkFlagsNode))
7777
{
7878
ssLOG_ERROR("ScriptInfo: Failed to parse OverrideLinkFlags.");
7979
return false;
8080
}
81-
OverrideLinkFlags[profile] = linkFlags;
81+
OverrideLinkFlags[platform] = linkFlags;
8282
}
8383
}
8484

0 commit comments

Comments
 (0)