Skip to content

Commit 2ba0454

Browse files
Refactoring to return list of names for a profile
1 parent 4994cf8 commit 2ba0454

File tree

7 files changed

+74
-91
lines changed

7 files changed

+74
-91
lines changed

Include/runcpp2/CompilingLinking.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ namespace runcpp2
99
{
1010
bool CompileAndLinkScript( const std::string& scriptPath,
1111
const Data::ScriptInfo& scriptInfo,
12+
const std::vector<Data::DependencyInfo*>& availableDependencies,
1213
const Data::Profile& profile,
1314
const std::vector<std::string>& copiedDependenciesBinariesPaths,
1415
bool buildExecutable,
1516
const std::string exeExt);
1617
}
1718

18-
#endif
19+
#endif

Include/runcpp2/Data/Profile.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ namespace runcpp2
2323
public:
2424
std::string Name;
2525

26-
//TODO: Add a function for getting value from map that uses profile name as key
27-
// Or maybe just a function that return all the names
28-
2926
std::unordered_set<std::string> NameAliases;
3027
std::unordered_set<std::string> FileExtensions;
3128
std::unordered_set<std::string> Languages;
@@ -36,6 +33,7 @@ namespace runcpp2
3633
StageInfo Compiler;
3734
StageInfo Linker;
3835

36+
void GetNames(std::vector<std::string>& outNames) const;
3937
bool ParseYAML_Node(ryml::ConstNodeRef& profileNode);
4038
std::string ToString(std::string indentation) const;
4139
};

Src/runcpp2/CompilingLinking.cpp

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,15 @@ namespace
3131
*runcpp2::GetValueFromPlatformMap(overrideFlags);
3232

3333
std::string foundProfileName;
34+
std::vector<std::string> currentProfileNames;
35+
profile.GetNames(currentProfileNames);
3436

35-
if(currentFlagsOverride.FlagsOverrides.count(profile.Name) > 0)
36-
foundProfileName = profile.Name;
37-
else
37+
for(int i = 0; i < currentProfileNames.size(); ++i)
3838
{
39-
for(auto it = profile.NameAliases.begin(); it != profile.NameAliases.end(); ++it)
39+
if(currentFlagsOverride.FlagsOverrides.count(currentProfileNames.at(i)) > 0)
4040
{
41-
if(currentFlagsOverride.FlagsOverrides.count(*it) > 0)
42-
{
43-
foundProfileName = *it;
44-
break;
45-
}
41+
foundProfileName = currentProfileNames.at(i);
42+
break;
4643
}
4744
}
4845

@@ -83,6 +80,7 @@ namespace
8380

8481
bool CompileScript( const std::string& scriptPath,
8582
const runcpp2::Data::ScriptInfo& scriptInfo,
83+
const std::vector<runcpp2::Data::DependencyInfo*>& availableDependencies,
8684
const runcpp2::Data::Profile& profile,
8785
bool compileAsExecutable,
8886
std::string& outScriptObjectFilePath)
@@ -112,15 +110,13 @@ namespace
112110

113111
//Include Directories
114112
{
115-
for(int i = 0; i < scriptInfo.Dependencies.size(); ++i)
113+
//TODO(NOW): Use filtered dependencies instead
114+
for(int i = 0; i < availableDependencies.size(); ++i)
116115
{
117-
if(!runcpp2::IsDependencyAvailableForThisPlatform(scriptInfo.Dependencies.at(i)))
118-
continue;
119-
120-
for(int j = 0; j < scriptInfo.Dependencies.at(i).AbsoluteIncludePaths.size(); ++j)
116+
for(int j = 0; j < availableDependencies.at(i)->AbsoluteIncludePaths.size(); ++j)
121117
{
122118
const std::string& currentIncludePath =
123-
scriptInfo.Dependencies.at(i).AbsoluteIncludePaths.at(j);
119+
availableDependencies.at(i)->AbsoluteIncludePaths.at(j);
124120

125121
substitutionMap["{IncludeDirectoryPath}"].push_back(currentIncludePath);
126122
}
@@ -262,6 +258,7 @@ namespace
262258

263259
bool LinkScript(const std::string& scriptPath,
264260
const runcpp2::Data::ScriptInfo& scriptInfo,
261+
const std::vector<runcpp2::Data::DependencyInfo*>& availableDependencies,
265262
const runcpp2::Data::Profile& profile,
266263
const std::string& scriptObjectFilePath,
267264
const std::vector<std::string>& copiedDependenciesBinariesPaths,
@@ -288,46 +285,27 @@ namespace
288285
AppendAndRemoveFlags(profile, scriptInfo.OverrideLinkFlags, linkFlags);
289286

290287
//Add link flags for the dependencies
291-
for(int i = 0; i < scriptInfo.Dependencies.size(); ++i)
288+
//TODO(NOW): Use the filtered dependencies
289+
for(int i = 0; i < availableDependencies.size(); ++i)
292290
{
293-
if(!runcpp2::IsDependencyAvailableForThisPlatform(scriptInfo.Dependencies.at(i)))
294-
continue;
295-
296291
std::string targetProfileName;
292+
std::vector<std::string> currentProfileNames;
293+
profile.GetNames(currentProfileNames);
297294

298-
//Check for profile name first
299-
if( scriptInfo.Dependencies.at(i).LinkProperties.find(profile.Name) !=
300-
scriptInfo.Dependencies.at(i).LinkProperties.end())
295+
for(int j = 0; j < currentProfileNames.size(); ++j)
301296
{
302-
targetProfileName = profile.Name;
303-
}
304-
else
305-
{
306-
//If not check for profile name aliases
307-
for(const auto& alias : profile.NameAliases)
308-
{
309-
if( scriptInfo.Dependencies.at(i).LinkProperties.find(alias) !=
310-
scriptInfo.Dependencies.at(i).LinkProperties.end())
311-
{
312-
targetProfileName = alias;
313-
break;
314-
}
315-
}
316-
317-
//Final check for "All"
318-
if( targetProfileName.empty() &&
319-
scriptInfo.Dependencies.at(i).LinkProperties.find("All") !=
320-
scriptInfo.Dependencies.at(i).LinkProperties.end())
297+
if( availableDependencies.at(i)->LinkProperties.find(currentProfileNames.at(j)) !=
298+
availableDependencies.at(i)->LinkProperties.end())
321299
{
322-
targetProfileName = "All";
300+
targetProfileName = currentProfileNames.at(j);
323301
}
324302
}
325303

326304
if(targetProfileName.empty())
327305
continue;
328306

329307
const runcpp2::Data::DependencyLinkProperty& currentLinkProperty =
330-
scriptInfo.Dependencies.at(i).LinkProperties.at(targetProfileName);
308+
availableDependencies.at(i)->LinkProperties.at(targetProfileName);
331309

332310
if(runcpp2::HasValueFromPlatformMap(currentLinkProperty.AdditionalLinkOptions))
333311
{
@@ -648,6 +626,7 @@ namespace
648626

649627
bool runcpp2::CompileAndLinkScript( const std::string& scriptPath,
650628
const Data::ScriptInfo& scriptInfo,
629+
const std::vector<Data::DependencyInfo*>& availableDependencies,
651630
const Data::Profile& profile,
652631
const std::vector<std::string>& copiedDependenciesBinariesPaths,
653632
bool buildExecutable,
@@ -661,14 +640,20 @@ bool runcpp2::CompileAndLinkScript( const std::string& scriptPath,
661640

662641
std::string scriptObjectFilePath;
663642

664-
if(!CompileScript(scriptPath, scriptInfo, profile, buildExecutable, scriptObjectFilePath))
643+
if(!CompileScript( scriptPath,
644+
scriptInfo,
645+
availableDependencies,
646+
profile,
647+
buildExecutable,
648+
scriptObjectFilePath))
665649
{
666650
ssLOG_ERROR("CompileScript failed");
667651
return false;
668652
}
669653

670654
if(!LinkScript( scriptPath,
671655
scriptInfo,
656+
availableDependencies,
672657
profile,
673658
scriptObjectFilePath,
674659
copiedDependenciesBinariesPaths,

Src/runcpp2/Data/Profile.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
#include "runcpp2/ParseUtil.hpp"
44
#include "ssLogger/ssLog.hpp"
55

6+
void runcpp2::Data::Profile::GetNames(std::vector<std::string>& outNames) const
7+
{
8+
outNames.clear();
9+
outNames.push_back(Name);
10+
for(const auto& alias : NameAliases)
11+
outNames.push_back(alias);
12+
13+
//Special name all that applies to all profile
14+
outNames.push_back("All");
15+
}
16+
617
bool runcpp2::Data::Profile::ParseYAML_Node(ryml::ConstNodeRef& profileNode)
718
{
819
ssLOG_FUNC_DEBUG();

Src/runcpp2/DependenciesHelper.cpp

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -133,33 +133,25 @@ namespace
133133
*runcpp2::GetValueFromPlatformMap(steps);
134134

135135
std::string profileNameToUse;
136-
//Check profile name is available first
137-
if(dependencySteps.CommandSteps.count(profile.Name) > 0)
138-
profileNameToUse = profile.Name;
139-
else
136+
std::vector<std::string> currentProfileNames;
137+
profile.GetNames(currentProfileNames);
138+
139+
for(int i = 0; i < currentProfileNames.size(); ++i)
140140
{
141-
//If not check for name alias
142-
for(const auto& alias : profile.NameAliases)
143-
{
144-
if(dependencySteps.CommandSteps.count(alias) > 0)
145-
{
146-
profileNameToUse = alias;
147-
break;
148-
}
149-
}
150-
151-
//Otherwise check for "All"
152-
if(dependencySteps.CommandSteps.count("All") > 0)
153-
profileNameToUse = "All";
154-
155-
if(profileNameToUse.empty())
141+
if(dependencySteps.CommandSteps.count(currentProfileNames.at(i)) > 0)
156142
{
157-
ssLOG_ERROR("Failed to find steps for profile " << profile.Name <<
158-
" for current platform");
159-
return false;
143+
profileNameToUse = currentProfileNames.at(i);
144+
break;
160145
}
161146
}
162147

148+
if(profileNameToUse.empty())
149+
{
150+
ssLOG_ERROR("Failed to find steps for profile " << profile.Name <<
151+
" for current platform");
152+
return false;
153+
}
154+
163155
//Run the commands
164156
const std::vector<std::string>& commands =
165157
dependencySteps.CommandSteps.at(profileNameToUse);
@@ -551,21 +543,17 @@ bool runcpp2::CopyDependenciesBinaries( const std::string& scriptPath,
551543
availableDependencies.at(i)->LinkProperties;
552544

553545
//See if we can find the link properties with the profile name
554-
auto foundPropertyIt = linkProperties.find(profile.Name);
555-
if(foundPropertyIt == linkProperties.end())
546+
std::vector<std::string> currentProfileNames;
547+
profile.GetNames(currentProfileNames);
548+
549+
auto foundPropertyIt = linkProperties.end();
550+
for(int j = 0; j < currentProfileNames.size(); ++j)
556551
{
557-
//If not, try alias
558-
for(const auto& alias : profile.NameAliases)
559-
{
560-
foundPropertyIt = linkProperties.find(alias);
561-
if(foundPropertyIt != linkProperties.end())
562-
break;
563-
}
564-
565-
//If not, try All
566-
if(foundPropertyIt == linkProperties.end())
567-
foundPropertyIt = linkProperties.find("All");
552+
foundPropertyIt = linkProperties.find(currentProfileNames.at(j));
553+
if(foundPropertyIt != linkProperties.end())
554+
break;
568555
}
556+
569557
if(foundPropertyIt == linkProperties.end())
570558
{
571559
ssLOG_ERROR("Search properties for dependency " << availableDependencies.at(i)->Name <<

Src/runcpp2/ProfileHelper.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,7 @@ namespace
7474
if(!scriptExtension.empty())
7575
scriptExtension.erase(0, 1);
7676

77-
if(profile.FileExtensions.find(scriptExtension) == profile.FileExtensions.end())
78-
{
79-
ssLOG_DEBUG("Failed to match file extension for " << scriptExtension);
80-
return false;
81-
}
82-
77+
//If the language is explicitly stated, use it instead of file extension
8378
if(!scriptInfo.Language.empty())
8479
{
8580
if(profile.Languages.find(scriptInfo.Language) == profile.Languages.end())
@@ -88,6 +83,11 @@ namespace
8883
return false;
8984
}
9085
}
86+
else if(profile.FileExtensions.find(scriptExtension) == profile.FileExtensions.end())
87+
{
88+
ssLOG_DEBUG("Failed to match file extension for " << scriptExtension);
89+
return false;
90+
}
9191

9292
if(!scriptInfo.RequiredProfiles.empty())
9393
{

Src/runcpp2/runcpp2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,8 @@ int runcpp2::RunScript( const std::string& scriptPath,
450450
std::vector<std::string> copiedBinariesPaths;
451451

452452
//Process Dependencies
453+
std::vector<Data::DependencyInfo*> availableDependencies;
453454
{
454-
std::vector<Data::DependencyInfo*> availableDependencies;
455455
for(int i = 0; i < scriptInfo.Dependencies.size(); ++i)
456456
{
457457
if(IsDependencyAvailableForThisPlatform(scriptInfo.Dependencies.at(i)))
@@ -469,7 +469,6 @@ int runcpp2::RunScript( const std::string& scriptPath,
469469
return -1;
470470
}
471471

472-
//If we are resetting cache, we need to clean up the dependencies first
473472
if( currentOptions.count(CmdOptions::RESET_CACHE) > 0 ||
474473
currentOptions.count(CmdOptions::REMOVE_DEPENDENCIES) > 0)
475474
{
@@ -531,6 +530,7 @@ int runcpp2::RunScript( const std::string& scriptPath,
531530
{
532531
if(!CompileAndLinkScript( absoluteScriptPath,
533532
scriptInfo,
533+
availableDependencies,
534534
profiles.at(profileIndex),
535535
copiedBinariesPaths,
536536
(currentOptions.count(CmdOptions::EXECUTABLE) > 0),

0 commit comments

Comments
 (0)