Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
CompilerStrategy.cpp
Go to the documentation of this file.
1#include "CompilerStrategy.h"
2
3#include <stdexcept>
4#include <sys/wait.h>
5
6bool executeCommand(const std::string& command) {
7 std::array<char, 128> buffer;
8 std::string result;
9
10 FILE* pipe = popen((command + " 2>&1").c_str(), "r");
11 if (!pipe) {
12 throw std::runtime_error("Error while opening command pipe for: " + command);
13 }
14
15 while (fgets(buffer.data(), buffer.size(), pipe) != nullptr) {
16 result += buffer.data();
17 }
18
19 const int status = pclose(pipe);
20 const bool ok = WIFEXITED(status) && WEXITSTATUS(status) == 0;
21
22 if (!ok) {
23 std::string message = "Command failed:\n" + command + "\n";
24 if (!result.empty()) {
25 message += "Output:\n" + result;
26 }
27 throw std::runtime_error(message);
28 }
29
30 return true;
31}
32
33bool CompilerStrategy::check_if_compile(const std::string& outputBinary) {
34 struct stat buffer;
35 if (stat(outputBinary.c_str(), &buffer) != 0) {
36 return false;
37 }
38 if (buffer.st_size == 0) {
39 return false;
40 }
41 LOG_DEBUG("Already compiled !");
42 return true;
43}
bool executeCommand(const std::string &command)
Executes a shell command and captures its output.
Declares compilation strategies and utilities for executing shell commands.
#define LOG_DEBUG(...)
Macro for logging debug messages.
Definition Logger.h:45
virtual bool check_if_compile(const std::string &outputBinary)
Checks whether a compiled binary already exists and is non-empty.