Skip to content

Commit

Permalink
[FEAT] Use single header yaml parser mini-yaml (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
acezen authored Apr 21, 2023
1 parent 80cb7e7 commit 02234f6
Show file tree
Hide file tree
Showing 10 changed files with 3,579 additions and 148 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "testing"]
path = testing
url = https://github.com/GraphScope/gar-test.git
[submodule "cpp/thirdparty/yaml-cpp"]
path = cpp/thirdparty/yaml-cpp
url = https://github.com/jbeder/yaml-cpp.git
[submodule "cpp/thirdparty/Catch2"]
path = cpp/thirdparty/Catch2
url = https://github.com/catchorg/Catch2.git
22 changes: 13 additions & 9 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -409,27 +409,31 @@ SOFTWARE.

-------------------------------------------------------------------------------

thirdparty/yaml-cpp: MIT License
thirdparty/mini-yaml is referred from jimmiebergmann/mini-yaml project,
which is licensed under MIT License.

Copyright (c) 2008-2015 Jesse Beder.
MIT License

Copyright(c) 2018 Jimmie Bergmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
furnished to do so, subject to the following conditions :

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


-------------------------------------------------------------------------------

Expand Down
10 changes: 2 additions & 8 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ endmacro()
# building or find third party library
# ------------------------------------------------------------------------------
find_package(Threads REQUIRED)
find_yaml_cpp()
find_package(OpenSSL QUIET)
if (APPLE)
find_package(curl REQUIRED)
Expand Down Expand Up @@ -178,28 +177,23 @@ endmacro()
# generate gar library
# ------------------------------------------------------------------------------
macro(build_gar)
file(GLOB_RECURSE CORE_SRC_FILES "src/*.cc")
file(GLOB_RECURSE CORE_SRC_FILES "src/*.cc" ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/mini-yaml/yaml/*.cpp)
add_library(gar SHARED ${CORE_SRC_FILES})
install_gar_target(gar)
target_compile_features(gar PRIVATE cxx_std_17)
target_include_directories(gar PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/yaml-cpp/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/mini-yaml>
)
target_include_directories(gar SYSTEM BEFORE PRIVATE ${GAR_ARROW_INCLUDE_DIR})
target_link_libraries(gar PRIVATE Threads::Threads ${CMAKE_DL_LIBS})

# make sure `libyaml-cpp.a` built first
add_dependencies(gar yaml-cpp)
get_target_location(YAML_CPP_LIBRARY_LOCATION yaml-cpp)
if(APPLE)
target_link_libraries(gar PRIVATE -Wl,-force_load gar_arrow_static
"${YAML_CPP_LIBRARY_LOCATION}"
"${GAR_PARQUET_STATIC_LIB}"
"${GAR_ARROW_BUNDLED_DEPS_STATIC_LIB}")
else()
target_link_libraries(gar PRIVATE -Wl,--exclude-libs,ALL -Wl,--whole-archive gar_arrow_static
"${YAML_CPP_LIBRARY_LOCATION}"
"${GAR_PARQUET_STATIC_LIB}"
"${GAR_ARROW_BUNDLED_DEPS_STATIC_LIB}" -Wl,--no-whole-archive)
endif()
Expand Down
19 changes: 6 additions & 13 deletions cpp/include/gar/utils/yaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ limitations under the License.
#include "gar/utils/result.h"

// forward declaration
namespace YAML {
namespace Yaml {
class Node;
}

namespace GAR_NAMESPACE_INTERNAL {

/** A wrapper of YAML::Node to provide functions to parse yaml. */
/** A wrapper of ::Yaml::Node to provide functions to parse yaml. */
class Yaml {
public:
explicit Yaml(std::shared_ptr<YAML::Node> root_node)
explicit Yaml(std::shared_ptr<::Yaml::Node> root_node)
: root_node_(root_node) {}

~Yaml() = default;

const YAML::Node operator[](const std::string& key) const;
const ::Yaml::Node operator[](const std::string& key) const;

/**
* Loads the input string as Yaml instance.
Expand All @@ -46,19 +46,12 @@ class Yaml {
*/
static Result<std::shared_ptr<Yaml>> Load(const std::string& input);

/**
* Loads the input string as Yaml instance.
*
* Return Status::YamlError if input string can not be loaded(malformed).
*/
static Result<std::shared_ptr<Yaml>> Load(const char* input);

/**
* Loads the input stream as Yaml instance.
*
* Return Status::YamlError if input string can not be loaded(malformed).
*/
static Result<std::shared_ptr<Yaml>> Load(std::istream& input);
static Result<std::shared_ptr<Yaml>> Load(std::iostream& input);

/**
* Loads the input file as a single Yaml instance.
Expand All @@ -68,7 +61,7 @@ class Yaml {
static Result<std::shared_ptr<Yaml>> LoadFile(const std::string& file_name);

private:
std::shared_ptr<YAML::Node> root_node_;
std::shared_ptr<::Yaml::Node> root_node_;
};

} // namespace GAR_NAMESPACE_INTERNAL
Expand Down
Loading

0 comments on commit 02234f6

Please sign in to comment.