error messages
This commit is contained in:
parent
a36beab2ac
commit
23fa8b98b0
9 changed files with 199 additions and 90 deletions
|
|
@ -31,6 +31,7 @@ module;
|
|||
#include <glslang/SPIRV/GlslangToSpv.h>
|
||||
#include <regex>
|
||||
#include <mutex>
|
||||
#include <tuple>
|
||||
module Crafter.Build;
|
||||
using namespace Crafter::Build;
|
||||
namespace fs = std::filesystem;
|
||||
|
|
@ -39,45 +40,42 @@ Project::Project(std::string name, fs::path path, std::vector<Configuration> con
|
|||
|
||||
}
|
||||
|
||||
const Configuration& Project::Build(std::string configuration) {
|
||||
std::tuple<Configuration&, std::vector<ClangError>> Project::Build(std::string configuration) {
|
||||
for(Configuration& config : configurations) {
|
||||
if(config.name == configuration){
|
||||
Build(config);
|
||||
return config;
|
||||
return {config, Build(config)};
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("Configuration: " + configuration + " not found.");
|
||||
}
|
||||
|
||||
const Configuration& Project::Build(std::string configuration, fs::path outputDir) {
|
||||
std::tuple<Configuration&, std::vector<ClangError>> Project::Build(std::string configuration, fs::path outputDir) {
|
||||
for(Configuration& config : configurations) {
|
||||
if(config.name == configuration){
|
||||
Build(config, outputDir);
|
||||
return config;
|
||||
return {config, Build(config, outputDir)};
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("Configuration: " + configuration + " not found.");
|
||||
}
|
||||
|
||||
const Configuration& Project::Build(std::string configuration, fs::path outputDir, fs::path binDir) {
|
||||
std::tuple<Configuration&, std::vector<ClangError>> Project::Build(std::string configuration, fs::path outputDir, fs::path binDir) {
|
||||
for(Configuration& config : configurations) {
|
||||
if(config.name == configuration){
|
||||
Build(config, outputDir, binDir);
|
||||
return config;
|
||||
return {config, Build(config, outputDir, binDir)};
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("Configuration: " + configuration + " not found.");
|
||||
}
|
||||
|
||||
void Project::Build(Configuration& configuration) {
|
||||
Build(configuration, configuration.outputDir);
|
||||
std::vector<ClangError> Project::Build(Configuration& configuration) {
|
||||
return Build(configuration, configuration.outputDir);
|
||||
}
|
||||
|
||||
void Project::Build(Configuration& config, fs::path outputDir) {
|
||||
Build(config, outputDir, outputDir);
|
||||
std::vector<ClangError> Project::Build(Configuration& config, fs::path outputDir) {
|
||||
return Build(config, outputDir, outputDir);
|
||||
}
|
||||
|
||||
void Project::Build(Configuration& config, fs::path outputDir, fs::path binDir) {
|
||||
std::vector<ClangError> Project::Build(Configuration& config, fs::path outputDir, fs::path binDir) {
|
||||
if(config.standard.empty()) {
|
||||
config.standard = "c++26";
|
||||
}
|
||||
|
|
@ -161,13 +159,16 @@ void Project::Build(Configuration& config, fs::path outputDir, fs::path binDir)
|
|||
if (depLibSet.insert(project.name).second) {
|
||||
libs+=std::format(" -l{}", project.name);
|
||||
}
|
||||
const Configuration& depConfig = project.Build(config.dependencies[i].configuration, pcmDir, binDir);
|
||||
for(const std::string& lib2 : depConfig.libs) {
|
||||
std::tuple<Configuration&, std::vector<ClangError>> depConfig = project.Build(config.dependencies[i].configuration, pcmDir, binDir);
|
||||
if(std::get<1>(depConfig).size() > 0) {
|
||||
return std::get<1>(depConfig);
|
||||
}
|
||||
for(const std::string& lib2 : std::get<0>(depConfig).libs) {
|
||||
if (depLibSet.insert(lib2).second) {
|
||||
libs+=std::format(" -l{}", lib2);
|
||||
}
|
||||
}
|
||||
for(const Dependency& dep2 : depConfig.dependencies) {
|
||||
for(const Dependency& dep2 : std::get<0>(depConfig).dependencies) {
|
||||
if (depLibSet.insert(dep2.name).second) {
|
||||
libs+=std::format(" -l{}", dep2.name);
|
||||
}
|
||||
|
|
@ -179,13 +180,16 @@ void Project::Build(Configuration& config, fs::path outputDir, fs::path binDir)
|
|||
if (depLibSet.insert(project.name).second) {
|
||||
libs+=std::format(" -l{}", project.name);
|
||||
}
|
||||
const Configuration& depConfig = project.Build(config.dependencies[i].configuration, pcmDir, binDir);
|
||||
for(const std::string& lib2 : depConfig.libs) {
|
||||
if (depLibSet.insert(lib2).second) {
|
||||
std::tuple<Configuration&, std::vector<ClangError>> depConfig = project.Build(config.dependencies[i].configuration, pcmDir, binDir);
|
||||
if(std::get<1>(depConfig).size() > 0) {
|
||||
return std::get<1>(depConfig);
|
||||
}
|
||||
for(const std::string& lib2 : std::get<0>(depConfig).libs) {
|
||||
if (depLibSet.insert(lib2).second) {
|
||||
libs+=std::format(" -l{}", lib2);
|
||||
}
|
||||
}
|
||||
for(const Dependency& dep2 : depConfig.dependencies) {
|
||||
for(const Dependency& dep2 : std::get<0>(depConfig).dependencies) {
|
||||
if (depLibSet.insert(dep2.name).second) {
|
||||
libs+=std::format(" -l{}", dep2.name);
|
||||
}
|
||||
|
|
@ -229,17 +233,24 @@ void Project::Build(Configuration& config, fs::path outputDir, fs::path binDir)
|
|||
}
|
||||
|
||||
std::string files;
|
||||
std::vector<Module> modules = Module::GetModules(clangDir, config, pcmDir, target, march, flags, files, buildDir);
|
||||
std::tuple<std::vector<Module>, std::vector<ClangError>> modules = Module::GetModules(clangDir, config, pcmDir, target, march, flags, files, buildDir);
|
||||
|
||||
if(std::get<1>(modules).size() > 0) {
|
||||
return std::get<1>(modules);
|
||||
}
|
||||
|
||||
std::vector<ClangError> errors = Source::GetSourceFiles(clangDir, config, pcmDir, target, march, flags, std::get<0>(modules), files, buildDir);
|
||||
if(errors.size() > 0) {
|
||||
return errors;
|
||||
}
|
||||
|
||||
std::vector<std::thread> threads;
|
||||
|
||||
Source::GetSourceFiles(clangDir, config, pcmDir, target, march, flags, threads, modules, files, buildDir);
|
||||
|
||||
for(std::uint_fast32_t i = 0; i < config.c_files.size(); i++) {
|
||||
files+=std::format("{}_source.o ",(buildDir/config.c_files[i].filename()).generic_string());
|
||||
if(!fs::exists((buildDir/config.c_files[i].filename()).generic_string()+"_source.o") || fs::last_write_time(config.c_files[i].generic_string()+".c") > fs::last_write_time((buildDir/config.c_files[i].filename()).generic_string()+"_source.o")) {
|
||||
threads.emplace_back([i, &config, pcmDir, target, clangDir, flags, march, &buildDir](){
|
||||
BounceCommand(std::format("clang {}.c -c -O{} {} {} -o {}_source.o {}", config.c_files[i].generic_string(), config.optimizationLevel, march, flags, (buildDir/config.c_files[i].filename()).generic_string(), target).c_str());
|
||||
RunCommand(std::format("clang {}.c -c -O{} {} {} -o {}_source.o {}", config.c_files[i].generic_string(), config.optimizationLevel, march, flags, (buildDir/config.c_files[i].filename()).generic_string(), target).c_str());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -249,19 +260,18 @@ void Project::Build(Configuration& config, fs::path outputDir, fs::path binDir)
|
|||
}
|
||||
|
||||
if(config.type == "executable"){
|
||||
if(config.target == "x86_64-w64-mingw64" || config.target == "x86_64-w64-mingw32") {
|
||||
flags += " -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread";
|
||||
name += ".exe";
|
||||
}
|
||||
std::string command = std::format("{} {} {}-O{} -o {} {} {} -fuse-ld=lld", clangDir, flags, files, config.optimizationLevel, (outputDir/name).generic_string(), target, libs);
|
||||
if(config.verbose) {
|
||||
std::cout << command << std::endl;
|
||||
}
|
||||
BounceCommand(command.c_str());
|
||||
std::vector<ClangError> errors = RunClang(command);
|
||||
if(errors.size() > 0) {
|
||||
return errors;
|
||||
}
|
||||
} else if(config.type == "library"){
|
||||
BounceCommandIgnore(std::format("ar r {}.a {}", (outputDir/fs::path("lib"+name)).generic_string(), files).c_str());
|
||||
RunCommandIgnore(std::format("ar r {}.a {}", (outputDir/fs::path("lib"+name)).generic_string(), files).c_str());
|
||||
} else if(config.type == "shared-library"){
|
||||
BounceCommandIgnore(std::format("ar r {}.so {}", (outputDir/fs::path("lib"+name)).generic_string(), files).c_str());
|
||||
RunCommandIgnore(std::format("ar r {}.so {}", (outputDir/fs::path("lib"+name)).generic_string(), files).c_str());
|
||||
}
|
||||
|
||||
for(const fs::path& additionalFile : config.additionalFiles){
|
||||
|
|
@ -272,6 +282,7 @@ void Project::Build(Configuration& config, fs::path outputDir, fs::path binDir)
|
|||
fs::copy(additionalFile, binDir);
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Project Project::LoadFromJSON(fs::path path) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue