Skip to content

Commit bbc8e22

Browse files
committed
Core: Remove boost iostreams dependency
(cherry picked from commit dbe8d1f11e844dc73c9ce971421e1d71c41bea3d)
1 parent 8719b30 commit bbc8e22

File tree

2 files changed

+14
-59
lines changed

2 files changed

+14
-59
lines changed

dep/boost/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ find_package(Boost ${BOOST_REQUIRED_VERSION}
4646
system
4747
filesystem
4848
program_options
49-
iostreams
5049
regex
5150
locale
5251
CONFIG

src/common/Utilities/StartProcess.cpp

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,61 +19,19 @@
1919
#include "Errors.h"
2020
#include "Log.h"
2121
#include "Optional.h"
22-
23-
#include <boost/algorithm/string/join.hpp>
24-
#include <boost/iostreams/copy.hpp>
2522
#include <boost/process/args.hpp>
2623
#include <boost/process/child.hpp>
2724
#include <boost/process/env.hpp>
2825
#include <boost/process/exe.hpp>
2926
#include <boost/process/io.hpp>
3027
#include <boost/process/pipe.hpp>
3128
#include <boost/process/search_path.hpp>
29+
#include <fmt/ranges.h>
3230

3331
using namespace boost::process;
34-
using namespace boost::iostreams;
3532

3633
namespace Trinity
3734
{
38-
39-
template<typename T>
40-
class TCLogSink
41-
{
42-
T callback_;
43-
44-
public:
45-
typedef char char_type;
46-
typedef sink_tag category;
47-
48-
// Requires a callback type which has a void(std::string) signature
49-
TCLogSink(T callback)
50-
: callback_(std::move(callback)) { }
51-
52-
std::streamsize write(char const* str, std::streamsize size)
53-
{
54-
std::string_view consoleStr(str, size);
55-
size_t lineEnd = consoleStr.find_first_of("\r\n");
56-
std::streamsize processedCharacters = size;
57-
if (lineEnd != std::string_view::npos)
58-
{
59-
consoleStr = consoleStr.substr(0, lineEnd);
60-
processedCharacters = lineEnd + 1;
61-
}
62-
63-
if (!consoleStr.empty())
64-
callback_(consoleStr);
65-
66-
return processedCharacters;
67-
}
68-
};
69-
70-
template<typename T>
71-
auto MakeTCLogSink(T&& callback)
72-
-> TCLogSink<typename std::decay<T>::type>
73-
{
74-
return { std::forward<T>(callback) };
75-
}
76-
7735
template<typename T>
7836
static int CreateChildProcess(T waiter, std::string const& executable,
7937
std::vector<std::string> const& argsVector,
@@ -101,15 +59,11 @@ static int CreateChildProcess(T waiter, std::string const& executable,
10159
if (!secure)
10260
{
10361
TC_LOG_TRACE(logger, "Starting process \"{}\" with arguments: \"{}\".",
104-
executable, boost::algorithm::join(argsVector, " "));
62+
executable, fmt::join(argsVector, " "));
10563
}
10664

10765
// prepare file with only read permission (boost process opens with read_write)
108-
std::shared_ptr<FILE> inputFile(!input.empty() ? fopen(input.c_str(), "rb") : nullptr, [](FILE* ptr)
109-
{
110-
if (ptr != nullptr)
111-
fclose(ptr);
112-
});
66+
auto inputFile = std::shared_ptr<FILE>(!input.empty() ? fopen(input.c_str(), "rb") : nullptr, [](FILE* f) { if (f) fclose(f); });
11367

11468
// Start the child process
11569
child c = [&]()
@@ -140,18 +94,20 @@ static int CreateChildProcess(T waiter, std::string const& executable,
14094
}
14195
}();
14296

143-
auto outInfo = MakeTCLogSink([&](std::string_view msg)
97+
std::string line;
98+
while (std::getline(outStream, line, '\n'))
14499
{
145-
TC_LOG_INFO(logger, "{}", msg);
146-
});
100+
std::erase(line, '\r');
101+
if (!line.empty())
102+
TC_LOG_INFO(logger, "{}", line);
103+
}
147104

148-
auto outError = MakeTCLogSink([&](std::string_view msg)
105+
while (std::getline(errStream, line, '\n'))
149106
{
150-
TC_LOG_ERROR(logger, "{}", msg);
151-
});
152-
153-
copy(outStream, outInfo);
154-
copy(errStream, outError);
107+
std::erase(line, '\r');
108+
if (!line.empty())
109+
TC_LOG_ERROR(logger, "{}", line);
110+
}
155111

156112
// Call the waiter in the current scope to prevent
157113
// the streams from closing too early on leaving the scope.

0 commit comments

Comments
 (0)