@dry-software/cmake-js 7.3.1 → 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.
@@ -1,97 +0,0 @@
1
- 'use strict'
2
- const os = require('os')
3
- const which = require('which')
4
-
5
- const environment = (module.exports = {
6
- cmakeJsVersion: require('../package.json').version,
7
- platform: os.platform(),
8
- isWin: os.platform() === 'win32',
9
- isLinux: os.platform() === 'linux',
10
- isOSX: os.platform() === 'darwin',
11
- arch: os.arch(),
12
- isX86: os.arch() === 'ia32' || os.arch() === 'x86',
13
- isX64: os.arch() === 'x64',
14
- isArm: os.arch() === 'arm',
15
- isArm64: os.arch() === 'arm64',
16
- runtime: 'node',
17
- runtimeVersion: process.versions.node,
18
- })
19
-
20
- Object.defineProperties(environment, {
21
- _isNinjaAvailable: {
22
- value: null,
23
- writable: true,
24
- },
25
- isNinjaAvailable: {
26
- get: function () {
27
- if (this._isNinjaAvailable === null) {
28
- this._isNinjaAvailable = false
29
- try {
30
- if (which.sync('ninja')) {
31
- this._isNinjaAvailable = true
32
- }
33
- } catch (e) {
34
- // Ignore
35
- }
36
- }
37
- return this._isNinjaAvailable
38
- },
39
- },
40
- _isMakeAvailable: {
41
- value: null,
42
- writable: true,
43
- },
44
- isMakeAvailable: {
45
- get: function () {
46
- if (this._isMakeAvailable === null) {
47
- this._isMakeAvailable = false
48
- try {
49
- if (which.sync('make')) {
50
- this._isMakeAvailable = true
51
- }
52
- } catch (e) {
53
- // Ignore
54
- }
55
- }
56
- return this._isMakeAvailable
57
- },
58
- },
59
- _isGPPAvailable: {
60
- value: null,
61
- writable: true,
62
- },
63
- isGPPAvailable: {
64
- get: function () {
65
- if (this._isGPPAvailable === null) {
66
- this._isGPPAvailable = false
67
- try {
68
- if (which.sync('g++')) {
69
- this._isGPPAvailable = true
70
- }
71
- } catch (e) {
72
- // Ignore
73
- }
74
- }
75
- return this._isGPPAvailable
76
- },
77
- },
78
- _isClangAvailable: {
79
- value: null,
80
- writable: true,
81
- },
82
- isClangAvailable: {
83
- get: function () {
84
- if (this._isClangAvailable === null) {
85
- this._isClangAvailable = false
86
- try {
87
- if (which.sync('clang++')) {
88
- this._isClangAvailable = true
89
- }
90
- } catch (e) {
91
- // Ignore
92
- }
93
- }
94
- return this._isClangAvailable
95
- },
96
- },
97
- })
@@ -1,24 +0,0 @@
1
- (The MIT License)
2
-
3
- Copyright (c) 2012 Nathan Rajlich <nathan@tootallnate.net>
4
-
5
- Permission is hereby granted, free of charge, to any person
6
- obtaining a copy of this software and associated documentation
7
- files (the "Software"), to deal in the Software without
8
- restriction, including without limitation the rights to use,
9
- copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the
11
- Software is furnished to do so, subject to the following
12
- conditions:
13
-
14
- The above copyright notice and this permission notice shall be
15
- included in all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
- OTHER DEALINGS IN THE SOFTWARE.
package/lib/import/README DELETED
@@ -1,6 +0,0 @@
1
- This is a copy of some files from node-gyp, with some minor modifications.
2
-
3
- Currently based on v10.0.1
4
-
5
- node-gyp has a decent strategy for finding Visual Studio, and has a lot more developer time behind them to make a good and robust solution.
6
- We may as well benefit from their solution than reinvent it
@@ -1,439 +0,0 @@
1
- 'use strict'
2
-
3
- const log = require('npmlog')
4
- const { existsSync } = require('fs')
5
- const { win32: path } = require('path')
6
- const { regSearchKeys, execFile, logWithPrefix } = require('./util')
7
- const semver = require('semver')
8
-
9
- class VisualStudioFinder {
10
- static findVisualStudio = (...args) => new VisualStudioFinder(...args).findVisualStudio()
11
-
12
- log = logWithPrefix(log, 'find VS')
13
-
14
- regSearchKeys = regSearchKeys
15
-
16
- constructor(nodeSemver, configMsvsVersion) {
17
- this.nodeSemver = nodeSemver
18
- this.configMsvsVersion = configMsvsVersion
19
- this.errorLog = []
20
- this.validVersions = []
21
- }
22
-
23
- // Logs a message at verbose level, but also saves it to be displayed later
24
- // at error level if an error occurs. This should help diagnose the problem.
25
- addLog(message) {
26
- this.log.verbose(message)
27
- this.errorLog.push(message)
28
- }
29
-
30
- async findVisualStudio() {
31
- this.configVersionYear = null
32
- this.configPath = null
33
- if (this.configMsvsVersion) {
34
- this.addLog('msvs_version was set from command line or npm config')
35
- if (this.configMsvsVersion.match(/^\d{4}$/)) {
36
- this.configVersionYear = parseInt(this.configMsvsVersion, 10)
37
- this.addLog(`- looking for Visual Studio version ${this.configVersionYear}`)
38
- } else {
39
- this.configPath = path.resolve(this.configMsvsVersion)
40
- this.addLog(`- looking for Visual Studio installed in "${this.configPath}"`)
41
- }
42
- } else {
43
- this.addLog('msvs_version not set from command line or npm config')
44
- }
45
-
46
- if (process.env.VCINSTALLDIR) {
47
- this.envVcInstallDir = path.resolve(process.env.VCINSTALLDIR, '..')
48
- this.addLog(
49
- 'running in VS Command Prompt, installation path is:\n' +
50
- `"${this.envVcInstallDir}"\n- will only use this version`,
51
- )
52
- } else {
53
- this.addLog('VCINSTALLDIR not set, not running in VS Command Prompt')
54
- }
55
-
56
- const checks = [
57
- () => this.findVisualStudio2017OrNewer(),
58
- () => this.findVisualStudio2015(),
59
- () => this.findVisualStudio2013(),
60
- ]
61
-
62
- for (const check of checks) {
63
- const info = await check()
64
- if (info) {
65
- return this.succeed(info)
66
- }
67
- }
68
-
69
- return this.fail()
70
- }
71
-
72
- succeed(info) {
73
- this.log.info(
74
- `using VS${info.versionYear} (${info.version}) found at:` +
75
- `\n"${info.path}"` +
76
- '\nrun with --verbose for detailed information',
77
- )
78
- return info
79
- }
80
-
81
- fail() {
82
- if (this.configMsvsVersion && this.envVcInstallDir) {
83
- this.errorLog.push('msvs_version does not match this VS Command Prompt or the', 'installation cannot be used.')
84
- } else if (this.configMsvsVersion) {
85
- // If msvs_version was specified but finding VS failed, print what would
86
- // have been accepted
87
- this.errorLog.push('')
88
- if (this.validVersions) {
89
- this.errorLog.push('valid versions for msvs_version:')
90
- this.validVersions.forEach((version) => {
91
- this.errorLog.push(`- "${version}"`)
92
- })
93
- } else {
94
- this.errorLog.push('no valid versions for msvs_version were found')
95
- }
96
- }
97
-
98
- const errorLog = this.errorLog.join('\n')
99
-
100
- // For Windows 80 col console, use up to the column before the one marked
101
- // with X (total 79 chars including logger prefix, 62 chars usable here):
102
- // X
103
- const infoLog = [
104
- '**************************************************************',
105
- 'You need to install the latest version of Visual Studio',
106
- 'including the "Desktop development with C++" workload.',
107
- 'For more information consult the documentation at:',
108
- 'https://github.com/nodejs/node-gyp#on-windows',
109
- '**************************************************************',
110
- ].join('\n')
111
-
112
- this.log.error(`\n${errorLog}\n\n${infoLog}\n`)
113
- throw new Error('Could not find any Visual Studio installation to use')
114
- }
115
-
116
- // Invoke the PowerShell script to get information about Visual Studio 2017
117
- // or newer installations
118
- async findVisualStudio2017OrNewer() {
119
- const ps = path.join(process.env.SystemRoot, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe')
120
- const csFile = path.join(__dirname, 'Find-VisualStudio.cs')
121
- const psArgs = [
122
- '-ExecutionPolicy',
123
- 'Unrestricted',
124
- '-NoProfile',
125
- '-Command',
126
- "&{Add-Type -Path '" + csFile + "';" + '[VisualStudioConfiguration.Main]::PrintJson()}',
127
- ]
128
-
129
- this.log.silly('Running', ps, psArgs)
130
- const [err, stdout, stderr] = await execFile(ps, psArgs, { encoding: 'utf8' })
131
- return this.parseData(err, stdout, stderr)
132
- }
133
-
134
- // Parse the output of the PowerShell script and look for an installation
135
- // of Visual Studio 2017 or newer to use
136
- parseData(err, stdout, stderr) {
137
- this.log.silly('PS stderr = %j', stderr)
138
-
139
- const failPowershell = () => {
140
- this.addLog(
141
- "could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details",
142
- )
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
- // Remove future versions or errors parsing version number
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
- // Sort to place newer versions first
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 ` + `at:\n"${info.path}"`)
192
-
193
- if (info.msBuild) {
194
- this.addLog('- found "Visual Studio C++ core features"')
195
- } else {
196
- this.addLog('- "Visual Studio C++ core features" missing')
197
- continue
198
- }
199
-
200
- if (info.toolset) {
201
- this.addLog(`- found VC++ toolset: ${info.toolset}`)
202
- } else {
203
- this.addLog('- missing any VC++ toolset')
204
- continue
205
- }
206
-
207
- if (info.sdk) {
208
- this.addLog(`- found Windows SDK: ${info.sdk}`)
209
- } else {
210
- this.addLog('- missing any Windows SDK')
211
- continue
212
- }
213
-
214
- if (!this.checkConfigVersion(info.versionYear, info.path)) {
215
- continue
216
- }
217
-
218
- return info
219
- }
220
-
221
- this.addLog('could not find a version of Visual Studio 2017 or newer to use')
222
- return null
223
- }
224
-
225
- // Helper - process version information
226
- getVersionInfo(info) {
227
- const match = /^(\d+)\.(\d+)\..*/.exec(info.version)
228
- if (!match) {
229
- this.log.silly('- failed to parse version:', info.version)
230
- return {}
231
- }
232
- this.log.silly('- version match = %j', match)
233
- const ret = {
234
- version: info.version,
235
- versionMajor: parseInt(match[1], 10),
236
- versionMinor: parseInt(match[2], 10),
237
- }
238
- if (ret.versionMajor === 15) {
239
- ret.versionYear = 2017
240
- return ret
241
- }
242
- if (ret.versionMajor === 16) {
243
- ret.versionYear = 2019
244
- return ret
245
- }
246
- if (ret.versionMajor === 17) {
247
- ret.versionYear = 2022
248
- return ret
249
- }
250
- this.log.silly('- unsupported version:', ret.versionMajor)
251
- return {}
252
- }
253
-
254
- msBuildPathExists(path) {
255
- return existsSync(path)
256
- }
257
-
258
- // Helper - process MSBuild information
259
- getMSBuild(info, versionYear) {
260
- const pkg = 'Microsoft.VisualStudio.VC.MSBuild.Base'
261
- const msbuildPath = path.join(info.path, 'MSBuild', 'Current', 'Bin', 'MSBuild.exe')
262
- const msbuildPathArm64 = path.join(info.path, 'MSBuild', 'Current', 'Bin', 'arm64', 'MSBuild.exe')
263
- if (info.packages.indexOf(pkg) !== -1) {
264
- this.log.silly('- found VC.MSBuild.Base')
265
- if (versionYear === 2017) {
266
- return path.join(info.path, 'MSBuild', '15.0', 'Bin', 'MSBuild.exe')
267
- }
268
- if (versionYear === 2019) {
269
- return msbuildPath
270
- }
271
- }
272
- /**
273
- * Visual Studio 2022 doesn't have the MSBuild package.
274
- * Support for compiling _on_ ARM64 was added in MSVC 14.32.31326,
275
- * so let's leverage it if the user has an ARM64 device.
276
- */
277
- if (process.arch === 'arm64' && this.msBuildPathExists(msbuildPathArm64)) {
278
- return msbuildPathArm64
279
- } else if (this.msBuildPathExists(msbuildPath)) {
280
- return msbuildPath
281
- }
282
- return null
283
- }
284
-
285
- // Helper - process toolset information
286
- getToolset(info, versionYear) {
287
- const pkg = 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64'
288
- const express = 'Microsoft.VisualStudio.WDExpress'
289
-
290
- if (info.packages.indexOf(pkg) !== -1) {
291
- this.log.silly('- found VC.Tools.x86.x64')
292
- } else if (info.packages.indexOf(express) !== -1) {
293
- this.log.silly('- found Visual Studio Express (looking for toolset)')
294
- } else {
295
- return null
296
- }
297
-
298
- if (versionYear === 2017) {
299
- return 'v141'
300
- } else if (versionYear === 2019) {
301
- return 'v142'
302
- } else if (versionYear === 2022) {
303
- return 'v143'
304
- }
305
- this.log.silly('- invalid versionYear:', versionYear)
306
- return null
307
- }
308
-
309
- // Helper - process Windows SDK information
310
- getSDK(info) {
311
- const win8SDK = 'Microsoft.VisualStudio.Component.Windows81SDK'
312
- const win10SDKPrefix = 'Microsoft.VisualStudio.Component.Windows10SDK.'
313
- const win11SDKPrefix = 'Microsoft.VisualStudio.Component.Windows11SDK.'
314
-
315
- let Win10or11SDKVer = 0
316
- info.packages.forEach((pkg) => {
317
- if (!pkg.startsWith(win10SDKPrefix) && !pkg.startsWith(win11SDKPrefix)) {
318
- return
319
- }
320
- const parts = pkg.split('.')
321
- if (parts.length > 5 && parts[5] !== 'Desktop') {
322
- this.log.silly('- ignoring non-Desktop Win10/11SDK:', pkg)
323
- return
324
- }
325
- const foundSdkVer = parseInt(parts[4], 10)
326
- if (isNaN(foundSdkVer)) {
327
- // Microsoft.VisualStudio.Component.Windows10SDK.IpOverUsb
328
- this.log.silly('- failed to parse Win10/11SDK number:', pkg)
329
- return
330
- }
331
- this.log.silly('- found Win10/11SDK:', foundSdkVer)
332
- Win10or11SDKVer = Math.max(Win10or11SDKVer, foundSdkVer)
333
- })
334
-
335
- if (Win10or11SDKVer !== 0) {
336
- return `10.0.${Win10or11SDKVer}.0`
337
- } else if (info.packages.indexOf(win8SDK) !== -1) {
338
- this.log.silly('- found Win8SDK')
339
- return '8.1'
340
- }
341
- return null
342
- }
343
-
344
- // Find an installation of Visual Studio 2015 to use
345
- async findVisualStudio2015() {
346
- if (semver.gte(this.nodeSemver, '19.0.0')) {
347
- this.addLog('not looking for VS2015 as it is only supported up to Node.js 18')
348
- return null
349
- }
350
- return this.findOldVS({
351
- version: '14.0',
352
- versionMajor: 14,
353
- versionMinor: 0,
354
- versionYear: 2015,
355
- toolset: 'v140',
356
- })
357
- }
358
-
359
- // Find an installation of Visual Studio 2013 to use
360
- async findVisualStudio2013() {
361
- if (semver.gte(this.nodeSemver, '9.0.0')) {
362
- this.addLog('not looking for VS2013 as it is only supported up to Node.js 8')
363
- return null
364
- }
365
- return this.findOldVS({
366
- version: '12.0',
367
- versionMajor: 12,
368
- versionMinor: 0,
369
- versionYear: 2013,
370
- toolset: 'v120',
371
- })
372
- }
373
-
374
- // Helper - common code for VS2013 and VS2015
375
- async findOldVS(info) {
376
- const regVC7 = [
377
- 'HKLM\\Software\\Microsoft\\VisualStudio\\SxS\\VC7',
378
- 'HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VC7',
379
- ]
380
- const regMSBuild = 'HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions'
381
-
382
- this.addLog(`looking for Visual Studio ${info.versionYear}`)
383
- try {
384
- let res = await this.regSearchKeys(regVC7, info.version, [])
385
- const vsPath = path.resolve(res, '..')
386
- this.addLog(`- found in "${vsPath}"`)
387
- const msBuildRegOpts = process.arch === 'ia32' ? [] : ['/reg:32']
388
-
389
- try {
390
- res = await this.regSearchKeys([`${regMSBuild}\\${info.version}`], 'MSBuildToolsPath', msBuildRegOpts)
391
- } catch (err) {
392
- this.addLog('- could not find MSBuild in registry for this version')
393
- return null
394
- }
395
-
396
- const msBuild = path.join(res, 'MSBuild.exe')
397
- this.addLog(`- MSBuild in "${msBuild}"`)
398
-
399
- if (!this.checkConfigVersion(info.versionYear, vsPath)) {
400
- return null
401
- }
402
-
403
- info.path = vsPath
404
- info.msBuild = msBuild
405
- info.sdk = null
406
- return info
407
- } catch (err) {
408
- this.addLog('- not found')
409
- return null
410
- }
411
- }
412
-
413
- // After finding a usable version of Visual Studio:
414
- // - add it to validVersions to be displayed at the end if a specific
415
- // version was requested and not found;
416
- // - check if this is the version that was requested.
417
- // - check if this matches the Visual Studio Command Prompt
418
- checkConfigVersion(versionYear, vsPath) {
419
- this.validVersions.push(versionYear)
420
- this.validVersions.push(vsPath)
421
-
422
- if (this.configVersionYear && this.configVersionYear !== versionYear) {
423
- this.addLog('- msvs_version does not match this version')
424
- return false
425
- }
426
- if (this.configPath && path.relative(this.configPath, vsPath) !== '') {
427
- this.addLog('- msvs_version does not point to this installation')
428
- return false
429
- }
430
- if (this.envVcInstallDir && path.relative(this.envVcInstallDir, vsPath) !== '') {
431
- this.addLog('- does not match this Visual Studio Command Prompt')
432
- return false
433
- }
434
-
435
- return true
436
- }
437
- }
438
-
439
- module.exports = VisualStudioFinder
@@ -1,70 +0,0 @@
1
- 'use strict'
2
-
3
- const log = require('npmlog')
4
- const cp = require('child_process')
5
- const path = require('path')
6
-
7
- const execFile = async (...args) =>
8
- new Promise((resolve) => {
9
- const child = cp.execFile(...args, (...a) => resolve(a))
10
- child.stdin.end()
11
- })
12
-
13
- function logWithPrefix(log, prefix) {
14
- function setPrefix(logFunction) {
15
- return (...args) => logFunction.apply(null, [prefix, ...args]) // eslint-disable-line
16
- }
17
- return {
18
- silly: setPrefix(log.silly),
19
- verbose: setPrefix(log.verbose),
20
- info: setPrefix(log.info),
21
- warn: setPrefix(log.warn),
22
- error: setPrefix(log.error),
23
- }
24
- }
25
-
26
- async function regGetValue(key, value, addOpts) {
27
- const outReValue = value.replace(/\W/g, '.')
28
- const outRe = new RegExp(`^\\s+${outReValue}\\s+REG_\\w+\\s+(\\S.*)$`, 'im')
29
- const reg = path.join(process.env.SystemRoot, 'System32', 'reg.exe')
30
- const regArgs = ['query', key, '/v', value].concat(addOpts)
31
-
32
- log.silly('reg', 'running', reg, regArgs)
33
- const [err, stdout, stderr] = await execFile(reg, regArgs, { encoding: 'utf8' })
34
-
35
- log.silly('reg', 'reg.exe stdout = %j', stdout)
36
- if (err || stderr.trim() !== '') {
37
- log.silly('reg', 'reg.exe err = %j', err && (err.stack || err))
38
- log.silly('reg', 'reg.exe stderr = %j', stderr)
39
- if (err) {
40
- throw err
41
- }
42
- throw new Error(stderr)
43
- }
44
-
45
- const result = outRe.exec(stdout)
46
- if (!result) {
47
- log.silly('reg', 'error parsing stdout')
48
- throw new Error('Could not parse output of reg.exe')
49
- }
50
-
51
- log.silly('reg', 'found: %j', result[1])
52
- return result[1]
53
- }
54
-
55
- async function regSearchKeys(keys, value, addOpts) {
56
- for (const key of keys) {
57
- try {
58
- return await regGetValue(key, value, addOpts)
59
- } catch {
60
- continue
61
- }
62
- }
63
- }
64
-
65
- module.exports = {
66
- logWithPrefix: logWithPrefix,
67
- regGetValue: regGetValue,
68
- regSearchKeys: regSearchKeys,
69
- execFile: execFile,
70
- }
package/lib/index.js DELETED
@@ -1,12 +0,0 @@
1
- 'use strict'
2
-
3
- module.exports = {
4
- BuildSystem: require('./buildSystem'),
5
- CMLog: require('./cmLog'),
6
- environment: require('./environment'),
7
- TargetOptions: require('./targetOptions'),
8
- Dist: require('./dist'),
9
- CMake: require('./cMake'),
10
- downloader: require('./downloader'),
11
- Toolset: require('./toolset'),
12
- }