aboutsummaryrefslogtreecommitdiff
path: root/devel/coccinelle/files/0001-Fix-263-wrong-default-path-for-COCCINELLE_HOME.patch
blob: 098ac1583b51ea2863ab8d00db4f0b5aa349e10f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
From 540888ff426e0b1f7907b63ce26e712d1fc172cc Mon Sep 17 00:00:00 2001
Message-Id: <540888ff426e0b1f7907b63ce26e712d1fc172cc.1660153142.git.osandov@osandov.com>
From: Thierry Martinez <Thierry.Martinez@inria.fr>
Date: Mon, 7 Feb 2022 11:24:49 +0100
Subject: [PATCH] Fix 263: wrong default path for COCCINELLE_HOME

COCCINELLE_HOME is the directory where standard.iso is looked for.
If COCCINELLE_HOME is not defined, we consider the directory $bindir
where the current executable is. If $bindir/standard.iso exists,
we use COCCINELLE_HOME=$bindir (this is a usual case during
development, where we run spatch.opt from the working directory of the
repository).

Otherwise, we suppose that coccinelle has been installed (make
install), and that standard.iso is installed in $libdir, where
$libdir is $exec_prefix/lib.

Before this commit, we considered wrongly that $exec_prefix was equal
to $bindir, whereas the default value for $bindir is
$exec_prefix/bin. Therefore, we should take for $exec_prefix the
parent directory of $bindir.
---
 globals/config.ml.in | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/globals/config.ml.in b/globals/config.ml.in
index da1e9da4..6505a911 100644
--- a/globals/config.ml.in
+++ b/globals/config.ml.in
@@ -26,15 +26,29 @@ let rec realpath path =
     end
 
 let path =
+  (* COCCINELLE_HOME is the directory where standard.iso is looked for. *)
   try (Sys.getenv "COCCINELLE_HOME")
   with Not_found->
+    (* If COCCINELLE_HOME is not defined, we consider the directory $bindir
+       where the current executable is. *)
     let exec_realpath = realpath Sys.executable_name in
-    let exec_dir = Filename.dirname exec_realpath in
-    if Sys.file_exists (Filename.concat exec_dir "standard.iso") then
-      exec_dir
+    let bin_dir = Filename.dirname exec_realpath in
+    if Sys.file_exists (Filename.concat bin_dir "standard.iso") then
+       (* If $bindir/standard.iso exists,
+          we use COCCINELLE_HOME=$bindir (this is a usual case during
+          development, where we run spatch.opt from the working directory
+          of the repository). *)
+      bin_dir
     else
+      (* Otherwise, we suppose that coccinelle has been installed (make
+         install), and that standard.iso is installed in $libdir, where
+         $libdir is $exec_prefix/lib.
+         The default value for $bindir is $exec_prefix/bin.
+         Therefore, we should take for $exec_prefix the parent directory
+         of $bindir.*)
       let libdir =
-        Str.global_replace (Str.regexp "[$]{exec_prefix}") exec_dir "@libdir@"
+        Str.global_replace (Str.regexp "[$]{exec_prefix}")
+          (Filename.dirname bin_dir) "@libdir@"
       in
       Filename.concat libdir "coccinelle"
 
-- 
2.37.1