Skip to content

Commit 90c4b9e

Browse files
committed
CDRIVER-2937 support BUILD_VERSION in addition to VERSION_CURRENT
1 parent 4bdf014 commit 90c4b9e

File tree

10 files changed

+112
-133
lines changed

10 files changed

+112
-133
lines changed

CMakeLists.txt

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -73,41 +73,52 @@ set (CMAKE_MODULE_PATH
7373
include (InstallRequiredSystemLibraries)
7474
include (GNUInstallDirs)
7575

76+
set (BUILD_VERSION "0.0.0" CACHE STRING "Library version (for both libbson and libmongoc)")
77+
78+
include (ParseVersion)
79+
7680
# Set MONGOC_MAJOR_VERSION, MONGOC_MINOR_VERSION, etc.
77-
include (LoadVersion)
78-
if (NOT EXISTS ${PROJECT_SOURCE_DIR}/VERSION_CURRENT)
79-
message (WARNING
80-
"${PROJECT_SOURCE_DIR}/VERSION_CURRENT not found; using version 0.0.0.\
81-
See the \\\"Building from git\\\" section of the installation guide for details."
82-
)
83-
set (MONGOC_MAJOR_VERSION "0")
84-
set (MONGOC_MINOR_VERSION "0")
85-
set (MONGOC_MICRO_VERSION "0")
86-
set (MONGOC_PRERELEASE_VERSION "")
87-
set (MONGOC_PRERELEASE_DIST_VERSION "")
88-
set (MONGOC_VERSION "${MONGOC_MAJOR_VERSION}.${MONGOC_MINOR_VERSION}.${MONGOC_MICRO_VERSION}")
89-
set (MONGOC_DIST_VERSION "${MONGOC_MAJOR_VERSION}.${MONGOC_MINOR_VERSION}.${MONGOC_MICRO_VERSION}")
90-
else ()
91-
LoadVersion (${PROJECT_SOURCE_DIR}/VERSION_CURRENT MONGOC)
92-
endif ()
93-
if (NOT EXISTS ${PROJECT_SOURCE_DIR}/VERSION_RELEASED)
94-
message (WARNING
95-
"${PROJECT_SOURCE_DIR}/VERSION_RELEASED not found; using version 0.0.0.\
96-
See the \\\"Building from git\\\" section of the installation guide for details."
97-
)
98-
set (MONGOC_RELEASED_MAJOR_VERSION "0")
99-
set (MONGOC_RELEASED_MINOR_VERSION "0")
100-
set (MONGOC_RELEASED_MICRO_VERSION "0")
101-
set (MONGOC_RELEASED_VERSION "${MONGOC_MAJOR_VERSION}.${MONGOC_MINOR_VERSION}.${MONGOC_MICRO_VERSION}")
102-
else ()
103-
LoadVersion (${PROJECT_SOURCE_DIR}/VERSION_RELEASED MONGOC_RELEASED)
104-
endif ()
105-
if (EXISTS ${PROJECT_SOURCE_DIR}/VERSION_CURRENT AND EXISTS ${PROJECT_SOURCE_DIR}/VERSION_RELEASED)
106-
set (DIST_VERSION_SET 1)
81+
if (BUILD_VERSION STREQUAL "0.0.0")
82+
if (EXISTS ${PROJECT_SOURCE_DIR}/VERSION_CURRENT)
83+
file (STRINGS ${PROJECT_SOURCE_DIR}/VERSION_CURRENT BUILD_VERSION)
84+
message ("file VERSION_CURRENT contained BUILD_VERSION ${BUILD_VERSION}")
85+
else ()
86+
find_package (PythonInterp)
87+
if (PYTHONINTERP_FOUND)
88+
execute_process (
89+
COMMAND ${PYTHON_EXECUTABLE} build/calc_release_version.py
90+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
91+
OUTPUT_VARIABLE CALC_RELEASE_VERSION
92+
RESULT_VARIABLE CALC_RELEASE_VERSION_RESULT
93+
OUTPUT_STRIP_TRAILING_WHITESPACE
94+
)
95+
if (NOT CALC_RELEASE_VERSION_RESULT STREQUAL 0)
96+
# If python failed above, stderr would tell the user about it
97+
message (WARNING
98+
"BUILD_VERSION not specified and could not be calculated\
99+
(script invocation failed); setting library version to 0.0.0"
100+
)
101+
else ()
102+
set (BUILD_VERSION ${CALC_RELEASE_VERSION})
103+
message ("calculated BUILD_VERSION ${BUILD_VERSION}")
104+
endif ()
105+
else ()
106+
message (WARNING
107+
"BUILD_VERSION not specified and could not be calculated\
108+
(Python was not found on the system); setting library version to 0.0.0"
109+
)
110+
endif ()
111+
message ("storing BUILD_VERSION ${BUILD_VERSION} in file VERSION_CURRENT for later use")
112+
file (WRITE ${PROJECT_SOURCE_DIR}/VERSION_CURRENT ${BUILD_VERSION})
113+
endif ()
107114
else ()
108-
set (DIST_VERSION_SET 0)
115+
message ("storing BUILD_VERSION ${BUILD_VERSION} in file VERSION_CURRENT for later use")
116+
file (WRITE ${PROJECT_SOURCE_DIR}/VERSION_CURRENT ${BUILD_VERSION})
109117
endif ()
110118

119+
include (LoadVersion)
120+
LoadVersion (${PROJECT_SOURCE_DIR}/VERSION_CURRENT MONGOC)
121+
111122
include (MaintainerFlags)
112123

113124
if ( (ENABLE_BUILD_DEPENDECIES STREQUAL OFF) AND (NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) )
@@ -271,25 +282,13 @@ if (ENABLE_MONGOC)
271282
add_subdirectory (src/libmongoc)
272283

273284
if (ENABLE_MAN_PAGES STREQUAL ON OR ENABLE_HTML_DOCS STREQUAL ON)
274-
if (DIST_VERSION_SET)
275-
find_package (Sphinx REQUIRED)
276-
add_custom_target (doc
277-
ALL
278-
DEPENDS
279-
$<$<STREQUAL:"${ENABLE_BSON}","ON">:bson-doc>
280-
$<$<STREQUAL:"${ENABLE_MONGOC}","ON">:mongoc-doc>
281-
)
282-
else ()
283-
string (CONCAT DISTERRMSG
284-
"The doc target is disabled. Generate VERSION_CURRENT and "
285-
"VERSION_RELEASED before invoking CMake to enable. Details are "
286-
"in the \\\"Building from git\\\" section of the installation guide."
287-
)
288-
289-
add_custom_target (doc
290-
COMMAND ${CMAKE_COMMAND} -E echo "${DISTERRMSG}"
291-
)
292-
endif ()
285+
find_package (Sphinx REQUIRED)
286+
add_custom_target (doc
287+
ALL
288+
DEPENDS
289+
$<$<STREQUAL:"${ENABLE_BSON}","ON">:bson-doc>
290+
$<$<STREQUAL:"${ENABLE_MONGOC}","ON">:mongoc-doc>
291+
)
293292
endif ()
294293

295294
# Implement 'dist' and 'distcheck' targets
@@ -315,7 +314,6 @@ if (ENABLE_MONGOC)
315314
README.rst
316315
THIRD_PARTY_NOTICES
317316
VERSION_CURRENT
318-
VERSION_RELEASED
319317
# This sub-directory is added later, so manually include here
320318
generate_uninstall/CMakeLists.txt
321319
)
@@ -350,7 +348,7 @@ if (ENABLE_MONGOC)
350348
${ALL_DIST} ${dist_generated_depends}
351349
)
352350

