diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2022-07-19 15:42:55 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-25 16:26:27 +0000 |
commit | b6eb0136c4cb25bb437375b639738fb28ec1956d (patch) | |
tree | e199ba3f957014f042b3b94fe020e5ce01883f45 /buildscripts/idl | |
parent | b8187fed0bfb96eeb8456100ea84b20d4731984a (diff) | |
download | mongo-b6eb0136c4cb25bb437375b639738fb28ec1956d.tar.gz |
SERVER-68155 Improve IDL struct command handling
Diffstat (limited to 'buildscripts/idl')
-rw-r--r-- | buildscripts/idl/idl/generator.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/buildscripts/idl/idl/generator.py b/buildscripts/idl/idl/generator.py index b03a74966ae..850e41922e8 100644 --- a/buildscripts/idl/idl/generator.py +++ b/buildscripts/idl/idl/generator.py @@ -278,9 +278,10 @@ def _encaps(val): if val is None: return '""' - for i in ["\\", '"', "'"]: - if i in val: - val = val.replace(i, '\\' + i) + for srch, repl in {"\\": "\\\\", '"': '\\"', "'": "\\'", "\n": "\\n"}.items(): + if srch in val: + val = val.replace(srch, repl) + return '"' + val + '"' @@ -368,11 +369,10 @@ class _CppFileWriterBase(object): def gen_description_comment(self, description): # type: (str) -> None """Generate a multiline comment with the description from the IDL.""" - self._writer.write_line( - textwrap.dedent("""\ - /** - * %s - */""" % (description))) + self._writer.write_line("/**") + for desc in description.split("\n"): + self._writer.write_line(" * " + desc) + self._writer.write_line(" */") def _with_template(self, template_params): # type: (Mapping[str,str]) -> writer.TemplateContext @@ -630,6 +630,11 @@ class _CppHeaderFileWriter(_CppFileWriterBase): if isinstance(struct, ast.Command): self._writer.write_line( + common.template_args( + 'static constexpr auto kCommandDescription = ${description}_sd;', + description=_encaps(struct.description))) + + self._writer.write_line( common.template_args('static constexpr auto kCommandName = "${command_name}"_sd;', command_name=struct.command_name)) |