[upstream_utils] Remove nlohmann JSON

This commit is contained in:
Peter Johnson
2026-03-28 21:02:15 -07:00
parent 3ac168f9d2
commit bfea2b7e1f
53 changed files with 0 additions and 25853 deletions

View File

@@ -1,65 +0,0 @@
#!/usr/bin/env python3
import os
import shutil
from pathlib import Path
from upstream_utils import Lib, walk_if
def copy_upstream_src(wpilib_root: Path):
wpiutil = wpilib_root / "wpiutil"
# Delete old install
for d in [
"src/main/native/thirdparty/json/include",
]:
shutil.rmtree(wpiutil / d, ignore_errors=True)
# Create lists of source and destination files
os.chdir("include/nlohmann")
files = walk_if(Path("."), lambda dp, f: True)
src_include_files = [f.absolute() for f in files]
wpiutil_json_root = wpiutil / "src/main/native/thirdparty/json/include/wpi/util"
dest_include_files = [wpiutil_json_root / f for f in files]
# Copy json header files into allwpilib
for i in range(len(src_include_files)):
dest_dir = dest_include_files[i].parent
if not dest_dir.exists():
dest_dir.mkdir(parents=True)
shutil.copyfile(src_include_files[i], dest_include_files[i])
for include_file in dest_include_files:
with open(include_file) as f:
content = f.read()
# Rename namespace from nlohmann to wpi
content = content.replace("namespace nlohmann", "namespace wpi::util")
content = content.replace("nlohmann::", "wpi::util::")
# Fix internal includes
content = content.replace("include <nlohmann/", "include <wpi/util/")
# Fix include guards and other #defines
content = content.replace("NLOHMANN_", "WPI_")
with open(include_file, "w") as f:
f.write(content)
def main():
name = "json"
url = "https://github.com/nlohmann/json"
tag = "v3.12.0"
patch_options = {
"use_threeway": True,
}
json = Lib(name, url, tag, copy_upstream_src, patch_options)
json.main()
if __name__ == "__main__":
main()

View File

@@ -1,76 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Fri, 8 Sep 2023 19:21:41 -0700
Subject: [PATCH 1/5] Remove version from namespace
---
include/nlohmann/detail/abi_macros.hpp | 46 ++------------------------
1 file changed, 3 insertions(+), 43 deletions(-)
diff --git a/include/nlohmann/detail/abi_macros.hpp b/include/nlohmann/detail/abi_macros.hpp
index 76cf336fcd14d3249b85c2e9cbfae926fe22562f..28facfc9464bcf2108f5d40fe57703cd755864b8 100644
--- a/include/nlohmann/detail/abi_macros.hpp
+++ b/include/nlohmann/detail/abi_macros.hpp
@@ -52,41 +52,6 @@
#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON
#endif
-#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION
- #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0
-#endif
-
-// Construct the namespace ABI tags component
-#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c) json_abi ## a ## b ## c
-#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b, c) \
- NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c)
-
-#define NLOHMANN_JSON_ABI_TAGS \
- NLOHMANN_JSON_ABI_TAGS_CONCAT( \
- NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
- NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON, \
- NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS)
-
-// Construct the namespace version component
-#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \
- _v ## major ## _ ## minor ## _ ## patch
-#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \
- NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch)
-
-#if NLOHMANN_JSON_NAMESPACE_NO_VERSION
-#define NLOHMANN_JSON_NAMESPACE_VERSION
-#else
-#define NLOHMANN_JSON_NAMESPACE_VERSION \
- NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \
- NLOHMANN_JSON_VERSION_MINOR, \
- NLOHMANN_JSON_VERSION_PATCH)
-#endif
-
-// Combine namespace components
-#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b
-#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \
- NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b)
-
#ifndef NLOHMANN_JSON_NAMESPACE
#define NLOHMANN_JSON_NAMESPACE \
nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \
@@ -95,17 +60,12 @@
#endif
#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
-#define NLOHMANN_JSON_NAMESPACE_BEGIN \
- namespace nlohmann \
- { \
- inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
- NLOHMANN_JSON_ABI_TAGS, \
- NLOHMANN_JSON_NAMESPACE_VERSION) \
+#define NLOHMANN_JSON_NAMESPACE_BEGIN \
+ namespace nlohmann \
{
#endif
#ifndef NLOHMANN_JSON_NAMESPACE_END
-#define NLOHMANN_JSON_NAMESPACE_END \
- } /* namespace (inline namespace) NOLINT(readability/namespace) */ \
+#define NLOHMANN_JSON_NAMESPACE_END \
} // namespace nlohmann
#endif

View File

