@flun/nodejs-mobile-gyp 1.0.1

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.
Files changed (82) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE +29 -0
  3. package/README.md +252 -0
  4. package/addon.gypi +209 -0
  5. package/bin/node-gyp.js +144 -0
  6. package/gyp/LICENSE +28 -0
  7. package/gyp/README.md +30 -0
  8. package/gyp/data/win/large-pdb-shim.cc +12 -0
  9. package/gyp/gyp +8 -0
  10. package/gyp/gyp.bat +5 -0
  11. package/gyp/gyp_main.py +45 -0
  12. package/gyp/pylib/gyp/MSVSNew.py +365 -0
  13. package/gyp/pylib/gyp/MSVSProject.py +206 -0
  14. package/gyp/pylib/gyp/MSVSSettings.py +1270 -0
  15. package/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  16. package/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  17. package/gyp/pylib/gyp/MSVSUtil.py +271 -0
  18. package/gyp/pylib/gyp/MSVSVersion.py +574 -0
  19. package/gyp/pylib/gyp/__init__.py +692 -0
  20. package/gyp/pylib/gyp/common.py +654 -0
  21. package/gyp/pylib/gyp/easy_xml.py +169 -0
  22. package/gyp/pylib/gyp/flock_tool.py +55 -0
  23. package/gyp/pylib/gyp/generator/__init__.py +0 -0
  24. package/gyp/pylib/gyp/generator/analyzer.py +804 -0
  25. package/gyp/pylib/gyp/generator/android.py +1173 -0
  26. package/gyp/pylib/gyp/generator/cmake.py +1318 -0
  27. package/gyp/pylib/gyp/generator/compile_commands_json.py +123 -0
  28. package/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  29. package/gyp/pylib/gyp/generator/eclipse.py +461 -0
  30. package/gyp/pylib/gyp/generator/gypd.py +89 -0
  31. package/gyp/pylib/gyp/generator/gypsh.py +58 -0
  32. package/gyp/pylib/gyp/generator/make.py +2710 -0
  33. package/gyp/pylib/gyp/generator/msvs.py +3981 -0
  34. package/gyp/pylib/gyp/generator/ninja.py +2933 -0
  35. package/gyp/pylib/gyp/generator/xcode.py +1397 -0
  36. package/gyp/pylib/gyp/input.py +3115 -0
  37. package/gyp/pylib/gyp/mac_tool.py +771 -0
  38. package/gyp/pylib/gyp/msvs_emulation.py +1262 -0
  39. package/gyp/pylib/gyp/ninja_syntax.py +174 -0
  40. package/gyp/pylib/gyp/simple_copy.py +61 -0
  41. package/gyp/pylib/gyp/win_tool.py +373 -0
  42. package/gyp/pylib/gyp/xcode_emulation.py +1935 -0
  43. package/gyp/pylib/gyp/xcode_ninja.py +302 -0
  44. package/gyp/pylib/gyp/xcodeproj_file.py +3198 -0
  45. package/gyp/pylib/gyp/xml_fix.py +65 -0
  46. package/gyp/pylib/packaging/LICENSE +3 -0
  47. package/gyp/pylib/packaging/LICENSE.APACHE +177 -0
  48. package/gyp/pylib/packaging/LICENSE.BSD +23 -0
  49. package/gyp/pylib/packaging/__init__.py +15 -0
  50. package/gyp/pylib/packaging/_elffile.py +108 -0
  51. package/gyp/pylib/packaging/_manylinux.py +252 -0
  52. package/gyp/pylib/packaging/_musllinux.py +83 -0
  53. package/gyp/pylib/packaging/_parser.py +359 -0
  54. package/gyp/pylib/packaging/_structures.py +61 -0
  55. package/gyp/pylib/packaging/_tokenizer.py +192 -0
  56. package/gyp/pylib/packaging/markers.py +252 -0
  57. package/gyp/pylib/packaging/metadata.py +825 -0
  58. package/gyp/pylib/packaging/py.typed +0 -0
  59. package/gyp/pylib/packaging/requirements.py +90 -0
  60. package/gyp/pylib/packaging/specifiers.py +1030 -0
  61. package/gyp/pylib/packaging/tags.py +553 -0
  62. package/gyp/pylib/packaging/utils.py +172 -0
  63. package/gyp/pylib/packaging/version.py +563 -0
  64. package/lib/Find-VisualStudio.cs +250 -0
  65. package/lib/build.js +221 -0
  66. package/lib/clean.js +19 -0
  67. package/lib/configure.js +295 -0
  68. package/lib/create-config-gypi.js +163 -0
  69. package/lib/download.js +44 -0
  70. package/lib/find-node-directory.js +62 -0
  71. package/lib/find-python.js +303 -0
  72. package/lib/find-visualstudio.js +448 -0
  73. package/lib/install.js +419 -0
  74. package/lib/list.js +30 -0
  75. package/lib/log.js +174 -0
  76. package/lib/node-gyp.js +201 -0
  77. package/lib/process-release.js +144 -0
  78. package/lib/rebuild.js +14 -0
  79. package/lib/remove.js +47 -0
  80. package/lib/util.js +83 -0
  81. package/package.json +72 -0
  82. package/src/win_delay_load_hook.cc +39 -0
@@ -0,0 +1,448 @@
1
+ import * as log from './log.js'
2
+ import { existsSync } from 'fs'
3
+ import nodePath from 'path'
4
+ import { fileURLToPath } from 'url'
5
+ import { regSearchKeys, execFile } from './util.js'
6
+
7
+ const path = nodePath.win32
8
+ const __dirname = nodePath.dirname(fileURLToPath(import.meta.url))
9
+
10
+ /**
11
+ * Visual Studio 查找器:定位可用的 VS 安装
12
+ */
13
+ class VisualStudioFinder {
14
+ static findVisualStudio = (...args) => new VisualStudioFinder(...args).findVisualStudio()
15
+
16
+ log = log.withPrefix('find VS')
17
+
18
+ regSearchKeys = regSearchKeys
19
+
20
+ constructor (nodeSemver, configMsvsVersion) {
21
+ this.nodeSemver = nodeSemver
22
+ this.configMsvsVersion = configMsvsVersion
23
+ this.errorLog = []
24
+ this.validVersions = []
25
+ }
26
+
27
+ // 以 verbose 级别记录日志,同时保存下来,出错时以 error 级别展示,便于诊断
28
+ addLog (message) {
29
+ this.log.verbose(message)
30
+ this.errorLog.push(message)
31
+ }
32
+
33
+ async findVisualStudio () {
34
+ this.configVersionYear = null
35
+ this.configPath = null
36
+ if (this.configMsvsVersion) {
37
+ this.addLog('msvs_version was set from command line or npm config')
38
+ if (this.configMsvsVersion.match(/^\d{4}$/)) {
39
+ this.configVersionYear = parseInt(this.configMsvsVersion, 10)
40
+ this.addLog(
41
+ `- looking for Visual Studio version ${this.configVersionYear}`)
42
+ } else {
43
+ this.configPath = path.resolve(this.configMsvsVersion)
44
+ this.addLog(
45
+ `- looking for Visual Studio installed in "${this.configPath}"`)
46
+ }
47
+ } else {
48
+ this.addLog('msvs_version not set from command line or npm config')
49
+ }
50
+
51
+ if (process.env.VCINSTALLDIR) {
52
+ this.envVcInstallDir =
53
+ path.resolve(process.env.VCINSTALLDIR, '..')
54
+ this.addLog('running in VS Command Prompt, installation path is:\n' +
55
+ `"${this.envVcInstallDir}"\n- will only use this version`)
56
+ } else {
57
+ this.addLog('VCINSTALLDIR not set, not running in VS Command Prompt')
58
+ }
59
+
60
+ const checks = [
61
+ () => this.findVisualStudio2017OrNewer(),
62
+ () => this.findVisualStudio2015(),
63
+ () => this.findVisualStudio2013()
64
+ ]
65
+
66
+ for (const check of checks) {
67
+ const info = await check()
68
+ if (info) {
69
+ return this.succeed(info)
70
+ }
71
+ }
72
+
73
+ return this.fail()
74
+ }
75
+
76
+ succeed (info) {
77
+ this.log.info(`using VS${info.versionYear} (${info.version}) found at:` +
78
+ `\n"${info.path}"` +
79
+ '\nrun with --verbose for detailed information')
80
+ return info
81
+ }
82
+
83
+ fail () {
84
+ if (this.configMsvsVersion && this.envVcInstallDir) {
85
+ this.errorLog.push(
86
+ 'msvs_version does not match this VS Command Prompt or the',
87
+ 'installation cannot be used.')
88
+ } else if (this.configMsvsVersion) {
89
+ // 指定了 msvs_version 但没找到 VS,输出可接受的版本
90
+ this.errorLog.push('')
91
+ if (this.validVersions) {
92
+ this.errorLog.push('valid versions for msvs_version:')
93
+ this.validVersions.forEach((version) => {
94
+ this.errorLog.push(`- "${version}"`)
95
+ })
96
+ } else {
97
+ this.errorLog.push('no valid versions for msvs_version were found')
98
+ }
99
+ }
100
+
101
+ const errorLog = this.errorLog.join('\n')
102
+
103
+ // Windows 80 列控制台,用到 X 标记列之前(含日志前缀共 79 字符,可用 62 字符):
104
+ // X
105
+ const infoLog = [
106
+ '**************************************************************',
107
+ 'You need to install the latest version of Visual Studio',
108
+ 'including the "Desktop development with C++" workload.',
109
+ 'For more information consult the documentation at:',
110
+ 'https://github.com/nodejs/node-gyp#on-windows',
111
+ '**************************************************************'
112
+ ].join('\n')
113
+
114
+ this.log.error(`\n${errorLog}\n\n${infoLog}\n`)
115
+ throw new Error('Could not find any Visual Studio installation to use')
116
+ }
117
+
118
+ // 调用 PowerShell 脚本,获取 Visual Studio 2017 或更新版本的信息
119
+ async findVisualStudio2017OrNewer () {
120
+ const ps = path.join(process.env.SystemRoot, 'System32',
121
+ 'WindowsPowerShell', 'v1.0', 'powershell.exe')
122
+ const csFile = path.join(__dirname, 'Find-VisualStudio.cs')
123
+ const psArgs = [
124
+ '-ExecutionPolicy',
125
+ 'Unrestricted',
126
+ '-NoProfile',
127
+ '-Command',
128
+ '&{Add-Type -Path \'' + csFile + '\';' + '[VisualStudioConfiguration.Main]::PrintJson()}'
129
+ ]
130
+
131
+ this.log.silly('Running', ps, psArgs)
132
+ const [err, stdout, stderr] = await execFile(ps, psArgs, { encoding: 'utf8' })
133
+ return this.parseData(err, stdout, stderr)
134
+ }
135
+
136
+ // 解析 PowerShell 脚本输出,寻找可用的 Visual Studio 2017 或更新版本
137
+ parseData (err, stdout, stderr) {
138
+ this.log.silly('PS stderr = %j', stderr)
139
+
140
+ const failPowershell = () => {
141
+ this.addLog(
142
+ 'could not use PowerShell to find Visual Studio 2017 or newer, try re-running with \'--loglevel silly\' for more details')
143
+ return null
144
+ }
145
+
146
+ if (err) {
147
+ this.log.silly('PS err = %j', err && (err.stack || err))
148
+ return failPowershell()
149
+ }
150
+
151
+ let vsInfo
152
+ try {
153
+ vsInfo = JSON.parse(stdout)
154
+ } catch (e) {
155
+ this.log.silly('PS stdout = %j', stdout)
156
+ this.log.silly(e)
157
+ return failPowershell()
158
+ }
159
+
160
+ if (!Array.isArray(vsInfo)) {
161
+ this.log.silly('PS stdout = %j', stdout)
162
+ return failPowershell()
163
+ }
164
+
165
+ vsInfo = vsInfo.map((info) => {
166
+ this.log.silly(`processing installation: "${info.path}"`)
167
+ info.path = path.resolve(info.path)
168
+ const ret = this.getVersionInfo(info)
169
+ ret.path = info.path
170
+ ret.msBuild = this.getMSBuild(info, ret.versionYear)
171
+ ret.toolset = this.getToolset(info, ret.versionYear)
172
+ ret.sdk = this.getSDK(info)
173
+ return ret
174
+ })
175
+ this.log.silly('vsInfo:', vsInfo)
176
+
177
+ // 去掉未来版本或版本号解析失败的项
178
+ vsInfo = vsInfo.filter((info) => {
179
+ if (info.versionYear) {
180
+ return true
181
+ }
182
+ this.addLog(`unknown version "${info.version}" found at "${info.path}"`)
183
+ return false
184
+ })
185
+
186
+ // 排序:新版本在前
187
+ vsInfo.sort((a, b) => b.versionYear - a.versionYear)
188
+
189
+ for (let i = 0; i < vsInfo.length; ++i) {
190
+ const info = vsInfo[i]
191
+ this.addLog(`checking VS${info.versionYear} (${info.version}) found ` +
192
+ `at:\n"${info.path}"`)
193
+
194
+ if (info.msBuild) {
195
+ this.addLog('- found "Visual Studio C++ core features"')
196
+ } else {
197
+ this.addLog('- "Visual Studio C++ core features" missing')
198
+ continue
199
+ }
200
+
201
+ if (info.toolset) {
202
+ this.addLog(`- found VC++ toolset: ${info.toolset}`)
203
+ } else {
204
+ this.addLog('- missing any VC++ toolset')
205
+ continue
206
+ }
207
+
208
+ if (info.sdk) {
209
+ this.addLog(`- found Windows SDK: ${info.sdk}`)
210
+ } else {
211
+ this.addLog('- missing any Windows SDK')
212
+ continue
213
+ }
214
+
215
+ if (!this.checkConfigVersion(info.versionYear, info.path)) {
216
+ continue
217
+ }
218
+
219
+ return info
220
+ }
221
+
222
+ this.addLog(
223
+ 'could not find a version of Visual Studio 2017 or newer to use')
224
+ return null
225
+ }
226
+
227
+ // 辅助:解析版本信息
228
+ getVersionInfo (info) {
229
+ const match = /^(\d+)\.(\d+)\..*/.exec(info.version)
230
+ if (!match) {
231
+ this.log.silly('- failed to parse version:', info.version)
232
+ return {}
233
+ }
234
+ this.log.silly('- version match = %j', match)
235
+ const ret = {
236
+ version: info.version,
237
+ versionMajor: parseInt(match[1], 10),
238
+ versionMinor: parseInt(match[2], 10)
239
+ }
240
+ if (ret.versionMajor === 15) {
241
+ ret.versionYear = 2017
242
+ return ret
243
+ }
244
+ if (ret.versionMajor === 16) {
245
+ ret.versionYear = 2019
246
+ return ret
247
+ }
248
+ if (ret.versionMajor === 17) {
249
+ ret.versionYear = 2022
250
+ return ret
251
+ }
252
+ if (ret.versionMajor === 18) {
253
+ ret.versionYear = 2026
254
+ return ret
255
+ }
256
+ this.log.silly('- unsupported version:', ret.versionMajor)
257
+ return {}
258
+ }
259
+
260
+ msBuildPathExists (path) {
261
+ return existsSync(path)
262
+ }
263
+
264
+ // 辅助:解析 MSBuild 信息
265
+ getMSBuild (info, versionYear) {
266
+ const pkg = 'Microsoft.VisualStudio.VC.MSBuild.Base'
267
+ const msbuildPath = path.join(info.path, 'MSBuild', 'Current', 'Bin', 'MSBuild.exe')
268
+ const msbuildPathArm64 = path.join(info.path, 'MSBuild', 'Current', 'Bin', 'arm64', 'MSBuild.exe')
269
+ if (info.packages.indexOf(pkg) !== -1) {
270
+ this.log.silly('- found VC.MSBuild.Base')
271
+ if (versionYear === 2017) {
272
+ return path.join(info.path, 'MSBuild', '15.0', 'Bin', 'MSBuild.exe')
273
+ }
274
+ if (versionYear === 2019) {
275
+ return msbuildPath
276
+ }
277
+ }
278
+ /**
279
+ * Visual Studio 2022 没有 MSBuild 包。
280
+ * ARM64 上编译的支持从 MSVC 14.32.31326 起加入,
281
+ * 因此用户设备是 ARM64 时优先使用它。
282
+ */
283
+ if (process.arch === 'arm64' && this.msBuildPathExists(msbuildPathArm64)) {
284
+ return msbuildPathArm64
285
+ } else if (this.msBuildPathExists(msbuildPath)) {
286
+ return msbuildPath
287
+ }
288
+ return null
289
+ }
290
+
291
+ // 辅助:解析 toolset 信息
292
+ getToolset (info, versionYear) {
293
+ const pkg = 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64'
294
+ const express = 'Microsoft.VisualStudio.WDExpress'
295
+
296
+ if (info.packages.indexOf(pkg) !== -1) {
297
+ this.log.silly('- found VC.Tools.x86.x64')
298
+ } else if (info.packages.indexOf(express) !== -1) {
299
+ this.log.silly('- found Visual Studio Express (looking for toolset)')
300
+ } else {
301
+ return null
302
+ }
303
+
304
+ if (versionYear === 2017) {
305
+ return 'v141'
306
+ } else if (versionYear === 2019) {
307
+ return 'v142'
308
+ } else if (versionYear === 2022) {
309
+ return 'v143'
310
+ } else if (versionYear === 2026) {
311
+ return 'v145'
312
+ }
313
+ this.log.silly('- invalid versionYear:', versionYear)
314
+ return null
315
+ }
316
+
317
+ // 辅助:解析 Windows SDK 信息
318
+ getSDK (info) {
319
+ const win8SDK = 'Microsoft.VisualStudio.Component.Windows81SDK'
320
+ const win10SDKPrefix = 'Microsoft.VisualStudio.Component.Windows10SDK.'
321
+ const win11SDKPrefix = 'Microsoft.VisualStudio.Component.Windows11SDK.'
322
+
323
+ let Win10or11SDKVer = 0
324
+ info.packages.forEach((pkg) => {
325
+ if (!pkg.startsWith(win10SDKPrefix) && !pkg.startsWith(win11SDKPrefix)) {
326
+ return
327
+ }
328
+ const parts = pkg.split('.')
329
+ if (parts.length > 5 && parts[5] !== 'Desktop') {
330
+ this.log.silly('- ignoring non-Desktop Win10/11SDK:', pkg)
331
+ return
332
+ }
333
+ const foundSdkVer = parseInt(parts[4], 10)
334
+ if (isNaN(foundSdkVer)) {
335
+ // Microsoft.VisualStudio.Component.Windows10SDK.IpOverUsb
336
+ this.log.silly('- failed to parse Win10/11SDK number:', pkg)
337
+ return
338
+ }
339
+ this.log.silly('- found Win10/11SDK:', foundSdkVer)
340
+ Win10or11SDKVer = Math.max(Win10or11SDKVer, foundSdkVer)
341
+ })
342
+
343
+ if (Win10or11SDKVer !== 0) {
344
+ return `10.0.${Win10or11SDKVer}.0`
345
+ } else if (info.packages.indexOf(win8SDK) !== -1) {
346
+ this.log.silly('- found Win8SDK')
347
+ return '8.1'
348
+ }
349
+ return null
350
+ }
351
+
352
+ // 查找可用的 Visual Studio 2015
353
+ async findVisualStudio2015 () {
354
+ if (this.nodeSemver.major >= 19) {
355
+ this.addLog(
356
+ 'not looking for VS2015 as it is only supported up to Node.js 18')
357
+ return null
358
+ }
359
+ return this.findOldVS({
360
+ version: '14.0',
361
+ versionMajor: 14,
362
+ versionMinor: 0,
363
+ versionYear: 2015,
364
+ toolset: 'v140'
365
+ })
366
+ }
367
+
368
+ // 查找可用的 Visual Studio 2013
369
+ async findVisualStudio2013 () {
370
+ if (this.nodeSemver.major >= 9) {
371
+ this.addLog(
372
+ 'not looking for VS2013 as it is only supported up to Node.js 8')
373
+ return null
374
+ }
375
+ return this.findOldVS({
376
+ version: '12.0',
377
+ versionMajor: 12,
378
+ versionMinor: 0,
379
+ versionYear: 2013,
380
+ toolset: 'v120'
381
+ })
382
+ }
383
+
384
+ // 辅助:VS2013 和 VS2015 的公共代码
385
+ async findOldVS (info) {
386
+ const regVC7 = ['HKLM\\Software\\Microsoft\\VisualStudio\\SxS\\VC7',
387
+ 'HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VC7']
388
+ const regMSBuild = 'HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions'
389
+
390
+ this.addLog(`looking for Visual Studio ${info.versionYear}`)
391
+ try {
392
+ let res = await this.regSearchKeys(regVC7, info.version, [])
393
+ const vsPath = path.resolve(res, '..')
394
+ this.addLog(`- found in "${vsPath}"`)
395
+ const msBuildRegOpts = process.arch === 'ia32' ? [] : ['/reg:32']
396
+
397
+ try {
398
+ res = await this.regSearchKeys([`${regMSBuild}\\${info.version}`], 'MSBuildToolsPath', msBuildRegOpts)
399
+ } catch (err) {
400
+ this.addLog('- could not find MSBuild in registry for this version')
401
+ return null
402
+ }
403
+
404
+ const msBuild = path.join(res, 'MSBuild.exe')
405
+ this.addLog(`- MSBuild in "${msBuild}"`)
406
+
407
+ if (!this.checkConfigVersion(info.versionYear, vsPath)) {
408
+ return null
409
+ }
410
+
411
+ info.path = vsPath
412
+ info.msBuild = msBuild
413
+ info.sdk = null
414
+ return info
415
+ } catch (err) {
416
+ this.addLog('- not found')
417
+ return null
418
+ }
419
+ }
420
+
421
+ // 找到可用的 Visual Studio 后:
422
+ // - 把它加入 validVersions,用于在指定版本未找到时输出;
423
+ // - 检查是否是请求的版本;
424
+ // - 检查是否匹配 Visual Studio 命令提示符。
425
+ checkConfigVersion (versionYear, vsPath) {
426
+ this.validVersions.push(versionYear)
427
+ this.validVersions.push(vsPath)
428
+
429
+ if (this.configVersionYear && this.configVersionYear !== versionYear) {
430
+ this.addLog('- msvs_version does not match this version')
431
+ return false
432
+ }
433
+ if (this.configPath &&
434
+ path.relative(this.configPath, vsPath) !== '') {
435
+ this.addLog('- msvs_version does not point to this installation')
436
+ return false
437
+ }
438
+ if (this.envVcInstallDir &&
439
+ path.relative(this.envVcInstallDir, vsPath) !== '') {
440
+ this.addLog('- does not match this Visual Studio Command Prompt')
441
+ return false
442
+ }
443
+
444
+ return true
445
+ }
446
+ }
447
+
448
+ export { VisualStudioFinder }