From 66029c405f1353061414c9a2dfe1db64ff071a56 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max.kellermann@gmail.com>
Date: Mon, 28 Nov 2022 23:05:15 +0100
Subject: [PATCH] system/FmtError: move to lib/fmt/

---
 src/LogInit.cxx                                      |  2 +-
 src/archive/plugins/ZzipArchivePlugin.cxx            |  2 +-
 src/archive/plugins/meson.build                      |  1 +
 src/db/plugins/simple/SimpleDatabasePlugin.cxx       |  2 +-
 src/event/InotifyEvent.cxx                           |  2 +-
 src/fs/DirectoryReader.cxx                           |  2 +-
 src/fs/FileInfo.hxx                                  |  2 +-
 src/fs/FileSystem.cxx                                |  2 +-
 src/input/plugins/UringInputPlugin.cxx               |  2 +-
 src/io/FileOutputStream.cxx                          |  2 +-
 src/io/FileReader.cxx                                |  2 +-
 src/io/Open.cxx                                      |  2 +-
 src/{system/FmtError.cxx => lib/fmt/SystemError.cxx} |  4 ++--
 src/{system/FmtError.hxx => lib/fmt/SystemError.hxx} |  2 +-
 src/lib/fmt/meson.build                              | 10 +++++++++-
 src/mixer/plugins/OssMixerPlugin.cxx                 |  2 +-
 src/output/plugins/FifoOutputPlugin.cxx              |  2 +-
 src/output/plugins/OssOutputPlugin.cxx               |  2 +-
 src/output/plugins/PipeOutputPlugin.cxx              |  2 +-
 src/output/plugins/SolarisOutputPlugin.cxx           |  2 +-
 src/system/meson.build                               |  1 -
 src/unix/Daemon.cxx                                  |  2 +-
 src/unix/PidFile.hxx                                 |  2 +-
 23 files changed, 31 insertions(+), 23 deletions(-)
 rename src/{system/FmtError.cxx => lib/fmt/SystemError.cxx} (97%)
 rename src/{system/FmtError.hxx => lib/fmt/SystemError.hxx} (98%)

diff --git a/src/LogInit.cxx b/src/LogInit.cxx
index 847e4c60c..d98dbfb28 100644
--- a/src/LogInit.cxx
+++ b/src/LogInit.cxx
@@ -30,7 +30,7 @@
 #include "util/Domain.hxx"
 #include "util/RuntimeError.hxx"
 #include "util/StringAPI.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 
 #include <cassert>
 
diff --git a/src/archive/plugins/ZzipArchivePlugin.cxx b/src/archive/plugins/ZzipArchivePlugin.cxx
index 41d7e7be3..258242a34 100644
--- a/src/archive/plugins/ZzipArchivePlugin.cxx
+++ b/src/archive/plugins/ZzipArchivePlugin.cxx
@@ -27,7 +27,7 @@
 #include "../ArchiveVisitor.hxx"
 #include "input/InputStream.hxx"
 #include "fs/Path.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 #include "util/RuntimeError.hxx"
 #include "util/UTF8.hxx"
 
