Skip to content

Commit 11e082a

Browse files
Merge pull request #26 from Neko-Box-Coder/UpdateLinkProperties
Update link properties
2 parents 3f52acf + c3bdd6b commit 11e082a

File tree

10 files changed

+226
-256
lines changed

10 files changed

+226
-256
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:

Examples/test.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Defines:
1717
Default:
1818
# Turns into `TEST_DEF=\"Test Define Working\"` in shell
19-
"Default": ["TEST_DEF=\\\"Test Define Working\\\""]
19+
Default: ["TEST_DEF=\\\"Test Define Working\\\""]
2020
2121
Dependencies:
2222
- Name: ssLogger
@@ -27,23 +27,24 @@
2727
LibraryType: Shared
2828
IncludePaths: ["Include"]
2929
LinkProperties:
30-
"Default":
31-
SearchLibraryNames: ["ssLogger"]
32-
ExcludeLibraryNames: ["ssLogger_SRC"]
33-
SearchDirectories: ["./build", "./build/Debug", "./build/Release"]
30+
Default:
31+
Default:
32+
SearchLibraryNames: ["ssLogger"]
33+
ExcludeLibraryNames: ["ssLogger_SRC"]
34+
SearchDirectories: ["./build", "./build/Debug", "./build/Release"]
3435
Setup:
3536
Default:
36-
"Default":
37+
Default:
3738
- "mkdir build"
3839
Build:
3940
Default:
40-
"Default":
41+
Default:
4142
- "cd build && cmake .. -DssLOG_BUILD_TYPE=SHARED"
4243
- "cd build && cmake --build . --config Release -j 16"
4344
FilesToCopy:
4445
# Target Platform (Default, Windows, Linux, MacOS, or Unix)
4546
Default:
46-
"Default":
47+
Default:
4748
- "./Include/ssLogger/ssLog.hpp"
4849
4950
- Name: System2.cpp
@@ -55,7 +56,7 @@
5556
IncludePaths: ["./", "./External/System2"]
5657
Setup:
5758
Default:
58-
"Default":
59+
Default:
5960
- "git submodule update --init --recursive"
6061
*/
6162

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;

Include/runcpp2/PlatformUtil.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define RUNCPP2_PLATFORM_UTIL_HPP
33

44
#include "runcpp2/Data/ParseCommon.hpp"
5+
#include "runcpp2/Data/Profile.hpp"
56
#include "System2.h"
67

78
#include <cstdint>
@@ -65,6 +66,37 @@ namespace runcpp2
6566
}
6667

6768
std::string GetFileExtensionWithoutVersion(const ghc::filesystem::path& path);
69+
70+
template <typename T>
71+
inline bool HasValueFromProfileMap( const Data::Profile& profile,
72+
const std::unordered_map<ProfileName, T>& map)
73+
{
74+
std::vector<std::string> profileNames;
75+
profile.GetNames(profileNames);
76+
77+
for(int i = 0; i < profileNames.size(); ++i)
78+
{
79+
if(map.find(profileNames.at(i)) != map.end())
80+
return true;
81+
}
82+
return false;
83+
}
84+
85+
template <typename T>
86+
inline const T* GetValueFromProfileMap( const Data::Profile& profile,
87+
const std::unordered_map<ProfileName, T>& map)
88+
{
89+
std::vector<std::string> profileNames;
90+
profile.GetNames(profileNames);
91+
92+
for(int i = 0; i < profileNames.size(); ++i)
93+
{
94+
auto it = map.find(profileNames.at(i));
95+
if(it != map.end())
96+
return &it->second;
97+
}
98+
return nullptr;
99+
}
68100
}
69101

70102
#endif

Src/runcpp2/CompilingLinking.cpp

Lines changed: 20 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,17 @@ namespace
3030
const runcpp2::Data::ProfilesFlagsOverride& currentFlagsOverride =
3131
*runcpp2::GetValueFromPlatformMap(overrideFlags);
3232

33-
std::string foundProfileName;
34-
std::vector<std::string> currentProfileNames;
35-
profile.GetNames(currentProfileNames);
33+
const runcpp2::Data::FlagsOverrideInfo* profileFlagsOverride =
34+
runcpp2::GetValueFromProfileMap(profile, currentFlagsOverride.FlagsOverrides);
3635

37-
for(int i = 0; i < currentProfileNames.size(); ++i)
38-
{
39-
if(currentFlagsOverride.FlagsOverrides.count(currentProfileNames.at(i)) > 0)
40-
{
41-
foundProfileName = currentProfileNames.at(i);
42-
break;
43-
}
44-
}
45-
46-
if(foundProfileName.empty())
36+
if(!profileFlagsOverride)
4737
{
4838
ssLOG_INFO("No override flags found for current profile");
4939
return;
5040
}
5141

