added specfic git commit or branch dependency

This commit is contained in:
Jorijn van der Graaf 2025-03-29 22:36:43 +01:00
commit 1bfc07db4b
4 changed files with 24 additions and 4 deletions

View file

@ -80,7 +80,15 @@ Configuration::Configuration(const nlohmann::json& configs, const nlohmann::json
outputDir = fullOutputPath.generic_string(); outputDir = fullOutputPath.generic_string();
} else if(key == "dependencies") { } else if(key == "dependencies") {
for (auto it : val) { for (auto it : val) {
dependencies.emplace_back(it["path"].get<std::string>(), it["configuration"].get<std::string>()); std::string commit;
std::string branch;
if(it.contains("commit")){
commit = it["commit"].get<std::string>();
}
if(it.contains("branch")){
branch = it["branch"].get<std::string>();
}
dependencies.emplace_back(it["path"].get<std::string>(), it["configuration"].get<std::string>(), commit, branch);
} }
} else if(key != "extends") { } else if(key != "extends") {
additionalProperties.insert({key, val}); additionalProperties.insert({key, val});

View file

@ -23,6 +23,6 @@ module;
module Crafter.Build; module Crafter.Build;
using namespace Crafter::Build; using namespace Crafter::Build;
Dependency::Dependency(std::string path, std::string configuration): path(path), configuration(configuration) { Dependency::Dependency(std::string path, std::string configuration, std::string commit, std::string branch): path(path), configuration(configuration), commit(commit), branch(branch) {
} }

View file

@ -26,6 +26,8 @@ export namespace Crafter::Build {
public: public:
std::string path; std::string path;
std::string configuration; std::string configuration;
Dependency(std::string path, std::string configuration); std::string commit;
std::string branch;
Dependency(std::string path, std::string configuration, std::string commit, std::string branch);
}; };
} }

View file

@ -112,7 +112,17 @@ void Project::Build(Configuration config, fs::path outputDir, fs::path binDir) c
for(std::int_fast32_t i = 0; i < depThreads.size(); i++) { for(std::int_fast32_t i = 0; i < depThreads.size(); i++) {
if(config.dependencies[i].path.ends_with(".git")) { if(config.dependencies[i].path.ends_with(".git")) {
system(std::format("cd {} && git clone {}", config.buildDir, config.dependencies[i].path).c_str()); std::string branch;
if(!config.dependencies[i].branch.empty()) {
fs::path name = fs::path(config.dependencies[i].path).filename();
name.replace_extension();
branch = std::format(" && cd {} && git switch {}", name.generic_string(), config.dependencies[i].branch);
} else if(!config.dependencies[i].commit.empty()){
fs::path name = fs::path(config.dependencies[i].path).filename();
name.replace_extension();
branch = std::format(" && cd {} && git checkout {}", name.generic_string(), config.dependencies[i].commit);
}
system(std::format("cd {} && git clone {}{}", config.buildDir, config.dependencies[i].path, branch).c_str());
config.dependencies[i].path = fs::path(config.dependencies[i].path).filename().replace_extension(); config.dependencies[i].path = fs::path(config.dependencies[i].path).filename().replace_extension();
Project project = Project::LoadFromJSON(fs::path(config.buildDir)/config.dependencies[i].path/"project.json"); Project project = Project::LoadFromJSON(fs::path(config.buildDir)/config.dependencies[i].path/"project.json");
libs+=std::format(" -l{}", project.name); libs+=std::format(" -l{}", project.name);