353-
if (DIST_VERSION_SET AND ENABLE_BSON MATCHES "ON|AUTO" AND ENABLE_MAN_PAGES STREQUAL ON AND ENABLE_HTML_DOCS STREQUAL ON)
351+
if (ENABLE_BSON MATCHES "ON|AUTO" AND ENABLE_MAN_PAGES STREQUAL ON AND ENABLE_HTML_DOCS STREQUAL ON)
354352
# Since our 'dist' implementation does not add top-level targets for every
355353
# file to be included, we declare a dependency on the 'mongo-doc' target so
356354
# that documentation is built before the distribution tarball is generated.
@@ -369,7 +367,7 @@ if (ENABLE_MONGOC)
369367
string (CONCAT DISTERRMSG
370368
"The dist and distcheck targets are disabled. Set ENABLE_BSON=ON, "
371369
"ENABLE_MAN_PAGES=ON, ENABLE_HTML_DOCS=ON, and generate VERSION_CURRENT "
372-
"and VERSION_RELEASED to enable."
370+
"to enable."
373371
)
374372

375373
add_custom_target (dist

build/cmake/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set (build_cmake_MODULES
99
LoadVersion.cmake
1010
MaintainerFlags.cmake
1111
MongoCPackage.cmake
12+
ParseVersion.cmake
1213
SphinxBuild.cmake
1314
)
1415

build/cmake/ParseVersion.cmake

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function (ParseVersion VERSION_CONTENTS PREFIX)
2+
# E.g., "MONGOC_VERSION".
3+
string (REPLACE ";" "" VERSION_NAME ${PREFIX} _VERSION)
4+
string (REPLACE ";" "" DIST_VERSION_NAME ${PREFIX} _DIST_VERSION)
5+
6+
# A list of version components separated by dots and dashes: "1.3.0-[prerelease-marker]"
7+
string (REGEX MATCHALL "[^.-]+" VERSION ${VERSION_CONTENTS})
8+
9+
list (GET VERSION 0 VERSION_MAJOR)
10+
string (REPLACE ";" "" VERSION_MAJOR_NAME ${PREFIX} _VERSION_MAJOR)
11+
set (${VERSION_MAJOR_NAME} ${VERSION_MAJOR} PARENT_SCOPE)
12+
13+
list (GET VERSION 1 VERSION_MINOR)
14+
string (REPLACE ";" "" VERSION_MINOR_NAME ${PREFIX} _VERSION_MINOR)
15+
set (${VERSION_MINOR_NAME} ${VERSION_MINOR} PARENT_SCOPE)
16+
17+
list (GET VERSION 2 VERSION_PATCH)
18+
string (REPLACE ";" "" VERSION_PATCH_NAME ${PREFIX} _VERSION_PATCH)
19+
set (${VERSION_PATCH_NAME} ${VERSION_PATCH} PARENT_SCOPE)
20+
21+
string (REPLACE ";" "" VERSION_EXTRA_NAME ${PREFIX} _VERSION_EXTRA)
22+
string (REPLACE ";" "" VERSION_DIST_EXTRA_NAME ${PREFIX} _VERSION_DIST_EXTRA)
23+
list (LENGTH VERSION VERSION_LENGTH)
24+
if (VERSION_LENGTH GREATER 3)
25+
list (GET VERSION 3 VERSION_EXTRA)
26+
set (${VERSION_DIST_EXTRA_NAME} "-${VERSION_EXTRA}" PARENT_SCOPE)
27+
set (${VERSION_EXTRA_NAME} "-pre" PARENT_SCOPE)
28+
set (${VERSION_NAME}
29+
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-pre"
30+
PARENT_SCOPE)
31+
set (${DIST_VERSION_NAME}
32+
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}${VERSION_EXTRA}"
33+
PARENT_SCOPE)
34+
else ()
35+
set (${VERSION_DIST_EXTRA_NAME} "" PARENT_SCOPE)
36+
set (${VERSION_EXTRA_NAME} "" PARENT_SCOPE)
37+
set (${VERSION_NAME}
38+
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
39+
PARENT_SCOPE)
40+
set (${DIST_VERSION_NAME}
41+
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
42+
PARENT_SCOPE)
43+
endif ()
44+
endfunction (ParseVersion)

