Skip to content

Commit f4c93aa

Browse files
Merge pull request #36 from Neko-Box-Coder/DepYAMLImport
Ability to import yaml for dependencies
2 parents c5268fd + e034f41 commit f4c93aa

File tree

14 files changed

+446
-118
lines changed

14 files changed

+446
-118
lines changed

DefaultYAMLs/DefaultScriptInfo.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,18 @@ Dependencies:
123123

124124
# The source of getting the dependency (Git, Local)
125125
Source:
126-
# Git: Dependency exists in a git server, and needs to be cloned
126+
# (Optional) Import dependency configuration from a YAML file
127+
# For Git source: Path is relative to the git repository root
128+
# For Local source: Path is relative to the script directory.
129+
# If neither source exists, local source with root script directory is assumed.
130+
# ImportPath: "config/dependency.yaml"
131+
132+
# Git: Dependency or import YAML file exists in a git server, and needs to be cloned.
127133
Git:
128134
# Git repository URL
129135
URL: "https://github.com/MyUser/MyLibrary.git"
130136

131-
# Local: Dependency exists in local filesystem
137+
# Local: Dependency or import YAML file exists in local filesystem
132138
# Local:
133139
# # Path to the library directory
134140
# Path: "./libs/LocalLibrary"

Examples/TestImport.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Name: "System2.cpp"
2+
Platforms: [DefaultPlatform]
3+
Source:
4+
Git:
5+
URL: "https://github.com/Neko-Box-Coder/System2.cpp.git"
6+
LibraryType: Header
7+
IncludePaths: [".", "./External/System2"]
8+
Setup:
9+
DefaultPlatform:
10+
DefaultProfile:
11+
- "git submodule update --init --recursive"

Examples/test.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,20 @@ PassScriptPath: true
8989
- "./Include/ssLogger/ssLog.hpp"
9090
9191
- Name: System2.cpp
92-
Platforms: [DefaultPlatform]
9392
Source:
94-
Git:
95-
URL: "https://github.com/Neko-Box-Coder/System2.cpp.git"
96-
LibraryType: Header
97-
IncludePaths: [".", "./External/System2"]
98-
Setup:
99-
DefaultPlatform:
100-
DefaultProfile:
101-
- "git submodule update --init --recursive"
93+
ImportPath: "./TestImport.yaml"
94+
95+
# - Name: System2.cpp
96+
# Platforms: [DefaultPlatform]
97+
# Source:
98+
# Git:
99+
# URL: "https://github.com/Neko-Box-Coder/System2.cpp.git"
100+
# LibraryType: Header
101+
# IncludePaths: [".", "./External/System2"]
102+
# Setup:
103+
# DefaultPlatform:
104+
# DefaultProfile:
105+
# - "git submodule update --init --recursive"
102106
*/
103107

104108

Include/runcpp2/Data/DependencySource.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
#include "runcpp2/Data/GitSource.hpp"
55
#include "runcpp2/Data/LocalSource.hpp"
66
#include "runcpp2/YamlLib.hpp"
7+
#include "ghc/filesystem.hpp"
78
#include "mpark/variant.hpp"
89

10+
#include <memory>
11+
#include <vector>
12+
913
namespace runcpp2
1014
{
1115
namespace Data
@@ -14,6 +18,8 @@ namespace runcpp2
1418
{
1519
public:
1620
mpark::variant<GitSource, LocalSource> Source;
21+
ghc::filesystem::path ImportPath;
22+
std::vector<std::shared_ptr<DependencySource>> ImportedSources;
1723

1824
bool ParseYAML_Node(ryml::ConstNodeRef& node);
1925
std::string ToString(std::string indentation) const;

Include/runcpp2/DependenciesHelper.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ namespace runcpp2
4040
const std::vector<std::string>& dependenciesCopiesPaths,
4141
const Data::Profile& profile,
4242
std::vector<std::string>& outBinariesPaths);
43+
44+
bool HandleImport( Data::DependencyInfo& dependency,
45+
const ghc::filesystem::path& basePath);
46+
47+
bool ResolveImports(Data::ScriptInfo& scriptInfo,
48+
const ghc::filesystem::path& scriptPath,
49+
const ghc::filesystem::path& buildDir);
4350
}
4451

4552
#endif

Include/runcpp2/PipelineSteps.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ namespace runcpp2
5454
BuildsManager& outBuildsManager,
5555
ghc::filesystem::path& outBuildDir,
5656
IncludeManager& outIncludeManager);
57+
58+
PipelineResult ResolveScriptImports(Data::ScriptInfo& scriptInfo,
59+
const ghc::filesystem::path& scriptPath,
60+
const ghc::filesystem::path& buildDir);
5761

5862
PipelineResult CheckScriptInfoChanges( const ghc::filesystem::path& buildDir,
5963
const Data::ScriptInfo& scriptInfo,

Src/Tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ target_compile_definitions(IncludeManagerTest PRIVATE INTERNAL_RUNCPP2_UNIT_TEST
1818
function(create_data_test TEST_NAME)
1919
add_executable("${TEST_NAME}" "${CMAKE_CURRENT_LIST_DIR}/Data/${TEST_NAME}.cpp")
2020
target_compile_options("${TEST_NAME}" PRIVATE "${STANDARD_COMPILE_FLAGS}")
21-
target_compile_definitions("${TEST_NAME}" PRIVATE INTERNAL_RUNCPP2_UNIT_TESTS=1)
21+
target_compile_definitions("${TEST_NAME}" PRIVATE INTERNAL_RUNCPP2_UNIT_TESTS=1 TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES=1)
2222
target_link_libraries("${TEST_NAME}" PUBLIC runcpp2 ssTest)
2323

2424
endfunction()

Src/runcpp2/Data/DependencyInfo.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,33 @@
66
bool runcpp2::Data::DependencyInfo::ParseYAML_Node(ryml::ConstNodeRef& node)
77
{
88
INTERNAL_RUNCPP2_SAFE_START();
9-
9+
10+
//If import is needed, we only need to parse the Source section
11+
do
12+
{
13+
if(!ExistAndHasChild(node, "Source"))
14+
{
15+
ssLOG_ERROR("DependencyInfo: Missing Source");
16+
return false;
17+
}
18+
19+
ryml::ConstNodeRef sourceNode = node["Source"];
20+
21+
if(!ExistAndHasChild(sourceNode, "ImportPath"))
22+
break;
23+
24+
if(!Source.ParseYAML_Node(sourceNode))
25+
{
26+
ssLOG_ERROR("DependencyInfo: Failed to parse Source");
27+
return false;
28+
}
29+
30+
ssLOG_DEBUG("DependencyInfo: Importing from " << Source.ImportPath.string());
31+
ssLOG_DEBUG("Skipping the rest of the DependencyInfo");
32+
return true;
33+
}
34+
while(false);
35+
1036
std::vector<NodeRequirement> requirements =
1137
{
1238
NodeRequirement("Name", ryml::NodeType_e::KEYVAL, true, false),

Src/runcpp2/Data/DependencySource.cpp

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ bool runcpp2::Data::DependencySource::ParseYAML_Node(ryml::ConstNodeRef& node)
77
{
88
INTERNAL_RUNCPP2_SAFE_START();
99

10+
if(ExistAndHasChild(node, "ImportPath"))
11+
{
12+
std::string importPathStr;
13+
node["ImportPath"] >> importPathStr;
14+
ImportPath = importPathStr;
15+
16+
if(ImportPath.is_absolute())
17+
{
18+
ssLOG_ERROR("DependencySource: ImportPath must be relative: " << ImportPath.string());
19+
return false;
20+
}
21+
}
22+
1023
if(ExistAndHasChild(node, "Git"))
1124
{
1225
if(ExistAndHasChild(node, "Local"))
@@ -37,6 +50,15 @@ bool runcpp2::Data::DependencySource::ParseYAML_Node(ryml::ConstNodeRef& node)
3750
Source = localSource;
3851
return true;
3952
}
53+
//If no source is found, we need to check if it's an imported source.
54+
//If so, we assume it's a local source with path "./"
55+
else if(!ImportPath.empty())
56+
{
57+
LocalSource localSource;
58+
localSource.Path = "./";
59+
Source = localSource;
60+
return true;
61+
}
4062

4163
ssLOG_ERROR("DependencySource: Neither Git nor Local source found");
4264
return false;
@@ -46,23 +68,33 @@ bool runcpp2::Data::DependencySource::ParseYAML_Node(ryml::ConstNodeRef& node)
4668

4769
std::string runcpp2::Data::DependencySource::ToString(std::string indentation) const
4870
{
71+
std::string out;
72+
if(!ImportPath.empty())
73+
out += indentation + "ImportPath: " + GetEscapedYAMLString(ImportPath.string()) + "\n";
74+
4975
if(mpark::get_if<GitSource>(&Source))
5076
{
5177
const GitSource* git = mpark::get_if<GitSource>(&Source);
52-
return git->ToString(indentation);
78+
out += git->ToString(indentation);
5379
}
5480
else if(mpark::get_if<LocalSource>(&Source))
5581
{
5682
const LocalSource* local = mpark::get_if<LocalSource>(&Source);
57-
return local->ToString(indentation);
83+
out += local->ToString(indentation);
5884
}
59-
60-
ssLOG_ERROR("Invalid DependencySource type");
61-
return "";
85+
else
86+
{
87+
ssLOG_ERROR("Invalid DependencySource type");
88+
return "";
89+
}
90+
return out;
6291
}
6392

6493
bool runcpp2::Data::DependencySource::Equals(const DependencySource& other) const
6594
{
95+
if(ImportPath != other.ImportPath)
96+
return false;
97+
6698
if(mpark::get_if<GitSource>(&Source))
6799
{
68100
if(mpark::get_if<GitSource>(&other.Source))

0 commit comments

Comments
 (0)