@@ -2,6 +2,7 @@ var path = require('path');
2
2
var fs = require ( 'fs' ) ;
3
3
var assert = require ( 'assert' ) ;
4
4
var os = require ( 'os' ) ;
5
+ var child_process = require ( 'child_process' ) ;
5
6
6
7
exports . testDir = path . dirname ( __filename ) ;
7
8
exports . fixturesDir = path . join ( exports . testDir , 'fixtures' ) ;
@@ -18,10 +19,33 @@ if (process.env.TEST_THREAD_ID) {
18
19
}
19
20
exports . tmpDir = path . join ( exports . testDir , exports . tmpDirName ) ;
20
21
21
- exports . opensslCli = path . join ( path . dirname ( process . execPath ) , 'openssl-cli' ) ;
22
+ var opensslCli = null ;
23
+
24
+ // opensslCli defined lazily to reduce overhead of spawnSync
25
+ Object . defineProperty ( exports , 'opensslCli' , { get : function ( ) {
26
+ if ( opensslCli !== null ) return opensslCli ;
27
+
28
+ if ( process . config . variables . node_shared_openssl ) {
29
+ // use external command
30
+ opensslCli = 'openssl' ;
31
+ } else {
32
+ // use command built from sources included in io.js repository
33
+ opensslCli = path . join ( path . dirname ( process . execPath ) , 'openssl-cli' ) ;
34
+ }
35
+
36
+ if ( process . platform === 'win32' ) opensslCli += '.exe' ;
37
+
38
+ var openssl_cmd = child_process . spawnSync ( opensslCli , [ 'version' ] ) ;
39
+ if ( openssl_cmd . status !== 0 || openssl_cmd . error !== undefined ) {
40
+ // openssl command cannot be executed
41
+ opensslCli = false ;
42
+ }
43
+ return opensslCli ;
44
+ } , enumerable : true } ) ;
45
+
46
+
22
47
if ( process . platform === 'win32' ) {
23
48
exports . PIPE = '\\\\.\\pipe\\libuv-test' ;
24
- exports . opensslCli += '.exe' ;
25
49
} else {
26
50
exports . PIPE = exports . tmpDir + '/test.sock' ;
27
51
}
@@ -37,12 +61,6 @@ if (process.env.NODE_COMMON_PIPE) {
37
61
}
38
62
}
39
63
40
- try {
41
- fs . accessSync ( exports . opensslCli ) ;
42
- } catch ( err ) {
43
- exports . opensslCli = false ;
44
- }
45
-
46
64
if ( process . platform === 'win32' ) {
47
65
exports . faketimeCli = false ;
48
66
} else {
0 commit comments