From a36beab2acbab9a58a96755724d28e03349ca55b Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Tue, 9 Sep 2025 18:10:54 +0200 Subject: [PATCH] update --- Crafter.Build-Bounce.cppm | 60 ++++++++++++++++++++++++++++++++++++ Crafter.Build-ModuleFile.cpp | 8 ++--- Crafter.Build-Project.cpp | 8 ++--- Crafter.Build-SourceFile.cpp | 2 +- Crafter.Build.cppm | 1 + project.json | 2 +- 6 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 Crafter.Build-Bounce.cppm diff --git a/Crafter.Build-Bounce.cppm b/Crafter.Build-Bounce.cppm new file mode 100644 index 0000000..c334f36 --- /dev/null +++ b/Crafter.Build-Bounce.cppm @@ -0,0 +1,60 @@ +/* +Crafter.Build +Copyright (C) 2025 Catcrafts® +Catcrafts.net + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +module; +#include +#include +#include +#include +#include +#include +export module Crafter.Build:Bounce; + +export void BounceCommand(const std::string& cmd) { + // std::array buffer; + // std::string result; + + // std::string with = cmd + " 2>&1"; + // // Open pipe to file + // FILE* pipe = popen(with.c_str(), "r"); + // if (!pipe) throw std::runtime_error("popen() failed!"); + + // // Read till end of process: + // while (fgets(buffer.data(), buffer.size(), pipe) != nullptr) { + // result += buffer.data(); + // } + + // // Close pipe + // auto returnCode = pclose(pipe); + // if (returnCode != 0) { + // // Optional: handle non-zero exit status + // } + + + // std::cout << result; + system(cmd.c_str()); +} + +export void BounceCommandIgnore(const std::string& cmd) { + std::string with = cmd + " > /dev/null 2>&1"; + FILE* pipe = popen(with.c_str(), "r"); + if (!pipe) throw std::runtime_error("popen() failed!"); + pclose(pipe); +} \ No newline at end of file diff --git a/Crafter.Build-ModuleFile.cpp b/Crafter.Build-ModuleFile.cpp index 01f6fbe..9bc8b76 100644 --- a/Crafter.Build-ModuleFile.cpp +++ b/Crafter.Build-ModuleFile.cpp @@ -98,7 +98,7 @@ void ModulePartition::Compile(std::string clangDir, const Configuration& config, if(config.verbose) { std::cout << command << std::endl; } - system(command.c_str()); + BounceCommand(command.c_str()); } *compiled = true; compiled->notify_all(); @@ -112,7 +112,7 @@ void ModulePartition::CompileSource(std::string clangDir, const Configuration& c if(config.verbose) { std::cout << command << std::endl; } - system(command.c_str()); + BounceCommand(command.c_str()); } 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) { @@ -187,7 +187,7 @@ void Module::Compile(std::string clangDir, const Configuration& config, fs::path if(config.verbose) { std::cout << command << std::endl; } - system(command.c_str()); + BounceCommand(command.c_str()); } std::vector threads2; @@ -203,7 +203,7 @@ void Module::Compile(std::string clangDir, const Configuration& config, fs::path if(config.verbose) { std::cout << command << std::endl; } - system(command.c_str()); + BounceCommand(command.c_str()); }); for(std::thread& thread : threads2){ diff --git a/Crafter.Build-Project.cpp b/Crafter.Build-Project.cpp index a7902ef..d298bac 100644 --- a/Crafter.Build-Project.cpp +++ b/Crafter.Build-Project.cpp @@ -239,7 +239,7 @@ void Project::Build(Configuration& config, fs::path outputDir, fs::path binDir) 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](){ - system(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()); + 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()); }); } } @@ -257,11 +257,11 @@ void Project::Build(Configuration& config, fs::path outputDir, fs::path binDir) if(config.verbose) { std::cout << command << std::endl; } - system(command.c_str()); + BounceCommand(command.c_str()); } else if(config.type == "library"){ - system(std::format("ar r {}.a {}", (outputDir/fs::path("lib"+name)).generic_string(), files).c_str()); + BounceCommandIgnore(std::format("ar r {}.a {}", (outputDir/fs::path("lib"+name)).generic_string(), files).c_str()); } else if(config.type == "shared-library"){ - system(std::format("ar r {}.so {}", (outputDir/fs::path("lib"+name)).generic_string(), files).c_str()); + BounceCommandIgnore(std::format("ar r {}.so {}", (outputDir/fs::path("lib"+name)).generic_string(), files).c_str()); } for(const fs::path& additionalFile : config.additionalFiles){ diff --git a/Crafter.Build-SourceFile.cpp b/Crafter.Build-SourceFile.cpp index 7f32cdf..a464c42 100644 --- a/Crafter.Build-SourceFile.cpp +++ b/Crafter.Build-SourceFile.cpp @@ -43,7 +43,7 @@ void Source::GetSourceFiles(std::string clangDir, const Configuration& config, f if(config.verbose) { std::cout << command << std::endl; } - system(command.c_str()); + BounceCommand(command.c_str()); }); } } diff --git a/Crafter.Build.cppm b/Crafter.Build.cppm index d6ecefd..b4d31a6 100644 --- a/Crafter.Build.cppm +++ b/Crafter.Build.cppm @@ -25,3 +25,4 @@ export import :Configuration; export import :ModuleFile; export import :SourceFile; export import :Shader; +export import :Bounce; diff --git a/project.json b/project.json index 3375bbf..2062cb5 100644 --- a/project.json +++ b/project.json @@ -5,7 +5,7 @@ "name": "base", "standard": "c++26", "source_files": ["Crafter.Build-Configuration", "Crafter.Build-Project", "Crafter.Build-Dependency", "Crafter.Build-ModuleFile", "Crafter.Build-Shader", "Crafter.Build-SourceFile"], - "module_files": ["Crafter.Build-Dependency", "Crafter.Build-Configuration", "Crafter.Build-Project", "Crafter.Build-Shader", "Crafter.Build", "Crafter.Build-ModuleFile", "Crafter.Build-SourceFile"], + "module_files": ["Crafter.Build-Dependency", "Crafter.Build-Configuration", "Crafter.Build-Project", "Crafter.Build-Shader", "Crafter.Build", "Crafter.Build-ModuleFile", "Crafter.Build-SourceFile", "Crafter.Build-Bounce"], "build_dir": "build", "output_dir": "bin", "libs": ["vulkan", "MachineIndependent", "OSDependent", "GenericCodeGen", "glslang", "glslang-default-resource-limits", "SPIRV", "SPVRemapper", "tbb"]