Skip to content

Commit b6c9d02

Browse files
Adding IncludePaths for script info
1 parent f6a9986 commit b6c9d02

File tree

10 files changed

+303
-105
lines changed

10 files changed

+303
-105
lines changed

DefaultYAMLs/DefaultScriptInfo.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,22 @@ OtherFilesToBeCompiled:
5757
DefaultProfile:
5858
- "./AnotherSourceFile.cpp"
5959

60+
# (Optional) Include paths (relative to script file path) for each platform and profile
61+
IncludePaths:
62+
# Target Platform (DefaultPlatform, Windows, Linux, MacOS, or Unix)
63+
DefaultPlatform:
64+
# Target Profile (e.g., "g++", "clang++", "msvc", or "DefaultProfile" for any profile)
65+
DefaultProfile:
66+
- "./include"
67+
- "./src/include"
68+
6069
# (Optional) Define cross-compiler defines for each platform and profile.
6170
# Defines can be specified as just a name or as a name-value pair.
6271
Defines:
6372
# Target Platform (DefaultPlatform, Windows, Linux, MacOS, or Unix)
6473
DefaultPlatform:
6574
# Profile name (e.g., "g++", "clang++", "msvc", or "DefaultProfile" for any profile)
66-
"DefaultProfile":
75+
DefaultProfile:
6776
- "EXAMPLE_DEFINE" # Define without a value
6877
- "VERSION_MAJOR=1" # Define with a value
6978

Examples/test.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ PassScriptPath: true
1717
"msvc":
1818
- "./OtherSources/AnotherSourceFileMSVC.cpp"
1919
20+
IncludePaths:
21+
DefaultPlatform:
22+
DefaultProfile:
23+
- "./OtherSources"
24+
2025
Defines:
2126
DefaultPlatform:
2227
# Turns into `TEST_DEF=\"Test Define Working\"` in shell
@@ -104,11 +109,11 @@ PassScriptPath: true
104109
#include "System2.hpp"
105110

106111
#if defined(__GNUC__)
107-
#include "./OtherSources/AnotherSourceFileGcc.hpp"
112+
#include "AnotherSourceFileGcc.hpp"
108113
#endif
109114

110115
#if defined(_MSC_VER)
111-
#include "./OtherSources/AnotherSourceFileMSVC.hpp"
116+
#include "AnotherSourceFileMSVC.hpp"
112117
#endif
113118

114119
#include <iostream>

Include/runcpp2/CompilingLinking.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace runcpp2
1414
const ghc::filesystem::path& scriptPath,
1515
const std::vector<ghc::filesystem::path>& sourceFiles,
1616
const std::vector<bool>& sourceHasCache,
17+
const std::vector<ghc::filesystem::path>& includePaths,
1718
const Data::ScriptInfo& scriptInfo,
1819
const std::vector<Data::DependencyInfo*>& availableDependencies,
1920
const Data::Profile& profile,
@@ -25,6 +26,7 @@ namespace runcpp2
2526
const std::string& outputName,
2627
const std::vector<ghc::filesystem::path>& sourceFiles,
2728
const std::vector<bool>& sourceHasCache,
29+
const std::vector<ghc::filesystem::path>& includePaths,
2830
const Data::ScriptInfo& scriptInfo,
2931
const std::vector<Data::DependencyInfo*>& availableDependencies,
3032
const Data::Profile& profile,

Include/runcpp2/Data/ScriptInfo.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace runcpp2
2727
std::unordered_map<PlatformName, ProfilesFlagsOverride> OverrideLinkFlags;
2828

2929
std::unordered_map<PlatformName, ProfilesCompilesFiles> OtherFilesToBeCompiled;
30+
std::unordered_map<PlatformName, ProfilesCompilesFiles> IncludePaths;
3031

3132
std::vector<DependencyInfo> Dependencies;
3233

Include/runcpp2/PipelineSteps.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ namespace runcpp2
105105
const Data::Profile& profile,
106106
const std::unordered_map<CmdOptions, std::string>& currentOptions,
107107
ghc::filesystem::path& outTarget);
108+
109+
bool GatherSourceFiles( const ghc::filesystem::path& absoluteScriptPath,
110+
const Data::ScriptInfo& scriptInfo,
111+
const Data::Profile& currentProfile,
112+
std::vector<ghc::filesystem::path>& outSourcePaths);
113+
114+
bool GatherIncludePaths(const ghc::filesystem::path& scriptDirectory,
115+
const Data::ScriptInfo& scriptInfo,
116+
const Data::Profile& currentProfile,
117+
const std::vector<Data::DependencyInfo*>& dependencies,
118+
std::vector<ghc::filesystem::path>& outIncludePaths);
108119
}
109120

