Skip to content

Commit 1339002

Browse files
committed
add s/switch/switch_/g step to proto custom command
1 parent 9f93d41 commit 1339002

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/viam/api/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
113113
)
114114
endif()
115115

116+
# List of names of non-compilable generated code
117+
# The Switch component generates protobuf which uses `switch` as a namespace.
118+
# This needs to be processed below.
119+
set(VIAMCPPSDK_SWITCH_REPLACE_PATHS
120+
${PROTO_GEN_DIR}/component/switch/v1/switch.grpc.pb.cc
121+
${PROTO_GEN_DIR}/component/switch/v1/switch.grpc.pb.h
122+
${PROTO_GEN_DIR}/component/switch/v1/switch.pb.cc
123+
${PROTO_GEN_DIR}/component/switch/v1/switch.pb.h
124+
)
125+
116126
add_custom_command(
117127
OUTPUT
118128
# Unfortunately, there isn't a good way to know in advance what
@@ -245,6 +255,9 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
245255
COMMAND ${BUF_COMMAND} generate ${BUF_GOOGLE_API_SOURCE} --template buf.gen.yaml --path google/rpc --path google/api
246256
COMMAND ${BUF_COMMAND} generate ${BUF_VIAM_GOUTILS_SOURCE} --template buf.gen.yaml
247257
COMMAND ${BUF_COMMAND} generate ${BUF_VIAM_API_SOURCE} --template buf.gen.yaml --path ${BUF_PROTO_COMPONENTS_JOINED}
258+
259+
# After generating the protos, include a step to invoke a search-and-replace for switch -> switch_ in the Switch component files
260+
COMMAND ${CMAKE_COMMAND} "-DSWITCH_REPLACE_PATHS=\"${VIAMCPPSDK_SWITCH_REPLACE_PATHS}\"" -P ${CMAKE_CURRENT_SOURCE_DIR}/viamcppsdk_replace_switch.cmake
248261
MAIN_DEPENDENCY buf.gen.yaml
249262
)
250263

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if (NOT SWITCH_REPLACE_PATHS)
2+
message(FATAL_ERROR "Please provide SWITCH_REPLACE_PATHS argument to switch replace script")
3+
endif()
4+
5+
foreach(SOURCE ${SWITCH_REPLACE_PATHS})
6+
file(READ "${SOURCE}" _src_text)
7+
string(REPLACE "namespace switch " "namespace switch_ " _src_text "${_src_text}")
8+
string(REPLACE "::switch::" "::switch_::" _src_text "${_src_text}")
9+
file(WRITE "${SOURCE}" "${_src_text}")
10+
endforeach()

0 commit comments

Comments
 (0)