threaded exception handling
Some checks failed
demo.yaml / threaded exception handling (push) Failing after 0s
Some checks failed
demo.yaml / threaded exception handling (push) Failing after 0s
This commit is contained in:
parent
598c666e91
commit
c2bb9023d4
14 changed files with 237 additions and 127 deletions
|
|
@ -31,28 +31,28 @@ namespace Crafter {
|
|||
Project::Project(std::string&& name, fs::path&& path, std::vector<Configuration>&& configurations) : name(std::move(name)), path(std::move(path)), configurations(std::move(configurations)) {}
|
||||
Project::Project(std::string&& name, fs::path&& path, std::vector<Configuration>&& configurations, fs::path&& binDir, fs::path&& buildDir) : name(std::move(name)), path(std::move(path)), configurations(std::move(configurations)), binDir(std::move(binDir)), buildDir(std::move(buildDir)) {}
|
||||
|
||||
Configuration& Project::Build(std::string_view configuration) {
|
||||
|
||||
std::tuple<Configuration&, BuildResult> Project::Build(std::string_view configuration) {
|
||||
for(Configuration& config : configurations) {
|
||||
if(config.name == configuration){
|
||||
Build(config);
|
||||
return config;
|
||||
return {config, Build(config)};
|
||||
}
|
||||
}
|
||||
throw std::runtime_error(std::format("Configuration: {} not found.", configuration));
|
||||
}
|
||||
Configuration& Project::Build(std::string_view configuration, const fs::path& binDir, const fs::path& outputDir, const fs::path& buildDir, std::string outputName) {
|
||||
std::tuple<Configuration&, BuildResult> Project::Build(std::string_view configuration, const fs::path& binDir, const fs::path& outputDir, const fs::path& buildDir, std::string outputName) {
|
||||
for(Configuration& config : configurations) {
|
||||
if(config.name == configuration){
|
||||
Build(config, binDir, binDir, outputDir, outputName);
|
||||
return config;
|
||||
return {config, Build(config)};
|
||||
}
|
||||
}
|
||||
throw std::runtime_error(std::format("Configuration: {} not found.", configuration));
|
||||
}
|
||||
void Project::Build(Configuration& config) const {
|
||||
Build(config, binDir/config.name, binDir/config.name, buildDir/config.name, name);
|
||||
BuildResult Project::Build(Configuration& config) const {
|
||||
return Build(config, binDir/config.name, binDir/config.name, buildDir/config.name, name);
|
||||
}
|
||||
void Project::Build(Configuration& config, const fs::path& binDir, const fs::path& outputDir, const fs::path& buildDir, std::string outputName) const {
|
||||
BuildResult Project::Build(Configuration& config, const fs::path& binDir, const fs::path& outputDir, const fs::path& buildDir, std::string outputName) const {
|
||||
BuildResult buildResult;
|
||||
if (!fs::exists(binDir)) {
|
||||
fs::create_directories(binDir);
|
||||
}
|
||||
|
|
@ -75,7 +75,6 @@ namespace Crafter {
|
|||
std::thread fileThread([&config, &outputDir](){
|
||||
for (const fs::path& additionalFile : config.additionalFiles) {
|
||||
fs::path destination = outputDir / additionalFile.filename();
|
||||
std::cout << destination << std::endl;
|
||||
|
||||
if (fs::is_directory(additionalFile)) {
|
||||
if (!fs::exists(destination)) {
|
||||
|
|
@ -190,9 +189,10 @@ namespace Crafter {
|
|||
std::vector<std::thread> depThreads = std::vector<std::thread>(config.dependencies.size());
|
||||
std::mutex libMutex;
|
||||
std::string libsString;
|
||||
std::vector<std::string> resultsDep(config.dependencies.size());
|
||||
|
||||
for(std::uint_fast32_t i = 0; i < depThreads.size(); i++) {
|
||||
depThreads[i] = std::thread([i, &config, &libMutex, &depLibSet, &buildDir, &pcmDir, &libsString, &binDir, this](){
|
||||
depThreads[i] = std::thread([i, &config, &libMutex, &depLibSet, &buildDir, &pcmDir, &libsString, &binDir, this, &buildResult, &resultsDep](){
|
||||
if(config.dependencies[i].path.ends_with(".git")) {
|
||||
fs::path name = fs::path(config.dependencies[i].path).filename();
|
||||
name.replace_extension();
|
||||
|
|
@ -216,8 +216,13 @@ namespace Crafter {
|
|||
for(Configuration& depConfig : project.configurations) {
|
||||
if(depConfig.name == config.dependencies[i].configuration){
|
||||
fs::path depBuildDir = fs::path(config.dependencies[i].path).parent_path()/project.buildDir/depConfig.name;
|
||||
project.Build(depConfig, pcmDir, binDir, depBuildDir, project.name);
|
||||
BuildResult depResult = project.Build(depConfig, pcmDir, binDir, depBuildDir, project.name);
|
||||
libMutex.lock();
|
||||
if(depResult.repack) {
|
||||
buildResult.repack = true;
|
||||
}
|
||||
resultsDep[i] = depResult.errors;
|
||||
|
||||
if (depLibSet.insert(project.name).second) {
|
||||
libsString+=std::format(" -l{}", project.name);
|
||||
}
|
||||
|
|
@ -231,6 +236,7 @@ namespace Crafter {
|
|||
libsString+=std::format(" -l{}", project.name);
|
||||
}
|
||||
}
|
||||
|
||||
libMutex.unlock();
|
||||
return;
|
||||
}
|
||||
|
|
@ -243,31 +249,55 @@ namespace Crafter {
|
|||
thread.join();
|
||||
}
|
||||
|
||||
for(const std::string& result2 : resultsDep) {
|
||||
buildResult.errors += result2;
|
||||
}
|
||||
|
||||
if(!buildResult.errors.empty()) {
|
||||
fileThread.join();
|
||||
return buildResult;
|
||||
}
|
||||
|
||||
std::string files;
|
||||
bool repack = false;
|
||||
for(std::unique_ptr<Module>& modulee : config.interfaces) {
|
||||
if(modulee->Check(pcmDir)) {
|
||||
threads.emplace_back(&Module::Compile, modulee.get(), command, pcmDir, buildDir);
|
||||
repack = true;
|
||||
std::vector<std::string> resultInterfaces(config.interfaces.size());
|
||||
|
||||
for(uint_fast32_t i = 0; i < config.interfaces.size(); i++) {
|
||||
if(config.interfaces[i]->Check(pcmDir)) {
|
||||
threads.emplace_back(&Module::Compile, config.interfaces[i].get(), command, pcmDir, buildDir, std::ref(resultInterfaces[i]));
|
||||
buildResult.repack = true;
|
||||
}
|
||||
files += std::format(" {}/{}.o", buildDir.string(), modulee->path.filename().string());
|
||||
for(std::unique_ptr<ModulePartition>& part : modulee->partitions) {
|
||||
files += std::format(" {}/{}.o", buildDir.string(), config.interfaces[i]->path.filename().string());
|
||||
for(std::unique_ptr<ModulePartition>& part : config.interfaces[i]->partitions) {
|
||||
files += std::format(" {}/{}.o", buildDir.string(), part->path.filename().string());
|
||||
}
|
||||
}
|
||||
std::vector<std::string> resultImplementations(config.implementations.size());
|
||||
|
||||
for(const Implementation& implementation : config.implementations) {
|
||||
if(implementation.Check(buildDir, pcmDir)) {
|
||||
repack = true;
|
||||
threads.emplace_back(&Implementation::Compile, &implementation, command, buildDir);
|
||||
for(uint_fast32_t i = 0; i < config.implementations.size(); i++) {
|
||||
if(config.implementations[i].Check(buildDir, pcmDir)) {
|
||||
buildResult.repack = true;
|
||||
threads.emplace_back(&Implementation::Compile, &config.implementations[i], command, buildDir, std::ref(resultImplementations[i]));
|
||||
}
|
||||
files += std::format(" {}/{}_impl.o", buildDir.string(), implementation.path.filename().string());
|
||||
files += std::format(" {}/{}_impl.o", buildDir.string(), config.implementations[i].path.filename().string());
|
||||
}
|
||||
|
||||
for(std::thread& thread : threads) {
|
||||
thread.join();
|
||||
}
|
||||
|
||||
for(const std::string& result2 : resultInterfaces) {
|
||||
buildResult.errors += result2;
|
||||
}
|
||||
for(const std::string& result2 : resultImplementations) {
|
||||
buildResult.errors += result2;
|
||||
}
|
||||
|
||||
|
||||
if(!buildResult.errors.empty()) {
|
||||
fileThread.join();
|
||||
return buildResult;
|
||||
}
|
||||
|
||||
if(config.target != "wasm32-wasi") {
|
||||
command += " -L/usr/local/lib";
|
||||
}
|
||||
|
|
@ -285,19 +315,21 @@ namespace Crafter {
|
|||
command += std::format(" -L{}", pcmDir.string());
|
||||
}
|
||||
|
||||
if(repack) {
|
||||
if(buildResult.repack) {
|
||||
if(config.type == CRAFTER_CONFIGURATION_TYPE_EXECUTABLE){
|
||||
if(config.target == "wasm32-wasi") {
|
||||
outputName += ".wasm";
|
||||
}
|
||||
RunClang(std::format("{}{} -o {} -fuse-ld=lld", command, files, (binDir/outputName).string()));
|
||||
buildResult.errors = RunClang(std::format("{}{} -o {} -fuse-ld=lld", command, files, (binDir/outputName).string()));
|
||||
} else if(config.type == CRAFTER_CONFIGURATION_TYPE_LIBRARY){
|
||||
std::cout << std::format("ar r {}.a {}", (binDir/fs::path(std::string("lib")+outputName)).string(), files) << std::endl;
|
||||
RunCommandIgnore(std::format("ar r {}.a {}", (binDir/fs::path(std::string("lib")+outputName)).string(), files));
|
||||
} else {
|
||||
RunClang(std::format("{}{} -shared -o {}.so -Wl,-rpath,'$ORIGIN' -fuse-ld=lld", command, files, (binDir/(std::string("lib")+outputName)).string()));
|
||||
buildResult.errors = RunClang(std::format("{}{} -shared -o {}.so -Wl,-rpath,'$ORIGIN' -fuse-ld=lld", command, files, (binDir/(std::string("lib")+outputName)).string()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return buildResult;
|
||||
}
|
||||
|
||||
Project Project::LoadFromJSON(const fs::path& path) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue