forked from qt-creator/qt-creator
Replace lookup in process environment with build environment
The generic manager looked up entries from the .includes and .files configuration files in the process (i.e. QtCreators) environment. In particular for the .includes file this is a problem, since it makes it impossible to use environment variables specific to a particular build environment. In my case I'd like to access the QTDIR variable added by QtCreator to the build environment to provide the generic manager with the Qt include directories. Of course this is different when working with two kits that have different Qt versions associated and hence its not possible to hardcode a particular path in the .includes file. This will break existing files that use the generic-manager-specific syntax for environment variables ($$(VARNAME)) as the BuildEnvironment uses the platform's native way to refer to such variables. Change-Id: I1a684db82fdbfd163b6a215f9591c8e4bb57b25c Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -289,25 +289,6 @@ void GenericProject::refresh(RefreshOptions options)
|
||||
emit parsingFinished();
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands environment variables in the given \a string when they are written
|
||||
* like $$(VARIABLE).
|
||||
*/
|
||||
static void expandEnvironmentVariables(const QProcessEnvironment &env, QString &string)
|
||||
{
|
||||
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.
|
||||
@@ -318,7 +299,10 @@ static void expandEnvironmentVariables(const QProcessEnvironment &env, QString &
|
||||
QStringList GenericProject::processEntries(const QStringList &paths,
|
||||
QHash<QString, QString> *map) const
|
||||
{
|
||||
const QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
const BuildConfiguration *const buildConfig = activeTarget() ? activeTarget()->activeBuildConfiguration()
|
||||
: nullptr;
|
||||
const Utils::Environment buildEnv = buildConfig ? buildConfig->environment()
|
||||
: Utils::Environment::systemEnvironment();
|
||||
const QDir projectDir(projectDirectory().toString());
|
||||
|
||||
QFileInfo fileInfo;
|
||||
@@ -328,7 +312,7 @@ QStringList GenericProject::processEntries(const QStringList &paths,
|
||||
if (trimmedPath.isEmpty())
|
||||
continue;
|
||||
|
||||
expandEnvironmentVariables(env, trimmedPath);
|
||||
trimmedPath = buildEnv.expandVariables(trimmedPath);
|
||||
|
||||
trimmedPath = Utils::FileName::fromUserInput(trimmedPath).toString();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user