Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions DefaultYAMLs/DefaultScriptInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ Dependencies:
Git:
# Git repository URL
URL: "https://github.com/MyUser/MyLibrary.git"

# (Optional) Branch name or tag name
# Defaults to default branch on specified git repo if this is not specified
# Branch: ""

# (Optional) Checkout full git history or just the target commit. Defaults to false
# FullHistory: false

# (Optional) Initialization type for all the submodules recursively
# - "None": Don't initialize any submodules
# - "Shallow": Only checkout the target commit of all the submodules (default)
# - "Full": Checkout the full git history of all the submodules
# SubmoduleInitType: "Shallow"

# Dependency or import YAML file exists in local filesystem directory,
# and needs to be copied to build directory
Expand Down
7 changes: 6 additions & 1 deletion Include/runcpp2/Data/GitSource.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef RUNCPP2_DATA_GIT_SOURCE_HPP
#define RUNCPP2_DATA_GIT_SOURCE_HPP

#include "runcpp2/Data/SubmoduleInitType.hpp"

#include "runcpp2/YamlLib.hpp"
#include <string>

Expand All @@ -12,6 +14,9 @@ namespace runcpp2
{
public:
std::string URL;
std::string Branch;
bool FullHistory = false;
SubmoduleInitType CurrentSubmoduleInitType = SubmoduleInitType::SHALLOW;

bool ParseYAML_Node(ryml::ConstNodeRef& node);
std::string ToString(std::string indentation) const;
Expand All @@ -20,4 +25,4 @@ namespace runcpp2
}
}

#endif
#endif
57 changes: 57 additions & 0 deletions Include/runcpp2/Data/SubmoduleInitType.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef RUNCPP2_DATA_SUBMODULE_INIT_TYPE_HPP
#define RUNCPP2_DATA_SUBMODULE_INIT_TYPE_HPP

#include <string>

namespace runcpp2
{
namespace Data
{
enum class SubmoduleInitType
{
NONE,
SHALLOW,
FULL,
COUNT
};

inline std::string SubmoduleInitTypeToString(SubmoduleInitType submoduleInitType)
{
static_assert( static_cast<int>(SubmoduleInitType::COUNT) == 3,
"Add new type to be processed");

switch(submoduleInitType)
{
case SubmoduleInitType::NONE:
return "None";

case SubmoduleInitType::SHALLOW:
return "Shallow";

case SubmoduleInitType::FULL:
return "Full";

case SubmoduleInitType::COUNT:
return "Count";

default:
return "";
}
}

inline SubmoduleInitType StringToSubmoduleInitType(const std::string& submoduleInitTypeStr)
{
if(submoduleInitTypeStr == "None")
return SubmoduleInitType::NONE;
else if(submoduleInitTypeStr == "Shallow")
return SubmoduleInitType::SHALLOW;
else if(submoduleInitTypeStr == "Full")
return SubmoduleInitType::FULL;

return SubmoduleInitType::COUNT;
}
}
}


#endif
62 changes: 60 additions & 2 deletions Src/Tests/Data/DependencySourceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ int main(int argc, char** argv)
const char* yamlStr = R"(
Git:
URL: https://github.com/user/repo.git
Branch: master
FullHistory: true
SubmoduleInitType: Full
)";

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

//Test ToString() and Equals()
ssTEST_OUTPUT_EXECUTION
Expand Down Expand Up @@ -184,7 +192,57 @@ int main(int argc, char** argv)
bool parseResult = dependencySource.ParseYAML_Node(nodeRef);
);

ssTEST_OUTPUT_ASSERT("ParseYAML_Node should fail", !parseResult);
ssTEST_OUTPUT_ASSERT("ParseYAML_Node should fail", parseResult, false);
};

ssTEST("DependencySource Should Handle Invalid FullHistory Option")
{
ssTEST_OUTPUT_SETUP
(
const char* yamlStr = R"(
Git:
URL: https://github.com/user/repo.git
FullHistory: What
)";

ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(yamlStr));
ryml::ConstNodeRef root = tree.rootref();

runcpp2::Data::DependencySource dependencySource;
);

ssTEST_OUTPUT_EXECUTION
(
ryml::ConstNodeRef nodeRef = root;
bool parseResult = dependencySource.ParseYAML_Node(nodeRef);
);

ssTEST_OUTPUT_ASSERT("ParseYAML_Node should fail", parseResult, false);
};

ssTEST("DependencySource Should Handle Invalid SubmoduleInitType Option")
{
ssTEST_OUTPUT_SETUP
(
const char* yamlStr = R"(
Git:
URL: https://github.com/user/repo.git
SubmoduleInitType: What
)";

ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(yamlStr));
ryml::ConstNodeRef root = tree.rootref();

runcpp2::Data::DependencySource dependencySource;
);

ssTEST_OUTPUT_EXECUTION
(
ryml::ConstNodeRef nodeRef = root;
bool parseResult = dependencySource.ParseYAML_Node(nodeRef);
);

ssTEST_OUTPUT_ASSERT("ParseYAML_Node should fail", parseResult, false);
};