@@ -1,55 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Thu, 7 Sep 2023 22:02:27 -0700
Subject: [PATCH 2/5] Make serializer public
---
include/nlohmann/detail/output/serializer.hpp | 4 +++-
include/nlohmann/json.hpp | 3 +--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp
index 3137f3c3602c8aefa4a1e4947e1f17e836e91eb6..3a8e6c18f64035670886089c924bd322acc673a8 100644
--- a/include/nlohmann/detail/output/serializer.hpp
+++ b/include/nlohmann/detail/output/serializer.hpp
@@ -373,7 +373,7 @@ class serializer
}
}
- JSON_PRIVATE_UNLESS_TESTED:
+ public:
/*!
@brief dump escaped string
@@ -696,6 +696,7 @@ class serializer
return false;
}
+ public:
/*!
@brief dump an integer
@@ -876,6 +877,7 @@ class serializer
}
}
+ private:
/*!
@brief check whether a string is UTF-8 encoded
diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp
index ed51cd544748c4b8ebabbd5bf32fd0bb1ef89738..491351330ba7a5994a750027c5766ae769e0b164 100644
--- a/include/nlohmann/json.hpp
+++ b/include/nlohmann/json.hpp
@@ -158,10 +158,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
template<typename CharType> using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
- JSON_PRIVATE_UNLESS_TESTED:
+ public:
using serializer = ::nlohmann::detail::serializer<basic_json>;
- public:
using value_t = detail::value_t;
/// JSON Pointer, see @ref nlohmann::json_pointer
using json_pointer = ::nlohmann::json_pointer<StringType>;

View File

@@ -1,22 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Fri, 8 Sep 2023 21:42:01 -0700
Subject: [PATCH 3/5] Make dump_escaped() take std::string_view
---
include/nlohmann/detail/output/serializer.hpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp
index 3a8e6c18f64035670886089c924bd322acc673a8..359eb82071b10e45e45f73f458660c4e44dd86e8 100644
--- a/include/nlohmann/detail/output/serializer.hpp
+++ b/include/nlohmann/detail/output/serializer.hpp
@@ -388,7 +388,7 @@ class serializer
@complexity Linear in the length of string @a s.
*/
- void dump_escaped(const string_t& s, const bool ensure_ascii)
+ void dump_escaped(std::string_view s, const bool ensure_ascii)
{
std::uint32_t codepoint{};
std::uint8_t state = UTF8_ACCEPT;

View File

@@ -1,133 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: PJ Reiniger <pj.reiniger@gmail.com>
Date: Wed, 20 Sep 2023 02:23:10 -0400
Subject: [PATCH 4/5] Add llvm stream support
---
.../detail/output/output_adapters.hpp | 26 +++++++++++++++++++
include/nlohmann/detail/output/serializer.hpp | 11 ++++++--
include/nlohmann/json.hpp | 24 +++++++++++++++++
3 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/include/nlohmann/detail/output/output_adapters.hpp b/include/nlohmann/detail/output/output_adapters.hpp
index 60806970203b3357b76fef851043f1ec602de9df..2e221ccaffcc25e6c4347ca6a9efd81953cf63ee 100644
--- a/include/nlohmann/detail/output/output_adapters.hpp
+++ b/include/nlohmann/detail/output/output_adapters.hpp
@@ -22,6 +22,8 @@
#include <nlohmann/detail/macro_scope.hpp>
+#include <wpi/util/raw_ostream.hpp>
+
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
@@ -118,6 +120,27 @@ class output_string_adapter : public output_adapter_protocol<CharType>
StringType& str;
};
+template<typename CharType>
+class raw_ostream_adapter : public output_adapter_protocol<CharType>
+{
+ public:
+ explicit raw_ostream_adapter(raw_ostream& s) noexcept
+ : os(s) {}
+
+
+ void write_character(CharType c) override {
+ os << c;
+ }
+
+ JSON_HEDLEY_NON_NULL(2)
+ void write_characters(const CharType* s, std::size_t length) override {
+ os.write(s, length);
+ }
+
+ private:
+ raw_ostream& os;
+};
+
template<typename CharType, typename StringType = std::basic_string<CharType>>
class output_adapter
{
@@ -134,6 +157,9 @@ class output_adapter
output_adapter(StringType& s)
: oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
+ output_adapter(raw_ostream& os)
+ : oa(std::make_shared<raw_ostream_adapter<CharType>>(os)) {}
+
operator output_adapter_t<CharType>()
{
return oa;
diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp
index 359eb82071b10e45e45f73f458660c4e44dd86e8..562dbea840527752c0e6f76a8d098ce98ce5c540 100644
--- a/include/nlohmann/detail/output/serializer.hpp
+++ b/include/nlohmann/detail/output/serializer.hpp
@@ -65,15 +65,22 @@ class serializer
@param[in] error_handler_ how to react on decoding errors
*/
serializer(output_adapter_t<char> s, const char ichar,
- error_handler_t error_handler_ = error_handler_t::strict)
+ error_handler_t error_handler_ = error_handler_t::strict,
+ size_t indent_init_len = 512)
: o(std::move(s))
, loc(std::localeconv())
, thousands_sep(loc->thousands_sep == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->thousands_sep)))
, decimal_point(loc->decimal_point == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->decimal_point)))
, indent_char(ichar)
- , indent_string(512, indent_char)
+ , indent_string(indent_init_len, indent_char)
, error_handler(error_handler_)
{}
+
+ serializer(raw_ostream& os, const char ichar,
+ size_t indent_init_len = 512,
+ error_handler_t error_handler_ = error_handler_t::strict)
+ : serializer(output_adapter<char>(os), ichar, error_handler_, indent_init_len)
+ {}
// delete because of pointer members
serializer(const serializer&) = delete;
diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp
index 491351330ba7a5994a750027c5766ae769e0b164..aa869a663906f14e28354d3af18d7528fa5a2bc0 100644
--- a/include/nlohmann/json.hpp
+++ b/include/nlohmann/json.hpp
@@ -1315,6 +1315,24 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
return result;
}
+ void dump(raw_ostream& os, const int indent = -1,
+ const char indent_char = ' ',
+ const bool ensure_ascii = false,
+ const error_handler_t error_handler = error_handler_t::strict) const {
+ serializer s(os, indent_char);
+
+ if (indent >= 0)
+ {
+ s.dump(*this, true, ensure_ascii, static_cast<unsigned int>(indent));
+ }
+ else
+ {
+ s.dump(*this, false, ensure_ascii, 0);
+ }
+
+ os.flush();
+ }
+
/// @brief return the type of the JSON value (explicit)
/// @sa https://json.nlohmann.me/api/basic_json/type/
constexpr value_t type() const noexcept
@@ -4026,6 +4044,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
return o << j;
}
#endif // JSON_NO_IO
+
+ friend raw_ostream& operator<<(raw_ostream& o, const basic_json& j)
+ {
+ j.dump(o, 0);
+ return o;
+ }
/// @}
/////////////////////

