src/Pure/System/bash.ML
author wenzelm
Sat, 20 Feb 2021 22:09:16 +0100
changeset 73263 ad60214bef09
parent 73244 5bded25065f8
permissions -rw-r--r--
more uniform Bash.process: always ask Isabelle/Scala;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
62584
6cd36a0d2a28 clarified files;
wenzelm
parents: 62569
diff changeset
     1
(*  Title:      Pure/System/bash.ML
40748
591b6778d076 removed bash from ML system bootstrap, and past the Secure ML barrier;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
591b6778d076 removed bash from ML system bootstrap, and past the Secure ML barrier;
wenzelm
parents:
diff changeset
     3
62879
4764473c9b8d back to static conditional compilation -- simplified bootstrap;
wenzelm
parents: 62850
diff changeset
     4
GNU bash processes, with propagation of interrupts -- POSIX version.
40748
591b6778d076 removed bash from ML system bootstrap, and past the Secure ML barrier;
wenzelm
parents:
diff changeset
     5
*)
591b6778d076 removed bash from ML system bootstrap, and past the Secure ML barrier;
wenzelm
parents:
diff changeset
     6
44054
da5fcc0f6c52 proper signature;
wenzelm
parents: 43850
diff changeset
     7
signature BASH =
da5fcc0f6c52 proper signature;
wenzelm
parents: 43850
diff changeset
     8
sig
64304
96bc94c87a81 clarified modules;
wenzelm
parents: 62923
diff changeset
     9
  val string: string -> string
96bc94c87a81 clarified modules;
wenzelm
parents: 62923
diff changeset
    10
  val strings: string list -> string
73263
ad60214bef09 more uniform Bash.process: always ask Isabelle/Scala;
wenzelm
parents: 73244
diff changeset
    11
  val process: string -> {out: string, err: string, rc: int}
44054
da5fcc0f6c52 proper signature;
wenzelm
parents: 43850
diff changeset
    12
end;
da5fcc0f6c52 proper signature;
wenzelm
parents: 43850
diff changeset
    13
62911
78e03d8bf1c4 back to dynamic conditional compilation (reverting 4764473c9b8d) via recursive ML name space;
wenzelm
parents: 62891
diff changeset
    14
structure Bash: BASH =
78e03d8bf1c4 back to dynamic conditional compilation (reverting 4764473c9b8d) via recursive ML name space;
wenzelm
parents: 62891
diff changeset
    15
struct
78e03d8bf1c4 back to dynamic conditional compilation (reverting 4764473c9b8d) via recursive ML name space;
wenzelm
parents: 62891
diff changeset
    16
64304
96bc94c87a81 clarified modules;
wenzelm
parents: 62923
diff changeset
    17
val string = Bash_Syntax.string;
96bc94c87a81 clarified modules;
wenzelm
parents: 62923
diff changeset
    18
val strings = Bash_Syntax.strings;
96bc94c87a81 clarified modules;
wenzelm
parents: 62923
diff changeset
    19
73263
ad60214bef09 more uniform Bash.process: always ask Isabelle/Scala;
wenzelm
parents: 73244
diff changeset
    20
fun process script =
73244
5bded25065f8 more parallelism: avoid exhaustion of standard thread pool;
wenzelm
parents: 73234
diff changeset
    21
  Scala.function_thread "bash_process"
73229
5be512af2a86 inherit ISABELLE_TMP from ML process, e.g. required for $AFP/Hello_World/RunningCodeFromIsabelle.thy;
wenzelm
parents: 73228
diff changeset
    22
    ("export ISABELLE_TMP=" ^ string (getenv "ISABELLE_TMP") ^ "\n" ^ script)
73228
0575cfd2ecfc support multi-threaded Bash.process invocation on Apple Silicon, where Poly/ML is running on Rosetta 2;
wenzelm
parents: 73227
diff changeset
    23
  |> YXML.parse_body
0575cfd2ecfc support multi-threaded Bash.process invocation on Apple Silicon, where Poly/ML is running on Rosetta 2;
wenzelm
parents: 73227
diff changeset
    24
  |>
0575cfd2ecfc support multi-threaded Bash.process invocation on Apple Silicon, where Poly/ML is running on Rosetta 2;
wenzelm
parents: 73227
diff changeset
    25
    let open XML.Decode in
0575cfd2ecfc support multi-threaded Bash.process invocation on Apple Silicon, where Poly/ML is running on Rosetta 2;
wenzelm
parents: 73227
diff changeset
    26
      variant
0575cfd2ecfc support multi-threaded Bash.process invocation on Apple Silicon, where Poly/ML is running on Rosetta 2;
wenzelm
parents: 73227
diff changeset
    27
       [fn ([], []) => raise Exn.Interrupt,
73230
d1bc5a376cf9 more robust: allow YXML text;
wenzelm
parents: 73229
diff changeset
    28
        fn ([], a) => error (YXML.string_of_body a),
73263
ad60214bef09 more uniform Bash.process: always ask Isabelle/Scala;
wenzelm
parents: 73244
diff changeset
    29
        fn ([a], c) =>
73228
0575cfd2ecfc support multi-threaded Bash.process invocation on Apple Silicon, where Poly/ML is running on Rosetta 2;
wenzelm
parents: 73227
diff changeset
    30
          let
0575cfd2ecfc support multi-threaded Bash.process invocation on Apple Silicon, where Poly/ML is running on Rosetta 2;
wenzelm
parents: 73227
diff changeset
    31
            val rc = int_atom a;
73230
d1bc5a376cf9 more robust: allow YXML text;
wenzelm
parents: 73229
diff changeset
    32
            val (out, err) = pair I I c |> apply2 YXML.string_of_body;
73263
ad60214bef09 more uniform Bash.process: always ask Isabelle/Scala;
wenzelm
parents: 73244
diff changeset
    33
          in {out = out, err = err, rc = rc} end]
73228
0575cfd2ecfc support multi-threaded Bash.process invocation on Apple Silicon, where Poly/ML is running on Rosetta 2;
wenzelm
parents: 73227
diff changeset
    34
    end;
0575cfd2ecfc support multi-threaded Bash.process invocation on Apple Silicon, where Poly/ML is running on Rosetta 2;
wenzelm
parents: 73227
diff changeset
    35
43850
7f2cbc713344 moved bash operations to Isabelle_System (cf. Scala version);
wenzelm
parents: 43847
diff changeset
    36
end;