diff --git a/src/archive/plugins/meson.build b/src/archive/plugins/meson.build
index ff58a3acc..5c967c344 100644
--- a/src/archive/plugins/meson.build
+++ b/src/archive/plugins/meson.build
@@ -31,6 +31,7 @@ archive_plugins = static_library(
   archive_plugins_sources,
   include_directories: inc,
   dependencies: [
+    fmt_dep,
     libbz2_dep,
     libiso9660_dep,
     libzzip_dep,
diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.cxx b/src/db/plugins/simple/SimpleDatabasePlugin.cxx
index f9728f792..73aa987b4 100644
--- a/src/db/plugins/simple/SimpleDatabasePlugin.cxx
+++ b/src/db/plugins/simple/SimpleDatabasePlugin.cxx
@@ -40,7 +40,7 @@
 #include "fs/FileInfo.hxx"
 #include "config/Block.hxx"
 #include "fs/FileSystem.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 #include "util/CharUtil.hxx"
 #include "util/Domain.hxx"
 #include "util/RecursiveMap.hxx"
diff --git a/src/event/InotifyEvent.cxx b/src/event/InotifyEvent.cxx
index cc6750547..e1f53b2ca 100644
--- a/src/event/InotifyEvent.cxx
+++ b/src/event/InotifyEvent.cxx
@@ -31,7 +31,7 @@
  */
 
 #include "InotifyEvent.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 #include "io/UniqueFileDescriptor.hxx"
 
 #include <array>
diff --git a/src/fs/DirectoryReader.cxx b/src/fs/DirectoryReader.cxx
index 546e6a7ee..c17e1b235 100644
--- a/src/fs/DirectoryReader.cxx
+++ b/src/fs/DirectoryReader.cxx
@@ -19,7 +19,7 @@
 
 #include "DirectoryReader.hxx"
 #include "lib/fmt/PathFormatter.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 
 #ifdef _WIN32
 
diff --git a/src/fs/FileInfo.hxx b/src/fs/FileInfo.hxx
index a50adf437..60e4bdb27 100644
--- a/src/fs/FileInfo.hxx
+++ b/src/fs/FileInfo.hxx
@@ -22,7 +22,7 @@
 
 #include "Path.hxx"
 #include "lib/fmt/PathFormatter.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 
 #ifdef _WIN32
 #include "time/FileTime.hxx"
diff --git a/src/fs/FileSystem.cxx b/src/fs/FileSystem.cxx
index dae47a648..deaba2420 100644
--- a/src/fs/FileSystem.cxx
+++ b/src/fs/FileSystem.cxx
@@ -21,7 +21,7 @@
 #include "AllocatedPath.hxx"
 #include "Limits.hxx"
 #include "lib/fmt/PathFormatter.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 
 #ifdef _WIN32
 #include <handleapi.h> // for CloseHandle()
diff --git a/src/input/plugins/UringInputPlugin.cxx b/src/input/plugins/UringInputPlugin.cxx
index e671d4850..33574a27b 100644
--- a/src/input/plugins/UringInputPlugin.cxx
+++ b/src/input/plugins/UringInputPlugin.cxx
@@ -21,7 +21,7 @@
 #include "../AsyncInputStream.hxx"
 #include "event/Call.hxx"
 #include "event/Loop.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 #include "io/Open.hxx"
 #include "io/UniqueFileDescriptor.hxx"
 #include "io/uring/ReadOperation.hxx"
diff --git a/src/io/FileOutputStream.cxx b/src/io/FileOutputStream.cxx
index 920f83b9f..959c59924 100644
--- a/src/io/FileOutputStream.cxx
+++ b/src/io/FileOutputStream.cxx
@@ -29,7 +29,7 @@
 
 #include "FileOutputStream.hxx"
 #include "lib/fmt/PathFormatter.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 #include "util/StringFormat.hxx"
 
 #ifdef _WIN32
diff --git a/src/io/FileReader.cxx b/src/io/FileReader.cxx
index 42799628d..3287e544c 100644
--- a/src/io/FileReader.cxx
+++ b/src/io/FileReader.cxx
@@ -30,7 +30,7 @@
 #include "FileReader.hxx"
 #include "lib/fmt/PathFormatter.hxx"
 #include "fs/FileInfo.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 #include "io/Open.hxx"
 
 #include <cassert>
diff --git a/src/io/Open.cxx b/src/io/Open.cxx
index 1b767b17e..612ee952d 100644
--- a/src/io/Open.cxx
+++ b/src/io/Open.cxx
@@ -29,7 +29,7 @@
 
 #include "Open.hxx"
 #include "UniqueFileDescriptor.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 
 #include <fcntl.h>
 
diff --git a/src/system/FmtError.cxx b/src/lib/fmt/SystemError.cxx
similarity index 97%
rename from src/system/FmtError.cxx
rename to src/lib/fmt/SystemError.cxx
index 3645357bb..19148fc76 100644
--- a/src/system/FmtError.cxx
+++ b/src/lib/fmt/SystemError.cxx
@@ -27,8 +27,8 @@
  * OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "FmtError.hxx"
-#include "lib/fmt/ToBuffer.hxx"
+#include "SystemError.hxx"
+#include "ToBuffer.hxx"
 
 #include <array>
 
diff --git a/src/system/FmtError.hxx b/src/lib/fmt/SystemError.hxx
similarity index 98%
rename from src/system/FmtError.hxx
rename to src/lib/fmt/SystemError.hxx
index 81bdb07b0..6cab0a387 100644
--- a/src/system/FmtError.hxx
+++ b/src/lib/fmt/SystemError.hxx
@@ -29,7 +29,7 @@
 
 #pragma once
 
-#include "Error.hxx" // IWYU pragma: export
+#include "system/Error.hxx" // IWYU pragma: export
 
 #include <fmt/core.h>
 #if FMT_VERSION >= 80000 && FMT_VERSION < 90000
diff --git a/src/lib/fmt/meson.build b/src/lib/fmt/meson.build
index 66007743e..84ddb8a72 100644
--- a/src/lib/fmt/meson.build
+++ b/src/lib/fmt/meson.build
@@ -8,6 +8,14 @@ if compiler.get_id() == 'clang' and compiler.version().version_compare('<15')
   )
 endif
 
-fmt_dep = declare_dependency(
+fmt = static_library(
+  'fmt',
+  'SystemError.cxx',
+  include_directories: inc,
+  dependencies: libfmt,
+)
+
+fmt_dep = declare_dependency(
+  link_with: fmt,
   dependencies: libfmt,
 )
diff --git a/src/mixer/plugins/OssMixerPlugin.cxx b/src/mixer/plugins/OssMixerPlugin.cxx
index c6ef53395..7a0edb725 100644
--- a/src/mixer/plugins/OssMixerPlugin.cxx
+++ b/src/mixer/plugins/OssMixerPlugin.cxx
@@ -21,7 +21,7 @@
 #include "mixer/Mixer.hxx"
 #include "config/Block.hxx"
 #include "io/FileDescriptor.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 #include "util/ASCII.hxx"
 #include "util/Domain.hxx"
 #include "util/RuntimeError.hxx"
diff --git a/src/output/plugins/FifoOutputPlugin.cxx b/src/output/plugins/FifoOutputPlugin.cxx
index a7551255c..0334e05f0 100644
--- a/src/output/plugins/FifoOutputPlugin.cxx
+++ b/src/output/plugins/FifoOutputPlugin.cxx
@@ -24,7 +24,7 @@
 #include "fs/AllocatedPath.hxx"
 #include "fs/FileSystem.hxx"
 #include "fs/FileInfo.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 #include "util/Domain.hxx"
 #include "util/RuntimeError.hxx"
 #include "Log.hxx"
diff --git a/src/output/plugins/OssOutputPlugin.cxx b/src/output/plugins/OssOutputPlugin.cxx
index f8a18d21e..9b111dc14 100644
--- a/src/output/plugins/OssOutputPlugin.cxx
+++ b/src/output/plugins/OssOutputPlugin.cxx
@@ -22,7 +22,7 @@
 #include "mixer/plugins/OssMixerPlugin.hxx"
 #include "pcm/Export.hxx"
 #include "io/UniqueFileDescriptor.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 #include "util/Domain.hxx"
 #include "util/ByteOrder.hxx"
 #include "util/Manual.hxx"
diff --git a/src/output/plugins/PipeOutputPlugin.cxx b/src/output/plugins/PipeOutputPlugin.cxx
index a83202ff5..0ce57ff6d 100644
--- a/src/output/plugins/PipeOutputPlugin.cxx
+++ b/src/output/plugins/PipeOutputPlugin.cxx
@@ -19,7 +19,7 @@
 
 #include "PipeOutputPlugin.hxx"
 #include "../OutputAPI.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 
 #include <string>
 #include <stdexcept>
diff --git a/src/output/plugins/SolarisOutputPlugin.cxx b/src/output/plugins/SolarisOutputPlugin.cxx
index 763596614..d3b831794 100644
--- a/src/output/plugins/SolarisOutputPlugin.cxx
+++ b/src/output/plugins/SolarisOutputPlugin.cxx
@@ -20,7 +20,7 @@
 #include "SolarisOutputPlugin.hxx"
 #include "../OutputAPI.hxx"
 #include "io/FileDescriptor.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 
 #include <cerrno>
 
diff --git a/src/system/meson.build b/src/system/meson.build
index 8272bde4d..9bc557217 100644
--- a/src/system/meson.build
+++ b/src/system/meson.build
@@ -1,6 +1,5 @@
 system_sources = [
   'EventPipe.cxx',
-  'FmtError.cxx',
 ]
 
 if host_machine.system() == 'linux'
diff --git a/src/unix/Daemon.cxx b/src/unix/Daemon.cxx
index 4e18bb111..f6db298ee 100644
--- a/src/unix/Daemon.cxx
+++ b/src/unix/Daemon.cxx
@@ -20,7 +20,7 @@
 #include "config.h"
 #include "Daemon.hxx"
 #include "lib/fmt/PathFormatter.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 #include "fs/AllocatedPath.hxx"
 #include "util/RuntimeError.hxx"
 
diff --git a/src/unix/PidFile.hxx b/src/unix/PidFile.hxx
index b59acabf6..65fc83840 100644
--- a/src/unix/PidFile.hxx
+++ b/src/unix/PidFile.hxx
@@ -23,7 +23,7 @@
 #include "lib/fmt/PathFormatter.hxx"
 #include "fs/FileSystem.hxx"
 #include "fs/AllocatedPath.hxx"
-#include "system/FmtError.hxx"
+#include "lib/fmt/SystemError.hxx"
 
 #include <cassert>