summaryrefslogtreecommitdiff
path: root/dev-libs/libclangformat-ide
diff options
context:
space:
mode:
Diffstat (limited to 'dev-libs/libclangformat-ide')
-rw-r--r--dev-libs/libclangformat-ide/Manifest6
-rw-r--r--dev-libs/libclangformat-ide/files/clang-qtcreator-compat.patch185
-rw-r--r--dev-libs/libclangformat-ide/libclangformat-ide-10.0.0.ebuild72
-rw-r--r--dev-libs/libclangformat-ide/libclangformat-ide-9.0.1.ebuild72
-rw-r--r--dev-libs/libclangformat-ide/metadata.xml8
5 files changed, 343 insertions, 0 deletions
diff --git a/dev-libs/libclangformat-ide/Manifest b/dev-libs/libclangformat-ide/Manifest
new file mode 100644
index 000000000000..c61aef07544d
--- /dev/null
+++ b/dev-libs/libclangformat-ide/Manifest
@@ -0,0 +1,6 @@
+AUX clang-qtcreator-compat.patch 7480 BLAKE2B aabe085093786be2733f50259be355596b8f35ddcf524aa9437f67462e48c22532e51b113a1e839e6f1bb22548229ee111c0587e58b62e3a145a6bdf43b9b347 SHA512 6e8d761dcd7bcdda476326fa8b2e3d5966f15959aefc500c04a57b6396a035fc822ad1a57184519de3ac7340c680a5f49f5fc9841d24210e20e949d6b28a57b4
+DIST llvmorg-10.0.0.tar.gz 120804856 BLAKE2B 6b0254f5b913398cdcf2b2ec1ff219888706d2b79d5296590934714e42ac79f6a6547941ac2b1d2c4e6313dd18b6c7068e748aa6ac033e49fccbf5d355aa8191 SHA512 baa182d62fef1851836013ae8a1a00861ea89769778d67fb97b407a9de664e6c85da2af9c5b3f75d2bf34ff6b00004e531ca7e4b3115a26c0e61c575cf2303a0
+DIST llvmorg-9.0.1.tar.gz 113193320 BLAKE2B b86e405f2b8e00436045fd409fe19cdde75c797b1192c62a22b5ec75e6b4dc8e874a0f33008dc31562445e4cbe53a992b6f48c684255a6a1ef261e595b8b161f SHA512 fa88beeaae94b6d0cd9b5ba38658d0ffed8004035d7d8a4f95c3d31a709b88b581ae9bd7761333c8e5375c44b8f6be01768b5a3be901163159d7e6c43b71da59
+EBUILD libclangformat-ide-10.0.0.ebuild 1719 BLAKE2B af595842b8e1928f435a93bdc04935bbfac86c90ec40a87344b1023e1bcb855dbcf3517e63f1c0d9093e652aa12aa8ceef8cc0e48a831831f445185e6687125d SHA512 c345fed4ed94521ec51ae5b998db71f29efc5b927bd3471c754649c787373939a396f0dcd16bfa3a2516eb415cbc2457cd7616b17a404b70712c94f8b99335d7
+EBUILD libclangformat-ide-9.0.1.ebuild 1719 BLAKE2B af595842b8e1928f435a93bdc04935bbfac86c90ec40a87344b1023e1bcb855dbcf3517e63f1c0d9093e652aa12aa8ceef8cc0e48a831831f445185e6687125d SHA512 c345fed4ed94521ec51ae5b998db71f29efc5b927bd3471c754649c787373939a396f0dcd16bfa3a2516eb415cbc2457cd7616b17a404b70712c94f8b99335d7
+MISC metadata.xml 247 BLAKE2B ab9618e71ad95ebd451d7b51076eb19801293790b027d4e390b35c1f2cc31ac20f8f41f91b8e167f700a3a42e7f366e2292e944fde98502016a4b0587c66d833 SHA512 be8285f713dca05e18b9ee5c5c45b4938cbc5ef707b0224a0aec98934633f7fcf526b6322e91a67b33804ca99a0997e1698bd2c772fa709256006517c89b7f51
diff --git a/dev-libs/libclangformat-ide/files/clang-qtcreator-compat.patch b/dev-libs/libclangformat-ide/files/clang-qtcreator-compat.patch
new file mode 100644
index 000000000000..72b9453ce7a4
--- /dev/null
+++ b/dev-libs/libclangformat-ide/files/clang-qtcreator-compat.patch
@@ -0,0 +1,185 @@
+From fa1b9053729ec6a4425a44ec5502dd388928274a Mon Sep 17 00:00:00 2001
+From: Ivan Donchevskii <ivan.donchevskii@qt.io>
+Date: Fri, 12 Oct 2018 08:19:25 +0200
+Subject: [PATCH] [clang-format] Introduce the flag which allows not to shrink
+ lines
+
+--------------------------------------------------------------------------
+* https://reviews.llvm.org/D53072
+--------------------------------------------------------------------------
+
+Currently there's no way to prevent to lines optimization even
+if you have intentionally put <CR> to split the line.
+
+In general case it's fine. So I would prefer to have such option
+which you can enable in special cases (for me it's an IDE related use case).
+
+Revert this change if upstream clang-format offers better solution.
+
+This is a cherry pick from commits b748c82e3664c2e2e3d29645ede472d87b8cde63
+and 1817513d4f3a2e4e26be124dbe395340f798fd51.
+
+Change-Id: I9d2935b937bb68ea8dc59fac8463718475e9c080
+Reviewed-by: Orgad Shaneh <orgads@gmail.com>
+---
+ include/clang/Format/Format.h | 13 +++++++++++++
+ lib/Format/Format.cpp | 4 ++++
+ lib/Format/UnwrappedLineFormatter.cpp | 9 +++++----
+ lib/Format/UnwrappedLineParser.cpp | 2 ++
+ unittests/Format/FormatTest.cpp | 16 ++++++++++++++++
+ 5 files changed, 40 insertions(+), 4 deletions(-)
+
+diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h
+index cb37b0c890c..b9c4df3d1af 100644
+--- a/include/clang/Format/Format.h
++++ b/include/clang/Format/Format.h
+@@ -22,6 +22,8 @@
+ #include "llvm/Support/Regex.h"
+ #include <system_error>
+
++#define KEEP_LINE_BREAKS_FOR_NON_EMPTY_LINES_BACKPORTED
++
+ namespace llvm {
+ namespace vfs {
+ class FileSystem;
+@@ -1200,6 +1202,16 @@ struct FormatStyle {
+ /// \endcode
+ bool JavaScriptWrapImports;
+
++ /// If true, no line breaks are optimized out (works only with ColumnLimit = 0)
++ /// \code
++ /// true: false:
++ /// int foo(int a, vs. int foo(int a, int b) {
++ /// int b) {
++ /// bar(); bar();
++ /// } }
++ /// \endcode
++ bool KeepLineBreaksForNonEmptyLines;
++
+ /// If true, the empty line at the start of blocks is kept.
+ /// \code
+ /// true: false:
+@@ -1767,6 +1779,7 @@ struct FormatStyle {
+ JavaImportGroups == R.JavaImportGroups &&
+ JavaScriptQuotes == R.JavaScriptQuotes &&
+ JavaScriptWrapImports == R.JavaScriptWrapImports &&
++ KeepLineBreaksForNonEmptyLines == R.KeepLineBreaksForNonEmptyLines &&
+ KeepEmptyLinesAtTheStartOfBlocks ==
+ R.KeepEmptyLinesAtTheStartOfBlocks &&
+ MacroBlockBegin == R.MacroBlockBegin &&
+diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
+index 2c4f8760540..61ea88626ee 100644
+--- a/lib/Format/Format.cpp
++++ b/lib/Format/Format.cpp
+@@ -417,6 +417,8 @@ template <> struct MappingTraits<FormatStyle> {
+ IO.mapOptional("JavaImportGroups", Style.JavaImportGroups);
+ IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes);
+ IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
++ IO.mapOptional("KeepLineBreaksForNonEmptyLines",
++ Style.KeepLineBreaksForNonEmptyLines);
+ IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
+ Style.KeepEmptyLinesAtTheStartOfBlocks);
+ IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
+@@ -678,6 +680,7 @@ FormatStyle getLLVMStyle() {
+ LLVMStyle.JavaScriptWrapImports = true;
+ LLVMStyle.TabWidth = 8;
+ LLVMStyle.MaxEmptyLinesToKeep = 1;
++ LLVMStyle.KeepLineBreaksForNonEmptyLines = false;
+ LLVMStyle.KeepEmptyLinesAtTheStartOfBlocks = true;
+ LLVMStyle.NamespaceIndentation = FormatStyle::NI_None;
+ LLVMStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Auto;
+@@ -745,6 +748,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
+ {"^<ext/.*\\.h>", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
+ GoogleStyle.IncludeStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
+ GoogleStyle.IndentCaseLabels = true;
++ GoogleStyle.KeepLineBreaksForNonEmptyLines = false;
+ GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
+ GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
+ GoogleStyle.ObjCSpaceAfterProperty = false;
+diff --git a/lib/Format/UnwrappedLineFormatter.cpp b/lib/Format/UnwrappedLineFormatter.cpp
+index 6b6a9aff461..c88efbc6867 100644
+--- a/lib/Format/UnwrappedLineFormatter.cpp
++++ b/lib/Format/UnwrappedLineFormatter.cpp
+@@ -684,7 +684,7 @@ public:
+ LineFormatter(ContinuationIndenter *Indenter, WhitespaceManager *Whitespaces,
+ const FormatStyle &Style,
+ UnwrappedLineFormatter *BlockFormatter)
+- : Indenter(Indenter), Whitespaces(Whitespaces), Style(Style),
++ : Indenter(Indenter), Style(Style), Whitespaces(Whitespaces),
+ BlockFormatter(BlockFormatter) {}
+ virtual ~LineFormatter() {}
+
+@@ -727,7 +727,8 @@ protected:
+ // assert so that we can simply call this function for all tokens.
+ return true;
+
+- if (NewLine) {
++ if (NewLine || (Previous.Children[0]->First->MustBreakBefore &&
++ Style.KeepLineBreaksForNonEmptyLines)) {
+ int AdditionalIndent = State.Stack.back().Indent -
+ Previous.Children[0]->Level * Style.IndentWidth;
+
+@@ -772,10 +773,10 @@ protected:
+ }
+
+ ContinuationIndenter *Indenter;
++ const FormatStyle &Style;
+
+ private:
+ WhitespaceManager *Whitespaces;
+- const FormatStyle &Style;
+ UnwrappedLineFormatter *BlockFormatter;
+ };
+
+@@ -798,7 +799,7 @@ public:
+ while (State.NextToken) {
+ bool Newline =
+ Indenter->mustBreak(State) ||
+- (Indenter->canBreak(State) && State.NextToken->NewlinesBefore > 0);
++ (State.NextToken->NewlinesBefore > 0 && Indenter->canBreak(State));
+ unsigned Penalty = 0;
+ formatChildren(State, Newline, /*DryRun=*/false, Penalty);
+ Indenter->addTokenToState(State, Newline, /*DryRun=*/false);
+diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
+index 3cd3c8f9cdf..3aa30c7cb3f 100644
+--- a/lib/Format/UnwrappedLineParser.cpp
++++ b/lib/Format/UnwrappedLineParser.cpp
+@@ -2554,6 +2554,8 @@ void UnwrappedLineParser::nextToken(int LevelDifference) {
+ else
+ readTokenWithJavaScriptASI();
+ FormatTok->Previous = Previous;
++ if (FormatTok->NewlinesBefore && Style.KeepLineBreaksForNonEmptyLines)
++ FormatTok->MustBreakBefore = true;
+ }
+
+ void UnwrappedLineParser::distributeComments(
+diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
+index c05fceb4766..38906d9ee31 100644
+--- a/unittests/Format/FormatTest.cpp
++++ b/unittests/Format/FormatTest.cpp
+@@ -385,6 +385,22 @@ TEST_F(FormatTest, RemovesEmptyLines) {
+ " void funk() {}\n"
+ "};",
+ Style));
++
++ Style.KeepLineBreaksForNonEmptyLines = true;
++ Style.ColumnLimit = 0;
++ EXPECT_EQ("int foo(int a,\n"
++ " int b)\n"
++ "{\n"
++ "}",
++ format("int foo(int a,\n"
++ "int b) {}",
++ Style));
++
++ EXPECT_EQ("[]() {\n"
++ " foo(); }",
++ format("[]() {\n"
++ "foo(); }",
++ Style));
+ }
+
+ TEST_F(FormatTest, RecognizesBinaryOperatorKeywords) {
+--
+2.26.2
+
diff --git a/dev-libs/libclangformat-ide/libclangformat-ide-10.0.0.ebuild b/dev-libs/libclangformat-ide/libclangformat-ide-10.0.0.ebuild
new file mode 100644
index 000000000000..5c04b67cf27c
--- /dev/null
+++ b/dev-libs/libclangformat-ide/libclangformat-ide-10.0.0.ebuild
@@ -0,0 +1,72 @@
+# Copyright 1999-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+inherit cmake llvm llvm.org toolchain-funcs
+
+DESCRIPTION="A static clangformat library patched for IDE use"
+HOMEPAGE="https://www.qt.io/blog/2019/04/17/clangformat-plugin-qt-creator-4-9"
+LLVM_COMPONENTS=( clang )
+
+llvm.org_set_globals
+
+LICENSE="Apache-2.0-with-LLVM-exceptions UoI-NCSA MIT"
+SLOT="$(ver_cut 1)"
+KEYWORDS="~amd64 ~x86"
+IUSE="debug"
+
+DEPEND="~sys-devel/llvm-${PV}:${SLOT}=[debug=]"
+
+# least intrusive of all
+CMAKE_BUILD_TYPE=RelWithDebInfo
+
+PATCHES=( "${FILESDIR}/clang-qtcreator-compat.patch" )
+
+pkg_setup() {
+ LLVM_MAX_SLOT=${SLOT} llvm_pkg_setup
+}
+
+src_unpack() {
+ llvm.org_src_unpack
+}
+
+src_configure() {
+ local mycmakeargs=(
+ -DLLVM_CMAKE_PATH="${EPREFIX}/usr/lib/llvm/${SLOT}/$(get_libdir)/cmake/llvm"
+ -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr/lib/llvm/${SLOT}"
+ -DBUILD_SHARED_LIBS=OFF
+ -DLLVM_ENABLE_EH=ON
+ -DLLVM_ENABLE_RTTI=ON
+ )
+
+ if [[ -n ${EPREFIX} ]]; then
+ mycmakeargs+=(
+ -DGCC_INSTALL_PREFIX="${EPREFIX}/usr"
+ )
+ fi
+
+ if tc-is-cross-compiler; then
+ [[ -x "/usr/bin/clang-tblgen" ]] \
+ || die "/usr/bin/clang-tblgen not found or usable"
+ mycmakeargs+=(
+ -DCMAKE_CROSSCOMPILING=ON
+ -DCLANG_TABLEGEN=/usr/bin/clang-tblgen
+ )
+ fi
+
+ # LLVM_ENABLE_ASSERTIONS=NO does not guarantee this for us, #614844
+ use debug || local -x CPPFLAGS="${CPPFLAGS} -DNDEBUG"
+ cmake_src_configure
+}
+
+src_compile() {
+ cmake_src_compile libclangFormat.a
+}
+
+src_install() {
+ into usr/lib/llvm/${SLOT}
+ newlib.a "${BUILD_DIR}/$(get_libdir)/libclangFormat.a" libclangFormatIDE.a
+ insinto usr/lib/llvm/${SLOT}/include/clang/Format
+ newins "${S}/include/clang/Format/Format.h" FormatIDE.h
+}
diff --git a/dev-libs/libclangformat-ide/libclangformat-ide-9.0.1.ebuild b/dev-libs/libclangformat-ide/libclangformat-ide-9.0.1.ebuild
new file mode 100644
index 000000000000..5c04b67cf27c
--- /dev/null
+++ b/dev-libs/libclangformat-ide/libclangformat-ide-9.0.1.ebuild
@@ -0,0 +1,72 @@
+# Copyright 1999-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+inherit cmake llvm llvm.org toolchain-funcs
+
+DESCRIPTION="A static clangformat library patched for IDE use"
+HOMEPAGE="https://www.qt.io/blog/2019/04/17/clangformat-plugin-qt-creator-4-9"
+LLVM_COMPONENTS=( clang )
+
+llvm.org_set_globals
+
+LICENSE="Apache-2.0-with-LLVM-exceptions UoI-NCSA MIT"
+SLOT="$(ver_cut 1)"
+KEYWORDS="~amd64 ~x86"
+IUSE="debug"
+
+DEPEND="~sys-devel/llvm-${PV}:${SLOT}=[debug=]"
+
+# least intrusive of all
+CMAKE_BUILD_TYPE=RelWithDebInfo
+
+PATCHES=( "${FILESDIR}/clang-qtcreator-compat.patch" )
+
+pkg_setup() {
+ LLVM_MAX_SLOT=${SLOT} llvm_pkg_setup
+}
+
+src_unpack() {
+ llvm.org_src_unpack
+}
+
+src_configure() {
+ local mycmakeargs=(
+ -DLLVM_CMAKE_PATH="${EPREFIX}/usr/lib/llvm/${SLOT}/$(get_libdir)/cmake/llvm"
+ -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr/lib/llvm/${SLOT}"
+ -DBUILD_SHARED_LIBS=OFF
+ -DLLVM_ENABLE_EH=ON
+ -DLLVM_ENABLE_RTTI=ON
+ )
+
+ if [[ -n ${EPREFIX} ]]; then
+ mycmakeargs+=(
+ -DGCC_INSTALL_PREFIX="${EPREFIX}/usr"
+ )
+ fi
+
+ if tc-is-cross-compiler; then
+ [[ -x "/usr/bin/clang-tblgen" ]] \
+ || die "/usr/bin/clang-tblgen not found or usable"
+ mycmakeargs+=(
+ -DCMAKE_CROSSCOMPILING=ON
+ -DCLANG_TABLEGEN=/usr/bin/clang-tblgen
+ )
+ fi
+
+ # LLVM_ENABLE_ASSERTIONS=NO does not guarantee this for us, #614844
+ use debug || local -x CPPFLAGS="${CPPFLAGS} -DNDEBUG"
+ cmake_src_configure
+}
+
+src_compile() {
+ cmake_src_compile libclangFormat.a
+}
+
+src_install() {
+ into usr/lib/llvm/${SLOT}
+ newlib.a "${BUILD_DIR}/$(get_libdir)/libclangFormat.a" libclangFormatIDE.a
+ insinto usr/lib/llvm/${SLOT}/include/clang/Format
+ newins "${S}/include/clang/Format/Format.h" FormatIDE.h
+}
diff --git a/dev-libs/libclangformat-ide/metadata.xml b/dev-libs/libclangformat-ide/metadata.xml
new file mode 100644
index 000000000000..d472e560c734
--- /dev/null
+++ b/dev-libs/libclangformat-ide/metadata.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer type="person">
+ <email>pesa@gentoo.org</email>
+ <name>Davide Pesavento</name>
+ </maintainer>
+</pkgmetadata>