@cryptotaxi247 / netdata-1 / commits / 2d4062ecd

Generate protobuf source files in build dir. (#19576)

vkalintiris committed Feb 5, 2025 at 16:02 UTC 2d4062ecd03166611364985070596841717aef09
7 files changed +74 -55
.gitignore
-4
@@ -33,10 +33,6 @@ src/collectors/ebpf.plugin/reset_netdata_trace.sh
33 !ebpf.plugin/
34 src/libnetdata/ebpf/includes/
35
36 -# protoc generated files
37 -*.pb.cc
38 -*.pb.h
39 -
36 # installation artifacts
37 packaging/installer/.environment.sh
38 *.tar.*
CMakeLists.txt
+3 -3
@@ -2288,7 +2288,7 @@ endif()
2288 # proto definitions
2289 #
2290 netdata_protoc_generate_cpp("${CMAKE_SOURCE_DIR}/src/aclk/aclk-schemas"
2291 - "${CMAKE_SOURCE_DIR}/src/aclk/aclk-schemas"
2291 + "${CMAKE_BINARY_DIR}/src/aclk/aclk-schemas"
2292 ACLK_PROTO_BUILT_SRCS
2293 ACLK_PROTO_BUILT_HDRS
2294 ${ACLK_PROTO_DEFS})
@@ -2777,7 +2777,7 @@ if(ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE)
2777 endif()
2778
2779 netdata_protoc_generate_cpp("${CMAKE_SOURCE_DIR}/src/exporting/prometheus/remote_write"
2780 - "${CMAKE_SOURCE_DIR}/src/exporting/prometheus/remote_write"
2780 + "${CMAKE_BINARY_DIR}/src/exporting/prometheus/remote_write"
2781 PROMETHEUS_REMOTE_WRITE_BUILT_SRCS
2782 PROMETHEUS_REMOTE_WRITE_BUILT_HDRS
2783 "src/exporting/prometheus/remote_write/remote_write.proto")
@@ -2836,7 +2836,7 @@ target_compile_options(netdata PRIVATE
2836 )
2837
2838 target_include_directories(netdata PRIVATE
2839 - "${CMAKE_SOURCE_DIR}/src/aclk/aclk-schemas"
2839 + "${CMAKE_BINARY_DIR}/src/aclk/aclk-schemas"
2840 "$<$<BOOL:${ENABLE_EXPORTER_MONGODB}>:${MONGOC_INCLUDE_DIRS}>"
2841 "$<$<BOOL:${ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE}>:${SNAPPY_INCLUDE_DIRS}>"
2842 )
packaging/cmake/Modules/NetdataProtobuf.cmake
+64 -41
@@ -140,48 +140,71 @@ macro(netdata_detect_protobuf)
140 endif()
141 endmacro()
142
143 -# Helper function to compile protocol definitions into C++ code.
144 -function(netdata_protoc_generate_cpp INC_DIR OUT_DIR SRCS HDRS)
145 - if(NOT ARGN)
146 - message(SEND_ERROR "Error: protoc_generate_cpp() called without any proto files")
147 - return()
148 - endif()
149 -
150 - set(${INC_DIR})
151 - set(${OUT_DIR})
152 - set(${SRCS})
153 - set(${HDRS})
154 -
155 - foreach(FIL ${ARGN})
156 - get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
157 - get_filename_component(DIR ${ABS_FIL} DIRECTORY)
158 - get_filename_component(FIL_WE ${FIL} NAME_WE)
159 -
160 - set(GENERATED_PB_CC "${DIR}/${FIL_WE}.pb.cc")
161 - list(APPEND ${SRCS} ${GENERATED_PB_CC})
162 -
163 - set(GENERATED_PB_H "${DIR}/${FIL_WE}.pb.h")
164 - list(APPEND ${HDRS} ${GENERATED_PB_H})
143
166 - list(APPEND _PROTOC_INCLUDE_DIRS ${INC_DIR})
167 -
168 - if(ENABLE_BUNDLED_PROTOBUF)
169 - list(APPEND _PROTOC_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/_deps/protobuf-src/src/)
170 - endif()
171 -
172 - add_custom_command(OUTPUT ${GENERATED_PB_CC} ${GENERATED_PB_H}
173 - COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
174 - ARGS "-I$<JOIN:${_PROTOC_INCLUDE_DIRS},;-I>" --cpp_out=${OUT_DIR} ${ABS_FIL}
175 - DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_EXECUTABLE}
176 - COMMENT "Running C++ protocol buffer compiler on ${FIL}"
177 - COMMAND_EXPAND_LISTS)
178 - endforeach()
179 -
180 - set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
181 - set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES COMPILE_OPTIONS -Wno-deprecated-declarations)
182 -
183 - set(${SRCS} ${${SRCS}} PARENT_SCOPE)
184 - set(${HDRS} ${${HDRS}} PARENT_SCOPE)
144 +# Helper function to compile protocol definitions into C++ code.
145 +function(netdata_protoc_generate_cpp PROTO_ROOT_DIR OUTPUT_ROOT_DIR GENERATED_SOURCES GENERATED_HEADERS)
146 + if(NOT ARGN)
147 + message(SEND_ERROR "Error: netdata_protoc_generate_cpp() called without any proto files")
148 + return()
149 + endif()
150 +
151 + # Initialize output variables
152 + set(output_sources)
153 + set(output_headers)
154 +
155 + # Setup include paths for protoc
156 + set(protoc_include_paths ${PROTO_ROOT_DIR})
157 + if(ENABLE_BUNDLED_PROTOBUF)
158 + list(APPEND protoc_include_paths ${CMAKE_BINARY_DIR}/_deps/protobuf-src/src/)
159 + endif()
160 +
161 + # Process each proto file
162 + foreach(proto_file ${ARGN})
163 + # Get absolute paths and component parts
164 + get_filename_component(proto_file_abs_path ${proto_file} ABSOLUTE)
165 + get_filename_component(proto_file_name_no_ext ${proto_file} NAME_WE)
166 + get_filename_component(proto_file_dir ${proto_file} DIRECTORY)
167 +
168 + # Calculate relative output path to maintain directory structure
169 + get_filename_component(proto_root_abs_path ${PROTO_ROOT_DIR} ABSOLUTE)
170 + get_filename_component(proto_dir_abs_path ${proto_file_dir} ABSOLUTE)
171 + file(RELATIVE_PATH proto_relative_path ${proto_root_abs_path} ${proto_dir_abs_path})
172 +
173 + # Construct output file paths
174 + set(output_dir "${OUTPUT_ROOT_DIR}/${proto_relative_path}")
175 + set(generated_source "${output_dir}/${proto_file_name_no_ext}.pb.cc")
176 + set(generated_header "${output_dir}/${proto_file_name_no_ext}.pb.h")
177 +
178 + # Add to output lists
179 + list(APPEND output_sources "${generated_source}")
180 + list(APPEND output_headers "${generated_header}")
181 +
182 + # Create custom command to generate the protobuf files
183 + add_custom_command(
184 + OUTPUT "${generated_source}" "${generated_header}"
185 + COMMAND ${CMAKE_COMMAND} -E make_directory "${output_dir}"
186 + COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
187 + ARGS "-I$<JOIN:${protoc_include_paths},;-I>"
188 + --cpp_out=${OUTPUT_ROOT_DIR}
189 + ${proto_file_abs_path}
190 + DEPENDS ${proto_file_abs_path} ${PROTOBUF_PROTOC_EXECUTABLE}
191 + COMMENT "Generating C++ protocol buffer files from ${proto_file}"
192 + COMMAND_EXPAND_LISTS
193 + VERBATIM
194 + )
195 + endforeach()
196 +
197 + # Mark generated files with proper properties
198 + set_source_files_properties(
199 + ${output_sources} ${output_headers}
200 + PROPERTIES
201 + GENERATED TRUE
202 + COMPILE_OPTIONS -Wno-deprecated-declarations
203 + )
204 +
205 + # Set output variables in parent scope
206 + set(${GENERATED_SOURCES} ${output_sources} PARENT_SCOPE)
207 + set(${GENERATED_HEADERS} ${output_headers} PARENT_SCOPE)
208 endfunction()
209
210 # Add protobuf to a specified target.
src/aclk/aclk_query.c
+1 -1
@@ -2,7 +2,7 @@
2
3 #include "aclk_query.h"
4 #include "aclk_tx_msgs.h"
5 -#include "../../web/server/web_client_cache.h"
5 +#include "web/server/web_client_cache.h"
6
7 static HTTP_ACL default_aclk_http_acl = HTTP_ACL_ALL_FEATURES;
8
src/aclk/schema-wrappers/connection.cc
+2 -2
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "proto/agent/v1/connection.pb.h"
4 -#include "proto/agent/v1/disconnect.pb.h"
3 +#include "src/aclk/aclk-schemas/proto/agent/v1/connection.pb.h"
4 +#include "src/aclk/aclk-schemas/proto/agent/v1/disconnect.pb.h"
5 #include "connection.h"
6
7 #include "schema_wrapper_utils.h"
src/database/sqlite/sqlite_aclk.c
+3 -3
@@ -9,9 +9,9 @@ void sanity_check(void) {
9 }
10
11 #include "sqlite_aclk_node.h"
12 -#include "../aclk_query_queue.h"
13 -#include "../aclk_query.h"
14 -#include "../aclk_capas.h"
12 +#include "aclk/aclk_query_queue.h"
13 +#include "aclk/aclk_query.h"
14 +#include "aclk/aclk_capas.h"
15
16 static void create_node_instance_result_job(const char *machine_guid, const char *node_id)
17 {
src/exporting/prometheus/remote_write/remote_write_request.cc
+1 -1
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #include <snappy.h>
4 -#include "remote_write.pb.h"
4 +#include "src/exporting/prometheus/remote_write/remote_write.pb.h"
5 #include "remote_write_request.h"
6
7 using namespace prometheus;