Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions DefaultYAMLs/DefaultScriptInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,23 @@ Dependencies:

# (Optional if LibraryType is Header) Link properties of the dependency
LinkProperties:
# Properties for searching the library binary for the profile
# You can also use "Default" if all compilers use the same values
"g++":
# The library names to be searched for when linking against the script.
# Binaries with linkable extension that contains one of the names will be linked
SearchLibraryNames: ["MyLibrary"]

# (Optional) The library names to be excluded from being searched.
# Works the same as SearchLibraryNames but will NOT be linked instead
ExcludeLibraryNames: []

# The path (relative to the dependency folder) to be searched for the dependency binaries
SearchDirectories: ["./build"]

# (Optional) Additional link flags for this dependency for each platform
AdditionalLinkOptions:
Default: []
# Properties for searching the library binary for each platform
Default:
# Profile-specific properties
"g++":
# The library names to be searched for when linking against the script.
# Binaries with linkable extension that contains one of the names will be linked
SearchLibraryNames: ["MyLibrary"]
# (Optional) The library names to be excluded from being searched.
# Works the same as SearchLibraryNames but will NOT be linked instead
ExcludeLibraryNames: []
# The path (relative to the dependency folder) to be searched for the dependency binaries
SearchDirectories: ["./build"]
# (Optional) Additional link flags for this dependency
AdditionalLinkOptions: []

# (Optional) Setup commands are run once when the dependency is populated
Setup:
Expand Down
19 changes: 10 additions & 9 deletions Examples/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Defines:
Default:
# Turns into `TEST_DEF=\"Test Define Working\"` in shell
"Default": ["TEST_DEF=\\\"Test Define Working\\\""]
Default: ["TEST_DEF=\\\"Test Define Working\\\""]

Dependencies:
- Name: ssLogger
Expand All @@ -27,23 +27,24 @@
LibraryType: Shared
IncludePaths: ["Include"]
LinkProperties:
"Default":
SearchLibraryNames: ["ssLogger"]
ExcludeLibraryNames: ["ssLogger_SRC"]
SearchDirectories: ["./build", "./build/Debug", "./build/Release"]
Default:
Default:
SearchLibraryNames: ["ssLogger"]
ExcludeLibraryNames: ["ssLogger_SRC"]
SearchDirectories: ["./build", "./build/Debug", "./build/Release"]
Setup:
Default:
"Default":
Default:
- "mkdir build"
Build:
Default:
"Default":
Default:
- "cd build && cmake .. -DssLOG_BUILD_TYPE=SHARED"
- "cd build && cmake --build . --config Release -j 16"
FilesToCopy:
# Target Platform (Default, Windows, Linux, MacOS, or Unix)
Default:
"Default":
Default:
- "./Include/ssLogger/ssLog.hpp"

- Name: System2.cpp
Expand All @@ -55,7 +56,7 @@
IncludePaths: ["./", "./External/System2"]
Setup:
Default:
"Default":
Default:
- "git submodule update --init --recursive"
*/

Expand Down
2 changes: 1 addition & 1 deletion Include/runcpp2/Data/DependencyInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace runcpp2
DependencyLibraryType LibraryType;
std::vector<std::string> IncludePaths;
std::vector<std::string> AbsoluteIncludePaths;
std::unordered_map<ProfileName, DependencyLinkProperty> LinkProperties;
std::unordered_map<PlatformName, DependencyLinkProperty> LinkProperties;
std::unordered_map<PlatformName, DependencyCommands> Setup;
std::unordered_map<PlatformName, DependencyCommands> Cleanup;
std::unordered_map<PlatformName, DependencyCommands> Build;
Expand Down
13 changes: 9 additions & 4 deletions Include/runcpp2/Data/DependencyLinkProperty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ namespace runcpp2
{
namespace Data
{
struct ProfileLinkProperty
{
std::vector<std::string> SearchLibraryNames;
std::vector<std::string> SearchDirectories;
std::vector<std::string> ExcludeLibraryNames;
std::vector<std::string> AdditionalLinkOptions;
};

class DependencyLinkProperty
{
public:
std::vector<std::string> SearchLibraryNames;
std::vector<std::string> SearchDirectories;
std::vector<std::string> ExcludeLibraryNames;
std::unordered_map<PlatformName, std::vector<std::string>> AdditionalLinkOptions;
std::unordered_map<ProfileName, ProfileLinkProperty> ProfileProperties;

bool ParseYAML_Node(ryml::ConstNodeRef& node);
std::string ToString(std::string indentation) const;
Expand Down
32 changes: 32 additions & 0 deletions Include/runcpp2/PlatformUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define RUNCPP2_PLATFORM_UTIL_HPP

#include "runcpp2/Data/ParseCommon.hpp"
#include "runcpp2/Data/Profile.hpp"
#include "System2.h"

#include <cstdint>
Expand Down Expand Up @@ -65,6 +66,37 @@ namespace runcpp2
}

std::string GetFileExtensionWithoutVersion(const ghc::filesystem::path& path);

template <typename T>
inline bool HasValueFromProfileMap( const Data::Profile& profile,
const std::unordered_map<ProfileName, T>& map)
{
std::vector<std::string> profileNames;
profile.GetNames(profileNames);

for(int i = 0; i < profileNames.size(); ++i)
{
if(map.find(profileNames.at(i)) != map.end())
return true;
}
return false;
}

template <typename T>
inline const T* GetValueFromProfileMap( const Data::Profile& profile,
const std::unordered_map<ProfileName, T>& map)
{
std::vector<std::string> profileNames;
profile.GetNames(profileNames);

for(int i = 0; i < profileNames.size(); ++i)
{
auto it = map.find(profileNames.at(i));
if(it != map.end())
return &it->second;
}
return nullptr;
}
}

#endif
79 changes: 20 additions & 59 deletions Src/runcpp2/CompilingLinking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,17 @@ namespace
const runcpp2::Data::ProfilesFlagsOverride& currentFlagsOverride =
*runcpp2::GetValueFromPlatformMap(overrideFlags);

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

for(int i = 0; i < currentProfileNames.size(); ++i)
{
if(currentFlagsOverride.FlagsOverrides.count(currentProfileNames.at(i)) > 0)
{
foundProfileName = currentProfileNames.at(i);
break;
}
}

if(foundProfileName.empty())
if(!profileFlagsOverride)
{
ssLOG_INFO("No override flags found for current profile");
return;
}

std::vector<std::string> flagsToRemove;
runcpp2::SplitString( currentFlagsOverride.FlagsOverrides.at(foundProfileName).Remove,
" ",
flagsToRemove);
runcpp2::SplitString(profileFlagsOverride->Remove, " ", flagsToRemove);

for(int i = 0; i < flagsToRemove.size(); ++i)
{
Expand All @@ -74,7 +62,7 @@ namespace
}

runcpp2::TrimRight(inOutFlags);
inOutFlags += " " + currentFlagsOverride.FlagsOverrides.at(foundProfileName).Append;
inOutFlags += " " + profileFlagsOverride->Append;
runcpp2::TrimRight(inOutFlags);
}

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

