Skip to content

Commit 6fbefbb

Browse files
author
Halton Huo
committed
[nodejs] Enable nodejs build for Travis
Changes: - Add linter support - Fix node-gyp issue with multiple python2 - Fix a typo of "make -j" and run as normal user - Adjust steps and do better format - Stop on failures on script step
1 parent e1cbaed commit 6fbefbb

File tree

8 files changed

+1407
-35
lines changed

8 files changed

+1407
-35
lines changed

.travis.yml

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,60 @@ sudo: required
77
dist: xenial
88

99
before_install:
10+
# Install nodejs via nvm
11+
- wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
12+
- source ~/.bashrc
13+
- nvm install 6 && nvm use 6
14+
- npm install -g node-gyp
15+
16+
# Remove duplicated python 2.x, otherwise node-gyp will complain and stop
17+
- pyenv uninstall -f 2.7.13
18+
19+
# Run linter
20+
- git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
21+
- export OLDPATH=$PATH && export PATH=$PATH:$(pwd)/depot_tools;
22+
- cd wrappers/nodejs/tools && npm install && cd ..
23+
- node ./tools/linter.js
24+
- export PATH=$OLDPATH && unset OLDPATH && cd ../../
25+
26+
# Get logical CPU number
27+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
28+
export CPU_NUM=`grep -c ^processor /proc/cpuinfo`;
29+
elif [ "$TRAVIS_OS_NAME" == "osx" ]; then
30+
export CPU_NUM=`sysctl -n hw.logicalcpu_max`;
31+
fi
32+
33+
# Install linux required packages
1034
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
1135
sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test;
12-
wget https://github.com/glfw/glfw/releases/download/3.1.1/glfw-3.1.1.zip;
13-
sudo apt-get update;
14-
sudo apt-get-repository ppa:ubuntu-toolchain-r/test;
1536
sudo apt-get update;
37+
sudo apt-get install -qq build-essential xorg-dev libglu1-mesa-dev libglew-dev libglm-dev;
38+
sudo apt-get install -qq libusb-1.0-0-dev;
39+
sudo apt-get install -qq libgtk-3-dev;
40+
sudo apt-get install -qq python python-dev;
1641
sudo apt-get install gcc-5 g++-5;
1742
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5;
1843
fi
1944

2045
install:
21-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
22-
sudo apt-get install -qq build-essential xorg-dev libglu1-mesa-dev libglew-dev libglm-dev;
23-
sudo apt-get install -qq cmake;
24-
sudo apt-get install -qq libusb-1.0-0-dev ;
25-
sudo apt-get install -qq libgtk-3-dev ;
26-
sudo apt-get install python python-dev ;
27-
pyenv local 3.6.1;
28-
29-
cmake --version;
30-
31-
unzip glfw-3.1.1.zip;
32-
cd glfw-3.1.1;
33-
sudo cmake -G "Unix Makefiles" -DBUILD_SHARED_LIBS=ON;
34-
sudo make;
35-
sudo make install;
36-
cd ..;
37-
fi
46+
# Install nodejs via nvm
47+
- wget https://github.com/glfw/glfw/releases/download/3.1.1/glfw-3.1.1.zip
48+
- unzip glfw-3.1.1.zip && cd glfw-3.1.1
49+
- cmake -G "Unix Makefiles" -DBUILD_SHARED_LIBS=ON
50+
- make -j $CPU_NUM
51+
- sudo make install && cd ..
52+
3853
script:
39-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
40-
uname -a;
41-
mkdir build;
42-
cd build;
43-
cmake .. -DBUILD_EXAMPLES:BOOL=true -DBUILD_PYTHON_BINDINGS:BOOL=true;
44-
make -J;
45-
sudo make install;
46-
export LRS_LOG_LEVEL="DEBUG";
47-
wget http://realsense-hw-public.s3.amazonaws.com/rs-tests/awgc4;
48-
./unit-tests/live-test from awgc4 -d yes;
49-
fi
54+
# Exit immediately if a command exits with a non-zero status
55+
- set -e
56+
# Build librealsense
57+
- pyenv local 3.6.1
58+
- mkdir build && cd build
59+
- cmake .. -DBUILD_EXAMPLES:BOOL=true -DBUILD_PYTHON_BINDINGS:BOOL=true -DBUILD_NODEJS_BINDINGS:BOOL=true
60+
- make -j $CPU_NUM
61+
- sudo "PATH=$PATH" make install
62+
63+
# Run test
64+
- export LRS_LOG_LEVEL="DEBUG"
65+
- wget http://realsense-hw-public.s3.amazonaws.com/rs-tests/awgc4
66+
- ./unit-tests/live-test from awgc4 -d yes

