diff options
author | Joerg Bornemann <joerg.bornemann@digia.com> | 2014-10-08 11:55:06 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@digia.com> | 2014-10-10 16:20:53 +0200 |
commit | 2b0184cf3e57942585ca4abd4311776d3998d4dc (patch) | |
tree | 775f0d91c65cb39a351962b71e58a93f923ee41d /src/lib | |
parent | c284f7e0e1f15af55224a660e16f5f066df150c8 (diff) | |
download | qbs-2b0184cf3e57942585ca4abd4311776d3998d4dc.tar.gz |
let JS extension Process find executables in PATH
Change-Id: I9052b8e895cb638bc4b8a185959c72e6819fb628
Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/corelib/buildgraph/processcommandexecutor.cpp | 3 | ||||
-rw-r--r-- | src/lib/corelib/jsextensions/process.cpp | 17 | ||||
-rw-r--r-- | src/lib/corelib/jsextensions/process.h | 5 | ||||
-rw-r--r-- | src/lib/corelib/tools/executablefinder.cpp | 30 | ||||
-rw-r--r-- | src/lib/corelib/tools/executablefinder.h | 9 |
5 files changed, 50 insertions, 14 deletions
diff --git a/src/lib/corelib/buildgraph/processcommandexecutor.cpp b/src/lib/corelib/buildgraph/processcommandexecutor.cpp index ff4cf65c4..75da7b050 100644 --- a/src/lib/corelib/buildgraph/processcommandexecutor.cpp +++ b/src/lib/corelib/buildgraph/processcommandexecutor.cpp @@ -82,7 +82,8 @@ void ProcessCommandExecutor::doStart() QBS_ASSERT(m_process.state() == QProcess::NotRunning, return); const ProcessCommand * const cmd = processCommand(); - const QString program = ExecutableFinder(transformer()->product(), logger()) + const QString program = ExecutableFinder(transformer()->product(), + transformer()->product()->buildEnvironment, logger()) .findExecutable(cmd->program(), cmd->workingDir()); // Use native separators for debug output, so people can copy-paste it to a command line. diff --git a/src/lib/corelib/jsextensions/process.cpp b/src/lib/corelib/jsextensions/process.cpp index 061cfa58d..10af9c911 100644 --- a/src/lib/corelib/jsextensions/process.cpp +++ b/src/lib/corelib/jsextensions/process.cpp @@ -31,6 +31,7 @@ #include <language/scriptengine.h> #include <logging/translator.h> +#include <tools/executablefinder.h> #include <tools/hostosinfo.h> #include <QProcess> @@ -123,7 +124,7 @@ bool Process::start(const QString &program, const QStringList &arguments) m_qProcess->setWorkingDirectory(m_workingDirectory); m_qProcess->setProcessEnvironment(m_environment); - m_qProcess->start(program, arguments); + m_qProcess->start(findExecutable(program), arguments); return m_qProcess->waitForStarted(); } @@ -131,7 +132,7 @@ int Process::exec(const QString &program, const QStringList &arguments, bool thr { Q_ASSERT(thisObject().engine() == engine()); - if (!start(program, arguments)) { + if (!start(findExecutable(program), arguments)) { if (throwOnError) { context()->throwError(Tr::tr("Error running '%1': %2") .arg(program, m_qProcess->errorString())); @@ -212,6 +213,18 @@ int Process::exitCode() const return m_qProcess->exitCode(); } +Logger Process::logger() const +{ + ScriptEngine *scriptEngine = static_cast<ScriptEngine *>(engine()); + return scriptEngine->logger(); +} + +QString Process::findExecutable(const QString &filePath) const +{ + ExecutableFinder exeFinder(ResolvedProductPtr(), m_environment, logger()); + return exeFinder.findExecutable(filePath, m_workingDirectory); +} + void Process::write(const QString &str) { (*m_textStream) << str; diff --git a/src/lib/corelib/jsextensions/process.h b/src/lib/corelib/jsextensions/process.h index 1dea021a3..86ed92853 100644 --- a/src/lib/corelib/jsextensions/process.h +++ b/src/lib/corelib/jsextensions/process.h @@ -30,6 +30,8 @@ #ifndef QBS_PROCESS_H #define QBS_PROCESS_H +#include <logging/logger.h> + #include <QObject> #include <QProcessEnvironment> #include <QScriptable> @@ -77,6 +79,9 @@ public: Q_INVOKABLE int exitCode() const; private: + Logger logger() const; + QString findExecutable(const QString &filePath) const; + QProcess *m_qProcess; QProcessEnvironment m_environment; QString m_workingDirectory; diff --git a/src/lib/corelib/tools/executablefinder.cpp b/src/lib/corelib/tools/executablefinder.cpp index 38c5da423..f82fa8ff5 100644 --- a/src/lib/corelib/tools/executablefinder.cpp +++ b/src/lib/corelib/tools/executablefinder.cpp @@ -33,7 +33,6 @@ #include "hostosinfo.h" #include <QDir> -#include <QProcessEnvironment> namespace qbs { namespace Internal { @@ -51,8 +50,11 @@ static QStringList populateExecutableSuffixes() QStringList ExecutableFinder::m_executableSuffixes = populateExecutableSuffixes(); -ExecutableFinder::ExecutableFinder(const ResolvedProductPtr &m_product, const Logger &logger) - : m_product(m_product), m_logger(logger) +ExecutableFinder::ExecutableFinder(const ResolvedProductPtr &m_product, + const QProcessEnvironment &env, const Logger &logger) + : m_product(m_product) + , m_environment(env) + , m_logger(logger) { } @@ -69,7 +71,7 @@ QString ExecutableFinder::findExecutable(const QString &path, const QString &wor QString ExecutableFinder::findBySuffix(const QString &filePath) const { - QString fullProgramPath = m_product->cachedExecutablePath(filePath); + QString fullProgramPath = cachedFilePath(filePath); if (!fullProgramPath.isEmpty()) return fullProgramPath; @@ -78,7 +80,7 @@ QString ExecutableFinder::findBySuffix(const QString &filePath) const m_logger.qbsTrace() << "[EXEC] looking for executable by suffix " << fullProgramPath; const QString emptyDirectory; candidateCheck(emptyDirectory, fullProgramPath, fullProgramPath); - m_product->cacheExecutablePath(filePath, fullProgramPath); + cacheFilePath(filePath, fullProgramPath); return fullProgramPath; } @@ -101,15 +103,14 @@ bool ExecutableFinder::candidateCheck(const QString &directory, const QString &p QString ExecutableFinder::findInPath(const QString &filePath, const QString &workingDirPath) const { - QString fullProgramPath = m_product->cachedExecutablePath(filePath); + QString fullProgramPath = cachedFilePath(filePath); if (!fullProgramPath.isEmpty()) return fullProgramPath; fullProgramPath = filePath; if (m_logger.traceEnabled()) m_logger.qbsTrace() << "[EXEC] looking for executable in PATH " << fullProgramPath; - const QProcessEnvironment &buildEnvironment = m_product->buildEnvironment; - QStringList pathEnv = buildEnvironment.value(QLatin1String("PATH")) + QStringList pathEnv = m_environment.value(QLatin1String("PATH")) .split(HostOsInfo::pathListSeparator(), QString::SkipEmptyParts); if (HostOsInfo::isWindowsHost()) pathEnv.prepend(QLatin1String(".")); @@ -125,10 +126,19 @@ QString ExecutableFinder::findInPath(const QString &filePath, const QString &wor if (candidateCheck(directory, fullProgramPath, fullProgramPath)) break; } - m_product->cacheExecutablePath(filePath, fullProgramPath); + cacheFilePath(filePath, fullProgramPath); return fullProgramPath; +} - return filePath; +QString ExecutableFinder::cachedFilePath(const QString &filePath) const +{ + return m_product ? m_product->cachedExecutablePath(filePath) : QString(); +} + +void ExecutableFinder::cacheFilePath(const QString &filePath, const QString &fullFilePath) const +{ + if (m_product) + m_product->cacheExecutablePath(filePath, fullFilePath); } } // namespace Internal diff --git a/src/lib/corelib/tools/executablefinder.h b/src/lib/corelib/tools/executablefinder.h index ca4bf1a42..e200e9d35 100644 --- a/src/lib/corelib/tools/executablefinder.h +++ b/src/lib/corelib/tools/executablefinder.h @@ -33,6 +33,8 @@ #include <language/language.h> #include <logging/logger.h> +#include <QProcessEnvironment> + namespace qbs { namespace Internal { @@ -42,7 +44,8 @@ namespace Internal { class ExecutableFinder { public: - ExecutableFinder(const ResolvedProductPtr &product, const Logger &logger); + ExecutableFinder(const ResolvedProductPtr &product, const QProcessEnvironment &env, + const Logger &logger); QString findExecutable(const QString &path, const QString &workingDirPath); @@ -53,7 +56,11 @@ private: QString &fullProgramPath) const; QString findInPath(const QString &filePath, const QString &workingDirPath) const; + QString cachedFilePath(const QString &filePath) const; + void cacheFilePath(const QString &filePaht, const QString &filePath) const; + ResolvedProductPtr m_product; + const QProcessEnvironment &m_environment; Logger m_logger; }; |