dependancy fix
Some checks failed
demo.yaml / dependancy fix (push) Failing after 0s

This commit is contained in:
Jorijn van der Graaf 2025-11-26 17:55:52 +01:00
commit 74f0f19b4a
2 changed files with 49 additions and 24 deletions

View file

@ -33,13 +33,11 @@ namespace Crafter {
Configuration::Configuration(std::string&& name) : name(std::move(name)) {
}
Configuration::Configuration(const nlohmann::json& configs, const nlohmann::json& config, fs::path workingDir, const Project& project) {
Configuration::Configuration(const nlohmann::json& configs, const nlohmann::json& config, fs::path workingDir, const Project& project) : type(CRAFTER_CONFIGURATION_TYPE_EXECUTABLE), debug(false) {
SetDataFromJson(configs, config, workingDir, project);
}
void Configuration::SetDataFromJson(const nlohmann::json& configs, const nlohmann::json& config, fs::path workingDir, const Project& project) {
type = static_cast<ConfigurationType>(-1);
debug = static_cast<bool>(2);
if(config.contains("extends")) {
const std::vector<std::string> extends = config["extends"].get<std::vector<std::string>>();
for(const std::string& extendName : extends) {
@ -63,8 +61,6 @@ namespace Crafter {
}
if(config.contains("debug")) {
debug = config["debug"].get<bool>();
} else if(static_cast<int>(debug) == 2) {
debug = false;
}
if(config.contains("type")) {
std::string typeString = config["type"].get<std::string>();
@ -77,8 +73,6 @@ namespace Crafter {
} else {
throw std::invalid_argument("Unknown type: " + typeString);
}
} else if(static_cast<int>(type) == -1) {
type = CRAFTER_CONFIGURATION_TYPE_EXECUTABLE;
}
if(config.contains("march")) {
march = config["march"].get<std::string>();
@ -221,7 +215,11 @@ namespace Crafter {
}
if(config.contains("defines")) {
for (auto it : config["defines"]) {
defines.emplace_back(it["name"].get<std::string>(), it["value"].get<std::string>());
if(it.contains("value")) {
defines.emplace_back(it["name"].get<std::string>(), it["value"].get<std::string>());
} else {
defines.emplace_back(it["name"].get<std::string>(), "");
}
}
}
if(config.contains("additional_files")) {
@ -237,20 +235,43 @@ namespace Crafter {
if(path.string().ends_with(".git")) {
fs::path name = path.filename();
name.replace_extension();
if(!fs::exists(project.buildDir/name)) {
if(it.contains("branch")) {
system(std::format("cd {} && git clone {} && cd {} && git switch {}",project.buildDir.string(), path.string(), (project.buildDir/name).string(), it["branch"].get<std::string>()).c_str());
} else if(it.contains("commit")){
system(std::format("cd {} && git clone {} && cd {} && git checkout {}", project.buildDir.string(), path.string(), (project.buildDir/name).string(), it["commit"].get<std::string>()).c_str());
} else {
system(std::format("cd {} && git clone {}", project.buildDir.string(), path.string()).c_str());
}
} else if(!it.contains("commit")) {
system(std::format("cd {} && git pull", (project.buildDir/name).string()).c_str());
std::string depFolder = name.string() + "-" + configName;
if (it.contains("commit")) {
depFolder + it["commit"].get<std::string>();
} else if (it.contains("branch")) {
depFolder + it["branch"].get<std::string>();
}
path = project.buildDir/name/"project.json";
if (!fs::exists(project.buildDir/depFolder)) {
fs::create_directories(project.buildDir/depFolder);
std::string cloneCommand = std::format("cd {} && git clone {} {} && cd {}",
project.buildDir.string(),
path.string(),
depFolder,
depFolder);
if (it.contains("branch")) {
cloneCommand += std::format(" && git switch {}", it["branch"].get<std::string>());
} else if (it.contains("commit")) {
cloneCommand += std::format(" && git checkout {}", it["commit"].get<std::string>());
}
// Execute the clone command
system(cloneCommand.c_str());
} else if (!it.contains("commit")) {
system(std::format("cd {} && git pull", (project.buildDir/depFolder).string()).c_str());
}
// Update path to the project.json of the dependency
path = project.buildDir/ depFolder / "project.json";
}
// Create a Project object for the dependency
std::unique_ptr<Project> depProject = std::make_unique<Project>(std::move(path), configName);
// Add the dependency to the list
dependencies.emplace_back(std::move(depProject), depProject->configurations[0]);
}
}

View file

@ -43,14 +43,14 @@ namespace Crafter {
nlohmann::json testJson = data["tests"];
if(data.contains("bin_dir")) {
binDir = data["bin_dir"].get<std::string>();
binDir = this->path/data["bin_dir"].get<std::string>();
} else {
binDir = "bin";
binDir = this->path/"bin";
}
if(data.contains("build_dir")) {
buildDir = data["build_dir"].get<std::string>();
buildDir = this->path/data["build_dir"].get<std::string>();
} else {
buildDir = "build";
buildDir = this->path/"build";
}
if (!fs::exists(binDir)) {
@ -224,7 +224,11 @@ namespace Crafter {
command += std::format(" -std=c++26");
}
for(const Define& define : config.defines) {
command += std::format(" -D {}={}", define.name, define.value);
if(define.value.empty()) {
command += std::format(" -D {}", define.name);
} else {
command += std::format(" -D {}={}", define.name, define.value);
}
}
fs::path pcmDir;