Skip to content

Commit 3f52acf

Browse files
Merge pull request #25 from Neko-Box-Coder/IgnoreVersionExtension
Ignore version extension and resolving symlink
2 parents 5e35371 + ba4a8bb commit 3f52acf

File tree

7 files changed

+90
-20
lines changed

7 files changed

+90
-20
lines changed

Include/runcpp2/PlatformUtil.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
#include <unordered_map>
1010
#include <vector>
1111

12+
namespace ghc
13+
{
14+
namespace filesystem
15+
{
16+
class path;
17+
}
18+
}
19+
1220
namespace runcpp2
1321
{
1422
std::string ProcessPath(const std::string& path);
@@ -55,6 +63,8 @@ namespace runcpp2
5563

5664
return nullptr;
5765
}
66+
67+
std::string GetFileExtensionWithoutVersion(const ghc::filesystem::path& path);
5868
}
5969

6070
#endif

Src/runcpp2/CompilingLinking.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,10 @@ namespace
406406
for(int i = 0; i < objectsFilesPaths.size(); ++i)
407407
{
408408
ssLOG_DEBUG("Trying to link " << objectsFilesPaths.at(i));
409+
using namespace runcpp2;
409410

410411
//Check if this is a file we can link
411-
std::string extension = objectsFilesPaths.at(i).extension();
412-
413-
using namespace runcpp2;
412+
std::string extension = GetFileExtensionWithoutVersion(objectsFilesPaths.at(i));
414413
Data::DependencyLibraryType currentLinkType = Data::DependencyLibraryType::COUNT;
415414

416415
if(!HasValueFromPlatformMap(profile.FilesTypes.ObjectLinkFile.Extension))

Src/runcpp2/Data/Profile.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ bool runcpp2::Data::Profile::ParseYAML_Node(ryml::ConstNodeRef& profileNode)
6363
ryml::ConstNodeRef currentPlatform = profileNode["Setup"][i];
6464

6565
std::string key = GetKey(currentPlatform);
66-
std::vector<std::string> extensions;
66+
std::vector<std::string> setupSteps;
6767

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

71-
Setup[key] = extensions;
71+
Setup[key] = setupSteps;
7272
}
7373
}
7474

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

8181
std::string key = GetKey(currentPlatform);
82-
std::vector<std::string> extensions;
82+
std::vector<std::string> cleanupSteps;
8383

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

87-
Cleanup[key] = extensions;
87+
Cleanup[key] = cleanupSteps;
8888
}
8989
}
9090

