mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
containers: add required features (#374)
Summary: Adds the option for required features to container definitions. These cause the container not to be passed to `DrgnParser` if that feature is not enabled during code generation. The thrift isset type does not currently work with `tree-builder-v2` and only provides benefit with `capture-thrift-isset`. This change makes sure the container is ignored if it won't be useful, allowing code generation under `tree-builder-v2`. Test Plan: - CI Differential Revision: D49960512 Pulled By: JakeHillion
This commit is contained in:
parent
593a1412d8
commit
4c6f232766
@ -26,17 +26,20 @@ target_link_libraries(symbol_service
|
|||||||
dw
|
dw
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_library(features Features.cpp)
|
||||||
|
target_link_libraries(features glog::glog)
|
||||||
|
|
||||||
add_library(container_info
|
add_library(container_info
|
||||||
ContainerInfo.cpp
|
ContainerInfo.cpp
|
||||||
)
|
)
|
||||||
target_link_libraries(container_info
|
target_link_libraries(container_info
|
||||||
|
features
|
||||||
glog::glog
|
glog::glog
|
||||||
toml
|
toml
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(codegen
|
add_library(codegen
|
||||||
CodeGen.cpp
|
CodeGen.cpp
|
||||||
Features.cpp
|
|
||||||
FuncGen.cpp
|
FuncGen.cpp
|
||||||
OICodeGen.cpp
|
OICodeGen.cpp
|
||||||
)
|
)
|
||||||
|
@ -1119,6 +1119,10 @@ bool CodeGen::codegenFromDrgn(struct drgn_type* drgnType, std::string& code) {
|
|||||||
|
|
||||||
void CodeGen::registerContainer(const fs::path& path) {
|
void CodeGen::registerContainer(const fs::path& path) {
|
||||||
auto info = std::make_unique<ContainerInfo>(path);
|
auto info = std::make_unique<ContainerInfo>(path);
|
||||||
|
if (info->requiredFeatures != (config_.features & info->requiredFeatures)) {
|
||||||
|
VLOG(1) << "Skipping container (feature conflict): " << info->typeName;
|
||||||
|
return;
|
||||||
|
}
|
||||||
VLOG(1) << "Registered container: " << info->typeName;
|
VLOG(1) << "Registered container: " << info->typeName;
|
||||||
containerInfos_.emplace_back(std::move(info));
|
containerInfos_.emplace_back(std::move(info));
|
||||||
}
|
}
|
||||||
|
@ -242,6 +242,19 @@ ContainerInfo::ContainerInfo(const fs::path& path) {
|
|||||||
|
|
||||||
underlyingContainerIndex = info["underlying_container_index"].value<size_t>();
|
underlyingContainerIndex = info["underlying_container_index"].value<size_t>();
|
||||||
|
|
||||||
|
if (toml::array* arr = info["required_features"].as_array()) {
|
||||||
|
arr->for_each([&](auto&& el) {
|
||||||
|
if constexpr (toml::is_string<decltype(el)>) {
|
||||||
|
oi::detail::Feature f = oi::detail::featureFromStr(*el);
|
||||||
|
if (f == oi::detail::Feature::UnknownFeature) {
|
||||||
|
LOG(WARNING) << "unknown feature in container config: " << el;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
requiredFeatures[f] = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!container["codegen"].is_table()) {
|
if (!container["codegen"].is_table()) {
|
||||||
throw ContainerInfoError(
|
throw ContainerInfoError(
|
||||||
path, "a container info file requires a `codegen` table");
|
path, "a container info file requires a `codegen` table");
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "oi/ContainerTypeEnum.h"
|
#include "oi/ContainerTypeEnum.h"
|
||||||
|
#include "oi/Features.h"
|
||||||
|
|
||||||
ContainerTypeEnum containerTypeEnumFromStr(std::string& str);
|
ContainerTypeEnum containerTypeEnumFromStr(std::string& str);
|
||||||
const char* containerTypeEnumToStr(ContainerTypeEnum ty);
|
const char* containerTypeEnumToStr(ContainerTypeEnum ty);
|
||||||
@ -94,6 +95,7 @@ struct ContainerInfo {
|
|||||||
std::optional<size_t> underlyingContainerIndex{};
|
std::optional<size_t> underlyingContainerIndex{};
|
||||||
std::vector<size_t> stubTemplateParams{};
|
std::vector<size_t> stubTemplateParams{};
|
||||||
bool captureKeys = false;
|
bool captureKeys = false;
|
||||||
|
oi::detail::FeatureSet requiredFeatures;
|
||||||
|
|
||||||
Codegen codegen;
|
Codegen codegen;
|
||||||
|
|
||||||
|
@ -47,11 +47,26 @@ class EnumBitset {
|
|||||||
return bitset.none();
|
return bitset.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator==(const EnumBitset<T, N>& that) const {
|
||||||
|
return bitset == that.bitset;
|
||||||
|
}
|
||||||
EnumBitset<T, N>& operator|=(const EnumBitset<T, N>& that) {
|
EnumBitset<T, N>& operator|=(const EnumBitset<T, N>& that) {
|
||||||
bitset |= that.bitset;
|
bitset |= that.bitset;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
EnumBitset<T, N>& operator&=(const EnumBitset<T, N>& that) {
|
||||||
|
bitset &= that.bitset;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BitsetType bitset;
|
BitsetType bitset;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T, size_t N>
|
||||||
|
EnumBitset<T, N> operator&(const EnumBitset<T, N>& lhs,
|
||||||
|
const EnumBitset<T, N>& rhs) {
|
||||||
|
auto out = lhs;
|
||||||
|
out &= rhs;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
@ -213,7 +213,6 @@ namespace cpp2 {
|
|||||||
]}]'''
|
]}]'''
|
||||||
|
|
||||||
[cases.no_capture]
|
[cases.no_capture]
|
||||||
oil_skip = 'oil does not support thrift isset yet' # https://github.com/facebookexperimental/object-introspection/issues/296
|
|
||||||
param_types = ["const cpp2::MyThriftStructBoxed&"]
|
param_types = ["const cpp2::MyThriftStructBoxed&"]
|
||||||
setup = '''
|
setup = '''
|
||||||
cpp2::MyThriftStructBoxed ret;
|
cpp2::MyThriftStructBoxed ret;
|
||||||
|
@ -22,6 +22,13 @@ This document describes the format of the container definition files contained i
|
|||||||
Only used for container adapters. Points OI to the template parameter
|
Only used for container adapters. Points OI to the template parameter
|
||||||
representing the underlying container to be measured.
|
representing the underlying container to be measured.
|
||||||
|
|
||||||
|
- `required_features`
|
||||||
|
|
||||||
|
A set of feature names such as `tree-builder-v2` which must be enabled for
|
||||||
|
this container description to be included. Currently only supported with
|
||||||
|
CodeGen v2 as that's their only use case and an implementation for CodeGen v1
|
||||||
|
would be untested.
|
||||||
|
|
||||||
### codegen
|
### codegen
|
||||||
- `decl`
|
- `decl`
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
type_name = "apache::thrift::detail::isset_bitset"
|
type_name = "apache::thrift::detail::isset_bitset"
|
||||||
ctype = "THRIFT_ISSET_TYPE"
|
ctype = "THRIFT_ISSET_TYPE"
|
||||||
header = "thrift/lib/cpp2/gen/module_types_h.h"
|
header = "thrift/lib/cpp2/gen/module_types_h.h"
|
||||||
|
required_features = ["capture-thrift-isset"]
|
||||||
|
|
||||||
# Old:
|
# Old:
|
||||||
typeName = "apache::thrift::detail::isset_bitset<"
|
typeName = "apache::thrift::detail::isset_bitset<"
|
||||||
|
Loading…
Reference in New Issue
Block a user