110121

Src/Tests/Data/ScriptInfoTest.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ int main(int argc, char** argv)
3737
MSVC:
3838
- src/extra.cpp
3939
- src/debug.cpp
40+
IncludePaths:
41+
Windows:
42+
MSVC:
43+
- include
4044
Defines:
4145
Windows:
4246
MSVC:
@@ -152,12 +156,21 @@ int main(int argc, char** argv)
152156
//Verify OtherFilesToBeCompiled
153157
ssTEST_OUTPUT_SETUP
154158
(
155-
const std::vector<ghc::filesystem::path>& msvcFiles =
159+
const std::vector<ghc::filesystem::path>& msvcCompileFiles =
156160
scriptInfo.OtherFilesToBeCompiled.at("Windows").CompilesFiles.at("MSVC");
157161
);
158-
ssTEST_OUTPUT_ASSERT("MSVC files count", msvcFiles.size() == 2);
159-
ssTEST_OUTPUT_ASSERT("MSVC first file", msvcFiles.at(0) == "src/extra.cpp");
162+
ssTEST_OUTPUT_ASSERT("MSVC files count", msvcCompileFiles.size() == 2);
163+
ssTEST_OUTPUT_ASSERT("MSVC first file", msvcCompileFiles.at(0) == "src/extra.cpp");
160164

165+
//Verify IncludePaths
166+
ssTEST_OUTPUT_SETUP
167+
(
168+
const std::vector<ghc::filesystem::path>& msvcIncludeFiles =
169+
scriptInfo.IncludePaths.at("Windows").CompilesFiles.at("MSVC");
170+
);
171+
ssTEST_OUTPUT_ASSERT("IncludePaths count", msvcIncludeFiles.size() == 1);
172+
ssTEST_OUTPUT_ASSERT("IncludePaths first path", msvcIncludeFiles.at(0) == "include");
173+
161174
//Verify Defines
162175
ssTEST_OUTPUT_SETUP
163176
(

Src/runcpp2/CompilingLinking.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace
6969
bool CompileScript( const ghc::filesystem::path& buildDir,
7070
const ghc::filesystem::path& scriptPath,
7171
const std::vector<ghc::filesystem::path>& sourceFiles,
72+
const std::vector<ghc::filesystem::path>& includePaths,
7273
const runcpp2::Data::ScriptInfo& scriptInfo,
7374
const std::vector<runcpp2::Data::DependencyInfo*>& availableDependencies,
7475
const runcpp2::Data::Profile& profile,
@@ -100,18 +101,11 @@ namespace
100101
substitutionMapTemplate["{CompileFlags}"] = {compileFlags};
101102
}
102103

103-
//Include Directories
104+
//Add script and dependency include paths
105+
for(const ghc::filesystem::path& includePath : includePaths)
104106
{
105-
for(int i = 0; i < availableDependencies.size(); ++i)
106-
{
107-
for(int j = 0; j < availableDependencies.at(i)->AbsoluteIncludePaths.size(); ++j)
108-
{
109-
const std::string& currentIncludePath =
110-
availableDependencies.at(i)->AbsoluteIncludePaths.at(j);
111-
112-
substitutionMapTemplate["{IncludeDirectoryPath}"].push_back(currentIncludePath);
113-
}
114-
}
107+
std::string processedInclude = runcpp2::ProcessPath(includePath.string());
108+
substitutionMapTemplate["{IncludeDirectoryPath}"].push_back(processedInclude);
115109
}
116110

117111
// Add defines
@@ -643,6 +637,7 @@ bool runcpp2::CompileScriptOnly(const ghc::filesystem::path& buildDir,
643637
const ghc::filesystem::path& scriptPath,
644638
const std::vector<ghc::filesystem::path>& sourceFiles,
645639
const std::vector<bool>& sourceHasCache,
640+
const std::vector<ghc::filesystem::path>& includePaths,
646641
const Data::ScriptInfo& scriptInfo,
647642
const std::vector<Data::DependencyInfo*>& availableDependencies,
648643
const Data::Profile& profile,
@@ -667,6 +662,7 @@ bool runcpp2::CompileScriptOnly(const ghc::filesystem::path& buildDir,
667662
if(!CompileScript( buildDir,
668663
scriptPath,
669664
sourceFilesNeededToCompile,
665+
includePaths,
670666
scriptInfo,
671667
availableDependencies,
672668
profile,
@@ -685,6 +681,7 @@ bool runcpp2::CompileAndLinkScript( const ghc::filesystem::path& buildDir,
685681
const std::string& outputName,
686682
const std::vector<ghc::filesystem::path>& sourceFiles,
687683
const std::vector<bool>& sourceHasCache,
684+
const std::vector<ghc::filesystem::path>& includePaths,
688685
const Data::ScriptInfo& scriptInfo,
689686
const std::vector<Data::DependencyInfo*>& availableDependencies,
690687
const Data::Profile& profile,
@@ -711,6 +708,7 @@ bool runcpp2::CompileAndLinkScript( const ghc::filesystem::path& buildDir,
711708
if(!CompileScript( buildDir,
712709
scriptPath,
713710
sourceFilesNeededToCompile,
711+
includePaths,
714712
scriptInfo,
715713
availableDependencies,
716714
profile,

Src/runcpp2/Data/ScriptInfo.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ bool runcpp2::Data::ScriptInfo::ParseYAML_Node(ryml::ConstNodeRef& node)
1717
NodeRequirement("OverrideCompileFlags", ryml::NodeType_e::MAP, false, true),
1818
NodeRequirement("OverrideLinkFlags", ryml::NodeType_e::MAP, false, true),
1919
NodeRequirement("OtherFilesToBeCompiled", ryml::NodeType_e::MAP, false, true),
20+
NodeRequirement("IncludePaths", ryml::NodeType_e::MAP, false, true),
2021
NodeRequirement("Dependencies", ryml::NodeType_e::SEQ, false, true),
2122
NodeRequirement("Defines", ryml::NodeType_e::MAP, false, true),
2223
NodeRequirement("Setup", ryml::NodeType_e::MAP, false, true),
@@ -126,6 +127,23 @@ bool runcpp2::Data::ScriptInfo::ParseYAML_Node(ryml::ConstNodeRef& node)
126127
OtherFilesToBeCompiled[platform] = compilesFiles;
127128
}
128129
}
130+
131+
if(ExistAndHasChild(node, "IncludePaths"))
132+
{
133+
for(int i = 0; i < node["IncludePaths"].num_children(); ++i)
134+
{
135+
ProfilesCompilesFiles includePaths;
136+
ryml::ConstNodeRef currentProfileMapNode = node["IncludePaths"][i];
137+
PlatformName platform = GetKey(currentProfileMapNode);
138+
139+
if(!includePaths.ParseYAML_Node(currentProfileMapNode))
140+
{
141+
ssLOG_ERROR("ScriptInfo: Failed to parse IncludePaths.");
142+
return false;
143+
}
144+
IncludePaths[platform] = includePaths;
145+
}
146+
}
129147

130148
if(ExistAndHasChild(node, "Dependencies"))
131149
{
@@ -290,6 +308,16 @@ std::string runcpp2::Data::ScriptInfo::ToString(std::string indentation) const
290308
out += it->second.ToString(indentation + " ");
291309
}
292310
}
311+
312+
if(!IncludePaths.empty())
313+
{
314+
out += indentation + "IncludePaths:\n";
315+
for(auto it = IncludePaths.begin(); it != IncludePaths.end(); ++it)
316+
{
317+
out += indentation + " " + it->first + ":\n";
318+
out += it->second.ToString(indentation + " ");
319+
}
320+
}
293321

294322
if(!Dependencies.empty())
295323
{
@@ -365,6 +393,7 @@ bool runcpp2::Data::ScriptInfo::Equals(const ScriptInfo& other) const
365393
OverrideCompileFlags.size() != other.OverrideCompileFlags.size() ||
366394
OverrideLinkFlags.size() != other.OverrideLinkFlags.size() ||
367395
OtherFilesToBeCompiled.size() != other.OtherFilesToBeCompiled.size() ||
396+
IncludePaths.size() != other.IncludePaths.size() ||
368397
Dependencies.size() != other.Dependencies.size() ||
369398
Defines.size() != other.Defines.size() ||
370399
Setup.size() != other.Setup.size() ||
@@ -412,6 +441,15 @@ bool runcpp2::Data::ScriptInfo::Equals(const ScriptInfo& other) const
412441
}
413442
}
414443

444+
for(const auto& it : IncludePaths)
445+
{
446+
if( other.IncludePaths.count(it.first) == 0 ||
447+
!other.IncludePaths.at(it.first).Equals(it.second))
448+
{
449+
return false;
450+
}
451+
}
452+
415453
for(size_t i = 0; i < Dependencies.size(); ++i)
416454
{
417455
if(!Dependencies[i].Equals(other.Dependencies[i]))

0 commit comments

Comments
 (0)