Skip to content

Commit

Permalink
CXX-584 implement loading of release version from file
Browse files Browse the repository at this point in the history
  • Loading branch information
rcsanchez97 committed Oct 17, 2018
1 parent 66c47d5 commit a1d3d2d
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 10 deletions.
26 changes: 26 additions & 0 deletions .evergreen/build_release.sh
@@ -0,0 +1,26 @@
#!/bin/sh

set -o errexit
set -o xtrace

#
# Copyright 2018-present MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

cd build
cmake "-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" -DMONGOCXX_ENABLE_SLOW_TESTS=ON "$@" ..

# TODO: uncomment this once dist and distcheck targets are implemented
# make DISTCHECK_BUILD_OPTS="-j 8" distcheck
12 changes: 12 additions & 0 deletions .mci.yml
Expand Up @@ -192,6 +192,18 @@ functions:
if [ "Windows_NT" == "$OS" ]; then
MONGOC_PREFIX=$(cygpath -m "$MONGOC_PREFIX")
fi
python -m virtualenv venv
cd venv
if [ -f bin/activate ]; then
. bin/activate
./bin/pip install GitPython
elif [ -f Scripts/activate ]; then
. Scripts/activate
./Scripts/pip install GitPython
fi
cd ..
.evergreen/compile.sh -DCMAKE_PREFIX_PATH="$MONGOC_PREFIX" ${cmake_flags} ${poly_flags} $ADDL_OPTS -DCMAKE_INSTALL_PREFIX=install
"test":
Expand Down
37 changes: 37 additions & 0 deletions CMakeLists.txt
Expand Up @@ -73,14 +73,51 @@ include(InstallRequiredSystemLibraries)

# Allow the user to decide whether to build the shared libaries or the static libraries.
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
set(BUILD_VERSION "0.0.0" CACHE STRING "Library version (for both libbsoncxx and libmongocxx)")

# If the user did not customize the install prefix,
# set it to live under build so we don't inadverently pollute /usr/local
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
endif()

set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${PROJECT_SOURCE_DIR}/cmake
)

include(GNUInstallDirs)
include (ParseVersion)

if(BUILD_VERSION STREQUAL "0.0.0")
if(EXISTS ${CMAKE_BINARY_DIR}/VERSION_CURRENT)
file(STRINGS ${CMAKE_BINARY_DIR}/VERSION_CURRENT BUILD_VERSION)
else()
find_package(PythonInterp)
if(PYTHONINTERP_FOUND)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} etc/calc_release_version.py
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE CALC_RELEASE_VERSION
RESULT_VARIABLE CALC_RELEASE_VERSION_RESULT
)
if(NOT CALC_RELEASE_VERSION_RESULT STREQUAL 0)
# If python failed above, stderr would tell the user about it
message(WARNING
"BUILD_VERSION not specified and could not be calculated\
(script invocation failed); setting library version to 0.0.0"
)
else()
set(BUILD_VERSION ${CALC_RELEASE_VERSION})
endif()
else()
message(WARNING
"BUILD_VERSION not specified and could not be calculated\
(Python was not found on the system); setting library version to 0.0.0"
)
endif()
endif()
endif()

if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default is Release")
Expand Down
44 changes: 44 additions & 0 deletions cmake/ParseVersion.cmake
@@ -0,0 +1,44 @@
function (ParseVersion VERSION_CONTENTS PREFIX)
# E.g., "MONGOCXX_VERSION".
string (REPLACE ";" "" VERSION_NAME ${PREFIX} _VERSION)
string (REPLACE ";" "" DIST_VERSION_NAME ${PREFIX} _DIST_VERSION)

# A list of version components separated by dots and dashes: "1.3.0-[prerelease-marker]"
string (REGEX MATCHALL "[^.-]+" VERSION ${VERSION_CONTENTS})

list (GET VERSION 0 VERSION_MAJOR)
string (REPLACE ";" "" VERSION_MAJOR_NAME ${PREFIX} _VERSION_MAJOR)
set (${VERSION_MAJOR_NAME} ${VERSION_MAJOR} PARENT_SCOPE)

list (GET VERSION 1 VERSION_MINOR)
string (REPLACE ";" "" VERSION_MINOR_NAME ${PREFIX} _VERSION_MINOR)
set (${VERSION_MINOR_NAME} ${VERSION_MINOR} PARENT_SCOPE)

