git.iko.soy/typeable/nixpkgs
on master help sign in
qtcreator: add clang code model compilation

Clang code model provides user with services: code completion, syntactic and semantic highlighting, diagnostics, outline of symbols, tooltips, renaming of local symbols. It's naturally depends on llvm and clang. To make it work with nixos: 1. Add qt version of clang as build dependency. 2. Added patch for clang libc++ regexp trunk regexp not including path like "libc++-version". 3. Fixed paths to llvm/clang libraries and includes. 4. Fixed name of clazy clang plugin.

commit6365fa1eb97f730b587df7e3b72025b5173be219 authorAndrew Newman <deadloko@gmail.com> dateTue 7 May 2019, 17:18 (8 years ago) parenteff932e
2 files changed+62−3
pkgs/development/tools/qtcreator/0001-Fix-clang-libcpp-regexp.patch+15 pkgs/development/tools/qtcreator/default.nix+47−3
pkgs/development/tools/qtcreator/0001-Fix-clang-libcpp-regexp.patchnew file+15
@@ -0,0 +1,15 @@
1+diff --git a/src/plugins/cpptools/headerpathfilter.cpp b/src/plugins/cpptools/headerpathfilter.cpp
2+index b514c46..5f96358 100644
3+--- a/src/plugins/cpptools/headerpathfilter.cpp
4++++ b/src/plugins/cpptools/headerpathfilter.cpp
5+@@ -92,8 +92,8 @@ HeaderPaths::iterator resourceIterator(HeaderPaths &headerPaths, bool isMacOs)
6+ {
7+ // include/c++, include/g++, libc++\include and libc++abi\include
8+ static const QString cppIncludes = R"((.*\/include\/.*(g\+\+|c\+\+).*))"
9+- R"(|(.*libc\+\+\/include))"
10+- R"(|(.*libc\+\+abi\/include))";
11++ R"(|(.*libc\+\+.*\/include))"
12++ R"(|(.*libc\+\+abi.*\/include))";
13+ static const QRegularExpression includeRegExp("\\A(" + cppIncludes + ")\\z");
14+
15+ // The same as includeRegExp but also matches /usr/local/include
pkgs/development/tools/qtcreator/default.nix+47−3
@@ -1,5 +1,5 @@
1−{ stdenv, fetchurl, makeWrapper
2−, qtbase, qtquickcontrols, qtscript, qtdeclarative, qmake
1+{ stdenv, fetchurl, fetchgit, fetchpatch, makeWrapper
2+, qtbase, qtquickcontrols, qtscript, qtdeclarative, qmake, llvmPackages_8
33, withDocumentation ? false
44}:
55
@@ -8,6 +8,17 @@ with stdenv.lib;
88let
99 baseVersion = "4.9";
1010 revision = "1";
11+
12+ # Fetch clang from qt vendor, this contains submodules like this:
13+ # clang<-clang-tools-extra<-clazy.
14+ clang_qt_vendor = llvmPackages_8.clang-unwrapped.overrideAttrs (oldAttrs: rec {
15+ src = fetchgit {
16+ url = "https://code.qt.io/clang/clang.git";
17+ rev = "c12b012bb7465299490cf93c2ae90499a5c417d5";
18+ sha256 = "0mgmnazgr19hnd03xcrv7d932j6dpz88nhhx008b0lv4bah9mqm0";
19+ };
20+ unpackPhase = "";
21+ });
1122in
1223
1324stdenv.mkDerivation rec {
@@ -19,10 +30,29 @@ stdenv.mkDerivation rec {
1930 sha256 = "10ddp1365rf0z4bs7yzc9hajisp3j6mzjshyd0vpi4ki126j5f3r";
2031 };
2132
22− buildInputs = [ qtbase qtscript qtquickcontrols qtdeclarative ];
33+ buildInputs = [ qtbase qtscript qtquickcontrols qtdeclarative llvmPackages_8.libclang clang_qt_vendor llvmPackages_8.llvm ];
2334
2435 nativeBuildInputs = [ qmake makeWrapper ];
2536
37+ # 0001-Fix-clang-libcpp-regexp.patch is for fixing regexp that is used to
38+ # find clang libc++ library include paths. By default it's not covering paths
39+ # like libc++-version, which is default name for libc++ folder in nixos.
40+ patches = [ ./0001-Fix-clang-libcpp-regexp.patch
41+
42+ # Fix clazy plugin name. This plugin was renamed with clang8
43+ # release, and patch didn't make it into 4.9.1 release. Should be removed
44+ # on qtcreator update, if this problem is fixed.
45+ (fetchpatch {
46+ url = "https://code.qt.io/cgit/qt-creator/qt-creator.git/patch/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp?id=53c407bc0c87e0b65b537bf26836ddd8e00ead82";
47+ sha256 = "1lanp7jg0x8jffajb852q8p4r34facg41l410xsz6s1k91jskbi9";
48+ })
49+
50+ (fetchpatch {
51+ url = "https://code.qt.io/cgit/qt-creator/qt-creator.git/patch/src/plugins/clangtools/clangtidyclazyrunner.cpp?id=53c407bc0c87e0b65b537bf26836ddd8e00ead82";
52+ sha256 = "1rl0rc2l297lpfhhawvkkmj77zb081hhp0bbi7nnykf3q9ch0clh";
53+ })
54+ ];
55+
2656 doCheck = true;
2757
2858 enableParallelBuilding = true;
@@ -34,6 +64,20 @@ stdenv.mkDerivation rec {
3464 preConfigure = ''
3565 substituteInPlace src/plugins/plugins.pro \
3666 --replace '$$[QT_INSTALL_QML]/QtQuick/Controls' '${qtquickcontrols}/${qtbase.qtQmlPrefix}/QtQuick/Controls'
67+
68+ # Fix paths for llvm/clang includes directories.
69+ substituteInPlace src/shared/clang/clang_defines.pri \
70+ --replace '$$clean_path($${LLVM_LIBDIR}/clang/$${LLVM_VERSION}/include)' '${clang_qt_vendor}/lib/clang/8.0.0/include' \
71+ --replace '$$clean_path($${LLVM_BINDIR})' '${clang_qt_vendor}/bin'
72+
73+ # Fix include path to find clang and clang-c include directories.
74+ substituteInPlace src/plugins/clangtools/clangtools.pro \
75+ --replace 'INCLUDEPATH += $$LLVM_INCLUDEPATH' 'INCLUDEPATH += $$LLVM_INCLUDEPATH ${clang_qt_vendor}'
76+
77+ # Fix paths to libclang library.
78+ substituteInPlace src/shared/clang/clang_installation.pri \
79+ --replace 'LIBCLANG_LIBS = -L$${LLVM_LIBDIR}' 'LIBCLANG_LIBS = -L${llvmPackages_8.libclang}/lib' \
80+ --replace 'LIBCLANG_LIBS += $${CLANG_LIB}' 'LIBCLANG_LIBS += -lclang'
3781 '';
3882
3983 preBuild = optional withDocumentation ''