}
}
-std::string
-format_argv_for_logging(const char* const* argv)
-{
- std::string result;
- for (size_t i = 0; argv[i]; ++i) {
- if (i != 0) {
- result += ' ';
- }
- std::string arg(argv[i]);
- if (arg.empty() || arg.find(' ') != std::string::npos) {
- arg = FMT("\"{}\"", arg);
- }
- result += arg;
- }
- return result;
-}
-
void
ensure_dir_exists(std::string_view dir)
{
// Like create_dir but throws Fatal on error.
void ensure_dir_exists(std::string_view dir);
-// Format `argv` as a simple string for logging purposes. That is, the result is
-// not intended to be machine parsable. `argv` must be terminated by a nullptr.
-std::string format_argv_for_logging(const char* const* argv);
-
// Return the file extension (including the dot) as a view into `path`. If
// `path` has no file extension, an empty string_view is returned.
std::string_view get_extension(std::string_view path);
});
}
- LOG("Command line: {}", Util::format_argv_for_logging(argv));
+ LOG("Command line: {}", util::format_argv_for_logging(argv));
LOG("Hostname: {}", Util::get_hostname());
LOG("Working directory: {}", ctx.actual_cwd);
if (ctx.apparent_cwd != ctx.actual_cwd) {
saved_temp_dir = ctx.config.temporary_dir();
saved_orig_args = std::move(ctx.orig_args);
auto execv_argv = saved_orig_args.to_argv();
- LOG("Executing {}", Util::format_argv_for_logging(execv_argv.data()));
+ LOG("Executing {}", util::format_argv_for_logging(execv_argv.data()));
// Execute the original command below after ctx and finalizer have been
// destructed.
}
#include <fmtmacros.hpp>
#include <util/file.hpp>
#include <util/path.hpp>
+#include <util/string.hpp>
#include <vector>
int
execute(Context& ctx, const char* const* argv, Fd&& fd_out, Fd&& fd_err)
{
- LOG("Executing {}", Util::format_argv_for_logging(argv));
+ LOG("Executing {}", util::format_argv_for_logging(argv));
return win32execute(argv[0],
argv,
int
execute(Context& ctx, const char* const* argv, Fd&& fd_out, Fd&& fd_err)
{
- LOG("Executing {}", Util::format_argv_for_logging(argv));
+ LOG("Executing {}", util::format_argv_for_logging(argv));
{
SignalHandlerBlocker signal_handler_blocker;
auto argv = args.to_argv();
LOG("Executing compiler check command {}",
- Util::format_argv_for_logging(argv.data()));
+ util::format_argv_for_logging(argv.data()));
#ifdef _WIN32
PROCESS_INFORMATION pi;
namespace util {
+std::string
+format_argv_for_logging(const char* const* argv)
+{
+ std::string result;
+ for (size_t i = 0; argv[i]; ++i) {
+ if (i != 0) {
+ result += ' ';
+ }
+ std::string arg(argv[i]);
+ if (arg.empty() || arg.find(' ') != std::string::npos) {
+ arg = FMT("\"{}\"", arg);
+ }
+ result += arg;
+ }
+ return result;
+}
+
std::string
format_base16(nonstd::span<const uint8_t> data)
{
// Return true if `suffix` is a suffix of `string`.
bool ends_with(std::string_view string, std::string_view suffix);
+// Format `argv` as a simple string for logging purposes. That is, the result is
+// not intended to be machine parsable. `argv` must be terminated by a nullptr.
+std::string format_argv_for_logging(const char* const* argv);
+
// Format a hexadecimal string representing `data`. The returned string will be
// `2 * data.size()` long.
std::string format_base16(nonstd::span<const uint8_t> data);
doctest::Contains("Failed to create directory create/dir/file:"));
}
-TEST_CASE("Util::format_argv_for_logging")
-{
- const char* argv_0[] = {nullptr};
- CHECK(Util::format_argv_for_logging(argv_0) == "");
-
- const char* argv_2[] = {"foo", "bar", nullptr};
- CHECK(Util::format_argv_for_logging(argv_2) == "foo bar");
-}
-
TEST_CASE("Util::get_extension")
{
CHECK(Util::get_extension("") == "");
TEST_SUITE_BEGIN("util");
+TEST_CASE("util::format_argv_for_logging")
+{
+ const char* argv_0[] = {nullptr};
+ CHECK(util::format_argv_for_logging(argv_0) == "");
+
+ const char* argv_2[] = {"foo", "bar", nullptr};
+ CHECK(util::format_argv_for_logging(argv_2) == "foo bar");
+}
+
TEST_CASE("util::format_base16")
{
uint8_t none[] = "";