author | wenzelm |
Sun, 13 Apr 2025 12:23:48 +0200 | |
changeset 82497 | b7554954d697 |
parent 82480 | 489f4a79d215 |
child 82498 | 6fda350c3726 |
permissions | -rw-r--r-- |
72448 | 1 |
/* Title: Pure/System/executable.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Support for platform-specific executables. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
75393 | 10 |
object Executable { |
82480
489f4a79d215
more robust access to GMP library that is provided here;
wenzelm
parents:
80224
diff
changeset
|
11 |
def library_path_variable(platform: Isabelle_Platform): String = |
489f4a79d215
more robust access to GMP library that is provided here;
wenzelm
parents:
80224
diff
changeset
|
12 |
if (platform.is_linux) "LD_LIBRARY_PATH" |
489f4a79d215
more robust access to GMP library that is provided here;
wenzelm
parents:
80224
diff
changeset
|
13 |
else if (platform.is_macos) "DYLD_LIBRARY_PATH" |
489f4a79d215
more robust access to GMP library that is provided here;
wenzelm
parents:
80224
diff
changeset
|
14 |
else if (platform.is_windows) "PATH" |
489f4a79d215
more robust access to GMP library that is provided here;
wenzelm
parents:
80224
diff
changeset
|
15 |
else error("Bad platform " + platform) |
489f4a79d215
more robust access to GMP library that is provided here;
wenzelm
parents:
80224
diff
changeset
|
16 |
|
72460 | 17 |
def libraries_closure(path: Path, |
82480
489f4a79d215
more robust access to GMP library that is provided here;
wenzelm
parents:
80224
diff
changeset
|
18 |
env_prefix: String = "", |
72454 | 19 |
mingw: MinGW = MinGW.none, |
79499
d117821a5e82
always use patchelf on Linux: base-line is Ubuntu 18.04 where that works properly (see also e79294c4230c);
wenzelm
parents:
78773
diff
changeset
|
20 |
filter: String => Boolean = _ => true |
75393 | 21 |
): List[String] = { |
72460 | 22 |
val exe_path = path.expand |
72454 | 23 |
val exe_dir = exe_path.dir |
24 |
val exe = exe_path.base |
|
72448 | 25 |
|
75393 | 26 |
val ldd_lines = { |
72454 | 27 |
val ldd = if (Platform.is_macos) "otool -L" else "ldd" |
82480
489f4a79d215
more robust access to GMP library that is provided here;
wenzelm
parents:
80224
diff
changeset
|
28 |
val script = mingw.bash_script(env_prefix + ldd + " " + File.bash_path(exe)) |
80224
db92e0b6a11a
clarified signature: prefer symbolic isabelle.Path over physical java.io.File;
wenzelm
parents:
79499
diff
changeset
|
29 |
split_lines(Isabelle_System.bash(script, cwd = exe_dir).check.out) |
72448 | 30 |
} |
31 |
||
72454 | 32 |
def lib_name(lib: String): String = |
72468 | 33 |
Library.take_prefix[Char](c => c != '.' && c != '-', |
72454 | 34 |
Library.take_suffix[Char](_ != '/', lib.toList)._2)._1.mkString |
35 |
||
36 |
val libs = |
|
37 |
if (Platform.is_macos) { |
|
38 |
val Pattern = """^\s*(/.+)\s+\(.*\)$""".r |
|
39 |
for { |
|
78592 | 40 |
case Pattern(lib) <- ldd_lines |
72454 | 41 |
if !lib.startsWith("@executable_path/") && filter(lib_name(lib)) |
42 |
} yield lib |
|
43 |
} |
|
44 |
else { |
|
45 |
val Pattern = """^.*=>\s*(/.+)\s+\(.*\)$""".r |
|
78592 | 46 |
for { case Pattern(lib) <- ldd_lines if filter(lib_name(lib)) } |
82497
b7554954d697
more accurate MinGW path conversion: support locations outside of mingw.root;
wenzelm
parents:
82480
diff
changeset
|
47 |
yield File.standard_path(mingw.platform_path(lib)) |
72454 | 48 |
} |
49 |
||
50 |
if (libs.nonEmpty) { |
|
73317 | 51 |
libs.foreach(lib => Isabelle_System.copy_file(Path.explode(lib), exe_dir)) |
72454 | 52 |
|
53 |
if (Platform.is_linux) { |
|
79499
d117821a5e82
always use patchelf on Linux: base-line is Ubuntu 18.04 where that works properly (see also e79294c4230c);
wenzelm
parents:
78773
diff
changeset
|
54 |
Isabelle_System.require_command("patchelf") |
d117821a5e82
always use patchelf on Linux: base-line is Ubuntu 18.04 where that works properly (see also e79294c4230c);
wenzelm
parents:
78773
diff
changeset
|
55 |
Isabelle_System.bash("patchelf --force-rpath --set-rpath '$ORIGIN' " + File.bash_path(exe_path)).check |
72454 | 56 |
} |
57 |
else if (Platform.is_macos) { |
|
58 |
val script = |
|
59 |
("install_name_tool" :: |
|
60 |
libs.map(file => "-change " + Bash.string(file) + " " + |
|
61 |
Bash.string("@executable_path/" + Path.explode(file).file_name) + " " + |
|
62 |
File.bash_path(exe))).mkString(" ") |
|
80224
db92e0b6a11a
clarified signature: prefer symbolic isabelle.Path over physical java.io.File;
wenzelm
parents:
79499
diff
changeset
|
63 |
Isabelle_System.bash(script, cwd = exe_dir).check |
72448 | 64 |
} |
65 |
} |
|
72454 | 66 |
|
67 |
libs |
|
72448 | 68 |
} |
69 |
} |