summaryrefslogtreecommitdiff
path: root/buildscripts
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2020-09-02 20:34:40 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-03 02:44:31 +0000
commitc6b83aca3aa431aff366c27d29eccac850758cef (patch)
treead1d32c0f69526b07272561eb92f5f89baae922b /buildscripts
parent8e64b07e3bb363347ee2c11a56aba873365ed74a (diff)
downloadmongo-c6b83aca3aa431aff366c27d29eccac850758cef.tar.gz
SERVER-50367 Add IDL support for feature flags
Diffstat (limited to 'buildscripts')
-rw-r--r--buildscripts/idl/idl/binder.py19
-rw-r--r--buildscripts/idl/idl/parser.py21
-rw-r--r--buildscripts/idl/idl/syntax.py17
3 files changed, 57 insertions, 0 deletions
diff --git a/buildscripts/idl/idl/binder.py b/buildscripts/idl/idl/binder.py
index 4d9bd3ff79c..8e01fe83b02 100644
--- a/buildscripts/idl/idl/binder.py
+++ b/buildscripts/idl/idl/binder.py
@@ -1005,6 +1005,22 @@ def _bind_server_parameter(ctxt, param):
return None
+def _bind_feature_flags(param):
+ # type: (syntax.FeatureFlag) -> ast.ServerParameter
+ """Bind a FeatureFlag as a serverParameter setting."""
+ ast_param = ast.ServerParameter(param.file_name, param.line, param.column)
+ ast_param.name = param.name
+ ast_param.description = param.description
+
+ ast_param.set_at = "ServerParameterType::kStartupOnly"
+
+ ast_param.cpp_vartype = "bool"
+ ast_param.default = _bind_expression(param.default)
+ ast_param.cpp_varname = param.cpp_varname
+
+ return ast_param
+
+
def _is_invalid_config_short_name(name):
# type: (str) -> bool
"""Check if a given name is valid as a short name."""
@@ -1168,6 +1184,9 @@ def bind(parsed_spec):
if not struct.imported:
bound_spec.structs.append(_bind_struct(ctxt, parsed_spec, struct))
+ for feature_flag in parsed_spec.feature_flags:
+ bound_spec.server_parameters.append(_bind_feature_flags(feature_flag))
+
for server_parameter in parsed_spec.server_parameters:
bound_spec.server_parameters.append(_bind_server_parameter(ctxt, server_parameter))
diff --git a/buildscripts/idl/idl/parser.py b/buildscripts/idl/idl/parser.py
index 7a3a1e376d2..08f76bf0273 100644
--- a/buildscripts/idl/idl/parser.py
+++ b/buildscripts/idl/idl/parser.py
@@ -608,6 +608,25 @@ def _parse_server_parameter(ctxt, spec, name, node):
spec.server_parameters.append(param)
+def _parse_feature_flag(ctxt, spec, name, node):
+ # type: (errors.ParserContext, syntax.IDLSpec, str, Union[yaml.nodes.MappingNode, yaml.nodes.ScalarNode, yaml.nodes.SequenceNode]) -> None
+ """Parse a feature_flags section in the IDL file."""
+ if not ctxt.is_mapping_node(node, "feature_flags"):
+ return
+
+ param = syntax.FeatureFlag(ctxt.file_name, node.start_mark.line, node.start_mark.column)
+ param.name = name
+
+ _generic_parser(
+ ctxt, node, "feature_flags", param, {
+ "description": _RuleDesc('scalar', _RuleDesc.REQUIRED),
+ "cpp_varname": _RuleDesc('scalar'),
+ "default": _RuleDesc('scalar_or_mapping', mapping_parser_func=_parse_expression),
+ })
+
+ spec.feature_flags.append(param)
+
+
def _parse_config_option(ctxt, spec, name, node):
# type: (errors.ParserContext, syntax.IDLSpec, str, Union[yaml.nodes.MappingNode, yaml.nodes.ScalarNode, yaml.nodes.SequenceNode]) -> None
"""Parse a configs section in the IDL file."""
@@ -727,6 +746,8 @@ def _parse(stream, error_file_name):
_parse_mapping(ctxt, spec, second_node, "server_parameters", _parse_server_parameter)
elif first_name == "configs":
_parse_mapping(ctxt, spec, second_node, "configs", _parse_config_option)
+ elif first_name == "feature_flags":
+ _parse_mapping(ctxt, spec, second_node, "feature_flags", _parse_feature_flag)
else:
ctxt.add_unknown_root_node_error(first_node)
diff --git a/buildscripts/idl/idl/syntax.py b/buildscripts/idl/idl/syntax.py
index 3c9bb7bedf1..9b3530a7db7 100644
--- a/buildscripts/idl/idl/syntax.py
+++ b/buildscripts/idl/idl/syntax.py
@@ -67,6 +67,7 @@ class IDLSpec(object):
self.imports = None # type: Optional[Import]
self.server_parameters = [] # type: List[ServerParameter]
self.configs = [] # type: List[ConfigOption]
+ self.feature_flags = [] # type: List[FeatureFlag]
def parse_array_type(name):
@@ -527,6 +528,22 @@ class ServerParameter(common.SourceLocation):
super(ServerParameter, self).__init__(file_name, line, column)
+class FeatureFlag(common.SourceLocation):
+ """IDL FeatureFlag information."""
+
+ # pylint: disable=too-many-instance-attributes
+
+ def __init__(self, file_name, line, column):
+ # type: (str, int, int) -> None
+ """Construct a FeatureFlag."""
+ self.name = None # type: str
+ self.description = None # type: str
+ self.cpp_varname = None # type: str
+ self.default = None # type: Expression
+
+ super(FeatureFlag, self).__init__(file_name, line, column)
+
+
class GlobalInitializer(common.SourceLocation):
"""Initializer details for custom registration/storage."""