Node.js: added check for libunit version at compile time.

This commit is contained in:
Alexander Borisov
2018-12-19 15:56:57 +03:00
parent c55f329ecf
commit d6f38a3268
4 changed files with 26 additions and 8 deletions

View File

@@ -123,6 +123,7 @@ fi
NXT_NODE_TMP=${NXT_BUILD_DIR}/src/${NXT_NODE}/unit-http
NXT_NODE_TARBALL=${NXT_BUILD_DIR}/${NXT_NODE}-unit-http.tar.gz
NXT_NODE_VERSION_FILE=${NXT_NODE_TMP}/version.h
NXT_NODE_EXPORTS="export UNIT_SRC_PATH=${PWD}/src \
&& export UNIT_BUILD_PATH=${PWD}/${NXT_BUILD_DIR} \
&& export UNIT_LIB_STATIC_PATH=${PWD}/${NXT_BUILD_DIR}/libunit.a"
@@ -149,9 +150,15 @@ ${NXT_NODE}: ${NXT_NODE}-copy $NXT_BUILD_DIR/$NXT_LIB_UNIT_STATIC
${NXT_NODE_EXPORTS} && \\
cd ${NXT_NODE_TMP} && ${NXT_NODE_GYP} configure build clean
${NXT_NODE}-copy:
${NXT_NODE}-copy: ${NXT_NODE_VERSION_FILE}
mkdir -p ${NXT_BUILD_DIR}/src/
cp -rp src/nodejs/ ${NXT_BUILD_DIR}/src/${NXT_NODE}
cp -rp src/nodejs/* ${NXT_BUILD_DIR}/src/${NXT_NODE}
${NXT_NODE_VERSION_FILE}: src/nxt_main.h
mkdir -p ${NXT_NODE_TMP}
$echo -n '#define NXT_NODE_VERNUM ' > $NXT_NODE_VERSION_FILE
grep 'define NXT_VERNUM' src/nxt_main.h \\
| sed -e 's/[^0-9]//g' >> $NXT_NODE_VERSION_FILE
${NXT_NODE_TARBALL}: ${NXT_NODE}-copy
tar -zcvf ${NXT_NODE_TARBALL} -C ${NXT_NODE_TMP} .

View File

@@ -3,7 +3,11 @@
DEFAULT_VERSION := $(shell grep 'define NXT_VERSION' ../../src/nxt_main.h \
| sed -e 's/^.*"\(.*\)".*/\1/')
DEFAULT_VERNUM := $(shell grep 'define NXT_VERNUM' ../../src/nxt_main.h \
| sed -e 's/[^0-9]//g')
VERSION ?= $(DEFAULT_VERSION)
VERNUM ?= $(DEFAULT_VERNUM)
NPM ?= npm
default:
@@ -11,6 +15,7 @@ default:
copy:
cp -rp ../../src/nodejs/unit-http .
echo '#define NXT_NODE_VERNUM ${VERNUM}' > unit-http/version.h
mv unit-http/binding_pub.gyp unit-http/binding.gyp
sed -e 's/"version"\s*:.*/"version": "${VERSION}.0",/' \
unit-http/package.json > unit-http/package.json.tmp

View File

@@ -4,14 +4,15 @@
"description": "HTTP module for NGINX Unit",
"main": "http.js",
"files": [
"unit.h",
"version.h",
"addon.cpp",
"binding.gyp",
"http_server.js",
"unit.cpp",
"http.js",
"http_server.js",
"package.json",
"socket.js",
"unit.cpp",
"unit.h",
"binding.gyp",
"README.md"
],
"scripts": {

View File

@@ -6,18 +6,23 @@
#ifndef _NXT_NODEJS_UNIT_H_INCLUDED_
#define _NXT_NODEJS_UNIT_H_INCLUDED_
#include <node_api.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "version.h"
#include <nxt_unit.h>
#if NXT_UNIT_VERNUM != NXT_NODE_VERNUM
#error "libunit version mismatch."
#endif
#include <nxt_unit_response.h>
#include <nxt_unit_request.h>
#ifdef __cplusplus
} /* extern "C" */
#endif