Import fmt-7.1.3, an alternative formatting library for C and C++

Port by Ashton Fagg (maintainer)

pkg/DESCR:
fmt is an open-source formatting library providing a fast and safe
alternative to C stdio and C++ iostreams.

Features include:

- Simple format API with positional arguments for localization Format

- string syntax similar to Python's format

- Safe printf implementation including POSIX extensions for positional
 arguments

- Fast IEEE 754 floating-point formatter with correct rounding,
  shortness and round-trip guarantees
This commit is contained in:
jca 2021-01-02 21:51:19 +00:00
parent 6ad89e9f8e
commit 6ab3f008f0
7 changed files with 147 additions and 0 deletions

26
devel/fmt/Makefile Normal file
View File

@ -0,0 +1,26 @@
# $OpenBSD: Makefile,v 1.1.1.1 2021/01/02 21:51:19 jca Exp $
COMMENT= alternative formatting library for C and C++
GH_ACCOUNT= fmtlib
GH_PROJECT= fmt
GH_TAGNAME= 7.1.3
SHARED_LIBS= fmt 0.0
CATEGORIES= devel
MAINTAINER= Ashton Fagg <ashton@fagg.id.au>
# MIT
PERMIT_PACKAGE= Yes
# C++11
COMPILER= base-clang ports-gcc
MODULES= devel/cmake
WANTLIB+= ${COMPILER_LIBCXX}
CONFIGURE_ARGS+= -DBUILD_SHARED_LIBS=on
.include <bsd.port.mk>

2
devel/fmt/distinfo Normal file
View File

@ -0,0 +1,2 @@
SHA256 (fmt-7.1.3.tar.gz) = XK5wcgQrMEPhLVPVDvQEu7dpSdrR3jaNf5k6FcjAXsw=
SIZE (fmt-7.1.3.tar.gz) = 770029

View File

@ -0,0 +1,50 @@
$OpenBSD: patch-test_gtest-extra-test_cc,v 1.1.1.1 2021/01/02 21:51:19 jca Exp $
Index: test/gtest-extra-test.cc
--- test/gtest-extra-test.cc.orig
+++ test/gtest-extra-test.cc
@@ -22,14 +22,6 @@
namespace {
-// This is used to suppress coverity warnings about untrusted values.
-std::string sanitize(const std::string& s) {
- std::string result;
- for (std::string::const_iterator i = s.begin(), end = s.end(); i != end; ++i)
- result.push_back(static_cast<char>(*i & 0xff));
- return result;
-}
-
// Tests that assertion macros evaluate their arguments exactly once.
class SingleEvaluationTest : public ::testing::Test {
protected:
@@ -369,6 +361,10 @@ TEST(OutputRedirectTest, FlushErrorInCtor) {
write_copy.dup2(write_fd); // "undo" close or dtor will fail
}
+#if !defined(__OpenBSD__)
+// NOTE(fagg): There's some bug in this test. Can't find it.
+// Upstream suggests it doesn't matter so lets leave this compiled
+// out for now while i work on figuring it out.
TEST(OutputRedirectTest, DupErrorInCtor) {
buffered_file f = open_buffered_file();
int fd = (f.fileno)();
@@ -380,6 +376,7 @@ TEST(OutputRedirectTest, DupErrorInCtor) {
fmt::format("cannot duplicate file descriptor {}", fd));
copy.dup2(fd); // "undo" close or dtor will fail
}
+#endif
TEST(OutputRedirectTest, RestoreAndRead) {
file read_end, write_end;
@@ -388,8 +385,8 @@ TEST(OutputRedirectTest, RestoreAndRead) {
std::fprintf(file.get(), "[[[");
OutputRedirect redir(file.get());
std::fprintf(file.get(), "censored");
- EXPECT_EQ("censored", sanitize(redir.restore_and_read()));
- EXPECT_EQ("", sanitize(redir.restore_and_read()));
+ EXPECT_EQ("censored", redir.restore_and_read());
+ EXPECT_EQ("", redir.restore_and_read());
std::fprintf(file.get(), "]]]");
file = buffered_file();
EXPECT_READ(read_end, "[[[]]]");

View File

@ -0,0 +1,19 @@
$OpenBSD: patch-test_posix-mock-test_cc,v 1.1.1.1 2021/01/02 21:51:19 jca Exp $
Index: test/posix-mock-test.cc
--- test/posix-mock-test.cc.orig
+++ test/posix-mock-test.cc
@@ -194,12 +194,12 @@ int(test::fileno)(FILE* stream) {
# define EXPECT_EQ_POSIX(expected, actual)
#endif
+#if FMT_USE_FCNTL
static void write_file(fmt::cstring_view filename, fmt::string_view content) {
fmt::buffered_file f(filename, "w");
f.print("{}", content);
}
-#if FMT_USE_FCNTL
using fmt::file;
TEST(UtilTest, GetPageSize) {

View File

@ -0,0 +1,14 @@
$OpenBSD: patch-test_std-format-test_cc,v 1.1.1.1 2021/01/02 21:51:19 jca Exp $
Index: test/std-format-test.cc
--- test/std-format-test.cc.orig
+++ test/std-format-test.cc
@@ -111,7 +111,7 @@ template <> struct std::formatter<S> {
char c = get_char();
if (!isdigit(c) || (++iter, get_char()) != '}')
throw format_error("invalid format");
- width_arg_id = c - '0';
+ width_arg_id = fmt::detail::to_unsigned(c - '0');
ctx.check_arg_id(width_arg_id);
return ++iter;
}

14
devel/fmt/pkg/DESCR Normal file
View File

@ -0,0 +1,14 @@
fmt is an open-source formatting library providing a fast and safe
alternative to C stdio and C++ iostreams.
Features include:
- Simple format API with positional arguments for localization Format
- string syntax similar to Python's format
- Safe printf implementation including POSIX extensions for positional
arguments
- Fast IEEE 754 floating-point formatter with correct rounding,
shortness and round-trip guarantees

22
devel/fmt/pkg/PLIST Normal file
View File

@ -0,0 +1,22 @@
@comment $OpenBSD: PLIST,v 1.1.1.1 2021/01/02 21:51:19 jca Exp $
include/fmt/
include/fmt/chrono.h
include/fmt/color.h
include/fmt/compile.h
include/fmt/core.h
include/fmt/format-inl.h
include/fmt/format.h
include/fmt/locale.h
include/fmt/os.h
include/fmt/ostream.h
include/fmt/posix.h
include/fmt/printf.h
include/fmt/ranges.h
lib/cmake/
lib/cmake/fmt/
lib/cmake/fmt/fmt-config-version.cmake
lib/cmake/fmt/fmt-config.cmake
lib/cmake/fmt/fmt-targets${MODCMAKE_BUILD_SUFFIX}
lib/cmake/fmt/fmt-targets.cmake
@lib lib/libfmt.so.${LIBfmt_VERSION}
lib/pkgconfig/fmt.pc