33#include " runcpp2/PlatformUtil.hpp"
44#include " ssLogger/ssLog.hpp"
55
6+ #include < unordered_set>
7+
68namespace
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
258269bool 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 }
0 commit comments