list (GET VERSION 2 VERSION_PATCH)
string (REPLACE ";" "" VERSION_PATCH_NAME ${PREFIX} _VERSION_PATCH)
set (${VERSION_PATCH_NAME} ${VERSION_PATCH} PARENT_SCOPE)

string (REPLACE ";" "" VERSION_EXTRA_NAME ${PREFIX} _VERSION_EXTRA)
string (REPLACE ";" "" VERSION_DIST_EXTRA_NAME ${PREFIX} _VERSION_DIST_EXTRA)
list (LENGTH VERSION VERSION_LENGTH)
if (VERSION_LENGTH GREATER 3)
list (GET VERSION 3 VERSION_EXTRA)
set (${VERSION_DIST_EXTRA_NAME} "-${VERSION_EXTRA}" PARENT_SCOPE)
set (${VERSION_EXTRA_NAME} "-pre" PARENT_SCOPE)
set (${VERSION_NAME}
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-pre"
PARENT_SCOPE)
set (${DIST_VERSION_NAME}
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}${VERSION_EXTRA}"
PARENT_SCOPE)
else ()
set (${VERSION_DIST_EXTRA_NAME} "" PARENT_SCOPE)
set (${VERSION_EXTRA_NAME} "" PARENT_SCOPE)
set (${VERSION_NAME}
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
PARENT_SCOPE)
set (${DIST_VERSION_NAME}
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
PARENT_SCOPE)
endif ()
endfunction (ParseVersion)
7 changes: 2 additions & 5 deletions src/bsoncxx/CMakeLists.txt
Expand Up @@ -14,12 +14,8 @@

project(BSONCXX)

# Update these as needed.
ParseVersion (${BUILD_VERSION} BSONCXX)
# TODO: read from file
set(BSONCXX_VERSION_MAJOR 3)
set(BSONCXX_VERSION_MINOR 5)
set(BSONCXX_VERSION_PATCH 0)
set(BSONCXX_VERSION_EXTRA "-rc0-pre")
set(BSONCXX_ABI_VERSION _noabi)

option(BSONCXX_POLY_USE_MNMLSTC "Use MNMLSTC/core for stdx polyfills" OFF)
Expand Down Expand Up @@ -71,6 +67,7 @@ endif()

set(BSONCXX_VERSION_NO_EXTRA ${BSONCXX_VERSION_MAJOR}.${BSONCXX_VERSION_MINOR}.${BSONCXX_VERSION_PATCH})
set(BSONCXX_VERSION ${BSONCXX_VERSION_NO_EXTRA}${BSONCXX_VERSION_EXTRA})
message ("bsoncxx version: ${BSONCXX_VERSION}")
set(BSONCXX_INLINE_NAMESPACE "v${BSONCXX_ABI_VERSION}")
set(BSONCXX_HEADER_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/bsoncxx/${BSONCXX_INLINE_NAMESPACE}" CACHE INTERNAL "")

Expand Down
7 changes: 2 additions & 5 deletions src/mongocxx/CMakeLists.txt
Expand Up @@ -14,19 +14,16 @@

project(MONGOCXX)

# Update these as needed.
ParseVersion (${BUILD_VERSION} MONGOCXX)
# TODO: read from file
set(MONGOCXX_VERSION_MAJOR 3)
set(MONGOCXX_VERSION_MINOR 5)
set(MONGOCXX_VERSION_PATCH 0)
set(MONGOCXX_VERSION_EXTRA "-rc0-pre")
set(MONGOCXX_ABI_VERSION _noabi)

option(MONGOCXX_ENABLE_SSL "Enable SSL - if the underlying C driver offers it" ON)
option(MONGOCXX_ENABLE_SLOW_TESTS "Run slow tests when invoking the the test target" OFF)

set(MONGOCXX_VERSION_NO_EXTRA ${MONGOCXX_VERSION_MAJOR}.${MONGOCXX_VERSION_MINOR}.${MONGOCXX_VERSION_PATCH})
set(MONGOCXX_VERSION ${MONGOCXX_VERSION_NO_EXTRA}${MONGOCXX_VERSION_EXTRA})
message ("mongocxx version: ${MONGOCXX_VERSION}")
set(MONGOCXX_INLINE_NAMESPACE "v${MONGOCXX_ABI_VERSION}")
set(MONGOCXX_HEADER_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/mongocxx/${MONGOCXX_INLINE_NAMESPACE}" CACHE INTERNAL "")

Expand Down

0 comments on commit a1d3d2d

Please sign in to comment.