Skip to content

Commit fe5d73c

Browse files
Adding SubmoduleInitType option for git dependency source
1 parent 6af999e commit fe5d73c

File tree

11 files changed

+179
-22
lines changed

11 files changed

+179
-22
lines changed

DefaultYAMLs/DefaultScriptInfo.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,18 @@ Dependencies:
150150
# Git repository URL
151151
URL: "https://github.com/MyUser/MyLibrary.git"
152152

153-
# (Optional) Branch name or tag name. Full ref path is accepted as well.
153+
# (Optional) Branch name or tag name
154154
# Defaults to default branch on specified git repo if this is not specified
155-
# Branch: "MyBranch"
155+
# Branch: ""
156156

157157
# (Optional) Checkout full git history or just the target commit. Defaults to false
158158
# 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"
159165

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

Include/runcpp2/Data/GitSource.hpp

Lines changed: 3 additions & 0 deletions
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

@@ -14,6 +16,7 @@ namespace runcpp2
1416
std::string URL;
1517
std::string Branch;
1618
bool FullHistory = false;
19+
SubmoduleInitType CurrentSubmoduleInitType = SubmoduleInitType::SHALLOW;
1720

1821
bool ParseYAML_Node(ryml::ConstNodeRef& node);
1922
std::string ToString(std::string indentation) const;
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int main(int argc, char** argv)
1919
URL: https://github.com/user/repo.git
2020
Branch: master
2121
FullHistory: true
22+
SubmoduleInitType: Full
2223
)";
2324

2425
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(yamlStr));
@@ -42,6 +43,9 @@ int main(int argc, char** argv)
4243
ssTEST_OUTPUT_ASSERT("URL", git->URL, "https://github.com/user/repo.git");
4344
ssTEST_OUTPUT_ASSERT("Branch", git->Branch, "master");
4445
ssTEST_OUTPUT_ASSERT("FullHistory", git->FullHistory, true);
46+
ssTEST_OUTPUT_ASSERT( "SubmoduleInitType",
47+
git->CurrentSubmoduleInitType ==
48+
runcpp2::Data::SubmoduleInitType::FULL);
4549

4650
//Test ToString() and Equals()
4751
ssTEST_OUTPUT_EXECUTION
@@ -216,6 +220,31 @@ int main(int argc, char** argv)
216220
ssTEST_OUTPUT_ASSERT("ParseYAML_Node should fail", parseResult, false);
217221
};
218222

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);
246+
};
247+
219248
ssTEST_END_TEST_GROUP();
220249
return 0;
221250
}

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: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ bool runcpp2::Data::GitSource::ParseYAML_Node(ryml::ConstNodeRef& node)
1111
{
1212
NodeRequirement("URL", ryml::NodeType_e::KEYVAL, true, false),
1313
NodeRequirement("Branch", ryml::NodeType_e::KEYVAL, false, false),
14-
NodeRequirement("FullHistory", ryml::NodeType_e::KEYVAL, false, false)
14+
NodeRequirement("FullHistory", ryml::NodeType_e::KEYVAL, false, false),
15+
NodeRequirement("SubmoduleInitType", ryml::NodeType_e::KEYVAL, false, false)
1516
};
1617

1718
if(!CheckNodeRequirements(node, requirements))
@@ -27,6 +28,18 @@ bool runcpp2::Data::GitSource::ParseYAML_Node(ryml::ConstNodeRef& node)
2728
if(ExistAndHasChild(node, "FullHistory"))
2829
node["FullHistory"] >> FullHistory;
2930

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+
3043
return true;
3144

3245
INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
@@ -40,10 +53,17 @@ std::string runcpp2::Data::GitSource::ToString(std::string indentation) const
4053
if(!Branch.empty())
4154
out += indentation + " Branch: " + GetEscapedYAMLString(Branch) + "\n";
4255
out += indentation + " FullHistory: " + (FullHistory ? "true" : "false") + "\n";
56+
out += indentation +
57+
" SubmoduleInitType: " +
58+
SubmoduleInitTypeToString(CurrentSubmoduleInitType) +
59+
"\n";
4360
return out;
4461
}
4562

