config: look up paths relative to config file

This commit is contained in:
Jake Hillion 2023-01-31 08:19:45 -08:00 committed by Jake Hillion
parent fcaede9e7d
commit 23026d80ba
4 changed files with 74 additions and 50 deletions

View File

@ -495,12 +495,13 @@ bool OICompiler::compile(const std::string &code, const fs::path &sourcePath,
for (const auto &path : config.userHeaderPaths) {
headerSearchOptions.AddPath(
path, clang::frontend::IncludeDirGroup::IndexHeaderMap, false, false);
path.c_str(), clang::frontend::IncludeDirGroup::IndexHeaderMap, false,
false);
}
for (const auto &path : config.sysHeaderPaths) {
headerSearchOptions.AddPath(path, clang::frontend::IncludeDirGroup::System,
false, false);
headerSearchOptions.AddPath(
path.c_str(), clang::frontend::IncludeDirGroup::System, false, false);
}
compInv->getFrontendOpts().OutputFile = objectPath;

View File

@ -44,8 +44,8 @@ class OICompiler {
/* Whether to generate DWARF debug info for the JIT code */
bool generateJitDebugInfo = false;
std::vector<std::string> userHeaderPaths{};
std::vector<std::string> sysHeaderPaths{};
std::vector<fs::path> userHeaderPaths{};
std::vector<fs::path> sysHeaderPaths{};
};
/**

View File

@ -20,10 +20,13 @@
#include <boost/algorithm/string/split.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <filesystem>
#include "OICodeGen.h"
#include "OICompiler.h"
namespace fs = std::filesystem;
namespace OIUtils {
using namespace std::literals;
@ -31,6 +34,8 @@ using namespace std::literals;
bool processConfigFile(const std::string& configFilePath,
OICompiler::Config& compilerConfig,
OICodeGen::Config& generatorConfig) {
fs::path configDirectory = fs::path(configFilePath).remove_filename();
toml::table config;
try {
config = toml::parse_file(configFilePath);
@ -44,7 +49,13 @@ bool processConfigFile(const std::string& configFilePath,
if (toml::array* arr = (*types)["containers"].as_array()) {
arr->for_each([&](auto&& el) {
if constexpr (toml::is_string<decltype(el)>) {
generatorConfig.containerConfigPaths.emplace(std::string(el));
/*
The / operator on std::filesystem::path will choose the right path
if the right path is absolute, else append the right path to the
left path.
*/
generatorConfig.containerConfigPaths.emplace(configDirectory /
el.get());
}
});
}
@ -54,14 +65,26 @@ bool processConfigFile(const std::string& configFilePath,
if (toml::array* arr = (*headers)["user_paths"].as_array()) {
arr->for_each([&](auto&& el) {
if constexpr (toml::is_string<decltype(el)>) {
compilerConfig.userHeaderPaths.emplace_back(el);
/*
The / operator on std::filesystem::path will choose the right path
if the right path is absolute, else append the right path to the
left path.
*/
compilerConfig.userHeaderPaths.emplace_back(configDirectory /
el.get());
}
});
}
if (toml::array* arr = (*headers)["system_paths"].as_array()) {
arr->for_each([&](auto&& el) {
if constexpr (toml::is_string<decltype(el)>) {
compilerConfig.sysHeaderPaths.emplace_back(el);
/*
The / operator on std::filesystem::path will choose the right path
if the right path is absolute, else append the right path to the
left path.
*/
compilerConfig.sysHeaderPaths.emplace_back(configDirectory /
el.get());
}
});
}

View File

@ -1,51 +1,51 @@
[types]
containers = [
"/home/circleci/project/types/array_type.toml",
"/home/circleci/project/types/string_type.toml",
"/home/circleci/project/types/cxx11_string_type.toml",
"/home/circleci/project/types/folly_iobuf_type.toml",
"/home/circleci/project/types/folly_iobuf_queue_type.toml",
"/home/circleci/project/types/set_type.toml",
"/home/circleci/project/types/unordered_set_type.toml",
"/home/circleci/project/types/seq_type.toml",
"/home/circleci/project/types/list_type.toml",
"/home/circleci/project/types/cxx11_list_type.toml",
"/home/circleci/project/types/deque_list_type.toml",
"/home/circleci/project/types/shrd_ptr_type.toml",
"/home/circleci/project/types/uniq_ptr_type.toml",
"/home/circleci/project/types/std_map_type.toml",
"/home/circleci/project/types/std_unordered_map_type.toml",
"/home/circleci/project/types/pair_type.toml",
"/home/circleci/project/types/stack_container_adapter_type.toml",
"/home/circleci/project/types/queue_container_adapter_type.toml",
"/home/circleci/project/types/priority_queue_container_adapter_type.toml",
"/home/circleci/project/types/ref_wrapper_type.toml",
"/home/circleci/project/types/multi_map_type.toml",
"/home/circleci/project/types/folly_small_heap_vector_map.toml",
"/home/circleci/project/types/folly_optional_type.toml",
"/home/circleci/project/types/optional_type.toml",
"/home/circleci/project/types/try_type.toml",
"/home/circleci/project/types/fb_string_type.toml",
"/home/circleci/project/types/small_vec_type.toml",
"/home/circleci/project/types/f14_fast_map.toml",
"/home/circleci/project/types/f14_node_map.toml",
"/home/circleci/project/types/f14_vector_map.toml",
"/home/circleci/project/types/f14_fast_set.toml",
"/home/circleci/project/types/f14_node_set.toml",
"/home/circleci/project/types/f14_vector_set.toml",
"/home/circleci/project/types/sorted_vec_set_type.toml",
"/home/circleci/project/types/map_seq_type.toml",
"/home/circleci/project/types/boost_bimap_type.toml",
"/home/circleci/project/types/repeated_field_type.toml",
"/home/circleci/project/types/repeated_ptr_field_type.toml",
"/home/circleci/project/types/caffe2_blob_type.toml",
"/home/circleci/project/types/std_variant.toml",
"/home/circleci/project/types/thrift_isset_type.toml",
"../types/array_type.toml",
"../types/string_type.toml",
"../types/cxx11_string_type.toml",
"../types/folly_iobuf_type.toml",
"../types/folly_iobuf_queue_type.toml",
"../types/set_type.toml",
"../types/unordered_set_type.toml",
"../types/seq_type.toml",
"../types/list_type.toml",
"../types/cxx11_list_type.toml",
"../types/deque_list_type.toml",
"../types/shrd_ptr_type.toml",
"../types/uniq_ptr_type.toml",
"../types/std_map_type.toml",
"../types/std_unordered_map_type.toml",
"../types/pair_type.toml",
"../types/stack_container_adapter_type.toml",
"../types/queue_container_adapter_type.toml",
"../types/priority_queue_container_adapter_type.toml",
"../types/ref_wrapper_type.toml",
"../types/multi_map_type.toml",
"../types/folly_small_heap_vector_map.toml",
"../types/folly_optional_type.toml",
"../types/optional_type.toml",
"../types/try_type.toml",
"../types/fb_string_type.toml",
"../types/small_vec_type.toml",
"../types/f14_fast_map.toml",
"../types/f14_node_map.toml",
"../types/f14_vector_map.toml",
"../types/f14_fast_set.toml",
"../types/f14_node_set.toml",
"../types/f14_vector_set.toml",
"../types/sorted_vec_set_type.toml",
"../types/map_seq_type.toml",
"../types/boost_bimap_type.toml",
"../types/repeated_field_type.toml",
"../types/repeated_ptr_field_type.toml",
"../types/caffe2_blob_type.toml",
"../types/std_variant.toml",
"../types/thrift_isset_type.toml",
]
[headers]
user_paths = [
"/home/circleci/project/extern/folly",
"../extern/folly",
]
system_paths = [
"/usr/include/c++/11",