src/Pure/Admin/component_bash_process.scala
author wenzelm
Tue, 26 Mar 2024 11:15:48 +0100
changeset 80002 ee449ca91c3b
child 80048 a213dd3c0b29
permissions -rw-r--r--
build bash_process in Isabelle/Scala, with etc/platforms.prop to preserve all platform directories (e.g. for SSH upload);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
    27
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
    28
    /* 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
    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
    val 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
    31
      proper_string(Isabelle_System.getenv("ISABELLE_APPLE_PLATFORM64")) orElse
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
    32
      proper_string(Isabelle_System.getenv("ISABELLE_PLATFORM64")) getOrElse
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
      error("Missing ISABELLE_PLATFORM64")
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
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
    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
    36
      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
    37
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
    /* 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
    40
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
    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
    42
    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
    43
"""/*  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
    44
    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
    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
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
    47
*/
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
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 <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
    50
#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
    51
#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
    52
#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
    53
#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
    54
#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
    55
#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
    56
#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
    57
#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
    58
#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
    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
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
    61
{
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
  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
    63
  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
    64
  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
    65
}
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
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
    68
{
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
  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
    70
  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
    71
    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
    72
  }
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
  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
    74
    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
    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
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
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
    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
  /* 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
    82
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
  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
    84
    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
    85
    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
    86
    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
    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
  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
    89
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
  /* 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
    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
  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
    94
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
  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
    96
    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
    97
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
    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
    99
    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
   100
      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
   101
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
      // 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
   103
      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
   104
      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
   105
      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
   106
      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
   107
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
      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
   109
        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
   110
      }
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
      /* 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
   113
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
      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
   115
        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
   116
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
        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
   118
        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
   119
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
        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
   121
          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
   122
          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
   123
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
        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
   125
        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
   126
        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
   127
        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
   128
      }
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
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
      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
   131
        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
   132
      }
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
      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
   134
        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
   135
      }
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
      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
   137
        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
   138
      }
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
    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
   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
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
  /* 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
   145
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
  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
   147
  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
   148
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
  /* 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
   151
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
  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
   153
  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
   154
    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
   155
  }
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
  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
   157
  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
   158
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
  /* 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
   161
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
  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
   163
  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
   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
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
    /* 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
   169
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
    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
   171
    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
   172
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
    /* 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
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
    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
   177
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
   178
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
   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
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
    /* platform.props */
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
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
    File.write(component_dir.platform_props,
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
      Platform.Family.list.map(family => family.toString + " = ").mkString("", "\n", "\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
   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
    /* 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
   189
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
    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
   191
"""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
   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
  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
   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
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
        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
   197
        """ + 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
   198
}
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
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
  /* 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
   202
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
  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
   204
    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
   205
      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
   206
      { 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
   207
        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
   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
        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
   210
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
   211
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
  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
   213
    -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
   214
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
  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
   216
""",
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
          "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
   218
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
   219
        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
   220
        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
   221
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
   222
        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
   223
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
   224
        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
   225
      })
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
   226
}