Skip to content

Commit ba3061d

Browse files
committed
Automate checking against MQ 9.1, and fix #1
1 parent 05e2721 commit ba3061d

File tree

4 files changed

+91
-15
lines changed

4 files changed

+91
-15
lines changed

code/ibmmq/ibmmqc.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,16 @@ static PyObject * ibmmqc_MQCONNX(PyObject *self, PyObject *args) {
235235
PMQCD mqcd = NULL;
236236
PMQSCO sco = NULL;
237237
PMQCSP csp = NULL;
238+
239+
/* The MQBNO structure was introduced after the oldest version of MQ (9.1) stated as
240+
* supported by this package. So we have to use ifdefs to not refer to it if
241+
* that's where we are building.
242+
*/
243+
#if defined MQBNO_CURRENT_VERSION
238244
PMQBNO bno = NULL;
245+
#else
246+
void *bno = NULL;
247+
#endif
239248

240249
Py_ssize_t mqcd_len = 0;
241250
Py_ssize_t sco_len = 0;
@@ -270,7 +279,7 @@ static PyObject * ibmmqc_MQCONNX(PyObject *self, PyObject *args) {
270279

271280
// SPLProtection is the only MQCD field more recent than the baseline 9.1
272281
// ... and it's only really valid for qmgr channels so should never be set by
273-
// client applications! But it's convenient for testing VERSION policies here.
282+
// client applications. But it's convenient for testing VERSION policies here.
274283
#if defined(MQCD_VERSION_12)
275284
if (mqcd->SPLProtection != 0) {
276285
if (mqcd->Version < MQCD_VERSION_12) {
@@ -290,10 +299,11 @@ static PyObject * ibmmqc_MQCONNX(PyObject *self, PyObject *args) {
290299
if (cno->Version < MQCNO_VERSION_7) {
291300
cno->Version = MQCNO_VERSION_7;
292301
}
293-
#endif
294302
}
303+
#endif
295304

296305
if (sco != NULL) {
306+
297307
#if defined(MQSCO_VERSION_6)
298308
if (sco->KeyRepoPasswordPtr) {
299309
if (sco->Version < MQSCO_VERSION_6) {
@@ -314,6 +324,10 @@ static PyObject * ibmmqc_MQCONNX(PyObject *self, PyObject *args) {
314324
#endif
315325
}
316326

327+
328+
/* The bno variable is always available even for older levels of MQ. But it is not USABLE without the
329+
* MQBNO structure and the CNO versions being suitable.
330+
*/
317331
if (bno != NULL) {
318332
#if defined(MQCNO_VERSION_8)
319333
if (cno->Version < MQCNO_VERSION_8) {
@@ -1341,7 +1355,7 @@ static PyObject* ibmmqc_MQSETMP(PyObject *self, PyObject *args) {
13411355
/* String value */
13421356
case MQTYPE_STRING:
13431357
v = PyUnicode_AsEncodedString(property_value_object,"utf-8","ignore");
1344-
value = PyBytes_AsString(v);
1358+
value = PyBytes_AsString(v);
13451359
break;
13461360

13471361
/* 32-bit floating-point number value */

setup.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616
# This is the only place where package version number is set!
1717
# The version should correspond to PEP440 and gets normalised if
1818
# not in the right format. VRM can be followed with a|b|rc with a further numeric
19-
# to indicate alpha/beta/release candidate versions.
19+
# to indicate alpha/beta/release-candidate versions.
2020
VERSION = '2.0.0b2'
2121

2222
# If the MQ SDK is in a non-default location, set MQ_FILE_PATH environment variable.
23-
# If that env var is not set, then use a default root of the current directory (which
24-
# might not be necessary, but shouldn't do any harm.
2523
custom_path = os.environ.get('MQ_FILE_PATH', None)
2624

2725
# Always build in 64-bit mode. And use libmqm regardless of whether the package
@@ -31,15 +29,20 @@
3129
# Seems the closest exception (now an alias of EnvironmentError)
3230
raise OSError("Cannot build in 32-bit mode. Only 64-bit systems supported.")
3331

32+
# The include_dirs and library_dirs used to be lists that always included the default
33+
# directories. But if you've gone to the trouble of setting a non-default
34+
# custom_path, then we should only use that. Otherwise the compile might get confused and use
35+
# the "wrong" version of the files.
36+
3437
def get_windows_settings():
3538
""" Windows settings.
3639
"""
3740

38-
library_dirs = [r'c:\Program Files\IBM\MQ\tools\Lib64']
3941
include_dirs = [r'c:\Program Files\IBM\MQ\tools\c\include']
42+
library_dirs = [r'c:\Program Files\IBM\MQ\tools\Lib64']
4043
if custom_path:
41-
library_dirs.append(r'{}\tools\Lib64'.format(custom_path))
42-
include_dirs.append(r'{}\tools\c\include'.format(custom_path))
44+
library_dirs = [r'{}\tools\Lib64'.format(custom_path)]
45+
include_dirs = [r'{}\tools\c\include'.format(custom_path)]
4346

4447
libraries = ['mqm']
4548

@@ -53,8 +56,8 @@ def get_aix_settings():
5356
include_dirs = ['/usr/mqm/inc']
5457

5558
if custom_path:
56-
library_dirs.append('{}/lib64'.format(custom_path))
57-
include_dirs.append('{}/inc'.format(custom_path))
59+
library_dirs = ['{}/lib64'.format(custom_path)]
60+
include_dirs = ['{}/inc'.format(custom_path)]
5861

5962
libraries = ['mqm_r']
6063

@@ -68,8 +71,8 @@ def get_generic_unix_settings():
6871
include_dirs = ['/opt/mqm/inc']
6972

7073
if custom_path:
71-
library_dirs.append('{}/lib64'.format(custom_path))
72-
include_dirs.append('{}/inc'.format(custom_path))
74+
library_dirs = ['{}/lib64'.format(custom_path)]
75+
include_dirs = ['{}/inc'.format(custom_path)]
7376

7477
# Get an embedded rpath into the library which can reduce need for LD_LIBRARY_PATH
7578
for d in library_dirs:
@@ -141,7 +144,10 @@ def get_locations_by_command_path(command_path):
141144
if os.path.isfile(p):
142145
found_headers = True
143146
if not found_headers:
144-
raise FileNotFoundError("Cannot find MQ C header files. Ensure you have already installed the MQ Client and SDK")
147+
msg = "Cannot find MQ C header files.\n"
148+
msg += "Ensure you have already installed the MQ Client and SDK.\n"
149+
msg += "Use the MQ_FILE_PATH environment variable to identify a non-default location."
150+
raise FileNotFoundError(msg)
145151

146152
LONG_DESCRIPTION = """
147153
Python library for IBM MQ
@@ -179,7 +185,7 @@ def get_locations_by_command_path(command_path):
179185
print('Here is the message:', msg)
180186
"""
181187

182-
# Define how the C module gets built. Set flags to try to build using the Python 3.9
188+
# Define how the C module gets built. Set flags to build using the Python 3.9
183189
# Limited API which should make the binary extension forwards compatible.
184190
mqi_extension = Extension('ibmmq.ibmmqc', c_source,
185191
define_macros=[('PYVERSION', '"' + VERSION + '"'),

tools/check

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,23 @@ else
223223
#fi
224224
fi
225225

226+
# Try building against an old level of MQ
227+
if [ -x $curdir/checkOld ]
228+
then
229+
echo
230+
continueYN "Build against an old level of MQ"
231+
if [ $? -eq 0 ]
232+
then
233+
cd $curdir
234+
checkOld
235+
if [ $? -ne 0 ]
236+
then
237+
echo " ERROR : Problem running old level build"
238+
exit 1
239+
fi
240+
fi
241+
fi
242+
226243
# Give a chance to quit now, before spending a lot of time on tests
227244
if [ -x $curdir/checkRemote ]
228245
then

tools/checkOld

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# Make sure we can compile against the oldest "supported" level of MQ (9.1)
4+
# Assumes the MQ installation is under /opt/mqm.91
5+
6+
curdir=`pwd`
7+
8+
# Location of old header files
9+
export MQ_FILE_PATH=/opt/mqm.91
10+
11+
venv=../../venv
12+
. $venv/bin/activate
13+
pip uninstall -y ibmmq
14+
cd ..
15+
16+
# Do an install of the local tree to check it builds
17+
pip install --verbose -e .
18+
pip list 2>&1| grep -q ibmmq
19+
if [ $? -ne 0 ]
20+
then
21+
echo "ERROR: Could not install ibmmq"
22+
exit 1
23+
fi
24+
25+
# MQ 9.1.5 Redist Client package does not have setmqenv, so
26+
# we fake it and export the symbols that might be relevant
27+
$MQ_FILE_PATH/bin/crtmqenv -k -s > /tmp/crtmqenv
28+
. /tmp/crtmqenv
29+
export LD_LIBRARY_PATH
30+
export PATH
31+
export MQ_INSTALLATION_NAME
32+
export MQ_INSTALLATION_PATH
33+
34+
# Now try to connect as a client to the qmgr. Since my machine
35+
# is using the redist client package, it can't rely on version-switching
36+
# to use local bindings.
37+
python $curdir/../code/examples/connect_client.py
38+
exit $?
39+

0 commit comments

Comments
 (0)