From d1c427c9cc4dd107f6bf3214489f62fb0c13d8dd Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Sat, 3 May 2025 01:48:55 +0200 Subject: [PATCH] dependency fix --- Crafter.Build-Project.cpp | 44 +++++++++++++++++++++++++++++++++++---- project.json | 3 ++- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Crafter.Build-Project.cpp b/Crafter.Build-Project.cpp index 689c6a0..e16eac4 100644 --- a/Crafter.Build-Project.cpp +++ b/Crafter.Build-Project.cpp @@ -26,6 +26,7 @@ module; #include #include "json.hpp" #include +#include #include #include #include @@ -33,6 +34,26 @@ module Crafter.Build; using namespace Crafter::Build; namespace fs = std::filesystem; + +std::vector mergeUnique(const std::vector& vec1, const std::vector& vec2) { + std::unordered_set uniqueElements; + std::vector result; + + for (const auto& str : vec1) { + if (uniqueElements.insert(str).second) { + result.push_back(str); + } + } + + for (const auto& str : vec2) { + if (uniqueElements.insert(str).second) { + result.push_back(str); + } + } + + return result; +} + Project::Project(std::string name, fs::path path, std::vector configurations) : name(name), path(path), configurations(configurations) { } @@ -91,16 +112,16 @@ void Project::Build(Configuration config, fs::path outputDir, fs::path binDir) c } if (!fs::exists(outputDir)) { fs::create_directory(outputDir); - } else{ - for (const auto& entry : fs::directory_iterator(outputDir)) { - fs::remove_all(entry); - } } + if (!fs::exists(config.buildDir)) { + fs::create_directory(config.buildDir); + } std::string buildDir = config.buildDir/fs::path(config.name); if (!fs::exists(buildDir)) { fs::create_directory(buildDir); } + std::string target; if(!config.target.empty()){ target = std::format("-target {}", config.target); @@ -145,7 +166,10 @@ void Project::Build(Configuration config, fs::path outputDir, fs::path binDir) c if(!config.dependencies[i].branch.empty()) { system(std::format("cd {} && git clone {} && cd {} && git switch {}", buildDir, config.dependencies[i].path, (buildDir/name).generic_string(), config.dependencies[i].branch).c_str()); } else if(!config.dependencies[i].commit.empty()){ + std::cout << std::format("cd {} && git clone {} && cd {} && git checkout {}", buildDir, config.dependencies[i].path, (buildDir/name).generic_string(), config.dependencies[i].commit).c_str() << std::endl; system(std::format("cd {} && git clone {} && cd {} && git checkout {}", buildDir, config.dependencies[i].path, (buildDir/name).generic_string(), config.dependencies[i].commit).c_str()); + } else { + system(std::format("cd {} && git clone {}", buildDir, config.dependencies[i].path).c_str()); } } else if(config.dependencies[i].commit.empty()) { system(std::format("cd {} && git pull", (buildDir/name).generic_string()).c_str()); @@ -156,12 +180,24 @@ void Project::Build(Configuration config, fs::path outputDir, fs::path binDir) c depThreads[i] = std::thread([i, pcmDir, config, project, binDir]() { project.Build(config.dependencies[i].configuration, pcmDir, binDir); }); + for(const Configuration& config2 : project.configurations) { + if(config2.name == config.dependencies[i].configuration){ + config.libs = mergeUnique(config.libs, config2.libs); + break; + } + } } else{ Project project = Project::LoadFromJSON(config.dependencies[i].path); libs+=std::format(" -l{}", project.name); depThreads[i] = std::thread([i, pcmDir, config, project, binDir]() { project.Build(config.dependencies[i].configuration, pcmDir, binDir); }); + for(const Configuration& config2 : project.configurations) { + if(config2.name == config.dependencies[i].configuration){ + config.libs = mergeUnique(config.libs, config2.libs); + break; + } + } } } diff --git a/project.json b/project.json index 1be8e3c..3375bbf 100644 --- a/project.json +++ b/project.json @@ -35,7 +35,8 @@ { "name": "debug-lib", "extends": ["lib"], - "optimization_level": "0" + "optimization_level": "0", + "debug": true }, { "name": "release-lib",