build: Remove dependencies on fmtlib
With C++23, we can replace fmt::format with std::format and fmt::print
with stdplus::print. This allows us to migrate to std::print once the
support is available.
Change-Id: I790901fb3b96d815275a3919e1fb90973189fc02
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/.gitignore b/.gitignore
index 27676e3..9dc3fde 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,7 +7,6 @@
!subprojects/metrics-ipmi-blobs/
!subprojects/ncsid/
!subprojects/nemora-postd/
-!subprojects/fmt.wrap
!subprojects/googletest.wrap
!subprojects/phosphor-dbus-interfaces.wrap
!subprojects/phosphor-logging.wrap
diff --git a/subprojects/dhcp-done/dhcp-done.cpp b/subprojects/dhcp-done/dhcp-done.cpp
index 00c0e3b..d6c5c96 100644
--- a/subprojects/dhcp-done/dhcp-done.cpp
+++ b/subprojects/dhcp-done/dhcp-done.cpp
@@ -12,12 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include <fmt/format.h>
-
#include <sdeventplus/event.hpp>
#include <sdeventplus/source/io.hpp>
#include <stdplus/fd/create.hpp>
#include <stdplus/fd/ops.hpp>
+#include <stdplus/print.hpp>
using namespace std::string_view_literals;
@@ -48,7 +47,7 @@
{
if (argc != 2)
{
- fmt::print(stderr, "Invalid parameter count\n");
+ stdplus::println(stderr, "Invalid parameter count");
return 1;
}
@@ -64,7 +63,7 @@
}
else
{
- fmt::print(stderr, "Invalid parameter\n");
+ stdplus::println(stderr, "Invalid parameter");
return 1;
}
@@ -84,7 +83,7 @@
}
catch (const std::exception& e)
{
- fmt::print(stderr, "Failed: {}\n", e.what());
+ stdplus::println(stderr, "Failed: {}", e.what());
return 1;
}
}
diff --git a/subprojects/fmt.wrap b/subprojects/fmt.wrap
deleted file mode 100644
index 6847ae5..0000000
--- a/subprojects/fmt.wrap
+++ /dev/null
@@ -1,3 +0,0 @@
-[wrap-git]
-url = https://github.com/fmtlib/fmt
-revision = HEAD
diff --git a/subprojects/ncsid/src/meson.build b/subprojects/ncsid/src/meson.build
index 8b01470..6a85c68 100644
--- a/subprojects/ncsid/src/meson.build
+++ b/subprojects/ncsid/src/meson.build
@@ -14,21 +14,7 @@
ncsid_headers = include_directories('.')
-fmt_dep = dependency('fmt', required: false)
-if not fmt_dep.found()
- fmt_proj = import('cmake').subproject(
- 'fmt',
- cmake_options: [
- '-DCMAKE_POSITION_INDEPENDENT_CODE=ON',
- '-DMASTER_PROJECT=OFF'
- ],
- required: false)
- assert(fmt_proj.found(), 'fmtlib is required')
- fmt_dep = fmt_proj.dependency('fmt')
-endif
-
ncsid_deps = [
- fmt_dep,
dependency('sdbusplus', fallback: ['sdbusplus', 'sdbusplus_dep']),
dependency('stdplus', fallback: ['stdplus', 'stdplus_dep']),
]
diff --git a/subprojects/ncsid/src/ncsi_state_machine.cpp b/subprojects/ncsid/src/ncsi_state_machine.cpp
index b2e0286..2ca4906 100644
--- a/subprojects/ncsid/src/ncsi_state_machine.cpp
+++ b/subprojects/ncsid/src/ncsi_state_machine.cpp
@@ -19,10 +19,11 @@
#include "platforms/nemora/portable/ncsi_fsm.h"
#include <arpa/inet.h>
-#include <fmt/printf.h>
#include <netinet/ether.h>
#include <unistd.h>
+#include <stdplus/print.hpp>
+
#include <chrono>
#include <cstdint>
#include <cstdlib>
@@ -48,9 +49,10 @@
{
if (line_rep_count > 0)
{
- fmt::print(stderr, "... Repeated {} times ...\n", line_rep_count);
+ stdplus::println(stderr, "... Repeated {} times ...",
+ line_rep_count);
}
- fmt::print(stderr, "{}", line);
+ stdplus::print(stderr, "{}", line);
last_line = std::move(line);
last_line_time = now;
line_rep_count = 0;
@@ -61,7 +63,7 @@
}
}
-#define CPRINTF(...) do_log(fmt::sprintf(__VA_ARGS__))
+#define CPRINT(...) do_log(std::format(__VA_ARGS__))
#ifdef NCSID_VERBOSE_LOGGING
#define DEBUG_PRINTF printf
@@ -131,7 +133,7 @@
StateMachine::~StateMachine()
{
- CPRINTF("[NCSI stopping]\n");
+ CPRINT("[NCSI stopping]\n");
}
size_t StateMachine::poll_l2_config()
@@ -200,7 +202,7 @@
NCSI_LINK_STATUS_UP;
if (!link_up_ || new_link_up != *link_up_)
{
- CPRINTF("[NCSI link %s]\n", new_link_up ? "up" : "down");
+ CPRINT("[NCSI link {}]\n", new_link_up ? "up" : "down");
link_up_ = new_link_up;
}
}
@@ -214,8 +216,8 @@
bool new_hostless = ncsi_fsm_is_nic_hostless(&ncsi_state_);
if (!hostless_ || new_hostless != *hostless_)
{
- CPRINTF("[NCSI nic %s]\n",
- new_hostless ? "hostless" : "hostfull");
+ CPRINT("[NCSI nic {}]\n",
+ new_hostless ? "hostless" : "hostfull");
net_config_->set_nic_hostless(new_hostless);
hostless_ = new_hostless;
}
@@ -241,27 +243,27 @@
if (!ncsi_buf_.len)
{
network_debug_.ncsi.rx_error.timeout_count++;
- CPRINTF("[NCSI timeout in state %s]\n", state_string);
+ CPRINT("[NCSI timeout in state {}]\n", state_string);
}
else
{
network_debug_.ncsi.rx_error.undersized_count++;
- CPRINTF("[NCSI undersized response in state %s]\n",
- state_string);
+ CPRINT("[NCSI undersized response in state {}]\n",
+ state_string);
}
break;
case NCSI_RESPONSE_NACK:
network_debug_.ncsi.rx_error.nack_count++;
- CPRINTF(
- "[NCSI nack in state %s. Response: 0x%04x Reason: 0x%04x]\n",
+ CPRINT(
+ "[NCSI nack in state {}. Response: {:#04x} Reason: {:#04x}]\n",
state_string, ntohs(response->response_code),
ntohs(response->reason_code));
break;
case NCSI_RESPONSE_UNEXPECTED_TYPE:
network_debug_.ncsi.rx_error.unexpected_type_count++;
- CPRINTF("[NCSI unexpected response in state %s. Response type: "
- "0x%02x]\n",
- state_string, response->hdr.control_packet_type);
+ CPRINT(
+ "[NCSI unexpected response in state {}. Response type: {:#02x}]\n",
+ state_string, response->hdr.control_packet_type);
break;
case NCSI_RESPONSE_UNEXPECTED_SIZE:
{
@@ -281,24 +283,24 @@
response->hdr.control_packet_type & (~NCSI_RESPONSE));
}
network_debug_.ncsi.rx_error.unexpected_size_count++;
- CPRINTF("[NCSI unexpected response size in state %s."
- " Expected %d]\n",
- state_string, expected_size);
+ CPRINT("[NCSI unexpected response size in state {}."
+ " Expected {}]\n",
+ state_string, expected_size);
}
break;
case NCSI_RESPONSE_OEM_FORMAT_ERROR:
network_debug_.ncsi.rx_error.unexpected_type_count++;
- CPRINTF("[NCSI OEM format error]\n");
+ CPRINT("[NCSI OEM format error]\n");
break;
case NCSI_RESPONSE_UNEXPECTED_PARAMS:
- CPRINTF("[NCSI OEM Filter MAC or TCP/IP Config Mismatch]\n");
+ CPRINT("[NCSI OEM Filter MAC or TCP/IP Config Mismatch]\n");
break;
default:
/* NCSI_RESPONSE_ACK and NCSI_RESPONSE_NONE are not errors and need
* not be handled here, so this branch is just to complete the
* switch.
*/
- CPRINTF("[NCSI OK]\n");
+ CPRINT("[NCSI OK]\n");
break;
}
}
@@ -343,10 +345,10 @@
{
if (!net_config_ || !sock_io_)
{
- CPRINTF("StateMachine configuration incomplete: "
- "net_config_: <%p>, sock_io_: <%p>",
- reinterpret_cast<void*>(net_config_),
- reinterpret_cast<void*>(sock_io_));
+ CPRINT("StateMachine configuration incomplete: "
+ "net_config_: <{}>, sock_io_: <{}>",
+ reinterpret_cast<void*>(net_config_),
+ reinterpret_cast<void*>(sock_io_));
return;
}
diff --git a/subprojects/ncsid/src/net_config.cpp b/subprojects/ncsid/src/net_config.cpp
index 97c6a43..4e52cc8 100644
--- a/subprojects/ncsid/src/net_config.cpp
+++ b/subprojects/ncsid/src/net_config.cpp
@@ -14,7 +14,6 @@
#include "net_config.h"
-#include <fmt/format.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -22,6 +21,7 @@
#include <sdbusplus/bus.hpp>
#include <stdplus/fd/create.hpp>
#include <stdplus/fd/ops.hpp>
+#include <stdplus/print.hpp>
#include <stdplus/util/string.hpp>
#include <cstdio>
@@ -92,7 +92,7 @@
{
if (mac == nullptr)
{
- fmt::print(stderr, "mac is nullptr\n");
+ stdplus::println(stderr, "mac is nullptr");
return -1;
}
@@ -114,14 +114,14 @@
}
catch (const sdbusplus::exception::SdBusError& ex)
{
- fmt::print(stderr, "Failed to get MACAddress: {}\n", ex.what());
+ stdplus::println(stderr, "Failed to get MACAddress: {}", ex.what());
return -1;
}
if (parse_mac(mac_string, mac) < 0)
{
- fmt::print(stderr, "Failed to parse MAC Address `{}`\n",
- mac_string);
+ stdplus::println(stderr, "Failed to parse MAC Address `{}`",
+ mac_string);
return -1;
}
@@ -154,8 +154,8 @@
}
catch (const std::exception& ex)
{
- fmt::print(stderr, "Failed to set MAC Addr `{}` writing file: {}\n",
- std::get<std::string>(mac_value), ex.what());
+ stdplus::println(stderr, "Failed to set MAC Addr `{}` writing file: {}",
+ std::get<std::string>(mac_value), ex.what());
return -1;
}
@@ -165,8 +165,8 @@
}
catch (const sdbusplus::exception::SdBusError& ex)
{
- fmt::print(stderr, "Failed to set MAC Addr `{}`: {}\n",
- std::get<std::string>(mac_value), ex.what());
+ stdplus::println(stderr, "Failed to set MAC Addr `{}`: {}",
+ std::get<std::string>(mac_value), ex.what());
return -1;
}
@@ -215,7 +215,8 @@
}
catch (const sdbusplus::exception::SdBusError& ex)
{
- fmt::print(stderr, "Failed to set systemd nic status: {}\n", ex.what());
+ stdplus::println(stderr, "Failed to set systemd nic status: {}",
+ ex.what());
return 1;
}
}
diff --git a/subprojects/ncsid/src/platforms/nemora/portable/ncsi_fsm.c b/subprojects/ncsid/src/platforms/nemora/portable/ncsi_fsm.c
index 5b5344c..ab04111 100644
--- a/subprojects/ncsid/src/platforms/nemora/portable/ncsi_fsm.c
+++ b/subprojects/ncsid/src/platforms/nemora/portable/ncsi_fsm.c
@@ -150,7 +150,7 @@
if (1 != get_capabilities_response->channel_count &&
2 != get_capabilities_response->channel_count) {
/* TODO: Return Error
- CPRINTF("[NCSI Unsupported channel count %d]\n",
+ CPRINT("[NCSI Unsupported channel count {}]\n",
get_capabilities_response->channel_count);
*/
ncsi_fsm_fail(ncsi_state, network_debug);
@@ -639,7 +639,7 @@
break;
}
// TODO: report this error.
- // CPRINTF("[NCSI Link Status down 0x%08lx]\n", link_status);
+ // CPRINT("[NCSI Link Status down {:#08x}]\n", link_status);
}
if (ncsi_fsm_retry_test(network_debug)) {
GO_TO_STATE(state_variable, NCSI_STATE_TEST_BEGIN);