Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

CDRIVER-141 fix build and install for shared libs

  • Loading branch information...
commit 5681a8a324bffe702a6c275473a3fe5c59f966c9 1 parent 8e4810a
Kyle Banker banker authored
Showing with 82 additions and 16 deletions.
  1. +14 −6 Makefile
  2. +50 −5 SConstruct
  3. +18 −5 test/replica_set_test.c
20 Makefile
View
@@ -37,6 +37,10 @@ MONGO_OBJECTS=src/bson.o src/encoding.o src/gridfs.o src/md5.o src/mongo.o \
src/numbers.o
BSON_OBJECTS=src/bson.o src/numbers.o src/encoding.o
+DYN_MONGO_OBJECTS=src/bson.os src/encoding.os src/gridfs.os src/md5.os \
+ src/mongo.os src/numbers.os
+DYN_BSON_OBJECTS=src/bson.os src/numbers.os src/encoding.os
+
ifeq ($(ENV),posix)
TESTS+=test/env_posix_test
MONGO_OBJECTS+=src/env_posix.o
@@ -48,6 +52,7 @@ endif
ALL_DEFINES=$(DEFINES)
ALL_DEFINES+=-D_POSIX_SOURCE
CC:=$(shell sh -c 'type $(CC) >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
+DYN_FLAGS:=-fPIC -DMONGO_DLL_BUILD
# Endianness check
endian := $(shell sh -c 'echo "ab" | od -x | grep "6261" >/dev/null && echo little || echo big')
@@ -84,12 +89,12 @@ STLIBSUFFIX=a
MONGO_DYLIBNAME=$(MONGO_LIBNAME).$(DYLIBSUFFIX)
MONGO_DYLIB_MINOR_NAME=$(MONGO_LIBNAME).$(DYLIBSUFFIX).$(MONGO_MAJOR).$(MONGO_MINOR)
MONGO_DYLIB_MAJOR_NAME=$(MONGO_LIBNAME).$(DYLIBSUFFIX).$(MONGO_MAJOR)
-MONGO_DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(MONGO_DYLIB_MINOR_NAME) -o $(MONGO_DYLIBNAME) $(ALL_LDFLAGS)
+MONGO_DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(MONGO_DYLIB_MINOR_NAME) -o $(MONGO_DYLIBNAME) $(ALL_LDFLAGS) $(DYN_MONGO_OBJECTS)
BSON_DYLIBNAME=$(BSON_LIBNAME).$(DYLIBSUFFIX)
BSON_DYLIB_MINOR_NAME=$(BSON_LIBNAME).$(DYLIBSUFFIX).$(BSON_MAJOR).$(BSON_MINOR)
BSON_DYLIB_MAJOR_NAME=$(BSON_LIBNAME).$(DYLIBSUFFIX).$(BSON_MAJOR)
-BSON_DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(BSON_DYLIB_MINOR_NAME) -o $(BSON_DYLIBNAME) $(ALL_LDFLAGS)
+BSON_DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(BSON_DYLIB_MINOR_NAME) -o $(BSON_DYLIBNAME) $(ALL_LDFLAGS) $(DYN_BSON_OBJECTS)
# Static libraries
MONGO_STLIBNAME=$(MONGO_LIBNAME).$(STLIBSUFFIX)
@@ -136,13 +141,13 @@ md5.o: src/md5.c src/md5.h
mongo.o: src/mongo.c src/mongo.h src/bson.h src/md5.h src/env.h
numbers.o: src/numbers.c
-$(MONGO_DYLIBNAME): $(MONGO_OBJECTS)
+$(MONGO_DYLIBNAME): $(DYN_MONGO_OBJECTS)
$(MONGO_DYLIB_MAKE_CMD)
$(MONGO_STLIBNAME): $(MONGO_OBJECTS)
$(AR) -rs $@ $(MONGO_OBJECTS)
-$(BSON_DYLIBNAME): $(BSON_OBJECTS)
+$(BSON_DYLIBNAME): $(DYN_BSON_OBJECTS)
$(BSON_DYLIB_MAKE_CMD)
$(BSON_STLIBNAME): $(BSON_OBJECTS)
@@ -170,7 +175,7 @@ docs:
python docs/buildscripts/docs.py
clean:
- rm -rf $(MONGO_DYLIBNAME) $(MONGO_STLIBNAME) $(BSON_DYLIBNAME) $(BSON_STLIBNAME) src/*.o test/*_test
+ rm -rf $(MONGO_DYLIBNAME) $(MONGO_STLIBNAME) $(BSON_DYLIBNAME) $(BSON_STLIBNAME) src/*.o src/*.os test/*_test
deps:
$(CC) -MM -DMONGO_HAVE_STDINT src/*.c
@@ -184,4 +189,7 @@ deps:
%.o: %.c
$(CC) -o $@ -c $(ALL_CFLAGS) $<
-.PHONY: clean docs
+%.os: %.c
+ $(CC) -o $@ -c $(ALL_CFLAGS) $(DYN_FLAGS) $<
+
+.PHONY: clean docs test
55 SConstruct
View
@@ -1,6 +1,9 @@
# -*- mode: python; -*-
-VERSION = "0.5.2"
+MAJOR_VERSION = "0"
+MINOR_VERSION = "5"
+PATCH_VERSION = "2"
+VERSION = MAJOR_VERSION + "." + MINOR_VERSION + "." + PATCH_VERSION
# --- options ----
AddOption('--test-server',
@@ -168,15 +171,57 @@ if os.sys.platform == "linux2":
dynm = env.SharedLibrary( "mongoc" , mSharedObjs )
dynb = bsonEnv.SharedLibrary( "bson" , bSharedObjs )
+
+
# ---- Install ----
-prefix = "/usr/local"
+if os.sys.platform == "darwim":
+ shared_obj_suffix = "dylib"
+else:
+ shared_obj_suffix = "so"
+
+install_library_path = "/usr/local/lib"
+install_include_path = "/usr/local/include"
+def remove_without_exception(filename):
+ try:
+ os.remove(filename)
+ except:
+ print "Could not find " + filename + ". Skipping removal."
+
+mongoc_target = os.path.join(install_library_path, "libmongoc." + shared_obj_suffix + "." + MAJOR_VERSION + "." + MINOR_VERSION)
+mongoc_major_target = os.path.join(install_library_path, "libmongoc." + shared_obj_suffix + "." + MAJOR_VERSION)
+mongoc_base_target = os.path.join(install_library_path, "libmongoc." + shared_obj_suffix)
+
+bson_target = os.path.join(install_library_path, "libbson." + shared_obj_suffix + "." + MAJOR_VERSION + "." + MINOR_VERSION)
+bson_major_target = os.path.join(install_library_path, "libbson." + shared_obj_suffix + "." + MAJOR_VERSION)
+bson_base_target = os.path.join(install_library_path, "libbson." + shared_obj_suffix)
+
+def uninstall_shared_libraries(target=None, source=None, env=None):
+ remove_without_exception(mongoc_major_target)
+ remove_without_exception(mongoc_base_target)
+ remove_without_exception(mongoc_target)
+
+ remove_without_exception(bson_major_target)
+ remove_without_exception(bson_base_target)
+ remove_without_exception(bson_target)
+
+def install_shared_libraries(target=None, source=None, env=None):
+ import shutil
+ uninstall_shared_libraries()
+
+ shutil.copy("libmongoc." + shared_obj_suffix, mongoc_target)
+ os.symlink(mongoc_target, mongoc_base_target)
+ os.symlink(mongoc_target, mongoc_major_target)
+
+ shutil.copy("libbson." + shared_obj_suffix, bson_target)
+ os.symlink(bson_target, bson_base_target)
+ os.symlink(bson_target, bson_major_target)
-env.Alias("install", env.Install(os.path.join(prefix, "lib"), [dynm[0] , dynb[0] ]))
-env.Alias("install", env.Install(os.path.join(prefix, "include"), headers))
+env.Alias("install", [], install_shared_libraries)
-env.Command("uninstall", None, Delete(FindInstalledFiles()))
+env.Command("uninstall", [], uninstall_shared_libraries)
env.Default( env.Alias( "sharedlib" , [ dynm[0] , dynb[0] ] ) )
+env.AlwaysBuild("install")
# ---- Benchmarking ----
benchmarkEnv = env.Clone()
23 test/replica_set_test.c
View
@@ -11,6 +11,10 @@
#define SEED_START_PORT 30000
#endif
+#ifndef REPLICA_SET_NAME
+#define REPLICA_SET_NAME "replica-set-foo"
+#endif
+
int test_connect( const char *set_name ) {
mongo conn[1];
@@ -50,6 +54,7 @@ int test_reconnect( const char *set_name ) {
mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT );
mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT + 1 );
+
if( ( mongo_replset_connect( conn ) != MONGO_OK ) ) {
mongo_destroy( conn );
return res;
@@ -72,18 +77,24 @@ int test_reconnect( const char *set_name ) {
} while( 1 );
}
+
return 0;
}
int test_insert_limits( const char *set_name ) {
char version[10];
mongo conn[1];
+ mongo_write_concern wc[1];
int i;
char key[10];
int res = 0;
bson b[1], b2[1];
bson *objs[2];
+ mongo_write_concern_init( wc );
+ wc->w = 1;
+ mongo_write_concern_finish( wc );
+
/* We'll perform the full test if we're running v2.0 or later. */
if( mongo_get_server_version( version ) != -1 && version[0] <= '1' )
return 0;
@@ -109,10 +120,10 @@ int test_insert_limits( const char *set_name ) {
ASSERT( bson_size( b ) > conn->max_bson_size );
- ASSERT( mongo_insert( conn, "test.foo", b ) == MONGO_ERROR );
+ ASSERT( mongo_insert( conn, "test.foo", b, wc ) == MONGO_ERROR );
ASSERT( conn->err == MONGO_BSON_TOO_LARGE );
- mongo_clear_stored_errors( conn );
+ mongo_clear_errors( conn );
ASSERT( conn->err == 0 );
bson_init( b2 );
@@ -122,16 +133,18 @@ int test_insert_limits( const char *set_name ) {
objs[0] = b;
objs[1] = b2;
- ASSERT( mongo_insert_batch( conn, "test.foo", (const bson**)objs, 2, NULL ) == MONGO_ERROR );
+ ASSERT( mongo_insert_batch( conn, "test.foo", (const bson**)objs, 2, wc, 0 ) == MONGO_ERROR );
ASSERT( conn->err == MONGO_BSON_TOO_LARGE );
+ mongo_write_concern_destroy( wc );
+
return 0;
}
int main() {
- ASSERT( test_connect( "replica-set-foo" ) == MONGO_OK );
+ ASSERT( test_connect( REPLICA_SET_NAME ) == MONGO_OK );
ASSERT( test_connect( "test-foobar" ) == MONGO_CONN_BAD_SET_NAME );
- ASSERT( test_insert_limits( "replica-set-foo" ) == MONGO_OK );
+ ASSERT( test_insert_limits( REPLICA_SET_NAME ) == MONGO_OK );
/*
ASSERT( test_reconnect( "test-rs" ) == 0 );
Please sign in to comment.
Something went wrong with that request. Please try again.