Skip to content

Commit

Permalink
oops, forgot to initialize the context
Browse files Browse the repository at this point in the history
also, build on msvc & gcc 6
  • Loading branch information
strega-nil committed Oct 14, 2021
1 parent 5596273 commit 1f34bef
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 57 deletions.
1 change: 1 addition & 0 deletions include/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <vcpkg/base/system_headers.h>

#include <vcpkg/base/files.h>
#include <vcpkg/base/format.h>
#include <vcpkg/base/pragmas.h>

#if defined(_WIN32)
Expand Down
26 changes: 15 additions & 11 deletions include/vcpkg/base/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,20 @@ namespace vcpkg
};
}

template<>
struct fmt::formatter<vcpkg::Path>
namespace fmt
{
constexpr auto parse(fmt::format_parse_context& ctx) -> decltype(ctx.begin())
template<>
struct formatter<vcpkg::Path>
{
return vcpkg::basic_format_parse_impl(ctx);
}
template<class FormatContext>
auto format(const vcpkg::Path& path, FormatContext& ctx) -> decltype(ctx.out())
{
return format_to(ctx.out(), "{}", path.native());
}
};
constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin())
{
return vcpkg::basic_format_parse_impl(ctx);
}
template<class FormatContext>
auto format(const vcpkg::Path& path, FormatContext& ctx) -> decltype(ctx.out())
{
return format_to(ctx.out(), "{}", path.native());
}
};

}
30 changes: 19 additions & 11 deletions include/vcpkg/base/format.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#pragma once

#include <vcpkg/base/lineinfo.h>
#include <vcpkg/base/pragmas.h>

VCPKG_MSVC_WARNING(push)
VCPKG_MSVC_WARNING(disable : 6239)
#include <fmt/format.h>
VCPKG_MSVC_WARNING(pop)

namespace vcpkg
{
Expand All @@ -17,16 +21,20 @@ namespace vcpkg
}
}

template<>
struct fmt::formatter<vcpkg::LineInfo>
namespace fmt
{
constexpr auto parse(fmt::format_parse_context& ctx) -> decltype(ctx.begin())
template<>
struct formatter<vcpkg::LineInfo>
{
return vcpkg::basic_format_parse_impl(ctx);
}
template<class FormatContext>
auto format(const vcpkg::LineInfo& li, FormatContext& ctx) -> decltype(ctx.out())
{
return format_to(ctx.out(), "{}({})", li.file_name, li.line_number);
}
};
constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin())
{
return vcpkg::basic_format_parse_impl(ctx);
}
template<class FormatContext>
auto format(const vcpkg::LineInfo& li, FormatContext& ctx) -> decltype(ctx.out())
{
return format_to(ctx.out(), "{}({})", li.file_name, li.line_number);
}
};

}
20 changes: 12 additions & 8 deletions include/vcpkg/base/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,17 @@ namespace vcpkg::msg
REGISTER_MESSAGE(NAME)
}

template<>
struct fmt::formatter<vcpkg::msg::LocalizedString> : fmt::formatter<vcpkg::StringView>
namespace fmt
{
// parse is inherited from formatter<StringView>
template<class FormatContext>
auto format(const vcpkg::msg::LocalizedString& s, FormatContext& ctx)
template<>
struct formatter<vcpkg::msg::LocalizedString> : formatter<vcpkg::StringView>
{
return fmt::formatter<vcpkg::StringView>::format(s.data(), ctx);
}
};
// parse is inherited from formatter<StringView>
template<class FormatContext>
auto format(const vcpkg::msg::LocalizedString& s, FormatContext& ctx)
{
return formatter<vcpkg::StringView>::format(s.data(), ctx);
}
};

}
18 changes: 11 additions & 7 deletions include/vcpkg/base/stringliteral.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ namespace vcpkg
};
}

template<>
struct fmt::formatter<vcpkg::StringLiteral> : fmt::formatter<vcpkg::ZStringView>
namespace fmt
{
template<class FormatContext>
auto format(const vcpkg::ZStringView& s, FormatContext& ctx) -> decltype(ctx.out())
template<>
struct formatter<vcpkg::StringLiteral> : formatter<vcpkg::ZStringView>
{
return fmt::formatter<vcpkg::StringView>::format(s, ctx);
}
};
template<class FormatContext>
auto format(const vcpkg::ZStringView& s, FormatContext& ctx) -> decltype(ctx.out())
{
return formatter<vcpkg::StringView>::format(s, ctx);
}
};

}
20 changes: 12 additions & 8 deletions include/vcpkg/base/stringview.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ namespace vcpkg
bool operator>=(StringView lhs, StringView rhs) noexcept;
}

template<>
struct fmt::formatter<vcpkg::StringView> : fmt::formatter<fmt::string_view>
namespace fmt
{
// parse is inherited from formatter<string_view>.
template<class FormatContext>
auto format(vcpkg::StringView sv, FormatContext& ctx)
template<>
struct formatter<vcpkg::StringView> : formatter<string_view>
{
return fmt::formatter<fmt::string_view>::format(fmt::string_view(sv.data(), sv.size()), ctx);
}
};
// parse is inherited from formatter<string_view>.
template<class FormatContext>
auto format(vcpkg::StringView sv, FormatContext& ctx)
{
return formatter<string_view>::format(string_view(sv.data(), sv.size()), ctx);
}
};

}
18 changes: 11 additions & 7 deletions include/vcpkg/base/zstringview.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ namespace vcpkg
inline bool operator==(ZStringView l, const char* r) { return strcmp(l.c_str(), r) == 0; }
}

template<>
struct fmt::formatter<vcpkg::ZStringView> : fmt::formatter<vcpkg::StringView>
namespace fmt
{
template<class FormatContext>
auto format(const vcpkg::ZStringView& s, FormatContext& ctx) -> decltype(ctx.out())
template<>
struct formatter<vcpkg::ZStringView> : formatter<vcpkg::StringView>
{
return fmt::formatter<vcpkg::StringView>::format(s, ctx);
}
};
template<class FormatContext>
auto format(const vcpkg::ZStringView& s, FormatContext& ctx) -> decltype(ctx.out())
{
return formatter<vcpkg::StringView>::format(s, ctx);
}
};

}
10 changes: 10 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"NoLocalizationForMessages": "No localization for the following messages:",
"VcpkgDebugTimeTaken": "[DEBUG] Exiting after %s (%d us)\n",
"_VcpkgDebugTimeTaken.comment": "{LOCKED}",
"VcpkgHasCrashed": "vcpkg.exe has crashed.\nPlease send an email to:\n {email}\ncontaining a brief summary of what you were trying to do and the following data blob:\n\nVersion={vcpkg_version}\nEXCEPTION='{error}'\nCMD=",
"VcpkgHasCrashedArgument": "{value}|",
"_VcpkgHasCrashedArgument.comment": "{LOCKED}",
"VcpkgInvalidCommand": "invalid command: {value}",
"VcpkgSendMetricsButDisabled": "Warning: passed --sendmetrics, but metrics are disabled."
}
1 change: 1 addition & 0 deletions src/vcpkg-test/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ TEST_CASE ("get_available_basic_commands works", "[commands]")
"version",
"x-download",
"x-init-registry",
"x-generate-default-message-map",
#if defined(_WIN32)
"x-upload-metrics",
#endif // defined(_WIN32)
Expand Down
20 changes: 20 additions & 0 deletions src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ int main(const int argc, const char* const* const argv)
if (argc == 0) std::abort();

