@dry-software/cmake-js 7.3.2 → 7.3.3
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/bin/cmake-js +15 -9
- package/dist/index.cjs +1975 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +1940 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +16 -4
- package/lib/appCMakeJSConfig.js +0 -58
- package/lib/buildSystem.js +0 -123
- package/lib/cMake.js +0 -362
- package/lib/cmLog.js +0 -61
- package/lib/dist.js +0 -176
- package/lib/downloader.js +0 -92
- package/lib/environment.js +0 -97
- package/lib/import/LICENSE +0 -24
- package/lib/import/README +0 -6
- package/lib/import/find-visualstudio.js +0 -439
- package/lib/import/util.js +0 -70
- package/lib/index.js +0 -12
- package/lib/locateNAN.js +0 -63
- package/lib/locateNodeApi.js +0 -18
- package/lib/npmConfig.js +0 -31
- package/lib/processHelpers.js +0 -53
- package/lib/runtimePaths.js +0 -95
- package/lib/targetOptions.js +0 -33
- package/lib/toolset.js +0 -224
- /package/{lib → dist}/cpp/win_delay_load_hook.cc +0 -0
- /package/{lib → dist}/import/Find-VisualStudio.cs +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1975 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __esm = (fn, res) => function __init() {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
};
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
|
|
32
|
+
// node_modules/tsup/assets/cjs_shims.js
|
|
33
|
+
var getImportMetaUrl, importMetaUrl;
|
|
34
|
+
var init_cjs_shims = __esm({
|
|
35
|
+
"node_modules/tsup/assets/cjs_shims.js"() {
|
|
36
|
+
getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
37
|
+
importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// lib/environment.js
|
|
42
|
+
var import_node_os, import_which, import_node_module, require2, packageJson, environment, environment_default;
|
|
43
|
+
var init_environment = __esm({
|
|
44
|
+
"lib/environment.js"() {
|
|
45
|
+
init_cjs_shims();
|
|
46
|
+
import_node_os = __toESM(require("os"), 1);
|
|
47
|
+
import_which = __toESM(require("which"), 1);
|
|
48
|
+
import_node_module = require("module");
|
|
49
|
+
require2 = (0, import_node_module.createRequire)(importMetaUrl);
|
|
50
|
+
packageJson = require2("../package.json");
|
|
51
|
+
environment = {
|
|
52
|
+
cmakeJsVersion: packageJson.version,
|
|
53
|
+
platform: import_node_os.default.platform(),
|
|
54
|
+
isWin: import_node_os.default.platform() === "win32",
|
|
55
|
+
isLinux: import_node_os.default.platform() === "linux",
|
|
56
|
+
isOSX: import_node_os.default.platform() === "darwin",
|
|
57
|
+
arch: import_node_os.default.arch(),
|
|
58
|
+
isX86: import_node_os.default.arch() === "ia32" || import_node_os.default.arch() === "x86",
|
|
59
|
+
isX64: import_node_os.default.arch() === "x64",
|
|
60
|
+
isArm: import_node_os.default.arch() === "arm",
|
|
61
|
+
isArm64: import_node_os.default.arch() === "arm64",
|
|
62
|
+
runtime: "node",
|
|
63
|
+
runtimeVersion: process.versions.node
|
|
64
|
+
};
|
|
65
|
+
Object.defineProperties(environment, {
|
|
66
|
+
_isNinjaAvailable: {
|
|
67
|
+
value: null,
|
|
68
|
+
writable: true
|
|
69
|
+
},
|
|
70
|
+
isNinjaAvailable: {
|
|
71
|
+
get: function() {
|
|
72
|
+
if (this._isNinjaAvailable === null) {
|
|
73
|
+
this._isNinjaAvailable = false;
|
|
74
|
+
try {
|
|
75
|
+
if (import_which.default.sync("ninja")) {
|
|
76
|
+
this._isNinjaAvailable = true;
|
|
77
|
+
}
|
|
78
|
+
} catch (e) {
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return this._isNinjaAvailable;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
_isMakeAvailable: {
|
|
85
|
+
value: null,
|
|
86
|
+
writable: true
|
|
87
|
+
},
|
|
88
|
+
isMakeAvailable: {
|
|
89
|
+
get: function() {
|
|
90
|
+
if (this._isMakeAvailable === null) {
|
|
91
|
+
this._isMakeAvailable = false;
|
|
92
|
+
try {
|
|
93
|
+
if (import_which.default.sync("make")) {
|
|
94
|
+
this._isMakeAvailable = true;
|
|
95
|
+
}
|
|
96
|
+
} catch (e) {
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return this._isMakeAvailable;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
_isGPPAvailable: {
|
|
103
|
+
value: null,
|
|
104
|
+
writable: true
|
|
105
|
+
},
|
|
106
|
+
isGPPAvailable: {
|
|
107
|
+
get: function() {
|
|
108
|
+
if (this._isGPPAvailable === null) {
|
|
109
|
+
this._isGPPAvailable = false;
|
|
110
|
+
try {
|
|
111
|
+
if (import_which.default.sync("g++")) {
|
|
112
|
+
this._isGPPAvailable = true;
|
|
113
|
+
}
|
|
114
|
+
} catch (e) {
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return this._isGPPAvailable;
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
_isClangAvailable: {
|
|
121
|
+
value: null,
|
|
122
|
+
writable: true
|
|
123
|
+
},
|
|
124
|
+
isClangAvailable: {
|
|
125
|
+
get: function() {
|
|
126
|
+
if (this._isClangAvailable === null) {
|
|
127
|
+
this._isClangAvailable = false;
|
|
128
|
+
try {
|
|
129
|
+
if (import_which.default.sync("clang++")) {
|
|
130
|
+
this._isClangAvailable = true;
|
|
131
|
+
}
|
|
132
|
+
} catch (e) {
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return this._isClangAvailable;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
environment_default = environment;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// lib/cmLog.js
|
|
144
|
+
var import_npmlog, import_debug, CMLog, cmLog_default;
|
|
145
|
+
var init_cmLog = __esm({
|
|
146
|
+
"lib/cmLog.js"() {
|
|
147
|
+
init_cjs_shims();
|
|
148
|
+
import_npmlog = __toESM(require("npmlog"), 1);
|
|
149
|
+
import_debug = __toESM(require("debug"), 1);
|
|
150
|
+
CMLog = class {
|
|
151
|
+
get level() {
|
|
152
|
+
if (this.options.noLog) {
|
|
153
|
+
return "silly";
|
|
154
|
+
} else {
|
|
155
|
+
return import_npmlog.default.level;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
constructor(options) {
|
|
159
|
+
this.options = options || {};
|
|
160
|
+
this.debug = (0, import_debug.default)(this.options.logName || "cmake-js");
|
|
161
|
+
}
|
|
162
|
+
silly(cat, msg) {
|
|
163
|
+
if (this.options.noLog) {
|
|
164
|
+
this.debug(cat + ": " + msg);
|
|
165
|
+
} else {
|
|
166
|
+
import_npmlog.default.silly(cat, msg);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
verbose(cat, msg) {
|
|
170
|
+
if (this.options.noLog) {
|
|
171
|
+
this.debug(cat + ": " + msg);
|
|
172
|
+
} else {
|
|
173
|
+
import_npmlog.default.verbose(cat, msg);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
info(cat, msg) {
|
|
177
|
+
if (this.options.noLog) {
|
|
178
|
+
this.debug(cat + ": " + msg);
|
|
179
|
+
} else {
|
|
180
|
+
import_npmlog.default.info(cat, msg);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
warn(cat, msg) {
|
|
184
|
+
if (this.options.noLog) {
|
|
185
|
+
this.debug(cat + ": " + msg);
|
|
186
|
+
} else {
|
|
187
|
+
import_npmlog.default.warn(cat, msg);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
http(cat, msg) {
|
|
191
|
+
if (this.options.noLog) {
|
|
192
|
+
this.debug(cat + ": " + msg);
|
|
193
|
+
} else {
|
|
194
|
+
import_npmlog.default.http(cat, msg);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
error(cat, msg) {
|
|
198
|
+
if (this.options.noLog) {
|
|
199
|
+
this.debug(cat + ": " + msg);
|
|
200
|
+
} else {
|
|
201
|
+
import_npmlog.default.error(cat, msg);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
cmLog_default = CMLog;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// lib/targetOptions.js
|
|
210
|
+
var TargetOptions, targetOptions_default;
|
|
211
|
+
var init_targetOptions = __esm({
|
|
212
|
+
"lib/targetOptions.js"() {
|
|
213
|
+
init_cjs_shims();
|
|
214
|
+
init_environment();
|
|
215
|
+
TargetOptions = class {
|
|
216
|
+
get arch() {
|
|
217
|
+
return this.options.arch || environment_default.arch;
|
|
218
|
+
}
|
|
219
|
+
get isX86() {
|
|
220
|
+
return this.arch === "ia32" || this.arch === "x86";
|
|
221
|
+
}
|
|
222
|
+
get isX64() {
|
|
223
|
+
return this.arch === "x64";
|
|
224
|
+
}
|
|
225
|
+
get isArm() {
|
|
226
|
+
return this.arch === "arm";
|
|
227
|
+
}
|
|
228
|
+
get isArm64() {
|
|
229
|
+
return this.arch === "arm64";
|
|
230
|
+
}
|
|
231
|
+
get runtime() {
|
|
232
|
+
return this.options.runtime || environment_default.runtime;
|
|
233
|
+
}
|
|
234
|
+
get runtimeVersion() {
|
|
235
|
+
return this.options.runtimeVersion || environment_default.runtimeVersion;
|
|
236
|
+
}
|
|
237
|
+
constructor(options) {
|
|
238
|
+
this.options = options || {};
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
targetOptions_default = TargetOptions;
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// lib/runtimePaths.js
|
|
246
|
+
var import_node_assert, import_semver, NODE_MIRROR, ELECTRON_MIRROR, runtimePaths, runtimePaths_default;
|
|
247
|
+
var init_runtimePaths = __esm({
|
|
248
|
+
"lib/runtimePaths.js"() {
|
|
249
|
+
init_cjs_shims();
|
|
250
|
+
import_node_assert = __toESM(require("assert"), 1);
|
|
251
|
+
import_semver = __toESM(require("semver"), 1);
|
|
252
|
+
NODE_MIRROR = process.env.NVM_NODEJS_ORG_MIRROR || "https://nodejs.org/dist";
|
|
253
|
+
ELECTRON_MIRROR = process.env.ELECTRON_MIRROR || "https://artifacts.electronjs.org/headers/dist";
|
|
254
|
+
runtimePaths = {
|
|
255
|
+
node: function(targetOptions) {
|
|
256
|
+
if (import_semver.default.lt(targetOptions.runtimeVersion, "4.0.0")) {
|
|
257
|
+
return {
|
|
258
|
+
externalPath: NODE_MIRROR + "/v" + targetOptions.runtimeVersion + "/",
|
|
259
|
+
winLibs: [
|
|
260
|
+
{
|
|
261
|
+
dir: targetOptions.isX64 ? "x64" : "",
|
|
262
|
+
name: targetOptions.runtime + ".lib"
|
|
263
|
+
}
|
|
264
|
+
],
|
|
265
|
+
tarPath: targetOptions.runtime + "-v" + targetOptions.runtimeVersion + ".tar.gz",
|
|
266
|
+
headerOnly: false
|
|
267
|
+
};
|
|
268
|
+
} else {
|
|
269
|
+
return {
|
|
270
|
+
externalPath: NODE_MIRROR + "/v" + targetOptions.runtimeVersion + "/",
|
|
271
|
+
winLibs: [
|
|
272
|
+
{
|
|
273
|
+
dir: targetOptions.isArm64 ? "win-arm64" : targetOptions.isX64 ? "win-x64" : "win-x86",
|
|
274
|
+
name: targetOptions.runtime + ".lib"
|
|
275
|
+
}
|
|
276
|
+
],
|
|
277
|
+
tarPath: targetOptions.runtime + "-v" + targetOptions.runtimeVersion + "-headers.tar.gz",
|
|
278
|
+
headerOnly: true
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
nw: function(targetOptions) {
|
|
283
|
+
if (import_semver.default.gte(targetOptions.runtimeVersion, "0.13.0")) {
|
|
284
|
+
return {
|
|
285
|
+
externalPath: "https://node-webkit.s3.amazonaws.com/v" + targetOptions.runtimeVersion + "/",
|
|
286
|
+
winLibs: [
|
|
287
|
+
{
|
|
288
|
+
dir: targetOptions.isX64 ? "x64" : "",
|
|
289
|
+
name: targetOptions.runtime + ".lib"
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
dir: targetOptions.isX64 ? "x64" : "",
|
|
293
|
+
name: "node.lib"
|
|
294
|
+
}
|
|
295
|
+
],
|
|
296
|
+
tarPath: "nw-headers-v" + targetOptions.runtimeVersion + ".tar.gz",
|
|
297
|
+
headerOnly: false
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
externalPath: "https://node-webkit.s3.amazonaws.com/v" + targetOptions.runtimeVersion + "/",
|
|
302
|
+
winLibs: [
|
|
303
|
+
{
|
|
304
|
+
dir: targetOptions.isX64 ? "x64" : "",
|
|
305
|
+
name: targetOptions.runtime + ".lib"
|
|
306
|
+
}
|
|
307
|
+
],
|
|
308
|
+
tarPath: "nw-headers-v" + targetOptions.runtimeVersion + ".tar.gz",
|
|
309
|
+
headerOnly: false
|
|
310
|
+
};
|
|
311
|
+
},
|
|
312
|
+
electron: function(targetOptions) {
|
|
313
|
+
return {
|
|
314
|
+
externalPath: ELECTRON_MIRROR + "/v" + targetOptions.runtimeVersion + "/",
|
|
315
|
+
winLibs: [
|
|
316
|
+
{
|
|
317
|
+
dir: targetOptions.isArm64 ? "arm64" : targetOptions.isX64 ? "x64" : "",
|
|
318
|
+
name: "node.lib"
|
|
319
|
+
}
|
|
320
|
+
],
|
|
321
|
+
tarPath: "node-v" + targetOptions.runtimeVersion + ".tar.gz",
|
|
322
|
+
headerOnly: import_semver.default.gte(targetOptions.runtimeVersion, "4.0.0-alpha")
|
|
323
|
+
};
|
|
324
|
+
},
|
|
325
|
+
get: function(targetOptions) {
|
|
326
|
+
(0, import_node_assert.default)(targetOptions && typeof targetOptions === "object");
|
|
327
|
+
const runtime = targetOptions.runtime;
|
|
328
|
+
const func = runtimePaths[runtime];
|
|
329
|
+
let paths;
|
|
330
|
+
if (typeof func === "function") {
|
|
331
|
+
paths = func(targetOptions);
|
|
332
|
+
if (paths && typeof paths === "object") {
|
|
333
|
+
return paths;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
throw new Error("Unknown runtime: " + runtime);
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
runtimePaths_default = runtimePaths;
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
// lib/downloader.js
|
|
344
|
+
var import_node_crypto, import_axios, import_memory_stream, import_node_zlib, tar, import_node_fs, Downloader, downloader_default;
|
|
345
|
+
var init_downloader = __esm({
|
|
346
|
+
"lib/downloader.js"() {
|
|
347
|
+
init_cjs_shims();
|
|
348
|
+
import_node_crypto = __toESM(require("crypto"), 1);
|
|
349
|
+
import_axios = __toESM(require("axios"), 1);
|
|
350
|
+
import_memory_stream = __toESM(require("memory-stream"), 1);
|
|
351
|
+
import_node_zlib = __toESM(require("zlib"), 1);
|
|
352
|
+
tar = __toESM(require("tar"), 1);
|
|
353
|
+
import_node_fs = __toESM(require("fs"), 1);
|
|
354
|
+
init_cmLog();
|
|
355
|
+
Downloader = class {
|
|
356
|
+
constructor(options) {
|
|
357
|
+
this.options = options || {};
|
|
358
|
+
this.log = new cmLog_default(this.options);
|
|
359
|
+
}
|
|
360
|
+
downloadToStream(url, stream, hash) {
|
|
361
|
+
const self = this;
|
|
362
|
+
const shasum = hash ? import_node_crypto.default.createHash(hash) : null;
|
|
363
|
+
return new Promise(function(resolve, reject) {
|
|
364
|
+
let length = 0;
|
|
365
|
+
let done = 0;
|
|
366
|
+
let lastPercent = 0;
|
|
367
|
+
import_axios.default.get(url, { responseType: "stream" }).then(function(response) {
|
|
368
|
+
length = parseInt(response.headers["content-length"]);
|
|
369
|
+
if (typeof length !== "number") {
|
|
370
|
+
length = 0;
|
|
371
|
+
}
|
|
372
|
+
response.data.on("data", function(chunk) {
|
|
373
|
+
if (shasum) {
|
|
374
|
+
shasum.update(chunk);
|
|
375
|
+
}
|
|
376
|
+
if (length) {
|
|
377
|
+
done += chunk.length;
|
|
378
|
+
let percent = done / length * 100;
|
|
379
|
+
percent = Math.round(percent / 10) * 10 + 10;
|
|
380
|
+
if (percent > lastPercent) {
|
|
381
|
+
self.log.verbose("DWNL", " " + lastPercent + "%");
|
|
382
|
+
lastPercent = percent;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
response.data.pipe(stream);
|
|
387
|
+
}).catch(function(err) {
|
|
388
|
+
reject(err);
|
|
389
|
+
});
|
|
390
|
+
stream.once("error", function(err) {
|
|
391
|
+
reject(err);
|
|
392
|
+
});
|
|
393
|
+
stream.once("finish", function() {
|
|
394
|
+
resolve(shasum ? shasum.digest("hex") : void 0);
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
async downloadString(url) {
|
|
399
|
+
const result = new import_memory_stream.default();
|
|
400
|
+
await this.downloadToStream(url, result);
|
|
401
|
+
return result.toString();
|
|
402
|
+
}
|
|
403
|
+
async downloadFile(url, options) {
|
|
404
|
+
if (typeof options === "string") {
|
|
405
|
+
options.path = options;
|
|
406
|
+
}
|
|
407
|
+
const result = import_node_fs.default.createWriteStream(options.path);
|
|
408
|
+
const sum = await this.downloadToStream(url, result, options.hash);
|
|
409
|
+
this.testSum(url, sum, options);
|
|
410
|
+
return sum;
|
|
411
|
+
}
|
|
412
|
+
async downloadTgz(url, options) {
|
|
413
|
+
if (typeof options === "string") {
|
|
414
|
+
options.cwd = options;
|
|
415
|
+
}
|
|
416
|
+
const gunzip = import_node_zlib.default.createGunzip();
|
|
417
|
+
const extractor = tar.extract(options);
|
|
418
|
+
gunzip.pipe(extractor);
|
|
419
|
+
const sum = await this.downloadToStream(url, gunzip, options.hash);
|
|
420
|
+
this.testSum(url, sum, options);
|
|
421
|
+
return sum;
|
|
422
|
+
}
|
|
423
|
+
testSum(url, sum, options) {
|
|
424
|
+
if (options.hash && sum && options.sum && options.sum !== sum) {
|
|
425
|
+
throw new Error(options.hash.toUpperCase() + " sum of download '" + url + "' mismatch!");
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
downloader_default = Downloader;
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// lib/dist.js
|
|
434
|
+
function testSum(sums, sum, fPath) {
|
|
435
|
+
const serverSum = sums.find(function(s) {
|
|
436
|
+
return s.getPath === fPath;
|
|
437
|
+
});
|
|
438
|
+
if (serverSum && serverSum.sum === sum) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
throw new Error("SHA sum of file '" + fPath + "' mismatch!");
|
|
442
|
+
}
|
|
443
|
+
var import_node_path, import_posix, import_fs_extra, import_node_os2, Dist, dist_default;
|
|
444
|
+
var init_dist = __esm({
|
|
445
|
+
"lib/dist.js"() {
|
|
446
|
+
init_cjs_shims();
|
|
447
|
+
init_environment();
|
|
448
|
+
import_node_path = __toESM(require("path"), 1);
|
|
449
|
+
import_posix = require("path/posix");
|
|
450
|
+
import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
451
|
+
init_cmLog();
|
|
452
|
+
init_targetOptions();
|
|
453
|
+
init_runtimePaths();
|
|
454
|
+
init_downloader();
|
|
455
|
+
import_node_os2 = __toESM(require("os"), 1);
|
|
456
|
+
Dist = class {
|
|
457
|
+
get internalPath() {
|
|
458
|
+
const cacheDirectory = ".cmake-js";
|
|
459
|
+
const runtimeArchDirectory = this.targetOptions.runtime + "-" + this.targetOptions.arch;
|
|
460
|
+
const runtimeVersionDirectory = "v" + this.targetOptions.runtimeVersion;
|
|
461
|
+
return this.options.runtimeDirectory || import_node_path.default.join(import_node_os2.default.homedir(), cacheDirectory, runtimeArchDirectory, runtimeVersionDirectory);
|
|
462
|
+
}
|
|
463
|
+
get externalPath() {
|
|
464
|
+
return runtimePaths_default.get(this.targetOptions).externalPath;
|
|
465
|
+
}
|
|
466
|
+
get downloaded() {
|
|
467
|
+
let headers2 = false;
|
|
468
|
+
let libs = true;
|
|
469
|
+
let stat = getStat(this.internalPath);
|
|
470
|
+
if (stat.isDirectory()) {
|
|
471
|
+
if (this.headerOnly) {
|
|
472
|
+
stat = getStat(import_node_path.default.join(this.internalPath, "include/node/node.h"));
|
|
473
|
+
headers2 = stat.isFile();
|
|
474
|
+
} else {
|
|
475
|
+
stat = getStat(import_node_path.default.join(this.internalPath, "src/node.h"));
|
|
476
|
+
if (stat.isFile()) {
|
|
477
|
+
stat = getStat(import_node_path.default.join(this.internalPath, "deps/v8/include/v8.h"));
|
|
478
|
+
headers2 = stat.isFile();
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
if (environment_default.isWin) {
|
|
482
|
+
for (const libPath of this.winLibs) {
|
|
483
|
+
stat = getStat(libPath);
|
|
484
|
+
libs = libs && stat.isFile();
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
return headers2 && libs;
|
|
489
|
+
function getStat(path9) {
|
|
490
|
+
try {
|
|
491
|
+
return import_fs_extra.default.statSync(path9);
|
|
492
|
+
} catch (e) {
|
|
493
|
+
return {
|
|
494
|
+
isFile: () => false,
|
|
495
|
+
isDirectory: () => false
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
get winLibs() {
|
|
501
|
+
const libs = runtimePaths_default.get(this.targetOptions).winLibs;
|
|
502
|
+
const result = [];
|
|
503
|
+
for (const lib of libs) {
|
|
504
|
+
result.push(import_node_path.default.join(this.internalPath, lib.dir, lib.name));
|
|
505
|
+
}
|
|
506
|
+
return result;
|
|
507
|
+
}
|
|
508
|
+
get headerOnly() {
|
|
509
|
+
return runtimePaths_default.get(this.targetOptions).headerOnly;
|
|
510
|
+
}
|
|
511
|
+
constructor(options) {
|
|
512
|
+
this.options = options || {};
|
|
513
|
+
this.log = new cmLog_default(this.options);
|
|
514
|
+
this.targetOptions = new targetOptions_default(this.options);
|
|
515
|
+
this.downloader = new downloader_default(this.options);
|
|
516
|
+
}
|
|
517
|
+
async ensureDownloaded() {
|
|
518
|
+
if (!this.downloaded) {
|
|
519
|
+
await this.download();
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
async download() {
|
|
523
|
+
const log4 = this.log;
|
|
524
|
+
log4.info("DIST", "Downloading distribution files to: " + this.internalPath);
|
|
525
|
+
await import_fs_extra.default.ensureDir(this.internalPath);
|
|
526
|
+
const sums = await this._downloadShaSums();
|
|
527
|
+
await Promise.all([this._downloadLibs(sums), this._downloadTar(sums)]);
|
|
528
|
+
}
|
|
529
|
+
async _downloadShaSums() {
|
|
530
|
+
if (this.targetOptions.runtime === "node") {
|
|
531
|
+
const sumUrl = (0, import_posix.join)(this.externalPath, "SHASUMS256.txt");
|
|
532
|
+
const log4 = this.log;
|
|
533
|
+
log4.http("DIST", " - " + sumUrl);
|
|
534
|
+
return (await this.downloader.downloadString(sumUrl)).split("\n").map(function(line) {
|
|
535
|
+
const parts = line.split(/\s+/);
|
|
536
|
+
return {
|
|
537
|
+
getPath: parts[1],
|
|
538
|
+
sum: parts[0]
|
|
539
|
+
};
|
|
540
|
+
}).filter(function(i) {
|
|
541
|
+
return i.getPath && i.sum;
|
|
542
|
+
});
|
|
543
|
+
} else {
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
async _downloadTar(sums) {
|
|
548
|
+
const log4 = this.log;
|
|
549
|
+
const self = this;
|
|
550
|
+
const tarLocalPath = runtimePaths_default.get(self.targetOptions).tarPath;
|
|
551
|
+
const tarUrl = (0, import_posix.join)(self.externalPath, tarLocalPath);
|
|
552
|
+
log4.http("DIST", " - " + tarUrl);
|
|
553
|
+
const sum = await this.downloader.downloadTgz(tarUrl, {
|
|
554
|
+
hash: sums ? "sha256" : null,
|
|
555
|
+
cwd: self.internalPath,
|
|
556
|
+
strip: 1,
|
|
557
|
+
filter: function(entryPath) {
|
|
558
|
+
if (entryPath === self.internalPath) {
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
const ext = import_node_path.default.extname(entryPath);
|
|
562
|
+
return ext && ext.toLowerCase() === ".h";
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
if (sums) {
|
|
566
|
+
testSum(sums, sum, tarLocalPath);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
async _downloadLibs(sums) {
|
|
570
|
+
const log4 = this.log;
|
|
571
|
+
const self = this;
|
|
572
|
+
if (!environment_default.isWin) {
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
const paths = runtimePaths_default.get(self.targetOptions);
|
|
576
|
+
for (const dirs of paths.winLibs) {
|
|
577
|
+
const subDir = dirs.dir;
|
|
578
|
+
const fn = dirs.name;
|
|
579
|
+
const fPath = subDir ? (0, import_posix.join)(subDir, fn) : fn;
|
|
580
|
+
const libUrl = (0, import_posix.join)(self.externalPath, fPath);
|
|
581
|
+
log4.http("DIST", " - " + libUrl);
|
|
582
|
+
await import_fs_extra.default.ensureDir(import_node_path.default.join(self.internalPath, subDir));
|
|
583
|
+
const sum = await this.downloader.downloadFile(libUrl, {
|
|
584
|
+
path: import_node_path.default.join(self.internalPath, fPath),
|
|
585
|
+
hash: sums ? "sha256" : null
|
|
586
|
+
});
|
|
587
|
+
if (sums) {
|
|
588
|
+
testSum(sums, sum, fPath);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
dist_default = Dist;
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
// lib/processHelpers.js
|
|
598
|
+
var import_node_child_process, processHelpers, processHelpers_default;
|
|
599
|
+
var init_processHelpers = __esm({
|
|
600
|
+
"lib/processHelpers.js"() {
|
|
601
|
+
init_cjs_shims();
|
|
602
|
+
import_node_child_process = require("child_process");
|
|
603
|
+
processHelpers = {
|
|
604
|
+
run: function(command, options) {
|
|
605
|
+
if (!options) options = {};
|
|
606
|
+
return new Promise(function(resolve, reject) {
|
|
607
|
+
const env = Object.assign({}, process.env);
|
|
608
|
+
if (env.Path && env.PATH) {
|
|
609
|
+
if (env.Path !== env.PATH) {
|
|
610
|
+
env.PATH = env.Path + ";" + env.PATH;
|
|
611
|
+
}
|
|
612
|
+
delete env.Path;
|
|
613
|
+
}
|
|
614
|
+
const child = (0, import_node_child_process.spawn)(command[0], command.slice(1), {
|
|
615
|
+
stdio: options.silent ? "ignore" : "inherit",
|
|
616
|
+
env
|
|
617
|
+
});
|
|
618
|
+
let ended = false;
|
|
619
|
+
child.on("error", function(e) {
|
|
620
|
+
if (!ended) {
|
|
621
|
+
reject(e);
|
|
622
|
+
ended = true;
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
child.on("exit", function(code, signal) {
|
|
626
|
+
if (!ended) {
|
|
627
|
+
if (code === 0) {
|
|
628
|
+
resolve();
|
|
629
|
+
} else {
|
|
630
|
+
reject(new Error("Process terminated: " + code || signal));
|
|
631
|
+
}
|
|
632
|
+
ended = true;
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
});
|
|
636
|
+
},
|
|
637
|
+
execFile: function(command) {
|
|
638
|
+
return new Promise(function(resolve, reject) {
|
|
639
|
+
(0, import_node_child_process.execFile)(command[0], command.slice(1), function(err, stdout, stderr) {
|
|
640
|
+
if (err) {
|
|
641
|
+
reject(new Error(err.message + "\n" + (stdout || stderr)));
|
|
642
|
+
} else {
|
|
643
|
+
resolve(stdout);
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
processHelpers_default = processHelpers;
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
// lib/locateNAN.js
|
|
654
|
+
async function isNodeJSProject(dir) {
|
|
655
|
+
const pjson = import_node_path2.default.join(dir, "package.json");
|
|
656
|
+
const node_modules = import_node_path2.default.join(dir, "node_modules");
|
|
657
|
+
try {
|
|
658
|
+
let stat = await import_fs_extra2.default.stat(pjson);
|
|
659
|
+
if (stat.isFile()) {
|
|
660
|
+
return true;
|
|
661
|
+
}
|
|
662
|
+
stat = await import_fs_extra2.default.stat(node_modules);
|
|
663
|
+
if (stat.isDirectory()) {
|
|
664
|
+
return true;
|
|
665
|
+
}
|
|
666
|
+
} catch (e) {
|
|
667
|
+
}
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
670
|
+
async function locateNAN(projectRoot) {
|
|
671
|
+
if (locateNAN.__projectRoot) {
|
|
672
|
+
projectRoot = locateNAN.__projectRoot;
|
|
673
|
+
}
|
|
674
|
+
let result = await isNodeJSProject(projectRoot);
|
|
675
|
+
if (!result) {
|
|
676
|
+
return null;
|
|
677
|
+
}
|
|
678
|
+
const nanModulePath = import_node_path2.default.join(projectRoot, "node_modules", "nan");
|
|
679
|
+
result = await isNANModule(nanModulePath);
|
|
680
|
+
if (result) {
|
|
681
|
+
return nanModulePath;
|
|
682
|
+
}
|
|
683
|
+
return await locateNAN(goUp(projectRoot));
|
|
684
|
+
}
|
|
685
|
+
function goUp(dir) {
|
|
686
|
+
const items = dir.split(import_node_path2.default.sep);
|
|
687
|
+
const scopeItem = items[items.length - 2];
|
|
688
|
+
if (scopeItem && scopeItem[0] === "@") {
|
|
689
|
+
dir = import_node_path2.default.join(dir, "..");
|
|
690
|
+
}
|
|
691
|
+
dir = import_node_path2.default.join(dir, "..", "..");
|
|
692
|
+
return import_node_path2.default.normalize(dir);
|
|
693
|
+
}
|
|
694
|
+
var import_fs_extra2, import_node_path2, isNANModule, locateNAN_default;
|
|
695
|
+
var init_locateNAN = __esm({
|
|
696
|
+
"lib/locateNAN.js"() {
|
|
697
|
+
init_cjs_shims();
|
|
698
|
+
import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
699
|
+
import_node_path2 = __toESM(require("path"), 1);
|
|
700
|
+
isNANModule = async function(dir) {
|
|
701
|
+
const h = import_node_path2.default.join(dir, "nan.h");
|
|
702
|
+
try {
|
|
703
|
+
const stat = await import_fs_extra2.default.stat(h);
|
|
704
|
+
return stat.isFile();
|
|
705
|
+
} catch (e) {
|
|
706
|
+
return false;
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
locateNAN_default = locateNAN;
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
// lib/locateNodeApi.js
|
|
714
|
+
async function locateNodeApi(projectRoot) {
|
|
715
|
+
if (locateNodeApi.__projectRoot) {
|
|
716
|
+
projectRoot = locateNodeApi.__projectRoot;
|
|
717
|
+
}
|
|
718
|
+
try {
|
|
719
|
+
const tmpRequire = (0, import_node_module2.createRequire)(import_node_path3.default.join(projectRoot, "package.json"));
|
|
720
|
+
const inc = tmpRequire("node-addon-api");
|
|
721
|
+
return inc.include.replace(/"/g, "");
|
|
722
|
+
} catch (e) {
|
|
723
|
+
return null;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
var import_node_path3, import_node_module2, locateNodeApi_default;
|
|
727
|
+
var init_locateNodeApi = __esm({
|
|
728
|
+
"lib/locateNodeApi.js"() {
|
|
729
|
+
init_cjs_shims();
|
|
730
|
+
import_node_path3 = __toESM(require("path"), 1);
|
|
731
|
+
import_node_module2 = require("module");
|
|
732
|
+
locateNodeApi_default = locateNodeApi;
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
// lib/import/util.js
|
|
737
|
+
function logWithPrefix(log4, prefix) {
|
|
738
|
+
function setPrefix(logFunction) {
|
|
739
|
+
return (...args) => logFunction.apply(null, [prefix, ...args]);
|
|
740
|
+
}
|
|
741
|
+
return {
|
|
742
|
+
silly: setPrefix(log4.silly),
|
|
743
|
+
verbose: setPrefix(log4.verbose),
|
|
744
|
+
info: setPrefix(log4.info),
|
|
745
|
+
warn: setPrefix(log4.warn),
|
|
746
|
+
error: setPrefix(log4.error)
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
async function regGetValue(key, value, addOpts) {
|
|
750
|
+
const outReValue = value.replace(/\W/g, ".");
|
|
751
|
+
const outRe = new RegExp(`^\\s+${outReValue}\\s+REG_\\w+\\s+(\\S.*)$`, "im");
|
|
752
|
+
const reg = import_node_path4.default.join(process.env.SystemRoot, "System32", "reg.exe");
|
|
753
|
+
const regArgs = ["query", key, "/v", value].concat(addOpts);
|
|
754
|
+
import_npmlog2.default.silly("reg", "running", reg, regArgs);
|
|
755
|
+
const [err, stdout, stderr] = await execFile(reg, regArgs, { encoding: "utf8" });
|
|
756
|
+
import_npmlog2.default.silly("reg", "reg.exe stdout = %j", stdout);
|
|
757
|
+
if (err || stderr.trim() !== "") {
|
|
758
|
+
import_npmlog2.default.silly("reg", "reg.exe err = %j", err && (err.stack || err));
|
|
759
|
+
import_npmlog2.default.silly("reg", "reg.exe stderr = %j", stderr);
|
|
760
|
+
if (err) {
|
|
761
|
+
throw err;
|
|
762
|
+
}
|
|
763
|
+
throw new Error(stderr);
|
|
764
|
+
}
|
|
765
|
+
const result = outRe.exec(stdout);
|
|
766
|
+
if (!result) {
|
|
767
|
+
import_npmlog2.default.silly("reg", "error parsing stdout");
|
|
768
|
+
throw new Error("Could not parse output of reg.exe");
|
|
769
|
+
}
|
|
770
|
+
import_npmlog2.default.silly("reg", "found: %j", result[1]);
|
|
771
|
+
return result[1];
|
|
772
|
+
}
|
|
773
|
+
async function regSearchKeys(keys, value, addOpts) {
|
|
774
|
+
for (const key of keys) {
|
|
775
|
+
try {
|
|
776
|
+
return await regGetValue(key, value, addOpts);
|
|
777
|
+
} catch {
|
|
778
|
+
continue;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
var import_npmlog2, import_node_child_process2, import_node_path4, execFile;
|
|
783
|
+
var init_util = __esm({
|
|
784
|
+
"lib/import/util.js"() {
|
|
785
|
+
init_cjs_shims();
|
|
786
|
+
import_npmlog2 = __toESM(require("npmlog"), 1);
|
|
787
|
+
import_node_child_process2 = __toESM(require("child_process"), 1);
|
|
788
|
+
import_node_path4 = __toESM(require("path"), 1);
|
|
789
|
+
execFile = async (...args) => new Promise((resolve) => {
|
|
790
|
+
const child = import_node_child_process2.default.execFile(...args, (...a) => resolve(a));
|
|
791
|
+
child.stdin.end();
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
// lib/import/find-visualstudio.js
|
|
797
|
+
var find_visualstudio_exports = {};
|
|
798
|
+
__export(find_visualstudio_exports, {
|
|
799
|
+
default: () => find_visualstudio_default,
|
|
800
|
+
findVisualStudio: () => findVisualStudio
|
|
801
|
+
});
|
|
802
|
+
var import_npmlog3, import_node_fs2, import_node_path5, import_node_path6, import_node_url, import_semver2, __dirname, VisualStudioFinder, find_visualstudio_default, findVisualStudio;
|
|
803
|
+
var init_find_visualstudio = __esm({
|
|
804
|
+
"lib/import/find-visualstudio.js"() {
|
|
805
|
+
init_cjs_shims();
|
|
806
|
+
import_npmlog3 = __toESM(require("npmlog"), 1);
|
|
807
|
+
import_node_fs2 = require("fs");
|
|
808
|
+
import_node_path5 = require("path");
|
|
809
|
+
import_node_path6 = require("path");
|
|
810
|
+
import_node_url = require("url");
|
|
811
|
+
init_util();
|
|
812
|
+
import_semver2 = __toESM(require("semver"), 1);
|
|
813
|
+
__dirname = (0, import_node_path6.dirname)((0, import_node_url.fileURLToPath)(importMetaUrl));
|
|
814
|
+
VisualStudioFinder = class _VisualStudioFinder {
|
|
815
|
+
static findVisualStudio = (...args) => new _VisualStudioFinder(...args).findVisualStudio();
|
|
816
|
+
log = logWithPrefix(import_npmlog3.default, "find VS");
|
|
817
|
+
regSearchKeys = regSearchKeys;
|
|
818
|
+
constructor(nodeSemver, configMsvsVersion) {
|
|
819
|
+
this.nodeSemver = nodeSemver;
|
|
820
|
+
this.configMsvsVersion = configMsvsVersion;
|
|
821
|
+
this.errorLog = [];
|
|
822
|
+
this.validVersions = [];
|
|
823
|
+
}
|
|
824
|
+
// Logs a message at verbose level, but also saves it to be displayed later
|
|
825
|
+
// at error level if an error occurs. This should help diagnose the problem.
|
|
826
|
+
addLog(message) {
|
|
827
|
+
this.log.verbose(message);
|
|
828
|
+
this.errorLog.push(message);
|
|
829
|
+
}
|
|
830
|
+
async findVisualStudio() {
|
|
831
|
+
this.configVersionYear = null;
|
|
832
|
+
this.configPath = null;
|
|
833
|
+
if (this.configMsvsVersion) {
|
|
834
|
+
this.addLog("msvs_version was set from command line or npm config");
|
|
835
|
+
if (this.configMsvsVersion.match(/^\d{4}$/)) {
|
|
836
|
+
this.configVersionYear = parseInt(this.configMsvsVersion, 10);
|
|
837
|
+
this.addLog(`- looking for Visual Studio version ${this.configVersionYear}`);
|
|
838
|
+
} else {
|
|
839
|
+
this.configPath = import_node_path5.win32.resolve(this.configMsvsVersion);
|
|
840
|
+
this.addLog(`- looking for Visual Studio installed in "${this.configPath}"`);
|
|
841
|
+
}
|
|
842
|
+
} else {
|
|
843
|
+
this.addLog("msvs_version not set from command line or npm config");
|
|
844
|
+
}
|
|
845
|
+
if (process.env.VCINSTALLDIR) {
|
|
846
|
+
this.envVcInstallDir = import_node_path5.win32.resolve(process.env.VCINSTALLDIR, "..");
|
|
847
|
+
this.addLog(
|
|
848
|
+
`running in VS Command Prompt, installation path is:
|
|
849
|
+
"${this.envVcInstallDir}"
|
|
850
|
+
- will only use this version`
|
|
851
|
+
);
|
|
852
|
+
} else {
|
|
853
|
+
this.addLog("VCINSTALLDIR not set, not running in VS Command Prompt");
|
|
854
|
+
}
|
|
855
|
+
const checks = [
|
|
856
|
+
() => this.findVisualStudio2017OrNewer(),
|
|
857
|
+
() => this.findVisualStudio2015(),
|
|
858
|
+
() => this.findVisualStudio2013()
|
|
859
|
+
];
|
|
860
|
+
for (const check of checks) {
|
|
861
|
+
const info = await check();
|
|
862
|
+
if (info) {
|
|
863
|
+
return this.succeed(info);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
return this.fail();
|
|
867
|
+
}
|
|
868
|
+
succeed(info) {
|
|
869
|
+
this.log.info(
|
|
870
|
+
`using VS${info.versionYear} (${info.version}) found at:
|
|
871
|
+
"${info.path}"
|
|
872
|
+
run with --verbose for detailed information`
|
|
873
|
+
);
|
|
874
|
+
return info;
|
|
875
|
+
}
|
|
876
|
+
fail() {
|
|
877
|
+
if (this.configMsvsVersion && this.envVcInstallDir) {
|
|
878
|
+
this.errorLog.push("msvs_version does not match this VS Command Prompt or the", "installation cannot be used.");
|
|
879
|
+
} else if (this.configMsvsVersion) {
|
|
880
|
+
this.errorLog.push("");
|
|
881
|
+
if (this.validVersions) {
|
|
882
|
+
this.errorLog.push("valid versions for msvs_version:");
|
|
883
|
+
this.validVersions.forEach((version) => {
|
|
884
|
+
this.errorLog.push(`- "${version}"`);
|
|
885
|
+
});
|
|
886
|
+
} else {
|
|
887
|
+
this.errorLog.push("no valid versions for msvs_version were found");
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
const errorLog = this.errorLog.join("\n");
|
|
891
|
+
const infoLog = [
|
|
892
|
+
"**************************************************************",
|
|
893
|
+
"You need to install the latest version of Visual Studio",
|
|
894
|
+
'including the "Desktop development with C++" workload.',
|
|
895
|
+
"For more information consult the documentation at:",
|
|
896
|
+
"https://github.com/nodejs/node-gyp#on-windows",
|
|
897
|
+
"**************************************************************"
|
|
898
|
+
].join("\n");
|
|
899
|
+
this.log.error(`
|
|
900
|
+
${errorLog}
|
|
901
|
+
|
|
902
|
+
${infoLog}
|
|
903
|
+
`);
|
|
904
|
+
throw new Error("Could not find any Visual Studio installation to use");
|
|
905
|
+
}
|
|
906
|
+
// Invoke the PowerShell script to get information about Visual Studio 2017
|
|
907
|
+
// or newer installations
|
|
908
|
+
async findVisualStudio2017OrNewer() {
|
|
909
|
+
const ps = import_node_path5.win32.join(process.env.SystemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
910
|
+
const csFile = import_node_path5.win32.join(__dirname, "Find-VisualStudio.cs");
|
|
911
|
+
const psArgs = [
|
|
912
|
+
"-ExecutionPolicy",
|
|
913
|
+
"Unrestricted",
|
|
914
|
+
"-NoProfile",
|
|
915
|
+
"-Command",
|
|
916
|
+
"&{Add-Type -Path '" + csFile + "';[VisualStudioConfiguration.Main]::PrintJson()}"
|
|
917
|
+
];
|
|
918
|
+
this.log.silly("Running", ps, psArgs);
|
|
919
|
+
const [err, stdout, stderr] = await execFile(ps, psArgs, { encoding: "utf8" });
|
|
920
|
+
return this.parseData(err, stdout, stderr);
|
|
921
|
+
}
|
|
922
|
+
// Parse the output of the PowerShell script and look for an installation
|
|
923
|
+
// of Visual Studio 2017 or newer to use
|
|
924
|
+
parseData(err, stdout, stderr) {
|
|
925
|
+
this.log.silly("PS stderr = %j", stderr);
|
|
926
|
+
const failPowershell = () => {
|
|
927
|
+
this.addLog(
|
|
928
|
+
"could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details"
|
|
929
|
+
);
|
|
930
|
+
return null;
|
|
931
|
+
};
|
|
932
|
+
if (err) {
|
|
933
|
+
this.log.silly("PS err = %j", err && (err.stack || err));
|
|
934
|
+
return failPowershell();
|
|
935
|
+
}
|
|
936
|
+
let vsInfo;
|
|
937
|
+
try {
|
|
938
|
+
vsInfo = JSON.parse(stdout);
|
|
939
|
+
} catch (e) {
|
|
940
|
+
this.log.silly("PS stdout = %j", stdout);
|
|
941
|
+
this.log.silly(e);
|
|
942
|
+
return failPowershell();
|
|
943
|
+
}
|
|
944
|
+
if (!Array.isArray(vsInfo)) {
|
|
945
|
+
this.log.silly("PS stdout = %j", stdout);
|
|
946
|
+
return failPowershell();
|
|
947
|
+
}
|
|
948
|
+
vsInfo = vsInfo.map((info) => {
|
|
949
|
+
this.log.silly(`processing installation: "${info.path}"`);
|
|
950
|
+
info.path = import_node_path5.win32.resolve(info.path);
|
|
951
|
+
const ret = this.getVersionInfo(info);
|
|
952
|
+
ret.path = info.path;
|
|
953
|
+
ret.msBuild = this.getMSBuild(info, ret.versionYear);
|
|
954
|
+
ret.toolset = this.getToolset(info, ret.versionYear);
|
|
955
|
+
ret.sdk = this.getSDK(info);
|
|
956
|
+
return ret;
|
|
957
|
+
});
|
|
958
|
+
this.log.silly("vsInfo:", vsInfo);
|
|
959
|
+
vsInfo = vsInfo.filter((info) => {
|
|
960
|
+
if (info.versionYear) {
|
|
961
|
+
return true;
|
|
962
|
+
}
|
|
963
|
+
this.addLog(`unknown version "${info.version}" found at "${info.path}"`);
|
|
964
|
+
return false;
|
|
965
|
+
});
|
|
966
|
+
vsInfo.sort((a, b) => b.versionYear - a.versionYear);
|
|
967
|
+
for (let i = 0; i < vsInfo.length; ++i) {
|
|
968
|
+
const info = vsInfo[i];
|
|
969
|
+
this.addLog(`checking VS${info.versionYear} (${info.version}) found at:
|
|
970
|
+
"${info.path}"`);
|
|
971
|
+
if (info.msBuild) {
|
|
972
|
+
this.addLog('- found "Visual Studio C++ core features"');
|
|
973
|
+
} else {
|
|
974
|
+
this.addLog('- "Visual Studio C++ core features" missing');
|
|
975
|
+
continue;
|
|
976
|
+
}
|
|
977
|
+
if (info.toolset) {
|
|
978
|
+
this.addLog(`- found VC++ toolset: ${info.toolset}`);
|
|
979
|
+
} else {
|
|
980
|
+
this.addLog("- missing any VC++ toolset");
|
|
981
|
+
continue;
|
|
982
|
+
}
|
|
983
|
+
if (info.sdk) {
|
|
984
|
+
this.addLog(`- found Windows SDK: ${info.sdk}`);
|
|
985
|
+
} else {
|
|
986
|
+
this.addLog("- missing any Windows SDK");
|
|
987
|
+
continue;
|
|
988
|
+
}
|
|
989
|
+
if (!this.checkConfigVersion(info.versionYear, info.path)) {
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
return info;
|
|
993
|
+
}
|
|
994
|
+
this.addLog("could not find a version of Visual Studio 2017 or newer to use");
|
|
995
|
+
return null;
|
|
996
|
+
}
|
|
997
|
+
// Helper - process version information
|
|
998
|
+
getVersionInfo(info) {
|
|
999
|
+
const match = /^(\d+)\.(\d+)\..*/.exec(info.version);
|
|
1000
|
+
if (!match) {
|
|
1001
|
+
this.log.silly("- failed to parse version:", info.version);
|
|
1002
|
+
return {};
|
|
1003
|
+
}
|
|
1004
|
+
this.log.silly("- version match = %j", match);
|
|
1005
|
+
const ret = {
|
|
1006
|
+
version: info.version,
|
|
1007
|
+
versionMajor: parseInt(match[1], 10),
|
|
1008
|
+
versionMinor: parseInt(match[2], 10)
|
|
1009
|
+
};
|
|
1010
|
+
if (ret.versionMajor === 15) {
|
|
1011
|
+
ret.versionYear = 2017;
|
|
1012
|
+
return ret;
|
|
1013
|
+
}
|
|
1014
|
+
if (ret.versionMajor === 16) {
|
|
1015
|
+
ret.versionYear = 2019;
|
|
1016
|
+
return ret;
|
|
1017
|
+
}
|
|
1018
|
+
if (ret.versionMajor === 17) {
|
|
1019
|
+
ret.versionYear = 2022;
|
|
1020
|
+
return ret;
|
|
1021
|
+
}
|
|
1022
|
+
this.log.silly("- unsupported version:", ret.versionMajor);
|
|
1023
|
+
return {};
|
|
1024
|
+
}
|
|
1025
|
+
msBuildPathExists(path9) {
|
|
1026
|
+
return (0, import_node_fs2.existsSync)(path9);
|
|
1027
|
+
}
|
|
1028
|
+
// Helper - process MSBuild information
|
|
1029
|
+
getMSBuild(info, versionYear) {
|
|
1030
|
+
const pkg = "Microsoft.VisualStudio.VC.MSBuild.Base";
|
|
1031
|
+
const msbuildPath = import_node_path5.win32.join(info.path, "MSBuild", "Current", "Bin", "MSBuild.exe");
|
|
1032
|
+
const msbuildPathArm64 = import_node_path5.win32.join(info.path, "MSBuild", "Current", "Bin", "arm64", "MSBuild.exe");
|
|
1033
|
+
if (info.packages.indexOf(pkg) !== -1) {
|
|
1034
|
+
this.log.silly("- found VC.MSBuild.Base");
|
|
1035
|
+
if (versionYear === 2017) {
|
|
1036
|
+
return import_node_path5.win32.join(info.path, "MSBuild", "15.0", "Bin", "MSBuild.exe");
|
|
1037
|
+
}
|
|
1038
|
+
if (versionYear === 2019) {
|
|
1039
|
+
return msbuildPath;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
if (process.arch === "arm64" && this.msBuildPathExists(msbuildPathArm64)) {
|
|
1043
|
+
return msbuildPathArm64;
|
|
1044
|
+
} else if (this.msBuildPathExists(msbuildPath)) {
|
|
1045
|
+
return msbuildPath;
|
|
1046
|
+
}
|
|
1047
|
+
return null;
|
|
1048
|
+
}
|
|
1049
|
+
// Helper - process toolset information
|
|
1050
|
+
getToolset(info, versionYear) {
|
|
1051
|
+
const pkg = "Microsoft.VisualStudio.Component.VC.Tools.x86.x64";
|
|
1052
|
+
const express = "Microsoft.VisualStudio.WDExpress";
|
|
1053
|
+
if (info.packages.indexOf(pkg) !== -1) {
|
|
1054
|
+
this.log.silly("- found VC.Tools.x86.x64");
|
|
1055
|
+
} else if (info.packages.indexOf(express) !== -1) {
|
|
1056
|
+
this.log.silly("- found Visual Studio Express (looking for toolset)");
|
|
1057
|
+
} else {
|
|
1058
|
+
return null;
|
|
1059
|
+
}
|
|
1060
|
+
if (versionYear === 2017) {
|
|
1061
|
+
return "v141";
|
|
1062
|
+
} else if (versionYear === 2019) {
|
|
1063
|
+
return "v142";
|
|
1064
|
+
} else if (versionYear === 2022) {
|
|
1065
|
+
return "v143";
|
|
1066
|
+
}
|
|
1067
|
+
this.log.silly("- invalid versionYear:", versionYear);
|
|
1068
|
+
return null;
|
|
1069
|
+
}
|
|
1070
|
+
// Helper - process Windows SDK information
|
|
1071
|
+
getSDK(info) {
|
|
1072
|
+
const win8SDK = "Microsoft.VisualStudio.Component.Windows81SDK";
|
|
1073
|
+
const win10SDKPrefix = "Microsoft.VisualStudio.Component.Windows10SDK.";
|
|
1074
|
+
const win11SDKPrefix = "Microsoft.VisualStudio.Component.Windows11SDK.";
|
|
1075
|
+
let Win10or11SDKVer = 0;
|
|
1076
|
+
info.packages.forEach((pkg) => {
|
|
1077
|
+
if (!pkg.startsWith(win10SDKPrefix) && !pkg.startsWith(win11SDKPrefix)) {
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
const parts = pkg.split(".");
|
|
1081
|
+
if (parts.length > 5 && parts[5] !== "Desktop") {
|
|
1082
|
+
this.log.silly("- ignoring non-Desktop Win10/11SDK:", pkg);
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
const foundSdkVer = parseInt(parts[4], 10);
|
|
1086
|
+
if (isNaN(foundSdkVer)) {
|
|
1087
|
+
this.log.silly("- failed to parse Win10/11SDK number:", pkg);
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
this.log.silly("- found Win10/11SDK:", foundSdkVer);
|
|
1091
|
+
Win10or11SDKVer = Math.max(Win10or11SDKVer, foundSdkVer);
|
|
1092
|
+
});
|
|
1093
|
+
if (Win10or11SDKVer !== 0) {
|
|
1094
|
+
return `10.0.${Win10or11SDKVer}.0`;
|
|
1095
|
+
} else if (info.packages.indexOf(win8SDK) !== -1) {
|
|
1096
|
+
this.log.silly("- found Win8SDK");
|
|
1097
|
+
return "8.1";
|
|
1098
|
+
}
|
|
1099
|
+
return null;
|
|
1100
|
+
}
|
|
1101
|
+
// Find an installation of Visual Studio 2015 to use
|
|
1102
|
+
async findVisualStudio2015() {
|
|
1103
|
+
if (import_semver2.default.gte(this.nodeSemver, "19.0.0")) {
|
|
1104
|
+
this.addLog("not looking for VS2015 as it is only supported up to Node.js 18");
|
|
1105
|
+
return null;
|
|
1106
|
+
}
|
|
1107
|
+
return this.findOldVS({
|
|
1108
|
+
version: "14.0",
|
|
1109
|
+
versionMajor: 14,
|
|
1110
|
+
versionMinor: 0,
|
|
1111
|
+
versionYear: 2015,
|
|
1112
|
+
toolset: "v140"
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
// Find an installation of Visual Studio 2013 to use
|
|
1116
|
+
async findVisualStudio2013() {
|
|
1117
|
+
if (import_semver2.default.gte(this.nodeSemver, "9.0.0")) {
|
|
1118
|
+
this.addLog("not looking for VS2013 as it is only supported up to Node.js 8");
|
|
1119
|
+
return null;
|
|
1120
|
+
}
|
|
1121
|
+
return this.findOldVS({
|
|
1122
|
+
version: "12.0",
|
|
1123
|
+
versionMajor: 12,
|
|
1124
|
+
versionMinor: 0,
|
|
1125
|
+
versionYear: 2013,
|
|
1126
|
+
toolset: "v120"
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
// Helper - common code for VS2013 and VS2015
|
|
1130
|
+
async findOldVS(info) {
|
|
1131
|
+
const regVC7 = [
|
|
1132
|
+
"HKLM\\Software\\Microsoft\\VisualStudio\\SxS\\VC7",
|
|
1133
|
+
"HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VC7"
|
|
1134
|
+
];
|
|
1135
|
+
const regMSBuild = "HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions";
|
|
1136
|
+
this.addLog(`looking for Visual Studio ${info.versionYear}`);
|
|
1137
|
+
try {
|
|
1138
|
+
let res = await this.regSearchKeys(regVC7, info.version, []);
|
|
1139
|
+
const vsPath = import_node_path5.win32.resolve(res, "..");
|
|
1140
|
+
this.addLog(`- found in "${vsPath}"`);
|
|
1141
|
+
const msBuildRegOpts = process.arch === "ia32" ? [] : ["/reg:32"];
|
|
1142
|
+
try {
|
|
1143
|
+
res = await this.regSearchKeys([`${regMSBuild}\\${info.version}`], "MSBuildToolsPath", msBuildRegOpts);
|
|
1144
|
+
} catch (err) {
|
|
1145
|
+
this.addLog("- could not find MSBuild in registry for this version");
|
|
1146
|
+
return null;
|
|
1147
|
+
}
|
|
1148
|
+
const msBuild = import_node_path5.win32.join(res, "MSBuild.exe");
|
|
1149
|
+
this.addLog(`- MSBuild in "${msBuild}"`);
|
|
1150
|
+
if (!this.checkConfigVersion(info.versionYear, vsPath)) {
|
|
1151
|
+
return null;
|
|
1152
|
+
}
|
|
1153
|
+
info.path = vsPath;
|
|
1154
|
+
info.msBuild = msBuild;
|
|
1155
|
+
info.sdk = null;
|
|
1156
|
+
return info;
|
|
1157
|
+
} catch (err) {
|
|
1158
|
+
this.addLog("- not found");
|
|
1159
|
+
return null;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
// After finding a usable version of Visual Studio:
|
|
1163
|
+
// - add it to validVersions to be displayed at the end if a specific
|
|
1164
|
+
// version was requested and not found;
|
|
1165
|
+
// - check if this is the version that was requested.
|
|
1166
|
+
// - check if this matches the Visual Studio Command Prompt
|
|
1167
|
+
checkConfigVersion(versionYear, vsPath) {
|
|
1168
|
+
this.validVersions.push(versionYear);
|
|
1169
|
+
this.validVersions.push(vsPath);
|
|
1170
|
+
if (this.configVersionYear && this.configVersionYear !== versionYear) {
|
|
1171
|
+
this.addLog("- msvs_version does not match this version");
|
|
1172
|
+
return false;
|
|
1173
|
+
}
|
|
1174
|
+
if (this.configPath && import_node_path5.win32.relative(this.configPath, vsPath) !== "") {
|
|
1175
|
+
this.addLog("- msvs_version does not point to this installation");
|
|
1176
|
+
return false;
|
|
1177
|
+
}
|
|
1178
|
+
if (this.envVcInstallDir && import_node_path5.win32.relative(this.envVcInstallDir, vsPath) !== "") {
|
|
1179
|
+
this.addLog("- does not match this Visual Studio Command Prompt");
|
|
1180
|
+
return false;
|
|
1181
|
+
}
|
|
1182
|
+
return true;
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
find_visualstudio_default = VisualStudioFinder;
|
|
1186
|
+
findVisualStudio = VisualStudioFinder.findVisualStudio;
|
|
1187
|
+
}
|
|
1188
|
+
});
|
|
1189
|
+
|
|
1190
|
+
// lib/toolset.js
|
|
1191
|
+
async function getFindVisualStudio() {
|
|
1192
|
+
if (!_findVisualStudio && environment_default.isWin) {
|
|
1193
|
+
const vsModule = await Promise.resolve().then(() => (init_find_visualstudio(), find_visualstudio_exports));
|
|
1194
|
+
_findVisualStudio = vsModule.findVisualStudio;
|
|
1195
|
+
}
|
|
1196
|
+
return _findVisualStudio;
|
|
1197
|
+
}
|
|
1198
|
+
var import_node_assert2, _findVisualStudio, Toolset, toolset_default;
|
|
1199
|
+
var init_toolset = __esm({
|
|
1200
|
+
"lib/toolset.js"() {
|
|
1201
|
+
init_cjs_shims();
|
|
1202
|
+
init_targetOptions();
|
|
1203
|
+
init_environment();
|
|
1204
|
+
import_node_assert2 = __toESM(require("assert"), 1);
|
|
1205
|
+
init_cmLog();
|
|
1206
|
+
_findVisualStudio = null;
|
|
1207
|
+
Toolset = class {
|
|
1208
|
+
constructor(options) {
|
|
1209
|
+
this.options = options || {};
|
|
1210
|
+
this.targetOptions = new targetOptions_default(this.options);
|
|
1211
|
+
this.generator = options.generator;
|
|
1212
|
+
this.toolset = options.toolset;
|
|
1213
|
+
this.platform = options.platform;
|
|
1214
|
+
this.target = options.target;
|
|
1215
|
+
this.cCompilerPath = options.cCompilerPath;
|
|
1216
|
+
this.cppCompilerPath = options.cppCompilerPath;
|
|
1217
|
+
this.compilerFlags = [];
|
|
1218
|
+
this.linkerFlags = [];
|
|
1219
|
+
this.makePath = null;
|
|
1220
|
+
this.log = new cmLog_default(this.options);
|
|
1221
|
+
this._initialized = false;
|
|
1222
|
+
}
|
|
1223
|
+
async initialize(install) {
|
|
1224
|
+
if (!this._initialized) {
|
|
1225
|
+
if (environment_default.isWin) {
|
|
1226
|
+
await this.initializeWin(install);
|
|
1227
|
+
} else {
|
|
1228
|
+
this.initializePosix(install);
|
|
1229
|
+
}
|
|
1230
|
+
this._initialized = true;
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
initializePosix(install) {
|
|
1234
|
+
if (!this.cCompilerPath || !this.cppCompilerPath) {
|
|
1235
|
+
if (!environment_default.isGPPAvailable && !environment_default.isClangAvailable) {
|
|
1236
|
+
if (environment_default.isOSX) {
|
|
1237
|
+
throw new Error(
|
|
1238
|
+
"C++ Compiler toolset is not available. Install Xcode Commandline Tools from Apple Dev Center, or install Clang with homebrew by invoking: 'brew install llvm --with-clang --with-asan'."
|
|
1239
|
+
);
|
|
1240
|
+
} else {
|
|
1241
|
+
throw new Error(
|
|
1242
|
+
"C++ Compiler toolset is not available. Install proper compiler toolset with your package manager, eg. 'sudo apt-get install g++'."
|
|
1243
|
+
);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
if (this.options.preferClang && environment_default.isClangAvailable) {
|
|
1247
|
+
if (install) {
|
|
1248
|
+
this.log.info("TOOL", "Using clang++ compiler, because preferClang option is set, and clang++ is available.");
|
|
1249
|
+
}
|
|
1250
|
+
this.cppCompilerPath = this.cppCompilerPath || "clang++";
|
|
1251
|
+
this.cCompilerPath = this.cCompilerPath || "clang";
|
|
1252
|
+
} else if (this.options.preferGnu && environment_default.isGPPAvailable) {
|
|
1253
|
+
if (install) {
|
|
1254
|
+
this.log.info("TOOL", "Using g++ compiler, because preferGnu option is set, and g++ is available.");
|
|
1255
|
+
}
|
|
1256
|
+
this.cppCompilerPath = this.cppCompilerPath || "g++";
|
|
1257
|
+
this.cCompilerPath = this.cCompilerPath || "gcc";
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
if (this.generator) {
|
|
1261
|
+
if (install) {
|
|
1262
|
+
this.log.info("TOOL", "Using " + this.generator + " generator, as specified from commandline.");
|
|
1263
|
+
}
|
|
1264
|
+
} else if (environment_default.isOSX) {
|
|
1265
|
+
if (this.options.preferXcode) {
|
|
1266
|
+
if (install) {
|
|
1267
|
+
this.log.info("TOOL", "Using Xcode generator, because preferXcode option is set.");
|
|
1268
|
+
}
|
|
1269
|
+
this.generator = "Xcode";
|
|
1270
|
+
} else if (this.options.preferMake && environment_default.isMakeAvailable) {
|
|
1271
|
+
if (install) {
|
|
1272
|
+
this.log.info(
|
|
1273
|
+
"TOOL",
|
|
1274
|
+
"Using Unix Makefiles generator, because preferMake option is set, and make is available."
|
|
1275
|
+
);
|
|
1276
|
+
}
|
|
1277
|
+
this.generator = "Unix Makefiles";
|
|
1278
|
+
} else if (environment_default.isNinjaAvailable) {
|
|
1279
|
+
if (install) {
|
|
1280
|
+
this.log.info("TOOL", "Using Ninja generator, because ninja is available.");
|
|
1281
|
+
}
|
|
1282
|
+
this.generator = "Ninja";
|
|
1283
|
+
} else {
|
|
1284
|
+
if (install) {
|
|
1285
|
+
this.log.info("TOOL", "Using Unix Makefiles generator.");
|
|
1286
|
+
}
|
|
1287
|
+
this.generator = "Unix Makefiles";
|
|
1288
|
+
}
|
|
1289
|
+
} else {
|
|
1290
|
+
if (this.options.preferMake && environment_default.isMakeAvailable) {
|
|
1291
|
+
if (install) {
|
|
1292
|
+
this.log.info(
|
|
1293
|
+
"TOOL",
|
|
1294
|
+
"Using Unix Makefiles generator, because preferMake option is set, and make is available."
|
|
1295
|
+
);
|
|
1296
|
+
}
|
|
1297
|
+
this.generator = "Unix Makefiles";
|
|
1298
|
+
} else if (environment_default.isNinjaAvailable) {
|
|
1299
|
+
if (install) {
|
|
1300
|
+
this.log.info("TOOL", "Using Ninja generator, because ninja is available.");
|
|
1301
|
+
}
|
|
1302
|
+
this.generator = "Ninja";
|
|
1303
|
+
} else {
|
|
1304
|
+
if (install) {
|
|
1305
|
+
this.log.info("TOOL", "Using Unix Makefiles generator.");
|
|
1306
|
+
}
|
|
1307
|
+
this.generator = "Unix Makefiles";
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
if (environment_default.isOSX) {
|
|
1311
|
+
if (install) {
|
|
1312
|
+
this.log.verbose("TOOL", "Setting default OSX compiler flags.");
|
|
1313
|
+
}
|
|
1314
|
+
this.compilerFlags.push("-D_DARWIN_USE_64_BIT_INODE=1");
|
|
1315
|
+
this.compilerFlags.push("-D_LARGEFILE_SOURCE");
|
|
1316
|
+
this.compilerFlags.push("-D_FILE_OFFSET_BITS=64");
|
|
1317
|
+
this.linkerFlags.push("-undefined dynamic_lookup");
|
|
1318
|
+
}
|
|
1319
|
+
this.compilerFlags.push("-DBUILDING_NODE_EXTENSION");
|
|
1320
|
+
if (this.options.target) {
|
|
1321
|
+
this.log.info("TOOL", "Building only the " + this.options.target + " target, as specified from the command line.");
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
async initializeWin(install) {
|
|
1325
|
+
if (!this.generator) {
|
|
1326
|
+
const foundVsInfo = await this._getTopSupportedVisualStudioGenerator();
|
|
1327
|
+
if (foundVsInfo) {
|
|
1328
|
+
if (install) {
|
|
1329
|
+
this.log.info("TOOL", `Using ${foundVsInfo.generator} generator.`);
|
|
1330
|
+
}
|
|
1331
|
+
this.generator = foundVsInfo.generator;
|
|
1332
|
+
const isAboveVS16 = foundVsInfo.versionMajor >= 16;
|
|
1333
|
+
if (!this.platform && isAboveVS16) {
|
|
1334
|
+
switch (this.targetOptions.arch) {
|
|
1335
|
+
case "ia32":
|
|
1336
|
+
case "x86":
|
|
1337
|
+
this.platform = "Win32";
|
|
1338
|
+
break;
|
|
1339
|
+
case "x64":
|
|
1340
|
+
this.platform = "x64";
|
|
1341
|
+
break;
|
|
1342
|
+
case "arm":
|
|
1343
|
+
this.platform = "ARM";
|
|
1344
|
+
break;
|
|
1345
|
+
case "arm64":
|
|
1346
|
+
this.platform = "ARM64";
|
|
1347
|
+
break;
|
|
1348
|
+
default:
|
|
1349
|
+
this.log.warn("TOOL", "Unknown NodeJS architecture: " + this.targetOptions.arch);
|
|
1350
|
+
break;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
} else {
|
|
1354
|
+
throw new Error("There is no Visual C++ compiler installed. Install Visual C++ Build Toolset or Visual Studio.");
|
|
1355
|
+
}
|
|
1356
|
+
} else {
|
|
1357
|
+
if (install) {
|
|
1358
|
+
this.log.info("TOOL", "Using " + this.options.generator + " generator, as specified from commandline.");
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
this.linkerFlags.push("/DELAYLOAD:NODE.EXE");
|
|
1362
|
+
if (this.targetOptions.isX86) {
|
|
1363
|
+
if (install) {
|
|
1364
|
+
this.log.verbose("TOOL", "Setting SAFESEH:NO linker flag.");
|
|
1365
|
+
}
|
|
1366
|
+
this.linkerFlags.push("/SAFESEH:NO");
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
async _getTopSupportedVisualStudioGenerator() {
|
|
1370
|
+
const { default: CMake2 } = await Promise.resolve().then(() => (init_cMake(), cMake_exports));
|
|
1371
|
+
(0, import_node_assert2.default)(environment_default.isWin);
|
|
1372
|
+
const findVisualStudio2 = await getFindVisualStudio();
|
|
1373
|
+
const selectedVs = await findVisualStudio2(environment_default.runtimeVersion, this.options.msvsVersion);
|
|
1374
|
+
if (!selectedVs) return null;
|
|
1375
|
+
const list = await CMake2.getGenerators(this.options, this.log);
|
|
1376
|
+
for (const gen of list) {
|
|
1377
|
+
const found = gen.startsWith(`Visual Studio ${selectedVs.versionMajor}`);
|
|
1378
|
+
if (!found) {
|
|
1379
|
+
continue;
|
|
1380
|
+
}
|
|
1381
|
+
const isAboveVS16 = selectedVs.versionMajor >= 16;
|
|
1382
|
+
if (!isAboveVS16) {
|
|
1383
|
+
const is64Bit = gen.endsWith("Win64");
|
|
1384
|
+
if (this.targetOptions.isX86 && is64Bit || this.targetOptions.isX64 && !is64Bit) {
|
|
1385
|
+
continue;
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
return {
|
|
1389
|
+
...selectedVs,
|
|
1390
|
+
generator: gen
|
|
1391
|
+
};
|
|
1392
|
+
}
|
|
1393
|
+
return null;
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
toolset_default = Toolset;
|
|
1397
|
+
}
|
|
1398
|
+
});
|
|
1399
|
+
|
|
1400
|
+
// lib/cMake.js
|
|
1401
|
+
var cMake_exports = {};
|
|
1402
|
+
__export(cMake_exports, {
|
|
1403
|
+
default: () => cMake_default
|
|
1404
|
+
});
|
|
1405
|
+
var import_which2, import_fs_extra3, import_node_path7, import_node_path8, import_node_url2, import_rc, import_node_api_headers, __dirname2, npmConfigData, CMake, cMake_default;
|
|
1406
|
+
var init_cMake = __esm({
|
|
1407
|
+
"lib/cMake.js"() {
|
|
1408
|
+
init_cjs_shims();
|
|
1409
|
+
import_which2 = __toESM(require("which"), 1);
|
|
1410
|
+
import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
1411
|
+
import_node_path7 = __toESM(require("path"), 1);
|
|
1412
|
+
import_node_path8 = require("path");
|
|
1413
|
+
import_node_url2 = require("url");
|
|
1414
|
+
init_environment();
|
|
1415
|
+
init_dist();
|
|
1416
|
+
init_cmLog();
|
|
1417
|
+
init_targetOptions();
|
|
1418
|
+
init_processHelpers();
|
|
1419
|
+
init_locateNAN();
|
|
1420
|
+
init_locateNodeApi();
|
|
1421
|
+
import_rc = __toESM(require("rc"), 1);
|
|
1422
|
+
init_toolset();
|
|
1423
|
+
import_node_api_headers = __toESM(require("node-api-headers"), 1);
|
|
1424
|
+
__dirname2 = (0, import_node_path8.dirname)((0, import_node_url2.fileURLToPath)(importMetaUrl));
|
|
1425
|
+
npmConfigData = (0, import_rc.default)("npm");
|
|
1426
|
+
CMake = class _CMake {
|
|
1427
|
+
get path() {
|
|
1428
|
+
return this.options.cmakePath || "cmake";
|
|
1429
|
+
}
|
|
1430
|
+
get isAvailable() {
|
|
1431
|
+
if (this._isAvailable === null) {
|
|
1432
|
+
this._isAvailable = _CMake.isAvailable(this.options);
|
|
1433
|
+
}
|
|
1434
|
+
return this._isAvailable;
|
|
1435
|
+
}
|
|
1436
|
+
constructor(options) {
|
|
1437
|
+
this.options = options || {};
|
|
1438
|
+
this.log = new cmLog_default(this.options);
|
|
1439
|
+
this.dist = new dist_default(this.options);
|
|
1440
|
+
this.projectRoot = import_node_path7.default.resolve(this.options.directory || process.cwd());
|
|
1441
|
+
this.workDir = import_node_path7.default.resolve(this.options.out || import_node_path7.default.join(this.projectRoot, "build"));
|
|
1442
|
+
this.config = this.options.config || (this.options.debug ? "Debug" : "Release");
|
|
1443
|
+
this.buildDir = import_node_path7.default.join(this.workDir, this.config);
|
|
1444
|
+
this._isAvailable = null;
|
|
1445
|
+
this.targetOptions = new targetOptions_default(this.options);
|
|
1446
|
+
this.toolset = new toolset_default(this.options);
|
|
1447
|
+
this.cMakeOptions = this.options.cMakeOptions || {};
|
|
1448
|
+
this.extraCMakeArgs = this.options.extraCMakeArgs || [];
|
|
1449
|
+
this.silent = !!options.silent;
|
|
1450
|
+
}
|
|
1451
|
+
static isAvailable(options) {
|
|
1452
|
+
options = options || {};
|
|
1453
|
+
try {
|
|
1454
|
+
if (options.cmakePath) {
|
|
1455
|
+
const stat = import_fs_extra3.default.lstatSync(options.cmakePath);
|
|
1456
|
+
return !stat.isDirectory();
|
|
1457
|
+
} else {
|
|
1458
|
+
import_which2.default.sync("cmake");
|
|
1459
|
+
return true;
|
|
1460
|
+
}
|
|
1461
|
+
} catch (e) {
|
|
1462
|
+
}
|
|
1463
|
+
return false;
|
|
1464
|
+
}
|
|
1465
|
+
static async getGenerators(options, log4) {
|
|
1466
|
+
const arch = " [arch]";
|
|
1467
|
+
options = options || {};
|
|
1468
|
+
const gens = [];
|
|
1469
|
+
if (_CMake.isAvailable(options)) {
|
|
1470
|
+
try {
|
|
1471
|
+
const stdout2 = await processHelpers_default.execFile([options.cmakePath || "cmake", "-E", "capabilities"]);
|
|
1472
|
+
const capabilities = JSON.parse(stdout2);
|
|
1473
|
+
return capabilities.generators.map((x) => x.name);
|
|
1474
|
+
} catch (error) {
|
|
1475
|
+
if (log4) {
|
|
1476
|
+
log4.verbose("TOOL", "Failed to query CMake capabilities (CMake is probably older than 3.7)");
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
const stdout = await processHelpers_default.execFile([options.cmakePath || "cmake", "--help"]);
|
|
1480
|
+
const hasCr = stdout.includes("\r\n");
|
|
1481
|
+
const output = hasCr ? stdout.split("\r\n") : stdout.split("\n");
|
|
1482
|
+
let on = false;
|
|
1483
|
+
output.forEach(function(line, i) {
|
|
1484
|
+
if (on) {
|
|
1485
|
+
const parts = line.split("=");
|
|
1486
|
+
if (parts.length === 2 && parts[0].trim() || parts.length === 1 && i !== output.length - 1 && output[i + 1].trim()[0] === "=") {
|
|
1487
|
+
let gen = parts[0].trim();
|
|
1488
|
+
if (gen.endsWith(arch)) {
|
|
1489
|
+
gen = gen.substr(0, gen.length - arch.length);
|
|
1490
|
+
}
|
|
1491
|
+
gens.push(gen);
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
if (line.trim() === "Generators") {
|
|
1495
|
+
on = true;
|
|
1496
|
+
}
|
|
1497
|
+
});
|
|
1498
|
+
} else {
|
|
1499
|
+
throw new Error("CMake is not installed. Install CMake.");
|
|
1500
|
+
}
|
|
1501
|
+
return gens;
|
|
1502
|
+
}
|
|
1503
|
+
verifyIfAvailable() {
|
|
1504
|
+
if (!this.isAvailable) {
|
|
1505
|
+
throw new Error(
|
|
1506
|
+
"CMake executable is not found. Please use your system's package manager to install it, or you can get installers from there: http://cmake.org."
|
|
1507
|
+
);
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
async getConfigureCommand() {
|
|
1511
|
+
let command = [this.path, this.projectRoot, "--no-warn-unused-cli"];
|
|
1512
|
+
const D = [];
|
|
1513
|
+
D.push({ CMAKE_JS_VERSION: environment_default.cmakeJsVersion });
|
|
1514
|
+
D.push({ CMAKE_BUILD_TYPE: this.config });
|
|
1515
|
+
if (environment_default.isWin) {
|
|
1516
|
+
D.push({ CMAKE_RUNTIME_OUTPUT_DIRECTORY: this.workDir });
|
|
1517
|
+
} else if (this.workDir.endsWith(this.config)) {
|
|
1518
|
+
D.push({ CMAKE_LIBRARY_OUTPUT_DIRECTORY: this.workDir });
|
|
1519
|
+
} else {
|
|
1520
|
+
D.push({ CMAKE_LIBRARY_OUTPUT_DIRECTORY: this.buildDir });
|
|
1521
|
+
}
|
|
1522
|
+
D.push({ CMAKE_MSVC_RUNTIME_LIBRARY: "MultiThreaded$<$<CONFIG:Debug>:Debug>" });
|
|
1523
|
+
const includesString = await this.getCmakeJsIncludeString();
|
|
1524
|
+
D.push({ CMAKE_JS_INC: includesString });
|
|
1525
|
+
const srcsString = this.getCmakeJsSrcString();
|
|
1526
|
+
D.push({ CMAKE_JS_SRC: srcsString });
|
|
1527
|
+
D.push({ NODE_RUNTIME: this.targetOptions.runtime });
|
|
1528
|
+
D.push({ NODE_RUNTIMEVERSION: this.targetOptions.runtimeVersion });
|
|
1529
|
+
D.push({ NODE_ARCH: this.targetOptions.arch });
|
|
1530
|
+
if (environment_default.isOSX) {
|
|
1531
|
+
if (this.targetOptions.arch) {
|
|
1532
|
+
let xcodeArch = this.targetOptions.arch;
|
|
1533
|
+
if (xcodeArch === "x64") xcodeArch = "x86_64";
|
|
1534
|
+
D.push({ CMAKE_OSX_ARCHITECTURES: xcodeArch });
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
for (const [key, value] of Object.entries(this.cMakeOptions)) {
|
|
1538
|
+
D.push({ [key]: value });
|
|
1539
|
+
}
|
|
1540
|
+
await this.toolset.initialize(false);
|
|
1541
|
+
const libsString = this.getCmakeJsLibString();
|
|
1542
|
+
D.push({ CMAKE_JS_LIB: libsString });
|
|
1543
|
+
if (environment_default.isWin) {
|
|
1544
|
+
const nodeLibDefPath = this.getNodeLibDefPath();
|
|
1545
|
+
if (nodeLibDefPath) {
|
|
1546
|
+
const nodeLibPath = import_node_path7.default.join(this.workDir, "node.lib");
|
|
1547
|
+
D.push({ CMAKE_JS_NODELIB_DEF: nodeLibDefPath });
|
|
1548
|
+
D.push({ CMAKE_JS_NODELIB_TARGET: nodeLibPath });
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
if (this.toolset.generator) {
|
|
1552
|
+
command.push("-G", this.toolset.generator);
|
|
1553
|
+
}
|
|
1554
|
+
if (this.toolset.platform) {
|
|
1555
|
+
command.push("-A", this.toolset.platform);
|
|
1556
|
+
}
|
|
1557
|
+
if (this.toolset.toolset) {
|
|
1558
|
+
command.push("-T", this.toolset.toolset);
|
|
1559
|
+
}
|
|
1560
|
+
if (this.toolset.cppCompilerPath) {
|
|
1561
|
+
D.push({ CMAKE_CXX_COMPILER: this.toolset.cppCompilerPath });
|
|
1562
|
+
}
|
|
1563
|
+
if (this.toolset.cCompilerPath) {
|
|
1564
|
+
D.push({ CMAKE_C_COMPILER: this.toolset.cCompilerPath });
|
|
1565
|
+
}
|
|
1566
|
+
if (this.toolset.compilerFlags.length) {
|
|
1567
|
+
D.push({ CMAKE_CXX_FLAGS: this.toolset.compilerFlags.join(" ") });
|
|
1568
|
+
}
|
|
1569
|
+
if (this.toolset.linkerFlags.length) {
|
|
1570
|
+
D.push({ CMAKE_SHARED_LINKER_FLAGS: this.toolset.linkerFlags.join(" ") });
|
|
1571
|
+
}
|
|
1572
|
+
if (this.toolset.makePath) {
|
|
1573
|
+
D.push({ CMAKE_MAKE_PROGRAM: this.toolset.makePath });
|
|
1574
|
+
}
|
|
1575
|
+
for (const [key, value] of Object.entries(npmConfigData)) {
|
|
1576
|
+
if (key.startsWith("cmake_")) {
|
|
1577
|
+
const sk = key.substr(6);
|
|
1578
|
+
if (sk && value) {
|
|
1579
|
+
D.push({ [sk]: value });
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
command = command.concat(
|
|
1584
|
+
D.map(function(p) {
|
|
1585
|
+
return "-D" + Object.keys(p)[0] + "=" + Object.values(p)[0];
|
|
1586
|
+
})
|
|
1587
|
+
);
|
|
1588
|
+
return command.concat(this.extraCMakeArgs);
|
|
1589
|
+
}
|
|
1590
|
+
getCmakeJsLibString() {
|
|
1591
|
+
const libs = [];
|
|
1592
|
+
if (environment_default.isWin) {
|
|
1593
|
+
const nodeLibDefPath = this.getNodeLibDefPath();
|
|
1594
|
+
if (nodeLibDefPath) {
|
|
1595
|
+
libs.push(import_node_path7.default.join(this.workDir, "node.lib"));
|
|
1596
|
+
} else {
|
|
1597
|
+
libs.push(...this.dist.winLibs);
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
return libs.join(";");
|
|
1601
|
+
}
|
|
1602
|
+
async getCmakeJsIncludeString() {
|
|
1603
|
+
let incPaths = [];
|
|
1604
|
+
if (!this.options.isNodeApi) {
|
|
1605
|
+
if (this.dist.headerOnly) {
|
|
1606
|
+
incPaths = [import_node_path7.default.join(this.dist.internalPath, "/include/node")];
|
|
1607
|
+
} else {
|
|
1608
|
+
const nodeH = import_node_path7.default.join(this.dist.internalPath, "/src");
|
|
1609
|
+
const v8H = import_node_path7.default.join(this.dist.internalPath, "/deps/v8/include");
|
|
1610
|
+
const uvH = import_node_path7.default.join(this.dist.internalPath, "/deps/uv/include");
|
|
1611
|
+
incPaths = [nodeH, v8H, uvH];
|
|
1612
|
+
}
|
|
1613
|
+
const nanH = await locateNAN_default(this.projectRoot);
|
|
1614
|
+
if (nanH) {
|
|
1615
|
+
incPaths.push(nanH);
|
|
1616
|
+
}
|
|
1617
|
+
} else {
|
|
1618
|
+
incPaths.push(import_node_api_headers.default.include_dir);
|
|
1619
|
+
const napiH = await locateNodeApi_default(this.projectRoot);
|
|
1620
|
+
if (napiH) {
|
|
1621
|
+
incPaths.push(napiH);
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
return incPaths.join(";");
|
|
1625
|
+
}
|
|
1626
|
+
getCmakeJsSrcString() {
|
|
1627
|
+
const srcPaths = [];
|
|
1628
|
+
if (environment_default.isWin) {
|
|
1629
|
+
const delayHook = import_node_path7.default.normalize(import_node_path7.default.join(__dirname2, "cpp", "win_delay_load_hook.cc"));
|
|
1630
|
+
srcPaths.push(delayHook.replace(/\\/gm, "/"));
|
|
1631
|
+
}
|
|
1632
|
+
return srcPaths.join(";");
|
|
1633
|
+
}
|
|
1634
|
+
getNodeLibDefPath() {
|
|
1635
|
+
return environment_default.isWin && this.options.isNodeApi ? import_node_api_headers.default.def_paths.node_api_def : void 0;
|
|
1636
|
+
}
|
|
1637
|
+
async configure() {
|
|
1638
|
+
this.verifyIfAvailable();
|
|
1639
|
+
this.log.info("CMD", "CONFIGURE");
|
|
1640
|
+
const listPath = import_node_path7.default.join(this.projectRoot, "CMakeLists.txt");
|
|
1641
|
+
const command = await this.getConfigureCommand();
|
|
1642
|
+
try {
|
|
1643
|
+
await import_fs_extra3.default.lstat(listPath);
|
|
1644
|
+
} catch (e) {
|
|
1645
|
+
throw new Error("'" + listPath + "' not found.");
|
|
1646
|
+
}
|
|
1647
|
+
try {
|
|
1648
|
+
await import_fs_extra3.default.ensureDir(this.workDir);
|
|
1649
|
+
} catch (e) {
|
|
1650
|
+
}
|
|
1651
|
+
const cwd = process.cwd();
|
|
1652
|
+
process.chdir(this.workDir);
|
|
1653
|
+
try {
|
|
1654
|
+
await this._run(command);
|
|
1655
|
+
} finally {
|
|
1656
|
+
process.chdir(cwd);
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
async ensureConfigured() {
|
|
1660
|
+
try {
|
|
1661
|
+
await import_fs_extra3.default.lstat(import_node_path7.default.join(this.workDir, "CMakeCache.txt"));
|
|
1662
|
+
} catch (e) {
|
|
1663
|
+
await this.configure();
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
getBuildCommand() {
|
|
1667
|
+
const command = [this.path, "--build", this.workDir, "--config", this.config];
|
|
1668
|
+
if (this.options.target) {
|
|
1669
|
+
command.push("--target", this.options.target);
|
|
1670
|
+
}
|
|
1671
|
+
if (this.options.parallel) {
|
|
1672
|
+
command.push("--parallel", this.options.parallel);
|
|
1673
|
+
}
|
|
1674
|
+
return Promise.resolve(command.concat(this.extraCMakeArgs));
|
|
1675
|
+
}
|
|
1676
|
+
async build() {
|
|
1677
|
+
this.verifyIfAvailable();
|
|
1678
|
+
await this.ensureConfigured();
|
|
1679
|
+
const buildCommand = await this.getBuildCommand();
|
|
1680
|
+
this.log.info("CMD", "BUILD");
|
|
1681
|
+
await this._run(buildCommand);
|
|
1682
|
+
}
|
|
1683
|
+
getCleanCommand() {
|
|
1684
|
+
return [this.path, "-E", "remove_directory", this.workDir].concat(this.extraCMakeArgs);
|
|
1685
|
+
}
|
|
1686
|
+
clean() {
|
|
1687
|
+
this.verifyIfAvailable();
|
|
1688
|
+
this.log.info("CMD", "CLEAN");
|
|
1689
|
+
return this._run(this.getCleanCommand());
|
|
1690
|
+
}
|
|
1691
|
+
async reconfigure() {
|
|
1692
|
+
this.extraCMakeArgs = [];
|
|
1693
|
+
await this.clean();
|
|
1694
|
+
await this.configure();
|
|
1695
|
+
}
|
|
1696
|
+
async rebuild() {
|
|
1697
|
+
this.extraCMakeArgs = [];
|
|
1698
|
+
await this.clean();
|
|
1699
|
+
await this.build();
|
|
1700
|
+
}
|
|
1701
|
+
async compile() {
|
|
1702
|
+
this.extraCMakeArgs = [];
|
|
1703
|
+
try {
|
|
1704
|
+
await this.build();
|
|
1705
|
+
} catch (e) {
|
|
1706
|
+
this.log.info("REP", "Build has been failed, trying to do a full rebuild.");
|
|
1707
|
+
await this.rebuild();
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
_run(command) {
|
|
1711
|
+
this.log.info("RUN", command);
|
|
1712
|
+
return processHelpers_default.run(command, { silent: this.silent });
|
|
1713
|
+
}
|
|
1714
|
+
async getGenerators() {
|
|
1715
|
+
return _CMake.getGenerators(this.options, this.log);
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
cMake_default = CMake;
|
|
1719
|
+
}
|
|
1720
|
+
});
|
|
1721
|
+
|
|
1722
|
+
// lib/index.js
|
|
1723
|
+
var index_exports = {};
|
|
1724
|
+
__export(index_exports, {
|
|
1725
|
+
BuildSystem: () => buildSystem_default,
|
|
1726
|
+
CMLog: () => cmLog_default,
|
|
1727
|
+
CMake: () => cMake_default,
|
|
1728
|
+
Dist: () => dist_default,
|
|
1729
|
+
Downloader: () => downloader_default,
|
|
1730
|
+
TargetOptions: () => targetOptions_default,
|
|
1731
|
+
Toolset: () => toolset_default,
|
|
1732
|
+
default: () => index_default,
|
|
1733
|
+
environment: () => environment_default
|
|
1734
|
+
});
|
|
1735
|
+
module.exports = __toCommonJS(index_exports);
|
|
1736
|
+
init_cjs_shims();
|
|
1737
|
+
|
|
1738
|
+
// lib/buildSystem.js
|
|
1739
|
+
init_cjs_shims();
|
|
1740
|
+
init_cMake();
|
|
1741
|
+
init_dist();
|
|
1742
|
+
init_cmLog();
|
|
1743
|
+
|
|
1744
|
+
// lib/appCMakeJSConfig.js
|
|
1745
|
+
init_cjs_shims();
|
|
1746
|
+
var import_node_path9 = __toESM(require("path"), 1);
|
|
1747
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
1748
|
+
function getConfig(lookPath, log4) {
|
|
1749
|
+
const pjsonPath = import_node_path9.default.join(lookPath, "package.json");
|
|
1750
|
+
log4.silly("CFG", "Looking for package.json in: '" + pjsonPath + "'.");
|
|
1751
|
+
try {
|
|
1752
|
+
const content = import_node_fs3.default.readFileSync(pjsonPath, "utf-8");
|
|
1753
|
+
const json = JSON.parse(content);
|
|
1754
|
+
log4.silly("CFG", "Loaded:\n" + JSON.stringify(json));
|
|
1755
|
+
if (json && json["cmake-js"] && typeof json["cmake-js"] === "object") {
|
|
1756
|
+
log4.silly("CFG", "Config found.");
|
|
1757
|
+
return json["cmake-js"];
|
|
1758
|
+
} else {
|
|
1759
|
+
log4.silly("CFG", "Config not found.");
|
|
1760
|
+
return null;
|
|
1761
|
+
}
|
|
1762
|
+
} catch (e) {
|
|
1763
|
+
log4.silly("CFG", "'package.json' not found.");
|
|
1764
|
+
return null;
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
function appCMakeJSConfig_default(projectPath, log4) {
|
|
1768
|
+
log4.verbose("CFG", "Looking for application level CMake.js config in '" + projectPath + ".");
|
|
1769
|
+
let currPath = projectPath;
|
|
1770
|
+
let lastConfig = null;
|
|
1771
|
+
let currConfig;
|
|
1772
|
+
for (; ; ) {
|
|
1773
|
+
currConfig = getConfig(currPath, log4);
|
|
1774
|
+
if (currConfig) {
|
|
1775
|
+
lastConfig = currConfig;
|
|
1776
|
+
}
|
|
1777
|
+
try {
|
|
1778
|
+
log4.silly("CFG", "Looking for parent path.");
|
|
1779
|
+
const lastPath = currPath;
|
|
1780
|
+
currPath = import_node_path9.default.normalize(import_node_path9.default.join(currPath, ".."));
|
|
1781
|
+
if (lastPath === currPath) {
|
|
1782
|
+
currPath = null;
|
|
1783
|
+
}
|
|
1784
|
+
if (currPath) {
|
|
1785
|
+
log4.silly("CFG", "Parent path: '" + currPath + "'.");
|
|
1786
|
+
}
|
|
1787
|
+
} catch (e) {
|
|
1788
|
+
log4.silly("CFG", "Exception:\n" + e.stack);
|
|
1789
|
+
break;
|
|
1790
|
+
}
|
|
1791
|
+
if (currPath === null) {
|
|
1792
|
+
log4.silly("CFG", "Parent path with package.json file doesn't exists. Done.");
|
|
1793
|
+
break;
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
if (lastConfig) {
|
|
1797
|
+
log4.verbose("CFG", "Application level CMake.js config found:\n" + JSON.stringify(lastConfig));
|
|
1798
|
+
} else {
|
|
1799
|
+
log4.verbose("CFG", "Application level CMake.js config doesn't exists.");
|
|
1800
|
+
}
|
|
1801
|
+
return lastConfig;
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
// lib/npmConfig.js
|
|
1805
|
+
init_cjs_shims();
|
|
1806
|
+
function getNpmConfig() {
|
|
1807
|
+
const npmOptions = {};
|
|
1808
|
+
const npmConfigPrefix = "npm_config_";
|
|
1809
|
+
Object.keys(process.env).forEach(function(name) {
|
|
1810
|
+
if (name.indexOf(npmConfigPrefix) !== 0) {
|
|
1811
|
+
return;
|
|
1812
|
+
}
|
|
1813
|
+
const value = process.env[name];
|
|
1814
|
+
name = name.substring(npmConfigPrefix.length);
|
|
1815
|
+
if (name) {
|
|
1816
|
+
npmOptions[name] = value;
|
|
1817
|
+
}
|
|
1818
|
+
}, this);
|
|
1819
|
+
return npmOptions;
|
|
1820
|
+
}
|
|
1821
|
+
function npmConfig_default(log4) {
|
|
1822
|
+
log4.verbose("CFG", "Looking for NPM config.");
|
|
1823
|
+
const options = getNpmConfig();
|
|
1824
|
+
if (options) {
|
|
1825
|
+
log4.silly("CFG", "NPM options:", options);
|
|
1826
|
+
} else {
|
|
1827
|
+
log4.verbose("CFG", "There are no NPM options available.");
|
|
1828
|
+
}
|
|
1829
|
+
return options;
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
// lib/buildSystem.js
|
|
1833
|
+
var import_node_path10 = __toESM(require("path"), 1);
|
|
1834
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
1835
|
+
init_toolset();
|
|
1836
|
+
function isNodeApi(log4, projectRoot) {
|
|
1837
|
+
try {
|
|
1838
|
+
const pjsonPath = import_node_path10.default.join(projectRoot, "package.json");
|
|
1839
|
+
const content = import_node_fs4.default.readFileSync(pjsonPath, "utf-8");
|
|
1840
|
+
const projectPkgJson = JSON.parse(content);
|
|
1841
|
+
return !!projectPkgJson?.binary?.napi_versions;
|
|
1842
|
+
} catch (e) {
|
|
1843
|
+
log4.silly("CFG", "'package.json' not found.");
|
|
1844
|
+
return false;
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
var BuildSystem = class {
|
|
1848
|
+
constructor(options) {
|
|
1849
|
+
this.options = options || {};
|
|
1850
|
+
this.options.directory = import_node_path10.default.resolve(this.options.directory || process.cwd());
|
|
1851
|
+
this.options.out = import_node_path10.default.resolve(this.options.out || import_node_path10.default.join(this.options.directory, "build"));
|
|
1852
|
+
this.log = new cmLog_default(this.options);
|
|
1853
|
+
this.options.isNodeApi = isNodeApi(this.log, this.options.directory);
|
|
1854
|
+
const appConfig = appCMakeJSConfig_default(this.options.directory, this.log);
|
|
1855
|
+
const npmOptions = npmConfig_default(this.log);
|
|
1856
|
+
if (npmOptions && typeof npmOptions === "object" && Object.keys(npmOptions).length) {
|
|
1857
|
+
this.options.runtimeDirectory = npmOptions["nodedir"];
|
|
1858
|
+
this.options.msvsVersion = npmOptions["msvs_version"];
|
|
1859
|
+
}
|
|
1860
|
+
if (appConfig && typeof appConfig === "object" && Object.keys(appConfig).length) {
|
|
1861
|
+
this.log.verbose("CFG", "Applying CMake.js config from root package.json:");
|
|
1862
|
+
this.log.verbose("CFG", JSON.stringify(appConfig));
|
|
1863
|
+
this.options.runtime = this.options.runtime || appConfig.runtime;
|
|
1864
|
+
this.options.runtimeVersion = this.options.runtimeVersion || appConfig.runtimeVersion;
|
|
1865
|
+
this.options.arch = this.options.arch || appConfig.arch;
|
|
1866
|
+
}
|
|
1867
|
+
this.log.verbose("CFG", "Build system options:");
|
|
1868
|
+
this.log.verbose("CFG", JSON.stringify(this.options));
|
|
1869
|
+
this.cmake = new cMake_default(this.options);
|
|
1870
|
+
this.dist = new dist_default(this.options);
|
|
1871
|
+
this.toolset = new toolset_default(this.options);
|
|
1872
|
+
}
|
|
1873
|
+
async _ensureInstalled() {
|
|
1874
|
+
try {
|
|
1875
|
+
await this.toolset.initialize(true);
|
|
1876
|
+
if (!this.options.isNodeApi) {
|
|
1877
|
+
await this.dist.ensureDownloaded();
|
|
1878
|
+
}
|
|
1879
|
+
} catch (e) {
|
|
1880
|
+
this._showError(e);
|
|
1881
|
+
throw e;
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
_showError(e) {
|
|
1885
|
+
if (this.log === void 0) {
|
|
1886
|
+
console.error("OMG", e.stack);
|
|
1887
|
+
return;
|
|
1888
|
+
}
|
|
1889
|
+
if (this.log.level === "verbose" || this.log.level === "silly") {
|
|
1890
|
+
this.log.error("OMG", e.stack);
|
|
1891
|
+
} else {
|
|
1892
|
+
this.log.error("OMG", e.message);
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
install() {
|
|
1896
|
+
return this._ensureInstalled();
|
|
1897
|
+
}
|
|
1898
|
+
async _invokeCMake(method) {
|
|
1899
|
+
try {
|
|
1900
|
+
await this._ensureInstalled();
|
|
1901
|
+
return await this.cmake[method]();
|
|
1902
|
+
} catch (e) {
|
|
1903
|
+
this._showError(e);
|
|
1904
|
+
throw e;
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
getConfigureCommand() {
|
|
1908
|
+
return this._invokeCMake("getConfigureCommand");
|
|
1909
|
+
}
|
|
1910
|
+
getCmakeJsLibString() {
|
|
1911
|
+
return this._invokeCMake("getCmakeJsLibString");
|
|
1912
|
+
}
|
|
1913
|
+
getCmakeJsIncludeString() {
|
|
1914
|
+
return this._invokeCMake("getCmakeJsIncludeString");
|
|
1915
|
+
}
|
|
1916
|
+
getCmakeJsSrcString() {
|
|
1917
|
+
return this._invokeCMake("getCmakeJsSrcString");
|
|
1918
|
+
}
|
|
1919
|
+
configure() {
|
|
1920
|
+
return this._invokeCMake("configure");
|
|
1921
|
+
}
|
|
1922
|
+
getBuildCommand() {
|
|
1923
|
+
return this._invokeCMake("getBuildCommand");
|
|
1924
|
+
}
|
|
1925
|
+
build() {
|
|
1926
|
+
return this._invokeCMake("build");
|
|
1927
|
+
}
|
|
1928
|
+
getCleanCommand() {
|
|
1929
|
+
return this._invokeCMake("getCleanCommand");
|
|
1930
|
+
}
|
|
1931
|
+
clean() {
|
|
1932
|
+
return this._invokeCMake("clean");
|
|
1933
|
+
}
|
|
1934
|
+
reconfigure() {
|
|
1935
|
+
return this._invokeCMake("reconfigure");
|
|
1936
|
+
}
|
|
1937
|
+
rebuild() {
|
|
1938
|
+
return this._invokeCMake("rebuild");
|
|
1939
|
+
}
|
|
1940
|
+
compile() {
|
|
1941
|
+
return this._invokeCMake("compile");
|
|
1942
|
+
}
|
|
1943
|
+
};
|
|
1944
|
+
var buildSystem_default = BuildSystem;
|
|
1945
|
+
|
|
1946
|
+
// lib/index.js
|
|
1947
|
+
init_cmLog();
|
|
1948
|
+
init_environment();
|
|
1949
|
+
init_targetOptions();
|
|
1950
|
+
init_dist();
|
|
1951
|
+
init_cMake();
|
|
1952
|
+
init_downloader();
|
|
1953
|
+
init_toolset();
|
|
1954
|
+
var index_default = {
|
|
1955
|
+
BuildSystem: buildSystem_default,
|
|
1956
|
+
CMLog: cmLog_default,
|
|
1957
|
+
environment: environment_default,
|
|
1958
|
+
TargetOptions: targetOptions_default,
|
|
1959
|
+
Dist: dist_default,
|
|
1960
|
+
CMake: cMake_default,
|
|
1961
|
+
downloader: downloader_default,
|
|
1962
|
+
Toolset: toolset_default
|
|
1963
|
+
};
|
|
1964
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1965
|
+
0 && (module.exports = {
|
|
1966
|
+
BuildSystem,
|
|
1967
|
+
CMLog,
|
|
1968
|
+
CMake,
|
|
1969
|
+
Dist,
|
|
1970
|
+
Downloader,
|
|
1971
|
+
TargetOptions,
|
|
1972
|
+
Toolset,
|
|
1973
|
+
environment
|
|
1974
|
+
});
|
|
1975
|
+
//# sourceMappingURL=index.cjs.map
|