Verified Commit bcd3ebf2 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Use genopts to generate config file schemas

parent ce59dff1
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -188,6 +188,31 @@ FetchContent_Declare(

FetchContent_MakeAvailable(spdlog)

### file_options: required for reading configuration files
message(STATUS "[${PROJECT_NAME}] Downloading and building file_options")
FetchContent_Declare(
  file_options
  GIT_REPOSITORY https://storage.bsc.es/gitlab/utils/file_options
  GIT_TAG b2de92b3755e3391595bb368573b82abed16978d # v0.1.0-pre
  GIT_SHALLOW ON
  GIT_PROGRESS ON
)

FetchContent_MakeAvailable(file_options)

### genopts: required for generating file_options schemas
message(STATUS "[${PROJECT_NAME}] Downloading and building genopts")
FetchContent_Declare(
  genopts
  GIT_REPOSITORY https://storage.bsc.es/gitlab/utils/genopts
  GIT_TAG 1dcef400f8fbc6e1969c856ca844707b730c3002 # v0.1.0-pre
  GIT_SHALLOW ON
  GIT_PROGRESS ON
)

FetchContent_MakeAvailable(genopts)


### Mark any CMake variables imported from {fmt} and spdlog as advanced, so
### that they don't appear in cmake-gui or ccmake. Similarly for FETCHCONTENT
### variables.
+21 −7
Original line number Diff line number Diff line
@@ -26,26 +26,40 @@ add_library(config STATIC)

target_include_directories(
  config PRIVATE ${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}
                 ${CMAKE_CURRENT_BINARY_DIR}
)
set_property(TARGET config PROPERTY POSITION_INDEPENDENT_CODE ON)

configure_file(defaults.cpp.in defaults.cpp)

configure_file(genopts.yml.in genopts.yml @ONLY)

add_custom_command(
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/config_options.hpp
         ${CMAKE_CURRENT_BINARY_DIR}/keywords.hpp
  COMMENT "Generating config_options.hpp, keywords.hpp"
  DEPENDS file_options.yml ${CMAKE_CURRENT_BINARY_DIR}/genopts.yml
  COMMAND
    Genopts::Python3_Interpreter -m genopts --config
    ${CMAKE_CURRENT_BINARY_DIR}/genopts.yml
    ${CMAKE_CURRENT_LIST_DIR}/file_options.yml
)

target_sources(
  config
  PRIVATE config.hpp
        config_schema.hpp
          defaults.hpp
          ${CMAKE_CURRENT_BINARY_DIR}/defaults.cpp
          ${CMAKE_CURRENT_BINARY_DIR}/config_options.hpp
          ${CMAKE_CURRENT_BINARY_DIR}/keywords.hpp
          file_options/file_options.hpp
          file_options/schema.hpp
          file_options/options_description.hpp
          file_options/yaml_parser.hpp
          keywords.hpp
          parsers.cpp
          parsers.hpp
          settings.cpp
          settings.hpp
)

target_link_libraries(config PRIVATE utils YAMLCpp::YAMLCpp)
target_link_libraries(config PRIVATE utils file_options::file_options)

src/config/config_schema.hpp

deleted100644 → 0
+0 −90
Original line number Diff line number Diff line
/******************************************************************************
 * Copyright 2021, Barcelona Supercomputing Center (BSC), Spain
 *
 * This software was partially supported by the EuroHPC-funded project ADMIRE
 *   (Project ID: 956748, https://www.admire-eurohpc.eu).
 *
 * This file is part of scord.
 *
 * scord is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * scord is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with scord.  If not, see <https://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *****************************************************************************/

#ifndef SCORD_CONFIG_SCHEMA_HPP
#define SCORD_CONFIG_SCHEMA_HPP

#include <filesystem>

#include "file_options/file_options.hpp"
#include "parsers.hpp"
#include "keywords.hpp"
#include "defaults.hpp"

namespace fs = std::filesystem;

namespace scord::config {

using file_options::converter;
using file_options::declare_file;
using file_options::declare_group;
using file_options::declare_list;
using file_options::declare_option;
using file_options::file_schema;
using file_options::opt_type;
using file_options::sec_type;

// define the configuration file structure and declare the supported options
const file_schema valid_options = declare_file({
        // section for global settings
        declare_section(
                keywords::global_settings, sec_type::mandatory,
                declare_group({

                        declare_option<bool>(
                                keywords::use_syslog, opt_type::mandatory,
                                converter<bool>(parsers::parse_bool)),

                        declare_option<fs::path>(
                                keywords::log_file, opt_type::optional,
                                converter<fs::path>(parsers::parse_path)),

                        declare_option<uint32_t>(
                                keywords::log_file_max_size, opt_type::optional,
                                converter<uint32_t>(parsers::parse_capacity)),

                        declare_option<std::string>(
                                keywords::transport_protocol,
                                opt_type::mandatory),

                        declare_option<std::string>(keywords::bind_address,
                                                    opt_type::mandatory),

                        declare_option<uint32_t>(
                                keywords::remote_port, opt_type::mandatory,
                                converter<uint32_t>(parsers::parse_number)),

                        declare_option<fs::path>(
                                keywords::pidfile, opt_type::mandatory,
                                converter<fs::path>(parsers::parse_path)),

                        declare_option<uint32_t>(
                                keywords::workers, opt_type::mandatory,
                                converter<uint32_t>(parsers::parse_number)),
                })),
});

} // namespace scord::config

#endif /* SCORD_CONFIG_SCHEMA_HPP */

src/config/keywords.hpp

deleted100644 → 0
+0 −55
Original line number Diff line number Diff line
/******************************************************************************
 * Copyright 2021, Barcelona Supercomputing Center (BSC), Spain
 *
 * This software was partially supported by the EuroHPC-funded project ADMIRE
 *   (Project ID: 956748, https://www.admire-eurohpc.eu).
 *
 * This file is part of scord.
 *
 * scord is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * scord is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with scord.  If not, see <https://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *****************************************************************************/

#ifndef SCORD_CONFIG_KEYWORDS_HPP
#define SCORD_CONFIG_KEYWORDS_HPP

namespace scord::config::keywords {

// section names
constexpr static const auto global_settings = "global_settings";
constexpr static const auto namespaces = "namespaces";

// option names for 'global-settings' section
constexpr static const auto use_syslog = "use_syslog";
constexpr static const auto log_file = "log_file";
constexpr static const auto log_file_max_size = "log_file_max_size";
constexpr static const auto transport_protocol = "transport_protocol";
constexpr static const auto bind_address = "bind_address";
constexpr static const auto remote_port = "remote_port";
constexpr static const auto pidfile = "pidfile";
constexpr static const auto workers = "workers";
constexpr static const auto staging_directory = "staging_directory";

// option names for 'namespaces' section
constexpr static const auto nsid = "nsid";
constexpr static const auto track_contents = "track_contents";
constexpr static const auto mountpoint = "mountpoint";
constexpr static const auto type = "type";
constexpr static const auto capacity = "capacity";
constexpr static const auto visibility = "visibility";

} // namespace scord::config::keywords

#endif /* SCORD_CONFIG_KEYWORDS_HPP */
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@

#include <filesystem>
#include <utility>
#include "config_schema.hpp"
#include "config_options.hpp"
#include "defaults.hpp"
#include "file_options/options_description.hpp"
#include "file_options/yaml_parser.hpp"