Baseline: Allow setting git commit through environment variable

Widget tests run in VMs that don't have their own git clone.

Pick-to: 6.3
Change-Id: I20ab32affabfc7ce6dfaa445306b19efb51803e9
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
Volker Hilsheimer 2022-03-13 23:12:08 +01:00
parent ad333b9b87
commit 16d154ca5f

View File

@ -70,24 +70,26 @@ PlatformInfo PlatformInfo::localHostInfo()
#endif
pi.insert(PI_OSVersion, QSysInfo::kernelVersion());
QString gc = qEnvironmentVariable("BASELINE_GIT_COMMIT");
#if QT_CONFIG(process)
QProcess git;
QString cmd;
QStringList args;
#if defined(Q_OS_WIN)
cmd = QLS("cmd.exe");
args << QLS("/c") << QLS("git");
#else
cmd = QLS("git");
#endif
args << QLS("log") << QLS("--max-count=1") << QLS("--pretty=%H [%an] [%ad] %s");
git.start(cmd, args);
git.waitForFinished(3000);
if (!git.exitCode())
pi.insert(PI_GitCommit, QString::fromLocal8Bit(git.readAllStandardOutput().constData()).simplified());
else
pi.insert(PI_GitCommit, QLS("Unknown"));
if (gc.isEmpty()) {
QProcess git;
QString cmd;
QStringList args;
#if defined(Q_OS_WIN)
cmd = QLS("cmd.exe");
args << QLS("/c") << QLS("git");
#else
cmd = QLS("git");
#endif
args << QLS("log") << QLS("--max-count=1") << QLS("--pretty=%H [%an] [%ad] %s");
git.start(cmd, args);
git.waitForFinished(3000);
if (!git.exitCode())
gc = QString::fromLocal8Bit(git.readAllStandardOutput().constData()).simplified();
}
#endif // QT_CONFIG(process)
pi.insert(PI_GitCommit, gc.isEmpty() ? QLS("Unknown") : gc);
if (qEnvironmentVariableIsSet("JENKINS_HOME"))
pi.setAdHocRun(false);