windows-autoconf
Advanced tools
Comparing version 1.10.0 to 1.11.1
module.exports = { | ||
"extends": "standard", | ||
"plugins": [ | ||
"standard", | ||
"promise" | ||
] | ||
}; | ||
'extends': 'standard', | ||
'plugins': [ | ||
'node', | ||
'standard', | ||
'promise' | ||
] | ||
} |
168
index.js
@@ -19,2 +19,3 @@ // Copyright 2017 - Refael Ackermann | ||
* @property {Boolean} SDK8 | ||
* @property {Boolean} IsVcCompatible | ||
* @property {Object} SDK | ||
@@ -24,41 +25,51 @@ * @property {Array} Packages | ||
*/ | ||
/** | ||
* @namespace lazy.bindings.fs.mkdirpSync | ||
*/ | ||
const lazy = { | ||
const bindings = { | ||
_patched: false, | ||
_bindings: null, | ||
get isDebug () { return (this._bindings.process.env['DEBUG'] || '').split(',').includes('autoconf') }, | ||
get bindings () { | ||
if (!this._bindings) { | ||
this._bindings = { | ||
fs: require('fs'), | ||
path: require('path'), | ||
log: console.log.bind(console), | ||
error: console.error.bind(console), | ||
execSync: require('child_process').execSync, | ||
process: process | ||
} | ||
if (!('mkdirpSync' in this._bindings.fs)) { | ||
this._bindings.fs.mkdirpSync = this._bindings.fs.mkdirSync | ||
} | ||
_checkForDebug (env) { return (env || '').split(',').includes('autoconf') }, | ||
_createDefaultBindings () { | ||
const _bindings = { | ||
fs: require('fs'), | ||
path: require('path'), | ||
log: console.log.bind(console), | ||
error: console.error.bind(console), | ||
execSync: require('child_process').execSync, | ||
process: process | ||
} | ||
return _bindings | ||
}, | ||
set inner (_bindings) { | ||
_bindings.isDebug = this._checkForDebug(_bindings.process.env['DEBUG']) | ||
this._bindings = _bindings | ||
Object.setPrototypeOf(this, _bindings) | ||
if (this.isDebug && !this._patched) { | ||
this._patched = true | ||
this._bindings._execSync = this._bindings.execSync | ||
this._bindings.execSync = (cmd, options) => { | ||
lazy.debug(`==== CMD ====\n${cmd}\n=============`) | ||
const ret = this._bindings._execSync(cmd, options) | ||
lazy.debug(`${ret}\n=============`) | ||
_bindings.util = require('util') | ||
_bindings._execSync = _bindings.execSync | ||
_bindings.execSync = (cmd, ...args) => { | ||
this.debug('============== execSync start ==============') | ||
this.debug('execSync cmd: %s', cmd) | ||
this.debug('execSync args: %j', args) | ||
const ret = _bindings._execSync(cmd, ...args) | ||
this.debug('=== output: ===') | ||
this.debug(ret.toString()) | ||
this.debug('===') | ||
this.debug('============== execSync end ================') | ||
return ret | ||
} | ||
} | ||
}, | ||
get inner () { | ||
if (!this._bindings) { | ||
this.inner = this._createDefaultBindings() | ||
} | ||
return this._bindings | ||
}, | ||
debug (...args) { if (this.isDebug) this.bindings.log(...args) }, | ||
debug (...args) { if (this.isDebug) this.error(...args) }, | ||
debugDir (arg) { | ||
if (this.isDebug) { | ||
const util = require('util') | ||
console.log('=============\n%s\n=============', util.inspect(arg, {colors: true})) | ||
this.debug('===== dir =====') | ||
this.debug(this.util.inspect(arg, {colors: true})) | ||
this.debug('=== dir end ===') | ||
} | ||
@@ -68,8 +79,8 @@ } | ||
function setBindings (bindings) { | ||
lazy._bindings = bindings | ||
function setBindings (_bindings) { | ||
bindings.inner = _bindings | ||
} | ||
function execAndParse (cmd) { | ||
const lines = lazy.bindings.execSync(cmd).toString().split(/\r?\n/g) | ||
const lines = bindings.inner.execSync(cmd).toString().split(/\r?\n/g) | ||
const ret = lines.filter(l => l.slice(0, 4) === ' ').join('') | ||
@@ -84,7 +95,7 @@ const log = lines.filter(l => l.slice(0, 4) !== ' ').join('') | ||
} catch (e) { | ||
lazy.debug('====== ret =======') | ||
lazy.debug(ret) | ||
lazy.debug('====== log =======') | ||
lazy.debug(log) | ||
lazy.debug('==================') | ||
bindings.debug('====== ret =======') | ||
bindings.debug(ret) | ||
bindings.debug('====== log =======') | ||
bindings.debug(log) | ||
bindings.debug('==================') | ||
return err.concat([e]) | ||
@@ -97,4 +108,7 @@ } | ||
setups.sort((a, b) => a.Version.localeCompare(b.Version)).reverse() | ||
const setup = setups.find(s => s.MSBuild && s.VCTools && (s.SDK || s.SDK8)) | ||
const setup = setups.find(s => s.IsVcCompatible) | ||
if (setups.length && !setup) return 'No C++' | ||
bindings.debug('=== checkSetup ===') | ||
bindings.debugDir(setup) | ||
bindings.debug('==================') | ||
return setup | ||
@@ -108,3 +122,3 @@ } | ||
} catch (e) { | ||
lazy.bindings.log('Couldn\'t find VS2017 with powershell') | ||
bindings.log('Couldn\'t find VS2017 with powershell') | ||
} | ||
@@ -118,3 +132,3 @@ } | ||
} catch (e) { | ||
lazy.bindings.log('Couldn\'t find VS2017 with a compiled exe') | ||
bindings.log('Couldn\'t find VS2017 with a compiled exe') | ||
} | ||
@@ -128,7 +142,7 @@ } | ||
if (vsSetupsRaw[0] === 'ERROR') { | ||
lazy.debug('Couldn\'t execute 2017 registry finder') | ||
bindings.debug('Couldn\'t execute 2017 registry finder') | ||
return | ||
} | ||
} catch (e) { | ||
lazy.debug('Couldn\'t execute 2017 registry finder: ' + e.message) | ||
bindings.debug('Couldn\'t execute 2017 registry finder: ' + e.message) | ||
} | ||
@@ -138,8 +152,8 @@ | ||
if (!vsSetup) { | ||
lazy.debug('Couldn\'t find ver 15.0 in registry') | ||
bindings.debug('Couldn\'t find ver 15.0 in registry') | ||
return | ||
} | ||
lazy.debugDir(vsSetup) | ||
if (!lazy.bindings.fs.existsSync(vsSetup.CmdPath)) { | ||
lazy.debug(`${vsSetup.CmdPath} doesn't exist`) | ||
bindings.debugDir(vsSetup) | ||
if (!bindings.inner.fs.existsSync(vsSetup.CmdPath)) { | ||
bindings.debug(`${vsSetup.CmdPath} doesn't exist`) | ||
return | ||
@@ -151,5 +165,5 @@ } | ||
env = resolveDevEnvironmentInner(`"${vsSetup.CmdPath}" -no_logo`) | ||
lazy.debugDir(env) | ||
bindings.debugDir(env) | ||
} catch (e) { | ||
lazy.debug('Couldn\'t execute 2017 VsDevCmd.bat: ' + e.message) | ||
bindings.debug('Couldn\'t execute 2017 VsDevCmd.bat: ' + e.message) | ||
} | ||
@@ -166,3 +180,3 @@ vsSetup.SDKFull = env['WindowsSDKVersion'].split('=').pop().replace('\\', '') | ||
const sdkSetups = execAndParse(module.exports.try_registry_sdk_path) | ||
lazy.debug(JSON.stringify(sdkSetups, null, ' ')) | ||
bindings.debug(JSON.stringify(sdkSetups, null, ' ')) | ||
const vers = sdkSetups | ||
@@ -177,7 +191,7 @@ .filter(s => s['InstallationFolder']) | ||
.reverse() | ||
lazy.debug(JSON.stringify(vers, null, ' ')) | ||
bindings.debug(JSON.stringify(vers, null, ' ')) | ||
const sdkSetup = sdkSetups.find(s => s['ProductVersion'] === vers[0].ProductVersion) | ||
return sdkSetup | ||
} catch (e) { | ||
lazy.bindings.log('Couldn\'t find any SDK in registry') | ||
bindings.log('Couldn\'t find any SDK in registry') | ||
} | ||
@@ -194,3 +208,3 @@ } | ||
} catch (e) { | ||
lazy.bindings.log('Couldn\'t find any SDK in registry') | ||
bindings.log('Couldn\'t find any SDK in registry') | ||
} | ||
@@ -202,2 +216,5 @@ } | ||
const vsSetup = tryVS2017Powershell() || tryVS2017CSC() || tryVS2017Registry() | ||
bindings.debug('=== Selected vsSetup ===') | ||
bindings.debugDir(vsSetup) | ||
bindings.debug('========================') | ||
getVS2017Setup.cache2017 = vsSetup | ||
@@ -211,3 +228,3 @@ return vsSetup | ||
if (!msbSetup) { | ||
lazy.bindings.log('Can\'t find "msbuild.exe"') | ||
bindings.log('Can\'t find "msbuild.exe"') | ||
return | ||
@@ -227,3 +244,3 @@ } | ||
if ('cacheSetup' in getMSVSSetup) return getMSVSSetup.cacheSetup | ||
const env = lazy.bindings.process.env | ||
const env = bindings.inner.process.env | ||
if (!version) { version = env['GYP_MSVS_VERSION'] || 'auto' } | ||
@@ -234,9 +251,9 @@ | ||
setup.version = '2017' | ||
} else if (version === '2015' || version === 'auto' && env['VS140COMNTOOLS']) { | ||
} else if ((version === '2015' || version === 'auto') && env['VS140COMNTOOLS']) { | ||
setup = {version: '2015', CommonTools: env['VS140COMNTOOLS']} | ||
} else if (version === '2013' || version === 'auto' && env['VS120COMNTOOLS']) { | ||
} else if ((version === '2013' || version === 'auto') && env['VS120COMNTOOLS']) { | ||
setup = {version: '2013', CommonTools: env['VS120COMNTOOLS']} | ||
} else if (version === '2012' || version === 'auto' && env['VS110COMNTOOLS']) { | ||
} else if ((version === '2012' || version === 'auto') && env['VS110COMNTOOLS']) { | ||
setup = {version: '2012', CommonTools: env['VS110COMNTOOLS']} | ||
} else if (version === '2010' || version === 'auto' && env['VS100COMNTOOLS']) { | ||
} else if ((version === '2010' || version === 'auto') && env['VS100COMNTOOLS']) { | ||
setup = {version: '2010', CommonTools: env['VS100COMNTOOLS']} | ||
@@ -247,3 +264,3 @@ } else { | ||
if (setup.CommonTools) { | ||
setup.InstallationPath = lazy.bindings.path.join(setup.CommonTools, '..', '..') | ||
setup.InstallationPath = bindings.path.join(setup.CommonTools, '..', '..') | ||
} | ||
@@ -255,3 +272,3 @@ getMSVSSetup.cacheSetup = setup | ||
function getOSBits () { | ||
const env = lazy.bindings.process.env | ||
const env = bindings.process.env | ||
@@ -295,3 +312,3 @@ // PROCESSOR_ARCHITEW6432 - is a system arch | ||
} | ||
setup.CmdPath = lazy.bindings.path.join(setup.InstallationPath, ...cmdPathParts) | ||
setup.CmdPath = bindings.path.join(setup.InstallationPath, ...cmdPathParts) | ||
setup.FullCmd = `"${setup.CmdPath}" ${arg}` | ||
@@ -309,3 +326,3 @@ } | ||
function resolveDevEnvironmentInner (fullCmd) { | ||
const lines = lazy.bindings.execSync(`${fullCmd} & set`, {env: {}}).toString().trim().split(/\r\n/g) | ||
const lines = bindings.execSync(`${fullCmd} & set`, {env: {}}).toString().trim().split(/\r\n/g) | ||
const hasFail = lines.slice(0, 2).some(l => l.includes('missing') || l.includes('not be installed')) | ||
@@ -327,6 +344,6 @@ if (hasFail) { | ||
try { | ||
const ex = lazy.bindings.fs.existsSync(cacheDir) | ||
if (!ex) lazy.bindings.fs.mkdirpSync(cacheDir) | ||
const testFile = lazy.bindings.path.join(cacheDir, '.check') | ||
lazy.bindings.fs.writeFileSync(testFile, '') | ||
const ex = bindings.fs.existsSync(cacheDir) | ||
if (!ex) bindings.fs.mkdirSync(cacheDir) | ||
const testFile = bindings.path.join(cacheDir, '.check') | ||
bindings.fs.writeFileSync(testFile, '') | ||
return true | ||
@@ -340,19 +357,19 @@ } catch (_) { | ||
const setup = getWithFullCmd(targetArch) | ||
lazy.debugDir(setup) | ||
bindings.debugDir(setup) | ||
const cacheKey = setup.FullCmd.replace(/\s|\\|\/|:|=|"/g, '') | ||
const env = lazy.bindings.process.env | ||
const cacheDir = lazy.bindings.path.join(env.HOME || env.USERPROFILE, '.autoconf') | ||
const cachable = setupCache(cacheDir) | ||
const cacheName = lazy.bindings.path.join(cacheDir, `_${cacheKey}${setup.Version}.json`) | ||
if (!noCache && cachable && lazy.bindings.fs.existsSync(cacheName)) { | ||
const file = lazy.bindings.fs.readFileSync(cacheName) | ||
const env = bindings.process.env | ||
const cacheDir = bindings.path.join(env.HOME || env.USERPROFILE, '.autoconf') | ||
const canCache = setupCache(cacheDir) | ||
const cacheName = bindings.path.join(cacheDir, `_${cacheKey}${setup.Version}.json`) | ||
if (!noCache && canCache && bindings.fs.existsSync(cacheName)) { | ||
const file = bindings.fs.readFileSync(cacheName) | ||
const ret = JSON.parse(file) | ||
lazy.debug('cache hit') | ||
lazy.debugDir(ret) | ||
bindings.debug('cache hit') | ||
bindings.debugDir(ret) | ||
return ret | ||
} else { | ||
const env = resolveDevEnvironmentInner(setup.FullCmd, targetArch) | ||
cachable && lazy.bindings.fs.writeFileSync(cacheName, JSON.stringify(env)) | ||
lazy.debug('actual resolution') | ||
lazy.debugDir(env) | ||
canCache && bindings.fs.writeFileSync(cacheName, JSON.stringify(env)) | ||
bindings.debug('actual resolution') | ||
bindings.debugDir(env) | ||
return env | ||
@@ -379,2 +396,3 @@ } | ||
_forTesting: { | ||
get bindings () { return bindings.inner && bindings }, | ||
tryVS2017Powershell, | ||
@@ -381,0 +399,0 @@ tryVS2017CSC, |
{ | ||
"name": "windows-autoconf", | ||
"version": "1.10.0", | ||
"version": "1.11.1", | ||
"description": "Try to find MS build tools", | ||
"main": "index.js", | ||
"dependencies": {}, | ||
"devDependencies": {}, | ||
"devDependencies": { | ||
"mocha": "^3.2.0" | ||
}, | ||
"scripts": { | ||
@@ -9,0 +11,0 @@ "test": "mocha test" |
// Copyright 2017 - Refael Ackermann | ||
// Distributed under MIT style license | ||
// See accompanying file LICENSE at https://github.com/node4good/windows-autoconf | ||
'use strict' | ||
@@ -14,20 +15,12 @@ /* eslint-disable no-path-concat */ | ||
const assert = require('assert') | ||
const execSync = require('child_process').execSync | ||
const getter = require('../') | ||
const execSync = getter._forTesting.bindings.execSync | ||
const prods = new Set(['BuildTools', 'Enterprise', 'Professional', 'Community']) | ||
function checkCom () { | ||
let ret | ||
try { | ||
ret = execSync(getter.check_VS2017_COM_path).toString() | ||
execSync(getter.check_VS2017_COM_path).toString() | ||
} catch (e) { | ||
assert.equal(e.status, 1) | ||
ret = e.output[1].toString().trim() | ||
assert.equal(ret, '"No COM"') | ||
} | ||
const setup = JSON.parse(ret) | ||
if (setup === 'No COM') { | ||
this.skip() | ||
} else { | ||
assert.equal(setup, 'COM Ok') | ||
} | ||
@@ -59,4 +52,4 @@ } | ||
it('Powershell -Version 2', function () { | ||
const csfile = getter.try_powershell_path.replace(/\\[^\\]+$/, '\\GetVS2017Configuration.cs').replace('"', '') | ||
const cmd = `"powershell.exe" -Version 2 -NoProfile -ExecutionPolicy Unrestricted -Command "& { Add-Type -Path '${csfile}'; [VisualStudioConfiguration.Main]::Query()}"` | ||
const csFiles = getter.try_powershell_path.replace(/\\[^\\]+$/, '\\..\\tools*\\*.cs').replace('"', '') | ||
const cmd = `"powershell.exe" -Version 2 -NoProfile -ExecutionPolicy Unrestricted -Command "& { Add-Type (Out-String -InputObject (Get-Content '${csFiles}')); [VisualStudioConfiguration.Program]::Query() }` | ||
let ret | ||
@@ -136,10 +129,18 @@ try { | ||
describe('Try cmd tools in a weird path', () => { | ||
const weirdDir = `"${__dirname}\\.tmp\\ t o l s !\\ oh$# boy lady gaga\\` | ||
console.log(__dirname) | ||
const weirdDirBase = `"${__dirname}\\.tmp\\ t o l s !\\ oh$# boy lady gaga\\` | ||
const weirdDir = `${weirdDirBase}tools` | ||
const weirdDir2 = `${weirdDirBase}tools-core` | ||
const {try_powershell_path, compile_run_path, try_registry_path} = getter | ||
before(() => { | ||
try { | ||
execSync(`"cmd.exe" /s /c mkdir ${weirdDir}`) | ||
execSync(`"cmd.exe" /s /c mkdir ${weirdDir2}`) | ||
} catch (_) {} | ||
const ret = execSync(`"cmd.exe" /s /c "xcopy /y /r /e /q "${__dirname + '\\..\\tools\\*.*'}" ${weirdDir}" "`).toString() | ||
assert(ret.includes('File(s) copied')) | ||
const ret2 = execSync(`"cmd.exe" /s /c "xcopy /y /r /e /q "${__dirname + '\\..\\tools-core\\*.*'}" ${weirdDir2}" "`).toString() | ||
assert(ret2.includes('File(s) copied')) | ||
getter.try_powershell_path = Path.join(weirdDir, Path.basename(getter.try_powershell_path)) | ||
@@ -242,4 +243,5 @@ getter.compile_run_path = Path.join(weirdDir, Path.basename(getter.compile_run_path)) | ||
describe('Try node wrapper', function () { | ||
it('getMSVSVersion', () => { | ||
it('getMSVSVersion', function () { | ||
const version = getter.getMSVSVersion() | ||
if (version === 'auto') return this.skip() | ||
console.log(`env#${process.env['GYP_MSVS_VERSION']}#`) | ||
@@ -316,4 +318,10 @@ if ('GYP_MSVS_VERSION' in process.env && !(['auto', ''].includes(process.env['GYP_MSVS_VERSION']))) { | ||
it('findOldVcVarsFile x64', () => { | ||
const cmd = getter.findOldVcVarsFile(null, 'x64') | ||
it('findOldVcVarsFile x64', function () { | ||
let cmd | ||
try { | ||
cmd = getter.findOldVcVarsFile(null, 'x64') | ||
} catch (e) { | ||
assert(e.message.includes('No Visual Studio found')) | ||
this.skip() | ||
} | ||
const path = extractFile(cmd) | ||
@@ -326,4 +334,10 @@ const parts = path.split('\\') | ||
it('findOldVcVarsFile ia32', () => { | ||
const cmd = getter.findOldVcVarsFile(null, 'ia32') | ||
it('findOldVcVarsFile ia32', function () { | ||
let cmd | ||
try { | ||
cmd = getter.findOldVcVarsFile(null, 'ia32') | ||
} catch (e) { | ||
assert(e.message.includes('No Visual Studio found')) | ||
this.skip() | ||
} | ||
const path = extractFile(cmd) | ||
@@ -336,20 +350,2 @@ const parts = path.split('\\') | ||
it('getWithFullCmd ia32', () => { | ||
const setup = getter._forTesting.getWithFullCmd('ia32') | ||
const cmd = setup.CmdPath | ||
const parts = cmd.split('\\') | ||
assert(parts.length >= 4) | ||
assert(parts.pop().match(/vs|vars/i)) | ||
assert(fs.existsSync(cmd)) | ||
}) | ||
it('getWithFullCmd x64', () => { | ||
const setup = getter._forTesting.getWithFullCmd('x64') | ||
const cmd = setup.CmdPath | ||
const parts = cmd.split('\\') | ||
assert(parts.length >= 4) | ||
assert(parts.pop().match(/vs|vars/i)) | ||
assert(fs.existsSync(cmd)) | ||
}) | ||
it('locateMsbuild', () => { | ||
@@ -371,2 +367,34 @@ const msbPath = getter.locateMsbuild() | ||
it('getWithFullCmd x64', function () { | ||
let setup | ||
try { | ||
setup = getter._forTesting.getWithFullCmd('x64') | ||
} catch (e) { | ||
assert(e.message.includes('No Visual Studio found')) | ||
this.skip() | ||
} | ||
const cmd = setup.CmdPath | ||
const parts = cmd.split('\\') | ||
assert(parts.length >= 4) | ||
assert(parts.pop().match(/vs|vars/i)) | ||
assert(fs.existsSync(cmd)) | ||
}) | ||
it('getWithFullCmd ia32', function () { | ||
let setup | ||
try { | ||
setup = getter._forTesting.getWithFullCmd('ia32') | ||
} catch (e) { | ||
assert(e.message.includes('No Visual Studio found')) | ||
this.skip() | ||
} | ||
const cmd = setup.CmdPath | ||
const parts = cmd.split('\\') | ||
assert(parts.length >= 4) | ||
assert(parts.pop().match(/vs|vars/i)) | ||
assert(fs.existsSync(cmd)) | ||
}) | ||
it('locateMsbuild(2017)', function () { | ||
@@ -392,2 +420,7 @@ const msbPath = getter.locateMsbuild(2017) | ||
describe('genEnvironment', function () { | ||
before(function () { | ||
const version = getter.getMSVSVersion() | ||
if (version === 'auto') return this.skip() | ||
}) | ||
function testEnvGen (arch, noCache) { | ||
@@ -394,0 +427,0 @@ return function () { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1401
95998
1
31