ClangFormat: Do not refuse to build against unpatched clang

The plugin builds just fine and should be mostly (fully?) functional with
upstream clang, so it seems excessive to force-disable it entirely for
everybody not using our custom patch.

Change-Id: Id6a179c20325290a8205218c9514a16c1adc9076
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2020-12-18 11:10:09 +01:00
parent 6263a58ef3
commit f7d8f8b704
2 changed files with 17 additions and 12 deletions

View File

@@ -209,7 +209,7 @@ The ClangFormat plugin depends on the additional patch
https://code.qt.io/cgit/clang/llvm-project.git/commit/?h=release_100-based&id=9b992a0f7f160dd6c75f20a4dcfcf7c60a4894df https://code.qt.io/cgit/clang/llvm-project.git/commit/?h=release_100-based&id=9b992a0f7f160dd6c75f20a4dcfcf7c60a4894df
While the plugin builds without it, it will be disabled on start with an error message. While the plugin builds without it, it might not be fully functional.
Note that the plugin is disabled by default. Note that the plugin is disabled by default.

View File

@@ -59,6 +59,7 @@
#include <clang/Format/Format.h> #include <clang/Format/Format.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/infobar.h>
#include <QAction> #include <QAction>
#include <QDebug> #include <QDebug>
@@ -70,7 +71,6 @@ using namespace ProjectExplorer;
namespace ClangFormat { namespace ClangFormat {
#ifdef KEEP_LINE_BREAKS_FOR_NON_EMPTY_LINES_BACKPORTED
class ClangFormatStyleFactory : public CppTools::CppCodeStylePreferencesFactory class ClangFormatStyleFactory : public CppTools::CppCodeStylePreferencesFactory
{ {
public: public:
@@ -101,13 +101,11 @@ static void replaceCppCodeStyle()
ICodeStylePreferencesFactory *factory = new ClangFormatStyleFactory(); ICodeStylePreferencesFactory *factory = new ClangFormatStyleFactory();
TextEditorSettings::registerCodeStyleFactory(factory); TextEditorSettings::registerCodeStyleFactory(factory);
} }
#endif
bool ClangFormatPlugin::initialize(const QStringList &arguments, QString *errorString) bool ClangFormatPlugin::initialize(const QStringList &arguments, QString *errorString)
{ {
Q_UNUSED(arguments) Q_UNUSED(arguments)
Q_UNUSED(errorString) Q_UNUSED(errorString)
#ifdef KEEP_LINE_BREAKS_FOR_NON_EMPTY_LINES_BACKPORTED
replaceCppCodeStyle(); replaceCppCodeStyle();
Core::ActionContainer *contextMenu = Core::ActionManager::actionContainer( Core::ActionContainer *contextMenu = Core::ActionManager::actionContainer(
@@ -151,18 +149,25 @@ bool ClangFormatPlugin::initialize(const QStringList &arguments, QString *errorS
openClangFormatConfigAction->setData(doc->filePath().toString()); openClangFormatConfigAction->setData(doc->filePath().toString());
}); });
} }
return true; #ifndef KEEP_LINE_BREAKS_FOR_NON_EMPTY_LINES_BACKPORTED
#else
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma message( \ #pragma message( \
"ClangFormat: building dummy plugin due to unmodified Clang, see README.md for more info") "ClangFormat: building against unmodified Clang, see README.md for more info")
#else #else
#warning ClangFormat: building dummy plugin due to unmodified Clang, see README.md for more info #warning ClangFormat: building against unmodified Clang, see README.md for more info
#endif #endif
*errorString = "Disabling ClangFormat plugin as it has not been built against a modified Clang's libFormat." static const char clangFormatFormatWarningKey[] = "ClangFormatFormatWarning";
"For more information see the Qt Creator README at " if (!Core::ICore::infoBar()->canInfoBeAdded(clangFormatFormatWarningKey))
"https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/README.md"; return true;
return false; Utils::InfoBarEntry
info(clangFormatFormatWarningKey,
tr("The ClangFormat plugin has been built against an unmodified Clang. "
"You might experience formatting glitches in certain circumstances. "
"See https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/README.md for more "
"information."),
Utils::InfoBarEntry::GlobalSuppression::Enabled);
Core::ICore::infoBar()->addInfo(info);
return true;
#endif #endif
} }