forked from qt-creator/qt-creator
move expandEnvVars() to QMakeGlobals
fits better there Change-Id: Id369d8e22db97affd03ed991433b898b110f1946 Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
@@ -76,7 +76,7 @@ QStringList ProFileEvaluator::values(const QString &variableName) const
|
|||||||
QStringList ret;
|
QStringList ret;
|
||||||
ret.reserve(values.size());
|
ret.reserve(values.size());
|
||||||
foreach (const ProString &str, values)
|
foreach (const ProString &str, values)
|
||||||
ret << d->expandEnvVars(str.toQString());
|
ret << d->m_option->expandEnvVars(str.toQString());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ QStringList ProFileEvaluator::values(const QString &variableName, const ProFile
|
|||||||
ret.reserve(values.size());
|
ret.reserve(values.size());
|
||||||
foreach (const ProString &str, values)
|
foreach (const ProString &str, values)
|
||||||
if (str.sourceFile() == pro)
|
if (str.sourceFile() == pro)
|
||||||
ret << d->expandEnvVars(str.toQString());
|
ret << d->m_option->expandEnvVars(str.toQString());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -397,7 +397,7 @@ ProStringList QMakeEvaluator::evaluateExpandFunction(
|
|||||||
if (args.count() > 1)
|
if (args.count() > 1)
|
||||||
singleLine = isTrue(args.at(1), m_tmp2);
|
singleLine = isTrue(args.at(1), m_tmp2);
|
||||||
|
|
||||||
QFile qfile(resolvePath(expandEnvVars(file)));
|
QFile qfile(resolvePath(m_option->expandEnvVars(file)));
|
||||||
if (qfile.open(QIODevice::ReadOnly)) {
|
if (qfile.open(QIODevice::ReadOnly)) {
|
||||||
QTextStream stream(&qfile);
|
QTextStream stream(&qfile);
|
||||||
while (!stream.atEnd()) {
|
while (!stream.atEnd()) {
|
||||||
@@ -414,7 +414,7 @@ ProStringList QMakeEvaluator::evaluateExpandFunction(
|
|||||||
evalError(fL1S("fromfile(file, variable) requires two arguments."));
|
evalError(fL1S("fromfile(file, variable) requires two arguments."));
|
||||||
} else {
|
} else {
|
||||||
QHash<ProString, ProStringList> vars;
|
QHash<ProString, ProStringList> vars;
|
||||||
QString fn = resolvePath(expandEnvVars(args.at(0).toQString(m_tmp1)));
|
QString fn = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1)));
|
||||||
fn.detach();
|
fn.detach();
|
||||||
if (evaluateFileInto(fn, QMakeEvaluatorHandler::EvalAuxFile,
|
if (evaluateFileInto(fn, QMakeEvaluatorHandler::EvalAuxFile,
|
||||||
&vars, &m_functionDefs, EvalWithDefaults))
|
&vars, &m_functionDefs, EvalWithDefaults))
|
||||||
@@ -702,7 +702,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateConditionalFunction(
|
|||||||
evalError(fL1S("infile(file, var, [values]) requires two or three arguments."));
|
evalError(fL1S("infile(file, var, [values]) requires two or three arguments."));
|
||||||
} else {
|
} else {
|
||||||
QHash<ProString, ProStringList> vars;
|
QHash<ProString, ProStringList> vars;
|
||||||
QString fn = resolvePath(expandEnvVars(args.at(0).toQString(m_tmp1)));
|
QString fn = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1)));
|
||||||
fn.detach();
|
fn.detach();
|
||||||
if (!evaluateFileInto(fn, QMakeEvaluatorHandler::EvalAuxFile,
|
if (!evaluateFileInto(fn, QMakeEvaluatorHandler::EvalAuxFile,
|
||||||
&vars, &m_functionDefs, EvalWithDefaults))
|
&vars, &m_functionDefs, EvalWithDefaults))
|
||||||
@@ -987,7 +987,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateConditionalFunction(
|
|||||||
evalError(fL1S("include(file, into, silent) requires one, two or three arguments."));
|
evalError(fL1S("include(file, into, silent) requires one, two or three arguments."));
|
||||||
return ReturnFalse;
|
return ReturnFalse;
|
||||||
}
|
}
|
||||||
QString fn = resolvePath(expandEnvVars(args.at(0).toQString(m_tmp1)));
|
QString fn = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1)));
|
||||||
fn.detach();
|
fn.detach();
|
||||||
bool ok;
|
bool ok;
|
||||||
if (parseInto.isEmpty()) {
|
if (parseInto.isEmpty()) {
|
||||||
@@ -1029,7 +1029,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateConditionalFunction(
|
|||||||
return ReturnFalse;
|
return ReturnFalse;
|
||||||
}
|
}
|
||||||
// XXX ignore_error unused
|
// XXX ignore_error unused
|
||||||
return returnBool(evaluateFeatureFile(expandEnvVars(args.at(0).toQString())));
|
return returnBool(evaluateFeatureFile(m_option->expandEnvVars(args.at(0).toQString())));
|
||||||
}
|
}
|
||||||
case T_DEBUG:
|
case T_DEBUG:
|
||||||
// Yup - do nothing. Nothing is going to enable debug output anyway.
|
// Yup - do nothing. Nothing is going to enable debug output anyway.
|
||||||
@@ -1040,7 +1040,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateConditionalFunction(
|
|||||||
.arg(function.toQString(m_tmp1)));
|
.arg(function.toQString(m_tmp1)));
|
||||||
return ReturnFalse;
|
return ReturnFalse;
|
||||||
}
|
}
|
||||||
const QString &msg = expandEnvVars(args.at(0).toQString(m_tmp2));
|
const QString &msg = m_option->expandEnvVars(args.at(0).toQString(m_tmp2));
|
||||||
if (!m_skipLevel)
|
if (!m_skipLevel)
|
||||||
m_handler->fileMessage(fL1S("Project %1: %2")
|
m_handler->fileMessage(fL1S("Project %1: %2")
|
||||||
.arg(function.toQString(m_tmp1).toUpper(), msg));
|
.arg(function.toQString(m_tmp1).toUpper(), msg));
|
||||||
@@ -1085,7 +1085,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateConditionalFunction(
|
|||||||
evalError(fL1S("exists(file) requires one argument."));
|
evalError(fL1S("exists(file) requires one argument."));
|
||||||
return ReturnFalse;
|
return ReturnFalse;
|
||||||
}
|
}
|
||||||
const QString &file = resolvePath(expandEnvVars(args.at(0).toQString(m_tmp1)));
|
const QString &file = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1)));
|
||||||
|
|
||||||
if (IoUtils::exists(file)) {
|
if (IoUtils::exists(file)) {
|
||||||
return ReturnTrue;
|
return ReturnTrue;
|
||||||
|
|||||||
@@ -98,9 +98,6 @@ void QMakeEvaluator::initStatics()
|
|||||||
statics.strTEMPLATE = ProString("TEMPLATE");
|
statics.strTEMPLATE = ProString("TEMPLATE");
|
||||||
statics.strQMAKE_DIR_SEP = ProString("QMAKE_DIR_SEP");
|
statics.strQMAKE_DIR_SEP = ProString("QMAKE_DIR_SEP");
|
||||||
|
|
||||||
statics.reg_variableName.setPattern(QLatin1String("\\$\\(.*\\)"));
|
|
||||||
statics.reg_variableName.setMinimal(true);
|
|
||||||
|
|
||||||
statics.fakeValue = ProStringList(ProString("_FAKE_")); // It has to have a unique begin() value
|
statics.fakeValue = ProStringList(ProString("_FAKE_")); // It has to have a unique begin() value
|
||||||
|
|
||||||
initFunctionStatics();
|
initFunctionStatics();
|
||||||
@@ -313,21 +310,10 @@ static void replaceInList(ProStringList *varlist,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QMakeEvaluator::expandEnvVars(const QString &str) const
|
|
||||||
{
|
|
||||||
QString string = str;
|
|
||||||
int rep;
|
|
||||||
QRegExp reg_variableName = statics.reg_variableName; // Copy for thread safety
|
|
||||||
while ((rep = reg_variableName.indexIn(string)) != -1)
|
|
||||||
string.replace(rep, reg_variableName.matchedLength(),
|
|
||||||
m_option->getEnv(string.mid(rep + 2, reg_variableName.matchedLength() - 3)));
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is braindead, but we want qmake compat
|
// This is braindead, but we want qmake compat
|
||||||
QString QMakeEvaluator::fixPathToLocalOS(const QString &str) const
|
QString QMakeEvaluator::fixPathToLocalOS(const QString &str) const
|
||||||
{
|
{
|
||||||
QString string = expandEnvVars(str);
|
QString string = m_option->expandEnvVars(str);
|
||||||
|
|
||||||
if (string.length() > 2 && string.at(0).isLetter() && string.at(1) == QLatin1Char(':'))
|
if (string.length() > 2 && string.at(0).isLetter() && string.at(1) == QLatin1Char(':'))
|
||||||
string[0] = string[0].toLower();
|
string[0] = string[0].toLower();
|
||||||
@@ -911,7 +897,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProFile(
|
|||||||
|
|
||||||
QStringList mkspec_roots = qmakeMkspecPaths();
|
QStringList mkspec_roots = qmakeMkspecPaths();
|
||||||
|
|
||||||
QString qmakespec = expandEnvVars(m_option->qmakespec);
|
QString qmakespec = m_option->expandEnvVars(m_option->qmakespec);
|
||||||
if (qmakespec.isEmpty()) {
|
if (qmakespec.isEmpty()) {
|
||||||
foreach (const QString &root, mkspec_roots) {
|
foreach (const QString &root, mkspec_roots) {
|
||||||
QString mkspec = root + QLatin1String("/default");
|
QString mkspec = root + QLatin1String("/default");
|
||||||
|
|||||||
@@ -166,7 +166,6 @@ public:
|
|||||||
QHash<ProString, ProStringList> &dependees,
|
QHash<ProString, ProStringList> &dependees,
|
||||||
ProStringList &rootSet) const;
|
ProStringList &rootSet) const;
|
||||||
|
|
||||||
QString expandEnvVars(const QString &str) const;
|
|
||||||
QString fixPathToLocalOS(const QString &str) const;
|
QString fixPathToLocalOS(const QString &str) const;
|
||||||
|
|
||||||
#ifndef QT_BOOTSTRAPPED
|
#ifndef QT_BOOTSTRAPPED
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ struct QMakeStatics {
|
|||||||
QHash<ProString, int> functions;
|
QHash<ProString, int> functions;
|
||||||
QHash<ProString, int> varList;
|
QHash<ProString, int> varList;
|
||||||
QHash<ProString, ProString> varMap;
|
QHash<ProString, ProString> varMap;
|
||||||
QRegExp reg_variableName;
|
|
||||||
ProStringList fakeValue;
|
ProStringList fakeValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -72,8 +72,27 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
#define fL1S(s) QString::fromLatin1(s)
|
#define fL1S(s) QString::fromLatin1(s)
|
||||||
|
|
||||||
|
namespace { // MSVC doesn't seem to know the semantics of "static" ...
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
QRegExp reg_variableName;
|
||||||
|
} statics;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void initStatics()
|
||||||
|
{
|
||||||
|
if (!statics.reg_variableName.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
statics.reg_variableName.setPattern(QLatin1String("\\$\\(.*\\)"));
|
||||||
|
statics.reg_variableName.setMinimal(true);
|
||||||
|
}
|
||||||
|
|
||||||
QMakeGlobals::QMakeGlobals()
|
QMakeGlobals::QMakeGlobals()
|
||||||
{
|
{
|
||||||
|
initStatics();
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
dirlist_sep = QLatin1Char(';');
|
dirlist_sep = QLatin1Char(';');
|
||||||
dir_sep = QLatin1Char('\\');
|
dir_sep = QLatin1Char('\\');
|
||||||
@@ -160,6 +179,17 @@ QStringList QMakeGlobals::getPathListEnv(const QString &var) const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QMakeGlobals::expandEnvVars(const QString &str) const
|
||||||
|
{
|
||||||
|
QString string = str;
|
||||||
|
int rep;
|
||||||
|
QRegExp reg_variableName = statics.reg_variableName; // Copy for thread safety
|
||||||
|
while ((rep = reg_variableName.indexIn(string)) != -1)
|
||||||
|
string.replace(rep, reg_variableName.matchedLength(),
|
||||||
|
getEnv(string.mid(rep + 2, reg_variableName.matchedLength() - 3)));
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef PROEVALUATOR_INIT_PROPS
|
#ifdef PROEVALUATOR_INIT_PROPS
|
||||||
bool QMakeGlobals::initProperties(const QString &qmake)
|
bool QMakeGlobals::initProperties(const QString &qmake)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ public:
|
|||||||
bool initProperties(const QString &qmake);
|
bool initProperties(const QString &qmake);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QString expandEnvVars(const QString &str) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString getEnv(const QString &) const;
|
QString getEnv(const QString &) const;
|
||||||
QStringList getPathListEnv(const QString &var) const;
|
QStringList getPathListEnv(const QString &var) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user