Skip to content
This repository was archived by the owner on Jun 8, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ berlin-latest.osrm*
stxxl.errlog
stxxl.log
*.sublime-*
/lib/osrm.node
mason_packages
npm-debug.log
98 changes: 55 additions & 43 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,66 +1,78 @@
language: cpp

os:
- linux
- osx
git:
depth: 10

compiler:
- clang
- gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- gdb

# TODO: no core files on sudo:false machines until https://github.com/travis-ci/travis-ci/issues/3754 is resolved
sudo: false

matrix:
exclude:
include:
# Coverage
- os: osx
compiler: clang
env: NODE_VERSION="0.10" COVERAGE=true TARGET=Debug NPM_FLAGS="--debug"
# Linux
- os: linux
compiler: gcc
env: NODE_VERSION="0.12.0" TARGET=Release
- os: linux
compiler: gcc
env: NODE_VERSION="0.10.36" TARGET=Release
- os: linux
compiler: gcc
env: NODE_VERSION="0.10.36" TARGET=Debug NPM_FLAGS="--debug"
# OS X
- os: osx
compiler: clang
env: NODE_VERSION="0.12.0" TARGET=Release
- os: osx
compiler: clang
env: NODE_VERSION="0.10.36" TARGET=Release

env:
matrix:
- NVM_NODE_VERSION="0.10.36"
- NVM_NODE_VERSION="0.12.0"
global:
- JOBS: "3"
- OSRM_RELEASE: "v4.6.1"
- secure: KitzGZjoDblX/3heajcvssGz0JnJ/k02dr2tu03ksUV+6MogC3RSQudqyKY57+f8VyZrcllN/UOlJ0Q/3iG38Oz8DljC+7RZxtkVmE1SFBoOezKCdhcvWM12G3uqPs7hhrRxuUgIh0C//YXEkulUrqa2H1Aj2xeen4E3FAqEoy0=
- secure: WLGmxl6VTVWhXGm6X83GYNYzPNsvTD+9usJOKM5YBLAdG7cnOBQBNiCCUKc9OZMMZVUr3ec2/iigakH5Y8Yc+U6AlWKzlORyqWLuk4nFuoedu62x6ocQkTkuOc7mHiYhKd21xTGMYauaZRS6kugv4xkpGES2UjI2T8cjZ+LN2jU=

before_install:
# check if tag exists and matches package.json
- scripts/validate_tag.sh
# get commit message
- COMMIT_MESSAGE=$(git show -s --format=%B $TRAVIS_COMMIT | tr -d '\n')
# put node-pre-gyp on path
- export PATH=./node_modules/.bin/:$PATH
# here we set up the node version on the fly based on the matrix value.
# This is done manually so that it is easy to flip the 'language' to
# objective-c in another branch (to run the same travis.yml on OS X)
- rm -rf ~/.nvm/ && git clone --depth 1 https://github.com/creationix/nvm.git ~/.nvm
- source ~/.nvm/nvm.sh
- nvm install $NVM_NODE_VERSION
- nvm use $NVM_NODE_VERSION
- node --version
- npm --version
- which node
- "if [[ `uname -s` == 'Linux' ]]; then sudo add-apt-repository -y ppa:kalakris/cmake && sudo apt-get update -qq && sudo apt-get install cmake pkg-config; fi"
- if [[ `uname -s` == 'Darwin' ]]; then brew install pkg-config; fi
- export COVERAGE=${COVERAGE:-false}
- if [[ $(uname -s) == 'Linux' ]]; then
export CXX="g++-4.8";
export CC="gcc-4.8";
export PYTHONPATH=$(pwd)/mason_packages/.link/lib/python2.7/site-packages;
else
export PYTHONPATH=$(pwd)/mason_packages/.link/lib/python/site-packages;
fi;
- source ./scripts/install_node.sh ${NODE_VERSION}