std::vector<std::string> profileNames;
profile.GetNames(profileNames);
const std::vector<runcpp2::Data::Define>* profileDefines =
runcpp2::GetValueFromProfileMap(profile, platformDefines.Defines);

std::string validProfileName;
for(int i = 0; i < profileNames.size(); ++i)
if(profileDefines)
{
if(platformDefines.Defines.count(profileNames[i]) > 0)
{
validProfileName = profileNames.at(i);
break;
}
}

if(!validProfileName.empty())
{
const std::vector<runcpp2::Data::Define>& profileDefines =
platformDefines.Defines.at(validProfileName);

for(int i = 0; i < profileDefines.size(); ++i)
for(int i = 0; i < profileDefines->size(); ++i)
{
const runcpp2::Data::Define& define = profileDefines.at(i);
const runcpp2::Data::Define& define = profileDefines->at(i);
if(define.HasValue)
{
substitutionMapTemplate["{DefineName}"].push_back(define.Name);
Expand Down Expand Up @@ -755,34 +730,20 @@ bool runcpp2::CompileAndLinkScript( const ghc::filesystem::path& buildDir,
//Add link flags for the dependencies
for(int i = 0; i < availableDependencies.size(); ++i)
{
std::string targetProfileName;
std::vector<std::string> currentProfileNames;
profile.GetNames(currentProfileNames);

for(int j = 0; j < currentProfileNames.size(); ++j)
{
if( availableDependencies.at(i)->LinkProperties.find(currentProfileNames.at(j)) !=
availableDependencies.at(i)->LinkProperties.end())
{
targetProfileName = currentProfileNames.at(j);
break;
}
}

if(targetProfileName.empty())
if(!runcpp2::HasValueFromPlatformMap(availableDependencies.at(i)->LinkProperties))
continue;

const runcpp2::Data::DependencyLinkProperty& currentLinkProperty =
availableDependencies.at(i)->LinkProperties.at(targetProfileName);
const runcpp2::Data::DependencyLinkProperty& linkProperty =
*runcpp2::GetValueFromPlatformMap(availableDependencies.at(i)->LinkProperties);

if(runcpp2::HasValueFromPlatformMap(currentLinkProperty.AdditionalLinkOptions))
{
const std::vector<std::string> additionalLinkOptions =
*runcpp2::GetValueFromPlatformMap(currentLinkProperty.AdditionalLinkOptions);
const runcpp2::Data::ProfileLinkProperty* profileLinkProperty =
runcpp2::GetValueFromProfileMap(profile, linkProperty.ProfileProperties);

for(int k = 0; k < additionalLinkOptions.size(); ++k)
dependenciesLinkFlags += additionalLinkOptions.at(k) + " ";
}
if(!profileLinkProperty)
continue;

for(const std::string& option : profileLinkProperty->AdditionalLinkOptions)
dependenciesLinkFlags += option + " ";
}

runcpp2::TrimRight(dependenciesLinkFlags);
Expand Down
17 changes: 8 additions & 9 deletions Src/runcpp2/Data/DependencyInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,20 @@ bool runcpp2::Data::DependencyInfo::ParseYAML_Node(ryml::ConstNodeRef& node)
{
ryml::ConstNodeRef linkPropertiesNode = node["LinkProperties"];

for(auto it = linkPropertiesNode.begin(); it != linkPropertiesNode.end(); ++it)

for(int i = 0; i < linkPropertiesNode.num_children(); ++i)
{
ProfileName profile = GetKey(linkPropertiesNode[i]);
ryml::ConstNodeRef currentPropertyNode = linkPropertiesNode[i];
PlatformName platform = GetKey(linkPropertiesNode[i]);
ryml::ConstNodeRef platformNode = linkPropertiesNode[i];

//Insert an empty DependencyLinkProperty and get a reference to it
DependencyLinkProperty& linkProperty = LinkProperties[platform];

DependencyLinkProperty property;
if(!property.ParseYAML_Node(currentPropertyNode))
if(!linkProperty.ParseYAML_Node(platformNode))
{
ssLOG_ERROR("DependencyInfo: Failed to parse SearchProperties");
ssLOG_ERROR("DependencyInfo: Failed to parse LinkProperties for platform " <<
platform);
return false;
}

LinkProperties[profile] = property;
}
}
else if(LibraryType != DependencyLibraryType::HEADER)
Expand Down
Loading