ssTEST_END_TEST_GROUP();
Expand Down
2 changes: 2 additions & 0 deletions Src/runcpp2/CompilingLinking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ namespace
resultCode != 0)
{
ssLOG_ERROR("Compile command failed with result " << resultCode);
ssLOG_ERROR("Was trying to run: " << compileCommand);
ssLOG_ERROR("Compile output: \n" << commandOutput);
return false;
}
Expand Down Expand Up @@ -756,6 +757,7 @@ namespace
resultCode) ||
resultCode != 0)
{
ssLOG_ERROR("Was trying to run: " << linkCommand);
ssLOG_ERROR("Link command failed with result " << resultCode);
ssLOG_ERROR("Link output: \n" << linkOutput);
return false;
Expand Down
37 changes: 34 additions & 3 deletions Src/runcpp2/Data/GitSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ bool runcpp2::Data::GitSource::ParseYAML_Node(ryml::ConstNodeRef& node)

std::vector<NodeRequirement> requirements =
{
NodeRequirement("URL", ryml::NodeType_e::KEYVAL, true, false)
NodeRequirement("URL", ryml::NodeType_e::KEYVAL, true, false),
NodeRequirement("Branch", ryml::NodeType_e::KEYVAL, false, false),
NodeRequirement("FullHistory", ryml::NodeType_e::KEYVAL, false, false),
NodeRequirement("SubmoduleInitType", ryml::NodeType_e::KEYVAL, false, false)
};

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

node["URL"] >> URL;
if(ExistAndHasChild(node, "Branch"))
node["Branch"] >> Branch;

if(ExistAndHasChild(node, "FullHistory"))
node["FullHistory"] >> FullHistory;

if(ExistAndHasChild(node, "SubmoduleInitType"))
{
std::string submoduleTypeString;
node["SubmoduleInitType"] >> submoduleTypeString;
CurrentSubmoduleInitType = StringToSubmoduleInitType(submoduleTypeString);
if(CurrentSubmoduleInitType == SubmoduleInitType::COUNT)
{
ssLOG_ERROR("GitSource: Invalid submodule init type " << submoduleTypeString);
return false;
}
}

return true;

INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
Expand All @@ -29,10 +50,20 @@ std::string runcpp2::Data::GitSource::ToString(std::string indentation) const
std::string out;
out += indentation + "Git:\n";
out += indentation + " URL: " + GetEscapedYAMLString(URL) + "\n";
if(!Branch.empty())
out += indentation + " Branch: " + GetEscapedYAMLString(Branch) + "\n";
out += indentation + " FullHistory: " + (FullHistory ? "true" : "false") + "\n";
out += indentation +
" SubmoduleInitType: " +
SubmoduleInitTypeToString(CurrentSubmoduleInitType) +
"\n";
return out;
}

bool runcpp2::Data::GitSource::Equals(const GitSource& other) const
{
return URL == other.URL;
}
return URL == other.URL &&
Branch == other.Branch &&
FullHistory == other.FullHistory &&
CurrentSubmoduleInitType == other.CurrentSubmoduleInitType;
}
34 changes: 33 additions & 1 deletion Src/runcpp2/DependenciesHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,37 @@ namespace
const runcpp2::Data::GitSource* git =
mpark::get_if<runcpp2::Data::GitSource>(&(dependency.Source.Source));

std::string gitCloneCommand = "git clone " + git->URL;
std::string submoduleString;
static_assert( static_cast<int>(runcpp2::Data::SubmoduleInitType::COUNT) == 3,
"Add new type to be processed");
switch(git->CurrentSubmoduleInitType)
{
case runcpp2::Data::SubmoduleInitType::NONE:
break;
case runcpp2::Data::SubmoduleInitType::SHALLOW:
submoduleString = "--recursive --shallow-submodules ";
break;
case runcpp2::Data::SubmoduleInitType::FULL:
submoduleString = "--recursive ";
break;
default:
{
ssLOG_ERROR("Invalid git submodule init type: " <<
static_cast<int>(git->CurrentSubmoduleInitType));
return false;
}
}

std::string gitCloneCommand =
std::string("git clone ") +
submoduleString +
(git->FullHistory ? "" : "--depth 1 ") +
(
git->Branch.empty() ?
std::string("") :
std::string("--branch ") + git->Branch + " "
) +
git->URL;

ssLOG_INFO("Running git clone command: " << gitCloneCommand << " in " <<
buildDir.string());
Expand All @@ -129,6 +159,7 @@ namespace
returnCode))
{
ssLOG_ERROR("Failed to run git clone with result: " << returnCode);
ssLOG_ERROR("Was trying to run: " << gitCloneCommand);
//ssLOG_ERROR("Output: \n" << output);
return false;
}
Expand Down Expand Up @@ -266,6 +297,7 @@ namespace
returnCode))
{
ssLOG_ERROR("Failed to run command with result: " << returnCode);
ssLOG_ERROR("Was trying to run: " << commands->at(k));
ssLOG_ERROR("Output: \n" << output);
return false;
}
Expand Down
1 change: 1 addition & 0 deletions Src/runcpp2/PipelineSteps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ runcpp2::RunProfileCommands(const Data::ProfilesCommands* commands,
{
ssLOG_ERROR(commandType << " command failed: " << cmd <<
" with return code " << returnCode);
ssLOG_ERROR("Was trying to run: " << cmd);
ssLOG_ERROR("Output: \n" << output);
return PipelineResult::UNEXPECTED_FAILURE;
}
Expand Down
15 changes: 9 additions & 6 deletions mkdocs/docs/TODO.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# Roadmap

## Planned
## Done

!!! info "`latest` version"
- More git options
- Add branch/tag option for git
- Add initialize submodule option for git
- Async/Multi-thread compile and dependencies processing


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


Loading