Skip to content

Commit f7a9d3a

Browse files
committed
Add helper function to generate visibility control files
Signed-off-by: Michel Hidalgo <[email protected]>
1 parent 2dcc401 commit f7a9d3a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

rosidl_cli/rosidl_cli/command/generate/helpers.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import contextlib
1616
import json
17+
import os
1718
import pathlib
1819
import tempfile
1920

@@ -110,3 +111,31 @@ def legacy_generator_arguments_file(
110111
}))
111112
tmp.flush()
112113
yield tmp.name
114+
115+
116+
def generate_visibility_control_file(
117+
*,
118+
package_name,
119+
template_path,
120+
output_path
121+
):
122+
"""
123+
Generate a visibility control file from a template.
124+
125+
:param package_name: Name of the ROS package for which
126+
to generate the file.
127+
:param template_path: Path to template visibility control file.
128+
May contain @PROJECT_NAME@ and @PROJECT_NAME_UPPER@ placeholders,
129+
to be substituted by the package name, accordingly.
130+
:param output_path: Path to visibility control file after interpolation.
131+
"""
132+
os.makedirs(os.path.dirname(output_path), exist_ok=True)
133+
134+
with open(template_path, 'r') as fd:
135+
content = fd.read()
136+
137+
content = content.replace('@PROJECT_NAME@', package_name)
138+
content = content.replace('@PROJECT_NAME_UPPER@', package_name.upper())
139+
140+
with open(output_path, 'w') as fd:
141+
fd.write(content)

0 commit comments

Comments
 (0)