Add config profiles to libspark (check pt)

This is part of a larger effort to unify the libspark build, and eliminate
compile time differences between the builds used by our various services
This commit is contained in:
John Colvin committed 2024-09-18 14:02:38 +00:00
1 parent e75cc05137
commit 489b289a6d
5 files changed
+103

No files matched your search

+1
View File
@@ -246,6 +246,7 @@
"CMAKE_CXX_FLAGS_RELEASE": "-fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -fno-omit-frame-pointer -DNDEBUG -O3",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/install/${presetName}",
"CONFIG_DEFAULTS_PATH": "config/profiles/default/*.conf;config/profiles/data_stream/*.conf",
"CONFIG_PROFILES": "default;data_stream",
"DOTNET_BINARY_DIR": "${sourceDir}/build/$<CONFIG>/bin/net7.0;${sourceDir}/build/$<CONFIG>/bin/net8.0",
"EXPORT_MD_CONSUMER": {
"type": "BOOL",
+33
View File
@@ -0,0 +1,33 @@
#!/bin/bash
# Define the bash array
# values=("value1" "value2" "value3")
values=$(dotnet sln DataStreamSuite.sln list | tail +3)
# Function to get the key for a value
get_key() {
local value=$1
# Replace this with your actual logic to get the key
echo "key_for_$value"
}
# Function to get the JSON array of child values for a value
get_children() {
local value=$1
# Replace this with your actual logic to get the JSON array of child values
echo '["child1", "child2", "child3"]'
}
# Create an empty JSON object
json_object="{}"
# Iterate through the array and construct the JSON object
for value in ${values[@]}; do
key=$(get_key "$value")
children=$(get_children "$value")
json_object=$(echo "$json_object" | jq --arg key "$key" --argjson children "$children" '. + {($key): $children}')
done
# Print the final JSON object
echo "$json_object"
+5
View File
@@ -4,6 +4,7 @@ set(CMAKE_SHARED_LIBRARY_PREFIX "")
include(${CMAKE_SOURCE_DIR}/cmake/safe_dep_glob.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/Protobuf.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateDefaultConfig.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateConfigProfile.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/PrintList.cmake)
if (DEFINED DOTNET_BINARY_DIR OR DEFINED DOTNET_WINDOWS_BINARY_DIR)
@@ -45,6 +46,10 @@ protobuf_generate_cpp(_proto_srcs _proto_hdrs ${_non_cfg_protos} ${_cfg_protos})
service_compiler_generate_cpp(SERVICE_COMPILER_SRCS SERVICE_COMPILER_HDRS ${_service_protos})
message(STATUS "Generating default config")
generate_default_config(_cfg_protos _cfg_defaults)
foreach(profile ${CONFIG_PROFILES})
message(STATUS "Generating config profile ${profile}")
generate_config_profile(${profile} _cfg_protos)
endforeach()
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_Sources} ${_proto_srcs} ${SERVICE_COMPILER_SRCS})
+59
View File
@@ -0,0 +1,59 @@
function(generate_config_profile profile_dir cfg_protos)
# Glob .conf files in profile dir (they define config defaults for this profile)
file(
GLOB_RECURSE _cfg_profile_defaults
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
config/profiles/${profile_dir}/*.conf)
# generate list of config protos
set(_cfg_proto_file ${CMAKE_CURRENT_BINARY_DIR}/config_proto_files.h)
# generate a string with the current config files
set(_cfg_proto_str "const char * config_proto_files[] = { // generated file\n")
foreach(_proto_path ${${cfg_protos}})
get_filename_component(_proto_name ${_proto_path} NAME)
string(APPEND _cfg_proto_str "\"${_proto_name}\",\n")
endforeach(_proto_path)
string(APPEND _cfg_proto_str "} ;\n")
# compare with file and if there is any difference update the file
set(_old_cfg_proto_str "")
if(EXISTS "${_cfg_proto_file}")
file(READ "${_cfg_proto_file}" _old_cfg_proto_str)
endif()
if(NOT _old_cfg_proto_str STREQUAL _cfg_proto_str)
file(WRITE "${_cfg_proto_file}" "${_cfg_proto_str}")
endif()
# generate static defaults
set(_cfg_defaults_file ${CMAKE_CURRENT_BINARY_DIR}/config/profiles/${profile_dir}/config_defaults.h)
# Defaults cannot be a single string because the compiler complains about a
# string longer than 65k
set(_cfg_defaults_str "const char * config_static_defaults[] = { ")
foreach(_cfg_file_path ${_cfg_profile_defaults})
file(READ ${_cfg_file_path} _cfg_file_content)
string(REPLACE "\"" "\\\"" _cfg_file_content_escaped ${_cfg_file_content})
string(REPLACE "\n" ";" _cfg_lines ${_cfg_file_content_escaped})
foreach(_line ${_cfg_lines})
string(APPEND _cfg_defaults_str "\n \"${_line}\",")
endforeach(_line)
endforeach(_cfg_file_path)
string(APPEND _cfg_defaults_str "};")
set(_old_cfg_defaults_str "")
if(EXISTS ${_cfg_defaults_file})
file(READ ${_cfg_defaults_file} _old_cfg_defaults_str)
endif()
if(NOT _cfg_defaults_str STREQUAL _old_cfg_defaults_str)
file(WRITE "${_cfg_defaults_file}" "${_cfg_defaults_str}")
endif()
endfunction()
+5
View File
@@ -0,0 +1,5 @@
#pragma once
#ifndef CONFIG_PROFILE
#define CONFIG_PROFILE "${BTS_SPARK_CONFIG_PROFILE}"
#endif