install:
# set a few env settings for the static build script
- NODE_MODULE_ROOT=`pwd`
- export OSRM_RELEASE="v4.6.1"
# WARNING: this script modifies the environment
- source ./scripts/static_build.sh
- source ./bootstrap.sh
- if [[ ${COVERAGE} == true ]]; then
PYTHONUSERBASE=$(pwd)/mason_packages/.link pip install --user cpp-coveralls;
export LDFLAGS="--coverage";
export CXXFLAGS="--coverage";
fi;
- npm install --build-from-source ${NPM_FLAGS} --clang=1;

before_script:
- if [[ `uname -s` == 'Darwin' ]]; then otool -L ./lib/binding/* || true; fi
- if [[ `uname -s` == 'Linux' ]]; then readelf -d ./lib/binding/* || true; fi
- which osrm-extract||true;rm -rf ${TMP_DEPS_DIR};which osrm-extract||true;
- make test
- ulimit -c unlimited -S

script:
- node-pre-gyp package
- if [[ ${COMMIT_MESSAGE} =~ "[publish binary]" ]]; then
node-pre-gyp publish;
fi;
- if [[ ${COMMIT_MESSAGE} =~ "[republish binary]" ]]; then
node-pre-gyp unpublish publish;
fi;
- RESULT=0
- make test || RESULT=$?
- for i in $(find ./ -maxdepth 1 -name 'core*' -print); do gdb $(which node) $i -ex "thread apply all bt" -ex "set pagination 0" -batch; done;
- if [[ ${RESULT} != 0 ]]; then exit $RESULT; fi
- if [[ ${COVERAGE} == true ]]; then ./mason_packages/.link/bin/cpp-coveralls --exclude node_modules --exclude mason_packages --exclude tests --build-root build --gcov-options '\-lp' --exclude doc --exclude build/Release/obj/gen; fi;
- if [[ ${COVERAGE} != true ]]; then ./scripts/publish.sh; fi;
58 changes: 40 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,46 @@
all: osrm.node
#http://www.gnu.org/prep/standards/html_node/Standard-Targets.html#Standard-Targets

./node_modules:
npm install --build-from-source
all: build

osrm.node: ./node_modules
./node_modules/.bin/node-pre-gyp build --loglevel=silent
pkgconfig:
@if [[ `which pkg-config` ]]; then echo "Success: Found pkg-config"; else "echo you need pkg-config installed" && exit 1; fi;

debug:
./node_modules/.bin/node-pre-gyp rebuild --debug
./node_modules/node-pre-gyp:
npm install node-pre-gyp

verbose:
./node_modules/.bin/node-pre-gyp rebuild --loglevel=verbose
./node_modules: ./node_modules/node-pre-gyp
source ./bootstrap.sh && npm install `node -e "console.log(Object.keys(require('./package.json').dependencies).join(' '))"` \
`node -e "console.log(Object.keys(require('./package.json').devDependencies).join(' '))"` --clang=1

./build: pkgconfig ./node_modules
source ./bootstrap.sh && ./node_modules/.bin/node-pre-gyp configure build --loglevel=error --clang=1

debug: pkgconfig ./node_modules
export TARGET=Debug && source ./bootstrap.sh && ./node_modules/.bin/node-pre-gyp configure build --debug --clang=1

coverage: pkgconfig ./node_modules
source ./bootstrap.sh && ./node_modules/.bin/node-pre-gyp configure build --debug --clang=1 --coverage=true

verbose: pkgconfig ./node_modules
source ./bootstrap.sh && ./node_modules/.bin/node-pre-gyp configure build --loglevel=verbose --clang=1

clean:
@rm -rf ./build
rm -rf ./lib/binding/
rm -rf ./node_modules
rm -f *.osrm*
rm -rf ./node_modules/
rm -f ./*tgz
rm -f ./*.osrm*
rm -rf ./mason_packages
rm -rf ./osrm-backend-*

grind:
valgrind --leak-check=full node node_modules/.bin/_mocha

testpack:
rm -f ./*tgz
npm pack
tar -ztvf *tgz
rm -f ./*tgz

rebuild:
@make clean
Expand All @@ -26,15 +50,13 @@ berlin-latest.osm.pbf:
wget http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf

berlin-latest.osrm: berlin-latest.osm.pbf
PATH="./lib/binding:${PATH}" && osrm-extract berlin-latest.osm.pbf -p test/data/car.lua
./lib/binding/osrm-extract berlin-latest.osm.pbf -p test/data/car.lua

berlin-latest.osrm.hsgr: berlin-latest.osrm
PATH="./lib/binding:${PATH}" && osrm-prepare berlin-latest.osrm -p test/data/car.lua
./lib/binding/osrm-prepare berlin-latest.osrm -p test/data/car.lua && \
./lib/binding/osrm-datastore berlin-latest.osrm

test: berlin-latest.osrm.hsgr
PATH="./lib/binding:${PATH}" && osrm-datastore berlin-latest.osrm
npm test

check: test
./node_modules/.bin/mocha -R spec

.PHONY: test
.PHONY: test clean build
2 changes: 1 addition & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'conditions': [
[ 'OS=="linux"', {
'cflags_cc' : [
'-std=c++11', '-flto'
'-std=c++11'
],
'libraries':[
'-Wl,-rpath=<!@(pkg-config libosrm --variable=prefix)/lib',
Expand Down
140 changes: 140 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/bin/bash

function dep() {
./.mason/mason install $1 $2
./.mason/mason link $1 $2
}

CURRENT_DIR=$(pwd)

# default to clang
CXX=${CXX:-clang++}
TARGET=${TARGET:-Release}
OSRM_RELEASE=${OSRM_RELEASE:-"v4.6.0"}
OSRM_REPO=${OSRM_REPO:-"https://github.com/Project-OSRM/osrm-backend.git"}

function all_deps() {
dep cmake 3.2.2 &
dep lua 5.3.0 &
dep luabind dev &
dep boost 1.57.0 &
dep boost_libsystem 1.57.0 &
dep boost_libthread 1.57.0 &
dep boost_libfilesystem 1.57.0 &
dep boost_libprogram_options 1.57.0 &
dep boost_libregex 1.57.0 &
dep boost_libiostreams 1.57.0 &
dep boost_libtest 1.57.0 &
dep boost_libdate_time 1.57.0 &
dep expat 2.1.0 &
dep stxxl 1.4.1 &
dep osmpbf 1.3.3 &
dep protobuf 2.6.1 &
dep bzip 1.0.6 &
dep zlib system &
dep tbb 43_20150316 &
wait
}

function move_tool() {
cp ${MASON_HOME}/bin/$1 "${TARGET_DIR}/"
if [[ `uname -s` == 'Darwin' ]]; then
install_name_tool -change libtbb.dylib @loader_path/libtbb.dylib ${TARGET_DIR}/$1
install_name_tool -change libtbbmalloc.dylib @loader_path/libtbbmalloc.dylib ${TARGET_DIR}/$1
fi
}

function copy_tbb() {
if [[ `uname -s` == 'Darwin' ]]; then
cp ${MASON_HOME}/lib/libtbb.dylib ${TARGET_DIR}/
cp ${MASON_HOME}/lib/libtbbmalloc.dylib ${TARGET_DIR}/
else
cp ${MASON_HOME}/lib/libtbb.so.2 ${TARGET_DIR}/
cp ${MASON_HOME}/lib/libtbbmalloc.so.2 ${TARGET_DIR}/
cp ${MASON_HOME}/lib/libtbbmalloc_proxy.so.2 ${TARGET_DIR}/
fi
}

function localize() {
mkdir -p ${TARGET_DIR}
copy_tbb
cp ${MASON_HOME}/bin/lua ${TARGET_DIR}
move_tool osrm-extract
move_tool osrm-datastore
move_tool osrm-prepare
}

function main() {
if [[ ! -d ./.mason ]]; then
git clone --depth 1 https://github.com/mapbox/mason.git ./.mason
fi
export MASON_DIR=$(pwd)/.mason
export MASON_HOME=$(pwd)/mason_packages/.link
if [[ ! -d ${MASON_HOME} ]]; then
all_deps
fi
export PATH=${MASON_HOME}/bin:$PATH
export PKG_CONFIG_PATH=${MASON_HOME}/lib/pkgconfig

# environment variables to tell the compiler and linker
# to prefer mason paths over other paths when finding
# headers and libraries. This should allow the build to
# work even when conflicting versions of dependencies
# exist on global paths
# stopgap until c++17 :) (http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4214.pdf)
export C_INCLUDE_PATH="${MASON_HOME}/include"
export CPLUS_INCLUDE_PATH="${MASON_HOME}/include"
export LIBRARY_PATH="${MASON_HOME}/lib"

if [[ ! -d ./node_modules/node-pre-gyp ]]; then
npm install node-pre-gyp
fi

export TARGET_DIR=$(./node_modules/.bin/node-pre-gyp reveal module_path --silent)

LINK_FLAGS=""
if [[ $(uname -s) == 'Linux' ]]; then
LINK_FLAGS="${LINK_FLAGS} "'-Wl,-z,origin -Wl,-rpath=\$ORIGIN'
fi

if [[ ! -d osrm-backend-${TARGET}/build/osrm-extract ]] || [[ ! -f ${MASON_HOME}/bin/osrm-extract ]]; then
mkdir -p osrm-backend-${TARGET}
git clone ${OSRM_REPO} osrm-backend-${TARGET}
cd osrm-backend-${TARGET}

echo "Using OSRM ${OSRM_RELEASE}"
echo "Using OSRM ${OSRM_REPO}"
git checkout .
git checkout ${OSRM_RELEASE}

# workaround https://github.com/Project-OSRM/node-osrm/issues/92
perl -i -p -e "s/-fprofile-arcs -ftest-coverage//g;" CMakeLists.txt
perl -i -p -e "s/\${CMAKE_CXX_FLAGS} -flto/\${CMAKE_CXX_FLAGS}/g;" CMakeLists.txt

rm -rf build
mkdir -p build
cd build
cmake ../ -DCMAKE_INSTALL_PREFIX=${MASON_HOME} \
-DCMAKE_CXX_COMPILER="$CXX" \
-DBoost_NO_SYSTEM_PATHS=ON \
-DTBB_INSTALL_DIR=${MASON_HOME} \
-DCMAKE_INCLUDE_PATH=${MASON_HOME}/include \
-DCMAKE_LIBRARY_PATH=${MASON_HOME}/lib \
-DCMAKE_BUILD_TYPE=${TARGET} \
-DCMAKE_EXE_LINKER_FLAGS="${LINK_FLAGS}"
make -j${JOBS}
make install

fi

cd ${CURRENT_DIR}

localize

#if [[ `uname -s` == 'Darwin' ]]; then otool -L ./lib/binding/* || true; fi
#if [[ `uname -s` == 'Linux' ]]; then readelf -d ./lib/binding/* || true; fi
echo "success: now run 'npm install --build-from-source'"

}

main
6 changes: 5 additions & 1 deletion lib/osrm.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
var OSRM = module.exports = require('./binding/osrm.node').OSRM;
var binary = require('node-pre-gyp');
var exists = require('fs').existsSync || require('path').existsSync;
var path = require('path');
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));

var OSRM = module.exports = require(binding_path).OSRM;
OSRM.version = require('../package.json').version;
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
},
"binary": {
"module_name": "osrm",
"module_path": "./lib/binding/",
"host": "https://mapbox-node-binary.s3.amazonaws.com",
"remote_path" : "./{module_name}/"
"module_path" : "./lib/binding/",
"host" : "https://mapbox-node-binary.s3.amazonaws.com",
"remote_path" : "./{name}/v{version}/{configuration}/",
"package_name": "{node_abi}-{platform}-{arch}.tar.gz"
},
"dependencies": {
"node-pre-gyp": "~0.6.4",
"nan": "~1.6.2"
"nan": "~1.8.4",
"node-pre-gyp": "~0.6.7"
},
"bundledDependencies":["node-pre-gyp"],
"licenses": [
Expand Down
9 changes: 9 additions & 0 deletions scripts/install_node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# here we set up the node version on the fly based on the matrix value.
# This is done manually so that the build works the same on OS X
rm -rf ~/.nvm/ && git clone --depth 1 https://github.com/creationix/nvm.git ~/.nvm
source ~/.nvm/nvm.sh
nvm install $1
nvm use $1
node --version
npm --version
which node
Loading