wrappers/nodejs/.eslintrc.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"extends": "google",
3+
"parserOptions": {
4+
"ecmaVersion": 6
5+
},
6+
"plugins": [
7+
"header"
8+
],
9+
"rules": {
10+
"header/header": [2, "tools/header.js"],
11+
"max-len": ["error",
12+
// Following Google Javascript 100 char line limit
13+
100,
14+
// Use 2-space as tab width
15+
2,
16+
{ "ignoreUrls": true }
17+
],
18+
// Prefer to use single quotes
19+
"quotes": ["error", "single"],
20+
// Disable JSDoc
21+
"require-jsdoc": ["error", {
22+
"require": {
23+
"FunctionDeclaration": false,
24+
"MethodDefinition": false,
25+
"ClassDeclaration": false
26+
}
27+
}]
28+
}
29+
}

wrappers/nodejs/.gitignore

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
# Ignore files
2+
build
13
doc/*
2-
!doc/jsdoc-template
34
node_modules/
4-
!package-lock.json
5-
!package.json
6-
build
75
*.png
86
*.csv
7+
8+
# Uningore files
9+
!.eslintrc.json
10+
!doc/jsdoc-template
11+
!package-lock.json
12+
!package.json

wrappers/nodejs/.jshintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"esversion": 6,
3+
"node": true
4+
}

wrappers/nodejs/tools/header.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Copyright (c) 2017 Intel Corporation. All rights reserved.
2+
// Use of this source code is governed by an Apache 2.0 license
3+
// that can be found in the LICENSE file.

wrappers/nodejs/tools/linter.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env node
2+
3+
// Copyright (c) 2017 Intel Corporation. All rights reserved.
4+
// Use of this source code is governed by an Apache 2.0 license
5+
// that can be found in the LICENSE file.
6+
7+
'use strict';
8+
9+
const os = require('os');
10+
const path = require('path');
11+
const recursive = require('recursive-readdir');
12+
const spawn = require('child_process').spawnSync;
13+
const which = require('which');
14+
15+
let errors = [];
16+
17+
function doCppLint(files) {
18+
if (!files) return;
19+
20+
let cpplint = which.sync('cpplint.py');
21+
if (!cpplint) {
22+
console.log('You need install depot_tools, and add to PATH.' +
23+
' https://dev.chromium.org/developers/how-tos/install-depot-tools');
24+
process.exit(1);
25+
}
26+
27+
let cmdOptions = [cpplint];
28+
cmdOptions = cmdOptions.concat(files);
29+
// cpplint report result in stderr, $? is always 0 whatever there are errors or not.
30+
// So we need check the last line as "Total errors found: 0"
31+
let output = spawn('python', cmdOptions).stderr.toString().split(os.EOL);
32+
if (output[output.length - 2] != 'Total errors found: 0') {
33+
errors = errors.concat(output);
34+
}
35+
}
36+
37+
function doJsLint(files) {
38+
if (!files) return;
39+
40+
let jsLinterDir = path.join(__dirname, 'node_modules', '.bin');
41+
42+
for (let linter of ['eslint', 'jshint']) {
43+
let cmdOptions = [path.join(jsLinterDir, linter)];
44+
cmdOptions = cmdOptions.concat(files);
45+
let output = spawn('node', cmdOptions).stdout.toString();
46+
if (output) {
47+
let lines = output.split(os.EOL);
48+
if (lines.length > 0) errors = errors.concat(lines);
49+
}
50+
}
51+
}
52+
53+
recursive(path.dirname(__dirname),
54+
// ignore files
55+
['node_modules', 'prettify'],
56+
function(err, files) {
57+
let cppFiles = [];
58+
let jsFiles = [];
59+
for (let f of files) {
60+
if (path.extname(f) == '.js') {
61+
jsFiles.push(f);
62+
} else if (path.extname(f) == '.cpp') {
63+
cppFiles.push(f);
64+
}
65+
}
66+
67+
doCppLint(cppFiles);
68+
doJsLint(jsFiles);
69+
70+
if (errors.length > 1) {
71+
for (let l of errors) console.log(l);
72+
process.exit(1);
73+
}
74+
});

0 commit comments

Comments
 (0)