author | wenzelm |
Thu, 28 Mar 2024 11:35:39 +0100 | |
changeset 80049 | b525f783b784 |
parent 80048 | a213dd3c0b29 |
child 80050 | 7d8a24c5559d |
permissions | -rw-r--r-- |
80002
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Pure/Admin/component_bash_process.scala |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
3 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
4 |
Build bash_process component from C source. |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
5 |
*/ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
6 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
8 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
9 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
10 |
object Component_Bash_Process { |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
11 |
/* build bash_process */ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
12 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
13 |
def build_bash_process( |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
14 |
progress: Progress = new Progress, |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
15 |
target_dir: Path = Path.current, |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
16 |
): Unit = { |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
17 |
Isabelle_System.require_command("cc") |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
18 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
19 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
20 |
/* component */ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
21 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
22 |
val component_date = Date.Format.alt_date(Date.now()) |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
23 |
val component_name = "bash_process-" + component_date |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
24 |
val component_dir = |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
25 |
Components.Directory(target_dir + Path.basic(component_name)).create(progress = progress) |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
26 |
|
80048 | 27 |
component_dir.write_platforms() |
28 |
||
80002
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
29 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
30 |
/* platform */ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
31 |
|
80049 | 32 |
val platform_name = Isabelle_Platform.self.ISABELLE_PLATFORM(apple = true) |
80002
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
33 |
val platform_dir = |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
34 |
Isabelle_System.make_directory(component_dir.path + Path.basic(platform_name)) |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
35 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
36 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
37 |
/* source */ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
38 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
39 |
val source_file = Path.explode("bash_process.c") |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
40 |
File.write(component_dir.path + source_file, |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
41 |
"""/* Author: Makarius |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
42 |
License: Isabelle BSD-3 |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
43 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
44 |
Bash process with separate process group id. |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
45 |
*/ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
46 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
47 |
#include <signal.h> |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
48 |
#include <stdio.h> |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
49 |
#include <stdlib.h> |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
50 |
#include <string.h> |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
51 |
#include <sys/resource.h> |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
52 |
#include <sys/time.h> |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
53 |
#include <sys/types.h> |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
54 |
#include <sys/wait.h> |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
55 |
#include <time.h> |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
56 |
#include <unistd.h> |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
57 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
58 |
static void fail(const char *msg) |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
59 |
{ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
60 |
fprintf(stderr, "%s\n", msg); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
61 |
fflush(stderr); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
62 |
exit(2); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
63 |
} |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
64 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
65 |
static time_t now() |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
66 |
{ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
67 |
struct timeval tv; |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
68 |
if (gettimeofday(&tv, NULL) == 0) { |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
69 |
return tv.tv_sec * 1000 + tv.tv_usec / 1000; |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
70 |
} |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
71 |
else { |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
72 |
return time(NULL) * 1000; |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
73 |
} |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
74 |
} |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
75 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
76 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
77 |
int main(int argc, char *argv[]) |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
78 |
{ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
79 |
/* args */ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
80 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
81 |
if (argc < 2) { |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
82 |
fprintf(stderr, "Bad arguments: missing TIMING_FILE\n"); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
83 |
fflush(stderr); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
84 |
exit(1); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
85 |
} |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
86 |
char *timing_name = argv[1]; |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
87 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
88 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
89 |
/* potential fork */ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
90 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
91 |
time_t time_start = now(); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
92 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
93 |
if (strlen(timing_name) > 0 || setsid() == -1) { |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
94 |
pid_t pid = fork(); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
95 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
96 |
if (pid == -1) fail("Cannot set session id (failed to fork)"); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
97 |
else if (pid != 0) { |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
98 |
int status; |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
99 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
100 |
// ingore SIGINT |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
101 |
struct sigaction sa; |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
102 |
memset(&sa, 0, sizeof(sa)); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
103 |
sa.sa_handler = SIG_IGN; |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
104 |
sigaction(SIGINT, &sa, 0); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
105 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
106 |
if (waitpid(pid, &status, 0) == -1) { |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
107 |
fail("Cannot join forked process"); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
108 |
} |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
109 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
110 |
/* report timing */ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
111 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
112 |
if (strlen(timing_name) > 0) { |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
113 |
long long timing_elapsed = now() - time_start; |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
114 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
115 |
struct rusage ru; |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
116 |
getrusage(RUSAGE_CHILDREN, &ru); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
117 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
118 |
long long timing_cpu = |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
119 |
ru.ru_utime.tv_sec * 1000 + ru.ru_utime.tv_usec / 1000 + |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
120 |
ru.ru_stime.tv_sec * 1000 + ru.ru_stime.tv_usec / 1000; |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
121 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
122 |
FILE *timing_file = fopen(timing_name, "w"); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
123 |
if (timing_file == NULL) fail("Cannot open timing file"); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
124 |
fprintf(timing_file, "%lld %lld", timing_elapsed, timing_cpu); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
125 |
fclose(timing_file); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
126 |
} |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
127 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
128 |
if (WIFEXITED(status)) { |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
129 |
exit(WEXITSTATUS(status)); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
130 |
} |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
131 |
else if (WIFSIGNALED(status)) { |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
132 |
exit(128 + WTERMSIG(status)); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
133 |
} |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
134 |
else { |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
135 |
fail("Unknown status of forked process"); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
136 |
} |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
137 |
} |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
138 |
else if (setsid() == -1) fail("Cannot set session id (after fork)"); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
139 |
} |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
140 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
141 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
142 |
/* report pid */ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
143 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
144 |
fprintf(stdout, "%d\n", getpid()); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
145 |
fflush(stdout); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
146 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
147 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
148 |
/* shift command line */ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
149 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
150 |
int i; |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
151 |
for (i = 2; i < argc; i++) { |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
152 |
argv[i - 2] = argv[i]; |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
153 |
} |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
154 |
argv[argc - 2] = NULL; |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
155 |
argv[argc - 1] = NULL; |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
156 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
157 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
158 |
/* exec */ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
159 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
160 |
execvp("bash", argv); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
161 |
fail("Cannot exec process"); |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
162 |
} |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
163 |
""") |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
164 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
165 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
166 |
/* build */ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
167 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
168 |
progress.echo("Building bash_process for " + platform_name + " ...") |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
169 |
progress.bash("cc ../bash_process.c -o bash_process", cwd = platform_dir.file).check |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
170 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
171 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
172 |
/* settings */ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
173 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
174 |
component_dir.write_settings(""" |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
175 |
ISABELLE_BASH_PROCESS_HOME="$COMPONENT" |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
176 |
ISABELLE_BASH_PROCESS="$ISABELLE_BASH_PROCESS_HOME/${ISABELLE_APPLE_PLATFORM64:-$ISABELLE_PLATFORM64}/bash_process" |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
177 |
""") |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
178 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
179 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
180 |
/* README */ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
181 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
182 |
File.write(component_dir.README, |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
183 |
"""The bash_process executable has been built like this: |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
184 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
185 |
cc -Wall bash_process.c -o bash_process |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
186 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
187 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
188 |
Makarius |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
189 |
""" + Date.Format.date(Date.now()) + "\n") |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
190 |
} |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
191 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
192 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
193 |
/* Isabelle tool wrapper */ |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
194 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
195 |
val isabelle_tool = |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
196 |
Isabelle_Tool("component_bash_process", "build bash_process component from C source", |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
197 |
Scala_Project.here, |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
198 |
{ args => |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
199 |
var target_dir = Path.current |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
200 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
201 |
val getopts = Getopts(""" |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
202 |
Usage: isabelle component_bash_process [OPTIONS] |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
203 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
204 |
Options are: |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
205 |
-D DIR target directory (default ".") |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
206 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
207 |
Build prover component from official download. |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
208 |
""", |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
209 |
"D:" -> (arg => target_dir = Path.explode(arg))) |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
210 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
211 |
val more_args = getopts(args) |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
212 |
if (more_args.nonEmpty) getopts.usage() |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
213 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
214 |
val progress = new Console_Progress() |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
215 |
|
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
216 |
build_bash_process(progress = progress, target_dir = target_dir) |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
217 |
}) |
ee449ca91c3b
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
wenzelm
parents:
diff
changeset
|
218 |
} |