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
10 changes: 10 additions & 0 deletions Include/runcpp2/PlatformUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
#include <unordered_map>
#include <vector>

namespace ghc
{
namespace filesystem
{
class path;
}
}

namespace runcpp2
{
std::string ProcessPath(const std::string& path);
Expand Down Expand Up @@ -55,6 +63,8 @@ namespace runcpp2

return nullptr;
}

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

#endif
5 changes: 2 additions & 3 deletions Src/runcpp2/CompilingLinking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,10 @@ namespace
for(int i = 0; i < objectsFilesPaths.size(); ++i)
{
ssLOG_DEBUG("Trying to link " << objectsFilesPaths.at(i));
using namespace runcpp2;

//Check if this is a file we can link
std::string extension = objectsFilesPaths.at(i).extension();

using namespace runcpp2;
std::string extension = GetFileExtensionWithoutVersion(objectsFilesPaths.at(i));
Data::DependencyLibraryType currentLinkType = Data::DependencyLibraryType::COUNT;

if(!HasValueFromPlatformMap(profile.FilesTypes.ObjectLinkFile.Extension))
Expand Down
12 changes: 6 additions & 6 deletions Src/runcpp2/Data/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ bool runcpp2::Data::Profile::ParseYAML_Node(ryml::ConstNodeRef& profileNode)
ryml::ConstNodeRef currentPlatform = profileNode["Setup"][i];

std::string key = GetKey(currentPlatform);
std::vector<std::string> extensions;
std::vector<std::string> setupSteps;

for(int j = 0; j < currentPlatform.num_children(); ++j)
extensions.push_back(GetValue(currentPlatform[j]));
setupSteps.push_back(GetValue(currentPlatform[j]));

Setup[key] = extensions;
Setup[key] = setupSteps;
}
}

Expand All @@ -79,12 +79,12 @@ bool runcpp2::Data::Profile::ParseYAML_Node(ryml::ConstNodeRef& profileNode)
ryml::ConstNodeRef currentPlatform = profileNode["Cleanup"][i];

std::string key = GetKey(currentPlatform);
std::vector<std::string> extensions;
std::vector<std::string> cleanupSteps;

for(int j = 0; j < currentPlatform.num_children(); ++j)
extensions.push_back(GetValue(currentPlatform[j]));
cleanupSteps.push_back(GetValue(currentPlatform[j]));