auto& fs = get_real_filesystem();
{
auto locale = get_environment_variable("VCPKG_LOCALE");
auto locale_base = get_environment_variable("VCPKG_LOCALE_BASE");

if (locale.has_value() && locale_base.has_value())
{
msg::threadunsafe_initialize_context(fs, *locale.get(), *locale_base.get());
}
else if (locale.has_value() || locale_base.has_value())
{
msg::write_unlocalized_text_to_stdout(
Color::error, "If either VCPKG_LOCALE or VCPKG_LOCALE_BASE is initialized, then both must be.\n");
Checks::exit_fail(VCPKG_LINE_INFO);
}
else
{
msg::threadunsafe_initialize_context();
}
}

*(LockGuardPtr<ElapsedTimer>(GlobalState::timer)) = ElapsedTimer::create_started();

#if defined(_WIN32)
Expand Down
10 changes: 5 additions & 5 deletions src/vcpkg/base/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ namespace vcpkg::msg
if (c != Color::none)
{
CONSOLE_SCREEN_BUFFER_INFO console_screen_buffer_info{};
::GetConsoleScreenBufferInfo(handle, &console_screen_buffer_info);
::GetConsoleScreenBufferInfo(stdout_handle, &console_screen_buffer_info);
original_color = console_screen_buffer_info.wAttributes;
::SetConsoleTextAttribute(handle, static_cast<WORD>(c) | (original_color & 0xF0));
::SetConsoleTextAttribute(stdout_handle, static_cast<WORD>(c) | (original_color & 0xF0));
}

auto as_wstr = Strings::to_utf16(sv);
Expand All @@ -57,14 +57,14 @@ namespace vcpkg::msg
while (size != 0)
{
DWORD written = 0;
check_write(::WriteConsoleW(handle, pointer, size_to_write(size), &written, nullptr));
check_write(::WriteConsoleW(stdout_handle, pointer, size_to_write(size), &written, nullptr));
pointer += written;
size -= written;
}

if (c != Color::none)
{
::SetConsoleTextAttribute(handle, original_color);
::SetConsoleTextAttribute(stdout_handle, original_color);
}
}
else
Expand All @@ -75,7 +75,7 @@ namespace vcpkg::msg
while (size != 0)
{
DWORD written = 0;
check_write(::WriteFile(handle, pointer, size_to_write(size), &written, nullptr));
check_write(::WriteFile(stdout_handle, pointer, size_to_write(size), &written, nullptr));
pointer += written;
size -= written;
}
Expand Down
1 change: 1 addition & 0 deletions src/vcpkg/base/system.process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <vcpkg/base/strings.h>
#include <vcpkg/base/system.debug.h>
#include <vcpkg/base/system.h>
#include <vcpkg/base/system.print.h>
#include <vcpkg/base/system.process.h>
#include <vcpkg/base/util.h>

Expand Down
3 changes: 3 additions & 0 deletions src/vcpkg/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <vcpkg/commands.env.h>
#include <vcpkg/commands.fetch.h>
#include <vcpkg/commands.format-manifest.h>
#include <vcpkg/commands.generate-message-map.h>
#include <vcpkg/commands.h>
#include <vcpkg/commands.hash.h>
#include <vcpkg/commands.info.h>
Expand Down Expand Up @@ -46,6 +47,7 @@ namespace vcpkg::Commands
static const Contact::ContactCommand contact{};
static const InitRegistry::InitRegistryCommand init_registry{};
static const X_Download::XDownloadCommand xdownload{};
static const GenerateDefaultMessageMapCommand generate_message_map{};
#if defined(_WIN32)
static const UploadMetrics::UploadMetricsCommand upload_metrics{};
#endif // defined(_WIN32)
Expand All @@ -55,6 +57,7 @@ namespace vcpkg::Commands
{"contact", &contact},
{"x-init-registry", &init_registry},
{"x-download", &xdownload},
{"x-generate-default-message-map", &generate_message_map},

#if defined(_WIN32)
{"x-upload-metrics", &upload_metrics},
Expand Down

0 comments on commit 1f34bef

Please sign in to comment.