Src/runcpp2/Data/StageInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,10 @@ bool runcpp2::Data::StageInfo::ConstructCommand(const SubstitutionMap& substitut
393393
{
394394
if(substitutionMap.count(substitutionsInCurrentPart.at(j)) == 0)
395395
{
396-
ssLOG_INFO("Failed to find " << substitutionsInCurrentPart.at(j) << " in " <<
396+
ssLOG_DEBUG("No substitution found for " << substitutionsInCurrentPart.at(j) << " in " <<
397397
currentRunParts.at(i).CommandPart);
398398

399-
ssLOG_INFO("Current run part is type repeat, skipping to next");
399+
ssLOG_DEBUG("Current run part is type repeat, skipping to next");
400400
continue;
401401
}
402402

Src/runcpp2/DependenciesHelper.cpp

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "runcpp2/PlatformUtil.hpp"
44
#include "ssLogger/ssLog.hpp"
55

6+
#include <unordered_set>
7+
68
namespace
79
{
810
bool PopulateLocalDependencies( const std::vector<runcpp2::Data::DependencyInfo*>& dependencies,
@@ -233,7 +235,7 @@ namespace
233235
{
234236
if(!runcpp2::HasValueFromPlatformMap(profile.FilesTypes.ObjectLinkFile.Extension))
235237
{
236-
ssLOG_ERROR("Failed to find shared library extensions for dependency " <<
238+
ssLOG_ERROR("Failed to find object file extensions for dependency " <<
237239
dependencyInfo.Name);
238240

239241
return false;
@@ -253,6 +255,15 @@ namespace
253255

254256
return true;
255257
}
258+
259+
ghc::filesystem::path ResolveSymlink(const ghc::filesystem::path& path, std::error_code& ec)
260+
{
261+
ghc::filesystem::path resolvedPath = ghc::filesystem::canonical(path, ec);
262+
if(ec)
263+
return path; // Return original path if canonical fails
264+
265+
return resolvedPath;
266+
}
256267
}
257268

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

479493
int minimumDependenciesCopiesCount = 0;
480494
for(int i = 0; i < availableDependencies.size(); ++i)
@@ -527,7 +541,9 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
527541
std::error_code e;
528542
if(ghc::filesystem::exists(srcPath, e))
529543
{
530-
outBinariesPaths.push_back(runcpp2::ProcessPath(srcPath));
544+
const std::string processedSrcPath = runcpp2::ProcessPath(srcPath);
545+
outBinariesPaths.push_back(processedSrcPath);
546+
binariesPathsSet.insert(processedSrcPath);
531547
++nonLinkFilesCount;
532548
ssLOG_INFO("Added binary path: " << srcPath.string());
533549
}
@@ -620,8 +636,8 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
620636
if(it.is_directory())
621637
continue;
622638

623-
std::string currentFileName = it.path().stem().string();
624-
std::string currentExtension = it.path().extension().string();
639+
std::string currentFileName = it.path().filename().string();
640+
std::string currentExtension = runcpp2::GetFileExtensionWithoutVersion(it.path());
625641

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

649665
bool extensionMatched = false;
650-
651666
for(int j = 0; j < extensionsToLink.size(); ++j)
652667
{
653668
if(currentExtension == extensionsToLink.at(j))
@@ -660,8 +675,28 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
660675
if(!extensionMatched)
661676
continue;
662677

663-
ssLOG_INFO("Linking " << it.path().string());
664-
outBinariesPaths.push_back(runcpp2::ProcessPath(it.path().string()));
678+
//Handle symlink
679+
ghc::filesystem::path resolvedPath = it.path();
680+
{
681+
std::error_code symlink_ec;
682+
resolvedPath = ResolveSymlink(resolvedPath, symlink_ec);
683+
if(symlink_ec)
684+
{
685+
ssLOG_ERROR("Failed to resolve symlink: " << symlink_ec.message());
686+
return false;
687+
}
688+
}
689+
690+
const std::string processedPath = runcpp2::ProcessPath(it.path().string());
691+
const std::string processedResolvedPath =
692+
runcpp2::ProcessPath(resolvedPath.string());
693+
694+
if(binariesPathsSet.count(processedResolvedPath) == 0)
695+
{
696+
ssLOG_INFO("Linking " << processedPath);
697+
outBinariesPaths.push_back(processedPath);
698+
binariesPathsSet.insert(processedResolvedPath);
699+
}
665700
}
666701
}
667702
}

Src/runcpp2/PlatformUtil.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "runcpp2/PlatformUtil.hpp"
22

33
#include "ssLogger/ssLog.hpp"
4+
#include "ghc/filesystem.hpp"
45
#include <stdio.h>
6+
#include <cctype>
57

68
namespace
79
{
@@ -156,3 +158,26 @@ bool runcpp2::RunCommandAndGetOutput( const std::string& command,
156158
return message;
157159
}
158160
#endif
161+
162+
std::string runcpp2::GetFileExtensionWithoutVersion(const ghc::filesystem::path& path)
163+
{
164+
std::string filename = path.filename().string();
165+
bool inNumericPart = true;
166+
int lastDotPos = filename.length();
167+
168+
for(int i = filename.length() - 1; i >= 0; --i)
169+
{
170+
if(filename[i] == '.')
171+
{
172+
if(!inNumericPart)
173+
return filename.substr(i, lastDotPos - i);
174+
175+
inNumericPart = true;
176+
lastDotPos = i;
177+
}
178+
else if(!std::isdigit(filename[i]))
179+
inNumericPart = false;
180+
}
181+
182+
return "";
183+
}

Src/runcpp2/runcpp2.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ namespace
218218
if(scriptFullMain != nullptr)
219219
{
220220
std::vector<std::string> runArgsCopy = runArgs;
221-
runArgsCopy.insert(runArgsCopy.begin(), scriptPath);
221+
runArgsCopy.insert( runArgsCopy.begin(),
222+
runcpp2::ProcessPath(compiledSharedLibPath.string()));
222223

223224
std::vector<char*> runArgsCStr(runArgsCopy.size());
224225
for(int i = 0; i < runArgsCopy.size(); ++i)
@@ -904,7 +905,7 @@ runcpp2::StartPipeline( const std::string& scriptPath,
904905
for(int i = 0; i < gatheredBinariesPaths.size(); ++i)
905906
{
906907
ghc::filesystem::path filePath(gatheredBinariesPaths.at(i));
907-
std::string extension = filePath.extension().string();
908+
std::string extension = runcpp2::GetFileExtensionWithoutVersion(filePath);
908909

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

0 commit comments

Comments
 (0)