Skip to content

Commit be173c4

Browse files
committed
downloading ZK sources on prepublish
1 parent bd7baa3 commit be173c4

10 files changed

+184
-114
lines changed

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.tgz
22
.npmignore
33
.gitignore
4+
deps/zookeeper*

binding.gyp

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
'action_name': 'build_zk_client_lib',
3636
'inputs': [''],
3737
'outputs': [''],
38-
'action': ['sh', 'libzk-build.sh']
38+
'action': ['sh', 'scripts/build.sh']
3939
}]
4040
},
4141
{
@@ -46,7 +46,7 @@
4646
"action_name": "symlink",
4747
"inputs": ["<@(PRODUCT_DIR)/zookeeper.node"],
4848
"outputs": ["<(module_root_dir)/build/zookeeper.node"],
49-
"action": ["sh", "libzk-symlink.sh", "<@(_inputs)"]
49+
"action": ["sh", "scripts/symlink.sh", "<@(_inputs)"]
5050
}]
5151
}
5252
],

deps/placeholder

Whitespace-only changes.

libzk-build.sh

-112
This file was deleted.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
,"scripts" : {
3232
"build" : "node-gyp configure build"
3333
,"test" : "pushd test; ./test; popd"
34+
,"prepublish" : "./scripts/prepublish.sh"
3435
}
3536
,"engines": { "node": ">=0.8" }
3637
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
diff --git src/c/include/recordio.h src/c/include/recordio.h
2+
index 4e1b78e..90f458b 100644
3+
--- src/c/include/recordio.h
4+
+++ src/c/include/recordio.h
5+
@@ -73,7 +73,7 @@ void close_buffer_iarchive(struct iarchive **ia);
6+
char *get_buffer(struct oarchive *);
7+
int get_buffer_len(struct oarchive *);
8+
9+
-int64_t htonll(int64_t v);
10+
+int64_t zoo_htonll(int64_t v);
11+
12+
#ifdef __cplusplus
13+
}
14+
diff --git src/c/src/recordio.c src/c/src/recordio.c
15+
index cf8a1ac..41797fb 100644
16+
--- src/c/src/recordio.c
17+
+++ src/c/src/recordio.c
18+
@@ -80,7 +80,7 @@ int oa_serialize_int(struct oarchive *oa, const char *tag, const int32_t *d)
19+
priv->off+=sizeof(i);
20+
return 0;
21+
}
22+
-int64_t htonll(int64_t v)
23+
+int64_t zoo_htonll(int64_t v)
24+
{
25+
int i = 0;
26+
char *s = (char *)&v;
27+
@@ -98,7 +98,7 @@ int64_t htonll(int64_t v)
28+
29+
int oa_serialize_long(struct oarchive *oa, const char *tag, const int64_t *d)
30+
{
31+
- const int64_t i = htonll(*d);
32+
+ const int64_t i = zoo_htonll(*d);
33+
struct buff_struct *priv = oa->priv;
34+
if ((priv->len - priv->off) < sizeof(i)) {
35+
int rc = resize_buffer(priv, priv->len + sizeof(i));
36+
@@ -207,7 +207,7 @@ int ia_deserialize_long(struct iarchive *ia, const char *tag, int64_t *count)
37+
}
38+
memcpy(count, priv->buffer+priv->off, sizeof(*count));
39+
priv->off+=sizeof(*count);
40+
- v = htonll(*count); // htonll and ntohll do the same
41+
+ v = zoo_htonll(*count); // htonll and ntohll do the same
42+
*count = v;
43+
return 0;
44+
}
45+
diff --git src/c/src/zookeeper.c src/c/src/zookeeper.c
46+
index 27ecf8a..ba55d27 100644
47+
--- src/c/src/zookeeper.c
48+
+++ src/c/src/zookeeper.c
49+
@@ -1408,7 +1408,7 @@ static int serialize_prime_connect(struct connect_req *req, char* buffer){
50+
memcpy(buffer + offset, &req->protocolVersion, sizeof(req->protocolVersion));
51+
offset = offset + sizeof(req->protocolVersion);
52+
53+
- req->lastZxidSeen = htonll(req->lastZxidSeen);
54+
+ req->lastZxidSeen = zoo_htonll(req->lastZxidSeen);
55+
memcpy(buffer + offset, &req->lastZxidSeen, sizeof(req->lastZxidSeen));
56+
offset = offset + sizeof(req->lastZxidSeen);
57+
58+
@@ -1416,7 +1416,7 @@ static int serialize_prime_connect(struct connect_req *req, char* buffer){
59+
memcpy(buffer + offset, &req->timeOut, sizeof(req->timeOut));
60+
offset = offset + sizeof(req->timeOut);
61+
62+
- req->sessionId = htonll(req->sessionId);
63+
+ req->sessionId = zoo_htonll(req->sessionId);
64+
memcpy(buffer + offset, &req->sessionId, sizeof(req->sessionId));
65+
offset = offset + sizeof(req->sessionId);
66+
67+
@@ -1447,7 +1447,7 @@ static int serialize_prime_connect(struct connect_req *req, char* buffer){
68+
memcpy(&req->sessionId, buffer + offset, sizeof(req->sessionId));
69+
offset = offset + sizeof(req->sessionId);
70+
71+
- req->sessionId = htonll(req->sessionId);
72+
+ req->sessionId = zoo_htonll(req->sessionId);
73+
memcpy(&req->passwd_len, buffer + offset, sizeof(req->passwd_len));
74+
offset = offset + sizeof(req->passwd_len);
75+
76+
diff --git src/c/tests/ZKMocks.cc src/c/tests/ZKMocks.cc
77+
index 8916674..69bea16 100644
78+
--- src/c/tests/ZKMocks.cc
79+
+++ src/c/tests/ZKMocks.cc
80+
@@ -41,7 +41,7 @@ HandshakeRequest* HandshakeRequest::parse(const std::string& buf){
81+
int offset=sizeof(req->protocolVersion);
82+
83+
memcpy(&req->lastZxidSeen,buf.data()+offset,sizeof(req->lastZxidSeen));
84+
- req->lastZxidSeen = htonll(req->lastZxidSeen);
85+
+ req->lastZxidSeen = zoo_htonll(req->lastZxidSeen);
86+
offset+=sizeof(req->lastZxidSeen);
87+
88+
memcpy(&req->timeOut,buf.data()+offset,sizeof(req->timeOut));
89+
@@ -49,7 +49,7 @@ HandshakeRequest* HandshakeRequest::parse(const std::string& buf){
90+
offset+=sizeof(req->timeOut);
91+
92+
memcpy(&req->sessionId,buf.data()+offset,sizeof(req->sessionId));
93+
- req->sessionId = htonll(req->sessionId);
94+
+ req->sessionId = zoo_htonll(req->sessionId);
95+
offset+=sizeof(req->sessionId);
96+
97+
memcpy(&req->passwd_len,buf.data()+offset,sizeof(req->passwd_len));
98+
@@ -322,7 +322,7 @@ string HandshakeResponse::toString() const {
99+
buf.append((char*)&tmp,sizeof(tmp));
100+
tmp=htonl(timeOut);
101+
buf.append((char*)&tmp,sizeof(tmp));
102+
- int64_t tmp64=htonll(sessionId);
103+
+ int64_t tmp64=zoo_htonll(sessionId);
104+
buf.append((char*)&tmp64,sizeof(sessionId));
105+
tmp=htonl(passwd_len);
106+
buf.append((char*)&tmp,sizeof(tmp));

scripts/build.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
. ./scripts/env.sh
4+
5+
if [ "$PLATFORM" != "SunOS" ]; then
6+
if [ -e "$BUILD/lib/libzookeeper_st.la" ]; then
7+
echo "ZooKeeper has already been built"
8+
exit 0
9+
fi
10+
11+
cd $ZK_DEPS/src/c && \
12+
./configure \
13+
--without-syncapi \
14+
--enable-static \
15+
--disable-shared \
16+
--with-pic \
17+
--libdir=$BUILD/lib \
18+
--prefix=$BUILD && \
19+
make && \
20+
make install
21+
if [ $? != 0 ] ; then
22+
echo "Unable to build zookeeper library"
23+
exit 1
24+
fi
25+
cd $ROOT
26+
else
27+
if [ `uname -v` =~ "joyent_.*" ] ; then
28+
pkgin list | grep zookeeper-client-$ZK_VERSION
29+
if [ $? != 0] ; then
30+
echo "You must install zookeeper before installing this module. Try:"
31+
echo "pkgin install zookeeper-client-$ZK_VERSION"
32+
exit 1
33+
fi
34+
fi
35+
fi

scripts/env.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
ROOT=`pwd`
4+
DEPS=$ROOT/deps
5+
BUILD=$ROOT/build/zk
6+
ZK_VERSION=3.4.6
7+
ZK=zookeeper-$ZK_VERSION
8+
ZK_DEPS=$DEPS/$ZK
9+
ZK_FILE=/tmp/$ZK.tar.gz
10+
ZK_URL=http://apache.mirrors.tds.net/zookeeper/$ZK/$ZK.tar.gz
11+
PATCHES=$(ls $ROOT/patches/*.patch)

scripts/prepublish.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
. ./scripts/env.sh
4+
5+
cd $DEPS
6+
7+
echo "Downloading $ZK from $ZK_URL"
8+
9+
curl --output $ZK_FILE $ZK_URL || wget $ZK_URL -O $ZK_FILE
10+
11+
if [ $? != 0 ] ; then
12+
echo "Unable to download zookeeper library"
13+
exit 1
14+
fi
15+
16+
tar zxf $ZK_FILE $ZK/src/c
17+
18+
cd $ZK_DEPS
19+
20+
echo "Applying patches"
21+
for PATCH in $PATCHES; do
22+
echo "Patching: $PATCH"
23+
patch -p0 < $PATCH
24+
if [ $? != 0 ] ; then
25+
echo "Unable to patch the ZooKeeper source"
26+
exit 1
27+
fi
28+
done
File renamed without changes.

0 commit comments

Comments
 (0)