Skip to content

Commit 9fbc151

Browse files
Updating link properties format
1 parent 3f52acf commit 9fbc151

File tree

7 files changed

+156
-124
lines changed

7 files changed

+156
-124
lines changed

DefaultYAMLs/DefaultScriptInfo.yaml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,23 @@ Dependencies:
9090

9191
# (Optional if LibraryType is Header) Link properties of the dependency
9292
LinkProperties:
93-
# Properties for searching the library binary for the profile
94-
# You can also use "Default" if all compilers use the same values
95-
"g++":
96-
# The library names to be searched for when linking against the script.
97-
# Binaries with linkable extension that contains one of the names will be linked
98-
SearchLibraryNames: ["MyLibrary"]
99-
100-
# (Optional) The library names to be excluded from being searched.
101-
# Works the same as SearchLibraryNames but will NOT be linked instead
102-
ExcludeLibraryNames: []
103-
104-
# The path (relative to the dependency folder) to be searched for the dependency binaries
105-
SearchDirectories: ["./build"]
106-
107-
# (Optional) Additional link flags for this dependency for each platform
108-
AdditionalLinkOptions:
109-
Default: []
93+
# Properties for searching the library binary for each platform
94+
Default:
95+
# Profile-specific properties
96+
"g++":
97+
# The library names to be searched for when linking against the script.
98+
# Binaries with linkable extension that contains one of the names will be linked
99+
SearchLibraryNames: ["MyLibrary"]
100+
101+
# (Optional) The library names to be excluded from being searched.
102+
# Works the same as SearchLibraryNames but will NOT be linked instead
103+
ExcludeLibraryNames: []
104+
105+
# The path (relative to the dependency folder) to be searched for the dependency binaries
106+
SearchDirectories: ["./build"]
107+
108+
# (Optional) Additional link flags for this dependency
109+
AdditionalLinkOptions: []
110110

111111
# (Optional) Setup commands are run once when the dependency is populated
112112
Setup:

Include/runcpp2/Data/DependencyInfo.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace runcpp2
2525
DependencyLibraryType LibraryType;
2626
std::vector<std::string> IncludePaths;
2727
std::vector<std::string> AbsoluteIncludePaths;
28-
std::unordered_map<ProfileName, DependencyLinkProperty> LinkProperties;
28+
std::unordered_map<PlatformName, DependencyLinkProperty> LinkProperties;
2929
std::unordered_map<PlatformName, DependencyCommands> Setup;
3030
std::unordered_map<PlatformName, DependencyCommands> Cleanup;
3131
std::unordered_map<PlatformName, DependencyCommands> Build;

