mirror of
https://github.com/ModOrganizer2/mob.git
synced 2026-07-27 14:07:05 -07:00
Remove fmt tasks switch from fmt to std::format internally.
This commit is contained in:
+7
-10
@@ -116,13 +116,13 @@ namespace mob {
|
||||
if (!task)
|
||||
return 1;
|
||||
|
||||
u8cout << "checking out pr " << pr.number << " "
|
||||
<< "in " << task->name() << "\n";
|
||||
u8cout << "checking out pr " << pr.number << " " << "in "
|
||||
<< task->name() << "\n";
|
||||
|
||||
git_wrap g(task->source_path());
|
||||
|
||||
g.fetch(task->git_url().string(),
|
||||
fmt::format("pull/{}/head", pr.number));
|
||||
std::format("pull/{}/head", pr.number));
|
||||
|
||||
g.checkout("FETCH_HEAD");
|
||||
}
|
||||
@@ -208,13 +208,10 @@ namespace mob {
|
||||
{
|
||||
nlohmann::json json;
|
||||
|
||||
constexpr auto* pattern =
|
||||
"https://api.github.com/search/issues?per_page=100&q="
|
||||
"is:pr+org:{org:}+author:{author:}+is:open+head:{branch:}";
|
||||
constexpr auto* pattern = "https://api.github.com/search/issues?per_page=100&q="
|
||||
"is:pr+org:{0:}+author:{1:}+is:open+head:{2:}";
|
||||
|
||||
const auto search_url =
|
||||
fmt::format(pattern, fmt::arg("org", org), fmt::arg("author", author),
|
||||
fmt::arg("branch", branch));
|
||||
const auto search_url = std::format(pattern, org, author, branch);
|
||||
|
||||
u8cout << "search url is " << search_url << "\n";
|
||||
|
||||
@@ -275,7 +272,7 @@ namespace mob {
|
||||
return {};
|
||||
}
|
||||
|
||||
const url u(fmt::format("https://api.github.com/repos/{}/{}/pulls/{}",
|
||||
const url u(std::format("https://api.github.com/repos/{}/{}/pulls/{}",
|
||||
task->org(), task->repo(), pr));
|
||||
|
||||
curl_downloader dl;
|
||||
|
||||
+2
-2
@@ -367,7 +367,7 @@ namespace mob {
|
||||
}
|
||||
|
||||
const auto q =
|
||||
fmt::format("prefix {} already exists, delete?", path_to_utf8(prefix));
|
||||
std::format("prefix {} already exists, delete?", path_to_utf8(prefix));
|
||||
|
||||
if (ask_yes_no(q, yn::no) != yn::yes)
|
||||
return false;
|
||||
@@ -489,7 +489,7 @@ namespace mob {
|
||||
const auto* lcp = static_cast<LANGANDCODEPAGE*>(value_pointer);
|
||||
|
||||
const auto sub_block =
|
||||
fmt::format(L"\\StringFileInfo\\{:04x}{:04x}\\FileVersion", lcp->wLanguage,
|
||||
std::format(L"\\StringFileInfo\\{:04x}{:04x}\\FileVersion", lcp->wLanguage,
|
||||
lcp->wCodePage);
|
||||
|
||||
ret = VerQueryValueW(buffer.get(), sub_block.c_str(), &value_pointer,
|
||||
|
||||
@@ -5,25 +5,6 @@
|
||||
#include "../utility.h"
|
||||
#include "conf.h"
|
||||
|
||||
namespace mob::details {
|
||||
|
||||
std::string converter<std::wstring>::convert(const std::wstring& s)
|
||||
{
|
||||
return utf16_to_utf8(s);
|
||||
}
|
||||
|
||||
std::string converter<fs::path>::convert(const fs::path& s)
|
||||
{
|
||||
return utf16_to_utf8(s.native());
|
||||
}
|
||||
|
||||
std::string converter<url>::convert(const url& u)
|
||||
{
|
||||
return u.string();
|
||||
}
|
||||
|
||||
} // namespace mob::details
|
||||
|
||||
namespace mob {
|
||||
|
||||
// timestamps are relative to this
|
||||
|
||||
+14
-52
@@ -1,45 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../utility.h"
|
||||
|
||||
// T to std::string converters
|
||||
//
|
||||
// those are kept in this namespace so they don't leak all over the place;
|
||||
// they're used directly by context::do_log() below
|
||||
|
||||
namespace mob::details {
|
||||
|
||||
class mob::url;
|
||||
|
||||
template <class T, class = void>
|
||||
struct converter {
|
||||
static const T& convert(const T& t) { return t; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct converter<std::wstring> {
|
||||
static std::string convert(const std::wstring& s);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct converter<fs::path> {
|
||||
static std::string convert(const fs::path& s);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct converter<url> {
|
||||
static std::string convert(const url& u);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct converter<T, std::enable_if_t<std::is_enum_v<T>>> {
|
||||
static std::string convert(T e)
|
||||
{
|
||||
return std::to_string(static_cast<std::underlying_type_t<T>>(e));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mob::details
|
||||
#include "./formatters.h"
|
||||
|
||||
namespace mob {
|
||||
|
||||
@@ -57,7 +19,7 @@ namespace mob {
|
||||
// in places where there is no context available, there's a global one can that
|
||||
// be retrieved with gcx() for logging
|
||||
//
|
||||
// all log functions will use fmt::format() internally, so they can be used
|
||||
// all log functions will use std::format() internally, so they can be used
|
||||
// like:
|
||||
//
|
||||
// cx.log(context::generic, "eat more {}", "potatoes");
|
||||
@@ -161,7 +123,7 @@ namespace mob {
|
||||
// logs a formatted string with the dump level
|
||||
//
|
||||
template <class... Args>
|
||||
void dump(reason r, const char* f, Args&&... args) const
|
||||
void dump(reason r, std::format_string<Args...> f, Args&&... args) const
|
||||
{
|
||||
do_log(false, r, level::dump, f, std::forward<Args>(args)...);
|
||||
}
|
||||
@@ -169,7 +131,7 @@ namespace mob {
|
||||
// logs a formatted string with the trace level
|
||||
//
|
||||
template <class... Args>
|
||||
void trace(reason r, const char* f, Args&&... args) const
|
||||
void trace(reason r, std::format_string<Args...> f, Args&&... args) const
|
||||
{
|
||||
do_log(false, r, level::trace, f, std::forward<Args>(args)...);
|
||||
}
|
||||
@@ -177,7 +139,7 @@ namespace mob {
|
||||
// logs a formatted string with the debug level
|
||||
//
|
||||
template <class... Args>
|
||||
void debug(reason r, const char* f, Args&&... args) const
|
||||
void debug(reason r, std::format_string<Args...> f, Args&&... args) const
|
||||
{
|
||||
do_log(false, r, level::debug, f, std::forward<Args>(args)...);
|
||||
}
|
||||
@@ -185,7 +147,7 @@ namespace mob {
|
||||
// logs a formatted string with the info level
|
||||
//
|
||||
template <class... Args>
|
||||
void info(reason r, const char* f, Args&&... args) const
|
||||
void info(reason r, std::format_string<Args...> f, Args&&... args) const
|
||||
{
|
||||
do_log(false, r, level::info, f, std::forward<Args>(args)...);
|
||||
}
|
||||
@@ -193,7 +155,7 @@ namespace mob {
|
||||
// logs a formatted string with the warning level
|
||||
//
|
||||
template <class... Args>
|
||||
void warning(reason r, const char* f, Args&&... args) const
|
||||
void warning(reason r, std::format_string<Args...> f, Args&&... args) const
|
||||
{
|
||||
do_log(false, r, level::warning, f, std::forward<Args>(args)...);
|
||||
}
|
||||
@@ -201,7 +163,7 @@ namespace mob {
|
||||
// logs a formatted string with the error level
|
||||
//
|
||||
template <class... Args>
|
||||
void error(reason r, const char* f, Args&&... args) const
|
||||
void error(reason r, std::format_string<Args...> f, Args&&... args) const
|
||||
{
|
||||
do_log(false, r, level::error, f, std::forward<Args>(args)...);
|
||||
}
|
||||
@@ -211,7 +173,8 @@ namespace mob {
|
||||
// tasks
|
||||
//
|
||||
template <class... Args>
|
||||
[[noreturn]] void bail_out(reason r, const char* f, Args&&... args) const
|
||||
[[noreturn]] void bail_out(reason r, std::format_string<Args...> f,
|
||||
Args&&... args) const
|
||||
{
|
||||
do_log(true, r, level::error, f, std::forward<Args>(args)...);
|
||||
}
|
||||
@@ -227,7 +190,8 @@ namespace mob {
|
||||
// bailed exception after logging
|
||||
//
|
||||
template <class... Args>
|
||||
void do_log(bool bail, reason r, level lv, const char* f, Args&&... args) const
|
||||
void do_log(bool bail, reason r, level lv, std::format_string<Args...> f,
|
||||
Args&&... args) const
|
||||
{
|
||||
// discard log if it's not enabled and it's not bailing out
|
||||
if (!bail && !enabled(lv))
|
||||
@@ -235,9 +199,7 @@ namespace mob {
|
||||
|
||||
try {
|
||||
// formatting string
|
||||
const std::string s =
|
||||
fmt::format(f, details::converter<std::decay_t<Args>>::convert(
|
||||
std::forward<Args>(args))...);
|
||||
const std::string s = std::format(f, std::forward<Args>(args)...);
|
||||
|
||||
do_log_impl(bail, r, lv, s);
|
||||
}
|
||||
@@ -253,7 +215,7 @@ namespace mob {
|
||||
// a ghetto conversion and hope it gives enough info
|
||||
std::wstring s;
|
||||
|
||||
const char* p = f;
|
||||
const char* p = f.get().data();
|
||||
while (*p) {
|
||||
s += (wchar_t)*p;
|
||||
++p;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "../utility/string.h"
|
||||
|
||||
template <>
|
||||
struct std::formatter<std::wstring, char> : std::formatter<std::string, char> {
|
||||
template <class FmtContext>
|
||||
FmtContext::iterator format(std::wstring const& s, FmtContext& ctx) const
|
||||
{
|
||||
return std::formatter<std::string, char>::format(mob::utf16_to_utf8(s), ctx);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct std::formatter<std::filesystem::path, char>
|
||||
: std::formatter<std::basic_string<std::filesystem::path::value_type>, char> {
|
||||
template <class FmtContext>
|
||||
FmtContext::iterator format(std::filesystem::path const& s, FmtContext& ctx) const
|
||||
{
|
||||
return std::formatter<std::basic_string<std::filesystem::path::value_type>,
|
||||
char>::format(s.native(), ctx);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Enum, class CharT>
|
||||
requires std::is_enum_v<Enum>
|
||||
struct std::formatter<Enum, CharT>
|
||||
: std::formatter<std::underlying_type_t<Enum>, CharT> {
|
||||
template <class FmtContext>
|
||||
FmtContext::iterator format(Enum v, FmtContext& ctx) const
|
||||
{
|
||||
return std::formatter<std::underlying_type_t<Enum>, CharT>::format(
|
||||
static_cast<std::underlying_type_t<Enum>>(v), ctx);
|
||||
}
|
||||
};
|
||||
+2
-2
@@ -10,11 +10,11 @@
|
||||
namespace mob {
|
||||
|
||||
template <class... Args>
|
||||
void ini_error(const ini_data& ini, std::size_t line, std::string_view f,
|
||||
void ini_error(const ini_data& ini, std::size_t line, std::format_string<Args...> f,
|
||||
Args&&... args)
|
||||
{
|
||||
gcx().bail_out(context::conf, "{}:{}: {}", path_to_utf8(ini.path), (line + 1),
|
||||
fmt::format(f, std::forward<Args>(args)...));
|
||||
std::format(f, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
ini_data::kv_map& ini_data::get_section(std::string_view name)
|
||||
|
||||
+1
-1
@@ -326,7 +326,7 @@ namespace mob {
|
||||
|
||||
// check known installation paths for a bunch of versions
|
||||
for (int v : {5, 6, 7, 8}) {
|
||||
const fs::path inno_dir = fmt::format("Inno Setup {}", v);
|
||||
const fs::path inno_dir = std::format("Inno Setup {}", v);
|
||||
|
||||
// check for both architectures
|
||||
for (fs::path pf : {conf().path().pf_x86(), conf().path().pf_x64()}) {
|
||||
|
||||
@@ -29,7 +29,6 @@ namespace mob {
|
||||
add_task<parallel_tasks>()
|
||||
.add_task<sevenz>()
|
||||
.add_task<zlib>()
|
||||
.add_task<fmt>()
|
||||
.add_task<gtest>()
|
||||
.add_task<libbsarch>()
|
||||
.add_task<libloot>()
|
||||
|
||||
@@ -115,3 +115,12 @@ namespace mob {
|
||||
};
|
||||
|
||||
} // namespace mob
|
||||
|
||||
template <>
|
||||
struct std::formatter<mob::url, char> : std::formatter<std::string, char> {
|
||||
template <class FmtContext>
|
||||
FmtContext::iterator format(mob::url const& u, FmtContext& ctx) const
|
||||
{
|
||||
return std::formatter<std::string, char>::format(u.string(), ctx);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
#include "pch.h"
|
||||
#include <fmt/format.cc>
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <atomic>
|
||||
#include <charconv>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
@@ -69,7 +70,6 @@
|
||||
|
||||
#include <clipp.h>
|
||||
#include <curl/curl.h>
|
||||
#include <fmt/format.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#pragma warning(pop)
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
#include "pch.h"
|
||||
#include "tasks.h"
|
||||
|
||||
namespace mob::tasks {
|
||||
|
||||
namespace {
|
||||
|
||||
url source_url()
|
||||
{
|
||||
return "https://github.com/fmtlib/fmt/releases/download/" + fmt::version() +
|
||||
"/fmt-" + fmt::version() + ".zip";
|
||||
}
|
||||
|
||||
cmake create_cmake_tool(const fs::path& src_path,
|
||||
cmake::ops o = cmake::ops::generate)
|
||||
{
|
||||
return std::move(cmake(o)
|
||||
.generator(cmake::vs)
|
||||
.root(src_path)
|
||||
.prefix(src_path / "build")
|
||||
.def("FMT_TEST", "OFF")
|
||||
.def("FMT_DOC", "OFF"));
|
||||
}
|
||||
|
||||
fs::path solution_path()
|
||||
{
|
||||
const auto build_path = create_cmake_tool(fmt::source_path()).build_path();
|
||||
|
||||
return build_path / "INSTALL.vcxproj";
|
||||
}
|
||||
|
||||
msbuild create_msbuild_tool(msbuild::ops o = msbuild::ops::build)
|
||||
{
|
||||
return std::move(msbuild(o).solution(solution_path()));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
fmt::fmt() : basic_task("fmt") {}
|
||||
|
||||
std::string fmt::version()
|
||||
{
|
||||
return conf().version().get("fmt");
|
||||
}
|
||||
|
||||
bool fmt::prebuilt()
|
||||
{
|
||||
// no prebuilts available
|
||||
return false;
|
||||
}
|
||||
|
||||
fs::path fmt::source_path()
|
||||
{
|
||||
return conf().path().build() / ("fmt-" + version());
|
||||
}
|
||||
|
||||
void fmt::do_clean(clean c)
|
||||
{
|
||||
// delete download
|
||||
if (is_set(c, clean::redownload))
|
||||
run_tool(downloader(source_url(), downloader::clean));
|
||||
|
||||
// delete the whole directory
|
||||
if (is_set(c, clean::reextract)) {
|
||||
cx().trace(context::reextract, "deleting {}", source_path());
|
||||
op::delete_directory(cx(), source_path(), op::optional);
|
||||
|
||||
// no need to do anything else
|
||||
return;
|
||||
}
|
||||
|
||||
// cmake clean
|
||||
if (is_set(c, clean::reconfigure))
|
||||
run_tool(create_cmake_tool(source_path(), cmake::clean));
|
||||
|
||||
// msbuild clean
|
||||
if (is_set(c, clean::rebuild))
|
||||
run_tool(create_msbuild_tool(msbuild::clean));
|
||||
}
|
||||
|
||||
void fmt::do_fetch()
|
||||
{
|
||||
const auto file = run_tool(downloader(source_url()));
|
||||
|
||||
run_tool(extractor().file(file).output(source_path()));
|
||||
}
|
||||
|
||||
void fmt::do_build_and_install()
|
||||
{
|
||||
run_tool(create_cmake_tool(source_path()));
|
||||
run_tool(create_msbuild_tool());
|
||||
}
|
||||
|
||||
} // namespace mob::tasks
|
||||
@@ -211,7 +211,6 @@ namespace mob::tasks {
|
||||
.def("DEPENDENCIES_DIR", conf().path().build())
|
||||
.def("BOOST_ROOT", boost::source_path())
|
||||
.def("BOOST_LIBRARYDIR", boost::lib_path(arch::x64))
|
||||
.def("FMT_ROOT", fmt::source_path())
|
||||
.def("SPDLOG_ROOT", spdlog::source_path())
|
||||
.def("LOOT_PATH", libloot::source_path())
|
||||
.def("LZ4_ROOT", lz4::source_path())
|
||||
|
||||
@@ -90,20 +90,6 @@ namespace mob::tasks {
|
||||
void do_fetch() override;
|
||||
};
|
||||
|
||||
class fmt : public basic_task<fmt> {
|
||||
public:
|
||||
fmt();
|
||||
|
||||
static std::string version();
|
||||
static bool prebuilt();
|
||||
static fs::path source_path();
|
||||
|
||||
protected:
|
||||
void do_clean(clean c) override;
|
||||
void do_fetch() override;
|
||||
void do_build_and_install() override;
|
||||
};
|
||||
|
||||
class gtest : public basic_task<gtest> {
|
||||
public:
|
||||
gtest();
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace mob::tasks {
|
||||
|
||||
if (dir_cs.size() != 2) {
|
||||
warnings_.push_back(
|
||||
::fmt::format("bad directory name '{}'; skipping", dir_name));
|
||||
::std::format("bad directory name '{}'; skipping", dir_name));
|
||||
|
||||
return {};
|
||||
}
|
||||
@@ -143,7 +143,7 @@ namespace mob::tasks {
|
||||
const auto project_name = trim_copy(dir_cs[1]);
|
||||
if (project_name.empty()) {
|
||||
warnings_.push_back(
|
||||
::fmt::format("bad directory name '{}', skipping", dir_name));
|
||||
::std::format("bad directory name '{}', skipping", dir_name));
|
||||
|
||||
return {};
|
||||
}
|
||||
@@ -162,7 +162,7 @@ namespace mob::tasks {
|
||||
// there should only be .ts files in there
|
||||
if (path.extension() != ".ts") {
|
||||
warnings_.push_back(
|
||||
::fmt::format("{} is not a .ts file", path_to_utf8(path)));
|
||||
::std::format("{} is not a .ts file", path_to_utf8(path)));
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -204,7 +204,7 @@ namespace mob::tasks {
|
||||
if (!warned_.contains(gamebryo_ts)) {
|
||||
warned_.insert(gamebryo_ts);
|
||||
|
||||
warnings_.push_back(::fmt::format(
|
||||
warnings_.push_back(::std::format(
|
||||
"{} is a gamebryo plugin but there is no '{}'; the "
|
||||
".qm file will be missing some translations (will "
|
||||
"only warn once)",
|
||||
@@ -223,7 +223,7 @@ namespace mob::tasks {
|
||||
|
||||
if (!t) {
|
||||
warnings_.push_back(
|
||||
::fmt::format("directory '{}' was parsed as project '{}', but there's "
|
||||
::std::format("directory '{}' was parsed as project '{}', but there's "
|
||||
"no task with this name",
|
||||
dir, project));
|
||||
|
||||
|
||||
+10
-14
@@ -27,14 +27,11 @@ namespace mob::details {
|
||||
// returns a github url for the given org and git file
|
||||
//
|
||||
std::string make_url(const std::string& org, const std::string& git_file,
|
||||
const std::string& url_pattern)
|
||||
std::optional<git_url_pattern_format_string> url_pattern)
|
||||
{
|
||||
const std::string default_github_url_pattern = "git@github.com:{}/{}";
|
||||
|
||||
const std::string pattern =
|
||||
url_pattern.empty() ? default_github_url_pattern : url_pattern;
|
||||
|
||||
return fmt::format(pattern, org, git_file);
|
||||
return std::format(
|
||||
url_pattern.value_or(git_url_pattern_format_string{"git@github.com:{}/{}"}),
|
||||
org, git_file);
|
||||
}
|
||||
|
||||
// creates a basic git process, used by all the functions below
|
||||
@@ -412,14 +409,13 @@ namespace mob {
|
||||
return (run(details::has_remote(root_, name)) == 0);
|
||||
}
|
||||
|
||||
void git_wrap::add_remote(const std::string& remote_name,
|
||||
const std::string& username, const std::string& key,
|
||||
bool push_default, const std::string& url_pattern,
|
||||
const std::string& opt_git_file)
|
||||
void git_wrap::add_remote(
|
||||
const std::string& remote_name, const std::string& username,
|
||||
const std::string& key, bool push_default,
|
||||
std::optional<details::git_url_pattern_format_string> url_pattern,
|
||||
std::optional<std::string> opt_git_file)
|
||||
{
|
||||
auto gf = opt_git_file;
|
||||
if (gf.empty())
|
||||
gf = git_file();
|
||||
auto gf = opt_git_file.value_or(git_file());
|
||||
|
||||
if (!has_remote(remote_name)) {
|
||||
run(details::add_remote(root_, remote_name,
|
||||
|
||||
+10
-4
@@ -2,6 +2,11 @@
|
||||
|
||||
namespace mob {
|
||||
|
||||
namespace details {
|
||||
using git_url_pattern_format_string =
|
||||
std::format_string<std::string const&, std::string const&>;
|
||||
}
|
||||
|
||||
// wrapper around git commands used by the git tool below or various `mob git`
|
||||
// commands
|
||||
//
|
||||
@@ -102,10 +107,11 @@ namespace mob {
|
||||
// set_origin_and_upstream_remotes() because the "origin"
|
||||
// remote might not exist at that point
|
||||
//
|
||||
void add_remote(const std::string& remote_name, const std::string& org,
|
||||
const std::string& key, bool push_default,
|
||||
const std::string& url_pattern = {},
|
||||
const std::string& git_file = {});
|
||||
void add_remote(
|
||||
const std::string& remote_name, const std::string& org,
|
||||
const std::string& key, bool push_default,
|
||||
std::optional<details::git_url_pattern_format_string> url_pattern = {},
|
||||
std::optional<std::string> git_file = {});
|
||||
|
||||
// renames remote `from` to `to`
|
||||
//
|
||||
|
||||
Vendored
-1119
File diff suppressed because it is too large
Load Diff
Vendored
-568
File diff suppressed because it is too large
Load Diff
Vendored
-595
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user