diff --git a/implementations/Crafter.Build-Configuration.cpp b/implementations/Crafter.Build-Configuration.cpp index 5f86f0f..794f0c4 100644 --- a/implementations/Crafter.Build-Configuration.cpp +++ b/implementations/Crafter.Build-Configuration.cpp @@ -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(-1); - debug = static_cast(2); if(config.contains("extends")) { const std::vector extends = config["extends"].get>(); for(const std::string& extendName : extends) { @@ -63,8 +61,6 @@ namespace Crafter { } if(config.contains("debug")) { debug = config["debug"].get(); - } else if(static_cast(debug) == 2) { - debug = false; } if(config.contains("type")) { std::string typeString = config["type"].get(); @@ -77,8 +73,6 @@ namespace Crafter { } else { throw std::invalid_argument("Unknown type: " + typeString); } - } else if(static_cast(type) == -1) { - type = CRAFTER_CONFIGURATION_TYPE_EXECUTABLE; } if(config.contains("march")) { march = config["march"].get(); @@ -221,7 +215,11 @@ namespace Crafter { } if(config.contains("defines")) { for (auto it : config["defines"]) { - defines.emplace_back(it["name"].get(), it["value"].get()); + if(it.contains("value")) { + defines.emplace_back(it["name"].get(), it["value"].get()); + } else { + defines.emplace_back(it["name"].get(), ""); + } } } 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()).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()).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(); + } else if (it.contains("branch")) { + depFolder + it["branch"].get(); } - 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()); + } else if (it.contains("commit")) { + cloneCommand += std::format(" && git checkout {}", it["commit"].get()); + } + + // 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 depProject = std::make_unique(std::move(path), configName); + + // Add the dependency to the list dependencies.emplace_back(std::move(depProject), depProject->configurations[0]); } } diff --git a/implementations/Crafter.Build-Project.cpp b/implementations/Crafter.Build-Project.cpp index 914d630..6e262a5 100644 --- a/implementations/Crafter.Build-Project.cpp +++ b/implementations/Crafter.Build-Project.cpp @@ -43,14 +43,14 @@ namespace Crafter { nlohmann::json testJson = data["tests"]; if(data.contains("bin_dir")) { - binDir = data["bin_dir"].get(); + binDir = this->path/data["bin_dir"].get(); } else { - binDir = "bin"; + binDir = this->path/"bin"; } if(data.contains("build_dir")) { - buildDir = data["build_dir"].get(); + buildDir = this->path/data["build_dir"].get(); } 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;