diff --git a/src/libs/utils/buildablehelperlibrary.cpp b/src/libs/utils/buildablehelperlibrary.cpp index de41c8bfa18..7eedba4368d 100644 --- a/src/libs/utils/buildablehelperlibrary.cpp +++ b/src/libs/utils/buildablehelperlibrary.cpp @@ -190,173 +190,4 @@ QStringList BuildableHelperLibrary::possibleQMakeCommands() return commands; } -// Helper: Run a build process with merged stdout/stderr -static inline bool runBuildProcessI(QtcProcess &proc, - int timeoutS, - bool ignoreNonNullExitCode, - QString *output, QString *errorMessage) -{ - proc.start(); - if (!proc.waitForStarted()) { - *errorMessage = QCoreApplication::translate("ProjectExplorer::BuildableHelperLibrary", - "Cannot start process: %1"). - arg(proc.errorString()); - return false; - } - // Read stdout/err and check for timeouts - QByteArray stdOut; - QByteArray stdErr; - if (!proc.readDataFromProcess(timeoutS, &stdOut, &stdErr, false)) { - *errorMessage = QCoreApplication::translate("ProjectExplorer::BuildableHelperLibrary", - "Timeout after %1 s."). - arg(timeoutS); - proc.stopProcess(); - return false; - } - if (proc.exitStatus() != QProcess::NormalExit) { - *errorMessage = QCoreApplication::translate("ProjectExplorer::BuildableHelperLibrary", - "The process crashed."); - return false; - } - const QString stdOutS = QString::fromLocal8Bit(stdOut); - if (!ignoreNonNullExitCode && proc.exitCode() != 0) { - *errorMessage = QCoreApplication::translate("ProjectExplorer::BuildableHelperLibrary", - "The process returned exit code %1:\n%2"). - arg(proc.exitCode()).arg(stdOutS); - return false; - } - output->append(stdOutS); - return true; -} - -// Run a build process with merged stdout/stderr and qWarn about errors. -static bool runBuildProcess(QtcProcess &proc, - const FilePath &binary, - const QStringList &args, - int timeoutS, - bool ignoreNonNullExitCode, - QString *output, QString *errorMessage) -{ - proc.setCommand({binary, args}); - const bool rc = runBuildProcessI(proc, timeoutS, ignoreNonNullExitCode, output, errorMessage); - if (!rc) { - // Fail - reformat error. - QString cmd = binary.toString(); - if (!args.isEmpty()) { - cmd += QLatin1Char(' '); - cmd += args.join(QLatin1Char(' ')); - } - *errorMessage = - QCoreApplication::translate("ProjectExplorer::BuildableHelperLibrary", - "Error running \"%1\" in %2: %3"). - arg(cmd, proc.workingDirectory().toUserOutput(), - *errorMessage); - qWarning("%s", qPrintable(*errorMessage)); - } - return rc; -} - - -bool BuildableHelperLibrary::buildHelper(const BuildHelperArguments &arguments, - QString *log, QString *errorMessage) -{ - const QChar newline = QLatin1Char('\n'); - // Setup process - QtcProcess proc; - proc.setEnvironment(arguments.environment); - proc.setWorkingDirectory(arguments.directory); - proc.setProcessChannelMode(QProcess::MergedChannels); - - log->append(tr("Building helper \"%1\" in %2\n").arg(arguments.helperName, arguments.directory)); - log->append(newline); - - const FilePath makeFullPath = arguments.environment.searchInPath(arguments.makeCommand); - if (QFileInfo::exists(arguments.directory + QLatin1String("/Makefile"))) { - if (makeFullPath.isEmpty()) { - *errorMessage = tr("%1 not found in PATH\n").arg(arguments.makeCommand); - return false; - } - const QString cleanTarget = QLatin1String("distclean"); - log->append(tr("Running %1 %2...\n").arg(makeFullPath.toUserOutput(), cleanTarget)); - if (!runBuildProcess(proc, makeFullPath, QStringList(cleanTarget), 30, true, log, errorMessage)) - return false; - } - QStringList qmakeArgs; - if (!arguments.targetMode.isEmpty()) - qmakeArgs << arguments.targetMode; - if (!arguments.mkspec.isEmpty()) - qmakeArgs << QLatin1String("-spec") << arguments.mkspec.toUserOutput(); - qmakeArgs << arguments.proFilename; - qmakeArgs << arguments.qmakeArguments; - - log->append(newline); - log->append(tr("Running %1 %2 ...\n").arg(arguments.qmakeCommand.toUserOutput(), - qmakeArgs.join(' '))); - - if (!runBuildProcess(proc, arguments.qmakeCommand, qmakeArgs, 30, false, log, errorMessage)) - return false; - log->append(newline); - if (makeFullPath.isEmpty()) { - *errorMessage = tr("%1 not found in PATH\n").arg(arguments.makeCommand); - return false; - } - log->append(tr("Running %1 %2 ...\n") - .arg(makeFullPath.toUserOutput(), arguments.makeArguments.join(QLatin1Char(' ')))); - return runBuildProcess(proc, makeFullPath, arguments.makeArguments, 120, false, log, errorMessage); -} - -bool BuildableHelperLibrary::getHelperFileInfoFor(const QStringList &validBinaryFilenames, - const QString &directory, QFileInfo* info) -{ - if (!info) - return false; - - for (const QString &binaryFilename : validBinaryFilenames) { - info->setFile(directory + binaryFilename); - if (info->exists()) - return true; - } - - return false; -} - -QString BuildableHelperLibrary::byInstallDataHelper(const QString &sourcePath, - const QStringList &sourceFileNames, - const QStringList &installDirectories, - const QStringList &validBinaryFilenames, - bool acceptOutdatedHelper) -{ - // find the latest change to the sources - QDateTime sourcesModified; - if (!acceptOutdatedHelper) { - for (const QString &sourceFileName : sourceFileNames) { - const QDateTime fileModified = QFileInfo(sourcePath + sourceFileName).lastModified(); - if (fileModified.isValid() && (!sourcesModified.isValid() || fileModified > sourcesModified)) - sourcesModified = fileModified; - } - } - - // We pretend that the lastmodified of dumper.cpp is 5 minutes before what - // the file system says because afer a installation from the package the - // modified dates of dumper.cpp and the actual library are close to each - // other, but not deterministic in one direction. - if (sourcesModified.isValid()) - sourcesModified = sourcesModified.addSecs(-300); - - // look for the newest helper library in the different locations - QString newestHelper; - QDateTime newestHelperModified = sourcesModified; // prevent using one that's older than the sources - QFileInfo fileInfo; - for (const QString &installDirectory : installDirectories) { - if (getHelperFileInfoFor(validBinaryFilenames, installDirectory, &fileInfo)) { - if (!newestHelperModified.isValid() - || (fileInfo.lastModified() > newestHelperModified)) { - newestHelper = fileInfo.filePath(); - newestHelperModified = fileInfo.lastModified(); - } - } - } - return newestHelper; -} - } // namespace Utils diff --git a/src/libs/utils/buildablehelperlibrary.h b/src/libs/utils/buildablehelperlibrary.h index d6176b0913f..432ed27de36 100644 --- a/src/libs/utils/buildablehelperlibrary.h +++ b/src/libs/utils/buildablehelperlibrary.h @@ -26,9 +26,7 @@ #pragma once #include "environment.h" -#include "fileutils.h" - -QT_FORWARD_DECLARE_CLASS(QFileInfo) +#include "filepath.h" namespace Utils { @@ -48,33 +46,6 @@ public: // returns something like qmake4, qmake, qmake-qt4 or whatever distributions have chosen (used by QtVersion) static QStringList possibleQMakeCommands(); static QString filterForQmakeFileDialog(); - - static QString byInstallDataHelper(const QString &sourcePath, - const QStringList &sourceFileNames, - const QStringList &installDirectories, - const QStringList &validBinaryFilenames, - bool acceptOutdatedHelper); - - struct BuildHelperArguments { - QString helperName; - QString directory; - Environment environment; - - FilePath qmakeCommand; - QString targetMode; - FilePath mkspec; - QString proFilename; - QStringList qmakeArguments; - - QString makeCommand; - QStringList makeArguments; - }; - - static bool buildHelper(const BuildHelperArguments &arguments, - QString *log, QString *errorMessage); - - static bool getHelperFileInfoFor(const QStringList &validBinaryFilenames, - const QString &directory, QFileInfo* info); }; -} +} // Utils