summaryrefslogtreecommitdiff
path: root/buildscripts
diff options
context:
space:
mode:
authorMedha Potluri <medha.potluri@mongodb.com>2019-06-14 11:13:14 -0400
committerMedha Potluri <medha.potluri@mongodb.com>2019-08-13 13:12:28 -0400
commit37c1295048441d605c1732e3a8e87e2cb0b9fb01 (patch)
tree58d3302b3da0f83357d777356065e5b33fb3dd70 /buildscripts
parente8b17d8be314671f303df2dab22c3402e4a01c47 (diff)
downloadmongo-37c1295048441d605c1732e3a8e87e2cb0b9fb01.tar.gz
SERVER-41499 Track number of elections called for each reason in serverStatus
(cherry picked from commit 8071e24f0f7a4fa83015daa59d828c11c246423c)
Diffstat (limited to 'buildscripts')
-rw-r--r--buildscripts/idl/idl/ast.py1
-rw-r--r--buildscripts/idl/idl/binder.py5
-rw-r--r--buildscripts/idl/idl/errors.py13
-rw-r--r--buildscripts/idl/idl/generator.py3
-rw-r--r--buildscripts/idl/idl/parser.py1
-rw-r--r--buildscripts/idl/idl/syntax.py1
-rw-r--r--buildscripts/idl/tests/test_binder.py12
7 files changed, 35 insertions, 1 deletions
diff --git a/buildscripts/idl/idl/ast.py b/buildscripts/idl/idl/ast.py
index a1f32bbd754..d38f95c3fa0 100644
--- a/buildscripts/idl/idl/ast.py
+++ b/buildscripts/idl/idl/ast.py
@@ -126,6 +126,7 @@ class Field(common.SourceLocation):
self.ignore = False # type: bool
self.chained = False # type: bool
self.comparison_order = -1 # type: int
+ self.non_const_getter = False # type: bool
# Properties specific to fields which are types.
self.cpp_type = None # type: unicode
diff --git a/buildscripts/idl/idl/binder.py b/buildscripts/idl/idl/binder.py
index 29183ae229f..42687c16e91 100644
--- a/buildscripts/idl/idl/binder.py
+++ b/buildscripts/idl/idl/binder.py
@@ -290,6 +290,10 @@ def _bind_struct_common(ctxt, parsed_spec, struct, ast_struct):
ctxt.add_bad_struct_field_as_doc_sequence_error(ast_struct, ast_struct.name,
ast_field.name)
+ if ast_field.non_const_getter and struct.immutable:
+ ctxt.add_bad_field_non_const_getter_in_immutable_struct_error(
+ ast_struct, ast_struct.name, ast_field.name)
+
if not _is_duplicate_field(ctxt, ast_struct.name, ast_struct.fields, ast_field):
ast_struct.fields.append(ast_field)
@@ -535,6 +539,7 @@ def _bind_field(ctxt, parsed_spec, field):
ast_field.serialize_op_msg_request_only = field.serialize_op_msg_request_only
ast_field.constructed = field.constructed
ast_field.comparison_order = field.comparison_order
+ ast_field.non_const_getter = field.non_const_getter
ast_field.cpp_name = field.name
if field.cpp_name:
diff --git a/buildscripts/idl/idl/errors.py b/buildscripts/idl/idl/errors.py
index d26f11a93c2..b0479702c70 100644
--- a/buildscripts/idl/idl/errors.py
+++ b/buildscripts/idl/idl/errors.py
@@ -98,6 +98,7 @@ ERROR_ID_IS_NODE_VALID_INT = "ID0049"
ERROR_ID_IS_NODE_VALID_NON_NEGATIVE_INT = "ID0050"
ERROR_ID_IS_DUPLICATE_COMPARISON_ORDER = "ID0051"
ERROR_ID_IS_COMMAND_TYPE_EXTRANEOUS = "ID0052"
+ERROR_ID_NON_CONST_GETTER_IN_IMMUTABLE_STRUCT = "ID0069"
class IDLError(Exception):
@@ -630,6 +631,16 @@ class ParserContext(object):
self._add_error(location, ERROR_ID_COMMAND_DUPLICATES_FIELD,
("Command '%s' cannot have the same name as a field.") % (command_name))
+ def add_bad_field_non_const_getter_in_immutable_struct_error(self, location, struct_name,
+ field_name):
+ # type: (common.SourceLocation, unicode, unicode) -> None
+ """Add an error about marking a field with non_const_getter in an immutable struct."""
+ # pylint: disable=invalid-name
+ self._add_error(location, ERROR_ID_NON_CONST_GETTER_IN_IMMUTABLE_STRUCT,
+ ("Cannot generate a non-const getter for field '%s' in struct '%s' since"
+ " struct '%s' is marked as immutable.") % (field_name, struct_name,
+ struct_name))
+
def is_scalar_non_negative_int_node(self, node, node_name):
# type: (Union[yaml.nodes.MappingNode, yaml.nodes.ScalarNode, yaml.nodes.SequenceNode], unicode) -> bool
"""Return True if this YAML node is a Scalar and a valid non-negative int."""
@@ -689,7 +700,7 @@ def _assert_unique_error_messages():
error_ids_set = set(error_ids)
if len(error_ids) != len(error_ids_set):
- raise IDLError("IDL error codes prefixed with ERRROR_ID are not unique.")
+ raise IDLError("IDL error codes prefixed with ERROR_ID are not unique.")
# On file import, check the error messages are unique
diff --git a/buildscripts/idl/idl/generator.py b/buildscripts/idl/idl/generator.py
index 22e22e1bdc5..a48fca76da3 100644
--- a/buildscripts/idl/idl/generator.py
+++ b/buildscripts/idl/idl/generator.py
@@ -489,6 +489,9 @@ class _CppHeaderFileWriter(_CppFileWriterBase):
self._writer.write_template(
'${const_type}${param_type} ${method_name}() const { ${body} }')
+ if field.non_const_getter:
+ self._writer.write_template('${param_type} ${method_name}() { ${body} }')
+
def gen_setter(self, field):
# type: (ast.Field) -> None
"""Generate the C++ setter definition for a field."""
diff --git a/buildscripts/idl/idl/parser.py b/buildscripts/idl/idl/parser.py
index f7f94b72417..ceb9081d524 100644
--- a/buildscripts/idl/idl/parser.py
+++ b/buildscripts/idl/idl/parser.py
@@ -220,6 +220,7 @@ def _parse_field(ctxt, name, node):
"default": _RuleDesc('scalar'),
"supports_doc_sequence": _RuleDesc("bool_scalar"),
"comparison_order": _RuleDesc("int_scalar"),
+ "non_const_getter": _RuleDesc("bool_scalar"),
})
return field
diff --git a/buildscripts/idl/idl/syntax.py b/buildscripts/idl/idl/syntax.py
index 0c145a71ec9..1ee06e9564a 100644
--- a/buildscripts/idl/idl/syntax.py
+++ b/buildscripts/idl/idl/syntax.py
@@ -299,6 +299,7 @@ class Field(common.SourceLocation):
self.default = None # type: unicode
self.supports_doc_sequence = False # type: bool
self.comparison_order = -1 # type: int
+ self.non_const_getter = False # type: bool
# Internal fields - not generated by parser
self.serialize_op_msg_request_only = False # type: bool
diff --git a/buildscripts/idl/tests/test_binder.py b/buildscripts/idl/tests/test_binder.py
index eb90425902d..a1cc6b75d5f 100644
--- a/buildscripts/idl/tests/test_binder.py
+++ b/buildscripts/idl/tests/test_binder.py
@@ -783,6 +783,18 @@ class TestBinder(testcase.IDLTestcase):
comparison_order: 1
"""), idl.errors.ERROR_ID_IS_DUPLICATE_COMPARISON_ORDER)
+ # Test field marked with non_const_getter in immutable struct
+ self.assert_bind_fail(test_preamble + textwrap.dedent("""
+ structs:
+ foo:
+ description: foo
+ immutable: true
+ fields:
+ foo:
+ type: string
+ non_const_getter: true
+ """), idl.errors.ERROR_ID_NON_CONST_GETTER_IN_IMMUTABLE_STRUCT)
+
def test_ignored_field_negative(self):
# type: () -> None
"""Test that if a field is marked as ignored, no other properties are set."""