src/Pure/Tools/build.scala
author wenzelm
Fri Jan 19 14:55:46 2018 +0100 (16 months ago)
changeset 67471 bddfa23a4ea9
parent 67380 8bef51521f21
child 67493 c4e9e0c50487
permissions -rw-r--r--
formal treatment of documentation names;
wenzelm@50686
     1
/*  Title:      Pure/Tools/build.scala
wenzelm@48276
     2
    Author:     Makarius
wenzelm@57923
     3
    Options:    :folding=explicit:
wenzelm@48276
     4
wenzelm@48276
     5
Build and manage Isabelle sessions.
wenzelm@48276
     6
*/
wenzelm@48276
     7
wenzelm@48276
     8
package isabelle
wenzelm@48276
     9
wenzelm@48276
    10
wenzelm@48548
    11
import java.io.{BufferedInputStream, FileInputStream,
wenzelm@48494
    12
  BufferedReader, InputStreamReader, IOException}
wenzelm@48494
    13
import java.util.zip.GZIPInputStream
wenzelm@48335
    14
wenzelm@48676
    15
import scala.collection.SortedSet
wenzelm@51397
    16
import scala.collection.mutable
wenzelm@48340
    17
import scala.annotation.tailrec
wenzelm@48337
    18
wenzelm@48335
    19
wenzelm@48276
    20
