forked from qt-creator/qt-creator
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:
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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();
|
||||
|
@@ -38,6 +38,7 @@
|
||||
#include <projectexplorer/toolchain.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/stringutils.h>
|
||||
@@ -148,7 +149,8 @@ ClangToolRunWorker::ClangToolRunWorker(RunControl *runControl,
|
||||
, m_fileInfos(fileInfos)
|
||||
, m_temporaryDir("clangtools-XXXXXX")
|
||||
{
|
||||
m_temporaryDir.setAutoRemove(qEnvironmentVariable("QTC_CLANG_DONT_DELETE_OUTPUT_FILES") != "1");
|
||||
m_temporaryDir.setAutoRemove(qtcEnvironmentVariable("QTC_CLANG_DONT_DELETE_OUTPUT_FILES")
|
||||
!= "1");
|
||||
setId("ClangTidyClazyRunner");
|
||||
setSupportsReRunning(false);
|
||||
|
||||
|
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
@@ -166,7 +167,7 @@ void ClangToolsUnitTests::addTestRow(const QByteArray &relativeFilePath,
|
||||
|
||||
int ClangToolsUnitTests::getTimeout()
|
||||
{
|
||||
const int t = qEnvironmentVariableIntValue("QTC_CLANGTOOLS_TEST_TIMEOUT");
|
||||
const int t = qtcEnvironmentVariableIntValue("QTC_CLANGTOOLS_TEST_TIMEOUT");
|
||||
return t > 0 ? t : 480000;
|
||||
}
|
||||
|
||||
|
@@ -287,11 +287,11 @@ ClangDiagnosticConfig diagnosticConfig(const Utils::Id &diagConfigId)
|
||||
return configs.configWithId(diagConfigId);
|
||||
}
|
||||
|
||||
static QStringList extraOptions(const char *envVar)
|
||||
static QStringList extraOptions(const QString &envVar)
|
||||
{
|
||||
if (!qEnvironmentVariableIsSet(envVar))
|
||||
if (!qtcEnvironmentVariableIsSet(envVar))
|
||||
return QStringList();
|
||||
QString arguments = qEnvironmentVariable(envVar);
|
||||
QString arguments = qtcEnvironmentVariable(envVar);
|
||||
return Utils::ProcessArgs::splitArgs(arguments);
|
||||
}
|
||||
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
|
||||
#include <cplusplus/LookupContext.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/stringutils.h>
|
||||
@@ -29,7 +30,6 @@
|
||||
|
||||
namespace CppEditor::Internal {
|
||||
|
||||
static const bool FindErrorsIndexing = qgetenv("QTC_FIND_ERRORS_INDEXING") == "1";
|
||||
static Q_LOGGING_CATEGORY(indexerLog, "qtc.cppeditor.indexer", QtWarningMsg)
|
||||
|
||||
namespace {
|
||||
@@ -228,7 +228,7 @@ void parse(QFutureInterface<void> &indexingFuture, const ParseParams params)
|
||||
|
||||
indexingFuture.setProgressRange(0, files.size());
|
||||
|
||||
if (FindErrorsIndexing)
|
||||
if (BuiltinIndexingSupport::isFindErrorsIndexingActive())
|
||||
indexFindErrors(indexingFuture, params);
|
||||
else
|
||||
index(indexingFuture, params);
|
||||
@@ -353,7 +353,7 @@ SymbolSearcher *BuiltinIndexingSupport::createSymbolSearcher(
|
||||
|
||||
bool BuiltinIndexingSupport::isFindErrorsIndexingActive()
|
||||
{
|
||||
return FindErrorsIndexing;
|
||||
return Utils::qtcEnvironmentVariable("QTC_FIND_ERRORS_INDEXING") == "1";
|
||||
}
|
||||
|
||||
} // namespace CppEditor::Internal
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include "ui_clangdiagnosticconfigswidget.h"
|
||||
#include "ui_clangbasechecks.h"
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/stringutils.h>
|
||||
#include <utils/treemodel.h>
|
||||
@@ -220,7 +221,7 @@ static bool isValidOption(const QString &option)
|
||||
static QString validateDiagnosticOptions(const QStringList &options)
|
||||
{
|
||||
// This is handy for testing, allow disabling validation.
|
||||
if (qEnvironmentVariableIntValue("QTC_CLANG_NO_DIAGNOSTIC_CHECK"))
|
||||
if (Utils::qtcEnvironmentVariableIntValue("QTC_CLANG_NO_DIAGNOSTIC_CHECK"))
|
||||
return QString();
|
||||
|
||||
for (const QString &option : options) {
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/cpplanguage_details.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/stringutils.h>
|
||||
@@ -378,7 +379,7 @@ void CompilerOptionsBuilder::addPrecompiledHeaderOptions(UsePrecompiledHeaders u
|
||||
|
||||
void CompilerOptionsBuilder::addProjectMacros()
|
||||
{
|
||||
static const int useMacros = qEnvironmentVariableIntValue("QTC_CLANG_USE_TOOLCHAIN_MACROS");
|
||||
const int useMacros = qtcEnvironmentVariableIntValue("QTC_CLANG_USE_TOOLCHAIN_MACROS");
|
||||
|
||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::CUSTOM_TOOLCHAIN_TYPEID
|
||||
|| m_projectPart.toolchainType == Qnx::Constants::QNX_TOOLCHAIN_ID
|
||||
@@ -772,8 +773,7 @@ void CompilerOptionsBuilder::reset()
|
||||
// QMakeProject: -pipe -Whello -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC
|
||||
void CompilerOptionsBuilder::evaluateCompilerFlags()
|
||||
{
|
||||
static QStringList userBlackList = QString::fromLocal8Bit(
|
||||
qgetenv("QTC_CLANG_CMD_OPTIONS_BLACKLIST"))
|
||||
const QStringList userBlackList = qtcEnvironmentVariable("QTC_CLANG_CMD_OPTIONS_BLACKLIST")
|
||||
.split(';', Qt::SkipEmptyParts);
|
||||
|
||||
const Id toolChain = m_projectPart.toolchainType;
|
||||
|
@@ -493,7 +493,7 @@ int ClangdSettings::Data::defaultCompletionResults()
|
||||
{
|
||||
// Default clangd --limit-results value is 100
|
||||
bool ok = false;
|
||||
const int userValue = qEnvironmentVariableIntValue("QTC_CLANGD_COMPLETION_RESULTS", &ok);
|
||||
const int userValue = qtcEnvironmentVariableIntValue("QTC_CLANGD_COMPLETION_RESULTS", &ok);
|
||||
return ok ? userValue : 100;
|
||||
}
|
||||
|
||||
|
@@ -9,9 +9,10 @@
|
||||
#include "cpptoolstestcase.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/locator/locatorfiltertest.h>
|
||||
#include <coreplugin/testdatadir.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <coreplugin/locator/locatorfiltertest.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QDebug>
|
||||
@@ -26,7 +27,7 @@ using namespace Utils;
|
||||
namespace CppEditor::Internal {
|
||||
namespace {
|
||||
|
||||
const bool debug = qEnvironmentVariable("QTC_DEBUG_CPPLOCATORFILTERTESTCASE") == "1";
|
||||
const bool debug = qtcEnvironmentVariable("QTC_DEBUG_CPPLOCATORFILTERTESTCASE") == "1";
|
||||
|
||||
QTC_DECLARE_MYTESTDATADIR("../../../tests/cpplocators/")
|
||||
|
||||
|
@@ -44,6 +44,7 @@
|
||||
|
||||
#include <texteditor/textdocument.h>
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -66,12 +67,12 @@
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
static const bool DumpProjectInfo = qgetenv("QTC_DUMP_PROJECT_INFO") == "1";
|
||||
|
||||
using namespace CPlusPlus;
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
static const bool DumpProjectInfo = qtcEnvironmentVariable("QTC_DUMP_PROJECT_INFO") == "1";
|
||||
|
||||
#ifdef QTCREATOR_WITH_DUMP_AST
|
||||
|
||||
#include <cxxabi.h>
|
||||
@@ -617,7 +618,7 @@ CppModelManager::CppModelManager()
|
||||
this, &CppModelManager::onSourceFilesRefreshed);
|
||||
|
||||
d->m_findReferences = new CppFindReferences(this);
|
||||
d->m_indexerEnabled = qgetenv("QTC_NO_CODE_INDEXER") != "1";
|
||||
d->m_indexerEnabled = qtcEnvironmentVariable("QTC_NO_CODE_INDEXER") != "1";
|
||||
|
||||
d->m_dirty = true;
|
||||
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include <texteditor/codeassist/iassistproposalmodel.h>
|
||||
#include <texteditor/storagesettings.h>
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
@@ -482,9 +483,9 @@ QString TemporaryCopiedDir::absolutePath(const QByteArray &relativePath) const
|
||||
|
||||
int clangdIndexingTimeout()
|
||||
{
|
||||
const QByteArray timeoutAsByteArray = qgetenv("QTC_CLANGD_INDEXING_TIMEOUT");
|
||||
bool isConversionOk = false;
|
||||
const int intervalAsInt = timeoutAsByteArray.toInt(&isConversionOk);
|
||||
const int intervalAsInt = qtcEnvironmentVariableIntValue("QTC_CLANGD_INDEXING_TIMEOUT",
|
||||
&isConversionOk);
|
||||
if (!isConversionOk)
|
||||
return Utils::HostOsInfo::isWindowsHost() ? 20000 : 10000;
|
||||
return intervalAsInt;
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include <cplusplus/CppDocument.h>
|
||||
#include <cplusplus/TranslationUnit.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
@@ -123,7 +124,7 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti
|
||||
{
|
||||
QVERIFY(succeededSoFar());
|
||||
|
||||
if (qgetenv("QTC_TEST_WAIT_FOR_LOADED_PROJECT") != "1")
|
||||
if (Utils::qtcEnvironmentVariable("QTC_TEST_WAIT_FOR_LOADED_PROJECT") != "1")
|
||||
QSKIP("Environment variable QTC_TEST_WAIT_FOR_LOADED_PROJECT=1 not set.");
|
||||
QVERIFY(waitUntilAProjectIsLoaded());
|
||||
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QDebug>
|
||||
@@ -483,7 +484,7 @@ namespace CppEditor::Internal::Tests {
|
||||
|
||||
void FollowSymbolTest::initTestCase()
|
||||
{
|
||||
const QString clangdFromEnv = qEnvironmentVariable("QTC_CLANGD");
|
||||
const QString clangdFromEnv = Utils::qtcEnvironmentVariable("QTC_CLANGD");
|
||||
if (clangdFromEnv.isEmpty())
|
||||
return;
|
||||
ClangdSettings::setClangdFilePath(Utils::FilePath::fromString(clangdFromEnv));
|
||||
|
Reference in New Issue
Block a user