4663
bool runcpp2::Data::GitSource::Equals(const GitSource& other) const
4764
{
48-
return URL == other.URL && Branch == other.Branch && FullHistory == other.FullHistory;
65+
return URL == other.URL &&
66+
Branch == other.Branch &&
67+
FullHistory == other.FullHistory &&
68+
CurrentSubmoduleInitType == other.CurrentSubmoduleInitType;
4969
}

Src/runcpp2/DependenciesHelper.cpp

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

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+
118139
std::string gitCloneCommand =
119140
std::string("git clone ") +
141+
submoduleString +
120142
(git->FullHistory ? "" : "--depth 1 ") +
121143
(
122144
git->Branch.empty() ?
123145
std::string("") :
124-
std::string("--branch ") + git->Branch
146+
std::string("--branch ") + git->Branch + " "
125147
) +
126148
git->URL;
127149

@@ -137,6 +159,7 @@ namespace
137159
returnCode))
138160
{
139161
ssLOG_ERROR("Failed to run git clone with result: " << returnCode);
162+
ssLOG_ERROR("Was trying to run: " << gitCloneCommand);
140163
//ssLOG_ERROR("Output: \n" << output);
141164
return false;
142165
}
@@ -274,6 +297,7 @@ namespace
274297
returnCode))
275298
{
276299
ssLOG_ERROR("Failed to run command with result: " << returnCode);
300+
ssLOG_ERROR("Was trying to run: " << commands->at(k));
277301
ssLOG_ERROR("Output: \n" << output);
278302
return false;
279303
}

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
## Done
44

55
!!! info "`latest` version"
6-
- Async/Multi-thread compile and dependencies processing
76
- More git options
87
- Add branch/tag option for git
98
- Add initialize submodule option for git
9+
- Async/Multi-thread compile and dependencies processing
1010

1111

1212
## Planned

mkdocs/docs/build_settings.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -312,18 +312,25 @@
312312
- Optional: `false`
313313
- Default: None
314314
- Description: The url of the git repository.
315-
- `Branch`
316-
- Type: `string`
317-
- Optional: `true`
318-
- Default: None
319-
- Description: Branch name or tag name. Full ref path is accepted as well.
320-
- !!! info "This requires `latest` version"
321-
- `FullHistory`
322-
- Type: `bool`
323-
- Optional: `true`
324-
- Default: `false`
325-
- Description: Checkout full git history or just the target commit.
326-
- !!! info "This requires `latest` version"
315+
!!! info "This requires `latest` version"
316+
- `Branch`
317+
- Type: `string`
318+
- Optional: `true`
319+
- Default: None
320+
- Description: Branch name or tag name.
321+
- `FullHistory`
322+
- Type: `bool`
323+
- Optional: `true`
324+
- Default: `false`
325+
- Description: Checkout full git history or just the target commit.
326+
- `SubmoduleInitType`
327+
- Type: `enum string`, can be one of the following:
328+
- `None`
329+
- `Shallow`
330+
- `Full`
331+
- Optional: `true`
332+
- Default: `Shallow`
333+
- Description: Initialization type for all the submodules recursively
327334
- `Local`
328335
- Type: `map` with child fields
329336
- Optional: `true` if `ImportPath` is specified or `Git` is specified
@@ -560,12 +567,18 @@ Dependencies:
560567
# Git repository URL
561568
URL: "https://github.com/MyUser/MyLibrary.git"
562569

563-
# (Optional) Branch name or tag name. Full ref path is accepted as well.
570+
# (Optional) Branch name or tag name
564571
# Defaults to default branch on specified git repo if this is not specified
565-
# Branch: "MyBranch"
572+
# Branch: ""
566573

567574
# (Optional) Checkout full git history or just the target commit. Defaults to false
568575
# FullHistory: false
576+
577+
# (Optional) Initialization type for all the submodules recursively
578+
# - "None": Don't initialize any submodules
579+
# - "Shallow": Only checkout the target commit of all the submodules (default)
580+
# - "Full": Checkout the full git history of all the submodules
581+
# SubmoduleInitType: "Shallow"
569582

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

0 commit comments

Comments
 (0)