aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/api/runenvironment.cpp
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@petroules.com>2014-04-01 11:51:46 -0400
committerJoerg Bornemann <joerg.bornemann@digia.com>2014-04-15 18:54:24 +0200
commit5877328c4dacb1283408083cb3538ea5bc46eae5 (patch)
tree1c0047b2a0a3d9ce38a7e49fb4bff84242baccf9 /src/lib/corelib/api/runenvironment.cpp
parentad533a593f0883f2a6e3362c2254afe4e0d5cf64 (diff)
Add support for running Node.js using qbs run.
Change-Id: I98a38e49cbea57d44b787eec12c2cb5f2e5cd601 Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'src/lib/corelib/api/runenvironment.cpp')
-rw-r--r--src/lib/corelib/api/runenvironment.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/lib/corelib/api/runenvironment.cpp b/src/lib/corelib/api/runenvironment.cpp
index b0be216f8..386a1769d 100644
--- a/src/lib/corelib/api/runenvironment.cpp
+++ b/src/lib/corelib/api/runenvironment.cpp
@@ -129,6 +129,21 @@ int RunEnvironment::runShell()
return system(command.toLocal8Bit().constData());
}
+static QString findExecutable(const QStringList &fileNames)
+{
+ const QStringList path = QString::fromLocal8Bit(qgetenv("PATH"))
+ .split(HostOsInfo::pathListSeparator(), QString::SkipEmptyParts);
+
+ foreach (const QString &fileName, fileNames) {
+ foreach (const QString &ppath, path) {
+ const QString fullPath = ppath + QLatin1Char('/') + fileName;
+ if (QFileInfo(fullPath).exists())
+ return QDir::cleanPath(fullPath);
+ }
+ }
+ return QString();
+}
+
int RunEnvironment::runTarget(const QString &targetBin, const QStringList &arguments)
{
const QStringList targetOS = PropertyFinder().propertyValue(
@@ -154,6 +169,15 @@ int RunEnvironment::runTarget(const QString &targetBin, const QStringList &argum
}
}
+ if (completeSuffix == QLatin1String("js")) {
+ // The Node.js binary is called nodejs on Debian/Ubuntu-family operating systems due to a
+ // conflict with another package containing a binary named node
+ targetExecutable = findExecutable(QStringList()
+ << QLatin1String("nodejs")
+ << QLatin1String("node"));
+ targetArguments.prepend(targetBin);
+ }
+
// Only check if the target is executable if we're not running it through another
// known application such as msiexec or wine, as we can't check in this case anyways
if (targetBin == targetExecutable && !QFileInfo(targetExecutable).isExecutable()) {
@@ -166,6 +190,7 @@ int RunEnvironment::runTarget(const QString &targetBin, const QStringList &argum
d->logger.qbsInfo() << Tr::tr("Starting target '%1'.").arg(QDir::toNativeSeparators(targetBin));
QProcess process;
+ process.setWorkingDirectory(QFileInfo(targetBin).absolutePath());
process.setProcessEnvironment(d->resolvedProduct->runEnvironment);
process.setProcessChannelMode(QProcess::ForwardedChannels);
process.start(targetExecutable, targetArguments);