Skip to content

Commit b503f46

Browse files
committed
Modify the generated .pb.h files to include the visibility file
1 parent d48ec42 commit b503f46

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

rosidl_adapter_proto/bin/rosidl_adapter_proto

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import argparse
2222
import sys
2323
import pathlib
2424
import os
25+
import re
2526

2627
from rosidl_cmake import read_generator_arguments
2728
from rosidl_adapter_proto import generate_proto
@@ -80,6 +81,22 @@ def main(argv=sys.argv[1:]):
8081
package_name = package_name
8182
)
8283

84+
# Modify the generated .pb.h to include visibility file
85+
for proto_file in proto_files:
86+
msg = os.path.splitext(os.path.basename(proto_file))[0]
87+
88+
# Just in case if the path contains another <xxx>.proto, e.g.,
89+
# /home/<xxx>.proto/<path-to-proto-file>
90+
with open(f"{cpp_out_dir}/{package_name}/msg/{msg}.pb.h", "r") as f:
91+
contents = f.readlines()
92+
93+
# Insert the visibility file on line 6
94+
contents.insert(
95+
6,
96+
f"#include \"{package_name}/rosidl_adapter_proto__visibility_control.h\"\n")
97+
with open(f"{cpp_out_dir}/{package_name}/msg/{msg}.pb.h", "w") as f:
98+
f.write("".join(contents))
99+
83100
return rc
84101

85102

0 commit comments

Comments
 (0)