-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: Add mariadb-connector-cpp library #18
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,132 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Try to find MariaDBClientCpp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Set MariaDBClientCpp_USE_STATIC_LIBS=ON to look for static libraries. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Once done this will define: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# MariaDBClientCpp_FOUND - Whether MariaDBClient was found on the system | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# MariaDBClientCpp_INCLUDE_DIR - The MariaDBClient include directories | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# MariaDBClientCpp_VERSION - The version of MariaDBClient installed on the system | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Conventions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# - Variables only for use within the script are prefixed with "mariadbclientcpp_" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# - Variables that should be externally visible are prefixed with "MariaDBClientCpp_" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(mariadbclientcpp_LIBNAME "mariadbcpp") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
include(cmake/Modules/FindLibraryDependencies.cmake) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Run pkg-config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
find_package(PkgConfig) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pkg_check_modules(mariadbclientcpp_PKGCONF QUIET "lib${mariadbclientcpp_LIBNAME}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Set include directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
find_path( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MariaDBClientCpp_INCLUDE_DIR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
conncpp.hpp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
HINTS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
${mariadbclientcpp_PKGCONF_INCLUDEDIR} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PATH_SUFFIXES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mariadb | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Handle static libraries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(MariaDBClientCpp_USE_STATIC_LIBS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Save current value of CMAKE_FIND_LIBRARY_SUFFIXES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(mariadbclientcpp_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Temporarily change CMAKE_FIND_LIBRARY_SUFFIXES to static library suffix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(CMAKE_FIND_LIBRARY_SUFFIXES .a) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# mariadb-connector-cpp uses .dylib for dynamic library, at least on macOS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(mariadbclientcpp_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(CMAKE_FIND_LIBRARY_SUFFIXES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.dylib | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
endif() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+33
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the incorrect saving of You're overwriting Apply this diff to fix the issue: +# Save current value of CMAKE_FIND_LIBRARY_SUFFIXES
+set(mariadbclientcpp_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
if(MariaDBClientCpp_USE_STATIC_LIBS)
- # Save current value of CMAKE_FIND_LIBRARY_SUFFIXES
- set(mariadbclientcpp_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
# Temporarily change CMAKE_FIND_LIBRARY_SUFFIXES to static library suffix
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
else()
- # Save current value of CMAKE_FIND_LIBRARY_SUFFIXES
- set(mariadbclientcpp_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
# `mariadb-connector-cpp` uses `.dylib` for dynamic libraries, at least on macOS
set(CMAKE_FIND_LIBRARY_SUFFIXES
.so
.dylib
)
endif() 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Find library | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
find_library( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MariaDBClientCpp_LIBRARY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
NAMES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
${mariadbclientcpp_LIBNAME} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
HINTS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
${mariadbclientcpp_PKGCONF_LIBDIR} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PATH_SUFFIXES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mariadb | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(MariaDBClientCpp_LIBRARY) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# NOTE: This must be set for find_package_handle_standard_args to work | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(MariaDBClientCpp_FOUND ON) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
endif() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(MariaDBClientCpp_USE_STATIC_LIBS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
findstaticlibrarydependencies(${mariadbclientcpp_LIBNAME} mariadbclientcpp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"${mariadbclientcpp_PKGCONF_STATIC_LIBRARIES}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Restore original value of CMAKE_FIND_LIBRARY_SUFFIXES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${mariadbclientcpp_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
unset(mariadbclientcpp_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${mariadbclientcpp_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
unset(mariadbclientcpp_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
endif() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
finddynamiclibrarydependencies(mariadbclientcpp "${mariadbclientcpp_DYNAMIC_LIBS}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Set version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(MariaDBClientCpp_VERSION ${mariadbclientcpp_PKGCONF_VERSION}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
include(FindPackageHandleStandardArgs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
find_package_handle_standard_args( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MariaDBClientCpp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
REQUIRED_VARS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MariaDBClientCpp_INCLUDE_DIR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
VERSION_VAR MariaDBClientCpp_VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(NOT TARGET MariaDBClientCpp::MariaDBClientCpp) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Add library to build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(MariaDBClientCpp_FOUND) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(MariaDBClientCpp_USE_STATIC_LIBS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
add_library(MariaDBClientCpp::MariaDBClientCpp STATIC IMPORTED) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# NOTE: We use UNKNOWN so that if the user doesn't have the SHARED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# libraries installed, we can still use the STATIC libraries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
add_library(MariaDBClientCpp::MariaDBClientCpp UNKNOWN IMPORTED) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
endif() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
endif() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Set include directories for library | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(MariaDBClientCpp_INCLUDE_DIR) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set_target_properties( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MariaDBClientCpp::MariaDBClientCpp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PROPERTIES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
INTERFACE_INCLUDE_DIRECTORIES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"${MariaDBClientCpp_INCLUDE_DIR}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
endif() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Set location of library | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(EXISTS "${MariaDBClientCpp_LIBRARY}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set_target_properties( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MariaDBClientCpp::MariaDBClientCpp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PROPERTIES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
IMPORTED_LINK_INTERFACE_LANGUAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"CXX" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
IMPORTED_LOCATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"${MariaDBClientCpp_LIBRARY}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Add component's dependencies for linking | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(mariadbclientcpp_LIBRARY_DEPENDENCIES) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set_target_properties( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MariaDBClientCpp::MariaDBClientCpp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PROPERTIES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
INTERFACE_LINK_LIBRARIES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"${mariadbclientcpp_LIBRARY_DEPENDENCIES}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
endif() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
endif() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
endif() |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,7 +18,12 @@ else() | |||||||||||||||||||||||||||||
add_library(spider_core SHARED) | ||||||||||||||||||||||||||||||
endif() | ||||||||||||||||||||||||||||||
target_sources(spider_core PRIVATE ${SPIDER_CORE_SOURCES}) | ||||||||||||||||||||||||||||||
target_link_libraries(spider_core PUBLIC Boost::boost PRIVATE absl::flat_hash_map) | ||||||||||||||||||||||||||||||
target_link_libraries( | ||||||||||||||||||||||||||||||
spider_core | ||||||||||||||||||||||||||||||
Boost::boost | ||||||||||||||||||||||||||||||
absl::flat_hash_map | ||||||||||||||||||||||||||||||
MariaDBClientCpp::MariaDBClientCpp | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
Comment on lines
+21
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add visibility specifiers to target_link_libraries. The target_link_libraries command should explicitly specify the visibility (PUBLIC/PRIVATE) for each dependency to prevent unintended exposure of internal dependencies to consumers of spider_core. Consider applying this change: target_link_libraries(
spider_core
- Boost::boost
- absl::flat_hash_map
- MariaDBClientCpp::MariaDBClientCpp
+ PUBLIC
+ Boost::boost
+ PRIVATE
+ absl::flat_hash_map
+ MariaDBClientCpp::MariaDBClientCpp
) Note: MariaDBClientCpp is listed last as it likely depends on Boost. Consider adding a comment to document this dependency order requirement if it's critical for static linking. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
set(SPIDER_WORKER_SOURCES worker/worker.cpp CACHE INTERNAL "spider worker source files") | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,73 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#!/bin/bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Dependencies: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# - cmake | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# - g++ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# - git | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# NOTE: Dependencies should be installed outside the script to allow the script to be largely distro-agnostic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Exit on any error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set -e | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cUsage="Usage: ${BASH_SOURCE[0]} <version>[ <.deb output directory>]" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if [ "$#" -lt 1 ] ; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo $cUsage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
exit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
version=$1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+12
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve argument validation The script could benefit from more robust argument validation. Replace the current validation with: -cUsage="Usage: ${BASH_SOURCE[0]} <version>[ <.deb output directory>]"
-if [ "$#" -lt 1 ] ; then
- echo $cUsage
- exit
-fi
-version=$1
+cUsage="Usage: ${BASH_SOURCE[0]} <version> [<.deb output directory>]"
+if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
+ echo "$cUsage"
+ exit 1
+fi
+
+version="$1"
+if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
+ echo "Error: Version must be in format X.Y.Z"
+ exit 1
+fi 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
package_name=mariadb-connector-cpp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
temp_dir=/tmp/${package_name}-installation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
deb_output_dir=${temp_dir} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+19
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Secure temporary directory creation The temporary directory is created without proper permissions, which could lead to security issues. Apply this diff to improve security: package_name=mariadb-connector-cpp
-temp_dir=/tmp/${package_name}-installation
+temp_dir=$(mktemp -d -t "${package_name}-XXXXXX")
+# Ensure proper permissions
+chmod 700 "${temp_dir}"
deb_output_dir=${temp_dir} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if [[ "$#" -gt 1 ]] ; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
deb_output_dir="$(readlink -f "$2")" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if [ ! -d ${deb_output_dir} ] ; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "${deb_output_dir} does not exist or is not a directory" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
exit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Check if already installed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set +e | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dpkg -l ${package_name} | grep ${version} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
installed=$? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set -e | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if [ $installed -eq 0 ] ; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Nothing to do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
exit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+30
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enhance package version check logic The current dpkg check might miss some edge cases and the error handling could be improved. Replace the current check with: -# Check if already installed
-set +e
-dpkg -l ${package_name} | grep ${version}
-installed=$?
-set -e
-if [ $installed -eq 0 ] ; then
- # Nothing to do
- exit
-fi
+# Check if already installed
+if command -v dpkg >/dev/null 2>&1; then
+ if dpkg -l "${package_name}" 2>/dev/null | grep -q "^ii.*${version}"; then
+ echo "${package_name} version ${version} is already installed"
+ exit 0
+ fi
+elif command -v brew >/dev/null 2>&1; then
+ if brew list "${package_name}" &>/dev/null; then
+ installed_version=$(brew list "${package_name}" --versions | awk '{print $2}')
+ if [ "${installed_version}" = "${version}" ]; then
+ echo "${package_name} version ${version} is already installed"
+ exit 0
+ fi
+ fi
+fi 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Get number of cpu cores | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if [ "$(uname -s)" == "Darwin" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
num_cpus=$(sysctl -n hw.ncpu) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
num_cpus=$(grep -c ^processor /proc/cpuinfo) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Checking for elevated privileges..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
privileged_command_prefix="" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if [ ${EUID:-$(id -u)} -ne 0 ] ; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sudo echo "Script can elevate privileges." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
privileged_command_prefix="${privileged_command_prefix} sudo" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+47
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enhance privilege escalation handling The current sudo check lacks proper error handling and could fail silently. Apply this diff to improve the privilege handling: echo "Checking for elevated privileges..."
privileged_command_prefix=""
if [ ${EUID:-$(id -u)} -ne 0 ] ; then
- sudo echo "Script can elevate privileges."
+ if ! sudo -v; then
+ echo "Error: This script requires sudo privileges to install packages"
+ exit 1
+ fi
+ echo "Script can elevate privileges."
privileged_command_prefix="${privileged_command_prefix} sudo"
fi 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Download | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mkdir -p $temp_dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cd $temp_dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git clone https://github.com/mariadb-corporation/mariadb-connector-cpp.git "mariadb-connector-cpp-${version}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cd "mariadb-connector-cpp-${version}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git checkout "${version}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git submodule update --init --recursive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+55
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add integrity verification for downloaded code The script downloads and builds from source without verifying the integrity of the downloaded code. Add checksum verification after the clone: git clone https://github.com/mariadb-corporation/mariadb-connector-cpp.git "mariadb-connector-cpp-${version}"
cd "mariadb-connector-cpp-${version}"
git checkout "${version}"
+# Verify the tag
+if ! git verify-tag "${version}" 2>/dev/null; then
+ echo "Warning: Unable to verify signature of version ${version}"
+ read -p "Continue anyway? (y/N) " -n 1 -r
+ echo
+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
+ exit 1
+ fi
+fi
git submodule update --init --recursive 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mkdir build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cd build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cmake .. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
make -j${num_cpus} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+63
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add build configuration options The cmake configuration lacks important build options that might be needed for different use cases. Enhance the build configuration: -cmake ..
+cmake .. \
+ -DCMAKE_BUILD_TYPE=RelWithDebInfo \
+ -DCONC_WITH_UNIT_TESTS=Off \
+ -DINSTALL_LAYOUT=RPM \
+ -DCMAKE_INSTALL_PREFIX=/usr 📝 Committable suggestion
Suggested change
Comment on lines
+62
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for build failures The build commands lack proper error handling and logging. Apply this diff to improve build reliability: mkdir build
cd build
+
+echo "Configuring build..."
cmake ..
-make -j${num_cpus}
+
+echo "Building with ${num_cpus} CPU cores..."
+if ! make -j${num_cpus}; then
+ echo "Build failed. Check the error messages above."
+ echo "Trying again with a single core..."
+ if ! make -j1; then
+ echo "Build failed again. Aborting."
+ exit 1
+ fi
+fi 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Install | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
install_command_prefix="${privileged_command_prefix}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
${install_command_prefix} make install | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Clean up | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rm -rf $temp_dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+72
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for cleanup The cleanup process should handle errors gracefully and ensure the temporary directory is removed even if the script fails. Replace the cleanup with: -# Clean up
-rm -rf $temp_dir
+# Clean up
+cleanup() {
+ if [ -d "$temp_dir" ]; then
+ echo "Cleaning up temporary files..."
+ rm -rf "$temp_dir"
+ fi
+}
+trap cleanup EXIT 📝 Committable suggestion
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Document MariaDB C++ connector build dependencies
The MariaDB C++ connector installation script (
tools/scripts/lib_install/mariadb-connector-cpp.sh
) only listscurl
andrsync
as dependencies, but misses critical build dependencies required for compilation. The script clones and builds from source, which requires:Suggested locations to document these requirements:
tools/scripts/lib_install/mariadb-connector-cpp.sh
🔗 Analysis chain
Verify C++ connector dependencies
The MariaDB C++ connector might have additional system dependencies compared to the C connector. Consider documenting these requirements in the installation scripts.
Let me check the installation scripts specifically for MariaDB C++ connector dependencies.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 4127
Script:
Length of output: 4968