Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

GH-45: Move to node-gyp, support SmartOS (and other Illumos-derived S…

…unOS variants)
  • Loading branch information...
commit 859cb048ce191a2de1c12fa947f323a4977e8fa8 1 parent 356293f
Mark Cavage authored
View
1  .gitignore
@@ -1,5 +1,4 @@
build
node_modules
npm-debug.log
-.lock-wscript
*.tgz
View
42 binding.gyp
@@ -0,0 +1,42 @@
+{
+ 'variables': {
+ 'platform': '<(OS)',
+ },
+ "targets":
+ [
+ {
+ "target_name": "zookeeper",
+ 'dependencies': ['libzk'],
+ "sources": [ "src/node-zk.cpp" ],
+ 'cflags': ['-Wall', '-Werror', '-O0'],
+ 'conditions': [
+ ['OS=="solaris"', {
+ 'cflags': ['-Wno-strict-aliasing'],
+ 'defines': ['_POSIX_PTHREAD_SEMANTICS'],
+ 'include_dirs': ['/opt/local/include/zookeeper'],
+ 'ldflags': ['-lzookeeper_st'],
+ }],['OS=="mac"',{
+ 'include_dirs': ['<(module_root_dir)/build/zk/include/zookeeper'],
+ 'libraries': ['<(module_root_dir)/build/zk/lib/libzookeeper_st.a'],
+ 'xcode_settings': {
+ 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
@fsvehla
fsvehla added a note

Typo here?

@kuebk Collaborator
kuebk added a note

What exactly do you mean?

@fsvehla
fsvehla added a note

I apologize, I misread that multiple times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 'MACOSX_DEPLOYMENT_TARGET': '10.5'
+ }
+ }],['OS=="linux"',{
+ 'include_dirs': ['<(module_root_dir)/build/zk/include/zookeeper'],
+ 'libraries': ['<(module_root_dir)/build/zk/lib/libzookeeper_st.a'],
+ }]
+ ]
+ },
+ {
+ 'target_name': 'libzk',
+ 'type': 'none',
+ 'actions': [{
+ 'action_name': 'build_zk_client_lib',
+ 'inputs': [''],
+ 'outputs': [''],
+ 'action': ['sh', 'libzk-build.sh']
+ }]
+ }
+ ],
+}
View
34 lib/zookeeper.js
@@ -3,15 +3,9 @@ var util = require('util');
var _ = require('underscore');
var path = require('path');
var async = require('async');
+var NativeZk = require(__dirname + '/../build/Release/zookeeper.node').ZooKeeper;
-try {
- // as of node 0.6.x, node-waf seems to build to a different directory. grr.
- var NativeZk = require(__dirname + '/../build/Release/zookeeper_native').ZooKeeper;
-} catch(e) {
- var NativeZk = require(__dirname + '/../build/default/zookeeper_native').ZooKeeper;
-}
-
-// with Node 0.5.x and greater, EventEmitter is pure-js, so we have to make a simple wrapper...
+// with Node 0.5.x and greater, EventEmitter is pure-js, so we make a simple wrapper...
// Partly inspired by https://github.com/bnoordhuis/node-event-emitter
////////////////////////////////////////////////////////////////////////////////
@@ -27,9 +21,10 @@ function ZooKeeper(config) {
self.config = config;
self._native = new NativeZk();
self._native.emit = function(ev, a1, a2, a3) {
- if(self.logger) self.logger("Emitting '" + ev + "' with args: " + a1 + ", " + a2 + ", " + a3);
+ if(self.logger)
+ self.logger("Emitting '" + ev + "' with args: " + a1 + ", " + a2 + ", " + a3);
if(ev === 'connect') {
- // the event is passing the native object. need to mangle this to return the wrapper instead
+ // the event is passing the native object. need to mangle to return the wrapper
a1 = self;
}
self.emit(ev, a1, a2, a3);
@@ -55,14 +50,15 @@ function ZooKeeper(config) {
proxyProperty('is_unrecoverable');
self.encoding = null; // Return 'Buffer' objects by default
-
+
self.setEncoding = function setEncoding(val) {
self.encoding = val;
};
// Backwards Compat for 'data_as_buffer' property. deprecated. just use setEncoding()
self.__defineGetter__('data_as_buffer', function(){
- // if there's an encoding, then data isn't a buffer. If there's no encoding, then data will be a buffer
+ // if there's an encoding, then data isn't a buffer. If there's no encoding,
+ // then data will be a buffer
return self.encoding ? false : true;
});
self.__defineSetter__('data_as_buffer', function(data_as_buffer){
@@ -182,9 +178,10 @@ ZooKeeper.prototype.init = function init(config) {
if(this.logger) this.logger("Encoding for data output: %s", self.encoding);
}
this._native.init.call(this._native, config);
-
- // The native code returns a ref to itself. So we should return a ref to the wrapper object
- return self;
+
+ // The native code returns a ref to itself.
+ // So we should return a ref to the wrapper object
+ return self;
}
ZooKeeper.prototype.connect = function connect(options, cb) {
@@ -194,13 +191,13 @@ ZooKeeper.prototype.connect = function connect(options, cb) {
options = null;
}
self.init(options);
-
+
function errorHandler(err) {
self.removeListener('error', errorHandler);
self.removeListener('connect', connectHandler);
cb(err);
}
-
+
function connectHandler() {
self.removeListener('error', errorHandler);
self.removeListener('connect', connectHandler);
@@ -209,7 +206,7 @@ ZooKeeper.prototype.connect = function connect(options, cb) {
self.on('error', errorHandler);
self.on('connect', connectHandler);
-
+
self.a_get('/',false,function(rc,error,stat,data){
if(rc != 0){
cb(error);
@@ -329,7 +326,6 @@ function create(con, p, cb) {
var flags = 0; // none
con.a_create(p, data, flags, function(rc, error, zkPath) {
// already exists, cool.
- // console.log('ZooKeeper.ZNODEEXISTS',ZooKeeper.ZNODEEXISTS);
if(rc == ZooKeeper.ZNODEEXISTS) {
return cb();
}
View
48 libzk-build.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+
+ROOT=`pwd`
+BUILD=$ROOT/build/zk
+BUILD_TMP=$BUILD/tmp
+PLATFORM=`uname`
+ZK=zookeeper-3.4.3
+ZK_FILE=/$BUILD_TMP/$ZK.tar.gz
+ZK_URL=http://apache.mirrors.tds.net/zookeeper/$ZK/$ZK.tar.gz
+
+if [ "$PLATFORM" != "SunOS" ]; then
+ mkdir -p $BUILD_TMP
+ if [ ! -e "$ZK_FILE" ] ; then
+ echo "Downloading $ZK from $ZK_URL"
+ curl --silent --output $ZK_FILE $ZK_URL
+ if [ $? != 0 ] ; then
+ echo "Unable to download zookeeper library"
+ exit 1
+ fi
+ fi
+
+ cd $BUILD_TMP
+
+ tar -zxf $ZK_FILE && \
+ cd $ZK/src/c && \
+ ./configure \
+ --without-syncapi \
+ --enable-static \
+ --disable-shared \
+ --with-pic \
+ --prefix=$BUILD && \
+ make && \
+ make install
+ if [ $? != 0 ] ; then
+ echo "Unable to build zookeeper library"
+ exit 1
+ fi
+ cd $ROOT
+else
+ if [ `uname -v` =~ "joyent_.*" ] ; then
+ pkgin list | grep zookeeper-client-3.4.3
+ if [ $? != 0] ; then
+ echo "You must install zookeeper before installing this module. Try:"
+ echo "pkgin install zookeeper-client-3.4.3"
+ exit 1
+ fi
+ fi
+fi
View
1  pack.sh
@@ -1 +0,0 @@
-npm pack --proprietary-attribs false | perl -pe 'print STDERR' | xargs gtar -tzf
View
16 package.json
@@ -1,33 +1,33 @@
{
- "name": "zookeeper"
+ "name": "zookeeper"
,"description": "apache zookeeper client (zookeeper async API >= 3.4.0)"
,"version": "3.4.1-2"
,"author": "Yuri Finkelstein <yurif2003@yahoo.com>"
,"contributors": [
"Yuri Finkelstein <yurif2003@yahoo.com>"
,"Woody Anderson <woody.anderson@gmail.com>"
+ ,"Mark Cavage <mcavage@gmail.com>"
,"Dave Dopson <ddopson@gmail.com>"
,"David Trejo <david.daniel.trejo@gmail.com>"
]
,"repository": {
"type": "git"
- ,"url": "https://github.com/yfinkelstein/node-zookeeper"
+ ,"url": "https://github.com/yfinkelstein/node-zookeeper"
}
,"keywords": ["apache", "zookeeper", "client"]
,"dependencies": {
- "webworker" : ">=0.8.2"
- ,"underscore" : "*"
- ,"async" : "~0.1.18"
+ "async": "~0.1.18"
+ ,"underscore": "*"
}
,"devDependencies": {
"log4js": "~0.4.3"
+ ,"webworker": ">=0.8.2"
}
,"main": "lib/index"
,"directories.lib": "build/default/"
,"scripts" : {
- "build" : "node-waf configure build"
+ "build" : "node-gyp configure build"
,"test" : "pushd test; ./test; popd"
- ,"doc" : "node-waf doc"
}
- ,"engines": { "node": "0.4.x || 0.6.x" }
+ ,"engines": { "node": ">=0.6" }
}
View
1  src/node-zk.cpp
@@ -1,4 +1,5 @@
#include <string.h>
+#include <strings.h>
#include <errno.h>
#include <assert.h>
#include <stdarg.h>
View
62 wscript
@@ -1,62 +0,0 @@
-import Options
-import platform
-
-srcdir = "."
-blddir = "build"
-APPNAME = "zookeeper"
-ZKVERSION = "3.4.3"
-OSTYPE = platform.system()
-
-
-def set_options(opt):
- opt.add_option('-z','--zookeeper', action='store', default='zookeeper-' + ZKVERSION, help='build zookeeper', dest='zookeeper')
- opt.tool_options("compiler_cxx")
-
-def configure(conf):
- conf.check_tool("compiler_cxx")
- conf.check_tool("node_addon")
-
-def zookeeper(ctx, z):
- t = ctx.bdir + '/zk'
- if z.find('/') == -1:
- tgz = z + '.tar.gz'
- r = ctx.exec_command("if [ ! -d '%s' -a ! -f '%s' ] ; then curl --silent --write-out '%%{http_code}' --output %s 'http://apache.mirrors.tds.net/zookeeper/%s/%s' | grep -v 404 ; fi" % (z,tgz,tgz,z,tgz))
- if r != 0:
- # probably building with an archive version, this is in a different directory
- print 'attempting to fetch from from archive location'
- ctx.exec_command("curl --output %s 'http://apache.mirrors.tds.net/hadoop/zookeeper/%s/%s'" % (tgz,z,tgz))
- ctx.exec_command("if [ ! -d '%s' ] ; then tar -xzvf %s ; fi" % (z,tgz))
-
- # We use "--without-shared" to force building/linking only the static libzookeeper.a library, else we would have unresolved runtime dependencies
- # We also use "--disable-shared" because on a newer version of the zk source (maybe 3.3.1 vs 3.3.0???), "--without-shared" is no longer recognized.
- # no idea why / wtf is going on here. but it works. and the other one gets silently ignored. keeping both in the code to cover all our bases
- # We use "--with-pic" to make position-independent code that can be statically linked into a shared object file (zookeeper.node)
- ctx.exec_command("mkdir -p zk ; cd %s/src/c && ./configure --without-syncapi --without-shared --disable-shared --with-pic --prefix=%s && make clean install"%(z,t))
-
-def build(bld):
- # for quicker development, run with "--zookeeper=" to skip rebuilding the zookeeper source (99% of build time)
- if Options.options.zookeeper != '':
- zookeeper(bld, Options.options.zookeeper)
-
- includes = [
- bld.bdir + '/zk/include/zookeeper', # zookeeper 3.4.x (local)
- bld.bdir + '/zk/include/c-client-src', # zookeeper 3.3.x (local)
- # '/usr/local/include/zookeeper', # zookeeper 3.4.x (system)
- # '/usr/local/include/c-client-src' # zookeeper 3.3.x (system)
- ]
- libpaths = [bld.bdir + '/zk/lib', '/usr/local/lib']
-
- obj = bld.new_task_gen("cxx", "shlib", "node_addon")
- if OSTYPE == 'Darwin':
- obj.cxxflags = ["-Wall", "-Werror", '-DDEBUG', '-O0', '-mmacosx-version-min=10.4']
- obj.ldflags = ['-mmacosx-version-min=10.4']
- else:
- # default build flags, add special cases if needed
- obj.cxxflags = ["-Wall", "-Werror", '-DDEBUG', '-O0']
- obj.ldflags = ['']
-
- obj.target = "zookeeper_native"
- obj.source = "src/node-zk.cpp"
- obj.lib = ["zookeeper_st"]
- obj.includes = includes
- obj.libpath = libpaths
@fsvehla

Typo here?

@kuebk
Collaborator

What exactly do you mean?

@fsvehla

I apologize, I misread that multiple times.

Please sign in to comment.
Something went wrong with that request. Please try again.