debian/rules

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
77
DPKG_EXPORT_BUILDFLAGS = 1
88
include /usr/share/dpkg/default.mk
9+
include /usr/share/dpkg/pkg-info.mk
910

1011
# see FEATURE AREAS in dpkg-buildflags(1)
1112
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
@@ -22,6 +23,7 @@ export DEB_LDFLAGS_MAINT_APPEND := -lpthread
2223

2324
override_dh_auto_configure:
2425
dh_auto_configure -- \
26+
-DBUILD_VERSION=$(DEB_VERSION_UPSTREAM) \
2527
-DENABLE_MONGOC=ON \
2628
-DENABLE_BSON=ON \
2729
-DENABLE_MAN_PAGES=ON \

src/libbson/CMakeLists.txt

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,9 @@ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/build/cmake)
2020
# Set BSON_MAJOR_VERSION, BSON_MINOR_VERSION, etc.
2121
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/../../build/cmake)
2222
include (LoadVersion)
23-
if (NOT EXISTS ${PROJECT_SOURCE_DIR}/../../VERSION_CURRENT)
24-
message (WARNING
25-
"${PROJECT_SOURCE_DIR}/../../VERSION_CURRENT not found; using version 0.0.0.\
26-
See the \\\"Building from git\\\" section of the installation guide for details."
27-
)
28-
set (BSON_MAJOR_VERSION "0")
29-
set (BSON_MINOR_VERSION "0")
30-
set (BSON_MICRO_VERSION "0")
31-
set (BSON_PRERELEASE_VERSION "")
32-
set (BSON_VERSION "${BSON_MAJOR_VERSION}.${BSON_MINOR_VERSION}.${BSON_MICRO_VERSION}")
33-
else ()
34-
LoadVersion (${PROJECT_SOURCE_DIR}/../../VERSION_CURRENT BSON)
35-
endif ()
36-
if (NOT EXISTS ${PROJECT_SOURCE_DIR}/../../VERSION_RELEASED)
37-
message (WARNING
38-
"${PROJECT_SOURCE_DIR}/../../VERSION_RELEASED not found; using version 0.0.0.\
39-
See the \\\"Building from git\\\" section of the installation guide for details."
40-
)
41-
set (BSON_RELEASED_MAJOR_VERSION "0")
42-
set (BSON_RELEASED_MINOR_VERSION "0")
43-
set (BSON_RELEASED_MICRO_VERSION "0")
44-
set (BSON_RELEASED_PRERELEASE_VERSION "")
45-
set (BSON_RELEASED_VERSION "${BSON_MAJOR_VERSION}.${BSON_MINOR_VERSION}.${BSON_MICRO_VERSION}")
46-
else ()
47-
LoadVersion (${PROJECT_SOURCE_DIR}/../../VERSION_RELEASED BSON_RELEASED)
48-
endif ()
23+
LoadVersion (${PROJECT_SOURCE_DIR}/../../VERSION_CURRENT BSON)
4924