5242
std::vector<std::string> flagsToRemove;
53-
runcpp2::SplitString( currentFlagsOverride.FlagsOverrides.at(foundProfileName).Remove,
54-
" ",
55-
flagsToRemove);
43+
runcpp2::SplitString(profileFlagsOverride->Remove, " ", flagsToRemove);
5644

5745
for(int i = 0; i < flagsToRemove.size(); ++i)
5846
{
@@ -74,7 +62,7 @@ namespace
7462
}
7563

7664
runcpp2::TrimRight(inOutFlags);
77-
inOutFlags += " " + currentFlagsOverride.FlagsOverrides.at(foundProfileName).Append;
65+
inOutFlags += " " + profileFlagsOverride->Append;
7866
runcpp2::TrimRight(inOutFlags);
7967
}
8068

@@ -132,27 +120,14 @@ namespace
132120
const runcpp2::Data::ProfilesDefines& platformDefines =
133121
*runcpp2::GetValueFromPlatformMap(scriptInfo.Defines);
134122

135-
std::vector<std::string> profileNames;
136-
profile.GetNames(profileNames);
123+
const std::vector<runcpp2::Data::Define>* profileDefines =
124+
runcpp2::GetValueFromProfileMap(profile, platformDefines.Defines);
137125

138-
std::string validProfileName;
139-
for(int i = 0; i < profileNames.size(); ++i)
126+
if(profileDefines)
140127
{
141-
if(platformDefines.Defines.count(profileNames[i]) > 0)
142-
{
143-
validProfileName = profileNames.at(i);
144-
break;
145-
}
146-
}
147-
148-
if(!validProfileName.empty())
149-
{
150-
const std::vector<runcpp2::Data::Define>& profileDefines =
151-
platformDefines.Defines.at(validProfileName);
152-
153-
for(int i = 0; i < profileDefines.size(); ++i)
128+
for(int i = 0; i < profileDefines->size(); ++i)
154129
{
155-
const runcpp2::Data::Define& define = profileDefines.at(i);
130+
const runcpp2::Data::Define& define = profileDefines->at(i);
156131
if(define.HasValue)
157132
{
158133
substitutionMapTemplate["{DefineName}"].push_back(define.Name);
@@ -755,34 +730,20 @@ bool runcpp2::CompileAndLinkScript( const ghc::filesystem::path& buildDir,
755730
//Add link flags for the dependencies
756731
for(int i = 0; i < availableDependencies.size(); ++i)
757732
{
758-
std::string targetProfileName;
759-
std::vector<std::string> currentProfileNames;
760-
profile.GetNames(currentProfileNames);
761-
762-
for(int j = 0; j < currentProfileNames.size(); ++j)
763-
{
764-
if( availableDependencies.at(i)->LinkProperties.find(currentProfileNames.at(j)) !=
765-
availableDependencies.at(i)->LinkProperties.end())
766-
{
767-
targetProfileName = currentProfileNames.at(j);
768-
break;
769-
}
770-
}
771-
772-
if(targetProfileName.empty())
733+
if(!runcpp2::HasValueFromPlatformMap(availableDependencies.at(i)->LinkProperties))
773734
continue;
774735

775-
const runcpp2::Data::DependencyLinkProperty& currentLinkProperty =
776-
availableDependencies.at(i)->LinkProperties.at(targetProfileName);
736+
const runcpp2::Data::DependencyLinkProperty& linkProperty =
737+
*runcpp2::GetValueFromPlatformMap(availableDependencies.at(i)->LinkProperties);
777738

778-
if(runcpp2::HasValueFromPlatformMap(currentLinkProperty.AdditionalLinkOptions))
779-
{
780-
const std::vector<std::string> additionalLinkOptions =
781-
*runcpp2::GetValueFromPlatformMap(currentLinkProperty.AdditionalLinkOptions);
739+
const runcpp2::Data::ProfileLinkProperty* profileLinkProperty =
740+
runcpp2::GetValueFromProfileMap(profile, linkProperty.ProfileProperties);
782741

783-
for(int k = 0; k < additionalLinkOptions.size(); ++k)
784-
dependenciesLinkFlags += additionalLinkOptions.at(k) + " ";
785-
}
742+
if(!profileLinkProperty)
743+
continue;
744+
745+
for(const std::string& option : profileLinkProperty->AdditionalLinkOptions)
746+
dependenciesLinkFlags += option + " ";
786747
}
787748

788749
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)

0 commit comments

Comments
 (0)