Clang/C++: Use qtcEnvironmentVariable* instead of qEnvironmentVariable*

And instead of qgetenv.
Takes Qt Creator's setting at "Environment > System > Environment" into
account, which makes it easier on some platforms to set them (e.g.
macOS), can be configured differently in different settings paths, and
potentially can be changed at runtime (depending on usage).

Change-Id: I7678b8e429b5eff79f87eb637f6f2131be43d904
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Eike Ziller
2022-08-24 14:53:40 +02:00
parent fe4e74af75
commit 57745407de
15 changed files with 41 additions and 30 deletions

View File

@@ -33,9 +33,10 @@
#include <texteditor/textmark.h>
#include <utils/temporarydirectory.h>
#include <utils/environment.h>
#include <utils/qtcassert.h>
#include <utils/runextensions.h>
#include <utils/temporarydirectory.h>
using namespace Utils;
@@ -174,7 +175,7 @@ void ClangCodeModelPlugin::createCompilationDBButton()
void ClangCodeModelPlugin::maybeHandleBatchFileAndExit() const
{
#ifdef WITH_TESTS
const QString batchFilePath = QString::fromLocal8Bit(qgetenv("QTC_CLANG_BATCH"));
const QString batchFilePath = qtcEnvironmentVariable("QTC_CLANG_BATCH");
if (!batchFilePath.isEmpty() && QTC_GUARD(QFileInfo::exists(batchFilePath))) {
const bool runSucceeded = runClangBatchFile(batchFilePath);
QCoreApplication::exit(!runSucceeded);

View File

@@ -22,6 +22,7 @@
#include <texteditor/textdocument.h>
#include <texteditor/texteditor.h>
#include <utils/environment.h>
#include <utils/executeondestruction.h>
#include <utils/qtcassert.h>
@@ -42,10 +43,9 @@ static Q_LOGGING_CATEGORY(debug, "qtc.clangcodemodel.batch", QtWarningMsg);
static int timeOutFromEnvironmentVariable()
{
const QByteArray timeoutAsByteArray = qgetenv("QTC_CLANG_BATCH_TIMEOUT");
bool isConversionOk = false;
const int intervalAsInt = timeoutAsByteArray.toInt(&isConversionOk);
const int intervalAsInt = Utils::qtcEnvironmentVariableIntValue("QTC_CLANG_BATCH_TIMEOUT",
&isConversionOk);
if (!isConversionOk) {
qCDebug(debug, "Environment variable QTC_CLANG_BATCH_TIMEOUT is not set, assuming 30000.");
return 30000;

View File

@@ -7,23 +7,24 @@
#include "../clangdclient.h"
#include "../clangmodelmanagersupport.h"
#include <coreplugin/editormanager/editormanager.h>
#include <cplusplus/FindUsages.h>
#include <cppeditor/cppcodemodelsettings.h>
#include <cppeditor/cpptoolsreuse.h>
#include <cppeditor/cpptoolstestcase.h>
#include <cppeditor/semantichighlighter.h>
#include <coreplugin/editormanager/editormanager.h>
#include <languageclient/languageclientmanager.h>
#include <projectexplorer/kitmanager.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/target.h>
#include <qtsupport/qtkitinformation.h>
#include <texteditor/codeassist/assistproposaliteminterface.h>
#include <texteditor/codeassist/textdocumentmanipulatorinterface.h>
#include <utils/algorithm.h>
#include <utils/environment.h>
#include <utils/filepath.h>
#include <utils/textutils.h>
#include <qtsupport/qtkitinformation.h>
#include <QElapsedTimer>
#include <QEventLoop>
@@ -113,7 +114,7 @@ void ClangdTest::waitForNewClient(bool withIndex)
void ClangdTest::initTestCase()
{
const QString clangdFromEnv = qEnvironmentVariable("QTC_CLANGD");
const QString clangdFromEnv = Utils::qtcEnvironmentVariable("QTC_CLANGD");
if (!clangdFromEnv.isEmpty())
CppEditor::ClangdSettings::setClangdFilePath(Utils::FilePath::fromString(clangdFromEnv));
const auto clangd = CppEditor::ClangdSettings::instance().clangdFilePath();