This commit is contained in:
parent
52436399e8
commit
d1c427c9cc
2 changed files with 42 additions and 5 deletions
|
|
@ -26,6 +26,7 @@ module;
|
|||
#include <iostream>
|
||||
#include "json.hpp"
|
||||
#include <filesystem>
|
||||
#include <unordered_set>
|
||||
#include <thread>
|
||||
#include <glslang/SPIRV/GlslangToSpv.h>
|
||||
#include <regex>
|
||||
|
|
@ -33,6 +34,26 @@ module Crafter.Build;
|
|||
using namespace Crafter::Build;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
|
||||
std::vector<std::string> mergeUnique(const std::vector<std::string>& vec1, const std::vector<std::string>& vec2) {
|
||||
std::unordered_set<std::string> uniqueElements;
|
||||
std::vector<std::string> 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<Configuration> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@
|
|||
{
|
||||
"name": "debug-lib",
|
||||
"extends": ["lib"],
|
||||
"optimization_level": "0"
|
||||
"optimization_level": "0",
|
||||
"debug": true
|
||||
},
|
||||
{
|
||||
"name": "release-lib",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue