diff --git a/README.md b/README.md index 755b3057..5d60abea 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,7 @@ Options: -g, --prefer-gnu use GNU compiler instead of default CMake compiler, if available (Posix) [boolean] -G, --generator use specified generator [string] + -t, --toolset use specified toolset [string] -T, --target only build the specified target [string] -C, --prefer-clang use Clang compiler instead of default CMake compiler, if available (Posix) [boolean] diff --git a/bin/cmake-js b/bin/cmake-js index bd3b8bf9..37639977 100755 --- a/bin/cmake-js +++ b/bin/cmake-js @@ -78,6 +78,12 @@ var yargs = require("yargs") describe: "use specified generator", type: "string" }, + t: { + alias: "toolset", + demand: false, + describe: "use specified toolset", + type: "string" + }, T: { alias: "target", demand: false, @@ -170,6 +176,7 @@ var options = { debug: argv.debug, cmakePath: argv.c || null, generator: argv.G, + toolset: argv.t, target: argv.T, preferMake: argv.m, preferXcode: argv.x, diff --git a/lib/es5/appCMakeJSConfig.js.map b/lib/es5/appCMakeJSConfig.js.map index c817843b..d22e26fc 100644 --- a/lib/es5/appCMakeJSConfig.js.map +++ b/lib/es5/appCMakeJSConfig.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["appCMakeJSConfig.js"],"sourcesContent":["\"use strict\";\r\nlet path = require(\"path\");\r\nlet _ = require(\"lodash\");\r\n\r\nfunction getConfig(lookPath, log) {\r\n let pjsonPath = path.join(lookPath, \"package.json\");\r\n log.silly(\"CFG\", \"Looking for package.json in: '\" + pjsonPath + \"'.\");\r\n try {\r\n let json = require(pjsonPath);\r\n log.silly(\"CFG\", \"Loaded:\\n\" + JSON.stringify(json));\r\n if (_.isPlainObject(json) && _.isPlainObject(json[\"cmake-js\"])) {\r\n log.silly(\"CFG\", \"Config found.\");\r\n return json[\"cmake-js\"];\r\n }\r\n else {\r\n log.silly(\"CFG\", \"Config not found.\");\r\n return null;\r\n }\r\n }\r\n catch (e) {\r\n log.silly(\"CFG\", \"'package.json' not found.\");\r\n return null;\r\n }\r\n}\r\n\r\nmodule.exports = function (projectPath, log) {\r\n log.verbose(\"CFG\", \"Looking for application level CMake.js config in '\" + projectPath + \".\");\r\n let currPath = projectPath;\r\n let lastConfig = null;\r\n let currConfig;\r\n for (; ;) {\r\n currConfig = getConfig(currPath, log);\r\n if (currConfig) {\r\n lastConfig = currConfig;\r\n }\r\n try {\r\n log.silly(\"CFG\", \"Looking for parent path.\");\r\n let lastPath = currPath;\r\n currPath = path.normalize(path.join(currPath, \"..\"));\r\n if (lastPath === currPath) {\r\n currPath = null; // root\r\n }\r\n if (currPath) {\r\n log.silly(\"CFG\", \"Parent path: '\" + currPath + \"'.\");\r\n }\r\n }\r\n catch (e) {\r\n log.silly(\"CFG\", \"Exception:\\n\" + e.stack);\r\n break;\r\n }\r\n if (currPath === null) {\r\n log.silly(\"CFG\", \"Parent path with package.json file doesn't exists. Done.\");\r\n break;\r\n }\r\n }\r\n if (lastConfig) {\r\n log.verbose(\"CFG\", \"Application level CMake.js config found:\\n\" + JSON.stringify(lastConfig));\r\n }\r\n else {\r\n log.verbose(\"CFG\", \"Application level CMake.js config doesn't exists.\");\r\n }\r\n return lastConfig;\r\n};\r\n"],"file":"appCMakeJSConfig.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["appCMakeJSConfig.js"],"sourcesContent":["\"use strict\";\nlet path = require(\"path\");\nlet _ = require(\"lodash\");\n\nfunction getConfig(lookPath, log) {\n let pjsonPath = path.join(lookPath, \"package.json\");\n log.silly(\"CFG\", \"Looking for package.json in: '\" + pjsonPath + \"'.\");\n try {\n let json = require(pjsonPath);\n log.silly(\"CFG\", \"Loaded:\\n\" + JSON.stringify(json));\n if (_.isPlainObject(json) && _.isPlainObject(json[\"cmake-js\"])) {\n log.silly(\"CFG\", \"Config found.\");\n return json[\"cmake-js\"];\n }\n else {\n log.silly(\"CFG\", \"Config not found.\");\n return null;\n }\n }\n catch (e) {\n log.silly(\"CFG\", \"'package.json' not found.\");\n return null;\n }\n}\n\nmodule.exports = function (projectPath, log) {\n log.verbose(\"CFG\", \"Looking for application level CMake.js config in '\" + projectPath + \".\");\n let currPath = projectPath;\n let lastConfig = null;\n let currConfig;\n for (; ;) {\n currConfig = getConfig(currPath, log);\n if (currConfig) {\n lastConfig = currConfig;\n }\n try {\n log.silly(\"CFG\", \"Looking for parent path.\");\n let lastPath = currPath;\n currPath = path.normalize(path.join(currPath, \"..\"));\n if (lastPath === currPath) {\n currPath = null; // root\n }\n if (currPath) {\n log.silly(\"CFG\", \"Parent path: '\" + currPath + \"'.\");\n }\n }\n catch (e) {\n log.silly(\"CFG\", \"Exception:\\n\" + e.stack);\n break;\n }\n if (currPath === null) {\n log.silly(\"CFG\", \"Parent path with package.json file doesn't exists. Done.\");\n break;\n }\n }\n if (lastConfig) {\n log.verbose(\"CFG\", \"Application level CMake.js config found:\\n\" + JSON.stringify(lastConfig));\n }\n else {\n log.verbose(\"CFG\", \"Application level CMake.js config doesn't exists.\");\n }\n return lastConfig;\n};\n"],"file":"appCMakeJSConfig.js"} \ No newline at end of file diff --git a/lib/es5/buildSystem.js.map b/lib/es5/buildSystem.js.map index 32ba288c..6756f239 100644 --- a/lib/es5/buildSystem.js.map +++ b/lib/es5/buildSystem.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["buildSystem.js"],"sourcesContent":["\"use strict\";\r\nlet CMake = require(\"./cMake\");\r\nlet Dist = require(\"./dist\");\r\nlet CMLog = require(\"./cmLog\");\r\nlet appCMakeJSConfig = require(\"./appCMakeJSConfig\");\r\nlet path = require(\"path\");\r\nlet _ = require(\"lodash\");\r\nlet Bluebird = require(\"bluebird\");\r\nlet async = Bluebird.coroutine;\r\nlet Toolset = require(\"./toolset\");\r\n\r\nfunction BuildSystem(options) {\r\n this.options = options || {};\r\n this.options.directory = path.resolve(this.options.directory || process.cwd());\r\n this.log = new CMLog(this.options);\r\n let appConfig = appCMakeJSConfig(this.options.directory, this.log);\r\n if (_.isPlainObject(appConfig)) {\r\n if (_.keys(appConfig).length) {\r\n this.log.verbose(\"CFG\", \"Applying CMake.js config from root package.json:\");\r\n this.log.verbose(\"CFG\", JSON.stringify(appConfig));\r\n // Applying applications's config, if there is no explicit runtime related options specified\r\n this.options.runtime = this.options.runtime || appConfig.runtime;\r\n this.options.runtimeVersion = this.options.runtimeVersion || appConfig.runtimeVersion;\r\n this.options.arch = this.options.arch || appConfig.arch;\r\n }\r\n }\r\n this.log.verbose(\"CFG\", \"Build system options:\");\r\n this.log.verbose(\"CFG\", JSON.stringify(this.options));\r\n this.cmake = new CMake(this.options);\r\n this.dist = new Dist(this.options);\r\n this.toolset = new Toolset(this.options);\r\n}\r\n\r\nBuildSystem.prototype._ensureInstalled = async(function* () {\r\n try {\r\n yield this.toolset.initialize(true);\r\n yield this.dist.ensureDownloaded();\r\n }\r\n catch (e) {\r\n this._showError(e);\r\n throw e;\r\n }\r\n});\r\n\r\nBuildSystem.prototype._showError = function (e) {\r\n if (this.log.level === \"verbose\" || this.log.level === \"silly\") {\r\n this.log.error(\"OMG\", e.stack);\r\n }\r\n else {\r\n this.log.error(\"OMG\", e.message);\r\n }\r\n};\r\n\r\nBuildSystem.prototype.install = function () {\r\n return this._ensureInstalled();\r\n};\r\n\r\nBuildSystem.prototype._invokeCMake = async(function* (method) {\r\n try {\r\n yield this._ensureInstalled();\r\n return yield this.cmake[method]();\r\n }\r\n catch (e) {\r\n this._showError(e);\r\n throw e;\r\n }\r\n});\r\n\r\nBuildSystem.prototype.getConfigureCommand = function () {\r\n return this._invokeCMake(\"getConfigureCommand\");\r\n};\r\n\r\nBuildSystem.prototype.configure = function () {\r\n return this._invokeCMake(\"configure\");\r\n};\r\n\r\nBuildSystem.prototype.getBuildCommand = function () {\r\n return this._invokeCMake(\"getBuildCommand\");\r\n};\r\n\r\nBuildSystem.prototype.build = function () {\r\n return this._invokeCMake(\"build\");\r\n};\r\n\r\nBuildSystem.prototype.getCleanCommand = function () {\r\n return this._invokeCMake(\"getCleanCommand\");\r\n};\r\n\r\nBuildSystem.prototype.clean = function () {\r\n return this._invokeCMake(\"clean\");\r\n};\r\n\r\nBuildSystem.prototype.reconfigure = function () {\r\n return this._invokeCMake(\"reconfigure\");\r\n};\r\n\r\nBuildSystem.prototype.rebuild = function () {\r\n return this._invokeCMake(\"rebuild\");\r\n};\r\n\r\nBuildSystem.prototype.compile = function () {\r\n return this._invokeCMake(\"compile\");\r\n};\r\n\r\nmodule.exports = BuildSystem;\r\n"],"file":"buildSystem.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["buildSystem.js"],"sourcesContent":["\"use strict\";\nlet CMake = require(\"./cMake\");\nlet Dist = require(\"./dist\");\nlet CMLog = require(\"./cmLog\");\nlet appCMakeJSConfig = require(\"./appCMakeJSConfig\");\nlet path = require(\"path\");\nlet _ = require(\"lodash\");\nlet Bluebird = require(\"bluebird\");\nlet async = Bluebird.coroutine;\nlet Toolset = require(\"./toolset\");\n\nfunction BuildSystem(options) {\n this.options = options || {};\n this.options.directory = path.resolve(this.options.directory || process.cwd());\n this.log = new CMLog(this.options);\n let appConfig = appCMakeJSConfig(this.options.directory, this.log);\n if (_.isPlainObject(appConfig)) {\n if (_.keys(appConfig).length) {\n this.log.verbose(\"CFG\", \"Applying CMake.js config from root package.json:\");\n this.log.verbose(\"CFG\", JSON.stringify(appConfig));\n // Applying applications's config, if there is no explicit runtime related options specified\n this.options.runtime = this.options.runtime || appConfig.runtime;\n this.options.runtimeVersion = this.options.runtimeVersion || appConfig.runtimeVersion;\n this.options.arch = this.options.arch || appConfig.arch;\n }\n }\n this.log.verbose(\"CFG\", \"Build system options:\");\n this.log.verbose(\"CFG\", JSON.stringify(this.options));\n this.cmake = new CMake(this.options);\n this.dist = new Dist(this.options);\n this.toolset = new Toolset(this.options);\n}\n\nBuildSystem.prototype._ensureInstalled = async(function* () {\n try {\n yield this.toolset.initialize(true);\n yield this.dist.ensureDownloaded();\n }\n catch (e) {\n this._showError(e);\n throw e;\n }\n});\n\nBuildSystem.prototype._showError = function (e) {\n if (this.log.level === \"verbose\" || this.log.level === \"silly\") {\n this.log.error(\"OMG\", e.stack);\n }\n else {\n this.log.error(\"OMG\", e.message);\n }\n};\n\nBuildSystem.prototype.install = function () {\n return this._ensureInstalled();\n};\n\nBuildSystem.prototype._invokeCMake = async(function* (method) {\n try {\n yield this._ensureInstalled();\n return yield this.cmake[method]();\n }\n catch (e) {\n this._showError(e);\n throw e;\n }\n});\n\nBuildSystem.prototype.getConfigureCommand = function () {\n return this._invokeCMake(\"getConfigureCommand\");\n};\n\nBuildSystem.prototype.configure = function () {\n return this._invokeCMake(\"configure\");\n};\n\nBuildSystem.prototype.getBuildCommand = function () {\n return this._invokeCMake(\"getBuildCommand\");\n};\n\nBuildSystem.prototype.build = function () {\n return this._invokeCMake(\"build\");\n};\n\nBuildSystem.prototype.getCleanCommand = function () {\n return this._invokeCMake(\"getCleanCommand\");\n};\n\nBuildSystem.prototype.clean = function () {\n return this._invokeCMake(\"clean\");\n};\n\nBuildSystem.prototype.reconfigure = function () {\n return this._invokeCMake(\"reconfigure\");\n};\n\nBuildSystem.prototype.rebuild = function () {\n return this._invokeCMake(\"rebuild\");\n};\n\nBuildSystem.prototype.compile = function () {\n return this._invokeCMake(\"compile\");\n};\n\nmodule.exports = BuildSystem;\n"],"file":"buildSystem.js"} \ No newline at end of file diff --git a/lib/es5/cMake.js b/lib/es5/cMake.js index 9748db6f..a99eb24d 100644 --- a/lib/es5/cMake.js +++ b/lib/es5/cMake.js @@ -233,6 +233,9 @@ CMake.prototype.getConfigureCommand = async($traceurRuntime.initGeneratorFunctio if (this.toolset.generator) { command += " -G\"" + this.toolset.generator + "\""; } + if (this.toolset.toolset) { + command += " -T\"" + this.toolset.toolset + "\""; + } if (this.toolset.cppCompilerPath) { D.push({"CMAKE_CXX_COMPILER": this.toolset.cppCompilerPath}); } diff --git a/lib/es5/cMake.js.map b/lib/es5/cMake.js.map index 30b9a2c5..bdfbfaae 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\";\r\nlet splitargs = require(\"splitargs\");\r\nlet which = require(\"which\");\r\nlet Bluebird = require(\"bluebird\");\r\nlet fs = Bluebird.promisifyAll(require(\"fs-extra\"));\r\nlet path = require(\"path\");\r\nlet _ = require(\"lodash\");\r\nlet environment = require(\"./environment\");\r\nlet Dist = require(\"./dist\");\r\nlet CMLog = require(\"./cmLog\");\r\nlet vsDetect = require(\"./vsDetect\");\r\nlet TargetOptions = require(\"./targetOptions\");\r\nlet processHelpers = require(\"./processHelpers\");\r\nlet locateNAN = require(\"./locateNAN\");\r\nlet npmconf = Bluebird.promisifyAll(require(\"npmconf\"));\r\nlet async = Bluebird.coroutine;\r\nlet Toolset = require(\"./toolset\");\r\n\r\nfunction CMake(options) {\r\n this.options = options || {};\r\n this.log = new CMLog(this.options);\r\n this.dist = new Dist(this.options);\r\n this.projectRoot = path.resolve(this.options.directory || process.cwd());\r\n this.workDir = this.options.out || path.join(this.projectRoot, \"build\");\r\n this.config = this.options.debug ? \"Debug\" : \"Release\";\r\n this.buildDir = path.join(this.workDir, this.config);\r\n this._isAvailable = null;\r\n this.targetOptions = new TargetOptions(this.options);\r\n this.toolset = new Toolset(this.options);\r\n this.cMakeOptions = this.options.cMakeOptions || {};\r\n this.silent = !!options.silent;\r\n}\r\n\r\nObject.defineProperties(CMake.prototype, {\r\n path: {\r\n get: function () {\r\n return this.options.cmakePath || \"cmake\";\r\n }\r\n },\r\n isAvailable: {\r\n get: function () {\r\n if (this._isAvailable === null) {\r\n this._isAvailable = CMake.isAvailable(this.options);\r\n }\r\n return this._isAvailable;\r\n }\r\n }\r\n});\r\n\r\nCMake.isAvailable = function (options) {\r\n options = options || {};\r\n try {\r\n if (options.cmakePath) {\r\n let stat = fs.lstatSync(options.cmakePath);\r\n return !stat.isDirectory();\r\n }\r\n else {\r\n which.sync(\"cmake\");\r\n return true;\r\n }\r\n }\r\n catch (e) {\r\n _.noop(e);\r\n }\r\n return false;\r\n};\r\n\r\nCMake.getGenerators = async(function* (options) {\r\n let arch = \" [arch]\";\r\n options = options || {};\r\n let gens = [];\r\n if (CMake.isAvailable(options)) {\r\n let stdout = yield processHelpers.exec((options.cmakePath || \"cmake\") + \" --help\");\r\n let hasCr = stdout.includes(\"\\r\\n\");\r\n let output = hasCr ? stdout.split(\"\\r\\n\") : stdout.split(\"\\n\");\r\n let on = false;\r\n output.forEach(function (line, i) {\r\n if (on) {\r\n let parts = line.split(\"=\");\r\n if ((parts.length === 2 && parts[0].trim()) ||\r\n (parts.length === 1 && i !== output.length - 1 && output[i + 1].trim()[0] === \"=\")) {\r\n let gen = parts[0].trim();\r\n if (_.endsWith(gen, arch)) {\r\n gen = gen.substr(0, gen.length - arch.length);\r\n }\r\n gens.push(gen);\r\n }\r\n }\r\n if (line.trim() === \"Generators\") {\r\n on = true;\r\n }\r\n });\r\n }\r\n return gens;\r\n});\r\n\r\nCMake.prototype.getGenerators = function () {\r\n return CMake.getGenerators(this.options);\r\n};\r\n\r\nCMake.prototype.verifyIfAvailable = function () {\r\n if (!this.isAvailable) {\r\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.\");\r\n }\r\n};\r\n\r\nCMake.prototype.getConfigureCommand = async(function* () {\r\n // Create command:\r\n let command = this.path;\r\n command += \" \\\"\" + this.projectRoot + \"\\\" --no-warn-unused-cli\";\r\n\r\n let D = [];\r\n\r\n // CMake.js watermark\r\n D.push({\"CMAKE_JS_VERSION\": environment.moduleVersion});\r\n\r\n // Build configuration:\r\n D.push({\"CMAKE_BUILD_TYPE\": this.config});\r\n if (environment.isWin) {\r\n\t\tD.push({\"CMAKE_RUNTIME_OUTPUT_DIRECTORY\": this.workDir});\r\n\t}\r\n\telse {\r\n\t\tD.push({\"CMAKE_LIBRARY_OUTPUT_DIRECTORY\": this.buildDir});\r\n\t}\r\n\r\n // Include and lib:\r\n let incPaths;\r\n if (this.dist.headerOnly) {\r\n incPaths = [path.join(this.dist.internalPath, \"/include/node\")];\r\n }\r\n else {\r\n let nodeH = path.join(this.dist.internalPath, \"/src\");\r\n let v8H = path.join(this.dist.internalPath, \"/deps/v8/include\");\r\n let uvH = path.join(this.dist.internalPath, \"/deps/uv/include\");\r\n incPaths = [nodeH, v8H, uvH];\r\n }\r\n\r\n // NAN\r\n let nanH = yield locateNAN(this.projectRoot);\r\n if (nanH) {\r\n incPaths.push(nanH);\r\n }\r\n\r\n // Includes:\r\n D.push({\"CMAKE_JS_INC\": incPaths.join(\";\")});\r\n\r\n // Runtime:\r\n D.push({\"NODE_RUNTIME\": this.targetOptions.runtime});\r\n D.push({\"NODE_RUNTIMEVERSION\": this.targetOptions.runtimeVersion});\r\n D.push({\"NODE_ARCH\": this.targetOptions.arch});\r\n\r\n if (environment.isWin) {\r\n // Win\r\n let libs = this.dist.winLibs;\r\n if (libs.length) {\r\n D.push({\"CMAKE_JS_LIB\": libs.join(\";\")});\r\n }\r\n }\r\n\r\n // Custom options\r\n for (let k of _.keys(this.cMakeOptions)) {\r\n D.push({[k]: this.cMakeOptions[k]});\r\n }\r\n\r\n // Toolset:\r\n yield this.toolset.initialize(false);\r\n\r\n if (this.toolset.generator) {\r\n command += \" -G\\\"\" + this.toolset.generator + \"\\\"\";\r\n }\r\n if (this.toolset.cppCompilerPath) {\r\n D.push({\"CMAKE_CXX_COMPILER\": this.toolset.cppCompilerPath});\r\n }\r\n if (this.toolset.cCompilerPath) {\r\n D.push({\"CMAKE_C_COMPILER\": this.toolset.cCompilerPath});\r\n }\r\n if (this.toolset.compilerFlags.length) {\r\n D.push({\"CMAKE_CXX_FLAGS\": this.toolset.compilerFlags.join(\" \")});\r\n }\r\n if (this.toolset.linkerFlags.length) {\r\n D.push({\"CMAKE_SHARED_LINKER_FLAGS\": this.toolset.linkerFlags.join(\" \")});\r\n }\r\n if (this.toolset.makePath) {\r\n D.push({\"CMAKE_MAKE_PROGRAM\": this.toolset.makePath});\r\n }\r\n\r\n // Load NPM config\r\n let npmConfig = yield npmconf.loadAsync();\r\n let npmConfigData = {};\r\n if (npmConfig.sources.global && npmConfig.sources.global.data) {\r\n _.extend(npmConfigData, npmConfig.sources.global.data);\r\n }\r\n if (npmConfig.sources.user && npmConfig.sources.user.data) {\r\n _.extend(npmConfigData, npmConfig.sources.user.data);\r\n }\r\n for (let key of _.keys(npmConfigData)) {\r\n let ukey = key.toUpperCase();\r\n if (_.startsWith(ukey, \"CMAKE_\")) {\r\n let s = {};\r\n let sk = ukey.substr(6);\r\n if (sk) {\r\n s[sk] = npmConfigData[key];\r\n if (s[sk]) {\r\n D.push(s);\r\n }\r\n }\r\n }\r\n }\r\n\r\n command += \" \" +\r\n D.map(function (p) {\r\n return \"-D\" + _.keys(p)[0] + \"=\\\"\" + _.values(p)[0] + \"\\\"\";\r\n }).join(\" \");\r\n\r\n return command;\r\n});\r\n\r\nCMake.prototype.configure = async(function* () {\r\n this.verifyIfAvailable();\r\n\r\n this.log.info(\"CMD\", \"CONFIGURE\");\r\n let listPath = path.join(this.projectRoot, \"CMakeLists.txt\");\r\n let command = yield this.getConfigureCommand();\r\n\r\n try {\r\n yield fs.lstatAsync(listPath);\r\n }\r\n catch (e) {\r\n throw new Error(\"'\" + listPath + \"' not found.\");\r\n }\r\n\r\n try {\r\n yield fs.mkdirAsync(this.workDir);\r\n }\r\n catch (e) {\r\n _.noop(e);\r\n }\r\n\r\n let cwd = process.cwd();\r\n process.chdir(this.workDir);\r\n try {\r\n yield this._run(command);\r\n }\r\n finally {\r\n process.chdir(cwd);\r\n }\r\n});\r\n\r\nCMake.prototype.ensureConfigured = async(function* () {\r\n try {\r\n yield fs.lstatAsync(path.join(this.workDir, \"CMakeCache.txt\"));\r\n }\r\n catch (e) {\r\n _.noop(e);\r\n yield this.configure();\r\n }\r\n});\r\n\r\nCMake.prototype.getBuildCommand = function() {\r\n var command = this.path + \" --build \\\"\" + this.workDir + \"\\\" --config \" + this.config;\r\n if (this.options.target) {\r\n command += \" --target \" + this.options.target;\r\n }\r\n return Bluebird.resolve(command);\r\n};\r\n\r\nCMake.prototype.build = async(function* () {\r\n this.verifyIfAvailable();\r\n\r\n yield this.ensureConfigured();\r\n let buildCommand = yield this.getBuildCommand();\r\n this.log.info(\"CMD\", \"BUILD\");\r\n yield this._run(buildCommand);\r\n});\r\n\r\nCMake.prototype.getCleanCommand = function () {\r\n return this.path + \" -E remove_directory \\\"\" + this.workDir + \"\\\"\";\r\n};\r\n\r\nCMake.prototype.clean = function () {\r\n this.verifyIfAvailable();\r\n\r\n this.log.info(\"CMD\", \"CLEAN\");\r\n return this._run(this.getCleanCommand());\r\n};\r\n\r\nCMake.prototype.reconfigure = async(function* () {\r\n yield this.clean();\r\n yield this.configure();\r\n});\r\n\r\nCMake.prototype.rebuild = async(function* () {\r\n yield this.clean();\r\n yield this.build();\r\n});\r\n\r\nCMake.prototype.compile = async(function* () {\r\n try {\r\n yield this.build();\r\n }\r\n catch (e) {\r\n _.noop(e);\r\n this.log.info(\"REP\", \"Build has been failed, trying to do a full rebuild.\");\r\n yield this.rebuild();\r\n }\r\n});\r\n\r\nCMake.prototype._run = function (command) {\r\n this.log.info(\"RUN\", command);\r\n return processHelpers.run(command, {silent: this.silent});\r\n};\r\n\r\nmodule.exports = CMake;\r\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 Bluebird = require(\"bluebird\");\nlet fs = Bluebird.promisifyAll(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 npmconf = Bluebird.promisifyAll(require(\"npmconf\"));\nlet async = Bluebird.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 = 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 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 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 // 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 let npmConfig = yield npmconf.loadAsync();\n let npmConfigData = {};\n if (npmConfig.sources.global && npmConfig.sources.global.data) {\n _.extend(npmConfigData, npmConfig.sources.global.data);\n }\n if (npmConfig.sources.user && npmConfig.sources.user.data) {\n _.extend(npmConfigData, npmConfig.sources.user.data);\n }\n for (let key of _.keys(npmConfigData)) {\n let ukey = key.toUpperCase();\n if (_.startsWith(ukey, \"CMAKE_\")) {\n let s = {};\n let sk = ukey.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.lstatAsync(listPath);\n }\n catch (e) {\n throw new Error(\"'\" + listPath + \"' not found.\");\n }\n\n try {\n yield fs.mkdirAsync(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.lstatAsync(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 Bluebird.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/cmLog.js.map b/lib/es5/cmLog.js.map index fdcb3331..ed8658cf 100644 --- a/lib/es5/cmLog.js.map +++ b/lib/es5/cmLog.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["cmLog.js"],"sourcesContent":["\"use strict\";\r\nlet log = require(\"npmlog\");\r\n\r\nfunction CMLog(options) {\r\n this.options = options || {};\r\n this.debug = require(\"debug\")(this.options.logName || \"cmake-js\");\r\n}\r\n\r\nObject.defineProperties(CMLog.prototype, {\r\n level: {\r\n get: function() {\r\n if (this.options.noLog) {\r\n return \"silly\";\r\n }\r\n else {\r\n return log.level;\r\n }\r\n }\r\n }\r\n});\r\n\r\nCMLog.prototype.silly = function(cat, msg) {\r\n if (this.options.noLog) {\r\n this.debug(cat + \": \" + msg);\r\n }\r\n else {\r\n log.silly(cat, msg);\r\n }\r\n};\r\n\r\nCMLog.prototype.verbose = function(cat, msg) {\r\n if (this.options.noLog) {\r\n this.debug(cat + \": \" + msg);\r\n }\r\n else {\r\n log.verbose(cat, msg);\r\n }\r\n};\r\n\r\nCMLog.prototype.info = function(cat, msg) {\r\n if (this.options.noLog) {\r\n this.debug(cat + \": \" + msg);\r\n }\r\n else {\r\n log.info(cat, msg);\r\n }\r\n};\r\n\r\nCMLog.prototype.warn = function(cat, msg) {\r\n if (this.options.noLog) {\r\n this.debug(cat + \": \" + msg);\r\n }\r\n else {\r\n log.warn(cat, msg);\r\n }\r\n};\r\n\r\nCMLog.prototype.http = function(cat, msg) {\r\n if (this.options.noLog) {\r\n this.debug(cat + \": \" + msg);\r\n }\r\n else {\r\n log.http(cat, msg);\r\n }\r\n};\r\n\r\nCMLog.prototype.error = function(cat, msg) {\r\n if (this.options.noLog) {\r\n this.debug(cat + \": \" + msg);\r\n }\r\n else {\r\n log.error(cat, msg);\r\n }\r\n};\r\n\r\nmodule.exports = CMLog;"],"file":"cmLog.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["cmLog.js"],"sourcesContent":["\"use strict\";\nlet log = require(\"npmlog\");\n\nfunction CMLog(options) {\n this.options = options || {};\n this.debug = require(\"debug\")(this.options.logName || \"cmake-js\");\n}\n\nObject.defineProperties(CMLog.prototype, {\n level: {\n get: function() {\n if (this.options.noLog) {\n return \"silly\";\n }\n else {\n return log.level;\n }\n }\n }\n});\n\nCMLog.prototype.silly = function(cat, msg) {\n if (this.options.noLog) {\n this.debug(cat + \": \" + msg);\n }\n else {\n log.silly(cat, msg);\n }\n};\n\nCMLog.prototype.verbose = function(cat, msg) {\n if (this.options.noLog) {\n this.debug(cat + \": \" + msg);\n }\n else {\n log.verbose(cat, msg);\n }\n};\n\nCMLog.prototype.info = function(cat, msg) {\n if (this.options.noLog) {\n this.debug(cat + \": \" + msg);\n }\n else {\n log.info(cat, msg);\n }\n};\n\nCMLog.prototype.warn = function(cat, msg) {\n if (this.options.noLog) {\n this.debug(cat + \": \" + msg);\n }\n else {\n log.warn(cat, msg);\n }\n};\n\nCMLog.prototype.http = function(cat, msg) {\n if (this.options.noLog) {\n this.debug(cat + \": \" + msg);\n }\n else {\n log.http(cat, msg);\n }\n};\n\nCMLog.prototype.error = function(cat, msg) {\n if (this.options.noLog) {\n this.debug(cat + \": \" + msg);\n }\n else {\n log.error(cat, msg);\n }\n};\n\nmodule.exports = CMLog;"],"file":"cmLog.js"} \ No newline at end of file diff --git a/lib/es5/dist.js.map b/lib/es5/dist.js.map index eaf5af80..33ad4514 100644 --- a/lib/es5/dist.js.map +++ b/lib/es5/dist.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["dist.js"],"sourcesContent":["\"use strict\";\r\nlet environment = require(\"./environment\");\r\nlet path = require(\"path\");\r\nlet urljoin = require(\"url-join\");\r\nlet Bluebird = require(\"bluebird\");\r\nlet fs = Bluebird.promisifyAll(require(\"fs-extra\"));\r\nlet _ = require(\"lodash\");\r\nlet CMLog = require(\"./cmLog\");\r\nlet TargetOptions = require(\"./targetOptions\");\r\nlet runtimePaths = require(\"./runtimePaths\");\r\nlet async = Bluebird.coroutine;\r\nlet Downloader = require(\"./downloader\");\r\n\r\nfunction testSum(sums, sum, fPath) {\r\n let serverSum = _.first(sums.filter(function (s) {\r\n return s.getPath === fPath;\r\n }));\r\n if (serverSum && serverSum.sum === sum) {\r\n return;\r\n }\r\n throw new Error(\"SHA sum of file '\" + fPath + \"' mismatch!\");\r\n}\r\n\r\nfunction Dist(options) {\r\n this.options = options || {};\r\n this.log = new CMLog(this.options);\r\n this.targetOptions = new TargetOptions(this.options);\r\n this.downloader = new Downloader(this.options);\r\n}\r\n\r\n// Props\r\nObject.defineProperties(Dist.prototype, {\r\n internalPath: {\r\n get: function () {\r\n return path.join(\r\n environment.home,\r\n \".cmake-js\",\r\n (this.targetOptions.runtime) + \"-\" + this.targetOptions.arch,\r\n \"v\" + this.targetOptions.runtimeVersion);\r\n }\r\n },\r\n externalPath: {\r\n get: function () {\r\n return runtimePaths.get(this.targetOptions).externalPath;\r\n }\r\n },\r\n downloaded: {\r\n get: function () {\r\n let headers = false;\r\n let libs = true;\r\n let stat = getStat(this.internalPath);\r\n if (stat.isDirectory()) {\r\n if (this.headerOnly) {\r\n stat = getStat(path.join(this.internalPath, \"include/node/node.h\"));\r\n headers = stat.isFile();\r\n }\r\n else {\r\n stat = getStat(path.join(this.internalPath, \"src/node.h\"));\r\n if (stat.isFile()) {\r\n stat = getStat(path.join(this.internalPath, \"deps/v8/include/v8.h\"));\r\n headers = stat.isFile();\r\n }\r\n }\r\n if (environment.isWin) {\r\n for (let libPath of this.winLibs) {\r\n stat = getStat(libPath);\r\n libs = libs && stat.isFile();\r\n }\r\n }\r\n }\r\n return headers && libs;\r\n\r\n function getStat(path) {\r\n try {\r\n return fs.statSync(path);\r\n }\r\n catch (e) {\r\n return {\r\n isFile: _.constant(false),\r\n isDirectory: _.constant(false)\r\n };\r\n }\r\n }\r\n }\r\n },\r\n winLibs: {\r\n get: function () {\r\n let libs = runtimePaths.get(this.targetOptions).winLibs;\r\n let result = [];\r\n for (let lib of libs) {\r\n result.push(path.join(this.internalPath, lib.dir, lib.name));\r\n }\r\n return result;\r\n }\r\n },\r\n headerOnly: {\r\n get: function () {\r\n return runtimePaths.get(this.targetOptions).headerOnly;\r\n }\r\n }\r\n});\r\n\r\n// Methods\r\nDist.prototype.ensureDownloaded = async(function* () {\r\n if (!this.downloaded) {\r\n yield this.download();\r\n }\r\n});\r\n\r\nDist.prototype.download = async(function* () {\r\n let log = this.log;\r\n log.info(\"DIST\", \"Downloading distribution files.\");\r\n yield fs.mkdirpAsync(this.internalPath);\r\n let sums = yield this._downloadShaSums();\r\n yield Bluebird.all([this._downloadLibs(sums), this._downloadTar(sums)]);\r\n});\r\n\r\nDist.prototype._downloadShaSums = async(function* () {\r\n if (this.targetOptions.runtime === \"node\" || this.targetOptions.runtime === \"iojs\") {\r\n let sumUrl = urljoin(this.externalPath, \"SHASUMS256.txt\");\r\n let log = this.log;\r\n log.http(\"DIST\", \"\\t- \" + sumUrl);\r\n return (yield this.downloader.downloadString(sumUrl))\r\n .split(\"\\n\")\r\n .map(function (line) {\r\n let parts = line.split(/\\s+/);\r\n return {\r\n getPath: parts[1],\r\n sum: parts[0]\r\n };\r\n })\r\n .filter(function (i) {\r\n return i.getPath && i.sum;\r\n });\r\n }\r\n else {\r\n return null;\r\n }\r\n});\r\n\r\nDist.prototype._downloadTar = async(function* (sums) {\r\n let log = this.log;\r\n let self = this;\r\n let tarLocalPath = runtimePaths.get(self.targetOptions).tarPath;\r\n let tarUrl = urljoin(self.externalPath, tarLocalPath);\r\n log.http(\"DIST\", \"\\t- \" + tarUrl);\r\n\r\n let sum = yield this.downloader.downloadTgz(tarUrl, {\r\n hash: sums ? \"sha256\" : null,\r\n cwd: self.internalPath,\r\n strip: 1,\r\n filter: function (entryPath) {\r\n if (entryPath === self.internalPath) {\r\n return true;\r\n }\r\n let ext = path.extname(entryPath);\r\n return ext && ext.toLowerCase() === \".h\";\r\n }\r\n });\r\n\r\n if (sums) {\r\n testSum(sums, sum, tarLocalPath);\r\n }\r\n});\r\n\r\nDist.prototype._downloadLibs = async(function* (sums) {\r\n const log = this.log;\r\n const self = this;\r\n if (!environment.isWin) {\r\n return;\r\n }\r\n\r\n const paths = runtimePaths.get(self.targetOptions);\r\n for (const dirs of paths.winLibs) {\r\n const subDir = dirs.dir;\r\n const fn = dirs.name;\r\n const fPath = subDir ? urljoin(subDir, fn) : fn;\r\n const libUrl = urljoin(self.externalPath, fPath);\r\n log.http(\"DIST\", \"\\t- \" + libUrl);\r\n\r\n yield fs.mkdirpAsync(path.join(self.internalPath, subDir));\r\n\r\n const sum = yield this.downloader.downloadFile(libUrl, {\r\n path: path.join(self.internalPath, fPath),\r\n hash: sums ? \"sha256\" : null\r\n });\r\n\r\n if (sums) {\r\n testSum(sums, sum, fPath);\r\n }\r\n }\r\n});\r\n\r\nmodule.exports = Dist;\r\n"],"file":"dist.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["dist.js"],"sourcesContent":["\"use strict\";\nlet environment = require(\"./environment\");\nlet path = require(\"path\");\nlet urljoin = require(\"url-join\");\nlet Bluebird = require(\"bluebird\");\nlet fs = Bluebird.promisifyAll(require(\"fs-extra\"));\nlet _ = require(\"lodash\");\nlet CMLog = require(\"./cmLog\");\nlet TargetOptions = require(\"./targetOptions\");\nlet runtimePaths = require(\"./runtimePaths\");\nlet async = Bluebird.coroutine;\nlet Downloader = require(\"./downloader\");\n\nfunction testSum(sums, sum, fPath) {\n let serverSum = _.first(sums.filter(function (s) {\n return s.getPath === fPath;\n }));\n if (serverSum && serverSum.sum === sum) {\n return;\n }\n throw new Error(\"SHA sum of file '\" + fPath + \"' mismatch!\");\n}\n\nfunction Dist(options) {\n this.options = options || {};\n this.log = new CMLog(this.options);\n this.targetOptions = new TargetOptions(this.options);\n this.downloader = new Downloader(this.options);\n}\n\n// Props\nObject.defineProperties(Dist.prototype, {\n internalPath: {\n get: function () {\n return path.join(\n environment.home,\n \".cmake-js\",\n (this.targetOptions.runtime) + \"-\" + this.targetOptions.arch,\n \"v\" + this.targetOptions.runtimeVersion);\n }\n },\n externalPath: {\n get: function () {\n return runtimePaths.get(this.targetOptions).externalPath;\n }\n },\n downloaded: {\n get: function () {\n let headers = false;\n let libs = true;\n let stat = getStat(this.internalPath);\n if (stat.isDirectory()) {\n if (this.headerOnly) {\n stat = getStat(path.join(this.internalPath, \"include/node/node.h\"));\n headers = stat.isFile();\n }\n else {\n stat = getStat(path.join(this.internalPath, \"src/node.h\"));\n if (stat.isFile()) {\n stat = getStat(path.join(this.internalPath, \"deps/v8/include/v8.h\"));\n headers = stat.isFile();\n }\n }\n if (environment.isWin) {\n for (let libPath of this.winLibs) {\n stat = getStat(libPath);\n libs = libs && stat.isFile();\n }\n }\n }\n return headers && libs;\n\n function getStat(path) {\n try {\n return fs.statSync(path);\n }\n catch (e) {\n return {\n isFile: _.constant(false),\n isDirectory: _.constant(false)\n };\n }\n }\n }\n },\n winLibs: {\n get: function () {\n let libs = runtimePaths.get(this.targetOptions).winLibs;\n let result = [];\n for (let lib of libs) {\n result.push(path.join(this.internalPath, lib.dir, lib.name));\n }\n return result;\n }\n },\n headerOnly: {\n get: function () {\n return runtimePaths.get(this.targetOptions).headerOnly;\n }\n }\n});\n\n// Methods\nDist.prototype.ensureDownloaded = async(function* () {\n if (!this.downloaded) {\n yield this.download();\n }\n});\n\nDist.prototype.download = async(function* () {\n let log = this.log;\n log.info(\"DIST\", \"Downloading distribution files.\");\n yield fs.mkdirpAsync(this.internalPath);\n let sums = yield this._downloadShaSums();\n yield Bluebird.all([this._downloadLibs(sums), this._downloadTar(sums)]);\n});\n\nDist.prototype._downloadShaSums = async(function* () {\n if (this.targetOptions.runtime === \"node\" || this.targetOptions.runtime === \"iojs\") {\n let sumUrl = urljoin(this.externalPath, \"SHASUMS256.txt\");\n let log = this.log;\n log.http(\"DIST\", \"\\t- \" + sumUrl);\n return (yield this.downloader.downloadString(sumUrl))\n .split(\"\\n\")\n .map(function (line) {\n let parts = line.split(/\\s+/);\n return {\n getPath: parts[1],\n sum: parts[0]\n };\n })\n .filter(function (i) {\n return i.getPath && i.sum;\n });\n }\n else {\n return null;\n }\n});\n\nDist.prototype._downloadTar = async(function* (sums) {\n let log = this.log;\n let self = this;\n let tarLocalPath = runtimePaths.get(self.targetOptions).tarPath;\n let tarUrl = urljoin(self.externalPath, tarLocalPath);\n log.http(\"DIST\", \"\\t- \" + tarUrl);\n\n let sum = yield this.downloader.downloadTgz(tarUrl, {\n hash: sums ? \"sha256\" : null,\n cwd: self.internalPath,\n strip: 1,\n filter: function (entryPath) {\n if (entryPath === self.internalPath) {\n return true;\n }\n let ext = path.extname(entryPath);\n return ext && ext.toLowerCase() === \".h\";\n }\n });\n\n if (sums) {\n testSum(sums, sum, tarLocalPath);\n }\n});\n\nDist.prototype._downloadLibs = async(function* (sums) {\n const log = this.log;\n const self = this;\n if (!environment.isWin) {\n return;\n }\n\n const paths = runtimePaths.get(self.targetOptions);\n for (const dirs of paths.winLibs) {\n const subDir = dirs.dir;\n const fn = dirs.name;\n const fPath = subDir ? urljoin(subDir, fn) : fn;\n const libUrl = urljoin(self.externalPath, fPath);\n log.http(\"DIST\", \"\\t- \" + libUrl);\n\n yield fs.mkdirpAsync(path.join(self.internalPath, subDir));\n\n const sum = yield this.downloader.downloadFile(libUrl, {\n path: path.join(self.internalPath, fPath),\n hash: sums ? \"sha256\" : null\n });\n\n if (sums) {\n testSum(sums, sum, fPath);\n }\n }\n});\n\nmodule.exports = Dist;\n"],"file":"dist.js"} \ No newline at end of file diff --git a/lib/es5/downloader.js.map b/lib/es5/downloader.js.map index b238dc32..5a1a22b5 100644 --- a/lib/es5/downloader.js.map +++ b/lib/es5/downloader.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["downloader.js"],"sourcesContent":["\"use strict\";\r\nlet Bluebird = require(\"bluebird\");\r\nlet crypto = require(\"crypto\");\r\nlet request = require(\"request\");\r\nlet async = Bluebird.coroutine;\r\nlet MemoryStream = require(\"memory-stream\");\r\nlet zlib = require(\"zlib\");\r\nlet tar = require(\"tar\");\r\nlet fs = Bluebird.promisifyAll(require(\"fs-extra\"));\r\nlet _ = require(\"lodash\");\r\nlet unzip = require(\"unzip\");\r\nlet CMLog = require(\"./cmLog\");\r\n\r\nfunction Downloader(options) {\r\n this.options = options || {};\r\n this.log = new CMLog(this.options);\r\n}\r\n\r\nDownloader.prototype.downloadToStream = function(url, stream, hash) {\r\n let self = this;\r\n let shasum = hash ? crypto.createHash(hash) : null;\r\n return new Bluebird(function (resolve, reject) {\r\n let length = 0;\r\n let done = 0;\r\n let lastPercent = 0;\r\n request\r\n .get(url)\r\n .on(\"error\", function (err) {\r\n reject(err);\r\n })\r\n .on(\"response\", function(data) {\r\n length = parseInt(data.headers[\"content-length\"]);\r\n if (!_.isNumber(length)) {\r\n length = 0;\r\n }\r\n })\r\n .on(\"data\", function (chunk) {\r\n if (shasum) {\r\n shasum.update(chunk);\r\n }\r\n if (length) {\r\n done += chunk.length;\r\n let percent = done / length * 100;\r\n percent = Math.round(percent / 10) * 10 + 10;\r\n if (percent > lastPercent) {\r\n self.log.verbose(\"DWNL\", \"\\t\" + lastPercent + \"%\");\r\n lastPercent = percent;\r\n }\r\n }\r\n })\r\n .pipe(stream);\r\n\r\n stream.once(\"error\", function (err) {\r\n reject(err);\r\n });\r\n\r\n stream.once(\"finish\", function () {\r\n resolve(shasum ? shasum.digest(\"hex\") : undefined);\r\n });\r\n });\r\n};\r\n\r\nDownloader.prototype.downloadString = async(function* (url) {\r\n let result = new MemoryStream();\r\n yield this.downloadToStream(url, result);\r\n return result.toString();\r\n});\r\n\r\nDownloader.prototype.downloadFile = async(function* (url, options) {\r\n if (_.isString(options)) {\r\n options.path = options;\r\n }\r\n let result = fs.createWriteStream(options.path);\r\n let sum = yield this.downloadToStream(url, result, options.hash);\r\n this.testSum(url, sum, options);\r\n return sum;\r\n});\r\n\r\nDownloader.prototype.downloadTgz = async(function*(url, options) {\r\n if (_.isString(options)) {\r\n options.cwd = options;\r\n }\r\n let gunzip = zlib.createGunzip();\r\n let extractor = tar.extract(options);\r\n gunzip.pipe(extractor);\r\n let sum = yield this.downloadToStream(url, gunzip, options.hash);\r\n this.testSum(url, sum, options);\r\n return sum;\r\n});\r\n\r\nDownloader.prototype.downloadZip = async(function*(url, options) {\r\n if (_.isString(options)) {\r\n options.path = options;\r\n }\r\n let extractor = new unzip.Extract(options);\r\n let sum = yield this.downloadToStream(url, extractor, options.hash);\r\n this.testSum(url, sum, options);\r\n return sum;\r\n});\r\n\r\nDownloader.prototype.testSum = function(url, sum, options) {\r\n if (options.hash && sum && options.sum && options.sum !== sum) {\r\n throw new Error(options.hash.toUpperCase() + \" sum of download '\" + url + \"' mismatch!\");\r\n }\r\n};\r\n\r\nmodule.exports = Downloader;"],"file":"downloader.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["downloader.js"],"sourcesContent":["\"use strict\";\nlet Bluebird = require(\"bluebird\");\nlet crypto = require(\"crypto\");\nlet request = require(\"request\");\nlet async = Bluebird.coroutine;\nlet MemoryStream = require(\"memory-stream\");\nlet zlib = require(\"zlib\");\nlet tar = require(\"tar\");\nlet fs = Bluebird.promisifyAll(require(\"fs-extra\"));\nlet _ = require(\"lodash\");\nlet unzip = require(\"unzip\");\nlet CMLog = require(\"./cmLog\");\n\nfunction Downloader(options) {\n this.options = options || {};\n this.log = new CMLog(this.options);\n}\n\nDownloader.prototype.downloadToStream = function(url, stream, hash) {\n let self = this;\n let shasum = hash ? crypto.createHash(hash) : null;\n return new Bluebird(function (resolve, reject) {\n let length = 0;\n let done = 0;\n let lastPercent = 0;\n request\n .get(url)\n .on(\"error\", function (err) {\n reject(err);\n })\n .on(\"response\", function(data) {\n length = parseInt(data.headers[\"content-length\"]);\n if (!_.isNumber(length)) {\n length = 0;\n }\n })\n .on(\"data\", function (chunk) {\n if (shasum) {\n shasum.update(chunk);\n }\n if (length) {\n done += chunk.length;\n let percent = done / length * 100;\n percent = Math.round(percent / 10) * 10 + 10;\n if (percent > lastPercent) {\n self.log.verbose(\"DWNL\", \"\\t\" + lastPercent + \"%\");\n lastPercent = percent;\n }\n }\n })\n .pipe(stream);\n\n stream.once(\"error\", function (err) {\n reject(err);\n });\n\n stream.once(\"finish\", function () {\n resolve(shasum ? shasum.digest(\"hex\") : undefined);\n });\n });\n};\n\nDownloader.prototype.downloadString = async(function* (url) {\n let result = new MemoryStream();\n yield this.downloadToStream(url, result);\n return result.toString();\n});\n\nDownloader.prototype.downloadFile = async(function* (url, options) {\n if (_.isString(options)) {\n options.path = options;\n }\n let result = fs.createWriteStream(options.path);\n let sum = yield this.downloadToStream(url, result, options.hash);\n this.testSum(url, sum, options);\n return sum;\n});\n\nDownloader.prototype.downloadTgz = async(function*(url, options) {\n if (_.isString(options)) {\n options.cwd = options;\n }\n let gunzip = zlib.createGunzip();\n let extractor = tar.extract(options);\n gunzip.pipe(extractor);\n let sum = yield this.downloadToStream(url, gunzip, options.hash);\n this.testSum(url, sum, options);\n return sum;\n});\n\nDownloader.prototype.downloadZip = async(function*(url, options) {\n if (_.isString(options)) {\n options.path = options;\n }\n let extractor = new unzip.Extract(options);\n let sum = yield this.downloadToStream(url, extractor, options.hash);\n this.testSum(url, sum, options);\n return sum;\n});\n\nDownloader.prototype.testSum = function(url, sum, options) {\n if (options.hash && sum && options.sum && options.sum !== sum) {\n throw new Error(options.hash.toUpperCase() + \" sum of download '\" + url + \"' mismatch!\");\n }\n};\n\nmodule.exports = Downloader;"],"file":"downloader.js"} \ No newline at end of file diff --git a/lib/es5/environment.js.map b/lib/es5/environment.js.map index 05f5c0b0..bb8ce864 100644 --- a/lib/es5/environment.js.map +++ b/lib/es5/environment.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["environment.js"],"sourcesContent":["\"use strict\";\r\nlet os = require(\"os\");\r\nlet isIOJS = require(\"is-iojs\");\r\nlet which = require(\"which\");\r\nlet _ = require(\"lodash\");\r\n\r\nlet environment = module.exports = {\r\n moduleVersion: require(\"../../package.json\").version,\r\n platform: os.platform(),\r\n isWin: os.platform() === \"win32\",\r\n isLinux: os.platform() === \"linux\",\r\n isOSX: os.platform() === \"darwin\",\r\n arch: os.arch(),\r\n isX86: os.arch() === \"ia32\",\r\n isX64: os.arch() === \"x64\",\r\n isArm: os.arch() === \"arm\",\r\n runtime: isIOJS ? \"iojs\" : \"node\",\r\n runtimeVersion: process.versions.node,\r\n home: process.env[(os.platform() === \"win32\") ? \"USERPROFILE\" : \"HOME\"],\r\n EOL: os.EOL\r\n};\r\n\r\nObject.defineProperties(environment, {\r\n isPosix: {\r\n get: function () {\r\n return !this.isWin;\r\n }\r\n },\r\n _isNinjaAvailable: {\r\n value: null,\r\n writable: true\r\n },\r\n isNinjaAvailable: {\r\n get: function() {\r\n if (this._isNinjaAvailable === null) {\r\n this._isNinjaAvailable = false;\r\n try {\r\n if (which.sync(\"ninja\")) {\r\n this._isNinjaAvailable = true;\r\n }\r\n }\r\n catch (e) {\r\n _.noop(e);\r\n }\r\n }\r\n return this._isNinjaAvailable;\r\n }\r\n },\r\n _isMakeAvailable: {\r\n value: null,\r\n writable: true\r\n },\r\n isMakeAvailable: {\r\n get: function() {\r\n if (this._isMakeAvailable === null) {\r\n this._isMakeAvailable = false;\r\n try {\r\n if (which.sync(\"make\")) {\r\n this._isMakeAvailable = true;\r\n }\r\n }\r\n catch (e) {\r\n _.noop(e);\r\n }\r\n }\r\n return this._isMakeAvailable;\r\n }\r\n },\r\n _isGPPAvailable: {\r\n value: null,\r\n writable: true\r\n },\r\n isGPPAvailable: {\r\n get: function() {\r\n if (this._isGPPAvailable === null) {\r\n this._isGPPAvailable = false;\r\n try {\r\n if (which.sync(\"g++\")) {\r\n this._isGPPAvailable = true;\r\n }\r\n }\r\n catch (e) {\r\n _.noop(e);\r\n }\r\n }\r\n return this._isGPPAvailable;\r\n }\r\n },\r\n _isClangAvailable: {\r\n value: null,\r\n writable: true\r\n },\r\n isClangAvailable: {\r\n get: function() {\r\n if (this._isClangAvailable === null) {\r\n this._isClangAvailable = false;\r\n try {\r\n if (which.sync(\"clang++\")) {\r\n this._isClangAvailable = true;\r\n }\r\n }\r\n catch (e) {\r\n _.noop(e);\r\n }\r\n }\r\n return this._isClangAvailable;\r\n }\r\n }\r\n});"],"file":"environment.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["environment.js"],"sourcesContent":["\"use strict\";\nlet os = require(\"os\");\nlet isIOJS = require(\"is-iojs\");\nlet which = require(\"which\");\nlet _ = require(\"lodash\");\n\nlet environment = module.exports = {\n moduleVersion: require(\"../../package.json\").version,\n platform: os.platform(),\n isWin: os.platform() === \"win32\",\n isLinux: os.platform() === \"linux\",\n isOSX: os.platform() === \"darwin\",\n arch: os.arch(),\n isX86: os.arch() === \"ia32\",\n isX64: os.arch() === \"x64\",\n isArm: os.arch() === \"arm\",\n runtime: isIOJS ? \"iojs\" : \"node\",\n runtimeVersion: process.versions.node,\n home: process.env[(os.platform() === \"win32\") ? \"USERPROFILE\" : \"HOME\"],\n EOL: os.EOL\n};\n\nObject.defineProperties(environment, {\n isPosix: {\n get: function () {\n return !this.isWin;\n }\n },\n _isNinjaAvailable: {\n value: null,\n writable: true\n },\n isNinjaAvailable: {\n get: function() {\n if (this._isNinjaAvailable === null) {\n this._isNinjaAvailable = false;\n try {\n if (which.sync(\"ninja\")) {\n this._isNinjaAvailable = true;\n }\n }\n catch (e) {\n _.noop(e);\n }\n }\n return this._isNinjaAvailable;\n }\n },\n _isMakeAvailable: {\n value: null,\n writable: true\n },\n isMakeAvailable: {\n get: function() {\n if (this._isMakeAvailable === null) {\n this._isMakeAvailable = false;\n try {\n if (which.sync(\"make\")) {\n this._isMakeAvailable = true;\n }\n }\n catch (e) {\n _.noop(e);\n }\n }\n return this._isMakeAvailable;\n }\n },\n _isGPPAvailable: {\n value: null,\n writable: true\n },\n isGPPAvailable: {\n get: function() {\n if (this._isGPPAvailable === null) {\n this._isGPPAvailable = false;\n try {\n if (which.sync(\"g++\")) {\n this._isGPPAvailable = true;\n }\n }\n catch (e) {\n _.noop(e);\n }\n }\n return this._isGPPAvailable;\n }\n },\n _isClangAvailable: {\n value: null,\n writable: true\n },\n isClangAvailable: {\n get: function() {\n if (this._isClangAvailable === null) {\n this._isClangAvailable = false;\n try {\n if (which.sync(\"clang++\")) {\n this._isClangAvailable = true;\n }\n }\n catch (e) {\n _.noop(e);\n }\n }\n return this._isClangAvailable;\n }\n }\n});"],"file":"environment.js"} \ No newline at end of file diff --git a/lib/es5/index.js.map b/lib/es5/index.js.map index cea7814c..c869eddb 100644 --- a/lib/es5/index.js.map +++ b/lib/es5/index.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["index.js"],"sourcesContent":["\"use strict\";\r\n\r\nmodule.exports = {\r\n BuildSystem: require(\"./buildSystem\"),\r\n CMLog: require(\"./cmLog\"),\r\n environment: require(\"./environment\"),\r\n TargetOptions: require(\"./targetOptions\"),\r\n Dist: require(\"./dist\"),\r\n CMake: require(\"./cMake\"),\r\n downloader: require(\"./downloader\"),\r\n Toolset: require(\"./toolset\"),\r\n processHelpers: require(\"./processHelpers\"),\r\n locateNAN: require(\"./locateNAN\")\r\n};\r\n"],"file":"index.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["index.js"],"sourcesContent":["\"use strict\";\n\nmodule.exports = {\n BuildSystem: require(\"./buildSystem\"),\n CMLog: require(\"./cmLog\"),\n environment: require(\"./environment\"),\n TargetOptions: require(\"./targetOptions\"),\n Dist: require(\"./dist\"),\n CMake: require(\"./cMake\"),\n downloader: require(\"./downloader\"),\n Toolset: require(\"./toolset\"),\n processHelpers: require(\"./processHelpers\"),\n locateNAN: require(\"./locateNAN\")\n};\n"],"file":"index.js"} \ No newline at end of file diff --git a/lib/es5/locateNAN.js.map b/lib/es5/locateNAN.js.map index 2f0e249d..141a69ec 100644 --- a/lib/es5/locateNAN.js.map +++ b/lib/es5/locateNAN.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["locateNAN.js"],"sourcesContent":["\"use strict\";\r\nlet Bluebird = require(\"bluebird\");\r\nlet fs = Bluebird.promisifyAll(require(\"fs-extra\"));\r\nlet path = require(\"path\");\r\nlet async = Bluebird.coroutine;\r\nlet _ = require(\"lodash\");\r\n\r\nlet isNANModule = async(function* (dir) {\r\n let h = path.join(dir, \"nan.h\");\r\n try {\r\n let stat = yield fs.statAsync(h);\r\n return stat.isFile();\r\n }\r\n catch (e) {\r\n _.noop(e);\r\n return false;\r\n }\r\n});\r\n\r\nlet isNodeJSProject = async(function* (dir) {\r\n let pjson = path.join(dir, \"package.json\");\r\n let node_modules = path.join(dir, \"node_modules\");\r\n try {\r\n let stat = yield fs.statAsync(pjson);\r\n if (stat.isFile()) {\r\n return true;\r\n }\r\n stat = yield fs.statAsync(node_modules);\r\n if (stat.isDirectory()) {\r\n return true;\r\n }\r\n }\r\n catch (e) {\r\n _.noop(e);\r\n }\r\n return false;\r\n});\r\n\r\nlet locateNAN = module.exports = async(function* (projectRoot) {\r\n if (locateNAN.__projectRoot) {\r\n projectRoot = locateNAN.__projectRoot;\r\n }\r\n let result = yield isNodeJSProject(projectRoot);\r\n if (!result) {\r\n return null;\r\n }\r\n let nanModulePath = path.join(projectRoot, \"node_modules\", \"nan\");\r\n result = yield isNANModule(nanModulePath);\r\n if (result) {\r\n return nanModulePath;\r\n }\r\n\r\n // Goto upper level:\r\n projectRoot = path.normalize(path.join(projectRoot, \"..\", \"..\"));\r\n return yield locateNAN(projectRoot);\r\n});"],"file":"locateNAN.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["locateNAN.js"],"sourcesContent":["\"use strict\";\nlet Bluebird = require(\"bluebird\");\nlet fs = Bluebird.promisifyAll(require(\"fs-extra\"));\nlet path = require(\"path\");\nlet async = Bluebird.coroutine;\nlet _ = require(\"lodash\");\n\nlet isNANModule = async(function* (dir) {\n let h = path.join(dir, \"nan.h\");\n try {\n let stat = yield fs.statAsync(h);\n return stat.isFile();\n }\n catch (e) {\n _.noop(e);\n return false;\n }\n});\n\nlet isNodeJSProject = async(function* (dir) {\n let pjson = path.join(dir, \"package.json\");\n let node_modules = path.join(dir, \"node_modules\");\n try {\n let stat = yield fs.statAsync(pjson);\n if (stat.isFile()) {\n return true;\n }\n stat = yield fs.statAsync(node_modules);\n if (stat.isDirectory()) {\n return true;\n }\n }\n catch (e) {\n _.noop(e);\n }\n return false;\n});\n\nlet locateNAN = module.exports = async(function* (projectRoot) {\n if (locateNAN.__projectRoot) {\n projectRoot = locateNAN.__projectRoot;\n }\n let result = yield isNodeJSProject(projectRoot);\n if (!result) {\n return null;\n }\n let nanModulePath = path.join(projectRoot, \"node_modules\", \"nan\");\n result = yield isNANModule(nanModulePath);\n if (result) {\n return nanModulePath;\n }\n\n // Goto upper level:\n projectRoot = path.normalize(path.join(projectRoot, \"..\", \"..\"));\n return yield locateNAN(projectRoot);\n});"],"file":"locateNAN.js"} \ No newline at end of file diff --git a/lib/es5/processHelpers.js.map b/lib/es5/processHelpers.js.map index 8b5a45de..9753fc63 100644 --- a/lib/es5/processHelpers.js.map +++ b/lib/es5/processHelpers.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["processHelpers.js"],"sourcesContent":["\"use strict\";\r\nlet Bluebird = require(\"bluebird\");\r\nlet splitargs = require(\"splitargs\");\r\nlet _ = require(\"lodash\");\r\nlet spawn = require(\"child_process\").spawn;\r\nlet exec = require(\"child_process\").exec;\r\n\r\nlet processHelpers = {\r\n run: function (command, options) {\r\n options = _.defaults(options, {silent: false});\r\n return new Bluebird(function (resolve, reject) {\r\n let args = splitargs(command);\r\n let name = args[0];\r\n args.splice(0, 1);\r\n let child = spawn(name, args, {stdio: options.silent ? \"ignore\" : \"inherit\"});\r\n let ended = false;\r\n child.on(\"error\", function (e) {\r\n if (!ended) {\r\n reject(e);\r\n ended = true;\r\n }\r\n });\r\n child.on(\"exit\", function (code, signal) {\r\n if (!ended) {\r\n if (code === 0) {\r\n resolve();\r\n }\r\n else {\r\n reject(new Error(\"Process terminated: \" + code || signal));\r\n }\r\n ended = true;\r\n }\r\n });\r\n });\r\n },\r\n exec: function(command) {\r\n return new Bluebird(function (resolve, reject) {\r\n exec(command, function (err, stdout, stderr) {\r\n if (err) {\r\n reject(new Error(err.message + \"\\n\" + (stdout || stderr)));\r\n }\r\n else {\r\n resolve(stdout);\r\n }\r\n });\r\n });\r\n }\r\n};\r\n\r\nmodule.exports = processHelpers;\r\n"],"file":"processHelpers.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["processHelpers.js"],"sourcesContent":["\"use strict\";\nlet Bluebird = require(\"bluebird\");\nlet splitargs = require(\"splitargs\");\nlet _ = require(\"lodash\");\nlet spawn = require(\"child_process\").spawn;\nlet exec = require(\"child_process\").exec;\n\nlet processHelpers = {\n run: function (command, options) {\n options = _.defaults(options, {silent: false});\n return new Bluebird(function (resolve, reject) {\n let args = splitargs(command);\n let name = args[0];\n args.splice(0, 1);\n let child = spawn(name, args, {stdio: options.silent ? \"ignore\" : \"inherit\"});\n let ended = false;\n child.on(\"error\", function (e) {\n if (!ended) {\n reject(e);\n ended = true;\n }\n });\n child.on(\"exit\", function (code, signal) {\n if (!ended) {\n if (code === 0) {\n resolve();\n }\n else {\n reject(new Error(\"Process terminated: \" + code || signal));\n }\n ended = true;\n }\n });\n });\n },\n exec: function(command) {\n return new Bluebird(function (resolve, reject) {\n exec(command, function (err, stdout, stderr) {\n if (err) {\n reject(new Error(err.message + \"\\n\" + (stdout || stderr)));\n }\n else {\n resolve(stdout);\n }\n });\n });\n }\n};\n\nmodule.exports = processHelpers;\n"],"file":"processHelpers.js"} \ No newline at end of file diff --git a/lib/es5/runtimePaths.js.map b/lib/es5/runtimePaths.js.map index 20d465bd..ba7da756 100644 --- a/lib/es5/runtimePaths.js.map +++ b/lib/es5/runtimePaths.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["runtimePaths.js"],"sourcesContent":["\"use strict\";\r\nlet _ = require(\"lodash\");\r\nlet assert = require(\"assert\");\r\nlet semver = require(\"semver\");\r\n\r\nlet runtimePaths = {\r\n node: function (targetOptions) {\r\n if (semver.lt(targetOptions.runtimeVersion, \"4.0.0\")) {\r\n return {\r\n externalPath: \"https://nodejs.org/dist/v\" + targetOptions.runtimeVersion + \"/\",\r\n winLibs: [{\r\n dir: targetOptions.isX64 ? \"x64\" : \"\",\r\n name: targetOptions.runtime + \".lib\"\r\n }],\r\n tarPath: targetOptions.runtime + \"-v\" + targetOptions.runtimeVersion + \".tar.gz\",\r\n headerOnly: false\r\n };\r\n }\r\n else {\r\n return {\r\n externalPath: \"https://nodejs.org/dist/v\" + targetOptions.runtimeVersion + \"/\",\r\n winLibs: [{\r\n dir: targetOptions.isX64 ? \"win-x64\" : \"win-x86\",\r\n name: targetOptions.runtime + \".lib\"\r\n }],\r\n tarPath: targetOptions.runtime + \"-v\" + targetOptions.runtimeVersion + \"-headers.tar.gz\",\r\n headerOnly: true\r\n };\r\n }\r\n },\r\n iojs: function (targetOptions) {\r\n return {\r\n externalPath: \"https://iojs.org/dist/v\" + targetOptions.runtimeVersion + \"/\",\r\n winLibs: [{\r\n dir: targetOptions.isX64 ? \"win-x64\" : \"win-x86\",\r\n name: targetOptions.runtime + \".lib\"\r\n }],\r\n tarPath: targetOptions.runtime + \"-v\" + targetOptions.runtimeVersion + \".tar.gz\",\r\n headerOnly: false\r\n };\r\n },\r\n nw: function (targetOptions) {\r\n if (semver.gte(targetOptions.runtimeVersion, \"0.13.0\")) {\r\n return {\r\n externalPath: \"https://node-webkit.s3.amazonaws.com/v\" + targetOptions.runtimeVersion + \"/\",\r\n winLibs: [\r\n {\r\n dir: targetOptions.isX64 ? \"x64\" : \"\",\r\n name: targetOptions.runtime + \".lib\"\r\n },\r\n {\r\n dir: targetOptions.isX64 ? \"x64\" : \"\",\r\n name: \"node.lib\"\r\n }\r\n ],\r\n tarPath: \"nw-headers-v\" + targetOptions.runtimeVersion + \".tar.gz\",\r\n headerOnly: false\r\n };\r\n }\r\n return {\r\n externalPath: \"https://node-webkit.s3.amazonaws.com/v\" + targetOptions.runtimeVersion + \"/\",\r\n winLibs: [{\r\n dir: targetOptions.isX64 ? \"x64\" : \"\",\r\n name: targetOptions.runtime + \".lib\"\r\n }],\r\n tarPath: \"nw-headers-v\" + targetOptions.runtimeVersion + \".tar.gz\",\r\n headerOnly: false\r\n };\r\n },\r\n electron: function (targetOptions) {\r\n return {\r\n externalPath: \"https://atom.io/download/atom-shell/v\" + targetOptions.runtimeVersion + \"/\",\r\n winLibs: [{\r\n dir: targetOptions.isX64 ? \"x64\" : \"\",\r\n name: \"node.lib\"\r\n }],\r\n tarPath: \"node\" + \"-v\" + targetOptions.runtimeVersion + \".tar.gz\",\r\n headerOnly: false\r\n };\r\n },\r\n get: function (targetOptions) {\r\n assert(_.isObject(targetOptions));\r\n\r\n let runtime = targetOptions.runtime;\r\n let func = runtimePaths[runtime];\r\n let paths;\r\n if (_.isFunction(func) && _.isPlainObject(paths = func(targetOptions))) {\r\n return paths;\r\n }\r\n throw new Error(\"Unknown runtime: \" + runtime);\r\n }\r\n};\r\n\r\nmodule.exports = runtimePaths;"],"file":"runtimePaths.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["runtimePaths.js"],"sourcesContent":["\"use strict\";\nlet _ = require(\"lodash\");\nlet assert = require(\"assert\");\nlet semver = require(\"semver\");\n\nlet runtimePaths = {\n node: function (targetOptions) {\n if (semver.lt(targetOptions.runtimeVersion, \"4.0.0\")) {\n return {\n externalPath: \"https://nodejs.org/dist/v\" + targetOptions.runtimeVersion + \"/\",\n winLibs: [{\n dir: targetOptions.isX64 ? \"x64\" : \"\",\n name: targetOptions.runtime + \".lib\"\n }],\n tarPath: targetOptions.runtime + \"-v\" + targetOptions.runtimeVersion + \".tar.gz\",\n headerOnly: false\n };\n }\n else {\n return {\n externalPath: \"https://nodejs.org/dist/v\" + targetOptions.runtimeVersion + \"/\",\n winLibs: [{\n dir: targetOptions.isX64 ? \"win-x64\" : \"win-x86\",\n name: targetOptions.runtime + \".lib\"\n }],\n tarPath: targetOptions.runtime + \"-v\" + targetOptions.runtimeVersion + \"-headers.tar.gz\",\n headerOnly: true\n };\n }\n },\n iojs: function (targetOptions) {\n return {\n externalPath: \"https://iojs.org/dist/v\" + targetOptions.runtimeVersion + \"/\",\n winLibs: [{\n dir: targetOptions.isX64 ? \"win-x64\" : \"win-x86\",\n name: targetOptions.runtime + \".lib\"\n }],\n tarPath: targetOptions.runtime + \"-v\" + targetOptions.runtimeVersion + \".tar.gz\",\n headerOnly: false\n };\n },\n nw: function (targetOptions) {\n if (semver.gte(targetOptions.runtimeVersion, \"0.13.0\")) {\n return {\n externalPath: \"https://node-webkit.s3.amazonaws.com/v\" + targetOptions.runtimeVersion + \"/\",\n winLibs: [\n {\n dir: targetOptions.isX64 ? \"x64\" : \"\",\n name: targetOptions.runtime + \".lib\"\n },\n {\n dir: targetOptions.isX64 ? \"x64\" : \"\",\n name: \"node.lib\"\n }\n ],\n tarPath: \"nw-headers-v\" + targetOptions.runtimeVersion + \".tar.gz\",\n headerOnly: false\n };\n }\n return {\n externalPath: \"https://node-webkit.s3.amazonaws.com/v\" + targetOptions.runtimeVersion + \"/\",\n winLibs: [{\n dir: targetOptions.isX64 ? \"x64\" : \"\",\n name: targetOptions.runtime + \".lib\"\n }],\n tarPath: \"nw-headers-v\" + targetOptions.runtimeVersion + \".tar.gz\",\n headerOnly: false\n };\n },\n electron: function (targetOptions) {\n return {\n externalPath: \"https://atom.io/download/atom-shell/v\" + targetOptions.runtimeVersion + \"/\",\n winLibs: [{\n dir: targetOptions.isX64 ? \"x64\" : \"\",\n name: \"node.lib\"\n }],\n tarPath: \"node\" + \"-v\" + targetOptions.runtimeVersion + \".tar.gz\",\n headerOnly: false\n };\n },\n get: function (targetOptions) {\n assert(_.isObject(targetOptions));\n\n let runtime = targetOptions.runtime;\n let func = runtimePaths[runtime];\n let paths;\n if (_.isFunction(func) && _.isPlainObject(paths = func(targetOptions))) {\n return paths;\n }\n throw new Error(\"Unknown runtime: \" + runtime);\n }\n};\n\nmodule.exports = runtimePaths;"],"file":"runtimePaths.js"} \ No newline at end of file diff --git a/lib/es5/targetOptions.js.map b/lib/es5/targetOptions.js.map index 1c9ae87f..703a0753 100644 --- a/lib/es5/targetOptions.js.map +++ b/lib/es5/targetOptions.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["targetOptions.js"],"sourcesContent":["\"use strict\";\r\n\r\nlet environment = require(\"./environment\");\r\nlet _ = require(\"lodash\");\r\n\r\nfunction TargetOptions(options) {\r\n this.options = options || {};\r\n}\r\n\r\nObject.defineProperties(TargetOptions.prototype, {\r\n arch: {\r\n get: function () {\r\n return this.options.arch || environment.arch;\r\n }\r\n },\r\n isX86: {\r\n get: function () {\r\n return this.arch === \"ia32\";\r\n }\r\n },\r\n isX64: {\r\n get: function () {\r\n return this.arch === \"x64\";\r\n }\r\n },\r\n isArm: {\r\n get: function () {\r\n return this.arch === \"arm\";\r\n }\r\n },\r\n runtime: {\r\n get: function () {\r\n return this.options.runtime || environment.runtime;\r\n }\r\n },\r\n runtimeVersion: {\r\n get: function () {\r\n return this.options.runtimeVersion || environment.runtimeVersion;\r\n }\r\n }\r\n});\r\n\r\nmodule.exports = TargetOptions;"],"file":"targetOptions.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["targetOptions.js"],"sourcesContent":["\"use strict\";\n\nlet environment = require(\"./environment\");\nlet _ = require(\"lodash\");\n\nfunction TargetOptions(options) {\n this.options = options || {};\n}\n\nObject.defineProperties(TargetOptions.prototype, {\n arch: {\n get: function () {\n return this.options.arch || environment.arch;\n }\n },\n isX86: {\n get: function () {\n return this.arch === \"ia32\";\n }\n },\n isX64: {\n get: function () {\n return this.arch === \"x64\";\n }\n },\n isArm: {\n get: function () {\n return this.arch === \"arm\";\n }\n },\n runtime: {\n get: function () {\n return this.options.runtime || environment.runtime;\n }\n },\n runtimeVersion: {\n get: function () {\n return this.options.runtimeVersion || environment.runtimeVersion;\n }\n }\n});\n\nmodule.exports = TargetOptions;"],"file":"targetOptions.js"} \ No newline at end of file diff --git a/lib/es5/toolset.js b/lib/es5/toolset.js index 24cd3d15..99d8db34 100644 --- a/lib/es5/toolset.js +++ b/lib/es5/toolset.js @@ -12,6 +12,7 @@ function Toolset(options) { this.options = options || {}; this.targetOptions = new TargetOptions(this.options); this.generator = options.generator; + this.toolset = options.toolset; this.target = options.target; this.cCompilerPath = null; this.cppCompilerPath = null; diff --git a/lib/es5/toolset.js.map b/lib/es5/toolset.js.map index 360a002c..6e1b64ab 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\";\r\nlet Bluebird = require(\"bluebird\");\r\nlet async = Bluebird.coroutine;\r\nlet _ = require(\"lodash\");\r\nlet TargetOptions = require(\"./targetOptions\");\r\nlet environment = require(\"./environment\");\r\nlet assert = require(\"assert\");\r\nlet vsDetect = require(\"./vsDetect\");\r\nlet path = require(\"path\");\r\nlet CMLog = require(\"./cmLog\");\r\n\r\nfunction Toolset(options) {\r\n this.options = options || {};\r\n this.targetOptions = new TargetOptions(this.options);\r\n this.generator = options.generator;\r\n this.target = options.target;\r\n this.cCompilerPath = null;\r\n this.cppCompilerPath = null;\r\n this.compilerFlags = [];\r\n this.linkerFlags = [];\r\n this.makePath = null;\r\n this.log = new CMLog(this.options);\r\n this._initialized = false;\r\n}\r\n\r\nToolset.prototype.initialize = async(function*(install) {\r\n if (!this._initialized) {\r\n if (environment.isWin) {\r\n yield this.initializeWin(install);\r\n }\r\n else {\r\n this.initializePosix(install);\r\n }\r\n this._initialized = true;\r\n }\r\n});\r\n\r\nToolset.prototype.initializePosix = function (install) {\r\n // 1: Compiler\r\n if (!environment.isGPPAvailable && !environment.isClangAvailable) {\r\n if (environment.isOSX) {\r\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'.\");\r\n }\r\n else {\r\n throw new Error(\"C++ Compiler toolset is not available. Install proper compiler toolset with your package manager, eg. 'sudo apt-get install g++'.\");\r\n }\r\n }\r\n\r\n if (this.options.preferClang && environment.isClangAvailable) {\r\n if (install) {\r\n this.log.info(\"TOOL\", \"Using clang++ compiler, because preferClang option is set, and clang++ is available.\");\r\n }\r\n this.cppCompilerPath = \"clang++\";\r\n this.cCompilerPath = \"clang\";\r\n }\r\n else if (this.options.preferGnu && environment.isGPPAvailable) {\r\n if (install) {\r\n this.log.info(\"TOOL\", \"Using g++ compiler, because preferGnu option is set, and g++ is available.\");\r\n }\r\n this.cppCompilerPath = \"g++\";\r\n this.cCompilerPath = \"gcc\";\r\n }\r\n // if it's already set because of options...\r\n if (this.generator) { \r\n if (install) {\r\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\r\n }\r\n }\r\n // 2: Generator\r\n else if (environment.isOSX) {\r\n if (this.options.preferXcode) {\r\n if (install) {\r\n this.log.info(\"TOOL\", \"Using Xcode generator, because preferXcode option is set.\");\r\n }\r\n this.generator = \"Xcode\";\r\n }\r\n else if (this.options.preferMake && environment.isMakeAvailable) {\r\n if (install) {\r\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\r\n }\r\n this.generator = \"Unix Makefiles\";\r\n }\r\n else if (environment.isNinjaAvailable) {\r\n if (install) {\r\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\r\n }\r\n this.generator = \"Ninja\";\r\n }\r\n else {\r\n if (install) {\r\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\r\n }\r\n this.generator = \"Unix Makefiles\";\r\n }\r\n }\r\n else {\r\n if (this.options.preferMake && environment.isMakeAvailable) {\r\n if (install) {\r\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator, because preferMake option is set, and make is available.\");\r\n }\r\n this.generator = \"Unix Makefiles\";\r\n }\r\n else if (environment.isNinjaAvailable) {\r\n if (install) {\r\n this.log.info(\"TOOL\", \"Using Ninja generator, because ninja is available.\");\r\n }\r\n this.generator = \"Ninja\";\r\n }\r\n else {\r\n if (install) {\r\n this.log.info(\"TOOL\", \"Using Unix Makefiles generator.\");\r\n }\r\n this.generator = \"Unix Makefiles\";\r\n }\r\n }\r\n\r\n // 3: Flags\r\n this._setupGNUStd(install);\r\n\r\n if (environment.isOSX) {\r\n if (install) {\r\n this.log.verbose(\"TOOL\", \"Setting default OSX compiler flags.\");\r\n }\r\n\r\n this.compilerFlags.push(\"-D_DARWIN_USE_64_BIT_INODE=1\");\r\n this.compilerFlags.push(\"-D_LARGEFILE_SOURCE\");\r\n this.compilerFlags.push(\"-D_FILE_OFFSET_BITS=64\");\r\n this.compilerFlags.push(\"-DBUILDING_NODE_EXTENSION\");\r\n this.compilerFlags.push(\"-w\");\r\n this.linkerFlags.push(\"-undefined dynamic_lookup\");\r\n }\r\n\r\n // 4: Build target\r\n if (this.options.target) {\r\n this.log.info(\"TOOL\", \"Building only the \" + this.options.target + \" target, as specified from the command line.\");\r\n }\r\n\r\n};\r\n\r\nToolset.prototype._setupGNUStd = function (install) {\r\n if (this.options.std) {\r\n if (this.options.std !== \"c++98\") {\r\n if (install) {\r\n this.log.info(\"TOOL\", `Using ${this.options.std} compiler standard.`);\r\n }\r\n this.compilerFlags.push(\"-std=\" + this.options.std);\r\n }\r\n }\r\n else {\r\n if (install) {\r\n this.log.info(\"TOOL\", \"Using c++11 compiler standard.\");\r\n }\r\n this.compilerFlags.push(\"-std=c++11\");\r\n }\r\n};\r\n\r\nToolset.prototype.initializeWin = async(function*(install) {\r\n // Visual Studio:\r\n // if it's already set because of options...\r\n if (this.generator) {\r\n if (install) {\r\n this.log.info(\"TOOL\", \"Using \" + this.options.generator + \" generator, as specified from commandline.\");\r\n }\r\n if (this.targetOptions.isX86) {\r\n if (install) {\r\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\r\n }\r\n this.linkerFlags.push(\"/SAFESEH:NO\");\r\n }\r\n return;\r\n }\r\n let topVS = yield this._getTopSupportedVisualStudioGenerator();\r\n //if (!this.options.noMSVC) {\r\n if (topVS) {\r\n if (install) {\r\n this.log.info(\"TOOL\", `Using ${topVS} generator.`);\r\n }\r\n this.generator = topVS;\r\n if (this.targetOptions.isX86) {\r\n if (install) {\r\n this.log.verbose(\"TOOL\", \"Setting SAFESEH:NO linker flag.\");\r\n }\r\n this.linkerFlags.push(\"/SAFESEH:NO\");\r\n }\r\n }\r\n else {\r\n throw new Error(\"There is no Visual C++ compiler installed. Install Visual C++ Build Toolset or Visual Studio.\");\r\n }\r\n});\r\n\r\nToolset.prototype._getTopSupportedVisualStudioGenerator = async(function*() {\r\n let CMake = require(\"./cMake\");\r\n assert(environment.isWin);\r\n let list = yield CMake.getGenerators(this.options);\r\n let maxVer = 0;\r\n let result = null;\r\n for (let gen of list) {\r\n let found = /^visual studio (\\d+)/i.exec(gen);\r\n if (found) {\r\n let ver = parseInt(found[1]);\r\n if (ver > maxVer) {\r\n if (yield vsDetect.isInstalled(ver + \".0\")) {\r\n result = this.targetOptions.isX64 ? (gen + \" Win64\") : gen;\r\n maxVer = ver;\r\n }\r\n }\r\n }\r\n }\r\n return result;\r\n});\r\n\r\nmodule.exports = Toolset;\r\n"],"file":"toolset.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["toolset.js"],"sourcesContent":["\"use strict\";\nlet Bluebird = require(\"bluebird\");\nlet async = Bluebird.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 this._setupGNUStd(install);\n\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.compilerFlags.push(\"-w\");\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};\n\nToolset.prototype._setupGNUStd = function (install) {\n if (this.options.std) {\n if (this.options.std !== \"c++98\") {\n if (install) {\n this.log.info(\"TOOL\", `Using ${this.options.std} compiler standard.`);\n }\n this.compilerFlags.push(\"-std=\" + this.options.std);\n }\n }\n else {\n if (install) {\n this.log.info(\"TOOL\", \"Using c++11 compiler standard.\");\n }\n this.compilerFlags.push(\"-std=c++11\");\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 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 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 let ver = parseInt(found[1]);\n if (ver > maxVer) {\n if (yield vsDetect.isInstalled(ver + \".0\")) {\n result = this.targetOptions.isX64 ? (gen + \" Win64\") : gen;\n maxVer = ver;\n }\n }\n }\n }\n return result;\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 b86d03b4..5870e374 100644 --- a/lib/es6/cMake.js +++ b/lib/es6/cMake.js @@ -168,6 +168,9 @@ CMake.prototype.getConfigureCommand = async(function* () { if (this.toolset.generator) { command += " -G\"" + this.toolset.generator + "\""; } + if (this.toolset.toolset) { + command += " -T\"" + this.toolset.toolset + "\""; + } if (this.toolset.cppCompilerPath) { D.push({"CMAKE_CXX_COMPILER": this.toolset.cppCompilerPath}); } diff --git a/lib/es6/toolset.js b/lib/es6/toolset.js index b78b6e15..5b4cdac5 100644 --- a/lib/es6/toolset.js +++ b/lib/es6/toolset.js @@ -13,6 +13,7 @@ function Toolset(options) { this.options = options || {}; this.targetOptions = new TargetOptions(this.options); this.generator = options.generator; + this.toolset = options.toolset; this.target = options.target; this.cCompilerPath = null; this.cppCompilerPath = null; diff --git a/tests/es5/buildSystem.js.map b/tests/es5/buildSystem.js.map index 13e9cd3e..fae68c0d 100644 --- a/tests/es5/buildSystem.js.map +++ b/tests/es5/buildSystem.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["buildSystem.js"],"sourcesContent":["\"use strict\";\r\n/* global describe,it,before */\r\n\r\nlet assert = require(\"assert\");\r\nlet lib = require(\"../../\");\r\nlet CMake = lib.CMake;\r\nlet BuildSystem = lib.BuildSystem;\r\nlet _ = require(\"lodash\");\r\nlet path = require(\"path\");\r\nlet Bluebird = require(\"bluebird\");\r\nlet async = Bluebird.coroutine;\r\nlet log = require(\"npmlog\");\r\nlet testRunner = require(\"./testRunner\");\r\nlet testCases = require(\"./testCases\");\r\n\r\ndescribe(\"BuildSystem\", function () {\r\n this.timeout(300000);\r\n\r\n before(function() {\r\n if (process.env.UT_LOG_LEVEL) {\r\n log.level = process.env.UT_LOG_LEVEL;\r\n log.resume();\r\n }\r\n lib.locateNAN.__projectRoot = path.resolve(path.join(__dirname, \"../../\"));\r\n });\r\n\r\n describe(\"Build with various options\", function() {\r\n testRunner.runCase(testCases.buildPrototypeWithDirectoryOption);\r\n });\r\n\r\n it(\"should provide list of generators\", function (done) {\r\n async(function*() {\r\n let gens = yield CMake.getGenerators();\r\n assert(_.isArray(gens));\r\n assert(gens.length > 0);\r\n assert.equal(gens.filter(function (g) { return g.length; }).length, gens.length);\r\n })().nodeify(done);\r\n });\r\n\r\n it(\"should rebuild prototype if cwd is the source directory\", function (done) {\r\n testCases.buildPrototype2WithCWD().nodeify(done);\r\n });\r\n\r\n it(\"should run with old GNU compilers\", function (done) {\r\n testCases.shouldConfigurePreC11Properly().nodeify(done);\r\n });\r\n\r\n it(\"should configure with custom option\", function (done) {\r\n testCases.configureWithCustomOptions().nodeify(done);\r\n });\r\n});\r\n"],"file":"buildSystem.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["buildSystem.js"],"sourcesContent":["\"use strict\";\n/* global describe,it,before */\n\nlet assert = require(\"assert\");\nlet lib = require(\"../../\");\nlet CMake = lib.CMake;\nlet BuildSystem = lib.BuildSystem;\nlet _ = require(\"lodash\");\nlet path = require(\"path\");\nlet Bluebird = require(\"bluebird\");\nlet async = Bluebird.coroutine;\nlet log = require(\"npmlog\");\nlet testRunner = require(\"./testRunner\");\nlet testCases = require(\"./testCases\");\n\ndescribe(\"BuildSystem\", function () {\n this.timeout(300000);\n\n before(function() {\n if (process.env.UT_LOG_LEVEL) {\n log.level = process.env.UT_LOG_LEVEL;\n log.resume();\n }\n lib.locateNAN.__projectRoot = path.resolve(path.join(__dirname, \"../../\"));\n });\n\n describe(\"Build with various options\", function() {\n testRunner.runCase(testCases.buildPrototypeWithDirectoryOption);\n });\n\n it(\"should provide list of generators\", function (done) {\n async(function*() {\n let gens = yield CMake.getGenerators();\n assert(_.isArray(gens));\n assert(gens.length > 0);\n assert.equal(gens.filter(function (g) { return g.length; }).length, gens.length);\n })().nodeify(done);\n });\n\n it(\"should rebuild prototype if cwd is the source directory\", function (done) {\n testCases.buildPrototype2WithCWD().nodeify(done);\n });\n\n it(\"should run with old GNU compilers\", function (done) {\n testCases.shouldConfigurePreC11Properly().nodeify(done);\n });\n\n it(\"should configure with custom option\", function (done) {\n testCases.configureWithCustomOptions().nodeify(done);\n });\n});\n"],"file":"buildSystem.js"} \ No newline at end of file diff --git a/tests/es5/dist.js.map b/tests/es5/dist.js.map index 51deafea..80ebd013 100644 --- a/tests/es5/dist.js.map +++ b/tests/es5/dist.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["dist.js"],"sourcesContent":["\"use strict\";\r\n/* global describe,it */\r\n\r\nlet Bluebird = require(\"bluebird\");\r\nlet fs = Bluebird.promisifyAll(require(\"fs-extra\"));\r\nlet Dist = require(\"../../\").Dist;\r\nlet assert = require(\"assert\");\r\nlet async = Bluebird.coroutine;\r\n\r\nlet testDownload = process.env.TEST_DOWNLOAD === \"1\";\r\n\r\ndescribe(\"dist\", function () {\r\n it(\"should download dist files if needed\", function (done) {\r\n this.timeout(60000);\r\n async(function*() {\r\n let dist = new Dist();\r\n if (testDownload) {\r\n yield fs.deleteAsync(dist.internalPath);\r\n assert(dist.downloaded === false);\r\n yield dist.ensureDownloaded();\r\n assert(dist.downloaded);\r\n }\r\n else {\r\n yield dist.ensureDownloaded();\r\n }\r\n })().nodeify(done); \r\n });\r\n\r\n});"],"file":"dist.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["dist.js"],"sourcesContent":["\"use strict\";\n/* global describe,it */\n\nlet Bluebird = require(\"bluebird\");\nlet fs = Bluebird.promisifyAll(require(\"fs-extra\"));\nlet Dist = require(\"../../\").Dist;\nlet assert = require(\"assert\");\nlet async = Bluebird.coroutine;\n\nlet testDownload = process.env.TEST_DOWNLOAD === \"1\";\n\ndescribe(\"dist\", function () {\n it(\"should download dist files if needed\", function (done) {\n this.timeout(60000);\n async(function*() {\n let dist = new Dist();\n if (testDownload) {\n yield fs.deleteAsync(dist.internalPath);\n assert(dist.downloaded === false);\n yield dist.ensureDownloaded();\n assert(dist.downloaded);\n }\n else {\n yield dist.ensureDownloaded();\n }\n })().nodeify(done); \n });\n\n});"],"file":"dist.js"} \ No newline at end of file diff --git a/tests/es5/index.js.map b/tests/es5/index.js.map index cd849bf5..c43a7587 100644 --- a/tests/es5/index.js.map +++ b/tests/es5/index.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["index.js"],"sourcesContent":["\"use strict\";\r\nrequire(\"./dist\");\r\nrequire(\"./buildSystem\");"],"file":"index.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["index.js"],"sourcesContent":["\"use strict\";\nrequire(\"./dist\");\nrequire(\"./buildSystem\");"],"file":"index.js"} \ No newline at end of file diff --git a/tests/es5/testCases.js.map b/tests/es5/testCases.js.map index e42a97f5..b678ecbc 100644 --- a/tests/es5/testCases.js.map +++ b/tests/es5/testCases.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["testCases.js"],"sourcesContent":["\"use strict\";\r\nlet assert = require(\"assert\");\r\nlet lib = require(\"../../\");\r\nlet BuildSystem = lib.BuildSystem;\r\nlet _ = require(\"lodash\");\r\nlet path = require(\"path\");\r\nlet Bluebird = require(\"bluebird\");\r\nlet async = Bluebird.coroutine;\r\nlet fs = Bluebird.promisifyAll(require(\"fs-extra\"));\r\n\r\nlet testCases = {\r\n buildPrototypeWithDirectoryOption: async(function*(options) {\r\n options = _.extend({\r\n directory: path.resolve(path.join(__dirname, \"./prototype\"))\r\n }, options);\r\n let buildSystem = new BuildSystem(options);\r\n yield buildSystem.rebuild();\r\n assert.ok((yield fs.statAsync(path.join(__dirname, \"prototype/build/Release/addon.node\"))).isFile());\r\n }),\r\n buildPrototype2WithCWD: async(function*(options) {\r\n let cwd = process.cwd();\r\n process.chdir(path.resolve(path.join(__dirname, \"./prototype2\")));\r\n let buildSystem = new BuildSystem(options);\r\n try {\r\n yield buildSystem.rebuild();\r\n assert.ok((yield fs.statAsync(path.join(__dirname, \"prototype2/build/Release/addon2.node\"))).isFile());\r\n }\r\n finally {\r\n process.chdir(cwd);\r\n }\r\n }),\r\n shouldConfigurePreC11Properly: async(function*(options) {\r\n options = _.extend({\r\n directory: path.resolve(path.join(__dirname, \"./prototype\")),\r\n std: \"c++98\"\r\n }, options);\r\n let buildSystem = new BuildSystem(options);\r\n if (!/visual studio/i.test(buildSystem.toolset.generator)) {\r\n let command = yield buildSystem.getConfigureCommand();\r\n assert.equal(command.indexOf(\"-std=c++11\"), -1, \"c++11 still forced\");\r\n }\r\n }),\r\n configureWithCustomOptions: async(function*(options) {\r\n options = _.extend({\r\n directory: path.resolve(path.join(__dirname, \"./prototype\")),\r\n cMakeOptions: {\r\n foo: \"bar\"\r\n }\r\n }, options);\r\n let buildSystem = new BuildSystem(options);\r\n\r\n let command = yield buildSystem.getConfigureCommand();\r\n assert.notEqual(command.indexOf(\"-Dfoo=\\\"bar\\\"\"), -1, \"custom options added\");\r\n })\r\n};\r\n\r\nmodule.exports = testCases;\r\n"],"file":"testCases.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["testCases.js"],"sourcesContent":["\"use strict\";\nlet assert = require(\"assert\");\nlet lib = require(\"../../\");\nlet BuildSystem = lib.BuildSystem;\nlet _ = require(\"lodash\");\nlet path = require(\"path\");\nlet Bluebird = require(\"bluebird\");\nlet async = Bluebird.coroutine;\nlet fs = Bluebird.promisifyAll(require(\"fs-extra\"));\n\nlet testCases = {\n buildPrototypeWithDirectoryOption: async(function*(options) {\n options = _.extend({\n directory: path.resolve(path.join(__dirname, \"./prototype\"))\n }, options);\n let buildSystem = new BuildSystem(options);\n yield buildSystem.rebuild();\n assert.ok((yield fs.statAsync(path.join(__dirname, \"prototype/build/Release/addon.node\"))).isFile());\n }),\n buildPrototype2WithCWD: async(function*(options) {\n let cwd = process.cwd();\n process.chdir(path.resolve(path.join(__dirname, \"./prototype2\")));\n let buildSystem = new BuildSystem(options);\n try {\n yield buildSystem.rebuild();\n assert.ok((yield fs.statAsync(path.join(__dirname, \"prototype2/build/Release/addon2.node\"))).isFile());\n }\n finally {\n process.chdir(cwd);\n }\n }),\n shouldConfigurePreC11Properly: async(function*(options) {\n options = _.extend({\n directory: path.resolve(path.join(__dirname, \"./prototype\")),\n std: \"c++98\"\n }, options);\n let buildSystem = new BuildSystem(options);\n if (!/visual studio/i.test(buildSystem.toolset.generator)) {\n let command = yield buildSystem.getConfigureCommand();\n assert.equal(command.indexOf(\"-std=c++11\"), -1, \"c++11 still forced\");\n }\n }),\n configureWithCustomOptions: async(function*(options) {\n options = _.extend({\n directory: path.resolve(path.join(__dirname, \"./prototype\")),\n cMakeOptions: {\n foo: \"bar\"\n }\n }, options);\n let buildSystem = new BuildSystem(options);\n\n let command = yield buildSystem.getConfigureCommand();\n assert.notEqual(command.indexOf(\"-Dfoo=\\\"bar\\\"\"), -1, \"custom options added\");\n })\n};\n\nmodule.exports = testCases;\n"],"file":"testCases.js"} \ No newline at end of file diff --git a/tests/es5/testRunner.js.map b/tests/es5/testRunner.js.map index 6c9a3533..dd15e41d 100644 --- a/tests/es5/testRunner.js.map +++ b/tests/es5/testRunner.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["testRunner.js"],"sourcesContent":["\"use strict\";\r\n/* global it */\r\nlet lib = require(\"../../\");\r\nlet environment = lib.environment;\r\nlet Bluebird = require(\"bluebird\");\r\nlet async = Bluebird.coroutine;\r\nlet _ = require(\"lodash\");\r\nlet log = require(\"npmlog\");\r\nlet util = require(\"util\");\r\n\r\nfunction* generateRuntimeOptions() {\r\n function* generateForNode(arch) {\r\n // Old:\r\n yield {\r\n runtime: \"node\",\r\n runtimeVersion: \"0.10.36\",\r\n arch: arch\r\n };\r\n\r\n // LTS:\r\n yield {\r\n runtime: \"node\",\r\n runtimeVersion: \"4.4.2\",\r\n arch: arch\r\n };\r\n\r\n // Current:\r\n if (environment.runtimeVersion !== \"5.10.0\") {\r\n yield {\r\n runtime: \"node\",\r\n runtimeVersion: \"5.10.0\",\r\n arch: arch\r\n };\r\n }\r\n }\r\n\r\n function* generateForNWJS(arch) {\r\n yield {\r\n runtime: \"nw\",\r\n runtimeVersion: \"0.12.3\",\r\n arch: arch\r\n };\r\n\r\n // Latest:\r\n yield {\r\n runtime: \"nw\",\r\n runtimeVersion: \"0.13.2\",\r\n arch: arch\r\n };\r\n }\r\n\r\n function* generateForElectron(arch) {\r\n // Latest:\r\n yield {\r\n runtime: \"electron\",\r\n runtimeVersion: \"0.37.3\",\r\n arch: arch\r\n };\r\n }\r\n\r\n function* generateForArch(arch) {\r\n yield* generateForNode(arch);\r\n yield* generateForNWJS(arch);\r\n yield* generateForElectron(arch);\r\n }\r\n\r\n if (environment.isWin) {\r\n yield* generateForArch(\"x64\");\r\n yield* generateForArch(\"ia32\");\r\n }\r\n else {\r\n yield* generateForArch();\r\n }\r\n\r\n // Actual:\r\n yield {};\r\n}\r\n\r\nfunction* generateOptions() {\r\n for (let runtimeOptions of generateRuntimeOptions()) {\r\n if (environment.isWin) {\r\n // V C++:\r\n yield runtimeOptions;\r\n }\r\n else {\r\n // Clang, Make\r\n yield _.extend({}, runtimeOptions, {preferClang: true, referMake: true});\r\n\r\n // Clang, Ninja\r\n yield _.extend({}, runtimeOptions, {preferClang: true});\r\n\r\n // g++, Make\r\n yield _.extend({}, runtimeOptions, {preferGnu: true, referMake: true});\r\n\r\n // g++, Ninja\r\n yield _.extend({}, runtimeOptions, {preferGnu: true});\r\n\r\n // Default:\r\n yield runtimeOptions;\r\n }\r\n }\r\n}\r\n\r\nlet testRunner = {\r\n runCase: function (testCase, options) {\r\n for (let testOptions of generateOptions()) {\r\n let currentOptions = _.extend({}, testOptions, options || {});\r\n it(\"should build with: \" + util.inspect(currentOptions), function (done) {\r\n async(function*() {\r\n log.info(\"TEST\", \"Running case for options of: \" + util.inspect(currentOptions));\r\n yield testCase(currentOptions);\r\n })().nodeify(done);\r\n });\r\n }\r\n }\r\n};\r\n\r\nmodule.exports = testRunner;"],"file":"testRunner.js"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["testRunner.js"],"sourcesContent":["\"use strict\";\n/* global it */\nlet lib = require(\"../../\");\nlet environment = lib.environment;\nlet Bluebird = require(\"bluebird\");\nlet async = Bluebird.coroutine;\nlet _ = require(\"lodash\");\nlet log = require(\"npmlog\");\nlet util = require(\"util\");\n\nfunction* generateRuntimeOptions() {\n function* generateForNode(arch) {\n // Old:\n yield {\n runtime: \"node\",\n runtimeVersion: \"0.10.36\",\n arch: arch\n };\n\n // LTS:\n yield {\n runtime: \"node\",\n runtimeVersion: \"4.4.2\",\n arch: arch\n };\n\n // Current:\n if (environment.runtimeVersion !== \"5.10.0\") {\n yield {\n runtime: \"node\",\n runtimeVersion: \"5.10.0\",\n arch: arch\n };\n }\n }\n\n function* generateForNWJS(arch) {\n yield {\n runtime: \"nw\",\n runtimeVersion: \"0.12.3\",\n arch: arch\n };\n\n // Latest:\n yield {\n runtime: \"nw\",\n runtimeVersion: \"0.13.2\",\n arch: arch\n };\n }\n\n function* generateForElectron(arch) {\n // Latest:\n yield {\n runtime: \"electron\",\n runtimeVersion: \"0.37.3\",\n arch: arch\n };\n }\n\n function* generateForArch(arch) {\n yield* generateForNode(arch);\n yield* generateForNWJS(arch);\n yield* generateForElectron(arch);\n }\n\n if (environment.isWin) {\n yield* generateForArch(\"x64\");\n yield* generateForArch(\"ia32\");\n }\n else {\n yield* generateForArch();\n }\n\n // Actual:\n yield {};\n}\n\nfunction* generateOptions() {\n for (let runtimeOptions of generateRuntimeOptions()) {\n if (environment.isWin) {\n // V C++:\n yield runtimeOptions;\n }\n else {\n // Clang, Make\n yield _.extend({}, runtimeOptions, {preferClang: true, referMake: true});\n\n // Clang, Ninja\n yield _.extend({}, runtimeOptions, {preferClang: true});\n\n // g++, Make\n yield _.extend({}, runtimeOptions, {preferGnu: true, referMake: true});\n\n // g++, Ninja\n yield _.extend({}, runtimeOptions, {preferGnu: true});\n\n // Default:\n yield runtimeOptions;\n }\n }\n}\n\nlet testRunner = {\n runCase: function (testCase, options) {\n for (let testOptions of generateOptions()) {\n let currentOptions = _.extend({}, testOptions, options || {});\n it(\"should build with: \" + util.inspect(currentOptions), function (done) {\n async(function*() {\n log.info(\"TEST\", \"Running case for options of: \" + util.inspect(currentOptions));\n yield testCase(currentOptions);\n })().nodeify(done);\n });\n }\n }\n};\n\nmodule.exports = testRunner;"],"file":"testRunner.js"} \ No newline at end of file