Skip to content

Commit da0391c

Browse files
Cleanup to perform all copying in 1 place
1 parent e9367af commit da0391c

File tree

3 files changed

+106
-158
lines changed

3 files changed

+106
-158
lines changed

Include/runcpp2/DependenciesHelper.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ namespace runcpp2
3535
const std::vector<Data::DependencyInfo*>& availableDependencies,
3636
const std::vector<std::string>& dependenciesLocalCopiesPaths);
3737

38-
bool CopyDependenciesBinaries( const ghc::filesystem::path& buildDir,
39-
const std::vector<Data::DependencyInfo*>& availableDependencies,
38+
bool GatherDependenciesBinaries(const std::vector<Data::DependencyInfo*>& availableDependencies,
4039
const std::vector<std::string>& dependenciesCopiesPaths,
4140
const Data::Profile& profile,
42-
std::vector<std::string>& outCopiedBinariesPaths);
41+
std::vector<std::string>& outBinariesPaths);
4342
}
4443

4544
#endif

Src/runcpp2/DependenciesHelper.cpp

Lines changed: 36 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ namespace
180180
return true;
181181
}
182182

183-
bool GetDependencyBinariesExtensionsToCopy( const runcpp2::Data::DependencyInfo& dependencyInfo,
183+
bool GetDependencyBinariesExtensionsToLink( const runcpp2::Data::DependencyInfo& dependencyInfo,
184184
const runcpp2::Data::Profile& profile,
185-
std::vector<std::string>& outExtensionsToCopy)
185+
std::vector<std::string>& outExtensionsToLink)
186186
{
187187
static_assert((int)runcpp2::Data::DependencyLibraryType::COUNT == 4, "");
188188
switch(dependencyInfo.LibraryType)
@@ -197,7 +197,7 @@ namespace
197197
return false;
198198
}
199199

200-
outExtensionsToCopy.push_back(
200+
outExtensionsToLink.push_back(
201201
*runcpp2::GetValueFromPlatformMap(profile .FilesTypes
202202
.StaticLinkFile
203203
.Extension));
@@ -215,13 +215,13 @@ namespace
215215
return false;
216216
}
217217

