@@ -563,7 +563,7 @@ bool runcpp2::CopyDependenciesBinaries( const std::string& scriptPath,
563563 }
564564 const Data::DependencyLinkProperty& searchProperty = foundPropertyIt->second ;
565565
566- // Copy the files with extensions that contains the search name
566+ // Copy the files with extensions that contains the search name if needed
567567 for (int j = 0 ; j < searchProperty.SearchLibraryNames .size (); ++j)
568568 {
569569 for (int k = 0 ; k < searchProperty.SearchDirectories .size (); ++k)
@@ -580,15 +580,16 @@ bool runcpp2::CopyDependenciesBinaries( const std::string& scriptPath,
580580 ssLOG_DEBUG (" currentSearchDirectory: " << currentSearchDirectory);
581581 ssLOG_DEBUG (" currentSearchLibraryName: " << currentSearchLibraryName);
582582
583- std::error_code _ ;
584- if ( !ghc::filesystem::exists (currentSearchDirectory, _ ) ||
585- !ghc::filesystem::is_directory (currentSearchDirectory, _ ))
583+ std::error_code e ;
584+ if ( !ghc::filesystem::exists (currentSearchDirectory, e ) ||
585+ !ghc::filesystem::is_directory (currentSearchDirectory, e ))
586586 {
587587 ssLOG_INFO (" Invalid search path: " << currentSearchDirectory);
588588 continue ;
589589 }
590590
591- for (auto it : ghc::filesystem::directory_iterator (currentSearchDirectory, _))
591+ // Iterate each files in the directory we are searching
592+ for (auto it : ghc::filesystem::directory_iterator (currentSearchDirectory, e))
592593 {
593594 if (it.is_directory ())
594595 continue ;
@@ -633,6 +634,45 @@ bool runcpp2::CopyDependenciesBinaries( const std::string& scriptPath,
633634 if (!extensionMatched)
634635 continue ;
635636
637+ std::string copiedPath = runcpp2ScriptDir + " /" + it.path ().filename ().string ();
638+
639+ // Check if we have previously copied the dependencies to the folder
640+ if (ghc::filesystem::exists (copiedPath, e))
641+ {
642+ ghc::filesystem::file_time_type builtWriteTime =
643+ ghc::filesystem::last_write_time (it.path (), e);
644+
645+ if (e)
646+ {
647+ ssLOG_ERROR (" Failed to get write time of " << it.path ().string ());
648+ ssLOG_ERROR (" Error: " << e.message ());
649+ return false ;
650+ }
651+
652+ ghc::filesystem::file_time_type copiedWriteTime =
653+ ghc::filesystem::last_write_time (copiedPath, e);
654+
655+ if (e)
656+ {
657+ ssLOG_ERROR (" Failed to get write time of " << copiedPath);
658+ ssLOG_ERROR (" Error: " << e.message ());
659+ return false ;
660+ }
661+
662+ // If the copied write time is newer than the original one, that means
663+ // the copy is up to date
664+ if (builtWriteTime <= copiedWriteTime)
665+ {
666+ ssLOG_INFO (copiedPath << " is up to date" );
667+ copiedPath = runcpp2::ProcessPath (copiedPath);
668+ outCopiedBinariesPaths.push_back (copiedPath);
669+ continue ;
670+ }
671+ else
672+ ssLOG_INFO (copiedPath << " is outdated" );
673+ }
674+
675+ // Copy the dependency binary to our folder
636676 std::error_code copyErrorCode;
637677 ghc::filesystem::copy ( it.path (),
638678 runcpp2ScriptDir,
@@ -648,8 +688,11 @@ bool runcpp2::CopyDependenciesBinaries( const std::string& scriptPath,
648688 return false ;
649689 }
650690
651- ssLOG_INFO (" Copied " << it.path ().string ());
652- outCopiedBinariesPaths.push_back (it.path ().string ());
691+
692+ ssLOG_INFO (" Copied from " << it.path ().string ());
693+ ssLOG_INFO (" Copied to " << copiedPath);
694+ copiedPath = runcpp2::ProcessPath (copiedPath);
695+ outCopiedBinariesPaths.push_back (copiedPath);
653696 }
654697 }
655698 }
0 commit comments