Skip to content

Commit cbb7870

Browse files
attempt to fix setting of env in build-debug command for cover task + added option to enable debug logging of require script via OPENCV4NODES_DEBUG_REQUIRE env
1 parent 9479518 commit cbb7870

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

ci/envs/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const cv = require('opencv4nodejs')
1+
process.env.OPENCV4NODES_DEBUG_REQUIRE = true
22

3-
if (!cv) {
3+
if (!require('opencv4nodejs')) {
44
throw new Error('failed to require opencv4nodejs')
55
}

lib/cv.js

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,57 @@ const { resolvePath } = require('./commons');
44

55
const requirePath = path.join(__dirname, process.env.BINDINGS_DEBUG ? '../build/Debug/opencv4nodejs' : '../build/Release/opencv4nodejs')
66

7+
const logDebug = process.env.OPENCV4NODES_DEBUG_REQUIRE ? require('npmlog').info : () => {}
8+
79
function tryGetOpencvBinDir() {
8-
// if the auto build is disabled via environment do not even attempt
10+
if (process.env.OPENCV_BIN_DIR) {
11+
logDebug('tryGetOpencvBinDir', 'OPENCV_BIN_DIR environment variable is set')
12+
return process.env.OPENCV_BIN_DIR
13+
}
14+
// if the auto build is not disabled via environment do not even attempt
915
// to read package.json
10-
if (opencvBuild.isAutoBuildDisabled()) {
16+
if (!opencvBuild.isAutoBuildDisabled()) {
17+
logDebug('tryGetOpencvBinDir', 'auto build has not been disabled via environment variable, using opencv bin dir of opencv-build')
1118
return opencvBuild.opencvBinDir
1219
}
1320

21+
logDebug('tryGetOpencvBinDir', 'auto build has not been explicitly disabled via environment variable, attempting to read envs from package.json...')
1422
const envs = opencvBuild.readEnvsFromPackageJson()
15-
return envs.disableAutoBuild
16-
? (envs.opencvBinDir || process.env.OPENCV_BIN_DIR)
17-
: opencvBuild.opencvBinDir
23+
24+
if (!envs.disableAutoBuild) {
25+
logDebug('tryGetOpencvBinDir', 'auto build has not been disabled via package.json, using opencv bin dir of opencv-build')
26+
return opencvBuild.opencvBinDir
27+
}
28+
29+
if (envs.opencvBinDir) {
30+
logDebug('tryGetOpencvBinDir', 'found opencv binary environment variable in package.json')
31+
return envs.opencvBinDir
32+
}
33+
logDebug('tryGetOpencvBinDir', 'failed to find opencv binary environment variable in package.json')
34+
return null
1835
}
1936

2037
let cv = null
2138
try {
39+
logDebug('require', 'require path is ' + requirePath)
2240
cv = require(requirePath);
2341
} catch (err) {
42+
logDebug('require', 'failed to require cv with exception: ' + err.toString())
43+
logDebug('require', 'attempting to add opencv binaries to path')
44+
45+
if (!process.env.path) {
46+
logDebug('require', 'there is no path environment variable, skipping...')
47+
throw err
48+
}
2449

25-
// TODO: non windows?
2650
const opencvBinDir = tryGetOpencvBinDir()
51+
logDebug('require', 'adding opencv binary dir to path: ' + opencvBinDir)
2752

2853
// ensure binaries are added to path on windows
2954
if (!process.env.path.includes(opencvBinDir)) {
3055
process.env.path = `${process.env.path};${opencvBinDir};`
3156
}
57+
logDebug('require', 'process.env.path: ' + process.env.path)
3258
cv = require(requirePath);
3359
}
3460

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"build": "node-gyp configure build --jobs max",
3535
"rebuild": "node-gyp rebuild --jobs max",
3636
"clean": "node-gyp clean",
37-
"build-debug": "BINDINGS_DEBUG=true && node ./install/install.js"
37+
"build-debug": "BINDINGS_DEBUG=true node ./install/install.js"
3838
},
3939
"gypfile": true,
4040
"dependencies": {

0 commit comments

Comments
 (0)