View File

@@ -1,102 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Gold856 <117957790+Gold856@users.noreply.github.com>
Date: Tue, 27 May 2025 23:39:02 -0400
Subject: [PATCH 5/5] Fix Doxygen warnings
---
include/nlohmann/json.hpp | 33 +++++++--------------------------
1 file changed, 7 insertions(+), 26 deletions(-)
diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp
index aa869a663906f14e28354d3af18d7528fa5a2bc0..c5829a32868c8d578cd8245d3744f63ed5fcd727 100644
--- a/include/nlohmann/json.hpp
+++ b/include/nlohmann/json.hpp
@@ -162,7 +162,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
using serializer = ::nlohmann::detail::serializer<basic_json>;
using value_t = detail::value_t;
- /// JSON Pointer, see @ref nlohmann::json_pointer
+ /// JSON Pointer, see @ref json_pointer
using json_pointer = ::nlohmann::json_pointer<StringType>;
template<typename T, typename SFINAE>
using json_serializer = JSONSerializer<T, SFINAE>;
@@ -176,7 +176,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
using initializer_list_t = std::initializer_list<detail::json_ref<basic_json>>;
using input_format_t = detail::input_format_t;
- /// SAX interface type, see @ref nlohmann::json_sax
+ /// SAX interface type, see nlohmann::json_sax
using json_sax_t = json_sax<basic_json>;
////////////////
@@ -1633,13 +1633,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@throw what @ref json_serializer<ValueType> `from_json()` method throws
- @liveexample{The example below shows several conversions from JSON values
- to other types. There a few things to note: (1) Floating-point numbers can
- be converted to integers\, (2) A JSON array can be converted to a standard
- `std::vector<short>`\, (3) A JSON object can be converted to C++
- associative containers such as `std::unordered_map<std::string\,
- json>`.,get__ValueType_const}
-
@since version 2.1.0
*/
template < typename ValueType,
@@ -1705,7 +1698,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@return a copy of *this, converted into @a BasicJsonType
- @complexity Depending on the implementation of the called `from_json()`
+ Complexity: Depending on the implementation of the called `from_json()`
method.
@since version 3.2.0
@@ -1729,7 +1722,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@return a copy of *this
- @complexity Constant.
+ Complexity: Constant.
@since version 2.1.0
*/
@@ -1813,12 +1806,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@return pointer to the internally stored JSON value if the requested
pointer type @a PointerType fits to the JSON value; `nullptr` otherwise
- @complexity Constant.
-
- @liveexample{The example below shows how pointers to internal values of a
- JSON value can be requested. Note that no type conversions are made and a
- `nullptr` is returned if the value and the requested pointer type does not
- match.,get__PointerType}
+ Complexity: Constant.
@sa see @ref get_ptr() for explicit pointer-member access
@@ -1896,7 +1884,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@brief get a value (implicit)
Implicit type conversion between the JSON value and a compatible value.
- The call is realized by calling @ref get() const.
+ The call is realized by calling @ref get().
@tparam ValueType non-pointer type compatible to the JSON value, for
instance `int` for JSON integer numbers, `bool` for JSON booleans, or
@@ -1910,14 +1898,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
to the JSON value type (e.g., the JSON value is of type boolean, but a
string is requested); see example below
- @complexity Linear in the size of the JSON value.
-
- @liveexample{The example below shows several conversions from JSON values
- to other types. There a few things to note: (1) Floating-point numbers can
- be converted to integers\, (2) A JSON array can be converted to a standard
- `std::vector<short>`\, (3) A JSON object can be converted to C++
- associative containers such as `std::unordered_map<std::string\,
- json>`.,operator__ValueType}
+ Complexity: Linear in the size of the JSON value.
@since version 1.0.0
*/