5025
message ("libbson version (from VERSION_CURRENT file): ${BSON_VERSION}")
51-
if (NOT ${BSON_VERSION} STREQUAL ${BSON_RELEASED_VERSION})
52-
message ("libbson previous release (from VERSION_RELEASED file): ${BSON_RELEASED_VERSION}")
53-
endif ()
5426

5527
set (BSON_API_VERSION 1.0)
5628

src/libbson/doc/conf.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
extensions = [
1212
'mongoc',
1313
'taglist',
14-
'sphinx.ext.extlinks',
1514
]
1615

1716
# General information about the project.
@@ -21,23 +20,6 @@
2120
version_path = os.path.join(
2221
os.path.dirname(__file__), '../../..', 'VERSION_CURRENT')
2322
version = open(version_path).read().strip()
24-
release_path = os.path.join(
25-
os.path.dirname(__file__), '../../..', 'VERSION_RELEASED')
26-
release = open(release_path).read().strip()
27-
release_major, release_minor, release_patch = release.split('.')
28-
release_download = 'https://github.com/mongodb/libbson/releases/download/{0}/libbson-{0}.tar.gz'.format(release)
29-
rst_prolog = """
30-
.. |release_major| replace:: %(release_major)s
31-
32-
.. |release_minor| replace:: %(release_minor)s
33-
34-
.. |release_patch| replace:: %(release_patch)s
35-
36-
.. |release_download| replace:: https://github.com/mongodb/libbson/releases/download/%(release)s/libbson-%(release)s.tar.gz
37-
""" % locals()
38-
39-
# The extension requires the "base" to contain '%s' exactly once, but we never intend to use it though
40-
extlinks = {'release': (release_download+'%s', '')}
4123

4224
language = 'en'
4325
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

src/libmongoc/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/../../build/cm
77
include (InstallRequiredSystemLibraries)
88

99
message ("libmongoc version (from VERSION_CURRENT file): ${MONGOC_VERSION}")
10-
if (NOT ${MONGOC_VERSION} STREQUAL ${MONGOC_RELEASED_VERSION})
11-
message ("libmongoc previous release (from VERSION_RELEASED file): ${MONGOC_RELEASED_VERSION}")
12-
endif ()
1310

1411
# Defaults.
1512
set (MONGOC_ENABLE_SSL 0)

src/libmongoc/doc/conf.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
'mongoc',
1414
'taglist',
1515
'sphinx.ext.intersphinx',
16-
'sphinx.ext.extlinks',
1716
]
1817

1918
# General information about the project.
@@ -24,23 +23,8 @@
2423
version_path = os.path.join(
2524
os.path.dirname(__file__), '../../..', 'VERSION_CURRENT')
2625
version = open(version_path).read().strip()
27-
release_path = os.path.join(
28-
os.path.dirname(__file__), '../../..', 'VERSION_RELEASED')
29-
release = open(release_path).read().strip()
30-
release_major, release_minor, release_patch = release.split('.')
31-
release_download = 'https://github.com/mongodb/mongo-c-driver/releases/download/{0}/mongo-c-driver-{0}.tar.gz'.format(release)
32-
rst_prolog = """
33-
.. |release_major| replace:: %(release_major)s
34-
35-
.. |release_minor| replace:: %(release_minor)s
36-
37-
.. |release_patch| replace:: %(release_patch)s
38-
39-
.. |release_download| replace:: https://github.com/mongodb/mongo-c-driver/releases/download/%(release)s/mongo-c-driver-%(release)s.tar.gz
40-
""" % locals()
4126

