Skip to content

Commit

Permalink
Build / install updates (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgilmour authored Sep 26, 2019
1 parent 1d0ddd7 commit 010c5ac
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 33 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

# Build folder
.build/
.nginx-build/

# Locally installed dependencies
.deps/

# Compiled Object files
*.slo
Expand Down
23 changes: 12 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,34 @@ endif()
# Configure the compiler.
set(CMAKE_CXX_STANDARD 14)

# Includes
set(CMAKE_INCLUDE_PATH 3rd_party/include deps/include)
include_directories(SYSTEM 3rd_party/include deps/include)
include_directories(include)

# Libraries
set(CMAKE_LIBRARY_PATH deps/lib)

# Dependencies
find_path(OPENTRACING_INCLUDE_DIR NAMES opentracing/tracer.h)
find_library(OPENTRACING_LIB opentracing)
find_package(ZLIB REQUIRED)
find_library(MSGPACK_LIB msgpack)
find_package(CURL)
find_package(Threads REQUIRED)
# Code Sanitizers, for testing.

# Code Sanitizers
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/3rd_party/sanitizers-cmake" ${CMAKE_MODULE_PATH})
find_package(Sanitizers)

set(DATADOG_LINK_LIBRARIES ${OPENTRACING_LIB} ${CURL_LIBRARIES} ${ZLIB_LIBRARIES} Threads::Threads)

# Includes
include_directories(SYSTEM 3rd_party/include)
include_directories(SYSTEM ${OPENTRACING_INCLUDE_DIR} ${CURL_INCLUDE_DIRS})
include_directories(include)

# Code
install(DIRECTORY include/datadog DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
file(GLOB DD_OPENTRACING_SOURCES "src/*.cpp")
add_compile_options(-Wall -Wextra -Werror -Wnon-virtual-dtor -Woverloaded-virtual -Wold-style-cast -std=c++14)


# Outputs
set(DATADOG_LINK_LIBRARIES ${OPENTRACING_LIB} ${CURL_LIBRARIES} ${ZLIB_LIBRARIES} Threads::Threads)

## Shared lib
if(BUILD_SHARED)
add_library(dd_opentracing SHARED ${DD_OPENTRACING_SOURCES})
Expand All @@ -64,8 +67,6 @@ if(BUILD_STATIC)
add_library(dd_opentracing-static STATIC ${DD_OPENTRACING_SOURCES})
add_sanitizers(dd_opentracing-static)
set_target_properties(dd_opentracing-static PROPERTIES OUTPUT_NAME dd_opentracing)
target_link_libraries(dd_opentracing-static ${DATADOG_LINK_LIBRARIES} datadog)

install(TARGETS dd_opentracing-static
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
Expand Down
68 changes: 47 additions & 21 deletions scripts/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
#!/bin/sh
#!/bin/bash
set -e
install_dir=$(mkdir -p "${0%/*}/../deps" && cd "${0%/*}/../deps" && echo "$PWD")
if [[ ! -d "$install_dir" ]]; then
echo "Unable to determine install directory"
exit 1
fi

OPENTRACING_VERSION=${OPENTRACING_VERSION:-1.5.1}
CURL_VERSION=${CURL_VERSION:-7.64.0}
MSGPACK_VERSION=${MSGPACK_VERSION:-3.1.1}
CURL_VERSION=${CURL_VERSION:-7.66.0}
MSGPACK_VERSION=${MSGPACK_VERSION:-3.2.0}
ZLIB_VERSION=${ZLIB_VERSION:-1.2.11}

# Just report versions and exit.
if [[ "$1" == "versions" ]]; then
echo "opentracing:$OPENTRACING_VERSION"
echo "curl:$CURL_VERSION"
echo "msgpack:$MSGPACK_VERSION"
echo "zlib:$ZLIB_VERSION"
exit 0
fi

# Allow specifying dependencies not to install. By default we want to compile
# our own versions, but under some circumstances (eg building opentracing-nginx
# docker images) some of these dependencies are already provided.
Expand Down Expand Up @@ -33,11 +47,12 @@ done

# OpenTracing
if [ "$BUILD_OPENTRACING" -eq "1" ]; then
wget https://github.com/opentracing/opentracing-cpp/archive/v${OPENTRACING_VERSION}.tar.gz -O opentracing-cpp.tar.gz
tar zxvf opentracing-cpp.tar.gz
mkdir opentracing-cpp-${OPENTRACING_VERSION}/.build
cd opentracing-cpp-${OPENTRACING_VERSION}/.build
cmake -DCMAKE_BUILD_TYPE=Release \
wget "https://github.com/opentracing/opentracing-cpp/archive/v${OPENTRACING_VERSION}.tar.gz" -O opentracing-cpp.tar.gz
tar zxf opentracing-cpp.tar.gz
mkdir -p "opentracing-cpp-${OPENTRACING_VERSION}/.build"
cd "opentracing-cpp-${OPENTRACING_VERSION}/.build"
cmake -DCMAKE_INSTALL_PREFIX="$install_dir" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="-fPIC" \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_TESTING=OFF \
Expand All @@ -46,36 +61,45 @@ if [ "$BUILD_OPENTRACING" -eq "1" ]; then
make
make install
cd ../..
rm -r "opentracing-cpp-${OPENTRACING_VERSION}/"
rm opentracing-cpp.tar.gz
fi

# Zlib
if [ "$BUILD_ZLIB" -eq "1" ]; then
wget https://zlib.net/zlib-${ZLIB_VERSION}.tar.gz
tar zxf zlib-${ZLIB_VERSION}.tar.gz
cd zlib-${ZLIB_VERSION}
CFLAGS="$CFLAGS -fPIC" ./configure --static
wget "https://zlib.net/zlib-${ZLIB_VERSION}.tar.gz"
tar zxf "zlib-${ZLIB_VERSION}.tar.gz"
mkdir -p "zlib-${ZLIB_VERSION}"
cd "zlib-${ZLIB_VERSION}"
CFLAGS="$CFLAGS -fPIC" ./configure --prefix="$install_dir" --static
make && make install
cd ..
rm -r "zlib-${ZLIB_VERSION}"
rm "zlib-${ZLIB_VERSION}.tar.gz"
fi

# Msgpack
if [ "$BUILD_MSGPACK" -eq "1" ]; then
wget https://github.com/msgpack/msgpack-c/releases/download/cpp-${MSGPACK_VERSION}/msgpack-${MSGPACK_VERSION}.tar.gz -O msgpack.tar.gz
tar zxvf msgpack.tar.gz
mkdir msgpack-${MSGPACK_VERSION}/.build
cd msgpack-${MSGPACK_VERSION}/.build
cmake -DBUILD_SHARED_LIBS=OFF ..
wget "https://github.com/msgpack/msgpack-c/releases/download/cpp-${MSGPACK_VERSION}/msgpack-${MSGPACK_VERSION}.tar.gz" -O msgpack.tar.gz
tar zxf msgpack.tar.gz
mkdir -p "msgpack-${MSGPACK_VERSION}/.build"
cd "msgpack-${MSGPACK_VERSION}/.build"
cmake -DCMAKE_INSTALL_PREFIX="$install_dir" -DBUILD_SHARED_LIBS=OFF ..
make
make install
cd ../..
rm -r "msgpack-${MSGPACK_VERSION}/"
rm msgpack.tar.gz
fi

# Libcurl
if [ "$BUILD_CURL" -eq "1" ]; then
wget https://curl.haxx.se/download/curl-${CURL_VERSION}.tar.gz
tar zxf curl-${CURL_VERSION}.tar.gz
cd curl-${CURL_VERSION}
./configure --disable-ftp \
wget "https://curl.haxx.se/download/curl-${CURL_VERSION}.tar.gz"
tar zxf "curl-${CURL_VERSION}.tar.gz"
mkdir -p "curl-${CURL_VERSION}"
cd "curl-${CURL_VERSION}"
./configure --prefix="$install_dir" \
--disable-ftp \
--disable-ldap \
--disable-dict \
--disable-telnet \
Expand All @@ -93,4 +117,6 @@ if [ "$BUILD_CURL" -eq "1" ]; then
--with-pic
make && make install
cd ..
rm -r "curl-${CURL_VERSION}/"
rm "curl-${CURL_VERSION}.tar.gz"
fi
35 changes: 35 additions & 0 deletions test/updates-needed/upstream/curl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# Checks if the version of cURL has become outdated and needs an update.
# Details are parsed from https://curl.haxx.se/docs/releases.csv and the outcome can be
# - unknown (eg: couldn't download or parse CSV file)
# - up-to-date (yay)
# - vulnerable, update and release required
# - outdated, not vulnerable but still could be updated

current_version=$(${0%/*}/../../../scripts/install_dependencies.sh versions | awk -F':' '$1 == "curl" { print $2; exit; }')

if [[ -z "$current_version" ]]; then
echo "Unable to determine current version of curl."
exit 1
fi

# This ironically requires curl installed
curl_releases=$(curl -s https://curl.haxx.se/docs/releases.csv)

latest=$(awk -F';' '{ print $2; exit; }' <<< "$curl_releases" )
if [[ $current_version == $latest ]]; then
echo "Up to date: $latest"
exit 0
fi

read -r age bugfixes changes vulns _ < <(awk -F';' -v "ver=$current_version" '$2 == ver { print $7, $9, $11, $3; exit; }' <<< "$curl_releases")

if ((vulns > 0)); then
echo "Vulnerable: $vulns reported vulnerabilities for this release. Update from $current_version to $latest"
exit 1
fi

echo "Outdated: $current_version is from $age days ago and contains $bugfixes bug fixes and $changes other changes."
if ((age > 100)); then
exit 1
fi

0 comments on commit 010c5ac

Please sign in to comment.