Include/runcpp2/Data/DependencyLinkProperty.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ namespace runcpp2
1313
{
1414
namespace Data
1515
{
16+
struct ProfileLinkProperty
17+
{
18+
std::vector<std::string> SearchLibraryNames;
19+
std::vector<std::string> SearchDirectories;
20+
std::vector<std::string> ExcludeLibraryNames;
21+
std::vector<std::string> AdditionalLinkOptions;
22+
};
23+
1624
class DependencyLinkProperty
1725
{
1826
public:
19-
std::vector<std::string> SearchLibraryNames;
20-
std::vector<std::string> SearchDirectories;
21-
std::vector<std::string> ExcludeLibraryNames;
22-
std::unordered_map<PlatformName, std::vector<std::string>> AdditionalLinkOptions;
27+
std::unordered_map<ProfileName, ProfileLinkProperty> ProfileProperties;
2328

2429
bool ParseYAML_Node(ryml::ConstNodeRef& node);
2530
std::string ToString(std::string indentation) const;

Src/runcpp2/CompilingLinking.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -759,10 +759,17 @@ bool runcpp2::CompileAndLinkScript( const ghc::filesystem::path& buildDir,
759759
std::vector<std::string> currentProfileNames;
760760
profile.GetNames(currentProfileNames);
761761

762+
if(!runcpp2::HasValueFromPlatformMap(availableDependencies.at(i)->LinkProperties))
763+
continue;
764+
765+
const runcpp2::Data::DependencyLinkProperty& linkProperty =
766+
*runcpp2::GetValueFromPlatformMap(availableDependencies.at(i)->LinkProperties);
767+
768+
// Find the matching profile
762769
for(int j = 0; j < currentProfileNames.size(); ++j)
763770
{
764-
if( availableDependencies.at(i)->LinkProperties.find(currentProfileNames.at(j)) !=
765-
availableDependencies.at(i)->LinkProperties.end())
771+
if( linkProperty.ProfileProperties.find(currentProfileNames.at(j)) !=
772+
linkProperty.ProfileProperties.end())
766773
{
767774
targetProfileName = currentProfileNames.at(j);
768775
break;
@@ -772,17 +779,11 @@ bool runcpp2::CompileAndLinkScript( const ghc::filesystem::path& buildDir,
772779
if(targetProfileName.empty())
773780
continue;
774781

775-
const runcpp2::Data::DependencyLinkProperty& currentLinkProperty =
776-
availableDependencies.at(i)->LinkProperties.at(targetProfileName);
782+
const runcpp2::Data::ProfileLinkProperty& profileLinkProperty =
783+
linkProperty.ProfileProperties.at(targetProfileName);
777784

778-
if(runcpp2::HasValueFromPlatformMap(currentLinkProperty.AdditionalLinkOptions))
779-
{
780-
const std::vector<std::string> additionalLinkOptions =
781-
*runcpp2::GetValueFromPlatformMap(currentLinkProperty.AdditionalLinkOptions);
782-
783-
for(int k = 0; k < additionalLinkOptions.size(); ++k)
784-
dependenciesLinkFlags += additionalLinkOptions.at(k) + " ";
785-
}
785+
for(const std::string& option : profileLinkProperty.AdditionalLinkOptions)
786+
dependenciesLinkFlags += option + " ";
786787
}
787788

788789
runcpp2::TrimRight(dependenciesLinkFlags);

Src/runcpp2/Data/DependencyInfo.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,20 @@ bool runcpp2::Data::DependencyInfo::ParseYAML_Node(ryml::ConstNodeRef& node)
6767
{
6868
ryml::ConstNodeRef linkPropertiesNode = node["LinkProperties"];
6969

70-
for(auto it = linkPropertiesNode.begin(); it != linkPropertiesNode.end(); ++it)
71-
7270
for(int i = 0; i < linkPropertiesNode.num_children(); ++i)
7371
{
74-
ProfileName profile = GetKey(linkPropertiesNode[i]);
75-
ryml::ConstNodeRef currentPropertyNode = linkPropertiesNode[i];
72+
PlatformName platform = GetKey(linkPropertiesNode[i]);
73+
ryml::ConstNodeRef platformNode = linkPropertiesNode[i];
74+
75+
//Insert an empty DependencyLinkProperty and get a reference to it
76+
DependencyLinkProperty& linkProperty = LinkProperties[platform];
7677

77-
DependencyLinkProperty property;
78-
if(!property.ParseYAML_Node(currentPropertyNode))
78+
if(!linkProperty.ParseYAML_Node(platformNode))
7979
{
80-
ssLOG_ERROR("DependencyInfo: Failed to parse SearchProperties");
80+
ssLOG_ERROR("DependencyInfo: Failed to parse LinkProperties for platform " <<
81+
platform);
8182
return false;
8283
}
83-
84-
LinkProperties[profile] = property;
8584
}
8685
}
8786
else if(LibraryType != DependencyLibraryType::HEADER)

Src/runcpp2/Data/DependencyLinkProperty.cpp

Lines changed: 66 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,55 @@ bool runcpp2::Data::DependencyLinkProperty::ParseYAML_Node(ryml::ConstNodeRef& n
99

1010
if(!node.is_map())
1111
{
12-
ssLOG_ERROR("DependencySearchProperty: Node is not a Map");
12+
ssLOG_ERROR("DependencyLinkProperty: Node is not a Map");
1313
return false;
1414
}
1515

16-
std::vector<NodeRequirement> requirements =
16+
for(int i = 0; i < node.num_children(); ++i)
1717
{
18-
NodeRequirement("SearchLibraryNames", ryml::NodeType_e::SEQ, true, false),
19-
NodeRequirement("SearchDirectories", ryml::NodeType_e::SEQ, true, false),
20-
NodeRequirement("ExcludeLibraryNames", ryml::NodeType_e::SEQ, false, true),
21-
NodeRequirement("AdditionalLinkOptions", ryml::NodeType_e::MAP, false, true)
22-
};
23-
24-
if(!CheckNodeRequirements(node, requirements))
25-
{
26-
ssLOG_ERROR("DependencySource: Failed to meet requirements");
27-
return false;
28-
}
29-
30-
for(int i = 0; i < node["SearchLibraryNames"].num_children(); ++i)
31-
SearchLibraryNames.push_back(GetValue(node["SearchLibraryNames"][i]));
32-
33-
for(int i = 0; i < node["SearchDirectories"].num_children(); ++i)
34-
SearchDirectories.push_back(GetValue(node["SearchDirectories"][i]));
35-
36-
for(int i = 0; i < node["ExcludeLibraryNames"].num_children(); ++i)
37-
ExcludeLibraryNames.push_back(GetValue(node["ExcludeLibraryNames"][i]));
38-
39-
if(ExistAndHasChild(node, "AdditionalLinkOptions"))
40-
{
41-
ryml::ConstNodeRef additionalLinkNode = node["AdditionalLinkOptions"];
18+
ProfileName profile = GetKey(node[i]);
19+
ryml::ConstNodeRef profileNode = node[i];
20+
21+
ProfileLinkProperty& property = ProfileProperties[profile];
22+
23+
std::vector<NodeRequirement> requirements =
24+
{
25+
NodeRequirement("SearchLibraryNames", ryml::NodeType_e::SEQ, true, false),
26+
NodeRequirement("SearchDirectories", ryml::NodeType_e::SEQ, true, false),
27+
NodeRequirement("ExcludeLibraryNames", ryml::NodeType_e::SEQ, false, true),
28+
NodeRequirement("AdditionalLinkOptions", ryml::NodeType_e::SEQ, false, true)
29+
};
30+
31+
if(!CheckNodeRequirements(profileNode, requirements))
32+
{
33+
ssLOG_ERROR("DependencyLinkProperty: Failed to meet requirements for profile " <<
34+
profile);
35+
return false;
36+
}
37+
38+
for(int j = 0; j < profileNode["SearchLibraryNames"].num_children(); ++j)
39+
property.SearchLibraryNames.push_back(GetValue(profileNode["SearchLibraryNames"][j]));
40+
41+
for(int j = 0; j < profileNode["SearchDirectories"].num_children(); ++j)
42+
property.SearchDirectories.push_back(GetValue(profileNode["SearchDirectories"][j]));
4243

43-
for(int i = 0; i < additionalLinkNode.num_children(); ++i)
44+
if(ExistAndHasChild(profileNode, "ExcludeLibraryNames"))
4445
{
45-
ryml::ConstNodeRef currentLinkNode = additionalLinkNode[i];
46-
47-
if(!currentLinkNode.is_seq())
46+
for(int j = 0; j < profileNode["ExcludeLibraryNames"].num_children(); ++j)
4847
{
49-
ssLOG_ERROR("Sequence is expected for AdditionalLinkOptions at " <<
50-
GetKey(currentLinkNode));
48+
property.ExcludeLibraryNames
49+
.push_back(GetValue(profileNode["ExcludeLibraryNames"][j]));
5150

52-
return false;
5351
}
54-
55-
const std::string currentPlatform = GetKey(currentLinkNode);
56-
for(int j = 0; j < currentLinkNode.num_children(); ++j)
57-
AdditionalLinkOptions[currentPlatform].push_back(GetValue(currentLinkNode[j]));
52+
}
53+
54+
if(ExistAndHasChild(profileNode, "AdditionalLinkOptions"))
55+
{
56+
for(int j = 0; j < profileNode["AdditionalLinkOptions"].num_children(); ++j)
57+
{
58+
property.AdditionalLinkOptions
59+
.push_back(GetValue(profileNode["AdditionalLinkOptions"][j]));
60+
}
5861
}
5962
}
6063

@@ -66,24 +69,33 @@ bool runcpp2::Data::DependencyLinkProperty::ParseYAML_Node(ryml::ConstNodeRef& n
6669
std::string runcpp2::Data::DependencyLinkProperty::ToString(std::string indentation) const
6770
{
6871
std::string out;
69-
out += indentation + "SearchLibraryName: \n";
70-
71-
for(int i = 0; i < SearchLibraryNames.size(); ++i)
72-
out += indentation + "- " + SearchLibraryNames[i] + "\n";
73-
74-
out += indentation + "SearchDirectories: \n";
75-
76-
for(int i = 0; i < SearchDirectories.size(); ++i)
77-
out += indentation + "- " + SearchDirectories[i] + "\n";
78-
79-
out += indentation + "AdditionalLinkOptions: \n";
80-
81-
for(auto it = AdditionalLinkOptions.begin(); it != AdditionalLinkOptions.end(); ++it)
72+
for(const std::pair<const ProfileName, ProfileLinkProperty>& profilePair : ProfileProperties)
8273
{
83-
out += indentation + "- " + it->first + ":\n";
84-
for(int i = 0; i < it->second.size(); ++i)
85-
out += indentation + " - " + it->second[i] + "\n";
74+
out += indentation + profilePair.first + ":\n";
75+
const ProfileLinkProperty& property = profilePair.second;
76+
77+
out += indentation + " SearchLibraryNames:\n";
78+
for(const std::string& name : property.SearchLibraryNames)
79+
out += indentation + " - " + name + "\n";
80+
81+
out += indentation + " SearchDirectories:\n";
82+
for(const std::string& dir : property.SearchDirectories)
83+
out += indentation + " - " + dir + "\n";
84+
85+
if(!property.ExcludeLibraryNames.empty())
86+
{
87+
out += indentation + " ExcludeLibraryNames:\n";
88+
for(const std::string& name : property.ExcludeLibraryNames)
89+
out += indentation + " - " + name + "\n";
90+
}
91+
92+
if(!property.AdditionalLinkOptions.empty())
93+
{
94+
out += indentation + " AdditionalLinkOptions:\n";
95+
for(const std::string& option : property.AdditionalLinkOptions)
96+
out += indentation + " - " + option + "\n";
97+
}
8698
}
8799

88100
return out;
89-
}
101+
}

0 commit comments

Comments
 (0)