Skip to content

Commit 3ece141

Browse files
Merge pull request #45 from Neko-Box-Coder/BetterGitOptions
Adding additioinal options for git dependency source
2 parents 6ca5449 + fe5d73c commit 3ece141

File tree

11 files changed

+274
-13
lines changed

11 files changed

+274
-13
lines changed

DefaultYAMLs/DefaultScriptInfo.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,19 @@ Dependencies:
149149
Git:
150150
# Git repository URL
151151
URL: "https://github.com/MyUser/MyLibrary.git"
152+
153+
# (Optional) Branch name or tag name
154+
# Defaults to default branch on specified git repo if this is not specified
155+
# Branch: ""
156+
157+
# (Optional) Checkout full git history or just the target commit. Defaults to false
158+
# FullHistory: false
159+
160+
# (Optional) Initialization type for all the submodules recursively
161+
# - "None": Don't initialize any submodules
162+
# - "Shallow": Only checkout the target commit of all the submodules (default)
163+
# - "Full": Checkout the full git history of all the submodules
164+
# SubmoduleInitType: "Shallow"
152165

153166
# Dependency or import YAML file exists in local filesystem directory,
154167
# and needs to be copied to build directory

Include/runcpp2/Data/GitSource.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef RUNCPP2_DATA_GIT_SOURCE_HPP
22
#define RUNCPP2_DATA_GIT_SOURCE_HPP
33

4+
#include "runcpp2/Data/SubmoduleInitType.hpp"
5+
46
#include "runcpp2/YamlLib.hpp"
57
#include <string>
68

@@ -12,6 +14,9 @@ namespace runcpp2
1214
{
1315
public:
1416
std::string URL;
17+
std::string Branch;
18+
bool FullHistory = false;
19+
SubmoduleInitType CurrentSubmoduleInitType = SubmoduleInitType::SHALLOW;
1520

1621
bool ParseYAML_Node(ryml::ConstNodeRef& node);
1722
std::string ToString(std::string indentation) const;
@@ -20,4 +25,4 @@ namespace runcpp2
2025
}
2126
}
2227

23-
#endif
28+
#endif
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#ifndef RUNCPP2_DATA_SUBMODULE_INIT_TYPE_HPP
2+
#define RUNCPP2_DATA_SUBMODULE_INIT_TYPE_HPP
3+
4+
#include <string>
5+
6+
namespace runcpp2
7+
{
8+
namespace Data
9+
{
10+
enum class SubmoduleInitType
11+
{
12+
NONE,
13+
SHALLOW,
14+
FULL,
15+
COUNT
16+
};
17+
18+
inline std::string SubmoduleInitTypeToString(SubmoduleInitType submoduleInitType)
19+
{
20+
static_assert( static_cast<int>(SubmoduleInitType::COUNT) == 3,
21+
"Add new type to be processed");
22+
23+
switch(submoduleInitType)
24+
{
25+
case SubmoduleInitType::NONE:
26+
return "None";
27+
28+
case SubmoduleInitType::SHALLOW:
29+
return "Shallow";
30+
31+
case SubmoduleInitType::FULL:
32+
return "Full";
33+
34+
case SubmoduleInitType::COUNT:
35+
return "Count";
36+
37+
default:
38+
return "";
39+
}
40+
}
41+
42+
inline SubmoduleInitType StringToSubmoduleInitType(const std::string& submoduleInitTypeStr)
43+
{
44+
if(submoduleInitTypeStr == "None")
45+
return SubmoduleInitType::NONE;
46+
else if(submoduleInitTypeStr == "Shallow")
47+
return SubmoduleInitType::SHALLOW;
48+
else if(submoduleInitTypeStr == "Full")
49+
return SubmoduleInitType::FULL;
50+
51+
return SubmoduleInitType::COUNT;
52+
}
53+
}
54+
}
55+
56+
57+
#endif

Src/Tests/Data/DependencySourceTest.cpp

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ int main(int argc, char** argv)
1717
const char* yamlStr = R"(
1818
Git:
1919
URL: https://github.com/user/repo.git
20+
Branch: master
21+
FullHistory: true
22+
SubmoduleInitType: Full
2023
)";
2124

2225
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(yamlStr));
@@ -37,7 +40,12 @@ int main(int argc, char** argv)
3740
const runcpp2::Data::GitSource* git =
3841
mpark::get_if<runcpp2::Data::GitSource>(&dependencySource.Source);
3942
ssTEST_OUTPUT_ASSERT("Should be Git source", git != nullptr);
40-
ssTEST_OUTPUT_ASSERT("URL", git->URL == "https://github.com/user/repo.git");
43+
ssTEST_OUTPUT_ASSERT("URL", git->URL, "https://github.com/user/repo.git");
44+
ssTEST_OUTPUT_ASSERT("Branch", git->Branch, "master");
45+
ssTEST_OUTPUT_ASSERT("FullHistory", git->FullHistory, true);
46+
ssTEST_OUTPUT_ASSERT( "SubmoduleInitType",
47+
git->CurrentSubmoduleInitType ==
48+
runcpp2::Data::SubmoduleInitType::FULL);
4149