4227
# The extension requires the "base" to contain '%s' exactly once, but we never intend to use it though
43-
extlinks = {'release': (release_download+'%s', '')}
4428

4529
language = 'en'
4630
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

src/libmongoc/doc/installing.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ Building from a release tarball
106106

107107
Unless you intend to contribute to mongo-c-driver and/or libbson, you will want to build from a release tarball.
108108

109-
The most recent release of libmongoc and libbson, both of which are included in mongo-c-driver, is |release| and can be :release:`downloaded here <>`. The instructions in this document utilize ``cmake``'s out-of-source build feature to keep build artifacts separate from source files.
109+
The most recent release of libmongoc and libbson, both of which are included in mongo-c-driver, can be downloaded here <https://github.com/mongodb/mongo-c-driver/releases/latest>. The instructions in this document utilize ``cmake``'s out-of-source build feature to keep build artifacts separate from source files.
110110

111111
The following snippet will download and extract the driver, and configure it:
112112

113113
.. parsed-literal::
114114
115-
$ wget |release_download|
116-
$ tar xzf mongo-c-driver-|release|.tar.gz
117-
$ cd mongo-c-driver-|release|
115+
$ wget https://github.com/mongodb/mongo-c-driver/releases/download/x.y.z/mongo-c-driver-x.y.z.tar.gz
116+
$ tar xzf mongo-c-driver-x.y.z.tar.gz
117+
$ cd mongo-c-driver-x.y.z
118118
$ mkdir cmake-build
119119
$ cd cmake-build
120120
$ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
@@ -125,7 +125,7 @@ If ``cmake`` completed successfully, you will see a considerable amount of outpu
125125

126126
.. parsed-literal::
127127
128-
-- Build files have been written to: /home/user/mongo-c-driver-|release|/cmake-build
128+
-- Build files have been written to: /home/user/mongo-c-driver-x.y.z/cmake-build
129129
130130
If ``cmake`` concludes with anything different, then there is likely an error or some other problem with the build. Review the output to identify and correct the problem.
131131

@@ -175,7 +175,6 @@ Clone the repository and build the current master or a particular release tag:
175175
$ cd mongo-c-driver
176176
$ git checkout x.y.z # To build a particular release
177177
$ python build/calc_release_version.py > VERSION_CURRENT
178-
$ python build/calc_release_version.py -p > VERSION_RELEASED
179178
$ mkdir cmake-build
180179
$ cd cmake-build
181180
$ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
@@ -216,9 +215,9 @@ Download the latest release tarball:
216215

217216
.. parsed-literal::
218217
219-
$ curl -LO |release_download|
220-
$ tar xzf mongo-c-driver-|release|.tar.gz
221-
$ cd mongo-c-driver-|release|
218+
$ curl -LO https://github.com/mongodb/mongo-c-driver/releases/download/x.y.z/mongo-c-driver-x.y.z.tar.gz
219+
$ tar xzf mongo-c-driver-x.y.z.tar.gz
220+
$ cd mongo-c-driver-x.y.z
222221
223222
Build and install the driver:
224223

@@ -241,7 +240,7 @@ Let's start by generating Visual Studio project files. The following assumes we
241240

242241
.. parsed-literal::
243242
244-
cd mongo-c-driver-|release|
243+
cd mongo-c-driver-x.y.z
245244
mkdir cmake-build
246245
cd cmake-build
247246
cmake -G "Visual Studio 14 2015 Win64" \\

src/libmongoc/doc/mongoc_version.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ This may be useful if you only want to enable a feature on a certain version of
1515
1616
#include <mongoc/mongoc.h>
1717
18-
#define MONGOC_MAJOR_VERSION (|release_major|)
19-
#define MONGOC_MINOR_VERSION (|release_minor|)
20-
#define MONGOC_MICRO_VERSION (|release_patch|)
21-
#define MONGOC_VERSION_S "|release|"
18+
#define MONGOC_MAJOR_VERSION (x)
19+
#define MONGOC_MINOR_VERSION (y)
20+
#define MONGOC_MICRO_VERSION (z)
21+
#define MONGOC_VERSION_S "x.y.z"
2222
#define MONGOC_VERSION_HEX ((1 << 24) | (0 << 16) | (0 << 8) | 0)
2323
#define MONGOC_CHECK_VERSION(major, minor, micro)
2424

0 commit comments

Comments
 (0)