author | wenzelm |
Wed, 09 Apr 2025 22:29:11 +0200 | |
changeset 82467 | b0740dce1f1d |
parent 82465 | 3cc075052033 |
child 82468 | 40a609d67b33 |
permissions | -rw-r--r-- |
72421 | 1 |
/* Title: Pure/System/mingw.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Support for MSYS2/MinGW64 on Windows. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
75393 | 10 |
object MinGW { |
82465 | 11 |
def env_prefix(pre_path: String = "", post_path: String = ""): String = { |
12 |
val path = |
|
13 |
if_proper(pre_path, pre_path + ":") + "/usr/bin:/bin:/mingw64/bin" + |
|
14 |
if_proper(post_path, ":" + post_path) |
|
15 |
Bash.exports("PATH=" + path, "CONFIG_SITE=/mingw64/etc/config.site") |
|
16 |
} |
|
72421 | 17 |
|
72424 | 18 |
val none: MinGW = new MinGW(None) |
72431 | 19 |
def apply(path: Path) = new MinGW(Some(path)) |
72424 | 20 |
} |
21 |
||
75393 | 22 |
class MinGW private(val root: Option[Path]) { |
72424 | 23 |
override def toString: String = |
24 |
root match { |
|
25 |
case None => "MinGW.none" |
|
72431 | 26 |
case Some(msys_root) => "MinGW(" + msys_root.toString + ")" |
72424 | 27 |
} |
72421 | 28 |
|
82463
3125fd1ee69c
added option -G to build GMP library from sources;
wenzelm
parents:
75393
diff
changeset
|
29 |
def standard_path(path: Path): String = |
3125fd1ee69c
added option -G to build GMP library from sources;
wenzelm
parents:
75393
diff
changeset
|
30 |
root match { |
3125fd1ee69c
added option -G to build GMP library from sources;
wenzelm
parents:
75393
diff
changeset
|
31 |
case Some(msys_root) if Platform.is_windows => |
3125fd1ee69c
added option -G to build GMP library from sources;
wenzelm
parents:
75393
diff
changeset
|
32 |
val command_line = |
3125fd1ee69c
added option -G to build GMP library from sources;
wenzelm
parents:
75393
diff
changeset
|
33 |
java.util.List.of( |
3125fd1ee69c
added option -G to build GMP library from sources;
wenzelm
parents:
75393
diff
changeset
|
34 |
File.platform_path(msys_root) + "\\usr\\bin\\cygpath", "-u", File.platform_path(path)) |
3125fd1ee69c
added option -G to build GMP library from sources;
wenzelm
parents:
75393
diff
changeset
|
35 |
val res = isabelle.setup.Environment.exec_process(command_line, null, null, false) |
3125fd1ee69c
added option -G to build GMP library from sources;
wenzelm
parents:
75393
diff
changeset
|
36 |
if (res.ok) Library.trim_line(res.out) |
3125fd1ee69c
added option -G to build GMP library from sources;
wenzelm
parents:
75393
diff
changeset
|
37 |
else error("Error: " + quote(Library.trim_line(res.err))) |
3125fd1ee69c
added option -G to build GMP library from sources;
wenzelm
parents:
75393
diff
changeset
|
38 |
case _ => File.standard_path(path) |
3125fd1ee69c
added option -G to build GMP library from sources;
wenzelm
parents:
75393
diff
changeset
|
39 |
} |
3125fd1ee69c
added option -G to build GMP library from sources;
wenzelm
parents:
75393
diff
changeset
|
40 |
|
82465 | 41 |
def bash_script(script: String, env_prefix: String = MinGW.env_prefix()): String = |
72424 | 42 |
root match { |
72428 | 43 |
case None => script |
72424 | 44 |
case Some(msys_root) => |
45 |
File.bash_path(msys_root + Path.explode("usr/bin/bash")) + |
|
82465 | 46 |
" -c " + Bash.string(env_prefix + script) |
72424 | 47 |
} |
72421 | 48 |
|
72424 | 49 |
def get_root: Path = |
50 |
if (!Platform.is_windows) error("Windows platform required") |
|
72425 | 51 |
else if (root.isEmpty) error("Windows platform requires msys/mingw root specification") |
72424 | 52 |
else root.get |
72421 | 53 |
|
82467
b0740dce1f1d
clarified signature: fewer warnings in IntelliJ IDEA;
wenzelm
parents:
82465
diff
changeset
|
54 |
def check(): Unit = { |
72424 | 55 |
if (Platform.is_windows) { |
56 |
get_root |
|
72428 | 57 |
try { require(Isabelle_System.bash(bash_script("uname -s")).check.out.startsWith("MSYS")) } |
72432 | 58 |
catch { case ERROR(msg) => cat_error("Bad msys/mingw installation " + get_root, msg) } |
72421 | 59 |
} |
60 |
} |
|
61 |
} |