-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #632 from justadudewhohacks/improve_install_script
Improve install script + configure environments via package.json
- Loading branch information
Showing
19 changed files
with
255 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ ci/coverage-report | |
!package.json | ||
!binding.gyp | ||
!lib | ||
!install | ||
!test | ||
!cc | ||
!data/got.jpg | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/sh | ||
image=opencv4nodejs-ci:$1-node$2-with-coverage | ||
docker build -t $image -f ./Dockerfile --build-arg TAG=$1 --build-arg NODE_MAJOR_VERSION=$2 ../../ | ||
docker run -v $PWD/coverage-report:/test/coverage-report $image | ||
docker run -v $PWD/coverage-report:/test/coverage-report -e OPENCV_VERSION=$OPENCV_VERSION -e TEST_MODULE_LIST=$TEST_MODULE_LIST $image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"scripts": { | ||
"test": "node ./test.js" | ||
}, | ||
"dependencies": { | ||
"opencv4nodejs": "../../" | ||
}, | ||
"opencv4nodejs": { | ||
"disableAutoBuild": 1, | ||
"opencvIncludeDir": "C:\\tools\\opencv\\build\\include", | ||
"opencvLibDir": "C:\\tools\\opencv\\build\\x64\\vc14\\lib", | ||
"opencvBinDir": "C:\\tools\\opencv\\build\\x64\\vc14\\bin" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
process.env.OPENCV4NODES_DEBUG_REQUIRE = true | ||
|
||
if (!require('opencv4nodejs')) { | ||
throw new Error('failed to require opencv4nodejs') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/sh | ||
image=opencv4nodejs-ci:$1-node$2 | ||
docker build -t $image -f ./Dockerfile --build-arg TAG=$1 --build-arg NODE_MAJOR_VERSION=$2 ../../ | ||
docker run -e TEST_MODULE_LIST=$TEST_MODULE_LIST $image | ||
docker run -e OPENCV_VERSION=$OPENCV_VERSION -e TEST_MODULE_LIST=$TEST_MODULE_LIST $image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
const opencvBuild = require('opencv-build') | ||
const child_process = require('child_process') | ||
const fs = require('fs') | ||
const log = require('npmlog') | ||
const { resolvePath } = require('../lib/commons') | ||
|
||
const defaultDir = '/usr/local' | ||
const defaultLibDir = `${defaultDir}/lib` | ||
const defaultIncludeDir = `${defaultDir}/include` | ||
const defaultIncludeDirOpenCV4 = `${defaultIncludeDir}/opencv4` | ||
|
||
function getDefaultIncludeDirs() { | ||
log.info('install', 'OPENCV_INCLUDE_DIR is not set, looking for default include dir') | ||
if (opencvBuild.isWin()) { | ||
throw new Error('OPENCV_INCLUDE_DIR has to be defined on windows when auto build is disabled') | ||
} | ||
return [defaultIncludeDir, defaultIncludeDirOpenCV4] | ||
} | ||
|
||
function getDefaultLibDir() { | ||
log.info('install', 'OPENCV_LIB_DIR is not set, looking for default lib dir') | ||
if (opencvBuild.isWin()) { | ||
throw new Error('OPENCV_LIB_DIR has to be defined on windows when auto build is disabled') | ||
} | ||
return defaultLibDir | ||
} | ||
|
||
opencvBuild.applyEnvsFromPackageJson() | ||
|
||
const libDir = opencvBuild.isAutoBuildDisabled() | ||
? (resolvePath(process.env.OPENCV_LIB_DIR) || getDefaultLibDir()) | ||
: resolvePath(opencvBuild.opencvLibDir) | ||
|
||
log.info('install', 'using lib dir: ' + libDir) | ||
|
||
if (!fs.existsSync(libDir)) { | ||
throw new Error('library dir does not exist: ' + libDir) | ||
} | ||
|
||
const libsFoundInDir = opencvBuild | ||
.getLibs(libDir) | ||
.filter(lib => lib.libPath) | ||
|
||
if (!libsFoundInDir.length) { | ||
throw new Error('no OpenCV libraries found in lib dir: ' + libDir) | ||
} | ||
|
||
log.info('install', 'found the following libs:') | ||
libsFoundInDir.forEach(lib => log.info('install', lib.opencvModule + ' : ' + lib.libPath)) | ||
|
||
const defines = libsFoundInDir | ||
.map(lib => `OPENCV4NODEJS_FOUND_LIBRARY_${lib.opencvModule.toUpperCase()}`) | ||
|
||
const explicitIncludeDir = resolvePath(process.env.OPENCV_INCLUDE_DIR) | ||
const includes = opencvBuild.isAutoBuildDisabled() | ||
? (explicitIncludeDir ? [explicitIncludeDir] : getDefaultIncludeDirs()) | ||
: [resolvePath(opencvBuild.opencvInclude), resolvePath(opencvBuild.opencv4Include)] | ||
|
||
const libs = opencvBuild.isWin() | ||
? libsFoundInDir.map(lib => resolvePath(lib.libPath)) | ||
// dynamically link libs if not on windows | ||
: ['-L' + libDir] | ||
.concat(libsFoundInDir.map(lib => '-lopencv_' + lib.opencvModule)) | ||
.concat('-Wl,-rpath,' + libDir) | ||
|
||
console.log() | ||
log.info('install', 'setting the following defines:') | ||
defines.forEach(def => log.info('defines', def)) | ||
console.log() | ||
log.info('install', 'setting the following includes:') | ||
includes.forEach(inc => log.info('includes', inc)) | ||
console.log() | ||
log.info('install', 'setting the following libs:') | ||
libs.forEach(lib => log.info('libs', lib)) | ||
|
||
process.env['OPENCV4NODEJS_DEFINES'] = defines.join('\n') | ||
process.env['OPENCV4NODEJS_INCLUDES'] = includes.join('\n') | ||
process.env['OPENCV4NODEJS_LIBRARIES'] = libs.join('\n') | ||
|
||
const flags = process.env.BINDINGS_DEBUG ? '--jobs max --debug' : '--jobs max' | ||
const nodegypCmd = 'node-gyp rebuild ' + flags | ||
log.info('install', `spawning node gyp process: ${nodegypCmd}`) | ||
const child = child_process.exec(nodegypCmd, {}, function(err, stdout, stderr) { | ||
const _err = err || stderr | ||
if (_err) log.error(_err) | ||
}) | ||
child.stdout.pipe(process.stdout) | ||
child.stderr.pipe(process.stderr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const envName = process.argv[2] | ||
|
||
if (!envName) { | ||
throw new Error('no env name passed to parseEnv') | ||
} | ||
const outputs = (process.env[envName] || '').split('\n') | ||
outputs.forEach(o => console.log(o)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,13 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
function resolvePath(filePath, file) { | ||
if (!filePath) { | ||
return undefined; | ||
return undefined | ||
} | ||
return (file ? path.resolve(filePath, file) : path.resolve(filePath)).replace(/\\/g, '/'); | ||
} | ||
|
||
const defaultDir = '/usr/local'; | ||
const defaultIncludeDir = `${defaultDir}/include`; | ||
const defaultIncludeDirOpenCV4 = `${defaultIncludeDir}/opencv4`; | ||
|
||
function getLibDir() { | ||
const libPath = resolvePath(process.env.OPENCV_LIB_DIR) | ||
if (process.platform === 'win32' && !libPath) { | ||
throw new Error('OPENCV_LIB_DIR is not defined') | ||
} | ||
return libPath || `${defaultDir}/lib`; | ||
return (file ? path.resolve(filePath, file) : path.resolve(filePath)).replace(/\\/g, '/') | ||
} | ||
|
||
module.exports = { | ||
resolvePath, | ||
defaultDir, | ||
defaultIncludeDir, | ||
defaultIncludeDirOpenCV4, | ||
getLibDir | ||
}; | ||
resolvePath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.