Some checks failed
demo.yaml / threaded exception handling (push) Failing after 0s
90 lines
No EOL
3 KiB
C++
90 lines
No EOL
3 KiB
C++
/*
|
|
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 version 3.0 as published by the Free Software Foundation;
|
|
|
|
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 <stdio.h>
|
|
module Crafter.Build:Command_impl;
|
|
import :Command;
|
|
import std;
|
|
|
|
|
|
namespace Crafter {
|
|
std::string RunCommand(const std::string_view cmd) {
|
|
std::array<char, 128> buffer;
|
|
std::string result;
|
|
|
|
std::string with = std::string(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
|
|
pclose(pipe);
|
|
return result;
|
|
}
|
|
|
|
void RunCommandIgnore(const std::string_view cmd) {
|
|
std::string with = std::string(cmd) + " > /dev/null 2>&1";
|
|
FILE* pipe = popen(with.c_str(), "r");
|
|
if (!pipe) throw std::runtime_error("popen() failed!");
|
|
pclose(pipe);
|
|
}
|
|
|
|
// CompileException::CompileException(std::vector<CompileError>&& errors) : errors(std::move(errors)) {
|
|
// for(CompileError error : errors) {
|
|
// message += std::format("File: {}:{}\nMessage: {}\nCode: {}", error.filename, error.line, error.message, error.code);
|
|
// }
|
|
// };
|
|
// const char* CompileException::what() const noexcept {
|
|
// return message.c_str();
|
|
// }
|
|
|
|
std::string RunClang(const std::string_view cmd) {
|
|
// std::string result = RunCommand(cmd);
|
|
// // std::vector<CompileError> errors;
|
|
|
|
// // std::regex error_regex(R"((/[^:]+\.cpp):(\d+):\d+: error: (.*)\n\s*[0-9| ]*\s*(.*))");
|
|
// // std::smatch match;
|
|
|
|
// // while (std::regex_search(result, match, error_regex)) {
|
|
// // CompileError error;
|
|
// // error.filename = match[1].str();
|
|
// // error.line = std::stoi(match[2].str());
|
|
// // error.message = match[3].str();
|
|
// // error.code = match[4].str();
|
|
// // errors.push_back(error);
|
|
// // result = match.suffix().str();
|
|
// // }
|
|
|
|
// if(result != "") {
|
|
// // if(errors.size() != 0) {
|
|
// // throw CompileException(std::move(errors));
|
|
// // } else {
|
|
// throw std::runtime_error(result);
|
|
// //}
|
|
// }
|
|
std::cout << cmd << std::endl;
|
|
return RunCommand(cmd);
|
|
}
|
|
} |