4250
//Test ToString() and Equals()
4351
ssTEST_OUTPUT_EXECUTION
@@ -184,7 +192,57 @@ int main(int argc, char** argv)
184192
bool parseResult = dependencySource.ParseYAML_Node(nodeRef);
185193
);
186194

187-
ssTEST_OUTPUT_ASSERT("ParseYAML_Node should fail", !parseResult);
195+
ssTEST_OUTPUT_ASSERT("ParseYAML_Node should fail", parseResult, false);
196+
};
197+
198+
ssTEST("DependencySource Should Handle Invalid FullHistory Option")
199+
{
200+
ssTEST_OUTPUT_SETUP
201+
(
202+
const char* yamlStr = R"(
203+
Git:
204+
URL: https://github.com/user/repo.git
205+
FullHistory: What
206+
)";
207+
208+
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(yamlStr));
209+
ryml::ConstNodeRef root = tree.rootref();
210+
211+
runcpp2::Data::DependencySource dependencySource;
212+
);
213+
214+
ssTEST_OUTPUT_EXECUTION
215+
(
216+
ryml::ConstNodeRef nodeRef = root;
217+
bool parseResult = dependencySource.ParseYAML_Node(nodeRef);
218+
);
219+
220+
ssTEST_OUTPUT_ASSERT("ParseYAML_Node should fail", parseResult, false);
221+
};
222+
223+
ssTEST("DependencySource Should Handle Invalid SubmoduleInitType Option")
224+
{
225+
ssTEST_OUTPUT_SETUP
226+
(
227+
const char* yamlStr = R"(
228+
Git:
229+
URL: https://github.com/user/repo.git
230+
SubmoduleInitType: What
231+
)";
232+
233+
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(yamlStr));
234+
ryml::ConstNodeRef root = tree.rootref();
235+
236+
runcpp2::Data::DependencySource dependencySource;
237+
);
238+
239+
ssTEST_OUTPUT_EXECUTION
240+
(
241+
ryml::ConstNodeRef nodeRef = root;
242+
bool parseResult = dependencySource.ParseYAML_Node(nodeRef);
243+
);
244+
245+
ssTEST_OUTPUT_ASSERT("ParseYAML_Node should fail", parseResult, false);
188246
};
189247

190248
ssTEST_END_TEST_GROUP();

Src/runcpp2/CompilingLinking.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ namespace
384384
resultCode != 0)
385385
{
386386
ssLOG_ERROR("Compile command failed with result " << resultCode);
387+
ssLOG_ERROR("Was trying to run: " << compileCommand);
387388
ssLOG_ERROR("Compile output: \n" << commandOutput);
388389
return false;
389390
}
@@ -756,6 +757,7 @@ namespace
756757
resultCode) ||
757758
resultCode != 0)
758759
{
760+
ssLOG_ERROR("Was trying to run: " << linkCommand);
759761
ssLOG_ERROR("Link command failed with result " << resultCode);
760762
ssLOG_ERROR("Link output: \n" << linkOutput);
761763
return false;

Src/runcpp2/Data/GitSource.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ bool runcpp2::Data::GitSource::ParseYAML_Node(ryml::ConstNodeRef& node)
99

1010
std::vector<NodeRequirement> requirements =
1111
{
12-
NodeRequirement("URL", ryml::NodeType_e::KEYVAL, true, false)
12+
NodeRequirement("URL", ryml::NodeType_e::KEYVAL, true, false),
13+
NodeRequirement("Branch", ryml::NodeType_e::KEYVAL, false, false),
14+
NodeRequirement("FullHistory", ryml::NodeType_e::KEYVAL, false, false),
15+
NodeRequirement("SubmoduleInitType", ryml::NodeType_e::KEYVAL, false, false)
1316
};
1417

1518
if(!CheckNodeRequirements(node, requirements))
@@ -19,6 +22,24 @@ bool runcpp2::Data::GitSource::ParseYAML_Node(ryml::ConstNodeRef& node)
1922
}
2023

2124
node["URL"] >> URL;
25+
if(ExistAndHasChild(node, "Branch"))
26+
node["Branch"] >> Branch;
27+
28+
if(ExistAndHasChild(node, "FullHistory"))
29+
node["FullHistory"] >> FullHistory;
30+
31+
if(ExistAndHasChild(node, "SubmoduleInitType"))
32+
{
33+
std::string submoduleTypeString;
34+
node["SubmoduleInitType"] >> submoduleTypeString;
35+
CurrentSubmoduleInitType = StringToSubmoduleInitType(submoduleTypeString);
36+
if(CurrentSubmoduleInitType == SubmoduleInitType::COUNT)
37+
{
38+
ssLOG_ERROR("GitSource: Invalid submodule init type " << submoduleTypeString);
39+
return false;
40+
}
41+
}
42+
2243
return true;
2344

2445
INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
@@ -29,10 +50,20 @@ std::string runcpp2::Data::GitSource::ToString(std::string indentation) const
2950
std::string out;
3051
out += indentation + "Git:\n";
3152
out += indentation + " URL: " + GetEscapedYAMLString(URL) + "\n";
53+
if(!Branch.empty())
54+
out += indentation + " Branch: " + GetEscapedYAMLString(Branch) + "\n";
55+
out += indentation + " FullHistory: " + (FullHistory ? "true" : "false") + "\n";
56+
out += indentation +
57+
" SubmoduleInitType: " +
58+
SubmoduleInitTypeToString(CurrentSubmoduleInitType) +
59+
"\n";
3260
return out;
3361
}
3462

3563
bool runcpp2::Data::GitSource::Equals(const GitSource& other) const
3664
{
37-
return URL == other.URL;
38-
}
65+
return URL == other.URL &&
66+
Branch == other.Branch &&
67+
FullHistory == other.FullHistory &&
68+
CurrentSubmoduleInitType == other.CurrentSubmoduleInitType;
69+
}

Src/runcpp2/DependenciesHelper.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,37 @@ namespace
115115
const runcpp2::Data::GitSource* git =
116116
mpark::get_if<runcpp2::Data::GitSource>(&(dependency.Source.Source));
117117

118-
std::string gitCloneCommand = "git clone " + git->URL;
118+
std::string submoduleString;
119+
static_assert( static_cast<int>(runcpp2::Data::SubmoduleInitType::COUNT) == 3,
120+
"Add new type to be processed");
121+
switch(git->CurrentSubmoduleInitType)
122+
{
123+
case runcpp2::Data::SubmoduleInitType::NONE:
124+
break;
125+
case runcpp2::Data::SubmoduleInitType::SHALLOW:
126+
submoduleString = "--recursive --shallow-submodules ";
127+
break;
128+
case runcpp2::Data::SubmoduleInitType::FULL:
129+
submoduleString = "--recursive ";
130+
break;
131+
default:
132+
{
133+
ssLOG_ERROR("Invalid git submodule init type: " <<
134+
static_cast<int>(git->CurrentSubmoduleInitType));
135+
return false;
136+
}
137+
}
138+
139+
std::string gitCloneCommand =
140+
std::string("git clone ") +
141+
submoduleString +
142+
(git->FullHistory ? "" : "--depth 1 ") +
143+
(
144+
git->Branch.empty() ?
145+
std::string("") :
146+
std::string("--branch ") + git->Branch + " "
147+
) +
148+
git->URL;
119149

120150
ssLOG_INFO("Running git clone command: " << gitCloneCommand << " in " <<
121151
buildDir.string());
@@ -129,6 +159,7 @@ namespace
129159
returnCode))
130160
{
131161
ssLOG_ERROR("Failed to run git clone with result: " << returnCode);
162+
ssLOG_ERROR("Was trying to run: " << gitCloneCommand);
132163
//ssLOG_ERROR("Output: \n" << output);
133164
return false;
134165
}
@@ -266,6 +297,7 @@ namespace
266297
returnCode))
267298
{
268299
ssLOG_ERROR("Failed to run command with result: " << returnCode);
300+
ssLOG_ERROR("Was trying to run: " << commands->at(k));
269301
ssLOG_ERROR("Output: \n" << output);
270302
return false;
271303
}

Src/runcpp2/PipelineSteps.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ runcpp2::RunProfileCommands(const Data::ProfilesCommands* commands,
245245
{
246246
ssLOG_ERROR(commandType << " command failed: " << cmd <<
247247
" with return code " << returnCode);
248+
ssLOG_ERROR("Was trying to run: " << cmd);
248249
ssLOG_ERROR("Output: \n" << output);
249250
return PipelineResult::UNEXPECTED_FAILURE;
250251
}

mkdocs/docs/TODO.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# Roadmap
22

3-
## Planned
3+
## Done
4+
5+
!!! info "`latest` version"
6+
- More git options
7+
- Add branch/tag option for git
8+
- Add initialize submodule option for git
9+
- Async/Multi-thread compile and dependencies processing
10+
411

12+
## Planned
513
- Ability to skip DefaultPlatform and DefaultProfile
6-
- More git options
7-
- Add branch/tag option for git
8-
- Add initialize submodule option for git
914
- Allow runcpp2 to be library for scriptable pipeline
1015
- Smoother CMake support by reading cmake target properties (https://stackoverflow.com/a/56738858/23479578)
1116
- Add the ability for user to specify custom substitution options which applies to all fields
@@ -37,6 +42,4 @@
3742
- Allow Languages to override FileExtensions in compiler profile (?)
3843
- Custom Platform
3944
- Ability to specify custom run commands
40-
-
41-
4245

0 commit comments

Comments
 (0)