forked from qt-creator/qt-creator
QmlProject: Add support for setting the environment
This allows setting arbitrary environment variables in the .qmlproject. This is required for example qtquickcontrols2.conf and QT_AUTO_SCREEN_SCALE_FACTOR. Task-number: QTCREATORBUG-19513 Change-Id: I8421a9fc7f85d24b3564f1b60f383be3838f2af4 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -70,4 +70,7 @@ Module {
|
|||||||
]
|
]
|
||||||
Property { name: "filter"; type: "string" }
|
Property { name: "filter"; type: "string" }
|
||||||
}
|
}
|
||||||
|
Component {
|
||||||
|
name: "Environment"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -127,6 +127,13 @@ QmlProjectItem *QmlProjectFileFormat::parseProjectFile(const Utils::FileName &fi
|
|||||||
OtherFileFilterItem *otherFileFilterItem = new OtherFileFilterItem(projectItem);
|
OtherFileFilterItem *otherFileFilterItem = new OtherFileFilterItem(projectItem);
|
||||||
setupFileFilterItem(otherFileFilterItem, childNode);
|
setupFileFilterItem(otherFileFilterItem, childNode);
|
||||||
projectItem->appendContent(otherFileFilterItem);
|
projectItem->appendContent(otherFileFilterItem);
|
||||||
|
} else if (childNode->name() == "Environment") {
|
||||||
|
const auto properties = childNode->properties();
|
||||||
|
auto i = properties.constBegin();
|
||||||
|
while (i != properties.constEnd()) {
|
||||||
|
projectItem->addToEnviroment(i.key(), i.value().toString());
|
||||||
|
++i;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Unknown type:" << childNode->name();
|
qWarning() << "Unknown type:" << childNode->name();
|
||||||
}
|
}
|
||||||
|
@@ -106,4 +106,14 @@ bool QmlProjectItem::matchesFile(const QString &filePath) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<Utils::EnvironmentItem> QmlProjectItem::environment() const
|
||||||
|
{
|
||||||
|
return m_environment;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlProjectItem::addToEnviroment(const QString &key, const QString &value)
|
||||||
|
{
|
||||||
|
m_environment.append(Utils::EnvironmentItem(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QmlProjectManager
|
} // namespace QmlProjectManager
|
||||||
|
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <utils/environment.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
@@ -60,6 +62,9 @@ public:
|
|||||||
|
|
||||||
void appendContent(QmlProjectContentItem *item) { m_content.append(item); }
|
void appendContent(QmlProjectContentItem *item) { m_content.append(item); }
|
||||||
|
|
||||||
|
QList<Utils::EnvironmentItem> environment() const;
|
||||||
|
void addToEnviroment(const QString &key, const QString &value);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void qmlFilesChanged(const QSet<QString> &, const QSet<QString> &);
|
void qmlFilesChanged(const QSet<QString> &, const QSet<QString> &);
|
||||||
|
|
||||||
@@ -69,6 +74,7 @@ protected:
|
|||||||
QStringList m_importPaths;
|
QStringList m_importPaths;
|
||||||
QStringList m_absoluteImportPaths;
|
QStringList m_absoluteImportPaths;
|
||||||
QString m_mainFile;
|
QString m_mainFile;
|
||||||
|
QList<Utils::EnvironmentItem> m_environment;
|
||||||
QList<QmlProjectContentItem *> m_content; // content property
|
QList<QmlProjectContentItem *> m_content; // content property
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -213,6 +213,13 @@ Utils::FileName QmlProject::targetFile(const Utils::FileName &sourceFile,
|
|||||||
return Utils::FileName::fromString(QDir::cleanPath(targetDir.absoluteFilePath(relative)));
|
return Utils::FileName::fromString(QDir::cleanPath(targetDir.absoluteFilePath(relative)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<Utils::EnvironmentItem> QmlProject::environment() const
|
||||||
|
{
|
||||||
|
if (m_projectItem)
|
||||||
|
return m_projectItem.data()->environment();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
bool QmlProject::validProjectFile() const
|
bool QmlProject::validProjectFile() const
|
||||||
{
|
{
|
||||||
return !m_projectItem.isNull();
|
return !m_projectItem.isNull();
|
||||||
|
@@ -30,6 +30,8 @@
|
|||||||
|
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
|
|
||||||
|
#include <utils/environment.h>
|
||||||
|
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
namespace ProjectExplorer { class RunConfiguration; }
|
namespace ProjectExplorer { class RunConfiguration; }
|
||||||
@@ -65,6 +67,8 @@ public:
|
|||||||
Utils::FileName targetDirectory(const ProjectExplorer::Target *target) const;
|
Utils::FileName targetDirectory(const ProjectExplorer::Target *target) const;
|
||||||
Utils::FileName targetFile(const Utils::FileName &sourceFile,
|
Utils::FileName targetFile(const Utils::FileName &sourceFile,
|
||||||
const ProjectExplorer::Target *target) const;
|
const ProjectExplorer::Target *target) const;
|
||||||
|
|
||||||
|
QList<Utils::EnvironmentItem> environment() const;
|
||||||
QStringList customImportPaths() const;
|
QStringList customImportPaths() const;
|
||||||
|
|
||||||
bool addFiles(const QStringList &filePaths);
|
bool addFiles(const QStringList &filePaths);
|
||||||
|
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include "qmlprojectenvironmentaspect.h"
|
#include "qmlprojectenvironmentaspect.h"
|
||||||
|
|
||||||
|
#include "qmlproject.h"
|
||||||
|
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
#include <projectexplorer/kit.h>
|
#include <projectexplorer/kit.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
@@ -57,6 +59,10 @@ Utils::Environment QmlProjectEnvironmentAspect::baseEnvironment() const
|
|||||||
if (base == static_cast<int>(KitEnvironmentBase))
|
if (base == static_cast<int>(KitEnvironmentBase))
|
||||||
runConfiguration()->target()->kit()->addToEnvironment(env);
|
runConfiguration()->target()->kit()->addToEnvironment(env);
|
||||||
|
|
||||||
|
QmlProject *project = qobject_cast<QmlProject *>(runConfiguration()->target()->project());
|
||||||
|
if (project)
|
||||||
|
env.modify(project->environment());
|
||||||
|
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user