forked from qt-creator/qt-creator
Utils: Remove some unused code from BuildableLibrary
Change-Id: I2d720faf57d644bd3b734383df5c4bdcaa7af961 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -190,173 +190,4 @@ QStringList BuildableHelperLibrary::possibleQMakeCommands()
|
|||||||
return commands;
|
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
|
} // namespace Utils
|
||||||
|
@@ -26,9 +26,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "environment.h"
|
#include "environment.h"
|
||||||
#include "fileutils.h"
|
#include "filepath.h"
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QFileInfo)
|
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
@@ -48,33 +46,6 @@ public:
|
|||||||
// returns something like qmake4, qmake, qmake-qt4 or whatever distributions have chosen (used by QtVersion)
|
// returns something like qmake4, qmake, qmake-qt4 or whatever distributions have chosen (used by QtVersion)
|
||||||
static QStringList possibleQMakeCommands();
|
static QStringList possibleQMakeCommands();
|
||||||
static QString filterForQmakeFileDialog();
|
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
|
||||||
|
Reference in New Issue
Block a user