218-
outExtensionsToCopy.push_back(
218+
outExtensionsToLink.push_back(
219219
*runcpp2::GetValueFromPlatformMap(profile.FilesTypes.SharedLinkFile.Extension));
220220

221221
if( *runcpp2::GetValueFromPlatformMap(profile.FilesTypes.SharedLinkFile.Extension) !=
222222
*runcpp2::GetValueFromPlatformMap(profile.FilesTypes.SharedLibraryFile.Extension))
223223
{
224-
outExtensionsToCopy.push_back(
224+
outExtensionsToLink.push_back(
225225
*runcpp2::GetValueFromPlatformMap(profile .FilesTypes
226226
.SharedLibraryFile
227227
.Extension));
@@ -239,7 +239,7 @@ namespace
239239
return false;
240240
}
241241

242-
outExtensionsToCopy.push_back(
242+
outExtensionsToLink.push_back(
243243
*runcpp2::GetValueFromPlatformMap(profile.FilesTypes.ObjectLinkFile.Extension));
244244

245245
break;
@@ -468,12 +468,11 @@ bool runcpp2::BuildDependencies(const runcpp2::Data::Profile& profile,
468468
return true;
469469
}
470470

471-
bool runcpp2::CopyDependenciesBinaries( const ghc::filesystem::path& buildDir,
472-
const std::vector<Data::DependencyInfo*>&
473-
availableDependencies,
474-
const std::vector<std::string>& dependenciesCopiesPaths,
475-
const Data::Profile& profile,
476-
std::vector<std::string>& outCopiedBinariesPaths)
471+
bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyInfo*>&
472+
availableDependencies,
473+
const std::vector<std::string>& dependenciesCopiesPaths,
474+
const Data::Profile& profile,
475+
std::vector<std::string>& outBinariesPaths)
477476
{
478477
std::vector<std::string> platformNames = GetPlatformNames();
479478

@@ -491,8 +490,10 @@ bool runcpp2::CopyDependenciesBinaries( const ghc::filesystem::path& buildDir,
491490
return false;
492491
}
493492

493+
int nonLinkFilesCount = 0;
494494
for(int i = 0; i < availableDependencies.size(); ++i)
495495
{
496+
ssLOG_INFO("Evaluating dependency " << availableDependencies.at(i)->Name);
496497
std::vector<std::string> currentProfileNames;
497498
profile.GetNames(currentProfileNames);
498499

@@ -514,52 +515,35 @@ bool runcpp2::CopyDependenciesBinaries( const ghc::filesystem::path& buildDir,
514515

515516
if(!profileNameToUse.empty())
516517
{
517-
const std::vector<std::string>& filesToCopyForProfile =
518+
const std::vector<std::string>& filesToGatherForProfile =
518519
filesToCopy.ProfileFiles.at(profileNameToUse);
519520

520-
for(int j = 0; j < filesToCopyForProfile.size(); ++j)
521+
for(int j = 0; j < filesToGatherForProfile.size(); ++j)
521522
{
522523
ghc::filesystem::path srcPath =
523524
ghc::filesystem::path(dependenciesCopiesPaths.at(i)) /
524-
filesToCopyForProfile.at(j);
525-
526-
ghc::filesystem::path destPath =
527-
buildDir / ghc::filesystem::path(filesToCopyForProfile.at(j)).filename();
525+
filesToGatherForProfile.at(j);
528526

529527
std::error_code e;
530-
//TODO: Maybe we can check if destPath timestamp is newer and avoid copy?
531528
if(ghc::filesystem::exists(srcPath, e))
532529
{
533-
ghc::filesystem::copy( srcPath,
534-
destPath,
535-
ghc::filesystem::copy_options::overwrite_existing,
536-
e);
537-
538-
if(e)
539-
{
540-
ssLOG_ERROR("Failed to copy file from " << srcPath.string() <<
541-
" to " << destPath.string());
542-
ssLOG_ERROR("Error: " << e.message());
543-
return false;
544-
}
545-
546-
ssLOG_INFO("Copied from " << srcPath.string());
547-
ssLOG_INFO("Copied to " << destPath.string());
548-
outCopiedBinariesPaths.push_back(runcpp2::ProcessPath(destPath));
530+
outBinariesPaths.push_back(runcpp2::ProcessPath(srcPath));
531+
++nonLinkFilesCount;
532+
ssLOG_INFO("Added binary path: " << srcPath.string());
549533
}
550534
else
551535
ssLOG_WARNING("File not found: " << srcPath.string());
552536
}
553537
}
554538
}
555539

556-
std::vector<std::string> extensionsToCopy;
540+
std::vector<std::string> extensionsToLink;
557541

558-
//Get all the file extensions to copy
542+
//Get all the file extensions to gather
559543
{
560-
if(!GetDependencyBinariesExtensionsToCopy( *availableDependencies.at(i),
544+
if(!GetDependencyBinariesExtensionsToLink( *availableDependencies.at(i),
561545
profile,
562-
extensionsToCopy))
546+
extensionsToLink))
563547
{
564548
return false;
565549
}
@@ -572,7 +556,10 @@ bool runcpp2::CopyDependenciesBinaries( const ghc::filesystem::path& buildDir,
572556
continue;
573557
}
574558

575-
extensionsToCopy.push_back(profile.FilesTypes.DebugSymbolFile.Extension.at(platformNames.at(j)));
559+
extensionsToLink.push_back(profile .FilesTypes
560+
.DebugSymbolFile
561+
.Extension
562+
.at(platformNames.at(j)));
576563
break;
577564
}
578565
}
@@ -602,7 +589,7 @@ bool runcpp2::CopyDependenciesBinaries( const ghc::filesystem::path& buildDir,
602589
}
603590
const Data::DependencyLinkProperty& searchProperty = foundPropertyIt->second;
604591

605-
//Copy the files with extensions that contains the search name if needed
592+
//Get the files with extensions that contains the search name if needed
606593
for(int j = 0; j < searchProperty.SearchLibraryNames.size(); ++j)
607594
{
608595
for(int k = 0; k < searchProperty.SearchDirectories.size(); ++k)
@@ -661,9 +648,9 @@ bool runcpp2::CopyDependenciesBinaries( const ghc::filesystem::path& buildDir,
661648

662649
bool extensionMatched = false;
663650

664-
for(int j = 0; j < extensionsToCopy.size(); ++j)
651+
for(int j = 0; j < extensionsToLink.size(); ++j)
665652
{
666-
if(currentExtension == extensionsToCopy.at(j))
653+
if(currentExtension == extensionsToLink.at(j))
667654
{
668655
extensionMatched = true;
669656
break;
@@ -673,77 +660,20 @@ bool runcpp2::CopyDependenciesBinaries( const ghc::filesystem::path& buildDir,
673660
if(!extensionMatched)
674661
continue;
675662

676-
//TODO: Group object files in folders to avoid name collision
677-
ghc::filesystem::path copiedPath = buildDir / it.path().filename();
678-
679-
//Check if we have previously copied the dependencies to the folder
680-
if(ghc::filesystem::exists(copiedPath, e))
681-
{
682-
ghc::filesystem::file_time_type builtWriteTime =
683-
ghc::filesystem::last_write_time(it.path(), e);
684-
685-
if(e)
686-
{
687-
ssLOG_ERROR("Failed to get write time of " << it.path().string());
688-
ssLOG_ERROR("Error: " << e.message());
689-
return false;
690-
}
691-
692-
ghc::filesystem::file_time_type copiedWriteTime =
693-
ghc::filesystem::last_write_time(copiedPath, e);
694-
695-
if(e)
696-
{
697-
ssLOG_ERROR("Failed to get write time of " << copiedPath.string());
698-
ssLOG_ERROR("Error: " << e.message());
699-
return false;
700-
}
701-
702-
//If the copied write time is newer than the original one, that means
703-
// the copy is up to date
704-
if(builtWriteTime <= copiedWriteTime)
705-
{
706-
ssLOG_INFO(copiedPath.string() << " is up to date");
707-
outCopiedBinariesPaths.push_back(runcpp2::ProcessPath(copiedPath));
708-
continue;
709-
}
710-
else
711-
ssLOG_INFO(copiedPath.string() << " is outdated");
712-
}
713-
714-
//Copy the dependency binary to our folder
715-
std::error_code copyErrorCode;
716-
ghc::filesystem::copy( it.path(),
717-
buildDir,
718-
ghc::filesystem::copy_options::overwrite_existing,
719-
copyErrorCode);
720-
721-
if(copyErrorCode)
722-
{
723-
ssLOG_ERROR("Failed to copy file from " << it.path().string() <<
724-
" to " << buildDir.string());
725-
726-
ssLOG_ERROR("Error: " << copyErrorCode.message());
727-
return false;
728-
}
729-
730-
731-
ssLOG_INFO("Copied from " << it.path().string());
732-
ssLOG_INFO("Copied to " << copiedPath.string());
733-
outCopiedBinariesPaths.push_back(runcpp2::ProcessPath(copiedPath));
663+
ssLOG_INFO("Linking " << it.path().string());
664+
outBinariesPaths.push_back(runcpp2::ProcessPath(it.path().string()));
734665
}
735666
}
736667
}
737668
}
738669

739670
//Do a check to see if any dependencies are copied
740-
if(outCopiedBinariesPaths.size() < minimumDependenciesCopiesCount)
671+
if(outBinariesPaths.size() - nonLinkFilesCount < minimumDependenciesCopiesCount)
741672
{
742-
ssLOG_WARNING("outCopiedBinariesPaths.size() does not match minimumDependenciesCopiesCount");
743-
ssLOG_WARNING("outCopiedBinariesPaths are");
673+
ssLOG_WARNING("We could missing some link files for dependencies");
744674

745-
for(int i = 0; i < outCopiedBinariesPaths.size(); ++i)
746-
ssLOG_WARNING("outCopiedBinariesPaths[" << i << "]: " << outCopiedBinariesPaths.at(i));
675+
for(int i = 0; i < outBinariesPaths.size(); ++i)
676+
ssLOG_WARNING("outBinariesPaths[" << i << "]: " << outBinariesPaths.at(i));
747677
}
748678

749679
return true;

0 commit comments

Comments
 (0)