diff options
| author | Jake Petroules <jake.petroules@petroules.com> | 2015-07-21 00:42:08 -0700 |
|---|---|---|
| committer | Jake Petroules <jake.petroules@petroules.com> | 2015-07-24 08:40:52 +0000 |
| commit | a621e751fcb5cb0d093e48da4556e69d8a26ba66 (patch) | |
| tree | 0bf76d415ba8c955575f7130935c035038ae937b | |
| parent | 4f99573b245a1ee8904384f41ec1f5aa4124f26d (diff) | |
| download | qbs-a621e751fcb5cb0d093e48da4556e69d8a26ba66.tar.gz | |
Add a TypeScript probe and use it in the modules.
This improves performance by ensursing that `tsc --version` is only
invoked once on module load, as well as providing qbs with the
knowledge of tsc's actual install location, which will be important in
future patches.
Change-Id: Ib736506a300f491ee1a7cccb3e679143ce7de89d
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
| -rw-r--r-- | share/qbs/imports/qbs/Probes/TypeScriptProbe.qbs | 86 | ||||
| -rw-r--r-- | share/qbs/modules/typescript/TypeScriptModule.qbs | 42 | ||||
| -rw-r--r-- | share/qbs/modules/typescript/typescript.js | 16 |
3 files changed, 117 insertions, 27 deletions
diff --git a/share/qbs/imports/qbs/Probes/TypeScriptProbe.qbs b/share/qbs/imports/qbs/Probes/TypeScriptProbe.qbs new file mode 100644 index 000000000..a676edc63 --- /dev/null +++ b/share/qbs/imports/qbs/Probes/TypeScriptProbe.qbs @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Jake Petroules. +** Contact: http://www.qt.io/licensing +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import qbs +import qbs.File +import qbs.FileInfo +import qbs.ModUtils +import "../../../modules/typescript/typescript.js" as TypeScript + +BinaryProbe { + id: tsc + names: ["tsc"] + + // Inputs + property path nodejsToolchainInstallPath + + // Outputs + property var version + + configure: { + // HACK: Duplicated from PathProbe.qbs + if (!names) + throw '"names" must be specified'; + var _names = ModUtils.concatAll(names); + if (nameFilter) + _names = _names.map(nameFilter); + // FIXME: Suggest how to obtain paths from system + var _paths = ModUtils.concatAll(pathPrefixes, platformPaths); + // FIXME: Add getenv support + var envs = ModUtils.concatAll(platformEnvironmentPaths, environmentPaths); + for (var i = 0; i < envs.length; ++i) { + var value = qbs.getEnv(envs[i]) || ''; + if (value.length > 0) + _paths = _paths.concat(value.split(qbs.pathListSeparator)); + } + var _suffixes = ModUtils.concatAll('', pathSuffixes); + for (i = 0; i < _names.length; ++i) { + for (var j = 0; j < _paths.length; ++j) { + for (var k = 0; k < _suffixes.length; ++k) { + var _filePath = FileInfo.joinPaths(_paths[j], _suffixes[k], _names[i]); + if (File.exists(_filePath)) { + found = true; + filePath = File.canonicalFilePath(_filePath); + fileName = FileInfo.fileName(filePath); + path = FileInfo.path(filePath); + version = TypeScript.findTscVersion(filePath, nodejsToolchainInstallPath); + return; + } + } + } + } + found = false; + path = undefined; + filePath = undefined; + fileName = undefined; + version = undefined; + // HACK: Duplicated from PathProbe.qbs + } +} diff --git a/share/qbs/modules/typescript/TypeScriptModule.qbs b/share/qbs/modules/typescript/TypeScriptModule.qbs index 34153e76c..654b13392 100644 --- a/share/qbs/modules/typescript/TypeScriptModule.qbs +++ b/share/qbs/modules/typescript/TypeScriptModule.qbs @@ -32,6 +32,7 @@ import qbs import qbs.File import qbs.FileInfo import qbs.ModUtils +import qbs.Probes import qbs.Process import "typescript.js" as TypeScript @@ -40,17 +41,23 @@ Module { additionalProductTypes: ["compiled_typescript"] - property path toolchainInstallPath - property string version: rawVersion ? rawVersion[2] : undefined + Probes.TypeScriptProbe { + id: tsc + pathPrefixes: [toolchainInstallPath] + nodejsToolchainInstallPath: nodejs.toolchainInstallPath + } + + property path toolchainInstallPath: tsc.path + property string version: tsc.version ? tsc.version[2] : undefined property var versionParts: version ? version.split('.').map(function(item) { return parseInt(item, 10); }) : [] property int versionMajor: versionParts[0] property int versionMinor: versionParts[1] property int versionPatch: versionParts[2] property int versionBuild: versionParts[3] - property string versionSuffix: rawVersion ? rawVersion[3] : undefined + property string versionSuffix: tsc.version ? tsc.version[3] : undefined - property string compilerName: "tsc" - property string compilerPath: FileInfo.joinPaths(toolchainInstallPath, compilerName) + property string compilerName: tsc.fileName + property string compilerPath: tsc.filePath property string warningLevel: "normal" PropertyOptions { @@ -104,22 +111,11 @@ Module { description: "whether to compile all source files to a single output file" } - // private properties - readonly property var rawVersion: { - var p = new Process(); - try { - p.exec(compilerPath, ["--version"]); - var re = /^(?:message TS6029: )?Version (([0-9]+(?:\.[0-9]+){1,3})(?:-(.+?))?)$/m; - var match = p.readStdOut().match(re); - if (match !== null) - return match; - } finally { - p.close(); - } - } - validate: { var validator = new ModUtils.PropertyValidator("typescript"); + validator.setRequiredProperty("toolchainInstallPath", toolchainInstallPath); + validator.setRequiredProperty("compilerName", compilerName); + validator.setRequiredProperty("compilerPath", compilerPath); validator.setRequiredProperty("version", version); validator.setRequiredProperty("versionParts", versionParts); validator.setRequiredProperty("versionMajor", versionMajor); @@ -138,14 +134,6 @@ Module { validator.validate(); } - setupBuildEnvironment: { - if (toolchainInstallPath) { - var v = new ModUtils.EnvironmentVariable("PATH", qbs.pathListSeparator, qbs.hostOS.contains("windows")); - v.prepend(toolchainInstallPath); - v.set(); - } - } - // TypeScript declaration files FileTagger { patterns: ["*.d.ts"] diff --git a/share/qbs/modules/typescript/typescript.js b/share/qbs/modules/typescript/typescript.js index c0ea71182..52676f6ea 100644 --- a/share/qbs/modules/typescript/typescript.js +++ b/share/qbs/modules/typescript/typescript.js @@ -29,6 +29,22 @@ ****************************************************************************/ var ModUtils = loadExtension("qbs.ModUtils"); +var Process = loadExtension("qbs.Process"); + +function findTscVersion(compilerFilePath, nodejsPath) { + var p = new Process(); + try { + if (nodejsPath) + p.setEnv("PATH", nodejsPath); + p.exec(compilerFilePath, ["--version"]); + var re = /^(?:message TS6029: )?Version (([0-9]+(?:\.[0-9]+){1,3})(?:-(.+?))?)$/m; + var match = p.readStdOut().trim().match(re); + if (match !== null) + return match; + } finally { + p.close(); + } +} function tscArguments(product, inputs, outputs) { var i; |
