This commit is contained in:
parent
0819baf6d3
commit
74f0f19b4a
2 changed files with 49 additions and 24 deletions
|
|
@ -33,13 +33,11 @@ namespace Crafter {
|
||||||
Configuration::Configuration(std::string&& name) : name(std::move(name)) {
|
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);
|
SetDataFromJson(configs, config, workingDir, project);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Configuration::SetDataFromJson(const nlohmann::json& configs, const nlohmann::json& config, fs::path workingDir, const Project& 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")) {
|
if(config.contains("extends")) {
|
||||||
const std::vector<std::string> extends = config["extends"].get<std::vector<std::string>>();
|
const std::vector<std::string> extends = config["extends"].get<std::vector<std::string>>();
|
||||||
for(const std::string& extendName : extends) {
|
for(const std::string& extendName : extends) {
|
||||||
|
|
@ -63,8 +61,6 @@ namespace Crafter {
|
||||||
}
|
}
|
||||||
if(config.contains("debug")) {
|
if(config.contains("debug")) {
|
||||||
debug = config["debug"].get<bool>();
|
debug = config["debug"].get<bool>();
|
||||||
} else if(static_cast<int>(debug) == 2) {
|
|
||||||
debug = false;
|
|
||||||
}
|
}
|
||||||
if(config.contains("type")) {
|
if(config.contains("type")) {
|
||||||
std::string typeString = config["type"].get<std::string>();
|
std::string typeString = config["type"].get<std::string>();
|
||||||
|
|
@ -77,8 +73,6 @@ namespace Crafter {
|
||||||
} else {
|
} else {
|
||||||
throw std::invalid_argument("Unknown type: " + typeString);
|
throw std::invalid_argument("Unknown type: " + typeString);
|
||||||
}
|
}
|
||||||
} else if(static_cast<int>(type) == -1) {
|
|
||||||
type = CRAFTER_CONFIGURATION_TYPE_EXECUTABLE;
|
|
||||||
}
|
}
|
||||||
if(config.contains("march")) {
|
if(config.contains("march")) {
|
||||||
march = config["march"].get<std::string>();
|
march = config["march"].get<std::string>();
|
||||||
|
|
@ -221,7 +215,11 @@ namespace Crafter {
|
||||||
}
|
}
|
||||||
if(config.contains("defines")) {
|
if(config.contains("defines")) {
|
||||||
for (auto it : config["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")) {
|
if(config.contains("additional_files")) {
|
||||||
|
|
@ -237,20 +235,43 @@ namespace Crafter {
|
||||||
if(path.string().ends_with(".git")) {
|
if(path.string().ends_with(".git")) {
|
||||||
fs::path name = path.filename();
|
fs::path name = path.filename();
|
||||||
name.replace_extension();
|
name.replace_extension();
|
||||||
if(!fs::exists(project.buildDir/name)) {
|
std::string depFolder = name.string() + "-" + configName;
|
||||||
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());
|
if (it.contains("commit")) {
|
||||||
} else if(it.contains("commit")){
|
depFolder + it["commit"].get<std::string>();
|
||||||
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 if (it.contains("branch")) {
|
||||||
} else {
|
depFolder + it["branch"].get<std::string>();
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
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);
|
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]);
|
dependencies.emplace_back(std::move(depProject), depProject->configurations[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,14 +43,14 @@ namespace Crafter {
|
||||||
nlohmann::json testJson = data["tests"];
|
nlohmann::json testJson = data["tests"];
|
||||||
|
|
||||||
if(data.contains("bin_dir")) {
|
if(data.contains("bin_dir")) {
|
||||||
binDir = data["bin_dir"].get<std::string>();
|
binDir = this->path/data["bin_dir"].get<std::string>();
|
||||||
} else {
|
} else {
|
||||||
binDir = "bin";
|
binDir = this->path/"bin";
|
||||||
}
|
}
|
||||||
if(data.contains("build_dir")) {
|
if(data.contains("build_dir")) {
|
||||||
buildDir = data["build_dir"].get<std::string>();
|
buildDir = this->path/data["build_dir"].get<std::string>();
|
||||||
} else {
|
} else {
|
||||||
buildDir = "build";
|
buildDir = this->path/"build";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs::exists(binDir)) {
|
if (!fs::exists(binDir)) {
|
||||||
|
|
@ -224,7 +224,11 @@ namespace Crafter {
|
||||||
command += std::format(" -std=c++26");
|
command += std::format(" -std=c++26");
|
||||||
}
|
}
|
||||||
for(const Define& define : config.defines) {
|
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;
|
fs::path pcmDir;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue