Skip to content

Commit

Permalink
recursive support for including dbcs
Browse files Browse the repository at this point in the history
  • Loading branch information
jnewb1 committed Jul 11, 2023
1 parent 8207262 commit 5de70b4
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,37 @@ def read_dbc(src_dir: str, filename: str) -> str:
return file_in.read()


def replace_includes_recursively(src_dir, filename, dbc_file_in, is_root=False):
includes = include_pattern.findall(dbc_file_in)

out = ""

for include_filename in includes:
include_file_header = '\n\nCM_ "Imported file %s starts here";\n' % include_filename
out += include_file_header

include_file = read_dbc(src_dir, include_filename)
out += replace_includes_recursively(src_dir, filename, include_file)

if is_root:
out += '\nCM_ "%s starts here";\n' % filename

core_dbc = include_pattern.sub('', dbc_file_in)
out += core_dbc

return out


def create_dbc(src_dir: str, filename: str, output_path: str):
dbc_file_in = read_dbc(src_dir, filename)

includes = include_pattern.findall(dbc_file_in)

output_filename = filename.replace('.dbc', generated_suffix)
output_file_location = os.path.join(output_path, output_filename)

with open(output_file_location, 'w', encoding='utf-8') as dbc_file_out:
dbc_file_out.write('CM_ "AUTOGENERATED FILE, DO NOT EDIT";\n')

for include_filename in includes:
include_file_header = '\n\nCM_ "Imported file %s starts here";\n' % include_filename
dbc_file_out.write(include_file_header)

include_file = read_dbc(src_dir, include_filename)
dbc_file_out.write(include_file)

dbc_file_out.write('\nCM_ "%s starts here";\n' % filename)

core_dbc = include_pattern.sub('', dbc_file_in)
dbc_file_out.write(core_dbc)
dbc_file_out.write(replace_includes_recursively(src_dir, filename, dbc_file_in, is_root=True))


def create_all(output_path: str):
Expand Down

0 comments on commit 5de70b4

Please sign in to comment.