Cleanup[key] = extensions;
Cleanup[key] = cleanupSteps;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Src/runcpp2/Data/StageInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,10 @@ bool runcpp2::Data::StageInfo::ConstructCommand(const SubstitutionMap& substitut
{
if(substitutionMap.count(substitutionsInCurrentPart.at(j)) == 0)
{
ssLOG_INFO("Failed to find " << substitutionsInCurrentPart.at(j) << " in " <<
ssLOG_DEBUG("No substitution found for " << substitutionsInCurrentPart.at(j) << " in " <<
currentRunParts.at(i).CommandPart);

ssLOG_INFO("Current run part is type repeat, skipping to next");
ssLOG_DEBUG("Current run part is type repeat, skipping to next");
continue;
}

Expand Down
49 changes: 42 additions & 7 deletions Src/runcpp2/DependenciesHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "runcpp2/PlatformUtil.hpp"
#include "ssLogger/ssLog.hpp"

#include <unordered_set>

namespace
{
bool PopulateLocalDependencies( const std::vector<runcpp2::Data::DependencyInfo*>& dependencies,
Expand Down Expand Up @@ -233,7 +235,7 @@ namespace
{
if(!runcpp2::HasValueFromPlatformMap(profile.FilesTypes.ObjectLinkFile.Extension))
{
ssLOG_ERROR("Failed to find shared library extensions for dependency " <<
ssLOG_ERROR("Failed to find object file extensions for dependency " <<
dependencyInfo.Name);

return false;
Expand All @@ -253,6 +255,15 @@ namespace

return true;
}

ghc::filesystem::path ResolveSymlink(const ghc::filesystem::path& path, std::error_code& ec)
{
ghc::filesystem::path resolvedPath = ghc::filesystem::canonical(path, ec);
if(ec)
return path; // Return original path if canonical fails

return resolvedPath;
}
}

bool runcpp2::GetDependenciesPaths( const std::vector<Data::DependencyInfo*>& availableDependencies,
Expand Down Expand Up @@ -475,6 +486,9 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
std::vector<std::string>& outBinariesPaths)
{
std::vector<std::string> platformNames = GetPlatformNames();
std::unordered_set<std::string> binariesPathsSet;
for(int i = 0; i < outBinariesPaths.size(); ++i)
binariesPathsSet.insert(outBinariesPaths[i]);

int minimumDependenciesCopiesCount = 0;
for(int i = 0; i < availableDependencies.size(); ++i)
Expand Down Expand Up @@ -527,7 +541,9 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
std::error_code e;
if(ghc::filesystem::exists(srcPath, e))
{
outBinariesPaths.push_back(runcpp2::ProcessPath(srcPath));
const std::string processedSrcPath = runcpp2::ProcessPath(srcPath);
outBinariesPaths.push_back(processedSrcPath);
binariesPathsSet.insert(processedSrcPath);
++nonLinkFilesCount;
ssLOG_INFO("Added binary path: " << srcPath.string());
}
Expand Down Expand Up @@ -620,8 +636,8 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
if(it.is_directory())
continue;

std::string currentFileName = it.path().stem().string();
std::string currentExtension = it.path().extension().string();
std::string currentFileName = it.path().filename().string();
std::string currentExtension = runcpp2::GetFileExtensionWithoutVersion(it.path());

ssLOG_DEBUG("currentFileName: " << currentFileName);
ssLOG_DEBUG("currentExtension: " << currentExtension);
Expand All @@ -647,7 +663,6 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
continue;

bool extensionMatched = false;

for(int j = 0; j < extensionsToLink.size(); ++j)
{
if(currentExtension == extensionsToLink.at(j))
Expand All @@ -660,8 +675,28 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
if(!extensionMatched)
continue;

ssLOG_INFO("Linking " << it.path().string());
outBinariesPaths.push_back(runcpp2::ProcessPath(it.path().string()));
//Handle symlink
ghc::filesystem::path resolvedPath = it.path();
{
std::error_code symlink_ec;
resolvedPath = ResolveSymlink(resolvedPath, symlink_ec);
if(symlink_ec)
{
ssLOG_ERROR("Failed to resolve symlink: " << symlink_ec.message());
return false;
}
}

const std::string processedPath = runcpp2::ProcessPath(it.path().string());
const std::string processedResolvedPath =
runcpp2::ProcessPath(resolvedPath.string());

if(binariesPathsSet.count(processedResolvedPath) == 0)
{
ssLOG_INFO("Linking " << processedPath);
outBinariesPaths.push_back(processedPath);
binariesPathsSet.insert(processedResolvedPath);
}
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions Src/runcpp2/PlatformUtil.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "runcpp2/PlatformUtil.hpp"

#include "ssLogger/ssLog.hpp"
#include "ghc/filesystem.hpp"
#include <stdio.h>
#include <cctype>

namespace
{
Expand Down Expand Up @@ -156,3 +158,26 @@ bool runcpp2::RunCommandAndGetOutput( const std::string& command,
return message;
}
#endif

std::string runcpp2::GetFileExtensionWithoutVersion(const ghc::filesystem::path& path)
{
std::string filename = path.filename().string();
bool inNumericPart = true;
int lastDotPos = filename.length();

for(int i = filename.length() - 1; i >= 0; --i)
{
if(filename[i] == '.')
{
if(!inNumericPart)
return filename.substr(i, lastDotPos - i);

inNumericPart = true;
lastDotPos = i;
}
else if(!std::isdigit(filename[i]))
inNumericPart = false;
}

return "";
}
5 changes: 3 additions & 2 deletions Src/runcpp2/runcpp2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ namespace
if(scriptFullMain != nullptr)
{
std::vector<std::string> runArgsCopy = runArgs;
runArgsCopy.insert(runArgsCopy.begin(), scriptPath);
runArgsCopy.insert( runArgsCopy.begin(),
runcpp2::ProcessPath(compiledSharedLibPath.string()));

std::vector<char*> runArgsCStr(runArgsCopy.size());
for(int i = 0; i < runArgsCopy.size(); ++i)
Expand Down Expand Up @@ -904,7 +905,7 @@ runcpp2::StartPipeline( const std::string& scriptPath,
for(int i = 0; i < gatheredBinariesPaths.size(); ++i)
{
ghc::filesystem::path filePath(gatheredBinariesPaths.at(i));
std::string extension = filePath.extension().string();
std::string extension = runcpp2::GetFileExtensionWithoutVersion(filePath);

//Check if the file is a link file based on its extension
if(linkExtensions.find(extension) != linkExtensions.end())
Expand Down