From 4e91de799125b2ca9ff51928361a6a7cd1de1b9d Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 20 Apr 2011 22:26:01 +0200 Subject: [PATCH] use QProcess in profile evaluator if not bootstrapped this avoids the nasty console popups under windows Task-number: QTCREATORBUG-1788 --- src/shared/proparser/ioutils.cpp | 2 + src/shared/proparser/ioutils.h | 2 + src/shared/proparser/profileevaluator.cpp | 56 ++++++++++++++++++++--- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/shared/proparser/ioutils.cpp b/src/shared/proparser/ioutils.cpp index 5b9c322a3c2..0470af2af86 100644 --- a/src/shared/proparser/ioutils.cpp +++ b/src/shared/proparser/ioutils.cpp @@ -91,6 +91,7 @@ QString IoUtils::resolvePath(const QString &baseDir, const QString &fileName) return QDir::cleanPath(baseDir + QLatin1Char('/') + fileName); } +#ifdef QT_BOOTSTRAPPED inline static bool isSpecialChar(ushort c) { // Chars that should be quoted (TM). This includes: @@ -148,3 +149,4 @@ QString IoUtils::shellQuote(const QString &arg) } return ret; } +#endif diff --git a/src/shared/proparser/ioutils.h b/src/shared/proparser/ioutils.h index 5526211867d..00618ba8e3c 100644 --- a/src/shared/proparser/ioutils.h +++ b/src/shared/proparser/ioutils.h @@ -55,7 +55,9 @@ public: static bool isAbsolutePath(const QString &fileName) { return !isRelativePath(fileName); } static QStringRef fileName(const QString &fileName); // Requires normalized path static QString resolvePath(const QString &baseDir, const QString &fileName); +#ifdef QT_BOOTSTRAPPED static QString shellQuote(const QString &arg); +#endif }; } diff --git a/src/shared/proparser/profileevaluator.cpp b/src/shared/proparser/profileevaluator.cpp index 4f82c76e23f..3d0d8581a9e 100644 --- a/src/shared/proparser/profileevaluator.cpp +++ b/src/shared/proparser/profileevaluator.cpp @@ -48,6 +48,9 @@ #include #include #include +#ifndef QT_BOOTSTRAPPED +# include +#endif #ifdef PROEVALUATOR_THREAD_SAFE # include #endif @@ -271,6 +274,10 @@ public: QString fixPathToLocalOS(const QString &str) const; QString sysrootify(const QString &path, const QString &baseDir) const; +#ifndef QT_BOOTSTRAPPED + void runProcess(QProcess *proc, const QString &command, QProcess::ProcessChannel chan) const; +#endif + int m_skipLevel; int m_loopLevel; // To report unexpected break() and next()s bool m_cumulative; @@ -1526,6 +1533,26 @@ QString ProFileEvaluator::Private::sysrootify(const QString &path, const QString return isHostSystemPath ? path : m_option->sysroot + path; } +#ifndef QT_BOOTSTRAPPED +void ProFileEvaluator::Private::runProcess(QProcess *proc, const QString &command, + QProcess::ProcessChannel chan) const +{ + proc->setWorkingDirectory(currentDirectory()); +# ifdef Q_OS_WIN + proc->setNativeArguments(QLatin1String("/v:off /s /c \"") + command + QLatin1Char('"')); + proc->start(m_option->getEnv(QLatin1String("COMSPEC")), QStringList()); +# else + proc->start(QLatin1String("/bin/sh"), QStringList() << QLatin1String("-c") << command); +# endif + proc->waitForFinished(-1); + proc->setReadChannel(chan); + QByteArray errout = proc->readAll(); + if (errout.endsWith('\n')) + errout.chop(1); + m_handler->evalError(QString(), 0, QString::fromLocal8Bit(errout)); +} +#endif + // The (QChar*)current->constData() constructs below avoid pointless detach() calls // FIXME: This is inefficient. Should not make new string if it is a straight subsegment static ALWAYS_INLINE void appendChar(ushort unicode, @@ -2307,14 +2334,22 @@ ProStringList ProFileEvaluator::Private::evaluateExpandFunction( if (args.count() < 1 || args.count() > 2) { evalError(fL1S("system(execute) requires one or two arguments.")); } else { + bool singleLine = true; + if (args.count() > 1) + singleLine = isTrue(args.at(1), m_tmp2); + QByteArray output; +#ifndef QT_BOOTSTRAPPED + QProcess proc; + runProcess(&proc, args.at(0).toQString(m_tmp2), QProcess::StandardError); + output = proc.readAllStandardOutput(); + output.replace('\t', ' '); + if (singleLine) + output.replace('\n', ' '); +#else char buff[256]; FILE *proc = QT_POPEN(QString(QLatin1String("cd ") + IoUtils::shellQuote(currentDirectory()) + QLatin1String(" && ") + args[0]).toLocal8Bit(), "r"); - bool singleLine = true; - if (args.count() > 1) - singleLine = isTrue(args.at(1), m_tmp2); - QString output; while (proc && !feof(proc)) { int read_in = int(fread(buff, 1, 255, proc)); if (!read_in) @@ -2323,12 +2358,12 @@ ProStringList ProFileEvaluator::Private::evaluateExpandFunction( if ((singleLine && buff[i] == '\n') || buff[i] == '\t') buff[i] = ' '; } - buff[read_in] = '\0'; - output += QString::fromLocal8Bit(buff); + output.append(buff, read_in); } - ret += split_value_list(output); if (proc) QT_PCLOSE(proc); +#endif + ret += split_value_list(QString::fromLocal8Bit(output)); } } break; @@ -2899,9 +2934,16 @@ ProFileEvaluator::Private::VisitReturn ProFileEvaluator::Private::evaluateCondit evalError(fL1S("system(exec) requires one argument.")); return ReturnFalse; } +#ifndef QT_BOOTSTRAPPED + QProcess proc; + proc.setProcessChannelMode(QProcess::MergedChannels); + runProcess(&proc, args.at(0).toQString(m_tmp2), QProcess::StandardOutput); + return returnBool(proc.exitStatus() == QProcess::NormalExit && proc.exitCode() == 0); +#else return returnBool(system((QLatin1String("cd ") + IoUtils::shellQuote(currentDirectory()) + QLatin1String(" && ") + args.at(0)).toLocal8Bit().constData()) == 0); +#endif } #endif case T_ISEMPTY: {