Refactor and add checking for conditions

main
Duncan Ogilvie 3 years ago
parent 9f9934e9a5
commit 6809e8da41

@ -4,10 +4,10 @@
#include "project_parser.hpp" #include "project_parser.hpp"
#include "fs.hpp" #include "fs.hpp"
#include <sstream>
#include <cstddef> #include <cstddef>
#include <stdexcept>
#include <cstdlib> #include <cstdlib>
#include <sstream>
#include <stdexcept>
#include <system_error> #include <system_error>
namespace cmkr { namespace cmkr {

@ -2,6 +2,7 @@
#include "enum_helper.hpp" #include "enum_helper.hpp"
#include "fs.hpp" #include "fs.hpp"
#include <deque>
#include <stdexcept> #include <stdexcept>
#include <toml.hpp> #include <toml.hpp>
#include <tsl/ordered_map.h> #include <tsl/ordered_map.h>
@ -34,35 +35,32 @@ static EnumType to_enum(const std::string &str, const std::string &help_name) {
return value; return value;
} }
template <typename T> static std::string format_key_error(const std::string &error, const toml::key &ky, const TomlBasicValue &value) {
static void get_optional(const TomlBasicValue &v, const toml::key &ky, T &destination); auto loc = value.location();
auto line_number_str = std::to_string(loc.line());
template <typename T> auto line_width = line_number_str.length();
static void get_optional(const TomlBasicValue &v, const toml::key &ky, Condition<T> &destination) { auto line_str = loc.line_str();
// TODO: this algorithm in O(n) over the amount of keys, kinda bad
const auto &table = v.as_table(); std::ostringstream oss;
for (const auto &itr : table) { oss << "[error] " << error << '\n';
const auto &key = itr.first; oss << " --> " << loc.file_name() << '\n';
const auto &value = itr.second;
if (value.is_table()) { oss << std::string(line_width + 2, ' ') << "|\n";
if (value.contains(ky)) { oss << ' ' << line_number_str << " | " << line_str << '\n';
destination[key] = toml::find<T>(value, ky);
}
} else if (key == ky) {
destination[""] = toml::find<T>(v, ky);
}
}
}
template <typename T> oss << std::string(line_width + 2, ' ') << '|';
static void get_optional(const TomlBasicValue &v, const toml::key &ky, T &destination) { auto key_start = line_str.substr(0, loc.column() - 1).rfind(ky);
// TODO: this currently doesn't allow you to get an optional map<string, X> if (key_start == std::string::npos) {
if (v.contains(ky)) { key_start = line_str.find(ky);
destination = toml::find<T>(v, ky);
} }
if (key_start != std::string::npos) {
oss << std::string(key_start + 1, ' ') << std::string(ky.length(), '~');
}
oss << '\n';
return oss.str();
} }
// TODO: construct this from a helper class with state so all the checking can be done implicitly
class TomlChecker { class TomlChecker {
const TomlBasicValue &m_v; const TomlBasicValue &m_v;
tsl::ordered_set<toml::key> m_visited; tsl::ordered_set<toml::key> m_visited;
@ -72,13 +70,25 @@ class TomlChecker {
TomlChecker(const TomlBasicValue &v, const toml::key &ky) : m_v(toml::find(v, ky)) {} TomlChecker(const TomlBasicValue &v, const toml::key &ky) : m_v(toml::find(v, ky)) {}
TomlChecker(const TomlBasicValue &v) : m_v(v) {} TomlChecker(const TomlBasicValue &v) : m_v(v) {}
TomlChecker(const TomlChecker &) = delete; TomlChecker(const TomlChecker &) = delete;
TomlChecker(TomlChecker &&) = delete;
~TomlChecker() noexcept(false) {}
// TOOD: check if the condition is valid during the parsing stage to print better errors!
template <typename T> template <typename T>
void optional(const toml::key &ky, Condition<T> &destination) { void optional(const toml::key &ky, Condition<T> &destination) {
get_optional(m_v, ky, destination); // TODO: this algorithm in O(n) over the amount of keys, kinda bad
const auto &table = m_v.as_table();
for (const auto &itr : table) {
const auto &key = itr.first;
const auto &value = itr.second;
if (value.is_table()) {
if (value.contains(ky)) {
destination[key] = toml::find<T>(value, ky);
}
} else if (key == ky) {
destination[""] = toml::find<T>(m_v, ky);
}
}
// Handle visiting logic
for (const auto &itr : destination) { for (const auto &itr : destination) {
if (!itr.first.empty()) { if (!itr.first.empty()) {
m_conditionVisited.emplace(itr.first); m_conditionVisited.emplace(itr.first);
@ -102,384 +112,394 @@ class TomlChecker {
visit(ky); visit(ky);
} }
void visit(const toml::key &ky) { m_visited.insert(ky); } bool contains(const toml::key &ky) {
visit(ky);
std::string format_unknown_key(const toml::key &ky, const TomlBasicValue &value) { return m_v.contains(ky);
auto loc = value.location(); }
auto line_number_str = std::to_string(loc.line());
auto line_width = line_number_str.length();
auto line_str = loc.line_str();
std::ostringstream oss;
oss << "[error] Unknown key: " << ky << '\n';
oss << " --> " << loc.file_name() << '\n';
oss << std::string(line_width + 2, ' ') << "|\n";
oss << ' ' << line_number_str << " | " << line_str << '\n';
oss << std::string(line_width + 2, ' ') << '|';
auto key_start = line_str.find_last_of(ky, loc.column());
if (key_start != std::string::npos) {
oss << std::string(key_start - ky.length() + 2, ' ') << std::string(ky.length(), '~');
}
oss << '\n';
return oss.str(); const TomlBasicValue &find(const toml::key &ky) {
visit(ky);
return toml::find(m_v, ky);
} }
void check() { void visit(const toml::key &ky) { m_visited.insert(ky); }
void check(const tsl::ordered_map<std::string, std::string> &conditions) const {
for (const auto &itr : m_v.as_table()) { for (const auto &itr : m_v.as_table()) {
const auto &ky = itr.first; const auto &ky = itr.first;
if (m_conditionVisited.count(ky)) { if (m_conditionVisited.contains(ky)) {
// TODO: check if condition (ky) exists if (!conditions.contains(ky)) {
throw std::runtime_error(format_key_error("Unknown condition '" + ky + "'", ky, itr.second));
}
for (const auto &jtr : itr.second.as_table()) { for (const auto &jtr : itr.second.as_table()) {
if (m_visited.count(jtr.first) == 0) { if (!m_visited.contains(jtr.first)) {
throw std::runtime_error(format_unknown_key(jtr.first, jtr.second)); throw std::runtime_error(format_key_error("Unknown key '" + jtr.first + "'", jtr.first, jtr.second));
} }
} }
} else if (m_visited.count(ky) == 0) { } else if (!m_visited.contains(ky)) {
if (itr.second.is_table()) { if (itr.second.is_table()) {
for (const auto &jtr : itr.second.as_table()) { for (const auto &jtr : itr.second.as_table()) {
if (m_visited.count(jtr.first) == 0) { if (!m_visited.contains(jtr.first)) {
throw std::runtime_error(format_unknown_key(jtr.first, jtr.second)); throw std::runtime_error(format_key_error("Unknown key '" + jtr.first + "'", jtr.first, jtr.second));
} }
} }
} }
throw std::runtime_error(format_unknown_key(ky, itr.second)); throw std::runtime_error(format_key_error("Unknown key '" + ky + "'", ky, itr.second));
} }
} }
} }
}; };
class TomlCheckerRoot {
std::deque<TomlChecker> m_checkers;
bool m_checked = false;
public:
TomlCheckerRoot() = default;
TomlCheckerRoot(const TomlCheckerRoot &) = delete;
TomlCheckerRoot(TomlCheckerRoot &&) = delete;
TomlChecker &create(const TomlBasicValue &v) {
m_checkers.emplace_back(v);
return m_checkers.back();
}
TomlChecker &create(const TomlBasicValue &v, const toml::key &ky) {
m_checkers.emplace_back(v, ky);
return m_checkers.back();
}
void check(const tsl::ordered_map<std::string, std::string> &conditions) {
for (const auto &checker : m_checkers) {
checker.check(conditions);
}
}
};
Project::Project(const Project *parent, const std::string &path, bool build) { Project::Project(const Project *parent, const std::string &path, bool build) {
const auto toml_path = fs::path(path) / "cmake.toml"; const auto toml_path = fs::path(path) / "cmake.toml";
if (!fs::exists(toml_path)) { if (!fs::exists(toml_path)) {
throw std::runtime_error("No cmake.toml was found!"); throw std::runtime_error("No cmake.toml was found!");
} }
const auto toml = toml::parse<toml::preserve_comments, tsl::ordered_map, std::vector>(toml_path.string()); const auto toml = toml::parse<toml::preserve_comments, tsl::ordered_map, std::vector>(toml_path.string());
// TODO: TomlChecker for the "cmake" section
if (build) {
if (toml.contains("cmake")) {
const auto &cmake = toml::find(toml, "cmake");
if (cmake.contains("bin-dir")) { TomlCheckerRoot checker;
throw std::runtime_error("bin-dir has been renamed to build-dir");
}
get_optional(cmake, "build-dir", build_dir); if (toml.contains("cmake")) {
get_optional(cmake, "generator", generator); auto &cmake = checker.create(toml, "cmake");
get_optional(cmake, "config", config);
get_optional(cmake, "arguments", gen_args); cmake.required("version", cmake_version);
get_optional(cmake, "allow-in-tree", allow_in_tree);
} if (cmake.contains("bin-dir")) {
} else { throw std::runtime_error("bin-dir has been renamed to build-dir");
// Reasonable default conditions (you can override these if you desire)
if (parent == nullptr) {
conditions["windows"] = R"cmake(WIN32)cmake";
conditions["macos"] = R"cmake(CMAKE_SYSTEM_NAME MATCHES "Darwin")cmake";
conditions["unix"] = R"cmake(UNIX)cmake";
conditions["bsd"] = R"cmake(CMAKE_SYSTEM_NAME MATCHES "BSD")cmake";
conditions["linux"] = conditions["lunix"] = R"cmake(CMAKE_SYSTEM_NAME MATCHES "Linux")cmake";
conditions["gcc"] = R"cmake(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")cmake";
conditions["clang"] = R"cmake(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "Clang")cmake";
conditions["msvc"] = R"cmake(MSVC)cmake";
} else {
conditions = parent->conditions;
} }
if (toml.contains("conditions")) { cmake.optional("build-dir", build_dir);
auto conds = toml::find<decltype(conditions)>(toml, "conditions"); cmake.optional("generator", generator);
for (const auto &cond : conds) { cmake.optional("config", config);
conditions[cond.first] = cond.second; cmake.optional("arguments", gen_args);
cmake.optional("allow-in-tree", allow_in_tree);
if (cmake.contains("cmkr-include")) {
const auto &cmkr_include_kv = cmake.find("cmkr-include");
if (cmkr_include_kv.is_string()) {
cmkr_include = cmkr_include_kv.as_string();
} else {
// Allow disabling this feature with cmkr-include = false
cmkr_include = "";
} }
} }
// TODO: make TomlCheckerFactory cmake.optional("cpp-flags", cppflags);
// .check() only once (at the end) cmake.optional("c-flags", cflags);
cmake.optional("link-flags", linkflags);
}
if (toml.contains("cmake")) { // Skip the rest of the parsing when building
const auto &cmake = toml::find(toml, "cmake"); if (build) {
cmake_version = toml::find(cmake, "version").as_string(); checker.check(conditions);
if (cmake.contains("cmkr-include")) { return;
const auto &cmkr_include_kv = toml::find(cmake, "cmkr-include"); }
if (cmkr_include_kv.is_string()) {
cmkr_include = cmkr_include_kv.as_string(); // Reasonable default conditions (you can override these if you desire)
} else { if (parent == nullptr) {
// Allow disabling this feature with cmkr-include = false conditions["windows"] = R"cmake(WIN32)cmake";
cmkr_include = ""; conditions["macos"] = R"cmake(CMAKE_SYSTEM_NAME MATCHES "Darwin")cmake";
} conditions["unix"] = R"cmake(UNIX)cmake";
} conditions["bsd"] = R"cmake(CMAKE_SYSTEM_NAME MATCHES "BSD")cmake";
get_optional(cmake, "cpp-flags", cppflags); conditions["linux"] = conditions["lunix"] = R"cmake(CMAKE_SYSTEM_NAME MATCHES "Linux")cmake";
get_optional(cmake, "c-flags", cflags); conditions["gcc"] = R"cmake(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")cmake";
get_optional(cmake, "link-flags", linkflags); conditions["clang"] = R"cmake(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "Clang")cmake";
} conditions["msvc"] = R"cmake(MSVC)cmake";
} else {
conditions = parent->conditions;
}
if (toml.contains("project")) { if (toml.contains("conditions")) {
TomlChecker project(toml, "project"); auto conds = toml::find<decltype(conditions)>(toml, "conditions");
project.required("name", project_name); for (const auto &cond : conds) {
project.optional("version", project_version); conditions[cond.first] = cond.second;
project.optional("description", project_description);
project.optional("languages", project_languages);
project.optional("cmake-before", cmake_before);
project.optional("cmake-after", cmake_after);
project.optional("include-before", include_before);
project.optional("include-after", include_after);
project.optional("subdirs", project_subdirs);
project.check();
} }
}
if (toml.contains("subdir")) { if (toml.contains("project")) {
const auto &subs = toml::find(toml, "subdir").as_table(); auto &project = checker.create(toml, "project");
for (const auto &itr : subs) { project.required("name", project_name);
Subdir subdir; project.optional("version", project_version);
subdir.name = itr.first; project.optional("description", project_description);
project.optional("languages", project_languages);
TomlChecker sub(itr.second); project.optional("cmake-before", cmake_before);
sub.optional("condition", subdir.condition); project.optional("cmake-after", cmake_after);
sub.optional("cmake-before", subdir.cmake_before); project.optional("include-before", include_before);
sub.optional("cmake-after", subdir.cmake_after); project.optional("include-after", include_after);
sub.optional("include-before", subdir.include_before); project.optional("subdirs", project_subdirs);
sub.optional("include-after", subdir.include_after); }
sub.check();
if (toml.contains("subdir")) {
subdirs.push_back(subdir); const auto &subs = toml::find(toml, "subdir").as_table();
} for (const auto &itr : subs) {
Subdir subdir;
subdir.name = itr.first;
auto &sub = checker.create(itr.second);
sub.optional("condition", subdir.condition);
sub.optional("cmake-before", subdir.cmake_before);
sub.optional("cmake-after", subdir.cmake_after);
sub.optional("include-before", subdir.include_before);
sub.optional("include-after", subdir.include_after);
subdirs.push_back(subdir);
} }
}
if (toml.contains("settings")) { if (toml.contains("settings")) {
using set_map = std::map<std::string, TomlBasicValue>; using set_map = std::map<std::string, TomlBasicValue>;
const auto &sets = toml::find<set_map>(toml, "settings"); const auto &sets = toml::find<set_map>(toml, "settings");
for (const auto &itr : sets) { for (const auto &itr : sets) {
Setting s; Setting s;
s.name = itr.first; s.name = itr.first;
const auto &value = itr.second; const auto &value = itr.second;
if (value.is_boolean()) { if (value.is_boolean()) {
s.val = value.as_boolean(); s.val = value.as_boolean();
} else if (value.is_string()) { } else if (value.is_string()) {
s.val = value.as_string(); s.val = value.as_string();
} else { } else {
TomlChecker setting(value); auto &setting = checker.create(value);
setting.optional("comment", s.comment); setting.optional("comment", s.comment);
setting.visit("value"); if (setting.contains("value")) {
if (value.contains("value")) { const auto &v = setting.find("value");
auto v = toml::find(value, "value"); if (v.is_boolean()) {
if (v.is_boolean()) { s.val = v.as_boolean();
s.val = v.as_boolean(); } else {
} else { s.val = v.as_string();
s.val = v.as_string();
}
} }
setting.optional("cache", s.cache);
setting.optional("force", s.force);
setting.check();
} }
settings.push_back(s); setting.optional("cache", s.cache);
setting.optional("force", s.force);
} }
settings.push_back(s);
} }
}
if (toml.contains("options")) { if (toml.contains("options")) {
using opts_map = tsl::ordered_map<std::string, TomlBasicValue>; using opts_map = tsl::ordered_map<std::string, TomlBasicValue>;
const auto &opts = toml::find<opts_map>(toml, "options"); const auto &opts = toml::find<opts_map>(toml, "options");
for (const auto &itr : opts) { for (const auto &itr : opts) {
Option o; Option o;
o.name = itr.first; o.name = itr.first;
const auto &value = itr.second; const auto &value = itr.second;
if (value.is_boolean()) { if (value.is_boolean()) {
o.val = value.as_boolean(); o.val = value.as_boolean();
} else { } else {
TomlChecker option(value); auto &option = checker.create(value);
option.optional("comment", o.comment); option.optional("comment", o.comment);
option.optional("value", o.val); option.optional("value", o.val);
option.check();
}
options.push_back(o);
} }
options.push_back(o);
} }
}
if (toml.contains("find-package")) { if (toml.contains("find-package")) {
using pkg_map = tsl::ordered_map<std::string, TomlBasicValue>; using pkg_map = tsl::ordered_map<std::string, TomlBasicValue>;
const auto &pkgs = toml::find<pkg_map>(toml, "find-package"); const auto &pkgs = toml::find<pkg_map>(toml, "find-package");
for (const auto &itr : pkgs) { for (const auto &itr : pkgs) {
Package p; Package p;
p.name = itr.first; p.name = itr.first;
const auto &value = itr.second; const auto &value = itr.second;
if (itr.second.is_string()) { if (itr.second.is_string()) {
p.version = itr.second.as_string(); p.version = itr.second.as_string();
} else { } else {
TomlChecker pkg(value); auto &pkg = checker.create(value);
pkg.optional("version", p.version); pkg.optional("version", p.version);
pkg.optional("required", p.required); pkg.optional("required", p.required);
pkg.optional("config", p.config); pkg.optional("config", p.config);
pkg.optional("components", p.components); pkg.optional("components", p.components);
pkg.check();
}
packages.push_back(p);
} }
packages.push_back(p);
} }
}
if (toml.contains("fetch-content")) { // TODO: perform checking here
const auto &fc = toml::find(toml, "fetch-content").as_table(); if (toml.contains("fetch-content")) {
for (const auto &itr : fc) { const auto &fc = toml::find(toml, "fetch-content").as_table();
Content content; for (const auto &itr : fc) {
content.name = itr.first; Content content;
for (const auto &argItr : itr.second.as_table()) { content.name = itr.first;
auto key = argItr.first; for (const auto &argItr : itr.second.as_table()) {
if (key == "git") { auto key = argItr.first;
key = "GIT_REPOSITORY"; if (key == "git") {
} else if (key == "tag") { key = "GIT_REPOSITORY";
key = "GIT_TAG"; } else if (key == "tag") {
} else if (key == "svn") { key = "GIT_TAG";
key = "SVN_REPOSITORY"; } else if (key == "svn") {
} else if (key == "rev") { key = "SVN_REPOSITORY";
key = "SVN_REVISION"; } else if (key == "rev") {
} else if (key == "url") { key = "SVN_REVISION";
key = "URL"; } else if (key == "url") {
} else if (key == "hash") { key = "URL";
key = "URL_HASH"; } else if (key == "hash") {
} else { key = "URL_HASH";
// don't change arg } else {
} // don't change arg
content.arguments.emplace(key, argItr.second.as_string());
} }
contents.emplace_back(std::move(content)); content.arguments.emplace(key, argItr.second.as_string());
} }
contents.emplace_back(std::move(content));
} }
}
if (toml.contains("bin")) { if (toml.contains("bin")) {
throw std::runtime_error("[[bin]] has been renamed to [[target]]"); throw std::runtime_error("[[bin]] has been renamed to [[target]]");
} }
if (toml.contains("target")) { if (toml.contains("target")) {
const auto &ts = toml::find(toml, "target").as_table(); const auto &ts = toml::find(toml, "target").as_table();
for (const auto &itr : ts) { for (const auto &itr : ts) {
const auto &value = itr.second; const auto &value = itr.second;
Target target; Target target;
target.name = itr.first; target.name = itr.first;
TomlChecker t(value); auto &t = checker.create(value);
std::string type; std::string type;
t.required("type", type); t.required("type", type);
target.type = to_enum<TargetType>(type, "target type"); target.type = to_enum<TargetType>(type, "target type");
t.optional("headers", target.headers); t.optional("headers", target.headers);
t.optional("sources", target.sources); t.optional("sources", target.sources);
t.optional("compile-definitions", target.compile_definitions); t.optional("compile-definitions", target.compile_definitions);
t.optional("private-compile-definitions", target.private_compile_definitions); t.optional("private-compile-definitions", target.private_compile_definitions);
t.optional("compile-features", target.compile_features); t.optional("compile-features", target.compile_features);
t.optional("private-compile-features", target.private_compile_features); t.optional("private-compile-features", target.private_compile_features);
t.optional("compile-options", target.compile_options); t.optional("compile-options", target.compile_options);
t.optional("private-compile-options", target.private_compile_options); t.optional("private-compile-options", target.private_compile_options);
t.optional("include-directories", target.include_directories); t.optional("include-directories", target.include_directories);
t.optional("private-include-directories", target.private_include_directories); t.optional("private-include-directories", target.private_include_directories);
t.optional("link-directories", target.link_directories); t.optional("link-directories", target.link_directories);
t.optional("private-link-directories", target.private_link_directories); t.optional("private-link-directories", target.private_link_directories);
t.optional("link-libraries", target.link_libraries); t.optional("link-libraries", target.link_libraries);
t.optional("private-link-libraries", target.private_link_libraries); t.optional("private-link-libraries", target.private_link_libraries);
t.optional("link-options", target.link_options); t.optional("link-options", target.link_options);
t.optional("private-link-options", target.private_link_options); t.optional("private-link-options", target.private_link_options);
t.optional("precompile-headers", target.precompile_headers); t.optional("precompile-headers", target.precompile_headers);
t.optional("private-precompile-headers", target.private_precompile_headers); t.optional("private-precompile-headers", target.private_precompile_headers);
if (!target.headers.empty()) { if (!target.headers.empty()) {
auto &sources = target.sources.nth(0).value(); auto &sources = target.sources.nth(0).value();
const auto &headers = target.headers.nth(0)->second; const auto &headers = target.headers.nth(0)->second;
sources.insert(sources.end(), headers.begin(), headers.end()); sources.insert(sources.end(), headers.begin(), headers.end());
} }
t.optional("condition", target.condition); t.optional("condition", target.condition);
t.optional("alias", target.alias); t.optional("alias", target.alias);
t.visit("properties"); if (t.contains("properties")) {
if (value.contains("properties")) { auto store_property = [&target](const toml::key &k, const TomlBasicValue &v, const std::string &condition) {
auto store_property = [&target](const toml::key &k, const TomlBasicValue &v, const std::string &condition) { if (v.is_array()) {
if (v.is_array()) { std::string property_list;
std::string property_list; for (const auto &list_val : v.as_array()) {
for (const auto &list_val : v.as_array()) { if (!property_list.empty()) {
if (!property_list.empty()) { property_list += ';';
property_list += ';';
}
property_list += list_val.as_string();
} }
target.properties[condition][k] = property_list; property_list += list_val.as_string();
} else if (v.is_boolean()) {
target.properties[condition][k] = v.as_boolean() ? "ON" : "OFF";
} else {
target.properties[condition][k] = v.as_string();
} }
}; target.properties[condition][k] = property_list;
} else if (v.is_boolean()) {
const auto &props = toml::find(value, "properties").as_table(); target.properties[condition][k] = v.as_boolean() ? "ON" : "OFF";
for (const auto &propKv : props) { } else {
const auto &k = propKv.first; target.properties[condition][k] = v.as_string();
const auto &v = propKv.second; }
if (v.is_table()) { };
for (const auto &condKv : v.as_table()) {
store_property(condKv.first, condKv.second, k); const auto &props = t.find("properties").as_table();
} for (const auto &propKv : props) {
} else { const auto &k = propKv.first;
store_property(k, v, ""); const auto &v = propKv.second;
if (v.is_table()) {
for (const auto &condKv : v.as_table()) {
store_property(condKv.first, condKv.second, k);
} }
} else {
store_property(k, v, "");
} }
} }
}
t.optional("cmake-before", target.cmake_before); t.optional("cmake-before", target.cmake_before);
t.optional("cmake-after", target.cmake_after); t.optional("cmake-after", target.cmake_after);
t.optional("include-before", target.include_before); t.optional("include-before", target.include_before);
t.optional("include-after", target.include_after); t.optional("include-after", target.include_after);
t.check();
targets.push_back(target); targets.push_back(target);
}
} }
}
if (toml.contains("test")) { if (toml.contains("test")) {
const auto &ts = toml::find(toml, "test").as_array(); const auto &ts = toml::find(toml, "test").as_array();
for (const auto &value : ts) { for (const auto &value : ts) {
TomlChecker t(value); auto &t = checker.create(value);
Test test; Test test;
t.required("name", test.name); t.required("name", test.name);
t.optional("configurations", test.configurations); t.optional("configurations", test.configurations);
t.optional("working-directory", test.working_directory); t.optional("working-directory", test.working_directory);
t.required("command", test.command); t.required("command", test.command);
t.optional("arguments", test.arguments); t.optional("arguments", test.arguments);
t.check(); tests.push_back(test);
tests.push_back(test);
}
} }
}
if (toml.contains("install")) { if (toml.contains("install")) {
const auto &is = toml::find(toml, "install").as_array(); const auto &is = toml::find(toml, "install").as_array();
for (const auto &value : is) { for (const auto &value : is) {
TomlChecker i(value); auto &i = checker.create(value);
Install inst; Install inst;
i.optional("targets", inst.targets); i.optional("targets", inst.targets);
i.optional("files", inst.files); i.optional("files", inst.files);
i.optional("dirs", inst.dirs); i.optional("dirs", inst.dirs);
i.optional("configs", inst.configs); i.optional("configs", inst.configs);
i.required("destination", inst.destination); i.required("destination", inst.destination);
i.check(); installs.push_back(inst);
installs.push_back(inst);
}
} }
}
if (toml.contains("vcpkg")) { if (toml.contains("vcpkg")) {
TomlChecker v(toml, "vcpkg"); auto &v = checker.create(toml, "vcpkg");
v.optional("url", vcpkg.url); v.optional("url", vcpkg.url);
v.optional("version", vcpkg.version); v.optional("version", vcpkg.version);
v.required("packages", vcpkg.packages); v.required("packages", vcpkg.packages);
v.check();
}
} }
checker.check(conditions);
} }
bool is_root_path(const std::string &path) { bool is_root_path(const std::string &path) {

Loading…
Cancel
Save