error messages
This commit is contained in:
parent
a36beab2ac
commit
23fa8b98b0
9 changed files with 199 additions and 90 deletions
|
|
@ -26,6 +26,7 @@ module;
|
|||
#include <regex>
|
||||
#include <print>
|
||||
#include <execution>
|
||||
#include <tuple>
|
||||
module Crafter.Build;
|
||||
using namespace Crafter::Build;
|
||||
namespace fs = std::filesystem;
|
||||
|
|
@ -83,7 +84,8 @@ void ModulePartition::Check() {
|
|||
}
|
||||
}
|
||||
|
||||
void ModulePartition::Compile(std::string clangDir, const Configuration& config, fs::path pcmDir, std::string target, const std::string& march, const std::string& flags) {
|
||||
std::vector<ClangError> ModulePartition::Compile(std::string clangDir, const Configuration& config, fs::path pcmDir, std::string target, const std::string& march, const std::string& flags) {
|
||||
std::vector<ClangError> errors;
|
||||
if(needsRecompiling) {
|
||||
std::string defines;
|
||||
for(const Define& define : config.defines) {
|
||||
|
|
@ -98,12 +100,13 @@ void ModulePartition::Compile(std::string clangDir, const Configuration& config,
|
|||
if(config.verbose) {
|
||||
std::cout << command << std::endl;
|
||||
}
|
||||
BounceCommand(command.c_str());
|
||||
errors = RunClang(command);
|
||||
}
|
||||
*compiled = true;
|
||||
compiled->notify_all();
|
||||
return errors;
|
||||
}
|
||||
void ModulePartition::CompileSource(std::string clangDir, const Configuration& config, fs::path pcmDir, std::string target, const std::string& march, const std::string& flags, const fs::path& buildDir) {
|
||||
std::vector<ClangError> ModulePartition::CompileSource(std::string clangDir, const Configuration& config, fs::path pcmDir, std::string target, const std::string& march, const std::string& flags, const fs::path& buildDir) {
|
||||
std::string defines;
|
||||
for(const Define& define : config.defines) {
|
||||
defines+=define.ToString();
|
||||
|
|
@ -112,7 +115,7 @@ void ModulePartition::CompileSource(std::string clangDir, const Configuration& c
|
|||
if(config.verbose) {
|
||||
std::cout << command << std::endl;
|
||||
}
|
||||
BounceCommand(command.c_str());
|
||||
return RunClang(command);
|
||||
}
|
||||
|
||||
Module::Module(const std::string& name, const fs::path& path, const Configuration& config, const fs::path& pcmDir, std::string& files, const fs::path& buildDir) : name(name), path(path) {
|
||||
|
|
@ -162,18 +165,25 @@ void Module::Check() {
|
|||
}
|
||||
}
|
||||
|
||||
void Module::Compile(std::string clangDir, const Configuration& config, fs::path pcmDir, std::string target, const std::string& march, const std::string& flags, const fs::path& buildDir) {
|
||||
std::vector<ClangError> Module::Compile(std::string clangDir, const Configuration& config, fs::path pcmDir, std::string target, const std::string& march, const std::string& flags, const fs::path& buildDir) {
|
||||
|
||||
std::string defines;
|
||||
for(const Define& define : config.defines) {
|
||||
defines+=define.ToString();
|
||||
}
|
||||
|
||||
std::mutex errorMutex;
|
||||
std::vector<ClangError> errors;
|
||||
std::vector<std::thread> threads;
|
||||
for(auto& [key, val] : partitions) {;
|
||||
if(val.needsRecompiling) {
|
||||
threads.emplace_back([&val, &clangDir, &config, &pcmDir, &target, &march, &flags](){
|
||||
val.Compile(clangDir, config, pcmDir, target, march, flags);
|
||||
threads.emplace_back([&val, &clangDir, &config, &pcmDir, &target, &march, &flags, &errors, &errorMutex](){
|
||||
std::vector<ClangError> newErrors = val.Compile(clangDir, config, pcmDir, target, march, flags);
|
||||
if(newErrors.size() > 0) {
|
||||
errorMutex.lock();
|
||||
errors.insert(errors.end(), newErrors.begin(), newErrors.end());
|
||||
errorMutex.unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -182,36 +192,56 @@ void Module::Compile(std::string clangDir, const Configuration& config, fs::path
|
|||
thread.join();
|
||||
}
|
||||
|
||||
if(errors.size() > 0) {
|
||||
return errors;
|
||||
}
|
||||
|
||||
{
|
||||
std::string command = std::format("{} {} {} -std={} {}.cppm --precompile {} -fprebuilt-module-path={} -o {}.pcm {}", clangDir, defines, flags, config.standard, path.generic_string(), march, pcmDir.generic_string(), (pcmDir/path.filename()).generic_string(), target);
|
||||
if(config.verbose) {
|
||||
std::cout << command << std::endl;
|
||||
}
|
||||
BounceCommand(command.c_str());
|
||||
errors = RunClang(command);
|
||||
}
|
||||
|
||||
if(errors.size() > 0) {
|
||||
return errors;
|
||||
}
|
||||
|
||||
std::vector<std::thread> threads2;
|
||||
for(auto& [key, val] : partitions) {;
|
||||
if(val.needsRecompiling) {
|
||||
threads2.emplace_back([&val, &clangDir, &config, &pcmDir, &target, &march, &flags, &buildDir](){
|
||||
val.CompileSource(clangDir, config, pcmDir, target, march, flags, buildDir);
|
||||
threads2.emplace_back([&val, &clangDir, &config, &pcmDir, &target, &march, &flags, &buildDir, &errors, &errorMutex](){
|
||||
std::vector<ClangError> newErrors = val.CompileSource(clangDir, config, pcmDir, target, march, flags, buildDir);
|
||||
if(newErrors.size() > 0) {
|
||||
errorMutex.lock();
|
||||
errors.insert(errors.end(), newErrors.begin(), newErrors.end());
|
||||
errorMutex.unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
threads2.emplace_back([this, &clangDir, &config, &pcmDir, &target, &march, &flags, &buildDir, &defines](){
|
||||
threads2.emplace_back([this, &clangDir, &config, &pcmDir, &target, &march, &flags, &buildDir, &defines, &errors, &errorMutex](){
|
||||
std::string command = std::format("{} {} -std={} {}.pcm -fprebuilt-module-path={} -c -O{} {} {} -o {}.o {}", clangDir, defines, config.standard, (pcmDir/path.filename()).generic_string(), pcmDir.generic_string(), config.optimizationLevel, march, flags, (buildDir/path.filename()).generic_string(), target);
|
||||
if(config.verbose) {
|
||||
std::cout << command << std::endl;
|
||||
}
|
||||
BounceCommand(command.c_str());
|
||||
std::vector<ClangError> newErrors = RunClang(command);
|
||||
if(newErrors.size() > 0) {
|
||||
errorMutex.lock();
|
||||
errors.insert(errors.end(), newErrors.begin(), newErrors.end());
|
||||
errorMutex.unlock();
|
||||
}
|
||||
});
|
||||
|
||||
for(std::thread& thread : threads2){
|
||||
thread.join();
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
std::vector<Module> Module::GetModules(std::string clangDir, const Configuration& config, fs::path pcmDir, std::string target, const std::string& march, const std::string& flags, std::string& files, const fs::path& buildDir) {
|
||||
std::tuple<std::vector<Module>, std::vector<ClangError>> Module::GetModules(std::string clangDir, const Configuration& config, fs::path pcmDir, std::string target, const std::string& march, const std::string& flags, std::string& files, const fs::path& buildDir) {
|
||||
std::vector<Module> modules;
|
||||
for(const fs::path& file: config.moduleFiles) {
|
||||
std::ifstream t(file.generic_string()+".cppm");
|
||||
|
|
@ -225,9 +255,16 @@ std::vector<Module> Module::GetModules(std::string clangDir, const Configuration
|
|||
modules.emplace_back(match[1], file, config, pcmDir, files, buildDir);
|
||||
}
|
||||
}
|
||||
std::for_each(std::execution::par, modules.begin(), modules.end(), [&clangDir, &config, &pcmDir, &target, &march, &flags, &buildDir](Module& modulee) {
|
||||
std::vector<ClangError> errors;
|
||||
std::mutex errorMutex;
|
||||
std::for_each(std::execution::par, modules.begin(), modules.end(), [&clangDir, &config, &pcmDir, &target, &march, &flags, &buildDir, &errors, &errorMutex](Module& modulee) {
|
||||
modulee.Check();
|
||||
modulee.Compile(clangDir, config, pcmDir, target, march, flags, buildDir);
|
||||
std::vector<ClangError> newErrors = modulee.Compile(clangDir, config, pcmDir, target, march, flags, buildDir);
|
||||
if(newErrors.size() > 0) {
|
||||
errorMutex.lock();
|
||||
errors.insert(errors.end(), newErrors.begin(), newErrors.end());
|
||||
errorMutex.unlock();
|
||||
}
|
||||
});
|
||||
return modules;
|
||||
return {modules, errors};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue