Skip to content

Commit 8a01739

Browse files
Adding helper function for getting profile mapped values, ...
Adding helper function for getting profile mapped values, Using helper function for getting profile/platform mapped values
1 parent 9fbc151 commit 8a01739

File tree

4 files changed

+89
-152
lines changed

4 files changed

+89
-152
lines changed

Include/runcpp2/PlatformUtil.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define RUNCPP2_PLATFORM_UTIL_HPP
33

44
#include "runcpp2/Data/ParseCommon.hpp"
5+
#include "runcpp2/Data/Profile.hpp"
56
#include "System2.h"
67

78
#include <cstdint>
@@ -65,6 +66,37 @@ namespace runcpp2
6566
}
6667

6768
std::string GetFileExtensionWithoutVersion(const ghc::filesystem::path& path);
69+
70+
template <typename T>
71+
inline bool HasValueFromProfileMap( const Data::Profile& profile,
72+
const std::unordered_map<ProfileName, T>& map)
73+
{
74+
std::vector<std::string> profileNames;
75+
profile.GetNames(profileNames);
76+
77+
for(int i = 0; i < profileNames.size(); ++i)
78+
{
79+
if(map.find(profileNames.at(i)) != map.end())
80+
return true;
81+
}
82+
return false;
83+
}
84+
85+
template <typename T>
86+
inline const T* GetValueFromProfileMap( const Data::Profile& profile,
87+
const std::unordered_map<ProfileName, T>& map)
88+
{
89+
std::vector<std::string> profileNames;
90+
profile.GetNames(profileNames);
91+
92+
for(int i = 0; i < profileNames.size(); ++i)
93+
{
94+
auto it = map.find(profileNames.at(i));
95+
if(it != map.end())
96+
return &it->second;
97+
}
98+
return nullptr;
99+
}
68100
}
69101

70102
#endif

Src/runcpp2/CompilingLinking.cpp

Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,17 @@ namespace
3030
const runcpp2::Data::ProfilesFlagsOverride& currentFlagsOverride =
3131
*runcpp2::GetValueFromPlatformMap(overrideFlags);
3232

33-
std::string foundProfileName;
34-
std::vector<std::string> currentProfileNames;
35-
profile.GetNames(currentProfileNames);
33+
const runcpp2::Data::FlagsOverrideInfo* profileFlagsOverride =
34+
runcpp2::GetValueFromProfileMap(profile, currentFlagsOverride.FlagsOverrides);
3635

37-
for(int i = 0; i < currentProfileNames.size(); ++i)
38-
{
39-
if(currentFlagsOverride.FlagsOverrides.count(currentProfileNames.at(i)) > 0)
40-
{
41-
foundProfileName = currentProfileNames.at(i);
42-
break;
43-
}
44-
}
45-
46-
if(foundProfileName.empty())
36+
if(!profileFlagsOverride)
4737
{
4838
ssLOG_INFO("No override flags found for current profile");
4939
return;
5040
}
5141

5242
std::vector<std::string> flagsToRemove;
53-
runcpp2::SplitString( currentFlagsOverride.FlagsOverrides.at(foundProfileName).Remove,
54-
" ",
55-
flagsToRemove);
43+
runcpp2::SplitString(profileFlagsOverride->Remove, " ", flagsToRemove);
5644

5745
for(int i = 0; i < flagsToRemove.size(); ++i)
5846
{
@@ -74,7 +62,7 @@ namespace
7462
}
7563

7664
runcpp2::TrimRight(inOutFlags);
77-
inOutFlags += " " + currentFlagsOverride.FlagsOverrides.at(foundProfileName).Append;
65+
inOutFlags += " " + profileFlagsOverride->Append;
7866
runcpp2::TrimRight(inOutFlags);
7967
}
8068

@@ -132,27 +120,14 @@ namespace
132120
const runcpp2::Data::ProfilesDefines& platformDefines =
133121
*runcpp2::GetValueFromPlatformMap(scriptInfo.Defines);
134122

135-
std::vector<std::string> profileNames;
136-
profile.GetNames(profileNames);
123+
const std::vector<runcpp2::Data::Define>* profileDefines =
124+
runcpp2::GetValueFromProfileMap(profile, platformDefines.Defines);
137125

138-
std::string validProfileName;
139-
for(int i = 0; i < profileNames.size(); ++i)
126+
if(profileDefines)
140127
{
141-
if(platformDefines.Defines.count(profileNames[i]) > 0)
128+
for(int i = 0; i < profileDefines->size(); ++i)
142129
{
143-
validProfileName = profileNames.at(i);
144-
break;
145-
}
146-
}
147-
148-
if(!validProfileName.empty())
149-
{
150-
const std::vector<runcpp2::Data::Define>& profileDefines =
151-
platformDefines.Defines.at(validProfileName);
152-
153-
for(int i = 0; i < profileDefines.size(); ++i)
154-
{
155-
const runcpp2::Data::Define& define = profileDefines.at(i);
130+
const runcpp2::Data::Define& define = profileDefines->at(i);
156131
if(define.HasValue)
157132
{
158133
substitutionMapTemplate["{DefineName}"].push_back(define.Name);
@@ -755,34 +730,19 @@ bool runcpp2::CompileAndLinkScript( const ghc::filesystem::path& buildDir,
755730
//Add link flags for the dependencies
756731
for(int i = 0; i < availableDependencies.size(); ++i)
757732
{
758-
std::string targetProfileName;
759-
std::vector<std::string> currentProfileNames;
760-
profile.GetNames(currentProfileNames);
761-
762733
if(!runcpp2::HasValueFromPlatformMap(availableDependencies.at(i)->LinkProperties))
763734
continue;
764735

765736
const runcpp2::Data::DependencyLinkProperty& linkProperty =
766737
*runcpp2::GetValueFromPlatformMap(availableDependencies.at(i)->LinkProperties);
767738

768-
// Find the matching profile
769-
for(int j = 0; j < currentProfileNames.size(); ++j)
770-
{
771-
if( linkProperty.ProfileProperties.find(currentProfileNames.at(j)) !=
772-
linkProperty.ProfileProperties.end())
773-
{
774-
targetProfileName = currentProfileNames.at(j);
775-
break;
776-
}
777-
}
778-
779-
if(targetProfileName.empty())
739+
const runcpp2::Data::ProfileLinkProperty* profileLinkProperty =
740+
runcpp2::GetValueFromProfileMap(profile, linkProperty.ProfileProperties);
741+
742+
if(!profileLinkProperty)
780743
continue;
781744

782-
const runcpp2::Data::ProfileLinkProperty& profileLinkProperty =
783-
linkProperty.ProfileProperties.at(targetProfileName);
784-
785-
for(const std::string& option : profileLinkProperty.AdditionalLinkOptions)
745+
for(const std::string& option : profileLinkProperty->AdditionalLinkOptions)
786746
dependenciesLinkFlags += option + " ";
787747
}
788748

Src/runcpp2/DependenciesHelper.cpp

Lines changed: 29 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ namespace
119119
return true;
120120

121121
//Find the platform name we use for setup
122-
PlatformName chosenPlatformName;
123122
if(!runcpp2::HasValueFromPlatformMap(steps))
124123
{
125124
if(required)
@@ -134,39 +133,26 @@ namespace
134133
const runcpp2::Data::DependencyCommands& dependencySteps =
135134
*runcpp2::GetValueFromPlatformMap(steps);
136135

137-
std::string profileNameToUse;
138-
std::vector<std::string> currentProfileNames;
139-
profile.GetNames(currentProfileNames);
140-
141-
for(int i = 0; i < currentProfileNames.size(); ++i)
142-
{
143-
if(dependencySteps.CommandSteps.count(currentProfileNames.at(i)) > 0)
144-
{
145-
profileNameToUse = currentProfileNames.at(i);
146-
break;
147-
}
148-
}
149-
150-
if(profileNameToUse.empty())
136+
const std::vector<std::string>* commands =
137+
runcpp2::GetValueFromProfileMap(profile, dependencySteps.CommandSteps);
138+
139+
if(!commands)
151140
{
152141
ssLOG_ERROR("Failed to find steps for profile " << profile.Name <<
153142
" for current platform");
154143
return false;
155144
}
156145

157146
//Run the commands
158-
const std::vector<std::string>& commands =
159-
dependencySteps.CommandSteps.at(profileNameToUse);
160-
161-
for(int k = 0; k < commands.size(); ++k)
147+
for(int k = 0; k < commands->size(); ++k)
162148
{
163149
std::string processedDependencyPath = runcpp2::ProcessPath(dependenciesCopiedDirectory);
164-
ssLOG_INFO( "Running command: " << commands.at(k) << " in " <<
150+
ssLOG_INFO( "Running command: " << commands->at(k) << " in " <<
165151
processedDependencyPath);
166152

167153
int returnCode = 0;
168154
std::string output;
169-
if(!runcpp2::RunCommandAndGetOutput(commands.at(k),
155+
if(!runcpp2::RunCommandAndGetOutput(commands->at(k),
170156
output,
171157
returnCode,
172158
processedDependencyPath))
@@ -485,7 +471,6 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
485471
const Data::Profile& profile,
486472
std::vector<std::string>& outBinariesPaths)
487473
{
488-
std::vector<std::string> platformNames = GetPlatformNames();
489474
std::unordered_set<std::string> binariesPathsSet;
490475
for(int i = 0; i < outBinariesPaths.size(); ++i)
491476
binariesPathsSet.insert(outBinariesPaths[i]);
@@ -508,35 +493,22 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
508493
for(int i = 0; i < availableDependencies.size(); ++i)
509494
{
510495
ssLOG_INFO("Evaluating dependency " << availableDependencies.at(i)->Name);
511-
std::vector<std::string> currentProfileNames;
512-
profile.GetNames(currentProfileNames);
513496

514497
if(runcpp2::HasValueFromPlatformMap(availableDependencies.at(i)->FilesToCopy))
515498
{
516499
const runcpp2::Data::FilesToCopyInfo& filesToCopy =
517500
*runcpp2::GetValueFromPlatformMap(availableDependencies.at(i)->FilesToCopy);
518501

519-
std::string profileNameToUse;
520-
for(int j = 0; j < currentProfileNames.size(); ++j)
521-
{
522-
if( filesToCopy.ProfileFiles.find(currentProfileNames.at(j)) !=
523-
filesToCopy.ProfileFiles.end())
524-
{
525-
profileNameToUse = currentProfileNames.at(j);
526-
break;
527-
}
528-
}
502+
const std::vector<std::string>* filesToGatherForProfile =
503+
runcpp2::GetValueFromProfileMap(profile, filesToCopy.ProfileFiles);
529504

530-
if(!profileNameToUse.empty())
505+
if(filesToGatherForProfile)
531506
{
532-
const std::vector<std::string>& filesToGatherForProfile =
533-
filesToCopy.ProfileFiles.at(profileNameToUse);
534-
535-
for(int j = 0; j < filesToGatherForProfile.size(); ++j)
507+
for(int j = 0; j < filesToGatherForProfile->size(); ++j)
536508
{
537509
ghc::filesystem::path srcPath =
538510
ghc::filesystem::path(dependenciesCopiesPaths.at(i)) /
539-
filesToGatherForProfile.at(j);
511+
filesToGatherForProfile->at(j);
540512

541513
std::error_code e;
542514
if(ghc::filesystem::exists(srcPath, e))
@@ -563,21 +535,12 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
563535
{
564536
return false;
565537
}
566-
567-
for(int j = 0; j < platformNames.size(); ++j)
568-
{
569-
if( profile.FilesTypes.DebugSymbolFile.Extension.find(platformNames.at(j)) ==
570-
profile.FilesTypes.DebugSymbolFile.Extension.end())
571-
{
572-
continue;
573-
}
538+
539+
const std::string* debugSymbolExt =
540+
runcpp2::GetValueFromPlatformMap(profile.FilesTypes.DebugSymbolFile.Extension);
574541

575-
extensionsToLink.push_back(profile .FilesTypes
576-
.DebugSymbolFile
577-
.Extension
578-
.at(platformNames.at(j)));
579-
break;
580-
}
542+
if(debugSymbolExt)
543+
extensionsToLink.push_back(*debugSymbolExt);
581544
}
582545

583546
if(availableDependencies.at(i)->LibraryType == Data::DependencyLibraryType::HEADER)
@@ -597,36 +560,24 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
597560
const Data::DependencyLinkProperty& linkProperty =
598561
*runcpp2::GetValueFromPlatformMap(linkProperties);
599562

600-
// Find the matching profile
601-
ProfileName targetProfileName;
602-
for(int j = 0; j < currentProfileNames.size(); ++j)
603-
{
604-
if( linkProperty.ProfileProperties.find(currentProfileNames.at(j)) !=
605-
linkProperty.ProfileProperties.end())
606-
{
607-
targetProfileName = currentProfileNames.at(j);
608-
break;
609-
}
610-
}
611-
612-
if(targetProfileName.empty())
563+
const Data::ProfileLinkProperty* profileLinkProperty =
564+
runcpp2::GetValueFromProfileMap(profile, linkProperty.ProfileProperties);
565+
566+
if(!profileLinkProperty)
613567
continue;
614568

615-
const Data::ProfileLinkProperty& profileLinkProperty =
616-
linkProperty.ProfileProperties.at(targetProfileName);
617-
618569
for(int searchLibIndex = 0;
619-
searchLibIndex < profileLinkProperty.SearchLibraryNames.size();
570+
searchLibIndex < profileLinkProperty->SearchLibraryNames.size();
620571
++searchLibIndex)
621572
{
622573
for(int searchDirIndex = 0;
623-
searchDirIndex < profileLinkProperty.SearchDirectories.size();
574+
searchDirIndex < profileLinkProperty->SearchDirectories.size();
624575
++searchDirIndex)
625576
{
626577
std::string currentSearchLibraryName =
627-
profileLinkProperty.SearchLibraryNames.at(searchLibIndex);
578+
profileLinkProperty->SearchLibraryNames.at(searchLibIndex);
628579
std::string currentSearchDirectory =
629-
profileLinkProperty.SearchDirectories.at(searchDirIndex);
580+
profileLinkProperty->SearchDirectories.at(searchDirIndex);
630581

631582
if(!ghc::filesystem::path(currentSearchDirectory).is_absolute())
632583
{
@@ -662,10 +613,12 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
662613
if(currentFileName.find(currentSearchLibraryName) != std::string::npos)
663614
nameMatched = true;
664615

665-
for(int excludeIndex = 0; excludeIndex < profileLinkProperty.ExcludeLibraryNames.size(); ++excludeIndex)
616+
for(int excludeIndex = 0;
617+
excludeIndex < profileLinkProperty->ExcludeLibraryNames.size();
618+
++excludeIndex)
666619
{
667620
std::string currentExcludeLibraryName =
668-
profileLinkProperty.ExcludeLibraryNames.at(excludeIndex);
621+
profileLinkProperty->ExcludeLibraryNames.at(excludeIndex);
669622

670623
if(currentFileName.find(currentExcludeLibraryName) != std::string::npos)
671624
{

0 commit comments

Comments
 (0)