Compare commits

...

11 Commits

Author SHA1 Message Date
Nekotekina 456c68f452 Move throw out of include headers 2023-10-11 19:55:16 +02:00
Megamouse ac144ed46c Hide uninstall target unless YAML_CPP_INSTALL is set, and allow it to be disabled by YAML_CPP_DISABLE_UNINSTALL
add_custom_target uninstall causes a clash with the same target in rtmidi (https://github.com/thestk/rtmidi).
"add_custom_target cannot create target "uninstall" because another target with the same name already exists.  The existing target is a custom target created in source directory"

Adds new option YAML_CPP_DISABLE_UNINSTALL 

fixes #1151

---------

Co-authored-by: Megamouse <studienricky89@googlemail.de>
Co-authored-by: Jesse Beder <jbeder+github@gmail.com>
2023-10-11 00:02:33 -04:00
Alfi Maulana 4c061a5058 Disable format target when not building as the main project (#1231) 2023-10-10 23:40:09 -04:00
Paul Jurczak 37f1b8b8c9 Update How-To-Emit-YAML.md (#976) 2023-09-21 15:38:56 -05:00
FireWolf d046eea331 node/convert: Enable the template specialization for std::string_view properly when the library is compiled by MSVC on Windows. (#1227) 2023-09-17 11:58:31 -04:00
Daniel Stonier 9f31491b0f bzlmodded (#1224) 2023-09-17 11:57:52 -04:00
Kefu Chai 016b2e7769 CI: test with supported C++ standards (#1226)
* CI: test with supported C++ standards

let's test with the supported standards for better coverage.
C++23 standard was just out, but the support on the toolchain is
not quite ready yet. so let's leave it for a future change.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>

* CI: drop redundant Build step

"Build Tests" is strictly a superset of "Build". in addition to
the library, the former builds the tests also. both these
steps share the same set of command line arguments. by removing
"Build" step, we don't lose anything regarding the test coverage
and information for further investigation if the build fails.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>

---------

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
2023-09-10 08:38:51 -04:00
Kefu Chai 2383e6d0f2 Revert "node/convert: relax the check for string_view (#1222)" (#1225)
This reverts commit 6262201182.

in 62622011, we wanted address the needs to use the `string_view`
converter in C++98, but that requirement was based on wrong
preconditions. `std::string_view` was introduced in C++17, and
popular standard libraries like libstdc++ and libc++ both provide
`std::string_view` when the source is built with C++17.

furthermore 62622011 is buggy. because it uses `<version>` to tell
the feature set provided by the standard library. but `<version>`
is a part of C++20. so this defeats the purpose of the change of
62622011.

Fixes #1223
2023-09-10 08:28:52 -04:00
Kefu Chai 6262201182 node/convert: relax the check for string_view (#1222) 2023-09-06 07:57:12 -05:00
Gianfranco Costamagna fcbb8193b9 Fix testsuite with gcc-13 (#1216)
cd /<<PKGBUILDDIR>>/build-static/test && /usr/bin/c++ -DYAML_CPP_STATIC_DEFINE -I/<<PKGBUILDDIR>>/test/integration -I/<<PKGBUILDDIR>>/test -I/<<PKGBUILDDIR>>/src -I/<<PKGBUILDDIR>>/include -isystem /usr/src/googletest/googlemock/include -isystem /usr/src/googletest/googlemock -isystem /usr/src/googletest/googletest/include -isystem /usr/src/googletest/googletest -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fdebug-prefix-map=/<<PKGBUILDDIR>>=/usr/src/yaml-cpp-0.8.0+dfsg-1~build1 -Wdate-time -D_FORTIFY_SOURCE=2 -std=gnu++14 -Wno-variadic-macros -Wno-sign-compare -DGTEST_HAS_PTHREAD=1 -MD -MT test/CMakeFiles/yaml-cpp-tests.dir/binary_test.cpp.o -MF CMakeFiles/yaml-cpp-tests.dir/binary_test.cpp.o.d -o CMakeFiles/yaml-cpp-tests.dir/binary_test.cpp.o -c /<<PKGBUILDDIR>>/test/binary_test.cpp
/<<PKGBUILDDIR>>/test/binary_test.cpp: In member function ‘virtual void BinaryTest_DecodingNoCrashOnNegative_Test::TestBody()’:
/<<PKGBUILDDIR>>/test/binary_test.cpp:11:38: error: narrowing conversion of ‘-58’ from ‘int’ to ‘char’ [-Wnarrowing]
   11 |   std::string input{-58, -1, -99, 109};
      |                                      ^
2023-08-19 15:36:16 -04:00
Craig Scott c268020048 Specify CMake policy range to avoid deprecation warning (#1211) 2023-08-16 17:54:05 -05:00
10 changed files with 94 additions and 44 deletions
+1
View File
@@ -0,0 +1 @@
test/gtest-1.11.0
+21 -8
View File
@@ -12,6 +12,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
cxx_standard: [11, 17, 20]
build: [static, shared]
generator: ["Default Generator", "MinGW Makefiles"]
exclude:
@@ -23,7 +24,6 @@ jobs:
generator: "MinGW Makefiles"
env:
YAML_BUILD_SHARED_LIBS: ${{ matrix.build == 'shared' && 'ON' || 'OFF' }}
YAML_CPP_BUILD_TESTS: 'ON'
CMAKE_GENERATOR: >-
${{format(matrix.generator != 'Default Generator' && '-G "{0}"' || '', matrix.generator)}}
runs-on: ${{ matrix.os }}
@@ -33,16 +33,10 @@ jobs:
- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v1
- name: Build
shell: bash
run: |
cmake ${{ env.CMAKE_GENERATOR }} -S "${{ github.workspace }}" -B build -DYAML_BUILD_SHARED_LIBS=${{ env.YAML_BUILD_SHARED_LIBS }}
cd build && cmake --build . --parallel ${{ steps.cpu-cores.outputs.count }}
- name: Build Tests
shell: bash
run: |
cmake ${{ env.CMAKE_GENERATOR }} -S "${{ github.workspace }}" -B build -DYAML_BUILD_SHARED_LIBS=${{ env.YAML_BUILD_SHARED_LIBS }} -DYAML_CPP_BUILD_TESTS=${{ env.YAML_CPP_BUILD_TESTS }}
cmake ${{ env.CMAKE_GENERATOR }} -S "${{ github.workspace }}" -B build -DCMAKE_CXX_STANDARD=${{ matrix.cxx_standard }} -DYAML_BUILD_SHARED_LIBS=${{ env.YAML_BUILD_SHARED_LIBS }} -DYAML_CPP_BUILD_TESTS=ON
cd build && cmake --build . --parallel ${{ steps.cpu-cores.outputs.count }}
- name: Run Tests
@@ -70,3 +64,22 @@ jobs:
cd "${{ github.workspace }}"
bazel test test
bzlmod-build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Build
shell: bash
run: |
cd "${{ github.workspace }}"
bazel build --enable_bzlmod :all
- name: Test
shell: bash
run: |
cd "${{ github.workspace }}"
bazel test --enable_bzlmod test
+8 -5
View File
@@ -1,5 +1,6 @@
# 3.5 is actually available almost everywhere, but this a good minimum
cmake_minimum_required(VERSION 3.4)
# 3.5 is actually available almost everywhere, but this a good minimum.
# 3.14 as the upper policy limit avoids CMake deprecation warnings.
cmake_minimum_required(VERSION 3.4...3.14)
# enable MSVC_RUNTIME_LIBRARY target property
# see https://cmake.org/cmake/help/latest/policy/CMP0091.html
@@ -24,14 +25,16 @@ option(YAML_CPP_BUILD_CONTRIB "Enable yaml-cpp contrib in library" ON)
option(YAML_CPP_BUILD_TOOLS "Enable parse tools" ON)
option(YAML_BUILD_SHARED_LIBS "Build yaml-cpp shared library" ${BUILD_SHARED_LIBS})
option(YAML_CPP_INSTALL "Enable generation of yaml-cpp install targets" ${YAML_CPP_MAIN_PROJECT})
option(YAML_CPP_FORMAT_SOURCE "Format source" ON)
option(YAML_CPP_FORMAT_SOURCE "Format source" ${YAML_CPP_MAIN_PROJECT})
option(YAML_CPP_DISABLE_UNINSTALL "Disable uninstallation of yaml-cpp" OFF)
cmake_dependent_option(YAML_CPP_BUILD_TESTS
"Enable yaml-cpp tests" OFF
"BUILD_TESTING;YAML_CPP_MAIN_PROJECT" OFF)
cmake_dependent_option(YAML_MSVC_SHARED_RT
"MSVC: Build yaml-cpp with shared runtime libs (/MD)" ON
"CMAKE_SYSTEM_NAME MATCHES Windows" OFF)
if (YAML_CPP_FORMAT_SOURCE)
find_program(YAML_CPP_CLANG_FORMAT_EXE NAMES clang-format)
endif()
@@ -196,7 +199,7 @@ if (YAML_CPP_FORMAT_SOURCE AND YAML_CPP_CLANG_FORMAT_EXE)
endif()
# uninstall target
if(NOT TARGET uninstall)
if(YAML_CPP_INSTALL AND NOT YAML_CPP_DISABLE_UNINSTALL AND NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
+14
View File
@@ -0,0 +1,14 @@
"""
yaml-cpp is a YAML parser and emitter in c++ matching the YAML specification.
"""
module(
name = "yaml-cpp",
compatibility_level = 1,
version = "0.8.0",
)
bazel_dep(name = "platforms", version = "0.0.7")
bazel_dep(name = "rules_cc", version = "0.0.8")
bazel_dep(name = "googletest", version = "1.14.0", dev_dependency = True)
+3 -9
View File
@@ -155,15 +155,9 @@ produces
We overload `operator <<` for `std::vector`, `std::list`, and `std::map`, so you can write stuff like:
```cpp
std::vector <int> squares;
squares.push_back(1);
squares.push_back(4);
squares.push_back(9);
squares.push_back(16);
std::vector <int> squares = {1, 4, 9, 16};
std::map <std::string, int> ages;
ages["Daniel"] = 26;
ages["Jesse"] = 24;
std::map <std::string, int> ages = {{"Daniel", 26}, {"Jesse", 24}};
YAML::Emitter out;
out << YAML::BeginSeq;
@@ -227,4 +221,4 @@ assert(out.good());
out << YAML::Key;
assert(!out.good());
std::cout << "Emitter error: " << out.GetLastError() << "\n";
```
```
+2 -2
View File
@@ -18,7 +18,7 @@
#include <valarray>
#include <vector>
#if __cplusplus >= 201703L
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
#include <string_view>
#endif
@@ -93,7 +93,7 @@ struct convert<char[N]> {
static Node encode(const char* rhs) { return Node(rhs); }
};
#if __cplusplus >= 201703L
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
template <>
struct convert<std::string_view> {
static Node encode(std::string_view rhs) { return Node(std::string(rhs)); }
+6 -3
View File
@@ -14,6 +14,7 @@
#include <type_traits>
namespace YAML {
[[noreturn]] void throw_bad_subscript(const YAML::Mark& mark);
namespace detail {
template <typename Key, typename Enable = void>
struct get_idx {
@@ -128,7 +129,7 @@ inline node* node_data::get(const Key& key,
return pNode;
return nullptr;
case NodeType::Scalar:
throw BadSubscript(m_mark, key);
throw_bad_subscript(m_mark);
}
auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) {
@@ -154,7 +155,7 @@ inline node& node_data::get(const Key& key, shared_memory_holder pMemory) {
convert_to_map(pMemory);
break;
case NodeType::Scalar:
throw BadSubscript(m_mark, key);
throw_bad_subscript(m_mark);
}
auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) {
@@ -200,6 +201,8 @@ inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) {
return false;
}
[[nodiscard]] void throw_bad_insert();
// map
template <typename Key, typename Value>
inline void node_data::force_insert(const Key& key, const Value& value,
@@ -213,7 +216,7 @@ inline void node_data::force_insert(const Key& key, const Value& value,
convert_to_map(pMemory);
break;
case NodeType::Scalar:
throw BadInsert();
throw_bad_insert();
}
node& k = convert_to_node(key, pMemory);
+18 -16
View File
@@ -16,6 +16,8 @@
#include <string>
namespace YAML {
[[noreturn]] extern void throw_invalid_node(const std::string& key);
[[noreturn]] extern void throw_bad_conversion(const YAML::Mark& mark);
inline Node::Node()
: m_isValid(true), m_invalidKey{}, m_pMemory(nullptr), m_pNode(nullptr) {}
@@ -57,7 +59,7 @@ inline Node::~Node() = default;
inline void Node::EnsureNodeExists() const {
if (!m_isValid)
throw InvalidNode(m_invalidKey);
throw_invalid_node(m_invalidKey);
if (!m_pNode) {
m_pMemory.reset(new detail::memory_holder);
m_pNode = &m_pMemory->create_node();
@@ -74,14 +76,14 @@ inline bool Node::IsDefined() const {
inline Mark Node::Mark() const {
if (!m_isValid) {
throw InvalidNode(m_invalidKey);
throw_invalid_node(m_invalidKey);
}
return m_pNode ? m_pNode->mark() : Mark::null_mark();
}
inline NodeType::value Node::Type() const {
if (!m_isValid)
throw InvalidNode(m_invalidKey);
throw_invalid_node(m_invalidKey);
return m_pNode ? m_pNode->type() : NodeType::Null;
}
@@ -125,12 +127,12 @@ struct as_if<T, void> {
T operator()() const {
if (!node.m_pNode)
throw TypedBadConversion<T>(node.Mark());
throw_bad_conversion(node.Mark()); // <T>
T t;
if (convert<T>::decode(node, t))
return t;
throw TypedBadConversion<T>(node.Mark());
throw_bad_conversion(node.Mark()); // <T>
}
};
@@ -143,7 +145,7 @@ struct as_if<std::string, void> {
if (node.Type() == NodeType::Null)
return "null";
if (node.Type() != NodeType::Scalar)
throw TypedBadConversion<std::string>(node.Mark());
throw_bad_conversion(node.Mark()); // <std::string>
return node.Scalar();
}
};
@@ -152,7 +154,7 @@ struct as_if<std::string, void> {
template <typename T>
inline T Node::as() const {
if (!m_isValid)
throw InvalidNode(m_invalidKey);
throw_invalid_node(m_invalidKey);
return as_if<T, void>(*this)();
}
@@ -165,13 +167,13 @@ inline T Node::as(const S& fallback) const {
inline const std::string& Node::Scalar() const {
if (!m_isValid)
throw InvalidNode(m_invalidKey);
throw_invalid_node(m_invalidKey);
return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar();
}
inline const std::string& Node::Tag() const {
if (!m_isValid)
throw InvalidNode(m_invalidKey);
throw_invalid_node(m_invalidKey);
return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar();
}
@@ -182,7 +184,7 @@ inline void Node::SetTag(const std::string& tag) {
inline EmitterStyle::value Node::Style() const {
if (!m_isValid)
throw InvalidNode(m_invalidKey);
throw_invalid_node(m_invalidKey);
return m_pNode ? m_pNode->style() : EmitterStyle::Default;
}
@@ -194,7 +196,7 @@ inline void Node::SetStyle(EmitterStyle::value style) {
// assignment
inline bool Node::is(const Node& rhs) const {
if (!m_isValid || !rhs.m_isValid)
throw InvalidNode(m_invalidKey);
throw_invalid_node(m_invalidKey);
if (!m_pNode || !rhs.m_pNode)
return false;
return m_pNode->is(*rhs.m_pNode);
@@ -215,7 +217,7 @@ inline Node& Node::operator=(const Node& rhs) {
inline void Node::reset(const YAML::Node& rhs) {
if (!m_isValid || !rhs.m_isValid)
throw InvalidNode(m_invalidKey);
throw_invalid_node(m_invalidKey);
m_pMemory = rhs.m_pMemory;
m_pNode = rhs.m_pNode;
}
@@ -223,7 +225,7 @@ inline void Node::reset(const YAML::Node& rhs) {
template <typename T>
inline void Node::Assign(const T& rhs) {
if (!m_isValid)
throw InvalidNode(m_invalidKey);
throw_invalid_node(m_invalidKey);
AssignData(convert<T>::encode(rhs));
}
@@ -253,7 +255,7 @@ inline void Node::AssignData(const Node& rhs) {
inline void Node::AssignNode(const Node& rhs) {
if (!m_isValid)
throw InvalidNode(m_invalidKey);
throw_invalid_node(m_invalidKey);
rhs.EnsureNodeExists();
if (!m_pNode) {
@@ -270,7 +272,7 @@ inline void Node::AssignNode(const Node& rhs) {
// size/iterator
inline std::size_t Node::size() const {
if (!m_isValid)
throw InvalidNode(m_invalidKey);
throw_invalid_node(m_invalidKey);
return m_pNode ? m_pNode->size() : 0;
}
@@ -303,7 +305,7 @@ inline iterator Node::end() {
template <typename T>
inline void Node::push_back(const T& rhs) {
if (!m_isValid)
throw InvalidNode(m_invalidKey);
throw_invalid_node(m_invalidKey);
push_back(Node(rhs));
}
+20
View File
@@ -17,4 +17,24 @@ BadPushback::~BadPushback() YAML_CPP_NOEXCEPT = default;
BadInsert::~BadInsert() YAML_CPP_NOEXCEPT = default;
EmitterException::~EmitterException() YAML_CPP_NOEXCEPT = default;
BadFile::~BadFile() YAML_CPP_NOEXCEPT = default;
[[noreturn]] void throw_bad_subscript(const YAML::Mark& mark)
{
throw BadSubscript(mark, std::string{});
}
[[noreturn]] void throw_invalid_node(const std::string& key)
{
throw InvalidNode(key);
}
[[noreturn]] void throw_bad_conversion(const YAML::Mark& mark)
{
throw BadConversion(mark);
}
[[noreturn]] void throw_bad_insert()
{
throw BadInsert();
}
} // namespace YAML
+1 -1
View File
@@ -33,7 +33,7 @@ target_include_directories(yaml-cpp-tests
target_compile_options(yaml-cpp-tests
PRIVATE
$<$<CXX_COMPILER_ID:Clang>:-Wno-c99-extensions -Wno-variadic-macros -Wno-sign-compare>
$<$<CXX_COMPILER_ID:GNU>:-Wno-variadic-macros -Wno-sign-compare>)
$<$<CXX_COMPILER_ID:GNU>:-Wno-variadic-macros -Wno-sign-compare -Wno-narrowing>)
target_link_libraries(yaml-cpp-tests
PRIVATE
Threads::Threads