Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix interpreter globals collision with multiple message templates or modules #54

Merged
merged 1 commit into from
Oct 13, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions src/genmsg/template_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,9 @@ def _generate_from_spec(input_file, output_dir, template_dir, msg_context, spec,

md5sum = genmsg.gentools.compute_md5(msg_context, spec)

# Set dictionary for the generator interpreter
g = { "file_name_in":input_file,
"spec":spec,
"md5sum":md5sum,
"search_path":search_path,
"msg_context" : msg_context }
# precompute msg definition once
if isinstance(spec, genmsg.msgs.MsgSpec):
g['msg_definition'] = genmsg.gentools.compute_full_text(msg_context, spec)
msg_definition = genmsg.gentools.compute_full_text(msg_context, spec)

# Loop over all files to generate
for template_file_name, output_file_name in template_map.items():
Expand All @@ -66,6 +61,17 @@ def _generate_from_spec(input_file, output_dir, template_dir, msg_context, spec,

ofile = open(output_file, 'w') #todo try

# Set dictionary for the generator interpreter
g = {
"file_name_in": input_file,
"spec": spec,
"md5sum": md5sum,
"search_path": search_path,
"msg_context": msg_context
}
if isinstance(spec, genmsg.msgs.MsgSpec):
g['msg_definition'] = msg_definition

# todo, reuse interpreter
interpreter = em.Interpreter(output=ofile, globals=g, options={em.RAW_OPT:True,em.BUFFERED_OPT:True})
if not os.path.isfile(template_file):
Expand Down Expand Up @@ -154,17 +160,17 @@ def generate_module(package_name, output_dir, template_dir, template_dict):
# Locate generate msg files
files = os.listdir(output_dir)

# Set dictionary for the generator intepreter
g = dict(files=files,
package=package_name)

# Loop over all files to generate
for template_file_name, output_file_name in template_dict.items():
template_file = os.path.join(template_dir, template_file_name)
output_file = os.path.join(output_dir, output_file_name)

ofile = open(output_file, 'w') #todo try

# Set dictionary for the generator intepreter
g = dict(files=files,
package=package_name)

# todo, reuse interpreter
interpreter = em.Interpreter(output=ofile, options={em.RAW_OPT:True,em.BUFFERED_OPT:True})
interpreter.updateGlobals(g)
Expand Down