Subject: Add Sourcetrail

From: phodina <[email-masked]>
Date: Fri, 02 Dec 2022 07:18:38 +0000

Hello,

these patches add Sourcetrail code analysis tool, which unfortunately is not longer developed.

----
Petr

From 2c2b9856f3b5af00d2d3c4c2c569ef830219c1bc Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Thu, 11 Nov 2021 19:19:18 +0100
Subject: [PATCH 1/2] gnu: Add boost-for-sourcetrail.

* gnu/packages/boost.scm (boost-for-sourcetrail): New variable.
* gnu/packages/patches/boost-fix-icu-build.patch: New file.
* gnu/local.mk: Add patch.

diff --git a/gnu/packages/boost.scm b/gnu/packages/boost.scm
index 40e4ca399e..a3899d0419 100644
--- a/gnu/packages/boost.scm
+++ b/gnu/packages/boost.scm
@@ -303,6 +303,86 @@ (define-public boost-static
                    (symlink libboost_pythonNN.a "libboost_python.a"))
                  #t)))))))))
 
+(define-public boost-for-sourcetrail
+  ;; Older version for Sourcetrail 1.1.30.
+  (package
+    (name "boost")
+    (version "1.67.0")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append
+                    "mirror://sourceforge/boost/boost/" version "/boost_"
+                    (string-map (lambda (x) (if (eq? x #\.) #\_ x)) version)
+                    ".tar.bz2"))
+              (sha256
+               (base32
+                "1fmdlmkzsrd46wwk834jsi2ypxj68w2by0rfcg2pzrafk5rck116"))
+              (patches (search-patches "boost-fix-icu-build.patch"))))
+    (build-system gnu-build-system)
+    (inputs `(("icu4c" ,icu4c)
+              ("zlib" ,zlib)))
+    (native-inputs
+     `(("perl" ,perl)
+       ("python" ,python-2)
+       ("tcsh" ,tcsh)))
+    (arguments
+     `(#:tests? #f
+       #:make-flags
+       (list "threading=multi" "link=shared"
+
+             ;; Set the RUNPATH to $libdir so that the libs find each other.
+             (string-append "linkflags=-Wl,-rpath="
+                            (assoc-ref %outputs "out") "/lib")
+
+             ;; Boost's 'context' library is not yet supported on mips64, so
+             ;; we disable it.  The 'coroutine' library depends on 'context',
+             ;; so we disable that too.
+             ,@(if (string-prefix? "mips64" (or (%current-target-system)
+                                                (%current-system)))
+                   '("--without-context"
+                     "--without-coroutine" "--without-coroutine2")
+                   '()))
+       #:phases
+       (modify-phases %standard-phases
+         (delete 'bootstrap)
+         (replace 'configure
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let ((icu (assoc-ref inputs "icu4c"))
+                   (out (assoc-ref outputs "out")))
+               (substitute* '("libs/config/configure"
+                              "libs/spirit/classic/phoenix/test/runtest.sh"
+                              "tools/build/doc/bjam.qbk"
+                              "tools/build/src/engine/execunix.c"
+                              "tools/build/src/engine/Jambase"
+                              "tools/build/src/engine/jambase.c")
+                 (("/bin/sh") (which "sh")))
+
+               (setenv "SHELL" (which "sh"))
+               (setenv "CONFIG_SHELL" (which "sh"))
+
+               (invoke "./bootstrap.sh"
+                       (string-append "--prefix=" out)
+                       ;; Auto-detection looks for ICU only in traditional
+                       ;; install locations.
+                       (string-append "--with-icu=" icu)
+                       "--with-toolset=gcc"))))
+         (replace 'build
+           (lambda* (#:key make-flags #:allow-other-keys)
+             (apply invoke "./b2"
+                    (format #f "-j~a" (parallel-job-count))
+                    make-flags)))
+         (replace 'install
+           (lambda* (#:key make-flags #:allow-other-keys)
+             (apply invoke "./b2" "install" make-flags))))))
+
+    (home-page "http://www.boost.org")
+    (synopsis "Peer-reviewed portable C++ source libraries")
+    (description
+     "A collection of libraries intended to be widely useful, and usable
+across a broad spectrum of applications.")
+    (license (license:x11-style "http://www.boost.org/LICENSE_1_0.txt"
+                                "Some components have other similar licences."))))
+
 (define-public boost-for-mysql
   ;; Older version for MySQL 5.7.23.
   (package
diff --git a/gnu/packages/patches/boost-fix-icu-build.patch b/gnu/packages/patches/boost-fix-icu-build.patch
new file mode 100644
index 0000000000..556f91b8f7
--- /dev/null
+++ b/gnu/packages/patches/boost-fix-icu-build.patch
@@ -0,0 +1,53 @@
+Pass -std=c++11 when compiling files that include the ICU headers.  Without
+this flag, compilation fails and causes Boost's build system to remove ICU
+support.  Note that $(pkg-config --variable=CXXFLAGS icu-uc) includes
+"-std=c++11", but Boost's build system does not use 'pkg-config'.
+
+--- boost_1_66_0/libs/locale/build/Jamfile.v2.orig	2017-12-13 18:56:44.000000000 -0500
++++ boost_1_66_0/libs/locale/build/Jamfile.v2	2018-04-08 15:18:58.673025760 -0400
+@@ -65,8 +65,8 @@
+ 
+ if $(ICU_LINK)
+ {
+-    ICU_OPTS = <include>$(ICU_PATH)/include <linkflags>$(ICU_LINK) <dll-path>$(ICU_PATH)/bin <runtime-link>shared ;
+-    ICU64_OPTS = <include>$(ICU_PATH)/include <linkflags>$(ICU_LINK) <dll-path>$(ICU_PATH)/bin64 <runtime-link>shared ;
++    ICU_OPTS = <include>$(ICU_PATH)/include <cxxflags>-std=c++11 <linkflags>$(ICU_LINK) <dll-path>$(ICU_PATH)/bin <runtime-link>shared ;
++    ICU64_OPTS = <include>$(ICU_PATH)/include <cxxflags>-std=c++11 <linkflags>$(ICU_LINK) <dll-path>$(ICU_PATH)/bin64 <runtime-link>shared ;
+ }
+ else
+ {
+@@ -121,6 +121,7 @@
+     explicit icuuc icudt icuin ;
+ 
+     ICU_OPTS =   <include>$(ICU_PATH)/include 
++      <cxxflags>-std=c++11
+       <library>icuuc/<link>shared/<runtime-link>shared 
+       <library>icudt/<link>shared/<runtime-link>shared 
+       <library>icuin/<link>shared/<runtime-link>shared
+@@ -180,6 +181,7 @@
+     explicit icuuc_64 icudt_64 icuin_64 ;
+ 
+     ICU64_OPTS =   <include>$(ICU_PATH)/include 
++      <cxxflags>-std=c++11
+       <library>icuuc_64/<link>shared/<runtime-link>shared 
+       <library>icudt_64/<link>shared/<runtime-link>shared 
+       <library>icuin_64/<link>shared/<runtime-link>shared
+--- boost_1_66_0/libs/regex/build/Jamfile.v2.orig	2017-12-13 18:56:48.000000000 -0500
++++ boost_1_66_0/libs/regex/build/Jamfile.v2	2018-04-08 15:20:40.865532505 -0400
+@@ -44,7 +44,7 @@
+ 
+    if $(ICU_LINK)
+    {
+-      ICU_OPTS = <include>$(ICU_PATH)/include <linkflags>$(ICU_LINK) <dll-path>$(ICU_PATH)/bin <define>BOOST_HAS_ICU=1 <runtime-link>shared ;
++      ICU_OPTS = <include>$(ICU_PATH)/include <cxxflags>-std=c++11 <linkflags>$(ICU_LINK) <dll-path>$(ICU_PATH)/bin <define>BOOST_HAS_ICU=1 <runtime-link>shared ;
+    }
+    else
+    {
+@@ -78,6 +78,7 @@
+ 
+       ICU_OPTS = 
+          <include>$(ICU_PATH)/include 
++         <cxxflags>-std=c++11
+          <runtime-link>shared:<library>icuuc/<link>shared
+          <runtime-link>shared:<library>icudt/<link>shared
+          <runtime-link>shared:<library>icuin/<link>shared
-- 
2.38.1

From 015a65f27f46bbdad3e07dbabc5154609ae6ec2d Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Thu, 11 Nov 2021 19:21:44 +0100
Subject: [PATCH 2/2] gnu: Add sourcetrail.

* gnu/packages/qt.scm (sourcetrail): New variable.

diff --git a/gnu/packages/qt.scm b/gnu/packages/qt.scm
index 30bf429897..540959bbbc 100644
--- a/gnu/packages/qt.scm
+++ b/gnu/packages/qt.scm
@@ -62,6 +62,7 @@ (define-module (gnu packages qt)
   #:use-module (gnu packages base)
   #:use-module (gnu packages bison)
   #:use-module (gnu packages check)
+  #:use-module (gnu packages boost)
   #:use-module (gnu packages cmake)
   #:use-module (gnu packages compression)
   #:use-module (gnu packages cups)
@@ -4261,6 +4262,46 @@ (define-public qhexedit
 data.")
     (license license:lgpl2.1)))
 
+(define-public sourcetrail
+(package
+  (name "sourcetrail")
+  (version "2021.1.30")
+  (source (origin
+            (method git-fetch)
+            (uri (git-reference
+             (url "https://github.com/CoatiSoftware/Sourcetrail")
+             (commit version)))
+            (file-name (git-file-name name version))
+            (sha256
+             (base32
+              "0h0q2bfa6dv8hmc15rzj48bna1krzjwlcjm25dffbsi81xjcazb5"))))
+  (build-system cmake-build-system)
+  (arguments
+    (list #:configure-flags #~(list "-DBoost_USE_STATIC_LIBS=OFF" (string-append
+	"-DBOOST_ROOT=" #$(this-package-input "boost") "/lib"))
+      #:phases
+      #~(modify-phases %standard-phases
+       (replace 'install
+        (lambda* (#:key outputs #:allow-other-keys)
+		 (let* ((out #$output)
+		       (prefix (string-append out "/opt/sourcetrail"))
+			   (build (getcwd))
+			   (share (string-append prefix "/share")))
+		       (mkdir-p (string-append out "/bin"))
+			   (install-file (string-append build "/app/Sourcetrail") (string-append
+			   out "/bin"))
+			   (install-file (string-append build
+			   "/app/sourcetrail_indexer") (string-append
+			   out "/bin"))))))))
+  (native-inputs (list pkg-config))
+  (inputs (list boost-for-sourcetrail
+            qtbase-5
+            qtsvg-5))
+  (synopsis "Interactive source explorer")
+  (description "Offline source explorer that helps you get productive on unfamiliar source code with optional IDE integration.")
+  (home-page "https://www.sourcetrail.com")
+  (license license:gpl3)))
+
 (define-public soqt
   (let ((commit-ref "fb8f655632bb9c9c60e0ff9fa69a5ba22d3ff99d")
         (revision "1"))
-- 
2.38.1