From f7d8f8b7048d631e369b55db24df0a14e2437354 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 18 Dec 2020 11:10:09 +0100 Subject: [PATCH] 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 --- README.md | 2 +- src/plugins/clangformat/clangformatplugin.cpp | 27 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4730334c0d8..1c3d4e6df9e 100644 --- a/README.md +++ b/README.md @@ -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 -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. diff --git a/src/plugins/clangformat/clangformatplugin.cpp b/src/plugins/clangformat/clangformatplugin.cpp index 9b76a0862ff..1e410aa5640 100644 --- a/src/plugins/clangformat/clangformatplugin.cpp +++ b/src/plugins/clangformat/clangformatplugin.cpp @@ -59,6 +59,7 @@ #include #include +#include #include #include @@ -70,7 +71,6 @@ using namespace ProjectExplorer; namespace ClangFormat { -#ifdef KEEP_LINE_BREAKS_FOR_NON_EMPTY_LINES_BACKPORTED class ClangFormatStyleFactory : public CppTools::CppCodeStylePreferencesFactory { public: @@ -101,13 +101,11 @@ static void replaceCppCodeStyle() ICodeStylePreferencesFactory *factory = new ClangFormatStyleFactory(); TextEditorSettings::registerCodeStyleFactory(factory); } -#endif bool ClangFormatPlugin::initialize(const QStringList &arguments, QString *errorString) { Q_UNUSED(arguments) Q_UNUSED(errorString) -#ifdef KEEP_LINE_BREAKS_FOR_NON_EMPTY_LINES_BACKPORTED replaceCppCodeStyle(); Core::ActionContainer *contextMenu = Core::ActionManager::actionContainer( @@ -151,18 +149,25 @@ bool ClangFormatPlugin::initialize(const QStringList &arguments, QString *errorS openClangFormatConfigAction->setData(doc->filePath().toString()); }); } - return true; -#else +#ifndef KEEP_LINE_BREAKS_FOR_NON_EMPTY_LINES_BACKPORTED #ifdef _MSC_VER #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 -#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 - *errorString = "Disabling ClangFormat plugin as it has not been built against a modified Clang's libFormat." - "For more information see the Qt Creator README at " - "https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/README.md"; - return false; + static const char clangFormatFormatWarningKey[] = "ClangFormatFormatWarning"; + if (!Core::ICore::infoBar()->canInfoBeAdded(clangFormatFormatWarningKey)) + return true; + 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 }