object Build
wenzelm@48276
    21
{
wenzelm@62631
    22
  /** auxiliary **/
wenzelm@48424
    23
wenzelm@65291
    24
  /* persistent build info */
wenzelm@65291
    25
wenzelm@65291
    26
  sealed case class Session_Info(
wenzelm@66749
    27
    sources: String,
wenzelm@65291
    28
    input_heaps: List[String],
wenzelm@65291
    29
    output_heap: Option[String],
wenzelm@65291
    30
    return_code: Int)
wenzelm@66747
    31
  {
wenzelm@66747
    32
    def ok: Boolean = return_code == 0
wenzelm@66747
    33
  }
wenzelm@65291
    34
wenzelm@65291
    35
wenzelm@65289
    36
  /* queue with scheduling information */
wenzelm@48676
    37
wenzelm@62631
    38
  private object Queue
wenzelm@48676
    39
  {
wenzelm@65831
    40
    def load_timings(progress: Progress, store: Sessions.Store, name: String)
wenzelm@65831
    41
      : (List[Properties.T], Double) =
wenzelm@65289
    42
    {
wenzelm@65291
    43
      val no_timings: (List[Properties.T], Double) = (Nil, 0.0)
wenzelm@65289
    44
wenzelm@65291
    45
      store.find_database(name) match {
wenzelm@65291
    46
        case None => no_timings
wenzelm@65291
    47
        case Some(database) =>
wenzelm@65291
    48
          def ignore_error(msg: String) =
wenzelm@65291
    49
          {
wenzelm@65831
    50
            progress.echo_warning("Ignoring bad database: " +
wenzelm@65365
    51
              database.expand + (if (msg == "") "" else "\n" + msg))
wenzelm@65291
    52
            no_timings
wenzelm@65291
    53
          }
wenzelm@65291
    54
          try {
wenzelm@65291
    55
            using(SQLite.open_database(database))(db =>
wenzelm@65291
    56
            {
wenzelm@65935
    57
              val command_timings = store.read_command_timings(db, name)
wenzelm@65935
    58
              val session_timing =
wenzelm@65935
    59
                store.read_session_timing(db, name) match {
wenzelm@65935
    60
                  case Markup.Elapsed(t) => t
wenzelm@65935
    61
                  case _ => 0.0
wenzelm@65935
    62
                }
wenzelm@65935
    63
              (command_timings, session_timing)
wenzelm@65291
    64
            })
wenzelm@65291
    65
          }
wenzelm@65291
    66
          catch {
wenzelm@65291
    67
            case ERROR(msg) => ignore_error(msg)
wenzelm@65291
    68
            case exn: java.lang.Error => ignore_error(Exn.message(exn))
wenzelm@65291
    69
            case _: XML.Error => ignore_error("")
wenzelm@65291
    70
          }
wenzelm@65289
    71
      }
wenzelm@65289
    72
    }
wenzelm@65289
    73
wenzelm@67052
    74
    def apply(progress: Progress, sessions: Sessions.Structure, store: Sessions.Store): Queue =
wenzelm@48676
    75
    {
wenzelm@65420
    76
      val graph = sessions.build_graph
wenzelm@65415
    77
      val names = graph.keys
wenzelm@51220
    78
wenzelm@65831
    79
      val timings = names.map(name => (name, load_timings(progress, store, name)))
wenzelm@51220
    80
      val command_timings =
wenzelm@51220
    81
        Map(timings.map({ case (name, (ts, _)) => (name, ts) }): _*).withDefaultValue(Nil)
wenzelm@51220
    82
      val session_timing =
wenzelm@51220
    83
        Map(timings.map({ case (name, (_, t)) => (name, t) }): _*).withDefaultValue(0.0)
wenzelm@48678
    84
wenzelm@48678
    85
      def outdegree(name: String): Int = graph.imm_succs(name).size
wenzelm@48678
    86
wenzelm@48678
    87
      object Ordering extends scala.math.Ordering[String]
wenzelm@48678
    88
      {
wenzelm@51227
    89
        def compare_timing(name1: String, name2: String): Int =
wenzelm@51227
    90
        {
wenzelm@51227
    91
          val t1 = session_timing(name1)
wenzelm@51227
    92
          val t2 = session_timing(name2)
wenzelm@51227
    93
          if (t1 == 0.0 || t2 == 0.0) 0
wenzelm@51227
    94
          else t1 compare t2
wenzelm@51227
    95
        }
wenzelm@51227
    96
wenzelm@48678
    97
        def compare(name1: String, name2: String): Int =
wenzelm@51229
    98
          outdegree(name2) compare outdegree(name1) match {
wenzelm@48678
    99
            case 0 =>
wenzelm@51229
   100
              compare_timing(name2, name1) match {
wenzelm@51220
   101
                case 0 =>
wenzelm@65415
   102
                  sessions(name2).timeout compare sessions(name1).timeout match {
wenzelm@51220
   103
                    case 0 => name1 compare name2
wenzelm@51220
   104
                    case ord => ord
wenzelm@51220
   105
                  }
wenzelm@48678
   106
                case ord => ord
wenzelm@48678
   107
              }
wenzelm@48678
   108
            case ord => ord
wenzelm@48678
   109
          }
wenzelm@48678
   110
      }
wenzelm@48678
   111
wenzelm@65415
   112
      new Queue(graph, SortedSet(names: _*)(Ordering), command_timings)
wenzelm@48676
   113
    }
wenzelm@48676
   114
  }
wenzelm@48676
   115
wenzelm@65314
   116
  private class Queue(
wenzelm@62631
   117
    graph: Graph[String, Sessions.Info],
wenzelm@51220
   118
    order: SortedSet[String],
wenzelm@51220
   119
    val command_timings: String => List[Properties.T])
wenzelm@48676
   120
  {
wenzelm@48676
   121
    def is_inner(name: String): Boolean = !graph.is_maximal(name)
wenzelm@48676
   122
wenzelm@48676
   123
    def is_empty: Boolean = graph.is_empty
wenzelm@48676
   124
wenzelm@51227
   125
    def - (name: String): Queue =
wenzelm@51227
   126
      new Queue(graph.del_node(name),
wenzelm@67011
   127
        order - name,  // FIXME scala-2.10.0 .. 2.12.4 TreeSet problem!?
wenzelm@51227
   128
        command_timings)
wenzelm@48676
   129
wenzelm@62631
   130
    def dequeue(skip: String => Boolean): Option[(String, Sessions.Info)] =
wenzelm@48676
   131
    {
wenzelm@51227
   132
      val it = order.iterator.dropWhile(name =>
wenzelm@51227
   133
        skip(name)
wenzelm@67011
   134
          || !graph.defined(name)  // FIXME scala-2.10.0 .. 2.12.4 TreeSet problem!?
wenzelm@51227
   135
          || !graph.is_minimal(name))
wenzelm@48680
   136
      if (it.hasNext) { val name = it.next; Some((name, graph.get_node(name))) }
wenzelm@48676
   137
      else None
wenzelm@48676
   138
    }
wenzelm@48676
   139
  }
wenzelm@48676
   140
wenzelm@48676
   141
wenzelm@65313
   142
  /* PIDE protocol handler */
wenzelm@65313
   143
wenzelm@65313
   144
  class Handler(progress: Progress, session: Session, session_name: String)
wenzelm@65313
   145
    extends Session.Protocol_Handler
wenzelm@65313
   146
  {
wenzelm@65313
   147
    val result_error: Promise[String] = Future.promise
wenzelm@65313
   148
wenzelm@65313
   149
    override def exit() { result_error.cancel }
wenzelm@65313
   150
wenzelm@65313
   151
    private def build_session_finished(msg: Prover.Protocol_Output): Boolean =
wenzelm@65313
   152
    {
wenzelm@65313
   153
      val error_message =
wenzelm@65344
   154
        try { Pretty.string_of(Symbol.decode_yxml(msg.text)) }
wenzelm@65313
   155
        catch { case ERROR(msg) => msg }
wenzelm@65313
   156
      result_error.fulfill(error_message)
wenzelm@65313
   157
      session.send_stop()
wenzelm@65313
   158
      true
wenzelm@65313
   159
    }
wenzelm@65313
   160
wenzelm@65313
   161
    private def loading_theory(msg: Prover.Protocol_Output): Boolean =
wenzelm@65313
   162
      msg.properties match {
wenzelm@65313
   163
        case Markup.Loading_Theory(name) =>
wenzelm@65313
   164
          progress.theory(session_name, name)
wenzelm@65313
   165
          true
wenzelm@65313
   166
        case _ => false
wenzelm@65313
   167
      }
wenzelm@65313
   168
wenzelm@65313
   169
    val functions =
wenzelm@65313
   170
      List(
wenzelm@65313
   171
        Markup.BUILD_SESSION_FINISHED -> build_session_finished _,
wenzelm@65313
   172
        Markup.LOADING_THEORY -> loading_theory _)
wenzelm@65313
   173
  }
wenzelm@65313
   174
wenzelm@65313
   175
wenzelm@65308
   176
  /* job: running prover process */
wenzelm@48341
   177
wenzelm@65308
   178
  private class Job(progress: Progress,
wenzelm@65308
   179
    name: String,
wenzelm@65308
   180
    val info: Sessions.Info,
wenzelm@67052
   181
    sessions: Sessions.Structure,
wenzelm@65313
   182
    deps: Sessions.Deps,
wenzelm@65308
   183
    store: Sessions.Store,
wenzelm@65308
   184
    do_output: Boolean,
wenzelm@65308
   185
    verbose: Boolean,
wenzelm@65308
   186
    pide: Boolean,
wenzelm@65308
   187
    val numa_node: Option[Int],
wenzelm@65308
   188
    command_timings: List[Properties.T])
wenzelm@48418
   189
  {
wenzelm@62633
   190
    val output = store.output_dir + Path.basic(name)
wenzelm@48674
   191
    def output_path: Option[Path] = if (do_output) Some(output) else None
wenzelm@62633
   192
    output.file.delete
wenzelm@48674
   193
wenzelm@65312
   194
    val options =
wenzelm@65312
   195
      numa_node match {
wenzelm@65312
   196
        case None => info.options
wenzelm@65312
   197
        case Some(n) => info.options.string("ML_process_policy") = NUMA.policy(n)
wenzelm@65312
   198
      }
wenzelm@65312
   199
wenzelm@59445
   200
    private val graph_file = Isabelle_System.tmp_file("session_graph", "pdf")
wenzelm@66822
   201
    isabelle.graphview.Graph_File.write(options, graph_file, deps(name).session_graph_display)
wenzelm@59445
   202
wenzelm@62573
   203
    private val future_result: Future[Process_Result] =
wenzelm@61559
   204
      Future.thread("build") {
wenzelm@65308
   205
        val parent = info.parent.getOrElse("")
wenzelm@65441
   206
        val base = deps(name)
wenzelm@65308
   207
        val args_yxml =
wenzelm@65308
   208
          YXML.string_of_body(
wenzelm@62944
   209
            {
wenzelm@62944
   210
              import XML.Encode._
wenzelm@62944
   211
              pair(list(pair(string, int)), pair(list(properties), pair(bool, pair(bool,
wenzelm@62944
   212
                pair(Path.encode, pair(list(pair(Path.encode, Path.encode)), pair(string,
wenzelm@65307
   213
                pair(string, pair(string, pair(string, pair(Path.encode,
wenzelm@65517
   214
                pair(list(pair(Options.encode, list(pair(string, properties)))),
wenzelm@67471
   215
                pair(list(string), pair(list(string), pair(list(pair(string, string)),
wenzelm@67471
   216
                pair(list(string), pair(list(pair(string, string)), list(string))))))))))))))))))(
wenzelm@62944
   217
              (Symbol.codes, (command_timings, (do_output, (verbose,
wenzelm@62944
   218
                (store.browser_info, (info.document_files, (File.standard_path(graph_file),
wenzelm@65307
   219
                (parent, (info.chapter, (name, (Path.current,
wenzelm@67471
   220
                (info.theories, (base.known.sessions.toList, (base.doc_names,
wenzelm@67471
   221
                (base.global_theories.toList, (base.loaded_theories.keys, (base.dest_known_theories,
wenzelm@67471
   222
                info.bibtex_entries.map(_.info)))))))))))))))))))
wenzelm@65308
   223
            })
wenzelm@65308
   224
wenzelm@65308
   225
        val env =
wenzelm@65308
   226
          Isabelle_System.settings() +
wenzelm@65312
   227
            ("ISABELLE_ML_DEBUGGER" -> options.bool("ML_debugger").toString)
wenzelm@65308
   228
wenzelm@65308
   229
        def save_heap: String =
wenzelm@66972
   230
          (if (info.theories.isEmpty) "" else "ML_Heap.share_common_data (); ") +
wenzelm@66972
   231
            "ML_Heap.save_child " + ML_Syntax.print_string_bytes(File.platform_path(output))
wenzelm@62944
   232
wenzelm@65360
   233
        if (pide && !Sessions.is_pure(name)) {
wenzelm@65532
   234
          val resources = new Resources(deps(parent))
wenzelm@65313
   235
          val session = new Session(options, resources)
wenzelm@65313
   236
          val handler = new Handler(progress, session, name)
wenzelm@65315
   237
          session.init_protocol_handler(handler)
wenzelm@65313
   238
wenzelm@65317
   239
          val session_result = Future.promise[Process_Result]
wenzelm@65313
   240
wenzelm@65313
   241
          Isabelle_Process.start(session, options, logic = parent,
wenzelm@65415
   242
            cwd = info.dir.file, env = env, sessions = Some(sessions), store = store,
wenzelm@65313
   243
            phase_changed =
wenzelm@65313
   244
            {
wenzelm@65313
   245
              case Session.Ready => session.protocol_command("build_session", args_yxml)
wenzelm@65317
   246
              case Session.Terminated(result) => session_result.fulfill(result)
wenzelm@65313
   247
              case _ =>
wenzelm@65313
   248
            })
wenzelm@65313
   249
wenzelm@65317
   250
          val result = session_result.join
wenzelm@65313
   251
          handler.result_error.join match {
wenzelm@65317
   252
            case "" => result
wenzelm@65317
   253
            case msg =>
wenzelm@65317
   254
              result.copy(
wenzelm@65317
   255
                rc = result.rc max 1,
wenzelm@65828
   256
                out_lines = result.out_lines ::: split_lines(Output.error_message_text(msg)))
wenzelm@65313
   257
          }
wenzelm@65308
   258
        }
wenzelm@65308
   259
        else {
wenzelm@65308
   260
          val args_file = Isabelle_System.tmp_file("build")
wenzelm@65308
   261
          File.write(args_file, args_yxml)
wenzelm@65308
   262
wenzelm@65308
   263
          val eval =
wenzelm@65308
   264
            "Command_Line.tool0 (fn () => (" +
wenzelm@66782
   265
            "Build.build " + ML_Syntax.print_string_bytes(File.standard_path(args_file)) +
wenzelm@67380
   266
            (if (Sessions.is_pure(name)) "; Theory.install_pure (Thy_Info.get_theory Context.PureN)"
wenzelm@67380
   267
             else "") + (if (do_output) "; " + save_heap else "") + "));"
wenzelm@64265
   268
wenzelm@65308
   269
          val process =
wenzelm@65360
   270
            if (Sessions.is_pure(name)) {
wenzelm@65312
   271
              ML_Process(options, raw_ml_system = true, cwd = info.dir.file,
wenzelm@65308
   272
                args =
wenzelm@65308
   273
                  (for ((root, _) <- Thy_Header.ml_roots) yield List("--use", root)).flatten :::
wenzelm@65308
   274
                  List("--eval", eval),
wenzelm@65415
   275
                env = env, sessions = Some(sessions), store = store,
wenzelm@65415
   276
                cleanup = () => args_file.delete)
wenzelm@65308
   277
            }
wenzelm@65308
   278
            else {
wenzelm@65312
   279
              ML_Process(options, parent, List("--eval", eval), cwd = info.dir.file,
wenzelm@65415
   280
                env = env, sessions = Some(sessions), store = store,
wenzelm@65415
   281
                cleanup = () => args_file.delete)
wenzelm@65308
   282
            }
wenzelm@64265
   283
wenzelm@65308
   284
          process.result(
wenzelm@65308
   285
            progress_stdout = (line: String) =>
wenzelm@65308
   286
              Library.try_unprefix("\floading_theory = ", line) match {
wenzelm@65308
   287
                case Some(theory) => progress.theory(name, theory)
wenzelm@65308
   288
                case None =>
wenzelm@65308
   289
              },
wenzelm@65308
   290
            progress_limit =
wenzelm@65312
   291
              options.int("process_output_limit") match {
wenzelm@65308
   292
                case 0 => None
wenzelm@65308
   293
                case m => Some(m * 1000000L)
wenzelm@65308
   294
              },
wenzelm@65308
   295
            strict = false)
wenzelm@65308
   296
        }
wenzelm@50845
   297
      }
wenzelm@48674
   298
wenzelm@62572
   299
    def terminate: Unit = future_result.cancel
wenzelm@62572
   300
    def is_finished: Boolean = future_result.is_finished
wenzelm@48674
   301
wenzelm@56779
   302
    private val timeout_request: Option[Event_Timer.Request] =
wenzelm@56779
   303
    {
wenzelm@62569
   304
      if (info.timeout > Time.zero)
wenzelm@66943
   305
        Some(Event_Timer.request(Time.now() + info.timeout) { terminate })
wenzelm@48674
   306
      else None
wenzelm@56779
   307
    }
wenzelm@48674
   308
wenzelm@62400
   309
    def join: Process_Result =
wenzelm@50845
   310
    {
wenzelm@62572
   311
      val result = future_result.join
wenzelm@50845
   312
wenzelm@62944
   313
      if (result.ok)
wenzelm@62633
   314
        Present.finish(progress, store.browser_info, graph_file, info, name)
wenzelm@61372
   315
wenzelm@59445
   316
      graph_file.delete
wenzelm@66943
   317
wenzelm@66943
   318
      val was_timeout =
wenzelm@66943
   319
        timeout_request match {
wenzelm@66943
   320
          case None => false
wenzelm@66943
   321
          case Some(request) => !request.cancel
wenzelm@66943
   322
        }
wenzelm@48674
   323
wenzelm@62572
   324
      if (result.interrupted) {
wenzelm@65828
   325
        if (was_timeout) result.error(Output.error_message_text("Timeout")).was_timeout
wenzelm@65828
   326
        else result.error(Output.error_message_text("Interrupt"))
wenzelm@52063
   327
      }
wenzelm@62572
   328
      else result
wenzelm@48674
   329
    }
wenzelm@48364
   330
  }
wenzelm@48364
   331
wenzelm@48424
   332
wenzelm@62631
   333
wenzelm@62641
   334
  /** build with results **/
wenzelm@48424
   335
wenzelm@63996
   336
  class Results private[Build](results: Map[String, (Option[Process_Result], Sessions.Info)])
wenzelm@62403
   337
  {
wenzelm@62403
   338
    def sessions: Set[String] = results.keySet
lars@63082
   339
    def cancelled(name: String): Boolean = results(name)._1.isEmpty
lars@63082
   340
    def apply(name: String): Process_Result = results(name)._1.getOrElse(Process_Result(1))
lars@63082
   341
    def info(name: String): Sessions.Info = results(name)._2
wenzelm@65253
   342
    val rc =
wenzelm@65253
   343
      (0 /: results.iterator.map(
wenzelm@65253
   344
        { case (_, (Some(r), _)) => r.rc case (_, (None, _)) => 1 }))(_ max _)
wenzelm@62641
   345
    def ok: Boolean = rc == 0
wenzelm@62406
   346
wenzelm@62406
   347
    override def toString: String = rc.toString
wenzelm@62403
   348
  }
wenzelm@62403
   349
wenzelm@62641
   350
  def build(
wenzelm@50404
   351
    options: Options,
wenzelm@64909
   352
    progress: Progress = No_Progress,
wenzelm@65832
   353
    check_unknown_files: Boolean = false,
wenzelm@48511
   354
    build_heap: Boolean = false,
wenzelm@48595
   355
    clean_build: Boolean = false,
wenzelm@56890
   356
    dirs: List[Path] = Nil,
wenzelm@56890
   357
    select_dirs: List[Path] = Nil,
wenzelm@66968
   358
    infos: List[Sessions.Info] = Nil,
wenzelm@64265
   359
    numa_shuffling: Boolean = false,
wenzelm@48509
   360
    max_jobs: Int = 1,
wenzelm@48903
   361
    list_files: Boolean = false,
wenzelm@59891
   362
    check_keywords: Set[String] = Set.empty,
wenzelm@66841
   363
    fresh_build: Boolean = false,
wenzelm@48509
   364
    no_build: Boolean = false,
wenzelm@66745
   365
    soft_build: Boolean = false,
wenzelm@48509
   366
    system_mode: Boolean = false,
wenzelm@48509
   367
    verbose: Boolean = false,
wenzelm@65308
   368
    pide: Boolean = false,
wenzelm@63224
   369
    requirements: Boolean = false,
wenzelm@63224
   370
    all_sessions: Boolean = false,
wenzelm@66737
   371
    base_sessions: List[String] = Nil,
wenzelm@63224
   372
    exclude_session_groups: List[String] = Nil,
wenzelm@59892
   373
    exclude_sessions: List[String] = Nil,
wenzelm@63224
   374
    session_groups: List[String] = Nil,
wenzelm@65422
   375
    sessions: List[String] = Nil,
wenzelm@65422
   376
    selection: Sessions.Selection = Sessions.Selection.empty): Results =
wenzelm@63224
   377
  {
wenzelm@66745
   378
    val build_options = options.int.update("completion_limit", 0).bool.update("ML_statistics", true)
wenzelm@51220
   379
wenzelm@66745
   380
    val store = Sessions.store(system_mode)
wenzelm@66745
   381
wenzelm@66745
   382
wenzelm@66745
   383
    /* session selection and dependencies */
wenzelm@65422
   384
wenzelm@66961
   385
    val full_sessions =
wenzelm@67026
   386
      Sessions.load_structure(build_options, dirs = dirs, select_dirs = select_dirs, infos = infos)
wenzelm@65422
   387
wenzelm@66749
   388
    def sources_stamp(deps: Sessions.Deps, name: String): String =
wenzelm@66749
   389
    {
wenzelm@66749
   390
      val digests =
wenzelm@66749
   391
        full_sessions(name).meta_digest :: deps.sources(name) ::: deps.imported_sources(name)
wenzelm@66749
   392
      SHA1.digest(cat_lines(digests.map(_.toString).sorted)).toString
wenzelm@66749
   393
    }
wenzelm@66745
   394
wenzelm@67030
   395
    val selection1 =
wenzelm@67030
   396
      Sessions.Selection(requirements, all_sessions, base_sessions, exclude_session_groups,
wenzelm@67030
   397
        exclude_sessions, session_groups, sessions) ++ selection
wenzelm@67030
   398
wenzelm@67025
   399
    val (selected_sessions, deps) =
wenzelm@66745
   400
    {
wenzelm@67030
   401
      val selected_sessions0 = full_sessions.selection(selection1)
wenzelm@66745
   402
      val deps0 =
wenzelm@66962
   403
        Sessions.deps(selected_sessions0, full_sessions.global_theories,
wenzelm@66962
   404
          progress = progress, inlined_files = true, verbose = verbose,
wenzelm@66962
   405
          list_files = list_files, check_keywords = check_keywords).check_errors
wenzelm@66745
   406
wenzelm@66841
   407
      if (soft_build && !fresh_build) {
wenzelm@66745
   408
        val outdated =
wenzelm@67025
   409
          selected_sessions0.build_topological_order.flatMap(name =>
wenzelm@66745
   410
            store.find_database(name) match {
wenzelm@66745
   411
              case Some(database) =>
wenzelm@66745
   412
                using(SQLite.open_database(database))(store.read_build(_, name)) match {
wenzelm@66745
   413
                  case Some(build)
wenzelm@66747
   414
                  if build.ok && build.sources == sources_stamp(deps0, name) => None
wenzelm@66745
   415
                  case _ => Some(name)
wenzelm@66745
   416
                }
wenzelm@66745
   417
              case None => Some(name)
wenzelm@66745
   418
            })
wenzelm@67025
   419
        val selected_sessions =
wenzelm@66745
   420
          full_sessions.selection(Sessions.Selection(sessions = outdated))
wenzelm@66745
   421
        val deps =
wenzelm@66962
   422
          Sessions.deps(selected_sessions, full_sessions.global_theories, inlined_files = true)
wenzelm@66962
   423
            .check_errors
wenzelm@67025
   424
        (selected_sessions, deps)
wenzelm@66745
   425
      }
wenzelm@67025
   426
      else (selected_sessions0, deps0)
wenzelm@66745
   427
    }
wenzelm@66745
   428
wenzelm@66745
   429
wenzelm@66745
   430
    /* check unknown files */
wenzelm@48504
   431
wenzelm@65832
   432
    if (check_unknown_files) {
wenzelm@65832
   433
      val source_files =
wenzelm@65832
   434
        (for {
wenzelm@65832
   435
          (_, base) <- deps.session_bases.iterator
wenzelm@65832
   436
          (path, _) <- base.sources.iterator
wenzelm@65832
   437
        } yield path).toList
wenzelm@67098
   438
      val exclude_files = List(Path.explode("$POLYML_EXE")).map(_.canonical_file)
wenzelm@67098
   439
      val unknown_files =
wenzelm@67098
   440
        Mercurial.unknown_files(source_files).
wenzelm@67098
   441
          filterNot(path => exclude_files.contains(path.canonical_file))
wenzelm@65832
   442
      if (unknown_files.nonEmpty) {
wenzelm@65832
   443
        progress.echo_warning("Unknown files (not part of a Mercurial repository):" +
wenzelm@65832
   444
          unknown_files.map(path => path.expand.implode).sorted.mkString("\n  ", "\n  ", ""))
wenzelm@65832
   445
      }
wenzelm@65832
   446
    }
wenzelm@65832
   447
wenzelm@51220
   448
wenzelm@51220
   449
    /* main build process */
wenzelm@51220
   450
wenzelm@65831
   451
    val queue = Queue(progress, selected_sessions, store)
wenzelm@65289
   452
wenzelm@62632
   453
    store.prepare_output()
wenzelm@48373
   454
wenzelm@48595
   455
    // optional cleanup
wenzelm@48595
   456
    if (clean_build) {
wenzelm@67030
   457
      for (name <- full_sessions.build_descendants(full_sessions.build_selection(selection1))) {
wenzelm@48595
   458
        val files =
wenzelm@65291
   459
          List(Path.basic(name), store.database(name), store.log(name), store.log_gz(name)).
wenzelm@62632
   460
            map(store.output_dir + _).filter(_.is_file)
wenzelm@59319
   461
        if (files.nonEmpty) progress.echo("Cleaning " + name + " ...")
wenzelm@50366
   462
        if (!files.forall(p => p.file.delete)) progress.echo(name + " FAILED to delete")
wenzelm@48595
   463
      }
wenzelm@48595
   464
    }
wenzelm@48595
   465
wenzelm@48425
   466
    // scheduler loop
lars@63082
   467
    case class Result(
wenzelm@66594
   468
      current: Boolean,
wenzelm@66594
   469
      heap_stamp: Option[String],
wenzelm@66594
   470
      process: Option[Process_Result],
wenzelm@66594
   471
      info: Sessions.Info)
wenzelm@62402
   472
    {
wenzelm@62402
   473
      def ok: Boolean =
wenzelm@62402
   474
        process match {
wenzelm@62402
   475
          case None => false
wenzelm@62402
   476
          case Some(res) => res.rc == 0
wenzelm@62402
   477
        }
wenzelm@62402
   478
    }
wenzelm@48639
   479
wenzelm@56837
   480
    def sleep()
wenzelm@56837
   481
    {
wenzelm@56837
   482
      try { Thread.sleep(500) }
wenzelm@56861
   483
      catch { case Exn.Interrupt() => Exn.Interrupt.impose() }
wenzelm@56837
   484
    }
wenzelm@50366
   485
wenzelm@64265
   486
    val numa_nodes = new NUMA.Nodes(numa_shuffling)
wenzelm@64265
   487
wenzelm@48425
   488
    @tailrec def loop(
wenzelm@48676
   489
      pending: Queue,
wenzelm@62628
   490
      running: Map[String, (List[String], Job)],
wenzelm@48639
   491
      results: Map[String, Result]): Map[String, Result] =
wenzelm@48425
   492
    {
wenzelm@64265
   493
      def used_node(i: Int): Boolean =
wenzelm@64265
   494
        running.iterator.exists(
wenzelm@64265
   495
          { case (_, (_, job)) => job.numa_node.isDefined && job.numa_node.get == i })
wenzelm@64265
   496
wenzelm@48425
   497
      if (pending.is_empty) results
wenzelm@51253
   498
      else {
wenzelm@51253
   499
        if (progress.stopped)
wenzelm@51253
   500
          for ((_, (_, job)) <- running) job.terminate
wenzelm@51253
   501
wenzelm@48674
   502
        running.find({ case (_, (_, job)) => job.is_finished }) match {
wenzelm@62628
   503
          case Some((name, (input_heaps, job))) =>
wenzelm@50367
   504
            //{{{ finish job
wenzelm@48424
   505
wenzelm@62401
   506
            val process_result = job.join
wenzelm@48373
   507
wenzelm@65294
   508
            val log_lines = process_result.out_lines.filterNot(_.startsWith("\f"))
wenzelm@62404
   509
            val process_result_tail =
wenzelm@62404
   510
            {
wenzelm@62409
   511
              val tail = job.info.options.int("process_output_tail")
wenzelm@62632
   512
              process_result.copy(
wenzelm@62632
   513
                out_lines =
wenzelm@65278
   514
                  "(see also " + (store.output_dir + store.log(name)).file.toString + ")" ::
wenzelm@65294
   515
                  (if (tail == 0) log_lines else log_lines.drop(log_lines.length - tail max 0)))
wenzelm@62404
   516
            }
wenzelm@62404
   517
wenzelm@66666
   518
wenzelm@66666
   519
            // write log file
wenzelm@62636
   520
            val heap_stamp =
wenzelm@62401
   521
              if (process_result.ok) {
wenzelm@65278
   522
                (store.output_dir + store.log(name)).file.delete
wenzelm@62636
   523
                val heap_stamp =
wenzelm@62704
   524
                  for (path <- job.output_path if path.is_file)
wenzelm@62704
   525
                    yield Sessions.write_heap_digest(path)
wenzelm@48639
   526
wenzelm@65294
   527
                File.write_gzip(store.output_dir + store.log_gz(name), terminate_lines(log_lines))
wenzelm@48639
   528
wenzelm@62636
   529
                heap_stamp
wenzelm@48639
   530
              }
wenzelm@48639
   531
              else {
wenzelm@62632
   532
                (store.output_dir + Path.basic(name)).file.delete
wenzelm@65278
   533
                (store.output_dir + store.log_gz(name)).file.delete
wenzelm@48639
   534
wenzelm@65294
   535
                File.write(store.output_dir + store.log(name), terminate_lines(log_lines))
wenzelm@48639
   536
wenzelm@62636
   537
                None
wenzelm@48639
   538
              }
wenzelm@65291
   539
wenzelm@65291
   540
            // write database
wenzelm@65291
   541
            {
wenzelm@65291
   542
              val database = store.output_dir + store.database(name)
wenzelm@65291
   543
              database.file.delete
wenzelm@65291
   544
wenzelm@66944
   545
              val build_log =
wenzelm@66944
   546
                Build_Log.Log_File(name, process_result.out_lines).
wenzelm@66944
   547
                  parse_session_info(
wenzelm@66944
   548
                    command_timings = true,
wenzelm@66944
   549
                    theory_timings = true,
wenzelm@66944
   550
                    ml_statistics = true,
wenzelm@66944
   551
                    task_statistics = true)
wenzelm@66944
   552
wenzelm@65291
   553
              using(SQLite.open_database(database))(db =>
wenzelm@65318
   554
                store.write_session_info(db, name,
wenzelm@65291
   555
                  build_log =
wenzelm@66944
   556
                    if (process_result.timeout) build_log.error("Timeout") else build_log,
wenzelm@65291
   557
                  build =
wenzelm@66746
   558
                    Session_Info(sources_stamp(deps, name), input_heaps, heap_stamp,
wenzelm@66744
   559
                      process_result.rc)))
wenzelm@65291
   560
            }
wenzelm@65291
   561
wenzelm@66666
   562
            // messages
wenzelm@66666
   563
            process_result.err_lines.foreach(progress.echo(_))
wenzelm@66666
   564
wenzelm@66666
   565
            if (process_result.ok)
wenzelm@66666
   566
              progress.echo("Finished " + name + " (" + process_result.timing.message_resources + ")")
wenzelm@66666
   567
            else {
wenzelm@66666
   568
              progress.echo(name + " FAILED")
wenzelm@66666
   569
              if (!process_result.interrupted) progress.echo(process_result_tail.out)
wenzelm@66666
   570
            }
wenzelm@66666
   571
wenzelm@50707
   572
            loop(pending - name, running - name,
lars@63082
   573
              results + (name -> Result(false, heap_stamp, Some(process_result_tail), job.info)))
wenzelm@50367
   574
            //}}}
wenzelm@60215
   575
          case None if running.size < (max_jobs max 1) =>
wenzelm@50367
   576
            //{{{ check/start next job
wenzelm@48547
   577
            pending.dequeue(running.isDefinedAt(_)) match {
wenzelm@48547
   578
              case Some((name, info)) =>
wenzelm@66848
   579
                val ancestor_results =
wenzelm@66848
   580
                  selected_sessions.build_requirements(List(name)).filterNot(_ == name).
wenzelm@66848
   581
                    map(results(_))
wenzelm@62636
   582
                val ancestor_heaps = ancestor_results.flatMap(_.heap_stamp)
wenzelm@62628
   583
wenzelm@65360
   584
                val do_output = build_heap || Sessions.is_pure(name) || queue.is_inner(name)
wenzelm@48547
   585
wenzelm@62636
   586
                val (current, heap_stamp) =
wenzelm@48547
   587
                {
wenzelm@65291
   588
                  store.find_database_heap(name) match {
wenzelm@65291
   589
                    case Some((database, heap_stamp)) =>
wenzelm@65320
   590
                      using(SQLite.open_database(database))(store.read_build(_, name)) match {
wenzelm@65291
   591
                        case Some(build) =>
wenzelm@62628
   592
                          val current =
wenzelm@66841
   593
                            !fresh_build &&
wenzelm@66747
   594
                            build.ok &&
wenzelm@66745
   595
                            build.sources == sources_stamp(deps, name) &&
wenzelm@65291
   596
                            build.input_heaps == ancestor_heaps &&
wenzelm@65291
   597
                            build.output_heap == heap_stamp &&
wenzelm@66595
   598
                            !(do_output && heap_stamp.isEmpty)
wenzelm@62636
   599
                          (current, heap_stamp)
wenzelm@62636
   600
                        case None => (false, None)
wenzelm@48547
   601
                      }
wenzelm@62636
   602
                    case None => (false, None)
wenzelm@48504
   603
                  }
wenzelm@48547
   604
                }
wenzelm@62628
   605
                val all_current = current && ancestor_results.forall(_.current)
wenzelm@48528
   606
wenzelm@48547
   607
                if (all_current)
wenzelm@62402
   608
                  loop(pending - name, running,
lars@63082
   609
                    results + (name -> Result(true, heap_stamp, Some(Process_Result(0)), info)))
wenzelm@48678
   610
                else if (no_build) {
wenzelm@50366
   611
                  if (verbose) progress.echo("Skipping " + name + " ...")
wenzelm@62402
   612
                  loop(pending - name, running,
lars@63082
   613
                    results + (name -> Result(false, heap_stamp, Some(Process_Result(1)), info)))
wenzelm@48678
   614
                }
wenzelm@62628
   615
                else if (ancestor_results.forall(_.ok) && !progress.stopped) {
wenzelm@64265
   616
                  val numa_node = numa_nodes.next(used_node(_))
wenzelm@50366
   617
                  progress.echo((if (do_output) "Building " else "Running ") + name + " ...")
wenzelm@51220
   618
                  val job =
wenzelm@65415
   619
                    new Job(progress, name, info, selected_sessions, deps, store, do_output,
wenzelm@65415
   620
                      verbose, pide, numa_node, queue.command_timings(name))
wenzelm@62628
   621
                  loop(pending, running + (name -> (ancestor_heaps, job)), results)
wenzelm@48547
   622
                }
wenzelm@48547
   623
                else {
wenzelm@50366
   624
                  progress.echo(name + " CANCELLED")
wenzelm@65253
   625
                  loop(pending - name, running,
wenzelm@65253
   626
                    results + (name -> Result(false, heap_stamp, None, info)))
wenzelm@48547
   627
                }
wenzelm@48547
   628
              case None => sleep(); loop(pending, running, results)
wenzelm@48425
   629
            }
wenzelm@50367
   630
            ///}}}
wenzelm@48425
   631
          case None => sleep(); loop(pending, running, results)
wenzelm@48373
   632
        }
wenzelm@51253
   633
      }
wenzelm@48425
   634
    }
wenzelm@48425
   635
wenzelm@51220
   636
wenzelm@51220
   637
    /* build results */
wenzelm@51220
   638
wenzelm@62641
   639
    val results0 =
wenzelm@48583
   640
      if (deps.is_empty) {
wenzelm@65827
   641
        progress.echo_warning("Nothing to build")
wenzelm@50707
   642
        Map.empty[String, Result]
wenzelm@48583
   643
      }
wenzelm@48583
   644
      else loop(queue, Map.empty, Map.empty)
wenzelm@48583
   645
wenzelm@62641
   646
    val results =
wenzelm@64265
   647
      new Results(
wenzelm@64265
   648
        (for ((name, result) <- results0.iterator)
wenzelm@64265
   649
          yield (name, (result.process, result.info))).toMap)
wenzelm@62641
   650
wenzelm@62641
   651
    if (results.rc != 0 && (verbose || !no_build)) {
wenzelm@62641
   652
      val unfinished =
wenzelm@62641
   653
        (for {
wenzelm@62641
   654
          name <- results.sessions.iterator
wenzelm@62641
   655
          if !results(name).ok
wenzelm@62641
   656
         } yield name).toList.sorted
wenzelm@62641
   657
      progress.echo("Unfinished session(s): " + commas(unfinished))
wenzelm@62641
   658
    }
wenzelm@62641
   659
wenzelm@51418
   660
wenzelm@51418
   661
    /* global browser info */
wenzelm@51418
   662
wenzelm@51418
   663
    if (!no_build) {
wenzelm@51418
   664
      val browser_chapters =
wenzelm@51418
   665
        (for {
wenzelm@62641
   666
          (name, result) <- results0.iterator
wenzelm@62944
   667
          if result.ok
wenzelm@65415
   668
          info = full_sessions(name)
wenzelm@51418
   669
          if info.options.bool("browser_info")
wenzelm@51418
   670
        } yield (info.chapter, (name, info.description))).toList.groupBy(_._1).
wenzelm@51418
   671
            map({ case (chapter, es) => (chapter, es.map(_._2)) }).filterNot(_._2.isEmpty)
wenzelm@51418
   672
wenzelm@51418
   673
      for ((chapter, entries) <- browser_chapters)
wenzelm@62632
   674
        Present.update_chapter_index(store.browser_info, chapter, entries)
wenzelm@51418
   675
wenzelm@62632
   676
      if (browser_chapters.nonEmpty) Present.make_global_index(store.browser_info)
wenzelm@51418
   677
    }
wenzelm@51418
   678
wenzelm@62641
   679
    results
wenzelm@48341
   680
  }
wenzelm@48341
   681
wenzelm@48341
   682
wenzelm@62833
   683
  /* Isabelle tool wrapper */
wenzelm@48341
   684
wenzelm@62833
   685
  val isabelle_tool = Isabelle_Tool("build", "build and manage Isabelle sessions", args =>
wenzelm@48341
   686
  {
wenzelm@62833
   687
    val build_options = Word.explode(Isabelle_System.getenv("ISABELLE_BUILD_OPTIONS"))
wenzelm@62590
   688
wenzelm@66737
   689
    var base_sessions: List[String] = Nil
wenzelm@62833
   690
    var select_dirs: List[Path] = Nil
wenzelm@64265
   691
    var numa_shuffling = false
wenzelm@65308
   692
    var pide = false
wenzelm@62833
   693
    var requirements = false
wenzelm@66745
   694
    var soft_build = false
wenzelm@62833
   695
    var exclude_session_groups: List[String] = Nil
wenzelm@62833
   696
    var all_sessions = false
wenzelm@62833
   697
    var build_heap = false
wenzelm@62833
   698
    var clean_build = false
wenzelm@62833
   699
    var dirs: List[Path] = Nil
wenzelm@66841
   700
    var fresh_build = false
wenzelm@62833
   701
    var session_groups: List[String] = Nil
wenzelm@62833
   702
    var max_jobs = 1
wenzelm@62833
   703
    var check_keywords: Set[String] = Set.empty
wenzelm@62833
   704
    var list_files = false
wenzelm@62833
   705
    var no_build = false
wenzelm@62833
   706
    var options = (Options.init() /: build_options)(_ + _)
wenzelm@62833
   707
    var system_mode = false
wenzelm@62833
   708
    var verbose = false
wenzelm@62833
   709
    var exclude_sessions: List[String] = Nil
wenzelm@62590
   710
wenzelm@62833
   711
    val getopts = Getopts("""
wenzelm@62590
   712
Usage: isabelle build [OPTIONS] [SESSIONS ...]
wenzelm@62590
   713
wenzelm@62590
   714
  Options are:
wenzelm@66737
   715
    -B NAME      include session NAME and all descendants
wenzelm@62590
   716
    -D DIR       include session directory and select its sessions
wenzelm@64265
   717
    -N           cyclic shuffling of NUMA CPU nodes (performance tuning)
wenzelm@65308
   718
    -P           build via PIDE protocol
wenzelm@62590
   719
    -R           operate on requirements of selected sessions
wenzelm@66745
   720
    -S           soft build: only observe changes of sources, not heap images
wenzelm@62590
   721
    -X NAME      exclude sessions from group NAME and all descendants
wenzelm@62590
   722
    -a           select all sessions
wenzelm@62590
   723
    -b           build heap images
wenzelm@62590
   724
    -c           clean build
wenzelm@62590
   725
    -d DIR       include session directory
wenzelm@66841
   726
    -f           fresh build
wenzelm@62590
   727
    -g NAME      select session group NAME
wenzelm@62590
   728
    -j INT       maximum number of parallel jobs (default 1)
wenzelm@62590
   729
    -k KEYWORD   check theory sources for conflicts with proposed keywords
wenzelm@62590
   730
    -l           list session source files
wenzelm@62590
   731
    -n           no build -- test dependencies only
wenzelm@62590
   732
    -o OPTION    override Isabelle system OPTION (via NAME=VAL or NAME)
wenzelm@62590
   733
    -s           system build mode: produce output in ISABELLE_HOME
wenzelm@62590
   734
    -v           verbose
wenzelm@62590
   735
    -x NAME      exclude session NAME and all descendants
wenzelm@62590
   736
wenzelm@62596
   737
  Build and manage Isabelle sessions, depending on implicit settings:
wenzelm@62596
   738
wenzelm@64455
   739
""" + Library.prefix_lines("  ", Build_Log.Settings.show()) + "\n",
wenzelm@66737
   740
      "B:" -> (arg => base_sessions = base_sessions ::: List(arg)),
wenzelm@62833
   741
      "D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))),
wenzelm@64265
   742
      "N" -> (_ => numa_shuffling = true),
wenzelm@65308
   743
      "P" -> (_ => pide = true),
wenzelm@62833
   744
      "R" -> (_ => requirements = true),
wenzelm@66745
   745
      "S" -> (_ => soft_build = true),
wenzelm@62833
   746
      "X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)),
wenzelm@62833
   747
      "a" -> (_ => all_sessions = true),
wenzelm@62833
   748
      "b" -> (_ => build_heap = true),
wenzelm@62833
   749
      "c" -> (_ => clean_build = true),
wenzelm@62833
   750
      "d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))),
wenzelm@66841
   751
      "f" -> (_ => fresh_build = true),
wenzelm@62833
   752
      "g:" -> (arg => session_groups = session_groups ::: List(arg)),
wenzelm@63805
   753
      "j:" -> (arg => max_jobs = Value.Int.parse(arg)),
wenzelm@62833
   754
      "k:" -> (arg => check_keywords = check_keywords + arg),
wenzelm@62833
   755
      "l" -> (_ => list_files = true),
wenzelm@62833
   756
      "n" -> (_ => no_build = true),
wenzelm@62833
   757
      "o:" -> (arg => options = options + arg),
wenzelm@62833
   758
      "s" -> (_ => system_mode = true),
wenzelm@62833
   759
      "v" -> (_ => verbose = true),
wenzelm@62833
   760
      "x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg)))
wenzelm@62590
   761
wenzelm@62833
   762
    val sessions = getopts(args)
wenzelm@62590
   763
wenzelm@64115
   764
    val progress = new Console_Progress(verbose = verbose)
wenzelm@62590
   765
wenzelm@64140
   766
    val start_date = Date.now()
wenzelm@64140
   767
wenzelm@62833
   768
    if (verbose) {
wenzelm@62833
   769
      progress.echo(
wenzelm@64155
   770
        "Started at " + Build_Log.print_date(start_date) +
wenzelm@64140
   771
          " (" + Isabelle_System.getenv("ML_IDENTIFIER") + " on " + Isabelle_System.hostname() +")")
wenzelm@64081
   772
      progress.echo(Build_Log.Settings.show() + "\n")
wenzelm@62833
   773
    }
wenzelm@62590
   774
wenzelm@62833
   775
    val results =
wenzelm@62833
   776
      progress.interrupt_handler {
wenzelm@63224
   777
        build(options, progress,
wenzelm@65832
   778
          check_unknown_files = Mercurial.is_repository(Path.explode("~~")),
wenzelm@63224
   779
          build_heap = build_heap,
wenzelm@63224
   780
          clean_build = clean_build,
wenzelm@63224
   781
          dirs = dirs,
wenzelm@63224
   782
          select_dirs = select_dirs,
wenzelm@65831
   783
          numa_shuffling = NUMA.enabled_warning(progress, numa_shuffling),
wenzelm@63224
   784
          max_jobs = max_jobs,
wenzelm@63224
   785
          list_files = list_files,
wenzelm@63224
   786
          check_keywords = check_keywords,
wenzelm@66841
   787
          fresh_build = fresh_build,
wenzelm@63224
   788
          no_build = no_build,
wenzelm@66745
   789
          soft_build = soft_build,
wenzelm@63224
   790
          system_mode = system_mode,
wenzelm@63224
   791
          verbose = verbose,
wenzelm@65308
   792
          pide = pide,
wenzelm@63224
   793
          requirements = requirements,
wenzelm@63224
   794
          all_sessions = all_sessions,
wenzelm@66737
   795
          base_sessions = base_sessions,
wenzelm@63224
   796
          exclude_session_groups = exclude_session_groups,
wenzelm@63224
   797
          exclude_sessions = exclude_sessions,
wenzelm@63224
   798
          session_groups = session_groups,
wenzelm@63224
   799
          sessions = sessions)
wenzelm@62833
   800
      }
wenzelm@64140
   801
    val end_date = Date.now()
wenzelm@64140
   802
    val elapsed_time = end_date.time - start_date.time
wenzelm@62590
   803
wenzelm@62833
   804
    if (verbose) {
wenzelm@64155
   805
      progress.echo("\nFinished at " + Build_Log.print_date(end_date))
wenzelm@62833
   806
    }
wenzelm@62590
   807
wenzelm@62833
   808
    val total_timing =
wenzelm@62833
   809
      (Timing.zero /: results.sessions.iterator.map(a => results(a).timing))(_ + _).
wenzelm@62833
   810
        copy(elapsed = elapsed_time)
wenzelm@62833
   811
    progress.echo(total_timing.message_resources)
wenzelm@62590
   812
wenzelm@62833
   813
    sys.exit(results.rc)
wenzelm@62833
   814
  })
wenzelm@48276
   815
}