diff --git a/src/shared/proparser/profileevaluator.cpp b/src/shared/proparser/profileevaluator.cpp index 9bae8f43a21..1865cfb4f7e 100644 --- a/src/shared/proparser/profileevaluator.cpp +++ b/src/shared/proparser/profileevaluator.cpp @@ -172,6 +172,39 @@ QString ProFileOption::getEnv(const QString &var) const return QString::fromLocal8Bit(qgetenv(var.toLocal8Bit().constData())); } +#ifdef PROEVALUATOR_INIT_PROPS +bool ProFileOption::initProperties(const QString &qmake) +{ + QByteArray data; +#ifndef QT_BOOTSTRAPPED + QProcess proc; + proc.start(qmake, QStringList() << QLatin1String("-query")); + if (!proc.waitForFinished()) + return false; + data = proc.readAll(); +#else + if (FILE *proc = QT_POPEN(QString(IoUtils::shellQuote(qmake) + QLatin1String(" -query")) + .toLocal8Bit(), "r")) { + char buff[1024]; + while (!feof(proc)) + data.append(buff, int(fread(buff, 1, 1023, proc))); + QT_PCLOSE(proc); + } +#endif + foreach (QByteArray line, data.split('\n')) + if (!line.startsWith("QMAKE_")) { + int off = line.indexOf(':'); + if (off < 0) // huh? + continue; + if (line.endsWith('\r')) + line.chop(1); + properties.insert(QString::fromLatin1(line.left(off)), + QString::fromLocal8Bit(line.mid(off + 1))); + } + return true; +} +#endif + /////////////////////////////////////////////////////////////////////// // // ProFileEvaluator::Private diff --git a/src/shared/proparser/profileevaluator.h b/src/shared/proparser/profileevaluator.h index 3f73de4ca1a..003042b922d 100644 --- a/src/shared/proparser/profileevaluator.h +++ b/src/shared/proparser/profileevaluator.h @@ -186,6 +186,9 @@ struct PROPARSER_EXPORT ProFileOption // -nocache, -cache, -spec, QMAKESPEC // -set persistent value void setCommandLineArguments(const QStringList &args); +#ifdef PROEVALUATOR_INIT_PROPS + bool initProperties(const QString &qmake); +#endif private: friend class ProFileEvaluator; diff --git a/tests/manual/proparser/main.cpp b/tests/manual/proparser/main.cpp index 6f70e513f1e..aec72921224 100644 --- a/tests/manual/proparser/main.cpp +++ b/tests/manual/proparser/main.cpp @@ -160,33 +160,11 @@ int main(int argc, char **argv) qFatal("need at least two arguments: [-v] [ []]"); ProFileOption option; + option.initProperties(QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1String("/qmake")); if (args.count() >= 4) option.setCommandLineArguments(args.mid(3)); ProFileParser parser(0, &parseHandler); - static const struct { - const char * const name; - QLibraryInfo::LibraryLocation index; - } props[] = { - { "QT_INSTALL_DATA", QLibraryInfo::DataPath }, - { "QT_INSTALL_LIBS", QLibraryInfo::LibrariesPath }, - { "QT_INSTALL_IMPORTS", QLibraryInfo::ImportsPath }, - { "QT_INSTALL_HEADERS", QLibraryInfo::HeadersPath }, - { "QT_INSTALL_DEMOS", QLibraryInfo::DemosPath }, - { "QT_INSTALL_EXAMPLES", QLibraryInfo::ExamplesPath }, - { "QT_INSTALL_CONFIGURATION", QLibraryInfo::SettingsPath }, - { "QT_INSTALL_TRANSLATIONS", QLibraryInfo::TranslationsPath }, - { "QT_INSTALL_PLUGINS", QLibraryInfo::PluginsPath }, - { "QT_INSTALL_BINS", QLibraryInfo::BinariesPath }, - { "QT_INSTALL_DOCS", QLibraryInfo::DocumentationPath }, - { "QT_INSTALL_PREFIX", QLibraryInfo::PrefixPath } - }; - for (unsigned i = 0; i < sizeof(props)/sizeof(props[0]); ++i) - option.properties.insert(QLatin1String(props[i].name), - QLibraryInfo::location(props[i].index)); - - option.properties.insert(QLatin1String("QT_VERSION"), QLatin1String(qVersion())); - bool cumulative = args[0] == QLatin1String("true"); QFileInfo infi(args[1]); QString file = infi.absoluteFilePath(); diff --git a/tests/manual/proparser/testreader.pro b/tests/manual/proparser/testreader.pro index 521e2b73ffb..a585ddd2ded 100644 --- a/tests/manual/proparser/testreader.pro +++ b/tests/manual/proparser/testreader.pro @@ -20,4 +20,4 @@ HEADERS = profileparser.h profileevaluator.h proitems.h ioutils.h DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII DEFINES += QT_USE_FAST_OPERATOR_PLUS QT_USE_FAST_CONCATENATION -DEFINES += PROEVALUATOR_CUMULATIVE +DEFINES += PROEVALUATOR_CUMULATIVE PROEVALUATOR_INIT_PROPS