From cad3f3efd8c15432d7bf1dcf03c654a603bcd669 Mon Sep 17 00:00:00 2001 From: Nik McG Date: Sun, 26 May 2019 20:40:24 -0400 Subject: [PATCH 1/7] Fixed determining generator on windows --- lib/es5/cMake.js | 1 - lib/es5/cMake.js.map | 2 +- lib/es5/toolset.js | 160 ++++++++--------------------------------- lib/es5/toolset.js.map | 2 +- lib/es6/cMake.js | 1 - lib/es6/toolset.js | 42 ++++------- 6 files changed, 48 insertions(+), 160 deletions(-) diff --git a/lib/es5/cMake.js b/lib/es5/cMake.js index af708461..c55dd6f5 100644 --- a/lib/es5/cMake.js +++ b/lib/es5/cMake.js @@ -8,7 +8,6 @@ var _ = require("lodash"); var environment = require("./environment"); var Dist = require("./dist"); var CMLog = require("./cmLog"); -var vsDetect = require("./vsDetect"); var TargetOptions = require("./targetOptions"); var processHelpers = require("./processHelpers"); var locateNAN = require("./locateNAN"); diff --git a/lib/es5/cMake.js.map b/lib/es5/cMake.js.map index 30d9b6c4..c3378984 100644 --- a/lib/es5/cMake.js.map +++ b/lib/es5/cMake.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["cMake.js"],"sourcesContent":["\"use strict\";\nlet splitargs = require(\"splitargs\");\nlet which = require(\"which\");\nlet Promise = require(\"bluebird\");\nlet fs = require(\"fs-extra\");\nlet path = require(\"path\");\nlet _ = require(\"lodash\");\nlet environment = require(\"./environment\");\nlet Dist = require(\"./dist\");\nlet CMLog = require(\"./cmLog\");\nlet vsDetect = require(\"./vsDetect\");\nlet TargetOptions = require(\"./targetOptions\");\nlet processHelpers = require(\"./processHelpers\");\nlet locateNAN = require(\"./locateNAN\");\nlet npmConfigData = require(\"rc\")(\"npm\");\nlet async = Promise.coroutine;\nlet Toolset = require(\"./toolset\");\n\nfunction CMake(options) {\n this.options = options || {};\n this.log = new CMLog(this.options);\n this.dist = new Dist(this.options);\n this.projectRoot = path.resolve(this.options.directory || process.cwd());\n this.workDir = path.resolve(this.options.out || path.join(this.projectRoot, \"build\"));\n this.config = this.options.debug ? \"Debug\" : \"Release\";\n this.buildDir = path.join(this.workDir, this.config);\n this._isAvailable = null;\n this.targetOptions = new TargetOptions(this.options);\n this.toolset = new Toolset(this.options);\n this.cMakeOptions = this.options.cMakeOptions || {};\n this.silent = !!options.silent;\n}\n\nObject.defineProperties(CMake.prototype, {\n path: {\n get: function () {\n return this.options.cmakePath || \"cmake\";\n }\n },\n isAvailable: {\n get: function () {\n if (this._isAvailable === null) {\n this._isAvailable = CMake.isAvailable(this.options);\n }\n return this._isAvailable;\n }\n }\n});\n\nCMake.isAvailable = function (options) {\n options = options || {};\n try {\n if (options.cmakePath) {\n let stat = fs.lstatSync(options.cmakePath);\n return !stat.isDirectory();\n }\n else {\n which.sync(\"cmake\");\n return true;\n }\n }\n catch (e) {\n _.noop(e);\n }\n return false;\n};\n\nCMake.getGenerators = async(function* (options) {\n let arch = \" [arch]\";\n options = options || {};\n let gens = [];\n if (CMake.isAvailable(options)) {\n // try parsing machine-readable capabilities (available since CMake 3.7)\n try {\n let stdout = yield processHelpers.exec((options.cmakePath || \"cmake\") + \" -E capabilities\");\n let capabilities = JSON.parse(stdout);\n return capabilities.generators.map(x => x.name);\n }\n catch (error) {\n this.log.verbose(\"TOOL\", \"Failed to query CMake capabilities (CMake is probably older than 3.7)\");\n }\n\n // fall back to parsing help text\n let stdout = yield processHelpers.exec((options.cmakePath || \"cmake\") + \" --help\");\n let hasCr = stdout.includes(\"\\r\\n\");\n let output = hasCr ? stdout.split(\"\\r\\n\") : stdout.split(\"\\n\");\n let on = false;\n output.forEach(function (line, i) {\n if (on) {\n let parts = line.split(\"=\");\n if ((parts.length === 2 && parts[0].trim()) ||\n (parts.length === 1 && i !== output.length - 1 && output[i + 1].trim()[0] === \"=\")) {\n let gen = parts[0].trim();\n if (_.endsWith(gen, arch)) {\n gen = gen.substr(0, gen.length - arch.length);\n }\n gens.push(gen);\n }\n }\n if (line.trim() === \"Generators\") {\n on = true;\n }\n });\n }\n else {\n throw new Error(\"CMake is not installed. Install CMake.\");\n }\n return gens;\n});\n\nCMake.prototype.getGenerators = function () {\n return CMake.getGenerators(this.options);\n};\n\nCMake.prototype.verifyIfAvailable = function () {\n if (!this.isAvailable) {\n throw new Error(\"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.\");\n }\n};\n\nCMake.prototype.getConfigureCommand = async(function* () {\n // Create command:\n let command = this.path;\n command += \" \\\"\" + this.projectRoot + \"\\\" --no-warn-unused-cli\";\n\n let D = [];\n\n // CMake.js watermark\n D.push({\"CMAKE_JS_VERSION\": environment.moduleVersion});\n\n // Build configuration:\n D.push({\"CMAKE_BUILD_TYPE\": this.config});\n if (environment.isWin) {\n\t\tD.push({\"CMAKE_RUNTIME_OUTPUT_DIRECTORY\": this.workDir});\n\t}\n\telse {\n\t\tD.push({\"CMAKE_LIBRARY_OUTPUT_DIRECTORY\": this.buildDir});\n\t}\n\n // Include and lib:\n let incPaths;\n if (this.dist.headerOnly) {\n incPaths = [path.join(this.dist.internalPath, \"/include/node\")];\n }\n else {\n let nodeH = path.join(this.dist.internalPath, \"/src\");\n let v8H = path.join(this.dist.internalPath, \"/deps/v8/include\");\n let uvH = path.join(this.dist.internalPath, \"/deps/uv/include\");\n incPaths = [nodeH, v8H, uvH];\n }\n\n // NAN\n let nanH = yield locateNAN(this.projectRoot);\n if (nanH) {\n incPaths.push(nanH);\n }\n\n // Includes:\n D.push({\"CMAKE_JS_INC\": incPaths.join(\";\")});\n\n // Sources:\n let srcPaths = [];\n if (environment.isWin) {\n let delayHook = path.normalize(path.join(__dirname, '..', 'cpp', 'win_delay_load_hook.cc'));\n\n srcPaths.push(delayHook.replace(/\\\\/gm, '/'));\n }\n\n D.push({\"CMAKE_JS_SRC\": srcPaths.join(\";\")});\n\n // Runtime:\n D.push({\"NODE_RUNTIME\": this.targetOptions.runtime});\n D.push({\"NODE_RUNTIMEVERSION\": this.targetOptions.runtimeVersion});\n D.push({\"NODE_ARCH\": this.targetOptions.arch});\n\n if (environment.isWin) {\n // Win\n let libs = this.dist.winLibs;\n if (libs.length) {\n D.push({\"CMAKE_JS_LIB\": libs.join(\";\")});\n }\n }\n\n // Custom options\n for (let k of _.keys(this.cMakeOptions)) {\n D.push({[k]: this.cMakeOptions[k]});\n }\n\n // Toolset:\n yield this.toolset.initialize(false);\n\n if (this.toolset.generator) {\n command += \" -G\\\"\" + this.toolset.generator + \"\\\"\";\n }\n if (this.toolset.toolset) {\n command += \" -T\\\"\" + this.toolset.toolset + \"\\\"\";\n }\n if (this.toolset.cppCompilerPath) {\n D.push({\"CMAKE_CXX_COMPILER\": this.toolset.cppCompilerPath});\n }\n if (this.toolset.cCompilerPath) {\n D.push({\"CMAKE_C_COMPILER\": this.toolset.cCompilerPath});\n }\n if (this.toolset.compilerFlags.length) {\n D.push({\"CMAKE_CXX_FLAGS\": this.toolset.compilerFlags.join(\" \")});\n }\n if (this.toolset.linkerFlags.length) {\n D.push({\"CMAKE_SHARED_LINKER_FLAGS\": this.toolset.linkerFlags.join(\" \")});\n }\n if (this.toolset.makePath) {\n D.push({\"CMAKE_MAKE_PROGRAM\": this.toolset.makePath});\n }\n\n // Load NPM config\n for (let key of _.keys(npmConfigData)) {\n if (_.startsWith(key, \"cmake_\")) {\n let s = {};\n let sk = key.substr(6);\n if (sk) {\n s[sk] = npmConfigData[key];\n if (s[sk]) {\n D.push(s);\n }\n }\n }\n }\n\n command += \" \" +\n D.map(function (p) {\n return \"-D\" + _.keys(p)[0] + \"=\\\"\" + _.values(p)[0] + \"\\\"\";\n }).join(\" \");\n\n return command;\n});\n\nCMake.prototype.configure = async(function* () {\n this.verifyIfAvailable();\n\n this.log.info(\"CMD\", \"CONFIGURE\");\n let listPath = path.join(this.projectRoot, \"CMakeLists.txt\");\n let command = yield this.getConfigureCommand();\n\n try {\n yield fs.lstat(listPath);\n }\n catch (e) {\n throw new Error(\"'\" + listPath + \"' not found.\");\n }\n\n try {\n yield fs.ensureDir(this.workDir);\n }\n catch (e) {\n _.noop(e);\n }\n\n let cwd = process.cwd();\n process.chdir(this.workDir);\n try {\n yield this._run(command);\n }\n finally {\n process.chdir(cwd);\n }\n});\n\nCMake.prototype.ensureConfigured = async(function* () {\n try {\n yield fs.lstat(path.join(this.workDir, \"CMakeCache.txt\"));\n }\n catch (e) {\n _.noop(e);\n yield this.configure();\n }\n});\n\nCMake.prototype.getBuildCommand = function() {\n var command = this.path + \" --build \\\"\" + this.workDir + \"\\\" --config \" + this.config;\n if (this.options.target) {\n command += \" --target \" + this.options.target;\n }\n return Promise.resolve(command);\n};\n\nCMake.prototype.build = async(function* () {\n this.verifyIfAvailable();\n\n yield this.ensureConfigured();\n let buildCommand = yield this.getBuildCommand();\n this.log.info(\"CMD\", \"BUILD\");\n yield this._run(buildCommand);\n});\n\nCMake.prototype.getCleanCommand = function () {\n return this.path + \" -E remove_directory \\\"\" + this.workDir + \"\\\"\";\n};\n\nCMake.prototype.clean = function () {\n this.verifyIfAvailable();\n\n this.log.info(\"CMD\", \"CLEAN\");\n return this._run(this.getCleanCommand());\n};\n\nCMake.prototype.reconfigure = async(function* () {\n yield this.clean();\n yield this.configure();\n});\n\nCMake.prototype.rebuild = async(function* () {\n yield this.clean();\n yield this.build();\n});\n\nCMake.prototype.compile = async(function* () {\n try {\n yield this.build();\n }\n catch (e) {\n _.noop(e);\n this.log.info(\"REP\", \"Build has been failed, trying to do a full rebuild.\");\n yield this.rebuild();\n }\n});\n\nCMake.prototype._run = function (command) {\n this.log.info(\"RUN\", command);\n return processHelpers.run(command, {silent: this.silent});\n};\n\nmodule.exports = CMake;\n"],"file":"cMake.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["cMake.js"],"sourcesContent":["\"use strict\";\nlet splitargs = require(\"splitargs\");\nlet which = require(\"which\");\nlet Promise = require(\"bluebird\");\nlet fs = require(\"fs-extra\");\nlet path = require(\"path\");\nlet _ = require(\"lodash\");\nlet environment = require(\"./environment\");\nlet Dist = require(\"./dist\");\nlet CMLog = require(\"./cmLog\");\nlet TargetOptions = require(\"./targetOptions\");\nlet processHelpers = require(\"./processHelpers\");\nlet locateNAN = require(\"./locateNAN\");\nlet npmConfigData = require(\"rc\")(\"npm\");\nlet async = Promise.coroutine;\nlet Toolset = require(\"./toolset\");\n\nfunction CMake(options) {\n this.options = options || {};\n this.log = new CMLog(this.options);\n this.dist = new Dist(this.options);\n this.projectRoot = path.resolve(this.options.directory || process.cwd());\n this.workDir = path.resolve(this.options.out || path.join(this.projectRoot, \"build\"));\n this.config = this.options.debug ? \"Debug\" : \"Release\";\n this.buildDir = path.join(this.workDir, this.config);\n this._isAvailable = null;\n this.targetOptions = new TargetOptions(this.options);\n this.toolset = new Toolset(this.options);\n this.cMakeOptions = this.options.cMakeOptions || {};\n this.silent = !!options.silent;\n}\n\nObject.defineProperties(CMake.prototype, {\n path: {\n get: function () {\n return this.options.cmakePath || \"cmake\";\n }\n },\n isAvailable: {\n get: function () {\n if (this._isAvailable === null) {\n this._isAvailable = CMake.isAvailable(this.options);\n }\n return this._isAvailable;\n }\n }\n});\n\nCMake.isAvailable = function (options) {\n options = options || {};\n try {\n if (options.cmakePath) {\n let stat = fs.lstatSync(options.cmakePath);\n return !stat.isDirectory();\n }\n else {\n which.sync(\"cmake\");\n return true;\n }\n }\n catch (e) {\n _.noop(e);\n }\n return false;\n};\n\nCMake.getGenerators = async(function* (options) {\n let arch = \" [arch]\";\n options = options || {};\n let gens = [];\n if (CMake.isAvailable(options)) {\n // try parsing machine-readable capabilities (available since CMake 3.7)\n try {\n let stdout = yield processHelpers.exec((options.cmakePath || \"cmake\") + \" -E capabilities\");\n let capabilities = JSON.parse(stdout);\n return capabilities.generators.map(x => x.name);\n }\n catch (error) {\n this.log.verbose(\"TOOL\", \"Failed to query CMake capabilities (CMake is probably older than 3.7)\");\n }\n\n // fall back to parsing help text\n let stdout = yield processHelpers.exec((options.cmakePath || \"cmake\") + \" --help\");\n let hasCr = stdout.includes(\"\\r\\n\");\n let output = hasCr ? stdout.split(\"\\r\\n\") : stdout.split(\"\\n\");\n let on = false;\n output.forEach(function (line, i) {\n if (on) {\n let parts = line.split(\"=\");\n if ((parts.length === 2 && parts[0].trim()) ||\n (parts.length === 1 && i !== output.length - 1 && output[i + 1].trim()[0] === \"=\")) {\n let gen = parts[0].trim();\n if (_.endsWith(gen, arch)) {\n gen = gen.substr(0, gen.length - arch.length);\n }\n gens.push(gen);\n }\n }\n if (line.trim() === \"Generators\") {\n on = true;\n }\n });\n }\n else {\n throw new Error(\"CMake is not installed. Install CMake.\");\n }\n return gens;\n});\n\nCMake.prototype.getGenerators = function () {\n return CMake.getGenerators(this.options);\n};\n\nCMake.prototype.verifyIfAvailable = function () {\n if (!this.isAvailable) {\n throw new Error(\"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.\");\n }\n};\n\nCMake.prototype.getConfigureCommand = async(function* () {\n // Create command:\n let command = this.path;\n command += \" \\\"\" + this.projectRoot + \"\\\" --no-warn-unused-cli\";\n\n let D = [];\n\n // CMake.js watermark\n D.push({\"CMAKE_JS_VERSION\": environment.moduleVersion});\n\n // Build configuration:\n D.push({\"CMAKE_BUILD_TYPE\": this.config});\n if (environment.isWin) {\n\t\tD.push({\"CMAKE_RUNTIME_OUTPUT_DIRECTORY\": this.workDir});\n\t}\n\telse {\n\t\tD.push({\"CMAKE_LIBRARY_OUTPUT_DIRECTORY\": this.buildDir});\n\t}\n\n // Include and lib:\n let incPaths;\n if (this.dist.headerOnly) {\n incPaths = [path.join(this.dist.internalPath, \"/include/node\")];\n }\n else {\n let nodeH = path.join(this.dist.internalPath, \"/src\");\n let v8H = path.join(this.dist.internalPath, \"/deps/v8/include\");\n let uvH = path.join(this.dist.internalPath, \"/deps/uv/include\");\n incPaths = [nodeH, v8H, uvH];\n }\n\n // NAN\n let nanH = yield locateNAN(this.projectRoot);\n if (nanH) {\n incPaths.push(nanH);\n }\n\n // Includes:\n D.push({\"CMAKE_JS_INC\": incPaths.join(\";\")});\n\n // Sources:\n let srcPaths = [];\n if (environment.isWin) {\n let delayHook = path.normalize(path.join(__dirname, '..', 'cpp', 'win_delay_load_hook.cc'));\n\n srcPaths.push(delayHook.replace(/\\\\/gm, '/'));\n }\n\n D.push({\"CMAKE_JS_SRC\": srcPaths.join(\";\")});\n\n // Runtime:\n D.push({\"NODE_RUNTIME\": this.targetOptions.runtime});\n D.push({\"NODE_RUNTIMEVERSION\": this.targetOptions.runtimeVersion});\n D.push({\"NODE_ARCH\": this.targetOptions.arch});\n\n if (environment.isWin) {\n // Win\n let libs = this.dist.winLibs;\n if (libs.length) {\n D.push({\"CMAKE_JS_LIB\": libs.join(\";\")});\n }\n }\n\n // Custom options\n for (let k of _.keys(this.cMakeOptions)) {\n D.push({[k]: this.cMakeOptions[k]});\n }\n\n // Toolset:\n yield this.toolset.initialize(false);\n\n if (this.toolset.generator) {\n command += \" -G\\\"\" + this.toolset.generator + \"\\\"\";\n }\n if (this.toolset.toolset) {\n command += \" -T\\\"\" + this.toolset.toolset + \"\\\"\";\n }\n if (this.toolset.cppCompilerPath) {\n D.push({\"CMAKE_CXX_COMPILER\": this.toolset.cppCompilerPath});\n }\n if (this.toolset.cCompilerPath) {\n D.push({\"CMAKE_C_COMPILER\": this.toolset.cCompilerPath});\n }\n if (this.toolset.compilerFlags.length) {\n D.push({\"CMAKE_CXX_FLAGS\": this.toolset.compilerFlags.join(\" \")});\n }\n if (this.toolset.linkerFlags.length) {\n D.push({\"CMAKE_SHARED_LINKER_FLAGS\": this.toolset.linkerFlags.join(\" \")});\n }\n if (this.toolset.makePath) {\n D.push({\"CMAKE_MAKE_PROGRAM\": this.toolset.makePath});\n }\n\n // Load NPM config\n for (let key of _.keys(npmConfigData)) {\n if (_.startsWith(key, \"cmake_\")) {\n let s = {};\n let sk = key.substr(6);\n if (sk) {\n s[sk] = npmConfigData[key];\n if (s[sk]) {\n D.push(s);\n }\n }\n }\n }\n\n command += \" \" +\n D.map(function (p) {\n return \"-D\" + _.keys(p)[0] + \"=\\\"\" + _.values(p)[0] + \"\\\"\";\n }).join(\" \");\n\n return command;\n});\n\nCMake.prototype.configure = async(function* () {\n this.verifyIfAvailable();\n\n this.log.info(\"CMD\", \"CONFIGURE\");\n let listPath = path.join(this.projectRoot, \"CMakeLists.txt\");\n let command = yield this.getConfigureCommand();\n\n try {\n yield fs.lstat(listPath);\n }\n catch (e) {\n throw new Error(\"'\" + listPath + \"' not found.\");\n }\n\n try {\n yield fs.ensureDir(this.workDir);\n }\n catch (e) {\n _.noop(e);\n }\n\n let cwd = process.cwd();\n process.chdir(this.workDir);\n try {\n yield this._run(command);\n }\n finally {\n process.chdir(cwd);\n }\n});\n\nCMake.prototype.ensureConfigured = async(function* () {\n try {\n yield fs.lstat(path.join(this.workDir, \"CMakeCache.txt\"));\n }\n catch (e) {\n _.noop(e);\n yield this.configure();\n }\n});\n\nCMake.prototype.getBuildCommand = function() {\n var command = this.path + \" --build \\\"\" + this.workDir + \"\\\" --config \" + this.config;\n if (this.options.target) {\n command += \" --target \" + this.options.target;\n }\n return Promise.resolve(command);\n};\n\nCMake.prototype.build = async(function* () {\n this.verifyIfAvailable();\n\n yield this.ensureConfigured();\n let buildCommand = yield this.getBuildCommand();\n this.log.info(\"CMD\", \"BUILD\");\n yield this._run(buildCommand);\n});\n\nCMake.prototype.getCleanCommand = function () {\n return this.path + \" -E remove_directory \\\"\" + this.workDir + \"\\\"\";\n};\n\nCMake.prototype.clean = function () {\n this.verifyIfAvailable();\n\n this.log.info(\"CMD\", \"CLEAN\");\n return this._run(this.getCleanCommand());\n};\n\nCMake.prototype.reconfigure = async(function* () {\n yield this.clean();\n yield this.configure();\n});\n\nCMake.prototype.rebuild = async(function* () {\n yield this.clean();\n yield this.build();\n});\n\nCMake.prototype.compile = async(function* () {\n try {\n yield this.build();\n }\n catch (e) {\n _.noop(e);\n this.log.info(\"REP\", \"Build has been failed, trying to do a full rebuild.\");\n yield this.rebuild();\n }\n});\n\nCMake.prototype._run = function (command) {\n this.log.info(\"RUN\", command);\n return processHelpers.run(command, {silent: this.silent});\n};\n\nmodule.exports = CMake;\n"],"file":"cMake.js"} \ No newline at end of file diff --git a/lib/es5/toolset.js b/lib/es5/toolset.js index 840d2358..59f0c234 100644 --- a/lib/es5/toolset.js +++ b/lib/es5/toolset.js @@ -5,9 +5,9 @@ var _ = require("lodash"); var TargetOptions = require("./targetOptions"); var environment = require("./environment"); var assert = require("assert"); -var vsDetect = require("./vsDetect"); var path = require("path"); var CMLog = require("./cmLog"); +var processHelpers = require("./processHelpers"); function Toolset(options) { this.options = options || {}; this.targetOptions = new TargetOptions(this.options); @@ -22,7 +22,7 @@ function Toolset(options) { this.log = new CMLog(this.options); this._initialized = false; } -Toolset.prototype.initialize = async($traceurRuntime.initGeneratorFunction(function $__8(install) { +Toolset.prototype.initialize = async($traceurRuntime.initGeneratorFunction(function $__1(install) { return $traceurRuntime.createGeneratorInstance(function($ctx) { while (true) switch ($ctx.state) { @@ -50,7 +50,7 @@ Toolset.prototype.initialize = async($traceurRuntime.initGeneratorFunction(funct default: return $ctx.end(); } - }, $__8, this); + }, $__1, this); })); Toolset.prototype.initializePosix = function(install) { if (!environment.isGPPAvailable && !environment.isClangAvailable) { @@ -131,7 +131,7 @@ Toolset.prototype.initializePosix = function(install) { this.log.info("TOOL", "Building only the " + this.options.target + " target, as specified from the command line."); } }; -Toolset.prototype.initializeWin = async($traceurRuntime.initGeneratorFunction(function $__9(install) { +Toolset.prototype.initializeWin = async($traceurRuntime.initGeneratorFunction(function $__2(install) { var topVS; return $traceurRuntime.createGeneratorInstance(function($ctx) { while (true) @@ -183,153 +183,55 @@ Toolset.prototype.initializeWin = async($traceurRuntime.initGeneratorFunction(fu default: return $ctx.end(); } - }, $__9, this); + }, $__2, this); })); -Toolset.prototype._getTopSupportedVisualStudioGenerator = async($traceurRuntime.initGeneratorFunction(function $__10() { +Toolset.prototype._getTopSupportedVisualStudioGenerator = async($traceurRuntime.initGeneratorFunction(function $__3() { var CMake, - list, - maxVer, - result, - $__4, - $__5, - $__6, - $__2, - $__1, - gen, - found, - ver, - is64Bit, - $__11, - $__12, - $__13, - $__7; + programFilesPath, + vswhereCommand, + vswhereOutput, + version; return $traceurRuntime.createGeneratorInstance(function($ctx) { while (true) switch ($ctx.state) { case 0: CMake = require("./cMake"); assert(environment.isWin); - $ctx.state = 50; + programFilesPath = _.get(process.env, "ProgramFiles(x86)", _.get(process.env, "ProgramFiles")); + vswhereCommand = path.resolve(programFilesPath, "Microsoft Visual Studio", "Installer", "vswhere.exe"); + $ctx.state = 11; break; - case 50: + case 11: $ctx.state = 2; - return CMake.getGenerators(this.options); + return processHelpers.exec(("\"" + vswhereCommand + "\" -property installationVersion")); case 2: - list = $ctx.sent; + vswhereOutput = $ctx.sent; $ctx.state = 4; break; case 4: - maxVer = 0; - result = null; - $__4 = true; - $__5 = false; - $__6 = undefined; - $ctx.state = 52; + $ctx.state = (!vswhereOutput) ? 5 : 6; break; - case 52: - $ctx.pushTry(34, 35); - $ctx.state = 37; - break; - case 37: - $__2 = void 0, $__1 = (list)[Symbol.iterator](); - $ctx.state = 33; - break; - case 33: - $ctx.state = (!($__4 = ($__2 = $__1.next()).done)) ? 29 : 31; - break; - case 21: - $__4 = true; - $ctx.state = 33; - break; - case 29: - gen = $__2.value; - $ctx.state = 30; - break; - case 30: - found = /^visual studio (\d+)/i.exec(gen); - $ctx.state = 24; - break; - case 24: - $ctx.state = (!found) ? 21 : 6; + case 5: + $ctx.returnValue = null; + $ctx.state = -2; break; case 6: - ver = parseInt(found[1]); - $ctx.state = 26; - break; - case 26: - $ctx.state = (ver <= maxVer) ? 21 : 9; - break; - case 9: - is64Bit = gen.endsWith("Win64"); - $ctx.state = 28; - break; - case 28: - $ctx.state = ((this.targetOptions.isX86 && is64Bit) || (this.targetOptions.isX64 && !is64Bit)) ? 21 : 12; - break; - case 12: - $__11 = vsDetect.isInstalled; - $__12 = $__11.call(vsDetect, ver + ".0"); - $ctx.state = 19; - break; - case 19: - $ctx.state = 15; - return $__12; - case 15: - $__13 = $ctx.sent; - $ctx.state = 17; - break; - case 17: - $ctx.state = ($__13) ? 20 : 21; - break; - case 20: - result = gen; - maxVer = ver; - $ctx.state = 21; - break; - case 31: - $ctx.popTry(); - $ctx.state = 35; - $ctx.finallyFallThrough = 39; - break; - case 34: - $ctx.popTry(); - $ctx.maybeUncatchable(); - $__7 = $ctx.storedException; - $ctx.state = 40; - break; - case 40: - $__5 = true; - $__6 = $__7; - $ctx.state = 35; - $ctx.finallyFallThrough = 39; - break; - case 35: - $ctx.popTry(); - $ctx.state = 46; - break; - case 46: - try { - if (!$__4 && $__1.return != null) { - $__1.return(); - } - } finally { - if ($__5) { - throw $__6; - } - } - $ctx.state = 44; - break; - case 39: - $ctx.returnValue = result; + version = vswhereOutput.trim(); + version = version.substring(0, version.indexOf(".")); + $ctx.state = 13; + break; + case 13: + $ctx.returnValue = { + "14": "Visual Studio 14 2015", + "15": "Visual Studio 15 2017", + "16": "Visual Studio 16 2019" + }[version] || null; $ctx.state = -2; break; - case 44: - $ctx.state = $ctx.finallyFallThrough; - break; default: return $ctx.end(); } - }, $__10, this); + }, $__3, this); })); module.exports = Toolset; diff --git a/lib/es5/toolset.js.map b/lib/es5/toolset.js.map index 9b4a2969..dd0f2ca3 100644 --- a/lib/es5/toolset.js.map +++ b/lib/es5/toolset.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["toolset.js"],"sourcesContent":["\"use strict\";\nlet Promise = require(\"bluebird\");\nlet async = Promise.coroutine;\nlet _ = require(\"lodash\");\nlet TargetOptions = require(\"./targetOptions\");\nlet environment = require(\"./environment\");\nlet assert = require(\"assert\");\nlet vsDetect = require(\"./vsDetect\");\nlet path = require(\"path\");\nlet CMLog = require(\"./cmLog\");\n\nfunction Toolset(options) {\n this.options = options || {};\n this.targetOptions = new TargetOptions(this.options);\n this.generator = options.generator;\n this.toolset = options.toolset;\n this.target = options.target;\n this.cCompilerPath = null;\n this.cppCompilerPath = null;\n this.compilerFlags = [];\n this.linkerFlags = [];\n this.makePath = null;\n this.log = new CMLog(this.options);\n this._initialized = false;\n}\n\nToolset.prototype.initialize = async(function*(install) {\n if (!this._initialized) {\n if (environment.isWin) {\n yield this.initializeWin(install);\n }\n else {\n this.initializePosix(install);\n }\n this._initialized = true;\n }\n});\n\nToolset.prototype.initializePosix = function (install) {\n // 1: Compiler\n if (!environment.isGPPAvailable && !environment.isClangAvailable) {\n if (environment.isOSX) {\n throw new Error(\"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'.\");\n }\n else {\n throw new Error(\"C++ Compiler toolset is not available. Install proper compiler toolset with your package manager, eg. 'sudo apt-get install g++'.\");\n }\n }\n\n if (this.options.preferClang && environment.isClangAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using clang++ compiler, because preferClang option is set, and clang++ is available.\");\n }\n this.cppCompilerPath = \"clang++\";\n this.cCompilerPath = \"clang\";\n }\n else if (this.options.preferGnu && environment.isGPPAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using g++ compiler, because preferGnu option is set, and g++ is available.\");\n }\n this.cppCompilerPath = \"g++\";\n this.cCompilerPath = \"gcc\";\n }\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n }\n // 2: Generator\n else if (environment.isOSX) {\n if (this.options.preferXcode) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Xcode generator, because preferXcode option is set.\");\n }\n this.generator = \"Xcode\";\n }\n else if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n else {\n if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n\n // 3: Flags\n if (environment.isOSX) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting default OSX compiler flags.\");\n }\n\n this.compilerFlags.push(\"-D_DARWIN_USE_64_BIT_INODE=1\");\n this.compilerFlags.push(\"-D_LARGEFILE_SOURCE\");\n this.compilerFlags.push(\"-D_FILE_OFFSET_BITS=64\");\n this.compilerFlags.push(\"-DBUILDING_NODE_EXTENSION\");\n this.linkerFlags.push(\"-undefined dynamic_lookup\");\n }\n\n // 4: Build target\n if (this.options.target) {\n this.log.info(\"TOOL\", \"Building only the \" + this.options.target + \" target, as specified from the command line.\");\n }\n};\n\nToolset.prototype.initializeWin = async(function*(install) {\n // Visual Studio:\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n return;\n }\n let topVS = yield this._getTopSupportedVisualStudioGenerator();\n //if (!this.options.noMSVC) {\n if (topVS) {\n if (install) {\n this.log.info(\"TOOL\", `Using ${topVS} generator.`);\n }\n this.generator = topVS;\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n }\n else {\n throw new Error(\"There is no Visual C++ compiler installed. Install Visual C++ Build Toolset or Visual Studio.\");\n }\n});\n\nToolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() {\n let CMake = require(\"./cMake\");\n assert(environment.isWin);\n let list = yield CMake.getGenerators(this.options);\n let maxVer = 0;\n let result = null;\n for (let gen of list) {\n let found = /^visual studio (\\d+)/i.exec(gen);\n if (!found) {\n continue;\n }\n\n let ver = parseInt(found[1]);\n if (ver <= maxVer) {\n continue;\n }\n\n const is64Bit = gen.endsWith(\"Win64\");\n if ((this.targetOptions.isX86 && is64Bit) || (this.targetOptions.isX64 && !is64Bit)) {\n continue;\n }\n\n if (yield vsDetect.isInstalled(ver + \".0\")) {\n result = gen;\n maxVer = ver;\n }\n }\n return result;\n});\n\nmodule.exports = Toolset;\n"],"file":"toolset.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["toolset.js"],"sourcesContent":["\"use strict\";\nlet Promise = require(\"bluebird\");\nlet async = Promise.coroutine;\nlet _ = require(\"lodash\");\nlet TargetOptions = require(\"./targetOptions\");\nlet environment = require(\"./environment\");\nlet assert = require(\"assert\");\nlet path = require(\"path\");\nlet CMLog = require(\"./cmLog\");\nlet processHelpers = require(\"./processHelpers\");\n\nfunction Toolset(options) {\n this.options = options || {};\n this.targetOptions = new TargetOptions(this.options);\n this.generator = options.generator;\n this.toolset = options.toolset;\n this.target = options.target;\n this.cCompilerPath = null;\n this.cppCompilerPath = null;\n this.compilerFlags = [];\n this.linkerFlags = [];\n this.makePath = null;\n this.log = new CMLog(this.options);\n this._initialized = false;\n}\n\nToolset.prototype.initialize = async(function*(install) {\n if (!this._initialized) {\n if (environment.isWin) {\n yield this.initializeWin(install);\n }\n else {\n this.initializePosix(install);\n }\n this._initialized = true;\n }\n});\n\nToolset.prototype.initializePosix = function (install) {\n // 1: Compiler\n if (!environment.isGPPAvailable && !environment.isClangAvailable) {\n if (environment.isOSX) {\n throw new Error(\"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'.\");\n }\n else {\n throw new Error(\"C++ Compiler toolset is not available. Install proper compiler toolset with your package manager, eg. 'sudo apt-get install g++'.\");\n }\n }\n\n if (this.options.preferClang && environment.isClangAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using clang++ compiler, because preferClang option is set, and clang++ is available.\");\n }\n this.cppCompilerPath = \"clang++\";\n this.cCompilerPath = \"clang\";\n }\n else if (this.options.preferGnu && environment.isGPPAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using g++ compiler, because preferGnu option is set, and g++ is available.\");\n }\n this.cppCompilerPath = \"g++\";\n this.cCompilerPath = \"gcc\";\n }\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n }\n // 2: Generator\n else if (environment.isOSX) {\n if (this.options.preferXcode) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Xcode generator, because preferXcode option is set.\");\n }\n this.generator = \"Xcode\";\n }\n else if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n else {\n if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n\n // 3: Flags\n if (environment.isOSX) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting default OSX compiler flags.\");\n }\n\n this.compilerFlags.push(\"-D_DARWIN_USE_64_BIT_INODE=1\");\n this.compilerFlags.push(\"-D_LARGEFILE_SOURCE\");\n this.compilerFlags.push(\"-D_FILE_OFFSET_BITS=64\");\n this.compilerFlags.push(\"-DBUILDING_NODE_EXTENSION\");\n this.linkerFlags.push(\"-undefined dynamic_lookup\");\n }\n\n // 4: Build target\n if (this.options.target) {\n this.log.info(\"TOOL\", \"Building only the \" + this.options.target + \" target, as specified from the command line.\");\n }\n};\n\nToolset.prototype.initializeWin = async(function*(install) {\n // Visual Studio:\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n return;\n }\n let topVS = yield this._getTopSupportedVisualStudioGenerator();\n //if (!this.options.noMSVC) {\n if (topVS) {\n if (install) {\n this.log.info(\"TOOL\", `Using ${topVS} generator.`);\n }\n this.generator = topVS;\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n }\n else {\n throw new Error(\"There is no Visual C++ compiler installed. Install Visual C++ Build Toolset or Visual Studio.\");\n }\n});\n\nToolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() {\n let CMake = require(\"./cMake\");\n assert(environment.isWin);\n\n let programFilesPath = _.get(process.env, \"ProgramFiles(x86)\", _.get(process.env, \"ProgramFiles\"));\n let vswhereCommand = path.resolve(programFilesPath, \"Microsoft Visual Studio\", \"Installer\", \"vswhere.exe\");\n const vswhereOutput = yield processHelpers.exec(`\"${vswhereCommand}\" -property installationVersion`);\n\n if (!vswhereOutput) {\n return null; // What should be returned here?\n }\n\n let version = vswhereOutput.trim();\n version = version.substring(0, version.indexOf(\".\"));\n\n return {\n \"14\": \"Visual Studio 14 2015\",\n \"15\": \"Visual Studio 15 2017\",\n \"16\": \"Visual Studio 16 2019\",\n }[version] || null;\n});\n\nmodule.exports = Toolset;\n"],"file":"toolset.js"} \ No newline at end of file diff --git a/lib/es6/cMake.js b/lib/es6/cMake.js index a1df75cc..fb9c6d0c 100644 --- a/lib/es6/cMake.js +++ b/lib/es6/cMake.js @@ -8,7 +8,6 @@ let _ = require("lodash"); let environment = require("./environment"); let Dist = require("./dist"); let CMLog = require("./cmLog"); -let vsDetect = require("./vsDetect"); let TargetOptions = require("./targetOptions"); let processHelpers = require("./processHelpers"); let locateNAN = require("./locateNAN"); diff --git a/lib/es6/toolset.js b/lib/es6/toolset.js index 83c5b904..d82740d8 100644 --- a/lib/es6/toolset.js +++ b/lib/es6/toolset.js @@ -5,9 +5,9 @@ let _ = require("lodash"); let TargetOptions = require("./targetOptions"); let environment = require("./environment"); let assert = require("assert"); -let vsDetect = require("./vsDetect"); let path = require("path"); let CMLog = require("./cmLog"); +let processHelpers = require("./processHelpers"); function Toolset(options) { this.options = options || {}; @@ -177,35 +177,23 @@ Toolset.prototype.initializeWin = async(function*(install) { Toolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() { let CMake = require("./cMake"); assert(environment.isWin); - let list = yield CMake.getGenerators(this.options); - let maxVer = 0; - let result = null; - for (let gen of list) { - let found = /^visual studio (\d+)/i.exec(gen); - if (!found) { - continue; - } - - let ver = parseInt(found[1]); - if (ver <= maxVer) { - continue; - } - // unlike previous versions "Visual Studio 16 2019" doesn't end with arch name - const isVS16 = (16 == ver); - if (!isVS16) { - const is64Bit = gen.endsWith("Win64"); - if ((this.targetOptions.isX86 && is64Bit) || (this.targetOptions.isX64 && !is64Bit)) { - continue; - } - } + let programFilesPath = _.get(process.env, "ProgramFiles(x86)", _.get(process.env, "ProgramFiles")); + let vswhereCommand = path.resolve(programFilesPath, "Microsoft Visual Studio", "Installer", "vswhere.exe"); + const vswhereOutput = yield processHelpers.exec(`"${vswhereCommand}" -property installationVersion`); - if (yield vsDetect.isInstalled(ver + ".0")) { - result = gen; - maxVer = ver; - } + if (!vswhereOutput) { + return null; // What should be returned here? } - return result; + + let version = vswhereOutput.trim(); + version = version.substring(0, version.indexOf(".")); + + return { + "14": "Visual Studio 14 2015", + "15": "Visual Studio 15 2017", + "16": "Visual Studio 16 2019", + }[version] || null; }); module.exports = Toolset; From 24c0ace5c0d672836afb7b8af343aae09e9dcde0 Mon Sep 17 00:00:00 2001 From: Nik McG Date: Sun, 26 May 2019 20:40:34 -0400 Subject: [PATCH 2/7] update package-lock --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index b8f06ca2..52c5d3e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "cmake-js", - "version": "5.1.1", + "version": "5.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { From 7c772b2983df1dcd8ad19b0dd6a2099b1b6b8497 Mon Sep 17 00:00:00 2001 From: Nik McG Date: Sun, 26 May 2019 20:47:42 -0400 Subject: [PATCH 3/7] Removed vsDetect.js --- lib/es5/vsDetect.js | 303 ---------------------------------------- lib/es5/vsDetect.js.map | 1 - lib/es6/vsDetect.js | 95 ------------- 3 files changed, 399 deletions(-) delete mode 100644 lib/es5/vsDetect.js delete mode 100644 lib/es5/vsDetect.js.map delete mode 100644 lib/es6/vsDetect.js diff --git a/lib/es5/vsDetect.js b/lib/es5/vsDetect.js deleted file mode 100644 index 1546b9a0..00000000 --- a/lib/es5/vsDetect.js +++ /dev/null @@ -1,303 +0,0 @@ -"use strict"; -var processHelpers = require("./processHelpers"); -var Promise = require("bluebird"); -var async = Promise.coroutine; -var _ = require("lodash"); -var path = require("path"); -var vsDetect = { - isInstalled: async($traceurRuntime.initGeneratorFunction(function $__1(version) { - var vsInstalled, - vsvNextInstalled, - buildToolsInstalled, - foundByVSWhere, - $__2, - $__3, - $__4, - $__5, - $__6, - $__7, - $__8, - $__9, - $__10, - $__11, - $__12, - $__13; - return $traceurRuntime.createGeneratorInstance(function($ctx) { - while (true) - switch ($ctx.state) { - case 0: - $__2 = this._isVSInstalled; - $__3 = $__2.call(this, version); - $ctx.state = 6; - break; - case 6: - $ctx.state = 2; - return $__3; - case 2: - $__4 = $ctx.sent; - $ctx.state = 4; - break; - case 4: - vsInstalled = $__4; - $ctx.state = 8; - break; - case 8: - $__5 = this._isVSvNextInstalled; - $__6 = $__5.call(this, version); - $ctx.state = 14; - break; - case 14: - $ctx.state = 10; - return $__6; - case 10: - $__7 = $ctx.sent; - $ctx.state = 12; - break; - case 12: - vsvNextInstalled = $__7; - $ctx.state = 16; - break; - case 16: - $__8 = this._isBuildToolsInstalled; - $__9 = $__8.call(this, version); - $ctx.state = 22; - break; - case 22: - $ctx.state = 18; - return $__9; - case 18: - $__10 = $ctx.sent; - $ctx.state = 20; - break; - case 20: - buildToolsInstalled = $__10; - $ctx.state = 24; - break; - case 24: - $__11 = this._isFoundByVSWhere; - $__12 = $__11.call(this, version); - $ctx.state = 30; - break; - case 30: - $ctx.state = 26; - return $__12; - case 26: - $__13 = $ctx.sent; - $ctx.state = 28; - break; - case 28: - foundByVSWhere = $__13; - $ctx.state = 32; - break; - case 32: - $ctx.returnValue = vsInstalled || vsvNextInstalled || buildToolsInstalled || foundByVSWhere; - $ctx.state = -2; - break; - default: - return $ctx.end(); - } - }, $__1, this); - })), - _isFoundByVSWhere: async($traceurRuntime.initGeneratorFunction(function $__14(version) { - return $traceurRuntime.createGeneratorInstance(function($ctx) { - while (true) - switch ($ctx.state) { - case 0: - $ctx.returnValue = false; - $ctx.state = -2; - break; - default: - return $ctx.end(); - } - }, $__14, this); - })), - _isBuildToolsInstalled: async($traceurRuntime.initGeneratorFunction(function $__15(version) { - var mainVer, - key, - testPhrase, - command, - stdout, - e; - return $traceurRuntime.createGeneratorInstance(function($ctx) { - while (true) - switch ($ctx.state) { - case 0: - mainVer = version.split(".")[0]; - if (Number(mainVer) >= 15) { - key = "HKLM\\SOFTWARE\\Classes\\Installer\\Dependencies\\Microsoft.VS.windows_toolscore,v" + mainVer; - testPhrase = "Version"; - } else { - key = "HKLM\\SOFTWARE\\Classes\\Installer\\Dependencies\\Microsoft.VS.VisualCppBuildTools_x86_enu,v" + mainVer; - testPhrase = "Visual C++"; - } - command = "reg query \"" + key + "\""; - $ctx.state = 19; - break; - case 19: - $ctx.pushTry(7, null); - $ctx.state = 10; - break; - case 10: - $ctx.state = 2; - return processHelpers.exec(command); - case 2: - stdout = $ctx.sent; - $ctx.state = 4; - break; - case 4: - $ctx.returnValue = stdout && stdout.indexOf(testPhrase) > 0; - $ctx.state = -2; - break; - case 6: - $ctx.popTry(); - $ctx.state = 12; - break; - case 7: - $ctx.popTry(); - $ctx.maybeUncatchable(); - e = $ctx.storedException; - $ctx.state = 13; - break; - case 13: - _.noop(e); - $ctx.state = 12; - break; - case 12: - $ctx.returnValue = false; - $ctx.state = -2; - break; - default: - return $ctx.end(); - } - }, $__15, this); - })), - _isVSInstalled: async($traceurRuntime.initGeneratorFunction(function $__16(version) { - var command, - stdout, - lines, - e; - return $traceurRuntime.createGeneratorInstance(function($ctx) { - while (true) - switch ($ctx.state) { - case 0: - command = "reg query \"HKLM\\Software\\Microsoft\\VisualStudio\\" + version + "\""; - $ctx.state = 23; - break; - case 23: - $ctx.pushTry(11, null); - $ctx.state = 14; - break; - case 14: - $ctx.state = 2; - return processHelpers.exec(command); - case 2: - stdout = $ctx.sent; - $ctx.state = 4; - break; - case 4: - $ctx.state = (stdout) ? 8 : 6; - break; - case 8: - lines = stdout.split("\r\n").filter(function(line) { - return line.length > 10; - }); - $ctx.state = 9; - break; - case 9: - $ctx.state = (lines.length >= 4) ? 5 : 6; - break; - case 5: - $ctx.returnValue = true; - $ctx.state = -2; - break; - case 6: - $ctx.popTry(); - $ctx.state = 16; - break; - case 11: - $ctx.popTry(); - $ctx.maybeUncatchable(); - e = $ctx.storedException; - $ctx.state = 17; - break; - case 17: - _.noop(e); - $ctx.state = 16; - break; - case 16: - $ctx.returnValue = false; - $ctx.state = -2; - break; - default: - return $ctx.end(); - } - }, $__16, this); - })), - _isVSvNextInstalled: async($traceurRuntime.initGeneratorFunction(function $__17(version) { - var mainVer, - command, - stdout, - lines, - e; - return $traceurRuntime.createGeneratorInstance(function($ctx) { - while (true) - switch ($ctx.state) { - case 0: - mainVer = version.split(".")[0]; - command = "reg query \"HKLM\\SOFTWARE\\Classes\\Installer\\Dependencies\\Microsoft.VisualStudio.MinShell.Msi,v" + mainVer + "\""; - $ctx.state = 23; - break; - case 23: - $ctx.pushTry(11, null); - $ctx.state = 14; - break; - case 14: - $ctx.state = 2; - return processHelpers.exec(command); - case 2: - stdout = $ctx.sent; - $ctx.state = 4; - break; - case 4: - $ctx.state = (stdout) ? 8 : 6; - break; - case 8: - lines = stdout.split("\r\n").filter(function(line) { - return line.length > 10; - }); - $ctx.state = 9; - break; - case 9: - $ctx.state = (lines.length >= 3) ? 5 : 6; - break; - case 5: - $ctx.returnValue = true; - $ctx.state = -2; - break; - case 6: - $ctx.popTry(); - $ctx.state = 16; - break; - case 11: - $ctx.popTry(); - $ctx.maybeUncatchable(); - e = $ctx.storedException; - $ctx.state = 17; - break; - case 17: - _.noop(e); - $ctx.state = 16; - break; - case 16: - $ctx.returnValue = false; - $ctx.state = -2; - break; - default: - return $ctx.end(); - } - }, $__17, this); - })) -}; -module.exports = vsDetect; - -//# sourceMappingURL=vsDetect.js.map diff --git a/lib/es5/vsDetect.js.map b/lib/es5/vsDetect.js.map deleted file mode 100644 index bca29a3b..00000000 --- a/lib/es5/vsDetect.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"names":[],"mappings":"","sources":["vsDetect.js"],"sourcesContent":["\"use strict\";\r\nlet processHelpers = require(\"./processHelpers\");\r\nlet Promise = require(\"bluebird\");\r\nlet async = Promise.coroutine;\r\nlet _ = require(\"lodash\");\r\nlet path = require(\"path\");\r\n\r\nlet vsDetect = {\r\n isInstalled: async(function* (version) {\r\n let vsInstalled = (yield this._isVSInstalled(version));\r\n let vsvNextInstalled = (yield this._isVSvNextInstalled(version));\r\n let buildToolsInstalled = (yield this._isBuildToolsInstalled(version));\r\n let foundByVSWhere = (yield this._isFoundByVSWhere(version));\r\n\r\n return vsInstalled || vsvNextInstalled || buildToolsInstalled || foundByVSWhere;\r\n }),\r\n _isFoundByVSWhere: async(function* (version) {\r\n // TODO: with auto download\r\n /*\r\n let mainVer = version.split(\".\")[0];\r\n let command = path.resolve(\"vswhere.exe\");\r\n try {\r\n let stdout = yield processHelpers.exec(command, [\"-version\", version]);\r\n return stdout && stdout.indexOf(\"installationVersion: \" + mainVer) > 0;\r\n }\r\n catch (e) {\r\n _.noop(e);\r\n }\r\n */\r\n return false;\r\n }),\r\n _isBuildToolsInstalled: async(function*(version) {\r\n let mainVer = version.split(\".\")[0];\r\n let key;\r\n let testPhrase;\r\n if (Number(mainVer) >= 15) {\r\n key = \"HKLM\\\\SOFTWARE\\\\Classes\\\\Installer\\\\Dependencies\\\\Microsoft.VS.windows_toolscore,v\" + mainVer;\r\n testPhrase = \"Version\";\r\n }\r\n else {\r\n key = \"HKLM\\\\SOFTWARE\\\\Classes\\\\Installer\\\\Dependencies\\\\Microsoft.VS.VisualCppBuildTools_x86_enu,v\" + mainVer;\r\n testPhrase = \"Visual C++\";\r\n }\r\n let command = \"reg query \\\"\" + key + \"\\\"\";\r\n try {\r\n let stdout = yield processHelpers.exec(command);\r\n return stdout && stdout.indexOf(testPhrase) > 0;\r\n }\r\n catch (e) {\r\n _.noop(e);\r\n }\r\n return false;\r\n }),\r\n _isVSInstalled: async(function*(version) {\r\n // On x64 this will look for x64 keys only, but if VS and compilers installed properly,\r\n // it will write it's keys to 64 bit registry as well.\r\n let command = \"reg query \\\"HKLM\\\\Software\\\\Microsoft\\\\VisualStudio\\\\\" + version + \"\\\"\";\r\n try {\r\n let stdout = yield processHelpers.exec(command);\r\n if (stdout) {\r\n let lines = stdout.split(\"\\r\\n\").filter(function (line) {\r\n return line.length > 10;\r\n });\r\n if (lines.length >= 4) {\r\n return true;\r\n }\r\n }\r\n }\r\n catch (e) {\r\n _.noop(e);\r\n }\r\n return false;\r\n }),\r\n _isVSvNextInstalled: async(function*(version) {\r\n let mainVer = version.split(\".\")[0];\r\n let command = \"reg query \\\"HKLM\\\\SOFTWARE\\\\Classes\\\\Installer\\\\Dependencies\\\\Microsoft.VisualStudio.MinShell.Msi,v\" + mainVer + \"\\\"\";\r\n try {\r\n let stdout = yield processHelpers.exec(command);\r\n if (stdout) {\r\n let lines = stdout.split(\"\\r\\n\").filter(function (line) {\r\n return line.length > 10;\r\n });\r\n if (lines.length >= 3) {\r\n return true;\r\n }\r\n }\r\n }\r\n catch (e) {\r\n _.noop(e);\r\n }\r\n return false;\r\n })\r\n};\r\n\r\nmodule.exports = vsDetect;\r\n"],"file":"vsDetect.js"} \ No newline at end of file diff --git a/lib/es6/vsDetect.js b/lib/es6/vsDetect.js deleted file mode 100644 index 96d6fe70..00000000 --- a/lib/es6/vsDetect.js +++ /dev/null @@ -1,95 +0,0 @@ -"use strict"; -let processHelpers = require("./processHelpers"); -let Promise = require("bluebird"); -let async = Promise.coroutine; -let _ = require("lodash"); -let path = require("path"); - -let vsDetect = { - isInstalled: async(function* (version) { - let vsInstalled = (yield this._isVSInstalled(version)); - let vsvNextInstalled = (yield this._isVSvNextInstalled(version)); - let buildToolsInstalled = (yield this._isBuildToolsInstalled(version)); - let foundByVSWhere = (yield this._isFoundByVSWhere(version)); - - return vsInstalled || vsvNextInstalled || buildToolsInstalled || foundByVSWhere; - }), - _isFoundByVSWhere: async(function* (version) { - // TODO: with auto download - /* - let mainVer = version.split(".")[0]; - let command = path.resolve("vswhere.exe"); - try { - let stdout = yield processHelpers.exec(command, ["-version", version]); - return stdout && stdout.indexOf("installationVersion: " + mainVer) > 0; - } - catch (e) { - _.noop(e); - } - */ - return false; - }), - _isBuildToolsInstalled: async(function*(version) { - let mainVer = version.split(".")[0]; - let key; - let testPhrase; - if (Number(mainVer) >= 15) { - key = "HKLM\\SOFTWARE\\Classes\\Installer\\Dependencies\\Microsoft.VS.windows_toolscore,v" + mainVer; - testPhrase = "Version"; - } - else { - key = "HKLM\\SOFTWARE\\Classes\\Installer\\Dependencies\\Microsoft.VS.VisualCppBuildTools_x86_enu,v" + mainVer; - testPhrase = "Visual C++"; - } - let command = "reg query \"" + key + "\""; - try { - let stdout = yield processHelpers.exec(command); - return stdout && stdout.indexOf(testPhrase) > 0; - } - catch (e) { - _.noop(e); - } - return false; - }), - _isVSInstalled: async(function*(version) { - // On x64 this will look for x64 keys only, but if VS and compilers installed properly, - // it will write it's keys to 64 bit registry as well. - let command = "reg query \"HKLM\\Software\\Microsoft\\VisualStudio\\" + version + "\""; - try { - let stdout = yield processHelpers.exec(command); - if (stdout) { - let lines = stdout.split("\r\n").filter(function (line) { - return line.length > 10; - }); - if (lines.length >= 4) { - return true; - } - } - } - catch (e) { - _.noop(e); - } - return false; - }), - _isVSvNextInstalled: async(function*(version) { - let mainVer = version.split(".")[0]; - let command = "reg query \"HKLM\\SOFTWARE\\Classes\\Installer\\Dependencies\\Microsoft.VisualStudio.MinShell.Msi,v" + mainVer + "\""; - try { - let stdout = yield processHelpers.exec(command); - if (stdout) { - let lines = stdout.split("\r\n").filter(function (line) { - return line.length > 10; - }); - if (lines.length >= 3) { - return true; - } - } - } - catch (e) { - _.noop(e); - } - return false; - }) -}; - -module.exports = vsDetect; From 1d854b5ad8a8e70e29fe1cd29479c3a52200653b Mon Sep 17 00:00:00 2001 From: Nik McG Date: Tue, 28 May 2019 12:57:15 -0400 Subject: [PATCH 4/7] Add Visual CPP build tools check --- lib/es6/toolset.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/es6/toolset.js b/lib/es6/toolset.js index d82740d8..635d97b0 100644 --- a/lib/es6/toolset.js +++ b/lib/es6/toolset.js @@ -175,7 +175,6 @@ Toolset.prototype.initializeWin = async(function*(install) { }); Toolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() { - let CMake = require("./cMake"); assert(environment.isWin); let programFilesPath = _.get(process.env, "ProgramFiles(x86)", _.get(process.env, "ProgramFiles")); @@ -183,17 +182,27 @@ Toolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() { const vswhereOutput = yield processHelpers.exec(`"${vswhereCommand}" -property installationVersion`); if (!vswhereOutput) { - return null; // What should be returned here? + return null; } let version = vswhereOutput.trim(); version = version.substring(0, version.indexOf(".")); - - return { + const generator = { "14": "Visual Studio 14 2015", "15": "Visual Studio 15 2017", "16": "Visual Studio 16 2019", - }[version] || null; + }[version]; + + if (!generator) { + return null; + } + + const cppBuildToolsOutput = yield processHelpers.exec(`"${vswhereCommand}" -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64`); + if (!cppBuildToolsOutput || cppBuildToolsOutput.indexOf("installationVersion: " + version) === -1) { + return null; + } + + return generator; }); module.exports = Toolset; From 21777fc6f5e0afbb39a529ff1255ab71fb116d43 Mon Sep 17 00:00:00 2001 From: Nik McG Date: Tue, 28 May 2019 14:09:19 -0400 Subject: [PATCH 5/7] Add support for windows-build-tools package --- lib/es5/toolset.js | 73 +++++++++++++++++++++++++++++++++++------- lib/es5/toolset.js.map | 2 +- lib/es6/toolset.js | 25 ++++++++++++++- 3 files changed, 86 insertions(+), 14 deletions(-) diff --git a/lib/es5/toolset.js b/lib/es5/toolset.js index 59f0c234..4f1a3a3e 100644 --- a/lib/es5/toolset.js +++ b/lib/es5/toolset.js @@ -186,22 +186,30 @@ Toolset.prototype.initializeWin = async($traceurRuntime.initGeneratorFunction(fu }, $__2, this); })); Toolset.prototype._getTopSupportedVisualStudioGenerator = async($traceurRuntime.initGeneratorFunction(function $__3() { - var CMake, + var hasWindowsBuildToolsPackage, programFilesPath, vswhereCommand, vswhereOutput, - version; + version, + generator, + cppBuildToolsOutput; return $traceurRuntime.createGeneratorInstance(function($ctx) { while (true) switch ($ctx.state) { case 0: - CMake = require("./cMake"); assert(environment.isWin); + hasWindowsBuildToolsPackage = false; + try { + hasGlobalPackage("windows-build-tools"); + hasWindowsBuildToolsPackage = true; + } catch (e) { + console.log("no windows-build-tools", e); + } programFilesPath = _.get(process.env, "ProgramFiles(x86)", _.get(process.env, "ProgramFiles")); vswhereCommand = path.resolve(programFilesPath, "Microsoft Visual Studio", "Installer", "vswhere.exe"); - $ctx.state = 11; + $ctx.state = 24; break; - case 11: + case 24: $ctx.state = 2; return processHelpers.exec(("\"" + vswhereCommand + "\" -property installationVersion")); case 2: @@ -209,23 +217,52 @@ Toolset.prototype._getTopSupportedVisualStudioGenerator = async($traceurRuntime. $ctx.state = 4; break; case 4: - $ctx.state = (!vswhereOutput) ? 5 : 6; + $ctx.state = (!vswhereOutput) ? 7 : 9; + break; + case 7: + $ctx.state = (hasWindowsBuildToolsPackage) ? 5 : 6; break; case 5: - $ctx.returnValue = null; + $ctx.returnValue = "Visual Studio 15 2017"; $ctx.state = -2; break; case 6: + $ctx.returnValue = null; + $ctx.state = -2; + break; + case 9: version = vswhereOutput.trim(); version = version.substring(0, version.indexOf(".")); - $ctx.state = 13; - break; - case 13: - $ctx.returnValue = { + generator = { "14": "Visual Studio 14 2015", "15": "Visual Studio 15 2017", "16": "Visual Studio 16 2019" - }[version] || null; + }[version]; + $ctx.state = 26; + break; + case 26: + $ctx.state = (!generator) ? 11 : 12; + break; + case 11: + $ctx.returnValue = null; + $ctx.state = -2; + break; + case 12: + $ctx.state = 15; + return processHelpers.exec(("\"" + vswhereCommand + "\" -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64")); + case 15: + cppBuildToolsOutput = $ctx.sent; + $ctx.state = 17; + break; + case 17: + $ctx.state = (!cppBuildToolsOutput || cppBuildToolsOutput.indexOf("installationVersion: " + version) === -1) ? 18 : 19; + break; + case 18: + $ctx.returnValue = null; + $ctx.state = -2; + break; + case 19: + $ctx.returnValue = generator; $ctx.state = -2; break; default: @@ -234,5 +271,17 @@ Toolset.prototype._getTopSupportedVisualStudioGenerator = async($traceurRuntime. }, $__3, this); })); module.exports = Toolset; +function hasGlobalPackage(packageName) { + var childProcess = require('child_process'); + var path = require('path'); + var fs = require('fs'); + var globalNodeModules = childProcess.execSync('npm root -g').toString().trim(); + var packageDir = path.join(globalNodeModules, packageName); + if (fs.existsSync(packageDir)) { + return true; + } + packageDir = path.join(globalNodeModules, 'npm/node_modules', packageName); + return fs.existsSync(packageDir); +} //# sourceMappingURL=toolset.js.map diff --git a/lib/es5/toolset.js.map b/lib/es5/toolset.js.map index dd0f2ca3..a760c4a0 100644 --- a/lib/es5/toolset.js.map +++ b/lib/es5/toolset.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["toolset.js"],"sourcesContent":["\"use strict\";\nlet Promise = require(\"bluebird\");\nlet async = Promise.coroutine;\nlet _ = require(\"lodash\");\nlet TargetOptions = require(\"./targetOptions\");\nlet environment = require(\"./environment\");\nlet assert = require(\"assert\");\nlet path = require(\"path\");\nlet CMLog = require(\"./cmLog\");\nlet processHelpers = require(\"./processHelpers\");\n\nfunction Toolset(options) {\n this.options = options || {};\n this.targetOptions = new TargetOptions(this.options);\n this.generator = options.generator;\n this.toolset = options.toolset;\n this.target = options.target;\n this.cCompilerPath = null;\n this.cppCompilerPath = null;\n this.compilerFlags = [];\n this.linkerFlags = [];\n this.makePath = null;\n this.log = new CMLog(this.options);\n this._initialized = false;\n}\n\nToolset.prototype.initialize = async(function*(install) {\n if (!this._initialized) {\n if (environment.isWin) {\n yield this.initializeWin(install);\n }\n else {\n this.initializePosix(install);\n }\n this._initialized = true;\n }\n});\n\nToolset.prototype.initializePosix = function (install) {\n // 1: Compiler\n if (!environment.isGPPAvailable && !environment.isClangAvailable) {\n if (environment.isOSX) {\n throw new Error(\"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'.\");\n }\n else {\n throw new Error(\"C++ Compiler toolset is not available. Install proper compiler toolset with your package manager, eg. 'sudo apt-get install g++'.\");\n }\n }\n\n if (this.options.preferClang && environment.isClangAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using clang++ compiler, because preferClang option is set, and clang++ is available.\");\n }\n this.cppCompilerPath = \"clang++\";\n this.cCompilerPath = \"clang\";\n }\n else if (this.options.preferGnu && environment.isGPPAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using g++ compiler, because preferGnu option is set, and g++ is available.\");\n }\n this.cppCompilerPath = \"g++\";\n this.cCompilerPath = \"gcc\";\n }\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n }\n // 2: Generator\n else if (environment.isOSX) {\n if (this.options.preferXcode) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Xcode generator, because preferXcode option is set.\");\n }\n this.generator = \"Xcode\";\n }\n else if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n else {\n if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n\n // 3: Flags\n if (environment.isOSX) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting default OSX compiler flags.\");\n }\n\n this.compilerFlags.push(\"-D_DARWIN_USE_64_BIT_INODE=1\");\n this.compilerFlags.push(\"-D_LARGEFILE_SOURCE\");\n this.compilerFlags.push(\"-D_FILE_OFFSET_BITS=64\");\n this.compilerFlags.push(\"-DBUILDING_NODE_EXTENSION\");\n this.linkerFlags.push(\"-undefined dynamic_lookup\");\n }\n\n // 4: Build target\n if (this.options.target) {\n this.log.info(\"TOOL\", \"Building only the \" + this.options.target + \" target, as specified from the command line.\");\n }\n};\n\nToolset.prototype.initializeWin = async(function*(install) {\n // Visual Studio:\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n return;\n }\n let topVS = yield this._getTopSupportedVisualStudioGenerator();\n //if (!this.options.noMSVC) {\n if (topVS) {\n if (install) {\n this.log.info(\"TOOL\", `Using ${topVS} generator.`);\n }\n this.generator = topVS;\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n }\n else {\n throw new Error(\"There is no Visual C++ compiler installed. Install Visual C++ Build Toolset or Visual Studio.\");\n }\n});\n\nToolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() {\n let CMake = require(\"./cMake\");\n assert(environment.isWin);\n\n let programFilesPath = _.get(process.env, \"ProgramFiles(x86)\", _.get(process.env, \"ProgramFiles\"));\n let vswhereCommand = path.resolve(programFilesPath, \"Microsoft Visual Studio\", \"Installer\", \"vswhere.exe\");\n const vswhereOutput = yield processHelpers.exec(`\"${vswhereCommand}\" -property installationVersion`);\n\n if (!vswhereOutput) {\n return null; // What should be returned here?\n }\n\n let version = vswhereOutput.trim();\n version = version.substring(0, version.indexOf(\".\"));\n\n return {\n \"14\": \"Visual Studio 14 2015\",\n \"15\": \"Visual Studio 15 2017\",\n \"16\": \"Visual Studio 16 2019\",\n }[version] || null;\n});\n\nmodule.exports = Toolset;\n"],"file":"toolset.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["toolset.js"],"sourcesContent":["\"use strict\";\nlet Promise = require(\"bluebird\");\nlet async = Promise.coroutine;\nlet _ = require(\"lodash\");\nlet TargetOptions = require(\"./targetOptions\");\nlet environment = require(\"./environment\");\nlet assert = require(\"assert\");\nlet path = require(\"path\");\nlet CMLog = require(\"./cmLog\");\nlet processHelpers = require(\"./processHelpers\");\n\nfunction Toolset(options) {\n this.options = options || {};\n this.targetOptions = new TargetOptions(this.options);\n this.generator = options.generator;\n this.toolset = options.toolset;\n this.target = options.target;\n this.cCompilerPath = null;\n this.cppCompilerPath = null;\n this.compilerFlags = [];\n this.linkerFlags = [];\n this.makePath = null;\n this.log = new CMLog(this.options);\n this._initialized = false;\n}\n\nToolset.prototype.initialize = async(function*(install) {\n if (!this._initialized) {\n if (environment.isWin) {\n yield this.initializeWin(install);\n }\n else {\n this.initializePosix(install);\n }\n this._initialized = true;\n }\n});\n\nToolset.prototype.initializePosix = function (install) {\n // 1: Compiler\n if (!environment.isGPPAvailable && !environment.isClangAvailable) {\n if (environment.isOSX) {\n throw new Error(\"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'.\");\n }\n else {\n throw new Error(\"C++ Compiler toolset is not available. Install proper compiler toolset with your package manager, eg. 'sudo apt-get install g++'.\");\n }\n }\n\n if (this.options.preferClang && environment.isClangAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using clang++ compiler, because preferClang option is set, and clang++ is available.\");\n }\n this.cppCompilerPath = \"clang++\";\n this.cCompilerPath = \"clang\";\n }\n else if (this.options.preferGnu && environment.isGPPAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using g++ compiler, because preferGnu option is set, and g++ is available.\");\n }\n this.cppCompilerPath = \"g++\";\n this.cCompilerPath = \"gcc\";\n }\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n }\n // 2: Generator\n else if (environment.isOSX) {\n if (this.options.preferXcode) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Xcode generator, because preferXcode option is set.\");\n }\n this.generator = \"Xcode\";\n }\n else if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n else {\n if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n\n // 3: Flags\n if (environment.isOSX) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting default OSX compiler flags.\");\n }\n\n this.compilerFlags.push(\"-D_DARWIN_USE_64_BIT_INODE=1\");\n this.compilerFlags.push(\"-D_LARGEFILE_SOURCE\");\n this.compilerFlags.push(\"-D_FILE_OFFSET_BITS=64\");\n this.compilerFlags.push(\"-DBUILDING_NODE_EXTENSION\");\n this.linkerFlags.push(\"-undefined dynamic_lookup\");\n }\n\n // 4: Build target\n if (this.options.target) {\n this.log.info(\"TOOL\", \"Building only the \" + this.options.target + \" target, as specified from the command line.\");\n }\n};\n\nToolset.prototype.initializeWin = async(function*(install) {\n // Visual Studio:\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n return;\n }\n let topVS = yield this._getTopSupportedVisualStudioGenerator();\n //if (!this.options.noMSVC) {\n if (topVS) {\n if (install) {\n this.log.info(\"TOOL\", `Using ${topVS} generator.`);\n }\n this.generator = topVS;\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n }\n else {\n throw new Error(\"There is no Visual C++ compiler installed. Install Visual C++ Build Toolset or Visual Studio.\");\n }\n});\n\nToolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() {\n assert(environment.isWin);\n\n let hasWindowsBuildToolsPackage = false;\n try {\n hasGlobalPackage(\"windows-build-tools\");\n hasWindowsBuildToolsPackage = true;\n } catch(e) {console.log(\"no windows-build-tools\", e)}\n\n let programFilesPath = _.get(process.env, \"ProgramFiles(x86)\", _.get(process.env, \"ProgramFiles\"));\n let vswhereCommand = path.resolve(programFilesPath, \"Microsoft Visual Studio\", \"Installer\", \"vswhere.exe\");\n const vswhereOutput = yield processHelpers.exec(`\"${vswhereCommand}\" -property installationVersion`);\n if (!vswhereOutput) {\n if (hasWindowsBuildToolsPackage) {\n return \"Visual Studio 15 2017\";\n }\n return null;\n }\n\n let version = vswhereOutput.trim();\n version = version.substring(0, version.indexOf(\".\"));\n const generator = {\n \"14\": \"Visual Studio 14 2015\",\n \"15\": \"Visual Studio 15 2017\",\n \"16\": \"Visual Studio 16 2019\",\n }[version];\n\n if (!generator) {\n return null;\n }\n\n const cppBuildToolsOutput = yield processHelpers.exec(`\"${vswhereCommand}\" -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64`);\n if (!cppBuildToolsOutput || cppBuildToolsOutput.indexOf(\"installationVersion: \" + version) === -1) {\n return null;\n }\n\n return generator;\n});\n\nmodule.exports = Toolset;\n\nfunction hasGlobalPackage(packageName) {\n var childProcess = require('child_process');\n var path = require('path');\n var fs = require('fs');\n \n var globalNodeModules = childProcess.execSync('npm root -g').toString().trim();\n var packageDir = path.join(globalNodeModules, packageName);\n if (fs.existsSync(packageDir)) {\n return true;\n }\n \n packageDir = path.join(globalNodeModules, 'npm/node_modules', packageName); //find package required by old npm\n return fs.existsSync(packageDir);\n}\n"],"file":"toolset.js"} \ No newline at end of file diff --git a/lib/es6/toolset.js b/lib/es6/toolset.js index 635d97b0..07b3c513 100644 --- a/lib/es6/toolset.js +++ b/lib/es6/toolset.js @@ -177,11 +177,19 @@ Toolset.prototype.initializeWin = async(function*(install) { Toolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() { assert(environment.isWin); + let hasWindowsBuildToolsPackage = false; + try { + hasGlobalPackage("windows-build-tools"); + hasWindowsBuildToolsPackage = true; + } catch(e) {console.log("no windows-build-tools", e)} + let programFilesPath = _.get(process.env, "ProgramFiles(x86)", _.get(process.env, "ProgramFiles")); let vswhereCommand = path.resolve(programFilesPath, "Microsoft Visual Studio", "Installer", "vswhere.exe"); const vswhereOutput = yield processHelpers.exec(`"${vswhereCommand}" -property installationVersion`); - if (!vswhereOutput) { + if (hasWindowsBuildToolsPackage) { + return "Visual Studio 15 2017"; + } return null; } @@ -206,3 +214,18 @@ Toolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() { }); module.exports = Toolset; + +function hasGlobalPackage(packageName) { + var childProcess = require('child_process'); + var path = require('path'); + var fs = require('fs'); + + var globalNodeModules = childProcess.execSync('npm root -g').toString().trim(); + var packageDir = path.join(globalNodeModules, packageName); + if (fs.existsSync(packageDir)) { + return true; + } + + packageDir = path.join(globalNodeModules, 'npm/node_modules', packageName); //find package required by old npm + return fs.existsSync(packageDir); +} From c59f67cd30562d700e31ed4982848c5636735bb8 Mon Sep 17 00:00:00 2001 From: Nik McG Date: Tue, 28 May 2019 14:11:30 -0400 Subject: [PATCH 6/7] Removed console log --- lib/es5/toolset.js | 4 +--- lib/es5/toolset.js.map | 2 +- lib/es6/toolset.js | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/es5/toolset.js b/lib/es5/toolset.js index 4f1a3a3e..f85c36ff 100644 --- a/lib/es5/toolset.js +++ b/lib/es5/toolset.js @@ -202,9 +202,7 @@ Toolset.prototype._getTopSupportedVisualStudioGenerator = async($traceurRuntime. try { hasGlobalPackage("windows-build-tools"); hasWindowsBuildToolsPackage = true; - } catch (e) { - console.log("no windows-build-tools", e); - } + } catch (e) {} programFilesPath = _.get(process.env, "ProgramFiles(x86)", _.get(process.env, "ProgramFiles")); vswhereCommand = path.resolve(programFilesPath, "Microsoft Visual Studio", "Installer", "vswhere.exe"); $ctx.state = 24; diff --git a/lib/es5/toolset.js.map b/lib/es5/toolset.js.map index a760c4a0..738bb4fc 100644 --- a/lib/es5/toolset.js.map +++ b/lib/es5/toolset.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["toolset.js"],"sourcesContent":["\"use strict\";\nlet Promise = require(\"bluebird\");\nlet async = Promise.coroutine;\nlet _ = require(\"lodash\");\nlet TargetOptions = require(\"./targetOptions\");\nlet environment = require(\"./environment\");\nlet assert = require(\"assert\");\nlet path = require(\"path\");\nlet CMLog = require(\"./cmLog\");\nlet processHelpers = require(\"./processHelpers\");\n\nfunction Toolset(options) {\n this.options = options || {};\n this.targetOptions = new TargetOptions(this.options);\n this.generator = options.generator;\n this.toolset = options.toolset;\n this.target = options.target;\n this.cCompilerPath = null;\n this.cppCompilerPath = null;\n this.compilerFlags = [];\n this.linkerFlags = [];\n this.makePath = null;\n this.log = new CMLog(this.options);\n this._initialized = false;\n}\n\nToolset.prototype.initialize = async(function*(install) {\n if (!this._initialized) {\n if (environment.isWin) {\n yield this.initializeWin(install);\n }\n else {\n this.initializePosix(install);\n }\n this._initialized = true;\n }\n});\n\nToolset.prototype.initializePosix = function (install) {\n // 1: Compiler\n if (!environment.isGPPAvailable && !environment.isClangAvailable) {\n if (environment.isOSX) {\n throw new Error(\"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'.\");\n }\n else {\n throw new Error(\"C++ Compiler toolset is not available. Install proper compiler toolset with your package manager, eg. 'sudo apt-get install g++'.\");\n }\n }\n\n if (this.options.preferClang && environment.isClangAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using clang++ compiler, because preferClang option is set, and clang++ is available.\");\n }\n this.cppCompilerPath = \"clang++\";\n this.cCompilerPath = \"clang\";\n }\n else if (this.options.preferGnu && environment.isGPPAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using g++ compiler, because preferGnu option is set, and g++ is available.\");\n }\n this.cppCompilerPath = \"g++\";\n this.cCompilerPath = \"gcc\";\n }\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n }\n // 2: Generator\n else if (environment.isOSX) {\n if (this.options.preferXcode) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Xcode generator, because preferXcode option is set.\");\n }\n this.generator = \"Xcode\";\n }\n else if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n else {\n if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n\n // 3: Flags\n if (environment.isOSX) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting default OSX compiler flags.\");\n }\n\n this.compilerFlags.push(\"-D_DARWIN_USE_64_BIT_INODE=1\");\n this.compilerFlags.push(\"-D_LARGEFILE_SOURCE\");\n this.compilerFlags.push(\"-D_FILE_OFFSET_BITS=64\");\n this.compilerFlags.push(\"-DBUILDING_NODE_EXTENSION\");\n this.linkerFlags.push(\"-undefined dynamic_lookup\");\n }\n\n // 4: Build target\n if (this.options.target) {\n this.log.info(\"TOOL\", \"Building only the \" + this.options.target + \" target, as specified from the command line.\");\n }\n};\n\nToolset.prototype.initializeWin = async(function*(install) {\n // Visual Studio:\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n return;\n }\n let topVS = yield this._getTopSupportedVisualStudioGenerator();\n //if (!this.options.noMSVC) {\n if (topVS) {\n if (install) {\n this.log.info(\"TOOL\", `Using ${topVS} generator.`);\n }\n this.generator = topVS;\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n }\n else {\n throw new Error(\"There is no Visual C++ compiler installed. Install Visual C++ Build Toolset or Visual Studio.\");\n }\n});\n\nToolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() {\n assert(environment.isWin);\n\n let hasWindowsBuildToolsPackage = false;\n try {\n hasGlobalPackage(\"windows-build-tools\");\n hasWindowsBuildToolsPackage = true;\n } catch(e) {console.log(\"no windows-build-tools\", e)}\n\n let programFilesPath = _.get(process.env, \"ProgramFiles(x86)\", _.get(process.env, \"ProgramFiles\"));\n let vswhereCommand = path.resolve(programFilesPath, \"Microsoft Visual Studio\", \"Installer\", \"vswhere.exe\");\n const vswhereOutput = yield processHelpers.exec(`\"${vswhereCommand}\" -property installationVersion`);\n if (!vswhereOutput) {\n if (hasWindowsBuildToolsPackage) {\n return \"Visual Studio 15 2017\";\n }\n return null;\n }\n\n let version = vswhereOutput.trim();\n version = version.substring(0, version.indexOf(\".\"));\n const generator = {\n \"14\": \"Visual Studio 14 2015\",\n \"15\": \"Visual Studio 15 2017\",\n \"16\": \"Visual Studio 16 2019\",\n }[version];\n\n if (!generator) {\n return null;\n }\n\n const cppBuildToolsOutput = yield processHelpers.exec(`\"${vswhereCommand}\" -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64`);\n if (!cppBuildToolsOutput || cppBuildToolsOutput.indexOf(\"installationVersion: \" + version) === -1) {\n return null;\n }\n\n return generator;\n});\n\nmodule.exports = Toolset;\n\nfunction hasGlobalPackage(packageName) {\n var childProcess = require('child_process');\n var path = require('path');\n var fs = require('fs');\n \n var globalNodeModules = childProcess.execSync('npm root -g').toString().trim();\n var packageDir = path.join(globalNodeModules, packageName);\n if (fs.existsSync(packageDir)) {\n return true;\n }\n \n packageDir = path.join(globalNodeModules, 'npm/node_modules', packageName); //find package required by old npm\n return fs.existsSync(packageDir);\n}\n"],"file":"toolset.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["toolset.js"],"sourcesContent":["\"use strict\";\nlet Promise = require(\"bluebird\");\nlet async = Promise.coroutine;\nlet _ = require(\"lodash\");\nlet TargetOptions = require(\"./targetOptions\");\nlet environment = require(\"./environment\");\nlet assert = require(\"assert\");\nlet path = require(\"path\");\nlet CMLog = require(\"./cmLog\");\nlet processHelpers = require(\"./processHelpers\");\n\nfunction Toolset(options) {\n this.options = options || {};\n this.targetOptions = new TargetOptions(this.options);\n this.generator = options.generator;\n this.toolset = options.toolset;\n this.target = options.target;\n this.cCompilerPath = null;\n this.cppCompilerPath = null;\n this.compilerFlags = [];\n this.linkerFlags = [];\n this.makePath = null;\n this.log = new CMLog(this.options);\n this._initialized = false;\n}\n\nToolset.prototype.initialize = async(function*(install) {\n if (!this._initialized) {\n if (environment.isWin) {\n yield this.initializeWin(install);\n }\n else {\n this.initializePosix(install);\n }\n this._initialized = true;\n }\n});\n\nToolset.prototype.initializePosix = function (install) {\n // 1: Compiler\n if (!environment.isGPPAvailable && !environment.isClangAvailable) {\n if (environment.isOSX) {\n throw new Error(\"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'.\");\n }\n else {\n throw new Error(\"C++ Compiler toolset is not available. Install proper compiler toolset with your package manager, eg. 'sudo apt-get install g++'.\");\n }\n }\n\n if (this.options.preferClang && environment.isClangAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using clang++ compiler, because preferClang option is set, and clang++ is available.\");\n }\n this.cppCompilerPath = \"clang++\";\n this.cCompilerPath = \"clang\";\n }\n else if (this.options.preferGnu && environment.isGPPAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using g++ compiler, because preferGnu option is set, and g++ is available.\");\n }\n this.cppCompilerPath = \"g++\";\n this.cCompilerPath = \"gcc\";\n }\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n }\n // 2: Generator\n else if (environment.isOSX) {\n if (this.options.preferXcode) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Xcode generator, because preferXcode option is set.\");\n }\n this.generator = \"Xcode\";\n }\n else if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n else {\n if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n\n // 3: Flags\n if (environment.isOSX) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting default OSX compiler flags.\");\n }\n\n this.compilerFlags.push(\"-D_DARWIN_USE_64_BIT_INODE=1\");\n this.compilerFlags.push(\"-D_LARGEFILE_SOURCE\");\n this.compilerFlags.push(\"-D_FILE_OFFSET_BITS=64\");\n this.compilerFlags.push(\"-DBUILDING_NODE_EXTENSION\");\n this.linkerFlags.push(\"-undefined dynamic_lookup\");\n }\n\n // 4: Build target\n if (this.options.target) {\n this.log.info(\"TOOL\", \"Building only the \" + this.options.target + \" target, as specified from the command line.\");\n }\n};\n\nToolset.prototype.initializeWin = async(function*(install) {\n // Visual Studio:\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n return;\n }\n let topVS = yield this._getTopSupportedVisualStudioGenerator();\n //if (!this.options.noMSVC) {\n if (topVS) {\n if (install) {\n this.log.info(\"TOOL\", `Using ${topVS} generator.`);\n }\n this.generator = topVS;\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n }\n else {\n throw new Error(\"There is no Visual C++ compiler installed. Install Visual C++ Build Toolset or Visual Studio.\");\n }\n});\n\nToolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() {\n assert(environment.isWin);\n\n let hasWindowsBuildToolsPackage = false;\n try {\n hasGlobalPackage(\"windows-build-tools\");\n hasWindowsBuildToolsPackage = true;\n } catch(e) {}\n\n let programFilesPath = _.get(process.env, \"ProgramFiles(x86)\", _.get(process.env, \"ProgramFiles\"));\n let vswhereCommand = path.resolve(programFilesPath, \"Microsoft Visual Studio\", \"Installer\", \"vswhere.exe\");\n const vswhereOutput = yield processHelpers.exec(`\"${vswhereCommand}\" -property installationVersion`);\n if (!vswhereOutput) {\n if (hasWindowsBuildToolsPackage) {\n return \"Visual Studio 15 2017\";\n }\n return null;\n }\n\n let version = vswhereOutput.trim();\n version = version.substring(0, version.indexOf(\".\"));\n const generator = {\n \"14\": \"Visual Studio 14 2015\",\n \"15\": \"Visual Studio 15 2017\",\n \"16\": \"Visual Studio 16 2019\",\n }[version];\n\n if (!generator) {\n return null;\n }\n\n const cppBuildToolsOutput = yield processHelpers.exec(`\"${vswhereCommand}\" -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64`);\n if (!cppBuildToolsOutput || cppBuildToolsOutput.indexOf(\"installationVersion: \" + version) === -1) {\n return null;\n }\n\n return generator;\n});\n\nmodule.exports = Toolset;\n\nfunction hasGlobalPackage(packageName) {\n var childProcess = require('child_process');\n var path = require('path');\n var fs = require('fs');\n \n var globalNodeModules = childProcess.execSync('npm root -g').toString().trim();\n var packageDir = path.join(globalNodeModules, packageName);\n if (fs.existsSync(packageDir)) {\n return true;\n }\n \n packageDir = path.join(globalNodeModules, 'npm/node_modules', packageName); //find package required by old npm\n return fs.existsSync(packageDir);\n}\n"],"file":"toolset.js"} \ No newline at end of file diff --git a/lib/es6/toolset.js b/lib/es6/toolset.js index 07b3c513..f344603c 100644 --- a/lib/es6/toolset.js +++ b/lib/es6/toolset.js @@ -181,7 +181,7 @@ Toolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() { try { hasGlobalPackage("windows-build-tools"); hasWindowsBuildToolsPackage = true; - } catch(e) {console.log("no windows-build-tools", e)} + } catch(e) {} let programFilesPath = _.get(process.env, "ProgramFiles(x86)", _.get(process.env, "ProgramFiles")); let vswhereCommand = path.resolve(programFilesPath, "Microsoft Visual Studio", "Installer", "vswhere.exe"); From 5b3e7b68b62cbd2bf6de8d58bf444604cbc6ae27 Mon Sep 17 00:00:00 2001 From: Nik McG Date: Wed, 29 May 2019 09:55:33 -0400 Subject: [PATCH 7/7] Fixed window-build-tools check --- lib/es5/toolset.js | 52 +++++++++++++++++------------------------- lib/es5/toolset.js.map | 2 +- lib/es6/toolset.js | 17 +++++--------- 3 files changed, 28 insertions(+), 43 deletions(-) diff --git a/lib/es5/toolset.js b/lib/es5/toolset.js index f85c36ff..79d5fc5d 100644 --- a/lib/es5/toolset.js +++ b/lib/es5/toolset.js @@ -186,8 +186,7 @@ Toolset.prototype.initializeWin = async($traceurRuntime.initGeneratorFunction(fu }, $__2, this); })); Toolset.prototype._getTopSupportedVisualStudioGenerator = async($traceurRuntime.initGeneratorFunction(function $__3() { - var hasWindowsBuildToolsPackage, - programFilesPath, + var programFilesPath, vswhereCommand, vswhereOutput, version, @@ -198,16 +197,11 @@ Toolset.prototype._getTopSupportedVisualStudioGenerator = async($traceurRuntime. switch ($ctx.state) { case 0: assert(environment.isWin); - hasWindowsBuildToolsPackage = false; - try { - hasGlobalPackage("windows-build-tools"); - hasWindowsBuildToolsPackage = true; - } catch (e) {} programFilesPath = _.get(process.env, "ProgramFiles(x86)", _.get(process.env, "ProgramFiles")); vswhereCommand = path.resolve(programFilesPath, "Microsoft Visual Studio", "Installer", "vswhere.exe"); - $ctx.state = 24; + $ctx.state = 21; break; - case 24: + case 21: $ctx.state = 2; return processHelpers.exec(("\"" + vswhereCommand + "\" -property installationVersion")); case 2: @@ -215,20 +209,13 @@ Toolset.prototype._getTopSupportedVisualStudioGenerator = async($traceurRuntime. $ctx.state = 4; break; case 4: - $ctx.state = (!vswhereOutput) ? 7 : 9; - break; - case 7: - $ctx.state = (hasWindowsBuildToolsPackage) ? 5 : 6; + $ctx.state = (!vswhereOutput) ? 5 : 6; break; case 5: - $ctx.returnValue = "Visual Studio 15 2017"; + $ctx.returnValue = windowBuildToolsPackageGeneratorOrNull(); $ctx.state = -2; break; case 6: - $ctx.returnValue = null; - $ctx.state = -2; - break; - case 9: version = vswhereOutput.trim(); version = version.substring(0, version.indexOf(".")); generator = { @@ -236,30 +223,30 @@ Toolset.prototype._getTopSupportedVisualStudioGenerator = async($traceurRuntime. "15": "Visual Studio 15 2017", "16": "Visual Studio 16 2019" }[version]; - $ctx.state = 26; + $ctx.state = 23; break; - case 26: - $ctx.state = (!generator) ? 11 : 12; + case 23: + $ctx.state = (!generator) ? 8 : 9; break; - case 11: - $ctx.returnValue = null; + case 8: + $ctx.returnValue = windowBuildToolsPackageGeneratorOrNull(); $ctx.state = -2; break; - case 12: - $ctx.state = 15; + case 9: + $ctx.state = 12; return processHelpers.exec(("\"" + vswhereCommand + "\" -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64")); - case 15: + case 12: cppBuildToolsOutput = $ctx.sent; - $ctx.state = 17; + $ctx.state = 14; break; - case 17: - $ctx.state = (!cppBuildToolsOutput || cppBuildToolsOutput.indexOf("installationVersion: " + version) === -1) ? 18 : 19; + case 14: + $ctx.state = (!cppBuildToolsOutput || cppBuildToolsOutput.indexOf("installationVersion: " + version) === -1) ? 15 : 16; break; - case 18: + case 15: $ctx.returnValue = null; $ctx.state = -2; break; - case 19: + case 16: $ctx.returnValue = generator; $ctx.state = -2; break; @@ -269,6 +256,9 @@ Toolset.prototype._getTopSupportedVisualStudioGenerator = async($traceurRuntime. }, $__3, this); })); module.exports = Toolset; +function windowBuildToolsPackageGeneratorOrNull() { + return hasGlobalPackage("windows-build-tools") ? "Visual Studio 15 2017" : null; +} function hasGlobalPackage(packageName) { var childProcess = require('child_process'); var path = require('path'); diff --git a/lib/es5/toolset.js.map b/lib/es5/toolset.js.map index 738bb4fc..d684f9a0 100644 --- a/lib/es5/toolset.js.map +++ b/lib/es5/toolset.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["toolset.js"],"sourcesContent":["\"use strict\";\nlet Promise = require(\"bluebird\");\nlet async = Promise.coroutine;\nlet _ = require(\"lodash\");\nlet TargetOptions = require(\"./targetOptions\");\nlet environment = require(\"./environment\");\nlet assert = require(\"assert\");\nlet path = require(\"path\");\nlet CMLog = require(\"./cmLog\");\nlet processHelpers = require(\"./processHelpers\");\n\nfunction Toolset(options) {\n this.options = options || {};\n this.targetOptions = new TargetOptions(this.options);\n this.generator = options.generator;\n this.toolset = options.toolset;\n this.target = options.target;\n this.cCompilerPath = null;\n this.cppCompilerPath = null;\n this.compilerFlags = [];\n this.linkerFlags = [];\n this.makePath = null;\n this.log = new CMLog(this.options);\n this._initialized = false;\n}\n\nToolset.prototype.initialize = async(function*(install) {\n if (!this._initialized) {\n if (environment.isWin) {\n yield this.initializeWin(install);\n }\n else {\n this.initializePosix(install);\n }\n this._initialized = true;\n }\n});\n\nToolset.prototype.initializePosix = function (install) {\n // 1: Compiler\n if (!environment.isGPPAvailable && !environment.isClangAvailable) {\n if (environment.isOSX) {\n throw new Error(\"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'.\");\n }\n else {\n throw new Error(\"C++ Compiler toolset is not available. Install proper compiler toolset with your package manager, eg. 'sudo apt-get install g++'.\");\n }\n }\n\n if (this.options.preferClang && environment.isClangAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using clang++ compiler, because preferClang option is set, and clang++ is available.\");\n }\n this.cppCompilerPath = \"clang++\";\n this.cCompilerPath = \"clang\";\n }\n else if (this.options.preferGnu && environment.isGPPAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using g++ compiler, because preferGnu option is set, and g++ is available.\");\n }\n this.cppCompilerPath = \"g++\";\n this.cCompilerPath = \"gcc\";\n }\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n }\n // 2: Generator\n else if (environment.isOSX) {\n if (this.options.preferXcode) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Xcode generator, because preferXcode option is set.\");\n }\n this.generator = \"Xcode\";\n }\n else if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n else {\n if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n\n // 3: Flags\n if (environment.isOSX) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting default OSX compiler flags.\");\n }\n\n this.compilerFlags.push(\"-D_DARWIN_USE_64_BIT_INODE=1\");\n this.compilerFlags.push(\"-D_LARGEFILE_SOURCE\");\n this.compilerFlags.push(\"-D_FILE_OFFSET_BITS=64\");\n this.compilerFlags.push(\"-DBUILDING_NODE_EXTENSION\");\n this.linkerFlags.push(\"-undefined dynamic_lookup\");\n }\n\n // 4: Build target\n if (this.options.target) {\n this.log.info(\"TOOL\", \"Building only the \" + this.options.target + \" target, as specified from the command line.\");\n }\n};\n\nToolset.prototype.initializeWin = async(function*(install) {\n // Visual Studio:\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n return;\n }\n let topVS = yield this._getTopSupportedVisualStudioGenerator();\n //if (!this.options.noMSVC) {\n if (topVS) {\n if (install) {\n this.log.info(\"TOOL\", `Using ${topVS} generator.`);\n }\n this.generator = topVS;\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n }\n else {\n throw new Error(\"There is no Visual C++ compiler installed. Install Visual C++ Build Toolset or Visual Studio.\");\n }\n});\n\nToolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() {\n assert(environment.isWin);\n\n let hasWindowsBuildToolsPackage = false;\n try {\n hasGlobalPackage(\"windows-build-tools\");\n hasWindowsBuildToolsPackage = true;\n } catch(e) {}\n\n let programFilesPath = _.get(process.env, \"ProgramFiles(x86)\", _.get(process.env, \"ProgramFiles\"));\n let vswhereCommand = path.resolve(programFilesPath, \"Microsoft Visual Studio\", \"Installer\", \"vswhere.exe\");\n const vswhereOutput = yield processHelpers.exec(`\"${vswhereCommand}\" -property installationVersion`);\n if (!vswhereOutput) {\n if (hasWindowsBuildToolsPackage) {\n return \"Visual Studio 15 2017\";\n }\n return null;\n }\n\n let version = vswhereOutput.trim();\n version = version.substring(0, version.indexOf(\".\"));\n const generator = {\n \"14\": \"Visual Studio 14 2015\",\n \"15\": \"Visual Studio 15 2017\",\n \"16\": \"Visual Studio 16 2019\",\n }[version];\n\n if (!generator) {\n return null;\n }\n\n const cppBuildToolsOutput = yield processHelpers.exec(`\"${vswhereCommand}\" -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64`);\n if (!cppBuildToolsOutput || cppBuildToolsOutput.indexOf(\"installationVersion: \" + version) === -1) {\n return null;\n }\n\n return generator;\n});\n\nmodule.exports = Toolset;\n\nfunction hasGlobalPackage(packageName) {\n var childProcess = require('child_process');\n var path = require('path');\n var fs = require('fs');\n \n var globalNodeModules = childProcess.execSync('npm root -g').toString().trim();\n var packageDir = path.join(globalNodeModules, packageName);\n if (fs.existsSync(packageDir)) {\n return true;\n }\n \n packageDir = path.join(globalNodeModules, 'npm/node_modules', packageName); //find package required by old npm\n return fs.existsSync(packageDir);\n}\n"],"file":"toolset.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["toolset.js"],"sourcesContent":["\"use strict\";\nlet Promise = require(\"bluebird\");\nlet async = Promise.coroutine;\nlet _ = require(\"lodash\");\nlet TargetOptions = require(\"./targetOptions\");\nlet environment = require(\"./environment\");\nlet assert = require(\"assert\");\nlet path = require(\"path\");\nlet CMLog = require(\"./cmLog\");\nlet processHelpers = require(\"./processHelpers\");\n\nfunction Toolset(options) {\n this.options = options || {};\n this.targetOptions = new TargetOptions(this.options);\n this.generator = options.generator;\n this.toolset = options.toolset;\n this.target = options.target;\n this.cCompilerPath = null;\n this.cppCompilerPath = null;\n this.compilerFlags = [];\n this.linkerFlags = [];\n this.makePath = null;\n this.log = new CMLog(this.options);\n this._initialized = false;\n}\n\nToolset.prototype.initialize = async(function*(install) {\n if (!this._initialized) {\n if (environment.isWin) {\n yield this.initializeWin(install);\n }\n else {\n this.initializePosix(install);\n }\n this._initialized = true;\n }\n});\n\nToolset.prototype.initializePosix = function (install) {\n // 1: Compiler\n if (!environment.isGPPAvailable && !environment.isClangAvailable) {\n if (environment.isOSX) {\n throw new Error(\"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'.\");\n }\n else {\n throw new Error(\"C++ Compiler toolset is not available. Install proper compiler toolset with your package manager, eg. 'sudo apt-get install g++'.\");\n }\n }\n\n if (this.options.preferClang && environment.isClangAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using clang++ compiler, because preferClang option is set, and clang++ is available.\");\n }\n this.cppCompilerPath = \"clang++\";\n this.cCompilerPath = \"clang\";\n }\n else if (this.options.preferGnu && environment.isGPPAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using g++ compiler, because preferGnu option is set, and g++ is available.\");\n }\n this.cppCompilerPath = \"g++\";\n this.cCompilerPath = \"gcc\";\n }\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n }\n // 2: Generator\n else if (environment.isOSX) {\n if (this.options.preferXcode) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Xcode generator, because preferXcode option is set.\");\n }\n this.generator = \"Xcode\";\n }\n else if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n else {\n if (this.options.preferMake && environment.isMakeAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n else if (environment.isNinjaAvailable) {\n if (install) {\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\n }\n this.generator = \"Ninja\";\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\n }\n this.generator = \"Unix Makefiles\";\n }\n }\n\n // 3: Flags\n if (environment.isOSX) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting default OSX compiler flags.\");\n }\n\n this.compilerFlags.push(\"-D_DARWIN_USE_64_BIT_INODE=1\");\n this.compilerFlags.push(\"-D_LARGEFILE_SOURCE\");\n this.compilerFlags.push(\"-D_FILE_OFFSET_BITS=64\");\n this.compilerFlags.push(\"-DBUILDING_NODE_EXTENSION\");\n this.linkerFlags.push(\"-undefined dynamic_lookup\");\n }\n\n // 4: Build target\n if (this.options.target) {\n this.log.info(\"TOOL\", \"Building only the \" + this.options.target + \" target, as specified from the command line.\");\n }\n};\n\nToolset.prototype.initializeWin = async(function*(install) {\n // Visual Studio:\n // if it's already set because of options...\n if (this.generator) {\n if (install) {\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\n }\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n return;\n }\n let topVS = yield this._getTopSupportedVisualStudioGenerator();\n //if (!this.options.noMSVC) {\n if (topVS) {\n if (install) {\n this.log.info(\"TOOL\", `Using ${topVS} generator.`);\n }\n this.generator = topVS;\n\n this.linkerFlags.push(\"/DELAYLOAD:NODE.EXE\");\n\n if (this.targetOptions.isX86) {\n if (install) {\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\n }\n this.linkerFlags.push(\"/SAFESEH:NO\");\n }\n }\n else {\n throw new Error(\"There is no Visual C++ compiler installed. Install Visual C++ Build Toolset or Visual Studio.\");\n }\n});\n\nToolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() {\n assert(environment.isWin);\n\n let programFilesPath = _.get(process.env, \"ProgramFiles(x86)\", _.get(process.env, \"ProgramFiles\"));\n let vswhereCommand = path.resolve(programFilesPath, \"Microsoft Visual Studio\", \"Installer\", \"vswhere.exe\");\n const vswhereOutput = yield processHelpers.exec(`\"${vswhereCommand}\" -property installationVersion`);\n if (!vswhereOutput) {\n return windowBuildToolsPackageGeneratorOrNull();\n }\n\n let version = vswhereOutput.trim();\n version = version.substring(0, version.indexOf(\".\"));\n const generator = {\n \"14\": \"Visual Studio 14 2015\",\n \"15\": \"Visual Studio 15 2017\",\n \"16\": \"Visual Studio 16 2019\",\n }[version];\n\n if (!generator) {\n return windowBuildToolsPackageGeneratorOrNull();\n }\n\n const cppBuildToolsOutput = yield processHelpers.exec(`\"${vswhereCommand}\" -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64`);\n if (!cppBuildToolsOutput || cppBuildToolsOutput.indexOf(\"installationVersion: \" + version) === -1) {\n return null;\n }\n\n return generator;\n});\n\nmodule.exports = Toolset;\n\nfunction windowBuildToolsPackageGeneratorOrNull() {\n return hasGlobalPackage(\"windows-build-tools\") ? \"Visual Studio 15 2017\" : null;\n}\n\nfunction hasGlobalPackage(packageName) {\n var childProcess = require('child_process');\n var path = require('path');\n var fs = require('fs');\n \n var globalNodeModules = childProcess.execSync('npm root -g').toString().trim();\n var packageDir = path.join(globalNodeModules, packageName);\n if (fs.existsSync(packageDir)) {\n return true;\n }\n \n packageDir = path.join(globalNodeModules, 'npm/node_modules', packageName); //find package required by old npm\n return fs.existsSync(packageDir);\n}\n"],"file":"toolset.js"} \ No newline at end of file diff --git a/lib/es6/toolset.js b/lib/es6/toolset.js index f344603c..f04e6c90 100644 --- a/lib/es6/toolset.js +++ b/lib/es6/toolset.js @@ -177,20 +177,11 @@ Toolset.prototype.initializeWin = async(function*(install) { Toolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() { assert(environment.isWin); - let hasWindowsBuildToolsPackage = false; - try { - hasGlobalPackage("windows-build-tools"); - hasWindowsBuildToolsPackage = true; - } catch(e) {} - let programFilesPath = _.get(process.env, "ProgramFiles(x86)", _.get(process.env, "ProgramFiles")); let vswhereCommand = path.resolve(programFilesPath, "Microsoft Visual Studio", "Installer", "vswhere.exe"); const vswhereOutput = yield processHelpers.exec(`"${vswhereCommand}" -property installationVersion`); if (!vswhereOutput) { - if (hasWindowsBuildToolsPackage) { - return "Visual Studio 15 2017"; - } - return null; + return windowBuildToolsPackageGeneratorOrNull(); } let version = vswhereOutput.trim(); @@ -202,7 +193,7 @@ Toolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() { }[version]; if (!generator) { - return null; + return windowBuildToolsPackageGeneratorOrNull(); } const cppBuildToolsOutput = yield processHelpers.exec(`"${vswhereCommand}" -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64`); @@ -215,6 +206,10 @@ Toolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() { module.exports = Toolset; +function windowBuildToolsPackageGeneratorOrNull() { + return hasGlobalPackage("windows-build-tools") ? "Visual Studio 15 2017" : null; +} + function hasGlobalPackage(packageName) { var childProcess = require('child_process'); var path = require('path');