Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 3 files changed
  • 0 comments
  • 1 contributor

Showing 3 changed files with 94 additions and 16 deletions. Show diff stats Hide diff stats

  1. +14 6 Makefile
  2. +62 5 SConstruct
  3. +18 5 test/replica_set_test.c
20 Makefile
@@ -37,6 +37,10 @@ MONGO_OBJECTS=src/bson.o src/encoding.o src/gridfs.o src/md5.o src/mongo.o \
37 37 src/numbers.o
38 38 BSON_OBJECTS=src/bson.o src/numbers.o src/encoding.o
39 39
  40 +DYN_MONGO_OBJECTS=src/bson.os src/encoding.os src/gridfs.os src/md5.os \
  41 + src/mongo.os src/numbers.os
  42 +DYN_BSON_OBJECTS=src/bson.os src/numbers.os src/encoding.os
  43 +
40 44 ifeq ($(ENV),posix)
41 45 TESTS+=test/env_posix_test
42 46 MONGO_OBJECTS+=src/env_posix.o
@@ -48,6 +52,7 @@ endif
48 52 ALL_DEFINES=$(DEFINES)
49 53 ALL_DEFINES+=-D_POSIX_SOURCE
50 54 CC:=$(shell sh -c 'type $(CC) >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
  55 +DYN_FLAGS:=-fPIC -DMONGO_DLL_BUILD
51 56
52 57 # Endianness check
53 58 endian := $(shell sh -c 'echo "ab" | od -x | grep "6261" >/dev/null && echo little || echo big')
@@ -84,12 +89,12 @@ STLIBSUFFIX=a
84 89 MONGO_DYLIBNAME=$(MONGO_LIBNAME).$(DYLIBSUFFIX)
85 90 MONGO_DYLIB_MINOR_NAME=$(MONGO_LIBNAME).$(DYLIBSUFFIX).$(MONGO_MAJOR).$(MONGO_MINOR)
86 91 MONGO_DYLIB_MAJOR_NAME=$(MONGO_LIBNAME).$(DYLIBSUFFIX).$(MONGO_MAJOR)
87   -MONGO_DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(MONGO_DYLIB_MINOR_NAME) -o $(MONGO_DYLIBNAME) $(ALL_LDFLAGS)
  92 +MONGO_DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(MONGO_DYLIB_MINOR_NAME) -o $(MONGO_DYLIBNAME) $(ALL_LDFLAGS) $(DYN_MONGO_OBJECTS)
88 93
89 94 BSON_DYLIBNAME=$(BSON_LIBNAME).$(DYLIBSUFFIX)
90 95 BSON_DYLIB_MINOR_NAME=$(BSON_LIBNAME).$(DYLIBSUFFIX).$(BSON_MAJOR).$(BSON_MINOR)
91 96 BSON_DYLIB_MAJOR_NAME=$(BSON_LIBNAME).$(DYLIBSUFFIX).$(BSON_MAJOR)
92   -BSON_DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(BSON_DYLIB_MINOR_NAME) -o $(BSON_DYLIBNAME) $(ALL_LDFLAGS)
  97 +BSON_DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(BSON_DYLIB_MINOR_NAME) -o $(BSON_DYLIBNAME) $(ALL_LDFLAGS) $(DYN_BSON_OBJECTS)
93 98
94 99 # Static libraries
95 100 MONGO_STLIBNAME=$(MONGO_LIBNAME).$(STLIBSUFFIX)
@@ -136,13 +141,13 @@ md5.o: src/md5.c src/md5.h
136 141 mongo.o: src/mongo.c src/mongo.h src/bson.h src/md5.h src/env.h
137 142 numbers.o: src/numbers.c
138 143
139   -$(MONGO_DYLIBNAME): $(MONGO_OBJECTS)
  144 +$(MONGO_DYLIBNAME): $(DYN_MONGO_OBJECTS)
140 145 $(MONGO_DYLIB_MAKE_CMD)
141 146
142 147 $(MONGO_STLIBNAME): $(MONGO_OBJECTS)
143 148 $(AR) -rs $@ $(MONGO_OBJECTS)
144 149
145   -$(BSON_DYLIBNAME): $(BSON_OBJECTS)
  150 +$(BSON_DYLIBNAME): $(DYN_BSON_OBJECTS)
146 151 $(BSON_DYLIB_MAKE_CMD)
147 152
148 153 $(BSON_STLIBNAME): $(BSON_OBJECTS)
@@ -170,7 +175,7 @@ docs:
170 175 python docs/buildscripts/docs.py
171 176
172 177 clean:
173   - rm -rf $(MONGO_DYLIBNAME) $(MONGO_STLIBNAME) $(BSON_DYLIBNAME) $(BSON_STLIBNAME) src/*.o test/*_test
  178 + rm -rf $(MONGO_DYLIBNAME) $(MONGO_STLIBNAME) $(BSON_DYLIBNAME) $(BSON_STLIBNAME) src/*.o src/*.os test/*_test
174 179
175 180 deps:
176 181 $(CC) -MM -DMONGO_HAVE_STDINT src/*.c
@@ -184,4 +189,7 @@ deps:
184 189 %.o: %.c
185 190 $(CC) -o $@ -c $(ALL_CFLAGS) $<
186 191
187   -.PHONY: clean docs
  192 +%.os: %.c
  193 + $(CC) -o $@ -c $(ALL_CFLAGS) $(DYN_FLAGS) $<
  194 +
  195 +.PHONY: clean docs test
67 SConstruct
... ... @@ -1,6 +1,9 @@
1 1 # -*- mode: python; -*-
2 2
3   -VERSION = "0.5.2"
  3 +MAJOR_VERSION = "0"
  4 +MINOR_VERSION = "5"
  5 +PATCH_VERSION = "2"
  6 +VERSION = MAJOR_VERSION + "." + MINOR_VERSION + "." + PATCH_VERSION
4 7
5 8 # --- options ----
6 9 AddOption('--test-server',
@@ -49,6 +52,18 @@ AddOption('--standard-env',
49 52 action='store_true',
50 53 help='Set this option if you want to use basic, platform-agnostic networking.')
51 54
  55 +AddOption('--install-library-path',
  56 + dest='install_library_path',
  57 + default='/usr/local/lib',
  58 + action='store',
  59 + help='The shared library install path. Defaults to /usr/local/lib.')
  60 +
  61 +AddOption('--install-include-path',
  62 + dest='install_include_path',
  63 + default='/usr/local/include',
  64 + action='store',
  65 + help='The header install path. Defaults to /usr/local/include.')
  66 +
52 67 import os, sys
53 68
54 69 if GetOption('use_m32'):
@@ -168,15 +183,57 @@ if os.sys.platform == "linux2":
168 183
169 184 dynm = env.SharedLibrary( "mongoc" , mSharedObjs )
170 185 dynb = bsonEnv.SharedLibrary( "bson" , bSharedObjs )
  186 +
  187 +
171 188 # ---- Install ----
172   -prefix = "/usr/local"
  189 +if os.sys.platform == "darwim":
  190 + shared_obj_suffix = "dylib"
  191 +else:
  192 + shared_obj_suffix = "so"
  193 +
  194 +install_library_path = env.GetOption("install_library_path")
  195 +install_include_path = env.GetOption("install_include_path")
  196 +def remove_without_exception(filename):
  197 + try:
  198 + os.remove(filename)
  199 + except:
  200 + print "Could not find " + filename + ". Skipping removal."
  201 +
  202 +mongoc_target = os.path.join(install_library_path, "libmongoc." + shared_obj_suffix + "." + MAJOR_VERSION + "." + MINOR_VERSION)
  203 +mongoc_major_target = os.path.join(install_library_path, "libmongoc." + shared_obj_suffix + "." + MAJOR_VERSION)
  204 +mongoc_base_target = os.path.join(install_library_path, "libmongoc." + shared_obj_suffix)
  205 +
  206 +bson_target = os.path.join(install_library_path, "libbson." + shared_obj_suffix + "." + MAJOR_VERSION + "." + MINOR_VERSION)
  207 +bson_major_target = os.path.join(install_library_path, "libbson." + shared_obj_suffix + "." + MAJOR_VERSION)
  208 +bson_base_target = os.path.join(install_library_path, "libbson." + shared_obj_suffix)
  209 +
  210 +def uninstall_shared_libraries(target=None, source=None, env=None):
  211 + remove_without_exception(mongoc_major_target)
  212 + remove_without_exception(mongoc_base_target)
  213 + remove_without_exception(mongoc_target)
  214 +
  215 + remove_without_exception(bson_major_target)
  216 + remove_without_exception(bson_base_target)
  217 + remove_without_exception(bson_target)
  218 +
  219 +def install_shared_libraries(target=None, source=None, env=None):
  220 + import shutil
  221 + uninstall_shared_libraries()
  222 +
  223 + shutil.copy("libmongoc." + shared_obj_suffix, mongoc_target)
  224 + os.symlink(mongoc_target, mongoc_base_target)
  225 + os.symlink(mongoc_target, mongoc_major_target)
  226 +
  227 + shutil.copy("libbson." + shared_obj_suffix, bson_target)
  228 + os.symlink(bson_target, bson_base_target)
  229 + os.symlink(bson_target, bson_major_target)
173 230
174   -env.Alias("install", env.Install(os.path.join(prefix, "lib"), [dynm[0] , dynb[0] ]))
175   -env.Alias("install", env.Install(os.path.join(prefix, "include"), headers))
  231 +env.Alias("install", [], install_shared_libraries)
176 232
177   -env.Command("uninstall", None, Delete(FindInstalledFiles()))
  233 +env.Command("uninstall", [], uninstall_shared_libraries)
178 234
179 235 env.Default( env.Alias( "sharedlib" , [ dynm[0] , dynb[0] ] ) )
  236 +env.AlwaysBuild("install")
180 237
181 238 # ---- Benchmarking ----
182 239 benchmarkEnv = env.Clone()
23 test/replica_set_test.c
@@ -11,6 +11,10 @@
11 11 #define SEED_START_PORT 30000
12 12 #endif
13 13
  14 +#ifndef REPLICA_SET_NAME
  15 +#define REPLICA_SET_NAME "replica-set-foo"
  16 +#endif
  17 +
14 18 int test_connect( const char *set_name ) {
15 19
16 20 mongo conn[1];
@@ -50,6 +54,7 @@ int test_reconnect( const char *set_name ) {
50 54 mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT );
51 55 mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT + 1 );
52 56
  57 +
53 58 if( ( mongo_replset_connect( conn ) != MONGO_OK ) ) {
54 59 mongo_destroy( conn );
55 60 return res;
@@ -72,18 +77,24 @@ int test_reconnect( const char *set_name ) {
72 77 } while( 1 );
73 78 }
74 79
  80 +
75 81 return 0;
76 82 }
77 83
78 84 int test_insert_limits( const char *set_name ) {
79 85 char version[10];
80 86 mongo conn[1];
  87 + mongo_write_concern wc[1];
81 88 int i;
82 89 char key[10];
83 90 int res = 0;
84 91 bson b[1], b2[1];
85 92 bson *objs[2];
86 93
  94 + mongo_write_concern_init( wc );
  95 + wc->w = 1;
  96 + mongo_write_concern_finish( wc );
  97 +
87 98 /* We'll perform the full test if we're running v2.0 or later. */
88 99 if( mongo_get_server_version( version ) != -1 && version[0] <= '1' )
89 100 return 0;
@@ -109,10 +120,10 @@ int test_insert_limits( const char *set_name ) {
109 120
110 121 ASSERT( bson_size( b ) > conn->max_bson_size );
111 122
112   - ASSERT( mongo_insert( conn, "test.foo", b ) == MONGO_ERROR );
  123 + ASSERT( mongo_insert( conn, "test.foo", b, wc ) == MONGO_ERROR );
113 124 ASSERT( conn->err == MONGO_BSON_TOO_LARGE );
114 125
115   - mongo_clear_stored_errors( conn );
  126 + mongo_clear_errors( conn );
116 127 ASSERT( conn->err == 0 );
117 128
118 129 bson_init( b2 );
@@ -122,16 +133,18 @@ int test_insert_limits( const char *set_name ) {
122 133 objs[0] = b;
123 134 objs[1] = b2;
124 135
125   - ASSERT( mongo_insert_batch( conn, "test.foo", (const bson**)objs, 2, NULL ) == MONGO_ERROR );
  136 + ASSERT( mongo_insert_batch( conn, "test.foo", (const bson**)objs, 2, wc, 0 ) == MONGO_ERROR );
126 137 ASSERT( conn->err == MONGO_BSON_TOO_LARGE );
127 138
  139 + mongo_write_concern_destroy( wc );
  140 +
128 141 return 0;
129 142 }
130 143
131 144 int main() {
132   - ASSERT( test_connect( "replica-set-foo" ) == MONGO_OK );
  145 + ASSERT( test_connect( REPLICA_SET_NAME ) == MONGO_OK );
133 146 ASSERT( test_connect( "test-foobar" ) == MONGO_CONN_BAD_SET_NAME );
134   - ASSERT( test_insert_limits( "replica-set-foo" ) == MONGO_OK );
  147 + ASSERT( test_insert_limits( REPLICA_SET_NAME ) == MONGO_OK );
135 148
136 149 /*
137 150 ASSERT( test_reconnect( "test-rs" ) == 0 );

No commit comments for this range

Something went wrong with that request. Please try again.