Qt 5.12 deprecation fixes (#1003)

This commit is contained in:
Malte Langkabel
2020-08-04 18:13:18 +02:00
committed by GitHub
parent ca890978ab
commit e946c475c4
43 changed files with 190 additions and 168 deletions
+16 -2
View File
@@ -170,10 +170,12 @@ find_package(Boost 1.67 COMPONENTS system program_options filesystem date_time R
# Qt ---------------------------------------------------------------------------
find_package(Qt5 COMPONENTS Widgets PrintSupport Network Svg REQUIRED)
set (QT_MIN_VERSION "5.12.0")
set (QT_MIN_VERSION_HEX 0x051200)
find_package(Qt5 ${QT_MIN_VERSION} COMPONENTS Widgets PrintSupport Network Svg REQUIRED)
if (WIN32)
find_package(Qt5 COMPONENTS WinExtras REQUIRED)
find_package(Qt5 ${QT_MIN_VERSION} COMPONENTS WinExtras REQUIRED)
endif()
if(Qt5Widgets_FOUND)
@@ -183,6 +185,18 @@ if(Qt5Widgets_FOUND)
if (Qt5_POSITION_INDEPENDENT_CODE)
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
add_definitions (-DQT_DEPRECATED_WARNINGS)
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=${QT_MIN_VERSION_HEX} # disables all the APIs deprecated at or before the specified Qt version
add_definitions (-DQT_DISABLE_DEPRECATED_BEFORE=${QT_MIN_VERSION_HEX})
endif()
-10
View File
@@ -426,16 +426,6 @@ std::wstring FilePath::wstr() const
return m_path->generic_wstring();
}
std::string FilePath::getBackslashedString() const
{
return utility::replace(str(), "/", "\\");
}
std::wstring FilePath::getBackslashedWString() const
{
return utility::replace(wstr(), L"/", L"\\");
}
std::wstring FilePath::fileName() const
{
return m_path->filename().generic_wstring();
-2
View File
@@ -52,8 +52,6 @@ public:
std::string str() const;
std::wstring wstr() const;
std::string getBackslashedString() const;
std::wstring getBackslashedWString() const;
std::wstring fileName() const;
std::wstring extension() const;
+6 -5
View File
@@ -1,6 +1,7 @@
#ifndef UTILITY_LIBRARY_H
#define UTILITY_LIBRARY_H
#include <QDir>
#include <functional>
#include <iostream>
#include <sstream>
@@ -23,8 +24,8 @@ std::function<Ret(Args...)> loadFunctionFromLibrary(
const FilePath& libraryPath, const std::string& functionName, std::string& errorString)
{
#ifdef _WIN32
const std::string libraryPathString = libraryPath.getBackslashedString();
HINSTANCE handle = LoadLibrary(libraryPathString.c_str());
QString libraryPathString = QDir::toNativeSeparators(QString::fromStdWString(libraryPath.wstr()));
HINSTANCE handle = LoadLibrary(libraryPathString.toStdString().c_str());
if (handle == nullptr)
{
DWORD errorCode = GetLastError();
@@ -53,8 +54,8 @@ std::function<Ret(Args...)> loadFunctionFromLibrary(
LocalFree(messageBuffer);
errorString = "Could not load library \"" + libraryPathString + "\" because of " +
errorReasonString;
errorString = "Could not load library \"" + libraryPathString.toStdString() +
"\" because of " + errorReasonString;
return std::function<Ret(Args...)>();
}
@@ -63,7 +64,7 @@ std::function<Ret(Args...)> loadFunctionFromLibrary(
if (!functionId)
{
errorString = "Could not locate the function \"" + functionName + "\" in library\"" +
libraryPathString + "\"";
libraryPathString.toStdString() + "\"";
return std::function<Ret(Args...)>();
}
#else
+1 -1
View File
@@ -134,7 +134,7 @@ void QtStatusBar::setErrorCount(ErrorCountInfo errorCount)
: QLatin1String("")));
m_errorButton.setMinimumWidth(
m_errorButton.fontMetrics().width(QString(m_errorButton.text().size(), 'a')));
m_errorButton.fontMetrics().boundingRect(QString(m_errorButton.text().size(), 'a')).width());
if (errorCount.fatal > 0)
{
+1 -1
View File
@@ -294,7 +294,7 @@ int QtCodeArea::lineNumberAreaWidth() const
{
if (m_showLineNumbers)
{
return fontMetrics().width(QLatin1Char('9')) * m_digits + 30;
return fontMetrics().boundingRect(QLatin1Char('9')).width() * m_digits + 30;
}
return 0;
+10 -10
View File
@@ -97,7 +97,7 @@ QtCodeField::QtCodeField(
QFont font(appSettings->getFontName().c_str());
font.setPixelSize(appSettings->getFontSize());
setFont(font);
setTabStopWidth(appSettings->getCodeTabWidth() * fontMetrics().width('9'));
setTabStopDistance(appSettings->getCodeTabWidth() * fontMetrics().boundingRect('9').width());
m_openInTabAction = new QAction(
QStringLiteral("Open in New Tab (Ctrl + Shift + Left Click)"), this);
@@ -123,15 +123,15 @@ QSize QtCodeField::sizeHint() const
QRectF rect = blockBoundingGeometry(block);
height += rect.height();
int blockWidth = fm.boundingRect(
0,
0,
1000000,
1000000,
Qt::AlignLeft | Qt::AlignTop | Qt::TextExpandTabs,
block.text(),
tabStopWidth())
.width();
const int blockWidth = fm.boundingRect(
0,
0,
1000000,
1000000,
Qt::AlignLeft | Qt::AlignTop | Qt::TextExpandTabs,
block.text(),
static_cast<int>(tabStopDistance()))
.width();
width = std::max(blockWidth, width);
}
+1 -1
View File
@@ -17,7 +17,7 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeNavigator* navigator, boo
setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->setAlignment(Qt::AlignTop);
setLayout(layout);
@@ -36,7 +36,7 @@ QtCodeFileSingle::QtCodeFileSingle(QtCodeNavigator* navigator, QWidget* parent)
m_areaWrapper->setSizePolicy(
m_areaWrapper->sizePolicy().horizontalPolicy(), QSizePolicy::Expanding);
m_areaWrapper->setLayout(new QVBoxLayout());
m_areaWrapper->layout()->setMargin(0);
m_areaWrapper->layout()->setContentsMargins(0, 0, 0, 0);
m_areaWrapper->layout()->setSpacing(0);
layout()->addWidget(m_areaWrapper);
}
@@ -25,7 +25,7 @@ QtCodeFileTitleBar::QtCodeFileTitleBar(QWidget* parent, bool isHovering, bool is
}
QHBoxLayout* titleLayout = new QHBoxLayout();
titleLayout->setMargin(0);
titleLayout->setContentsMargins(0, 0, 0, 0);
titleLayout->setSpacing(0);
titleLayout->setAlignment(Qt::AlignLeft);
setLayout(titleLayout);
@@ -219,8 +219,8 @@ void QtCodeNavigator::updateReferenceCount(
}
m_refLabel->setMinimumWidth(
m_refLabel->fontMetrics().width(
QString(QString::number(referenceCount).size() * 2, 'a') + "/ references") +
m_refLabel->fontMetrics().boundingRect(
QString(QString::number(referenceCount).size() * 2, 'a') + "/ references").width() +
30);
m_prevReferenceButton->setEnabled(referenceCount > 1);
@@ -239,8 +239,8 @@ void QtCodeNavigator::updateReferenceCount(
}
m_localRefLabel->setMinimumWidth(
m_localRefLabel->fontMetrics().width(
QString(QString::number(localReferenceCount).size() * 2, 'a') + "/ local references") +
m_localRefLabel->fontMetrics().boundingRect(
QString(QString::number(localReferenceCount).size() * 2, 'a') + "/ local references").width() +
30);
m_nextLocalReferenceButton->setVisible(localReferenceCount > 1);
@@ -24,7 +24,7 @@ QtCodeSnippet::QtCodeSnippet(const CodeSnippetParams& params, QtCodeNavigator* n
setObjectName(QStringLiteral("code_snippet"));
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->setAlignment(Qt::AlignTop);
setLayout(layout);
@@ -268,7 +268,7 @@ void QtCodeSnippet::clickedFooter()
QtHoverButton* QtCodeSnippet::createScopeLine(QBoxLayout* layout)
{
QHBoxLayout* lineLayout = new QHBoxLayout();
lineLayout->setMargin(0);
lineLayout->setContentsMargins(0, 0, 0, 0);
lineLayout->setSpacing(0);
lineLayout->setAlignment(Qt::AlignLeft);
layout->addLayout(lineLayout);
@@ -22,7 +22,7 @@ QtNewsWidget::QtNewsWidget(QWidget* parent): QWidget(parent)
m_text = new QtTextEdit();
m_text->setObjectName(QStringLiteral("textField"));
m_text->setReadOnly(true);
m_text->setTabStopWidth(8 * m_text->fontMetrics().width('9'));
m_text->setTabStopDistance(8 * m_text->fontMetrics().boundingRect('9').width());
m_text->setViewportMargins(6, 4, 16, 4);
m_text->setOpenExternalLinks(true);
layout->addWidget(m_text);
@@ -80,7 +80,8 @@ QtHistoryItem::QtHistoryItem(const SearchMatch& match, size_t index, bool isCurr
QSize QtHistoryItem::getSizeHint() const
{
return QSize(
m_name->fontMetrics().width(m_name->text()) + 40, m_name->fontMetrics().height() + 8);
m_name->fontMetrics().boundingRect(m_name->text()).width() + 40,
m_name->fontMetrics().height() + 8);
}
const SearchMatch& QtHistoryItem::getMatch() const
@@ -336,7 +336,7 @@ void QtAutocompletionDelegate::calculateCharSizes(QFont font)
m_font1 = font;
QFontMetrics metrics1(font);
m_charWidth1 = metrics1.width(QStringLiteral(
m_charWidth1 = metrics1.boundingRect(QStringLiteral(
"---------------------------------------------------------------------------"
"-------------------------"
"---------------------------------------------------------------------------"
@@ -346,7 +346,8 @@ void QtAutocompletionDelegate::calculateCharSizes(QFont font)
"---------------------------------------------------------------------------"
"-------------------------"
"---------------------------------------------------------------------------"
"-------------------------")) /
"-------------------------"))
.width() /
500.0f;
m_charHeight1 = static_cast<float>(metrics1.height());
@@ -354,7 +355,7 @@ void QtAutocompletionDelegate::calculateCharSizes(QFont font)
m_font2 = font;
QFontMetrics metrics2(font);
m_charWidth2 = metrics2.width(QStringLiteral(
m_charWidth2 = metrics2.boundingRect(QStringLiteral(
"---------------------------------------------------------------------------"
"-------------------------"
"---------------------------------------------------------------------------"
@@ -364,7 +365,8 @@ void QtAutocompletionDelegate::calculateCharSizes(QFont font)
"---------------------------------------------------------------------------"
"-------------------------"
"---------------------------------------------------------------------------"
"-------------------------")) /
"-------------------------"))
.width() /
500.0f;
m_charHeight2 = static_cast<float>(metrics2.height());
@@ -901,7 +901,7 @@ void QtSmartSearchBox::layoutElements()
if (!hasSelected && i == m_cursorIndex)
{
editX = x - 5;
x += fontMetrics().width(text());
x += fontMetrics().horizontalAdvance(text());
}
if (i < m_elements.size())
@@ -923,7 +923,7 @@ void QtSmartSearchBox::layoutElements()
}
}
int cursorX = fontMetrics().width(text().left(cursorPosition()));
int cursorX = fontMetrics().horizontalAdvance(text().left(cursorPosition()));
int offsetX = m_oldLayoutOffset;
if (x < width())
+2 -2
View File
@@ -473,9 +473,9 @@ void QtGraphicsView::wheelEvent(QWheelEvent* event)
if (zoomDefault != (shiftPressed | ctrlPressed))
{
if (event->delta() != 0.0f)
if (event->angleDelta().y() != 0.0f)
{
updateZoom(static_cast<float>(event->delta()));
updateZoom(static_cast<float>(event->angleDelta().y()));
}
}
else
@@ -24,7 +24,7 @@ QtCountCircleItem::~QtCountCircleItem() {}
void QtCountCircleItem::setPosition(const Vec2f& pos)
{
qreal width = QFontMetrics(m_number->font()).width(m_number->text());
qreal width = QFontMetrics(m_number->font()).boundingRect(m_number->text()).width();
qreal height = QFontMetrics(m_number->font()).height();
this->setRadius(height / 2 + 1);
@@ -693,7 +693,7 @@ void QtGraphNode::setStyle(const GraphViewStyle::NodeStyle& style)
static_cast<qreal>(style.textOffset.y));
const float charWidth =
QFontMetrics(font).width(QStringLiteral("QtGraphNode::QtGraphNode::QtGraphNode")) / 37.0f;
QFontMetrics(font).boundingRect(QStringLiteral("QtGraphNode::QtGraphNode::QtGraphNode")).width() / 37.0f;
const float charHeight = static_cast<float>(QFontMetrics(font).height());
m_matchRect->setRect(
static_cast<qreal>(
@@ -69,7 +69,7 @@ void QtGraphNodeExpandToggle::updateStyle()
setStyle(style);
float textX = static_cast<float>(
(m_rect->rect().width() / 2) - (QFontMetrics(m_text->font()).width(m_text->text()) / 2));
(m_rect->rect().width() / 2) - (QFontMetrics(m_text->font()).boundingRect(m_text->text()).width() / 2));
const float textY = static_cast<float>(
m_rect->rect().height() / 2 - QFontMetrics(m_text->font()).height() / 1.8f);
@@ -38,7 +38,7 @@ bool QtGraphNodeQualifier::isQualifierNode() const
bool QtGraphNodeQualifier::setPosition(const Vec2i& pos)
{
const int width = QFontMetrics(m_name->font()).width(m_name->text()) + 10;
const int width = QFontMetrics(m_name->font()).boundingRect(m_name->text()).width() + 10;
const int height = QFontMetrics(m_name->font()).height() + 2;
const int arrowWidth = static_cast<int>(height * 0.85);
@@ -109,7 +109,7 @@ void QtGraphNodeQualifier::updateStyle()
void QtGraphNodeQualifier::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
const int width = QFontMetrics(m_name->font()).width(m_name->text()) + 10;
const int width = QFontMetrics(m_name->font()).boundingRect(m_name->text()).width() + 10;
const int height = QFontMetrics(m_name->font()).height() + 2;
const int arrowWidth = static_cast<int>(height * 0.85);
const float smallFactor = 0.5f;
@@ -425,16 +425,13 @@ void QtProjectWizardContentPreferences::populate(QGridLayout* layout, int& row)
// maven path
m_mavenPath = new QtLocationPicker(this);
if (QSysInfo::windowsVersion() != QSysInfo::WV_None)
{
m_mavenPath->setFileFilter(QStringLiteral("Maven command (mvn.cmd)"));
m_mavenPath->setPlaceholderText(QStringLiteral("<maven_path>/bin/mvn.cmd"));
}
else
{
m_mavenPath->setFileFilter(QStringLiteral("Maven command (mvn)"));
m_mavenPath->setPlaceholderText(QStringLiteral("<binarypath>/mvn"));
}
#ifdef WIN32
m_mavenPath->setFileFilter(QStringLiteral("Maven command (mvn.cmd)"));
m_mavenPath->setPlaceholderText(QStringLiteral("<maven_path>/bin/mvn.cmd"));
#else
m_mavenPath->setFileFilter(QStringLiteral("Maven command (mvn)"));
m_mavenPath->setPlaceholderText(QStringLiteral("<binarypath>/mvn"));
#endif
addLabelAndWidget(QStringLiteral("Maven Path"), m_mavenPath, layout, row);
@@ -25,8 +25,8 @@ void QtProjectWizardContentSelect::populate(QGridLayout* layout, int& row)
std::string pythonIndexerVersion = " ";
{
std::string str = utility::executeProcess(
"\"" + ResourcePaths::getPythonPath().str() +
"SourcetrailPythonIndexer\" --version",
ResourcePaths::getPythonPath().wstr().append(L"SourcetrailPythonIndexer"),
std::vector<std::wstring>{L"--version"},
FilePath(),
5000)
.second;
@@ -63,12 +63,13 @@ void QtProjectWizardContentPathPythonEnvironment::onTextChanged(const QString& t
m_resultLabel->setText("Checking validity of Python environment...");
std::thread([=]() {
std::pair<int, std::string> out = utility::executeProcess(
"\"" + ResourcePaths::getPythonPath().str() +
"SourcetrailPythonIndexer\" check-environment " + "--environment-path \"" +
utility::getExpandedAndAbsolutePath(
ResourcePaths::getPythonPath().wstr().append(L"SourcetrailPythonIndexer"),
std::vector<std::wstring>{
L"check-environment",
L"--environment-path " + utility::getExpandedAndAbsolutePath(
FilePath(text.toStdWString()), m_settings->getProjectDirectoryPath())
.str() +
"\"",
.wstr()
},
FilePath(),
5000);
m_onQtThread([=]() {
+3 -4
View File
@@ -4,6 +4,7 @@
#include <QClipboard>
#include <QContextMenuEvent>
#include <QDesktopServices>
#include <QDir>
#include <QUrl>
#include "MessageHistoryRedo.h"
@@ -118,10 +119,8 @@ void QtContextMenu::redoActionTriggered()
void QtContextMenu::copyFullPathActionTriggered()
{
const std::wstring pathString = (QSysInfo::windowsVersion() != QSysInfo::WV_None)
? s_filePath.getBackslashedWString()
: s_filePath.wstr();
QApplication::clipboard()->setText(QString::fromStdWString(pathString));
QApplication::clipboard()->setText(
QDir::toNativeSeparators(QString::fromStdWString(s_filePath.wstr())));
}
void QtContextMenu::openContainingFolderActionTriggered()
+5 -2
View File
@@ -76,7 +76,7 @@ QLayoutItem* QtFlowLayout::takeAt(int index)
Qt::Orientations QtFlowLayout::expandingDirections() const
{
return 0;
return Qt::Orientation::Horizontal | Qt::Orientation::Vertical;
}
bool QtFlowLayout::hasHeightForWidth() const
@@ -110,7 +110,10 @@ QSize QtFlowLayout::minimumSize() const
size = size.expandedTo(item->minimumSize());
}
size += QSize(2 * margin(), 2 * margin());
int left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom);
size += QSize(left + right, top + bottom);
return size;
}
+1 -1
View File
@@ -9,7 +9,7 @@
float QtGraphViewStyleImpl::getCharWidth(const std::string& fontName, size_t fontSize)
{
return QFontMetrics(getFontForStyleType(fontName, fontSize))
.width(QStringLiteral("QtGraphNode::QtGraphNode::QtGraphNode")) /
.boundingRect(QStringLiteral("QtGraphNode::QtGraphNode::QtGraphNode")).width() /
37.0f;
}
+3 -3
View File
@@ -65,7 +65,7 @@ void QtBookmarkBrowser::setupBookmarkBrowser()
connect(
m_filterComboBox,
QOverload<const QString&>::of(&QComboBox::currentIndexChanged),
QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
&QtBookmarkBrowser::filterOrOrderChanged);
@@ -91,7 +91,7 @@ void QtBookmarkBrowser::setupBookmarkBrowser()
connect(
m_orderComboBox,
QOverload<const QString&>::of(&QComboBox::currentIndexChanged),
QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
&QtBookmarkBrowser::filterOrOrderChanged);
}
@@ -188,7 +188,7 @@ void QtBookmarkBrowser::handleNext()
close();
}
void QtBookmarkBrowser::filterOrOrderChanged(const QString& text)
void QtBookmarkBrowser::filterOrOrderChanged(int index)
{
Bookmark::BookmarkFilter filter = getSelectedFilter();
Bookmark::BookmarkOrder order = getSelectedOrder();
+1 -1
View File
@@ -30,7 +30,7 @@ protected:
virtual void handleNext() override;
private slots:
void filterOrOrderChanged(const QString& text);
void filterOrOrderChanged(int index);
void treeItemClicked(QTreeWidgetItem* item, int column);
private:
+1 -1
View File
@@ -1134,7 +1134,7 @@ void QtMainWindow::setShowDockWidgetTitleBars(bool showTitleBars)
{
if (showTitleBars)
{
dock.widget->setFeatures(QDockWidget::AllDockWidgetFeatures);
dock.widget->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
dock.widget->setTitleBarWidget(nullptr);
}
else
@@ -57,14 +57,14 @@ void QtSelectPathsDialog::setPathsList(
if (!s.exists())
{
item->setTextColor(Qt::red);
item->setForeground(Qt::red);
item->setToolTip(QStringLiteral("Path does not exist"));
item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
item->setCheckState(Qt::Unchecked);
}
else
{
item->setTextColor(Qt::black);
item->setForeground(Qt::black);
}
}
}
+2 -2
View File
@@ -139,7 +139,7 @@ void QtStartScreen::updateButtons()
button->setIcon(m_projectIcon);
break;
}
button->setFixedWidth(button->fontMetrics().width(button->text()) + 45);
button->setFixedWidth(button->fontMetrics().boundingRect(button->text()).width() + 45);
connect(
button,
&QtRecentProjectButton::clicked,
@@ -274,7 +274,7 @@ void QtStartScreen::setupStartScreen()
button->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
button->setIcon(m_projectIcon);
button->setIconSize(QSize(30, 30));
button->setMinimumSize(button->fontMetrics().width(button->text()) + 45, 40);
button->setMinimumSize(button->fontMetrics().boundingRect(button->text()).width() + 45, 40);
button->setObjectName(QStringLiteral("recentButtonMissing"));
button->minimumSizeHint(); // force font loading
m_recentProjectsButtons.push_back(button);
+1 -1
View File
@@ -50,7 +50,7 @@ void QtTextEditDialog::populateWindow(QWidget* widget)
m_text = new QPlainTextEdit();
m_text->setObjectName(QStringLiteral("textField"));
m_text->setLineWrapMode(QPlainTextEdit::NoWrap);
m_text->setTabStopWidth(8 * m_text->fontMetrics().width('9'));
m_text->setTabStopDistance(8 * m_text->fontMetrics().boundingRect('9').width());
layout->addWidget(m_text);
widget->setLayout(layout);
+1 -1
View File
@@ -12,8 +12,8 @@ QtWindowBase::QtWindowBase(bool isSubWindow, QWidget* parent)
, m_isSubWindow(isSubWindow)
, m_window(nullptr)
, m_content(nullptr)
, m_sizeGrip(nullptr)
, m_mousePressedInWindow(false)
, m_sizeGrip(nullptr)
{
if (isSubWindow)
{
@@ -20,11 +20,10 @@ std::vector<FilePath> CxxVs15HeaderPathDetector::doGetPaths() const
.expandEnvironmentVariables();
if (!expandedPaths.empty())
{
const std::string command = "\"" + expandedPaths[0].str() +
"\" -latest -property installationPath";
const std::string command2 =
"\"C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe\"";
const std::string output = utility::executeProcess(command, FilePath(), 10000).second;
const std::string output =
utility::executeProcess(
expandedPaths[0].wstr(), std::vector<std::wstring> {L"-latest", L"-property installationPath"}, FilePath(), 10000)
.second;
const FilePath vsInstallPath(output);
if (vsInstallPath.exists())
@@ -12,7 +12,10 @@ namespace utility
std::vector<std::string> getCxxHeaderPaths(const std::string& compilerName)
{
std::string command = compilerName + " -x c++ -v -E /dev/null";
std::string clangOutput = utility::executeProcess(command.c_str()).second;
std::string clangOutput = utility::executeProcess(
utility::decodeFromUtf8(compilerName),
std::vector<std::wstring> {L"-x c++", L"-v", L"-E /dev/null"})
.second;
std::string standardHeaders = utility::substrBetween<std::string>(
clangOutput, "#include <...> search starts here:\n", "\nEnd of search list");
std::vector<std::string> paths;
@@ -54,8 +54,7 @@ std::vector<FilePath> JavaPathDetectorLinux::doGetPaths() const
FilePath JavaPathDetectorLinux::getJavaInPath() const
{
std::string command = "which java";
std::string output = utility::executeProcess(command.c_str()).second;
std::string output = utility::executeProcess(L"which", std::vector<std::wstring>{L"java"}).second;
if (!output.empty())
{
@@ -73,8 +72,7 @@ FilePath JavaPathDetectorLinux::getJavaInPath() const
FilePath JavaPathDetectorLinux::readLink(const FilePath& path) const
{
std::string command = "readlink -f " + path.str();
FilePath javaPath(utility::executeProcess(command.c_str()).second);
FilePath javaPath(utility::executeProcess(L"readlink", std::vector<std::wstring>{L"-f " + path.wstr()}).second);
if (!javaPath.empty())
{
return javaPath;
@@ -115,8 +113,7 @@ FilePath JavaPathDetectorLinux::getJavaInJavaHome() const
bool JavaPathDetectorLinux::checkVersion(const FilePath& path) const
{
std::string command = path.str() + " -version";
std::string output = utility::executeProcess(command.c_str()).second;
std::string output = utility::executeProcess(path.wstr(), std::vector<std::wstring>{L"-version"}).second;
return output.find(m_javaVersion) != std::string::npos;
}
@@ -14,8 +14,7 @@ std::vector<FilePath> JavaPathDetectorMac::doGetPaths() const
std::vector<FilePath> paths;
FilePath javaPath;
std::string command = "/usr/libexec/java_home";
std::string output = utility::executeProcess(command.c_str()).second;
std::string output = utility::executeProcess(L"/usr/libexec/java_home", std::vector<std::wstring>{}).second;
if (!output.empty())
{
@@ -7,8 +7,7 @@ MavenPathDetectorUnix::MavenPathDetectorUnix(): PathDetector("Maven for Unix") {
std::vector<FilePath> MavenPathDetectorUnix::doGetPaths() const
{
std::string command = "which mvn";
FilePath mavenPath(utility::executeProcess(command.c_str()).second);
FilePath mavenPath(utility::executeProcess(L"which", std::vector<std::wstring>{L"mvn"}).second);
std::vector<FilePath> paths;
if (mavenPath.exists())
@@ -7,8 +7,7 @@ MavenPathDetectorWindows::MavenPathDetectorWindows(): PathDetector("Maven for Wi
std::vector<FilePath> MavenPathDetectorWindows::doGetPaths() const
{
std::string command = "cmd /c where mvn.cmd && exit";
FilePath mavenPath(utility::executeProcess(command.c_str()).second);
FilePath mavenPath(utility::executeProcess(L"cmd", std::vector<std::wstring>{L"/c where mvn.cmd && exit"}).second);
std::vector<FilePath> paths;
if (mavenPath.exists())
+25 -37
View File
@@ -57,7 +57,10 @@ std::set<QProcess*> s_runningProcesses;
} // namespace utility
std::pair<int, std::string> utility::executeProcess(
const std::string& command, const FilePath& workingDirectory, const int timeout)
const std::wstring& commandPath,
const std::vector<std::wstring>& commandArguments,
const FilePath& workingDirectory,
const int timeout)
{
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
@@ -67,6 +70,12 @@ std::pair<int, std::string> utility::executeProcess(
process.setWorkingDirectory(QString::fromStdWString(workingDirectory.wstr()));
}
QString command = QString::fromStdWString(commandPath);
for (const std::wstring& commandArgument: commandArguments)
{
command += QString::fromStdWString(L" " + commandArgument);
}
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QStringList envlist = env.toStringList();
envlist.replaceInStrings(
@@ -76,7 +85,7 @@ std::pair<int, std::string> utility::executeProcess(
{
std::lock_guard<std::mutex> lock(s_runningProcessesMutex);
process.start(command.c_str());
process.start(command);
s_runningProcesses.insert(&process);
}
@@ -96,7 +105,10 @@ std::pair<int, std::string> utility::executeProcess(
}
std::string utility::executeProcessUntilNoOutput(
const std::string& command, const FilePath& workingDirectory, const int waitTime)
const std::wstring& commandPath,
const std::vector<std::wstring>& commandArguments,
const FilePath& workingDirectory,
const int waitTime)
{
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
@@ -106,6 +118,12 @@ std::string utility::executeProcessUntilNoOutput(
process.setWorkingDirectory(QString::fromStdWString(workingDirectory.wstr()));
}
QString command = QString::fromStdWString(commandPath);
for (const std::wstring& commandArgument: commandArguments)
{
command += QString::fromStdWString(L" " + commandArgument);
}
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QStringList envlist = env.toStringList();
envlist.replaceInStrings(
@@ -115,7 +133,7 @@ std::string utility::executeProcessUntilNoOutput(
{
std::lock_guard<std::mutex> lock(s_runningProcessesMutex);
process.start(command.c_str());
process.start(command);
s_runningProcesses.insert(&process);
}
@@ -161,9 +179,7 @@ int utility::executeProcessAndGetExitCode(
QProcess process;
QObject::connect(
&process,
&QProcess::errorOccurred,
[&finished, errorMessage, commandPath](QProcess::ProcessError error) {
&process, &QProcess::errorOccurred, [&finished, errorMessage](QProcess::ProcessError error) {
finished = true;
if (errorMessage != nullptr)
{
@@ -205,7 +221,7 @@ int utility::executeProcessAndGetExitCode(
QString command = QString::fromStdWString(commandPath);
for (const std::wstring& commandArgument: commandArguments)
{
command += " " + QString::fromStdWString(commandArgument);
command += QString::fromStdWString(L" " + commandArgument);
}
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
@@ -276,23 +292,6 @@ int utility::getIdealThreadCount()
return std::max(1, threadCount);
}
OsType utility::getOsType()
{
if (QSysInfo::windowsVersion() != QSysInfo::WV_None)
{
return OS_WINDOWS;
}
else if (QSysInfo::macVersion() != QSysInfo::MV_None)
{
return OS_MAC;
}
else
{
return OS_LINUX;
}
return OS_UNKNOWN;
}
std::string utility::getOsTypeString()
{
// WARNING: Don't change these string. The server API relies on them.
@@ -308,15 +307,4 @@ std::string utility::getOsTypeString()
break;
}
return "unknown";
}
ApplicationArchitectureType utility::getApplicationArchitectureType()
{
#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) || \
defined(WIN64)
return APPLICATION_ARCHITECTURE_X86_64;
#else
return APPLICATION_ARCHITECTURE_X86_32;
#endif
return APPLICATION_ARCHITECTURE_UNKNOWN;
}
}
+30 -4
View File
@@ -10,11 +10,15 @@
namespace utility
{
std::pair<int, std::string> executeProcess(
const std::string& command,
const std::wstring& commandPath,
const std::vector<std::wstring>& commandArguments,
const FilePath& workingDirectory = FilePath(),
const int timeout = 30000);
std::string executeProcessUntilNoOutput(
const std::string& command, const FilePath& workingDirectory, int waitTime = 10000);
const std::wstring& commandPath,
const std::vector<std::wstring>& commandArguments,
const FilePath& workingDirectory,
int waitTime = 10000);
int executeProcessAndGetExitCode(
const std::wstring& commandPath,
const std::vector<std::wstring>& commandArguments,
@@ -26,9 +30,31 @@ int executeProcessAndGetExitCode(
void killRunningProcesses();
int getIdealThreadCount();
OsType getOsType();
constexpr OsType getOsType()
{
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
return OS_WINDOWS;
#elif defined(__APPLE__)
return OS_MAC;
#elif defined(__linux) || defined(__linux__) || defined(linux)
return OS_LINUX;
#else
return OS_UNKNOWN;
#endif
}
std::string getOsTypeString();
ApplicationArchitectureType getApplicationArchitectureType();
constexpr ApplicationArchitectureType getApplicationArchitectureType()
{
#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) || \
defined(WIN64)
return APPLICATION_ARCHITECTURE_X86_64;
#else
return APPLICATION_ARCHITECTURE_X86_32;
#endif
return APPLICATION_ARCHITECTURE_UNKNOWN;
}
} // namespace utility
#endif // UTILITY_APP_H
+25 -19
View File
@@ -82,20 +82,14 @@ std::wstring getErrorMessageFromMavenOutput(std::shared_ptr<const TextAccess> ma
return errorMessage;
}
std::string getMavenArgsString(const FilePath& settingsFilePath)
std::vector<std::wstring> getMavenArgs(const FilePath& settingsFilePath)
{
std::vector<std::string> args;
std::vector<std::wstring> args;
if (!settingsFilePath.empty() && settingsFilePath.exists())
{
args.push_back("--settings \"" + settingsFilePath.str() + "\"");
args.push_back(L"--settings \"" + settingsFilePath.wstr() + L"\"");
}
std::string ret = "";
for (const std::string& arg: args)
{
ret += arg + " ";
}
return ret;
return args;
}
} // namespace
@@ -107,9 +101,13 @@ std::wstring mavenGenerateSources(
{
utility::setJavaHomeVariableIfNotExists();
auto args = getMavenArgs(settingsFilePath);
args.push_back(L"generate-sources");
std::shared_ptr<TextAccess> outputAccess = TextAccess::createFromString(
utility::executeProcessUntilNoOutput(
"\"" + mavenPath.str() + "\" " + getMavenArgsString(settingsFilePath) + "generate-sources",
mavenPath.wstr(),
args,
projectDirectoryPath,
60000));
@@ -130,11 +128,15 @@ bool mavenCopyDependencies(
{
utility::setJavaHomeVariableIfNotExists();
auto args = getMavenArgs(settingsFilePath);
args.push_back(L"dependency:copy-dependencies");
args.push_back(L"-DoutputDirectory=" + outputDirectoryPath.wstr());
std::shared_ptr<TextAccess> outputAccess = TextAccess::createFromString(
utility::executeProcessUntilNoOutput(
"\"" + mavenPath.str() + "\" " + getMavenArgsString(settingsFilePath) +
"dependency:copy-dependencies -DoutputDirectory=" + outputDirectoryPath.str(),
projectDirectoryPath,
utility::executeProcessUntilNoOutput(
mavenPath.wstr(),
args,
projectDirectoryPath,
60000));
const std::wstring errorMessage = getErrorMessageFromMavenOutput(outputAccess);
@@ -159,11 +161,15 @@ std::vector<FilePath> mavenGetAllDirectoriesFromEffectivePom(
FilePath outputPath = outputDirectoryPath.getConcatenated(FilePath("/effective-pom.xml"));
auto args = getMavenArgs(settingsFilePath);
args.push_back(L"help:effective-pom");
args.push_back(L"-Doutput=" + outputPath.wstr());
std::shared_ptr<TextAccess> outputAccess = TextAccess::createFromString(
utility::executeProcessUntilNoOutput(
"\"" + mavenPath.str() + "\" " + getMavenArgsString(settingsFilePath) +
"help:effective-pom -Doutput=\"" + outputPath.str(),
projectDirectoryPath,
utility::executeProcessUntilNoOutput(
mavenPath.wstr(),
args,
projectDirectoryPath,
60000));
const std::wstring errorMessage = getErrorMessageFromMavenOutput(outputAccess);