@flun/nodejs-mobile-gyp 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +56 -36
- package/README.md +256 -252
- package/addon.gypi +13 -1
- package/bin/node-gyp.js +66 -109
- package/gyp/pylib/gyp/MSVSSettings.py +13 -0
- package/lib/build.js +127 -209
- package/lib/clean.js +13 -16
- package/lib/configure.js +183 -265
- package/lib/create-config-gypi.js +102 -156
- package/lib/download.js +29 -42
- package/lib/find-node-directory.js +38 -55
- package/lib/find-python.js +162 -198
- package/lib/find-visualstudio.js +196 -295
- package/lib/install.js +269 -378
- package/lib/list.js +19 -25
- package/lib/log.js +69 -133
- package/lib/node-gyp.js +62 -107
- package/lib/process-release.js +100 -139
- package/lib/rebuild.js +3 -8
- package/lib/remove.js +34 -44
- package/lib/util.js +62 -73
- package/package.json +5 -3
- package/gyp/LICENSE +0 -28
package/lib/configure.js
CHANGED
|
@@ -1,295 +1,213 @@
|
|
|
1
|
-
import gracefulFs from 'graceful-fs'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import * as log from './log.js'
|
|
4
|
-
import os from 'os'
|
|
5
|
-
import { processRelease } from './process-release.js'
|
|
6
|
-
import { findNodeDirectory } from './find-node-directory.js'
|
|
7
|
-
import { createConfigGypi } from './create-config-gypi.js'
|
|
8
|
-
import { format as msgFormat } from 'util'
|
|
9
|
-
import { findAccessibleSync } from './util.js'
|
|
10
|
-
import { PythonFinder } from './find-python.js'
|
|
11
|
-
import { fileURLToPath } from 'url'
|
|
12
|
-
|
|
13
|
-
const fs = gracefulFs.promises
|
|
14
|
-
const win = process.platform === 'win32'
|
|
15
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
1
|
+
import gracefulFs from 'graceful-fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import * as log from './log.js';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import { processRelease } from './process-release.js';
|
|
6
|
+
import { findNodeDirectory } from './find-node-directory.js';
|
|
7
|
+
import { createConfigGypi } from './create-config-gypi.js';
|
|
8
|
+
import { format as msgFormat } from 'util';
|
|
9
|
+
import { findAccessibleSync } from './util.js';
|
|
10
|
+
import { PythonFinder } from './find-python.js';
|
|
11
|
+
import { fileURLToPath } from 'url';
|
|
12
|
+
|
|
13
|
+
const fs = gracefulFs.promises, win = process.platform === 'win32', __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
16
14
|
|
|
17
15
|
// 条件加载:仅在 Windows 上需要
|
|
18
|
-
let findVisualStudio = null
|
|
16
|
+
let findVisualStudio = null, nodeDir;
|
|
19
17
|
if (win) {
|
|
20
|
-
const { VisualStudioFinder } = await import('./find-visualstudio.js')
|
|
21
|
-
findVisualStudio = VisualStudioFinder.findVisualStudio
|
|
18
|
+
const { VisualStudioFinder } = await import('./find-visualstudio.js');
|
|
19
|
+
findVisualStudio = VisualStudioFinder.findVisualStudio;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
/**
|
|
25
23
|
* 生成构建文件(Makefile / MSVC 工程)
|
|
26
24
|
*/
|
|
27
25
|
const configure = async (gyp, argv) => {
|
|
28
|
-
const buildDir = path.resolve('build')
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// 指定了 --nodedir,用它作为开发文件目录
|
|
43
|
-
nodeDir = gyp.opts.nodedir.replace(/^~/, os.homedir())
|
|
44
|
-
log.verbose('get node dir', 'compiling against specified --nodedir dev files: %s', nodeDir)
|
|
45
|
-
} else {
|
|
46
|
-
// 未指定 --nodedir,先确保 Node 依赖已安装
|
|
47
|
-
if ('v' + release.version !== process.version) {
|
|
48
|
-
// 指定了 --target,确定目标版本
|
|
49
|
-
log.verbose('get node dir', 'compiling against --target node version: %s', release.version)
|
|
50
|
-
} else {
|
|
51
|
-
// 未指定 --target,使用当前主机 Node 版本
|
|
52
|
-
log.verbose('get node dir', 'no --target version specified, falling back to host node version: %s', release.version)
|
|
26
|
+
const buildDir = path.resolve('build'), configNames = ['config.gypi', 'common.gypi'], configs = [],
|
|
27
|
+
release = processRelease(argv, gyp, process.version, process.release),
|
|
28
|
+
python = await PythonFinder.findPython(gyp.opts.python),
|
|
29
|
+
runGyp = async () => {
|
|
30
|
+
if (!~argv.indexOf('-f') && !~argv.indexOf('--format')) {
|
|
31
|
+
if (win) {
|
|
32
|
+
log.verbose('gyp', 'gyp format was not specified; forcing "msvs"');
|
|
33
|
+
// 非 Windows 强制使用 make 目标
|
|
34
|
+
argv.push('-f', ('format' in gyp.opts) ? gyp.opts.format : 'msvs');
|
|
35
|
+
} else {
|
|
36
|
+
log.verbose('gyp', 'gyp format was not specified; forcing "make"');
|
|
37
|
+
// 非 Windows 强制使用 make 目标
|
|
38
|
+
argv.push('-f', ('format' in gyp.opts) ? gyp.opts.format : 'make');
|
|
39
|
+
}
|
|
53
40
|
}
|
|
54
41
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
42
|
+
configs.forEach(config => argv.push('-I', config)); // 引入所有找到的 .gypi 文件
|
|
43
|
+
// AIX 和 z/OS 需要设置导出文件路径,其中包含链接所需符号
|
|
44
|
+
let nodeExpFile, nodeRootDir, candidates, logprefix = 'find exports file';
|
|
45
|
+
if (process.platform === 'aix' || process.platform === 'os390' || process.platform === 'os400') {
|
|
46
|
+
const ext = process.platform === 'os390' ? 'x' : 'exp';
|
|
47
|
+
nodeRootDir = findNodeDirectory();
|
|
48
|
+
|
|
49
|
+
if (process.platform === 'aix' || process.platform === 'os400')
|
|
50
|
+
candidates = ['include/node/node', 'out/Release/node', 'out/Debug/node', 'node'].map(file => file + '.' + ext);
|
|
51
|
+
else
|
|
52
|
+
candidates = [
|
|
53
|
+
'out/Release/lib.target/libnode', 'out/Debug/lib.target/libnode', 'out/Release/obj.target/libnode',
|
|
54
|
+
'out/Debug/obj.target/libnode', 'lib/libnode'].map(file => file + '.' + ext);
|
|
55
|
+
|
|
56
|
+
nodeExpFile = findAccessibleSync(logprefix, nodeRootDir, candidates);
|
|
57
|
+
if (nodeExpFile !== undefined) log.verbose(logprefix, 'Found exports file: %s', nodeExpFile);
|
|
58
|
+
else {
|
|
59
|
+
const msg = msgFormat('Could not find node.%s file in %s', ext, nodeRootDir);
|
|
60
|
+
log.error(logprefix, 'Could not find exports file');
|
|
61
|
+
throw new Error(msg);
|
|
62
|
+
}
|
|
58
63
|
}
|
|
59
64
|
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async function findConfigs () {
|
|
95
|
-
const name = configNames.shift()
|
|
96
|
-
if (!name) {
|
|
97
|
-
return runGyp()
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const fullPath = path.resolve(name)
|
|
101
|
-
log.verbose(name, 'checking for gypi file: %s', fullPath)
|
|
102
|
-
try {
|
|
103
|
-
await fs.stat(fullPath)
|
|
104
|
-
log.verbose(name, 'found gypi file')
|
|
105
|
-
configs.push(fullPath)
|
|
106
|
-
} catch (err) {
|
|
107
|
-
// ENOENT 时继续检查下一个 gypi 文件名
|
|
108
|
-
if (err.code !== 'ENOENT') {
|
|
109
|
-
throw err
|
|
65
|
+
// z/OS 需要设置 zoslib 头文件目录,其中包含 v8config.h 引用的头文件
|
|
66
|
+
let zoslibIncDir;
|
|
67
|
+
if (process.platform === 'os390') {
|
|
68
|
+
logprefix = "find zoslib's zos-base.h:";
|
|
69
|
+
let msg, zoslibIncPath = process.env.ZOSLIB_INCLUDES;
|
|
70
|
+
if (zoslibIncPath) {
|
|
71
|
+
zoslibIncPath = findAccessibleSync(logprefix, zoslibIncPath, ['zos-base.h']);
|
|
72
|
+
if (zoslibIncPath === undefined) {
|
|
73
|
+
msg = msgFormat('Could not find zos-base.h file in the directory set ' +
|
|
74
|
+
'in ZOSLIB_INCLUDES environment variable: %s; set it ' +
|
|
75
|
+
'to the correct path, or unset it to search %s', process.env.ZOSLIB_INCLUDES, nodeRootDir)
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
candidates = [
|
|
79
|
+
'include/node/zoslib/zos-base.h', 'include/zoslib/zos-base.h', 'zoslib/include/zos-base.h',
|
|
80
|
+
'install/include/node/zoslib/zos-base.h'
|
|
81
|
+
]
|
|
82
|
+
zoslibIncPath = findAccessibleSync(logprefix, nodeRootDir, candidates);
|
|
83
|
+
if (zoslibIncPath === undefined) {
|
|
84
|
+
msg = msgFormat('Could not find any of %s in directory %s; set ' +
|
|
85
|
+
'environmant variable ZOSLIB_INCLUDES to the path ' +
|
|
86
|
+
'that contains zos-base.h', candidates.toString(), nodeRootDir)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (zoslibIncPath !== undefined) {
|
|
90
|
+
zoslibIncDir = path.dirname(zoslibIncPath);
|
|
91
|
+
log.verbose(logprefix, "Found zoslib's zos-base.h in: %s", zoslibIncDir);
|
|
92
|
+
} else if (release.version.split('.')[0] >= 16) {
|
|
93
|
+
// zoslib 只随 Node v16 及以上发布
|
|
94
|
+
log.error(logprefix, msg);
|
|
95
|
+
throw new Error(msg);
|
|
96
|
+
}
|
|
110
97
|
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return findConfigs()
|
|
114
|
-
}
|
|
115
98
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// 非 Windows 强制使用 make 目标
|
|
125
|
-
argv.push('-f', ('format' in gyp.opts) ? gyp.opts.format : 'make')
|
|
99
|
+
// 这段逻辑移植自旧的 `gyp_addon` Python 文件
|
|
100
|
+
const gypScript = path.resolve(__dirname, '..', 'gyp', 'gyp_main.py'),
|
|
101
|
+
addonGypi = path.resolve(__dirname, '..', 'addon.gypi');
|
|
102
|
+
let commonGypi = path.resolve(nodeDir, 'include/node/common.gypi');
|
|
103
|
+
try {
|
|
104
|
+
await fs.stat(commonGypi);
|
|
105
|
+
} catch (err) {
|
|
106
|
+
commonGypi = path.resolve(nodeDir, 'common.gypi');
|
|
126
107
|
}
|
|
127
|
-
}
|
|
128
108
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
})
|
|
109
|
+
let outputDir = 'build';
|
|
110
|
+
if (win) outputDir = buildDir; // Windows 需要绝对路径
|
|
111
|
+
const nodeGypDir = path.resolve(__dirname, '..');
|
|
133
112
|
|
|
134
|
-
|
|
135
|
-
let nodeExpFile
|
|
136
|
-
let nodeRootDir
|
|
137
|
-
let candidates
|
|
138
|
-
let logprefix = 'find exports file'
|
|
139
|
-
if (process.platform === 'aix' || process.platform === 'os390' || process.platform === 'os400') {
|
|
140
|
-
const ext = process.platform === 'os390' ? 'x' : 'exp'
|
|
141
|
-
nodeRootDir = findNodeDirectory()
|
|
113
|
+
let nodeLibFile = path.join(nodeDir, !gyp.opts.nodedir ? '<(target_arch)' : '$(Configuration)', release.name + '.lib');
|
|
142
114
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
115
|
+
argv.push('-I', addonGypi), argv.push('-I', commonGypi), argv.push('-Dlibrary=shared_library');
|
|
116
|
+
argv.push('-Dvisibility=default'), argv.push('-Dnode_root_dir=' + nodeDir);
|
|
117
|
+
if (process.platform === 'aix' || process.platform === 'os390' || process.platform === 'os400') {
|
|
118
|
+
argv.push('-Dnode_exp_file=' + nodeExpFile);
|
|
119
|
+
if (process.platform === 'os390' && zoslibIncDir) argv.push('-Dzoslib_include_dir=' + zoslibIncDir);
|
|
120
|
+
}
|
|
121
|
+
argv.push('-Dnode_gyp_dir=' + nodeGypDir);
|
|
122
|
+
|
|
123
|
+
// 这样做是为了让 Cygwin 环境正常工作,否则未转义的 '\' 会被吃掉,
|
|
124
|
+
// 导致路径错误,如 c:parentFolderfolderanotherFolder 而非 c:\parentFolder\folder\anotherFolder
|
|
125
|
+
if (win) nodeLibFile = nodeLibFile.replace(/\\/g, '\\\\');
|
|
126
|
+
argv.push('-Dnode_lib_file=' + nodeLibFile), argv.push('-Dmodule_root_dir=' + process.cwd());
|
|
127
|
+
argv.push('-Dnode_engine=' + (gyp.opts.node_engine || process.jsEngine || 'v8'));
|
|
128
|
+
argv.push('--depth=.'), argv.push('--no-parallel');
|
|
129
|
+
argv.push('--generator-output', outputDir); // 告诉 gyp 把 Makefile/Solution 文件写到 output_dir
|
|
130
|
+
if (win) argv.push('-Gmsvs_toolset=v145');
|
|
131
|
+
|
|
132
|
+
argv.push('-Goutput_dir=.'); // 告诉 make 把输出写到同一目录
|
|
133
|
+
argv.unshift('binding.gyp'); // 强制使用 binding.gyp 文件
|
|
134
|
+
argv.unshift(gypScript); // 从当前目标 nodedir 执行 `gyp`
|
|
135
|
+
|
|
136
|
+
// 确保 python 使用该 node 包自带的文件
|
|
137
|
+
const pypath = [path.join(__dirname, '..', 'gyp', 'pylib')]
|
|
138
|
+
if (process.env.PYTHONPATH) pypath.push(process.env.PYTHONPATH);
|
|
139
|
+
process.env.PYTHONPATH = pypath.join(win ? ';' : ':');
|
|
140
|
+
|
|
141
|
+
await new Promise((resolve, reject) => {
|
|
142
|
+
const cp = gyp.spawn(python, argv);
|
|
143
|
+
cp.on('exit', code => {
|
|
144
|
+
if (code !== 0) reject(new Error('`gyp` failed with exit code: ' + code));
|
|
145
|
+
else resolve(); // 完成
|
|
161
146
|
})
|
|
147
|
+
})
|
|
148
|
+
},
|
|
149
|
+
findConfigs = async () => {
|
|
150
|
+
const name = configNames.shift();
|
|
151
|
+
if (!name) return runGyp();
|
|
152
|
+
|
|
153
|
+
const fullPath = path.resolve(name);
|
|
154
|
+
log.verbose(name, 'checking for gypi file: %s', fullPath);
|
|
155
|
+
try {
|
|
156
|
+
await fs.stat(fullPath), log.verbose(name, 'found gypi file'), configs.push(fullPath);
|
|
157
|
+
} catch (err) {
|
|
158
|
+
if (err.code !== 'ENOENT') throw err; // ENOENT 时继续检查下一个 gypi 文件名
|
|
162
159
|
}
|
|
163
160
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
throw new Error(msg)
|
|
161
|
+
return findConfigs();
|
|
162
|
+
},
|
|
163
|
+
createConfigFile = async vsInfo => {
|
|
164
|
+
if (win) {
|
|
165
|
+
process.env.GYP_MSVS_VERSION = Math.min(vsInfo.versionYear, 2015);
|
|
166
|
+
process.env.GYP_MSVS_OVERRIDE_PATH = vsInfo.path;
|
|
171
167
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
168
|
+
const configPath = await createConfigGypi({ gyp, buildDir, nodeDir, vsInfo, python });
|
|
169
|
+
configs.push(configPath);
|
|
170
|
+
return findConfigs();
|
|
171
|
+
},
|
|
172
|
+
createBuildDir = async () => {
|
|
173
|
+
log.verbose('build dir', 'attempting to create "build" dir: %s', buildDir);
|
|
174
|
+
|
|
175
|
+
const isNew = await fs.mkdir(buildDir, { recursive: true });
|
|
176
|
+
log.verbose('build dir', '"build" dir needed to be created?', isNew ? 'Yes' : 'No');
|
|
177
|
+
const vsInfo = win ? await findVisualStudio(release.semver, gyp.opts['msvs-version']) : null;
|
|
178
|
+
return createConfigFile(vsInfo);
|
|
179
|
+
},
|
|
180
|
+
getNodeDir = async () => {
|
|
181
|
+
// 此时 python 已确定
|
|
182
|
+
process.env.PYTHON = python;
|
|
183
|
+
|
|
184
|
+
if (gyp.opts.nodedir) {
|
|
185
|
+
// 指定了 --nodedir,用它作为开发文件目录
|
|
186
|
+
nodeDir = gyp.opts.nodedir.replace(/^~/, os.homedir());
|
|
187
|
+
log.verbose('get node dir', 'compiling against specified --nodedir dev files: %s', nodeDir);
|
|
187
188
|
} else {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (zoslibIncPath === undefined) {
|
|
196
|
-
msg = msgFormat('Could not find any of %s in directory %s; set ' +
|
|
197
|
-
'environmant variable ZOSLIB_INCLUDES to the path ' +
|
|
198
|
-
'that contains zos-base.h', candidates.toString(), nodeRootDir)
|
|
189
|
+
// 未指定 --nodedir,先确保 Node 依赖已安装
|
|
190
|
+
if ('v' + release.version !== process.version) {
|
|
191
|
+
// 指定了 --target,确定目标版本
|
|
192
|
+
log.verbose('get node dir', 'compiling against --target node version: %s', release.version);
|
|
193
|
+
} else {
|
|
194
|
+
// 未指定 --target,使用当前主机 Node 版本
|
|
195
|
+
log.verbose('get node dir', 'no --target version specified, falling back to host node version: %s', release.version);
|
|
199
196
|
}
|
|
200
|
-
}
|
|
201
|
-
if (zoslibIncPath !== undefined) {
|
|
202
|
-
zoslibIncDir = path.dirname(zoslibIncPath)
|
|
203
|
-
log.verbose(logprefix, "Found zoslib's zos-base.h in: %s", zoslibIncDir)
|
|
204
|
-
} else if (release.version.split('.')[0] >= 16) {
|
|
205
|
-
// zoslib 只随 Node v16 及以上发布
|
|
206
|
-
log.error(logprefix, msg)
|
|
207
|
-
throw new Error(msg)
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// 这段逻辑移植自旧的 `gyp_addon` Python 文件
|
|
212
|
-
const gypScript = path.resolve(__dirname, '..', 'gyp', 'gyp_main.py')
|
|
213
|
-
const addonGypi = path.resolve(__dirname, '..', 'addon.gypi')
|
|
214
|
-
let commonGypi = path.resolve(nodeDir, 'include/node/common.gypi')
|
|
215
|
-
try {
|
|
216
|
-
await fs.stat(commonGypi)
|
|
217
|
-
} catch (err) {
|
|
218
|
-
commonGypi = path.resolve(nodeDir, 'common.gypi')
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
let outputDir = 'build'
|
|
222
|
-
if (win) {
|
|
223
|
-
// Windows 需要绝对路径
|
|
224
|
-
outputDir = buildDir
|
|
225
|
-
}
|
|
226
|
-
const nodeGypDir = path.resolve(__dirname, '..')
|
|
227
197
|
|
|
228
|
-
|
|
229
|
-
!gyp.opts.nodedir ? '<(target_arch)' : '$(Configuration)',
|
|
230
|
-
release.name + '.lib')
|
|
198
|
+
if (!release.semver) throw new Error('版本号无效: ' + release.version); // 无法用 semver 解析版本字符串
|
|
231
199
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
if (process.platform === 'aix' || process.platform === 'os390' || process.platform === 'os400') {
|
|
238
|
-
argv.push('-Dnode_exp_file=' + nodeExpFile)
|
|
239
|
-
if (process.platform === 'os390' && zoslibIncDir) {
|
|
240
|
-
argv.push('-Dzoslib_include_dir=' + zoslibIncDir)
|
|
200
|
+
// 如果指定了 tarball 选项,总是删除并重装 headers 到 devdir,
|
|
201
|
+
// 否则只在不存在时安装
|
|
202
|
+
gyp.opts.ensure = !gyp.opts.tarball, await gyp.commands.install([release.version]);
|
|
203
|
+
log.verbose('get node dir', 'target node version installed:', release.versionDir);
|
|
204
|
+
nodeDir = path.resolve(gyp.devDir, release.versionDir);
|
|
241
205
|
}
|
|
242
|
-
}
|
|
243
|
-
argv.push('-Dnode_gyp_dir=' + nodeGypDir)
|
|
244
|
-
|
|
245
|
-
// 这样做是为了让 Cygwin 环境正常工作,否则未转义的 '\' 会被吃掉,
|
|
246
|
-
// 导致路径错误,如 c:parentFolderfolderanotherFolder 而非 c:\parentFolder\folder\anotherFolder
|
|
247
|
-
if (win) {
|
|
248
|
-
nodeLibFile = nodeLibFile.replace(/\\/g, '\\\\')
|
|
249
|
-
}
|
|
250
|
-
argv.push('-Dnode_lib_file=' + nodeLibFile)
|
|
251
|
-
argv.push('-Dmodule_root_dir=' + process.cwd())
|
|
252
|
-
argv.push('-Dnode_engine=' +
|
|
253
|
-
(gyp.opts.node_engine || process.jsEngine || 'v8'))
|
|
254
|
-
argv.push('--depth=.')
|
|
255
|
-
argv.push('--no-parallel')
|
|
256
|
-
|
|
257
|
-
// 告诉 gyp 把 Makefile/Solution 文件写到 output_dir
|
|
258
|
-
argv.push('--generator-output', outputDir)
|
|
259
|
-
if (win) {
|
|
260
|
-
argv.push('-Gmsvs_toolset=v145')
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// 告诉 make 把输出写到同一目录
|
|
264
|
-
argv.push('-Goutput_dir=.')
|
|
265
|
-
|
|
266
|
-
// 强制使用 binding.gyp 文件
|
|
267
|
-
argv.unshift('binding.gyp')
|
|
268
|
-
|
|
269
|
-
// 从当前目标 nodedir 执行 `gyp`
|
|
270
|
-
argv.unshift(gypScript)
|
|
271
|
-
|
|
272
|
-
// 确保 python 使用该 node 包自带的文件
|
|
273
|
-
const pypath = [path.join(__dirname, '..', 'gyp', 'pylib')]
|
|
274
|
-
if (process.env.PYTHONPATH) {
|
|
275
|
-
pypath.push(process.env.PYTHONPATH)
|
|
276
|
-
}
|
|
277
|
-
process.env.PYTHONPATH = pypath.join(win ? ';' : ':')
|
|
278
|
-
|
|
279
|
-
await new Promise((resolve, reject) => {
|
|
280
|
-
const cp = gyp.spawn(python, argv)
|
|
281
|
-
cp.on('exit', (code) => {
|
|
282
|
-
if (code !== 0) {
|
|
283
|
-
reject(new Error('`gyp` failed with exit code: ' + code))
|
|
284
|
-
} else {
|
|
285
|
-
// 完成
|
|
286
|
-
resolve()
|
|
287
|
-
}
|
|
288
|
-
})
|
|
289
|
-
})
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
206
|
|
|
293
|
-
|
|
207
|
+
return createBuildDir();
|
|
208
|
+
};
|
|
209
|
+
return getNodeDir();
|
|
210
|
+
};
|
|
294
211
|
|
|
295
|
-
|
|
212
|
+
configure.usage = 'Generates ' + (win ? 'MSVC project files' : 'a Makefile') + ' for the current module';
|
|
213
|
+
export { configure };
|