Commit 3c1142d7 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer

Expand environment variables in Generic Project file lists

Environment variables will now be expanded in the Generic Project file
and include path lists. They have to be written like $$(VARIABLE), like
in qmake .pro files.

Task-number: QTCREATORBUG-366
parent d1480ef6
......@@ -41,6 +41,7 @@
#include <coreplugin/icore.h>
#include <QtCore/QDir>
#include <QtCore/QProcessEnvironment>
#include <QtGui/QFormLayout>
#include <QtGui/QMainWindow>
......@@ -170,11 +171,11 @@ void GenericProject::parseProject(RefreshOptions options)
if (options & Files) {
m_rawFileList = readLines(filesFileName());
m_files = convertToAbsoluteFiles(m_rawFileList, &m_rawListEntries);
m_files = processEntries(m_rawFileList, &m_rawListEntries);
if (options & Configuration) {
m_projectIncludePaths = convertToAbsoluteFiles(readLines(includesFileName()));
m_projectIncludePaths = processEntries(readLines(includesFileName()));
// TODO: Possibly load some configuration from the project file
//QSettings projectInfo(m_fileName, QSettings::IniFormat);
......@@ -249,22 +250,49 @@ void GenericProject::refresh(RefreshOptions options)
* Expands environment variables in the given \a string when they are written
* like $$(VARIABLE).
static void expandEnvironmentVariables(const QProcessEnvironment &env, QString &string)
const static QRegExp candidate(QLatin1String("\\$\\$\\((.+)\\)"));
int index = candidate.indexIn(string);
while (index != -1) {
const QString value = env.value(candidate.cap(1));
string.replace(index, candidate.matchedLength(), value);
index += value.length();
index = candidate.indexIn(string, index);
* Expands environment variables and converts the path from relative to the
* project to an absolute path.
* The \a map variable is an optional argument that will map the returned
* absolute paths back to their original \a paths.
* absolute paths back to their original \a entries.
QStringList GenericProject::convertToAbsoluteFiles(const QStringList &paths,
QHash<QString, QString> *map) const
QStringList GenericProject::processEntries(const QStringList &paths,
QHash<QString, QString> *map) const
const QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
const QDir projectDir(QFileInfo(m_fileName).dir());
QStringList absolutePaths;
foreach (const QString &path, paths) {
if (path.trimmed().isEmpty())
QString trimmedPath = path.trimmed();
if (trimmedPath.isEmpty())
const QString absPath = QFileInfo(projectDir, path).absoluteFilePath();
expandEnvironmentVariables(env, trimmedPath);
const QString absPath = QFileInfo(projectDir, trimmedPath).absoluteFilePath();
if (map)
map->insert(absPath, path);
map->insert(absPath, trimmedPath);
return absolutePaths;
......@@ -117,8 +117,8 @@ protected:
bool saveRawFileList(const QStringList &rawFileList);
void parseProject(RefreshOptions options);
QStringList convertToAbsoluteFiles(const QStringList &paths,
QHash<QString, QString> *map = 0) const;
QStringList processEntries(const QStringList &paths,
QHash<QString, QString> *map = 0) const;
Manager *m_manager;
QString m_fileName;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment