src/Pure/Tools/build.scala
author wenzelm
Sat, 01 Jul 2023 16:42:57 +0200
changeset 78237 c2c59de57df9
parent 78233 1a12e6246212
child 78280 865b44cbaad1
permissions -rw-r--r--
clarified static Build_Process.Context vs. dynamic Build_Process.State; more dynamic Build_Process.Sessions, to accomodate multiple workers (and multiple builds);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50686
d703e3aafa8c moved files;
wenzelm
parents: 50566
diff changeset
     1
/*  Title:      Pure/Tools/build.scala
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
57923
cdae2467311d tuned comments;
wenzelm
parents: 56890
diff changeset
     3
    Options:    :folding=explicit:
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     4
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
     5
Command-line tools to build and manage Isabelle sessions.
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     6
*/
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     7
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     8
package isabelle
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     9
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
    10
import scala.collection.mutable
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
    11
import scala.util.matching.Regex
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
    12
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    13
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74845
diff changeset
    14
object Build {
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
    15
  /** "isabelle build" **/
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
    16
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    17
  /* options */
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    18
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    19
  def hostname(options: Options): String =
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    20
    Isabelle_System.hostname(options.string("build_hostname"))
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    21
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    22
  def engine_name(options: Options): String = options.string("build_engine")
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    23
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    24
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    25
77330
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
    26
  /* results */
48424
wenzelm
parents: 48423
diff changeset
    27
77311
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    28
  object Results {
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    29
    def apply(context: Build_Process.Context, results: Map[String, Process_Result]): Results =
77453
e72b1f5fd88d tuned signature;
wenzelm
parents: 77411
diff changeset
    30
      new Results(context.store, context.build_deps, results)
77311
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    31
  }
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    32
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    33
  class Results private(
78178
a177f71dc79f clarified modules;
wenzelm
parents: 77719
diff changeset
    34
    val store: Store,
76209
365f6a621fc5 clarified signature;
wenzelm
parents: 76206
diff changeset
    35
    val deps: Sessions.Deps,
77253
792dad9cb04f clarified data structure: absorb Option[Process_Result] into Process_Result, e.g. to simplify database storage;
wenzelm
parents: 77252
diff changeset
    36
    results: Map[String, Process_Result]
76198
fb4215da4919 clarified presentation_sessions: work with partial results;
wenzelm
parents: 76197
diff changeset
    37
  ) {
76206
769a7cd5a16a clarified signature: re-use store/cache from build results;
wenzelm
parents: 76202
diff changeset
    38
    def cache: Term.Cache = store.cache
769a7cd5a16a clarified signature: re-use store/cache from build results;
wenzelm
parents: 76202
diff changeset
    39
77311
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    40
    def sessions_ok: List[String] =
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    41
      (for {
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    42
        name <- deps.sessions_structure.build_topological_order.iterator
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    43
        result <- results.get(name) if result.ok
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    44
      } yield name).toList
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    45
77250
22016642d6af clarified data structure: use static info from deps, not dynamic results;
wenzelm
parents: 77246
diff changeset
    46
    def info(name: String): Sessions.Info = deps.sessions_structure(name)
62403
1d7aba20a332 explicit class Build_Results;
wenzelm
parents: 62402
diff changeset
    47
    def sessions: Set[String] = results.keySet
77253
792dad9cb04f clarified data structure: absorb Option[Process_Result] into Process_Result, e.g. to simplify database storage;
wenzelm
parents: 77252
diff changeset
    48
    def cancelled(name: String): Boolean = !results(name).defined
792dad9cb04f clarified data structure: absorb Option[Process_Result] into Process_Result, e.g. to simplify database storage;
wenzelm
parents: 77252
diff changeset
    49
    def apply(name: String): Process_Result = results(name).strict
792dad9cb04f clarified data structure: absorb Option[Process_Result] into Process_Result, e.g. to simplify database storage;
wenzelm
parents: 77252
diff changeset
    50
    val rc: Int = results.valuesIterator.map(_.strict.rc).foldLeft(Process_Result.RC.ok)(_ max _)
74306
a117c076aa22 clarified signature;
wenzelm
parents: 73826
diff changeset
    51
    def ok: Boolean = rc == Process_Result.RC.ok
62406
b5b8fb87447a tuned signature;
wenzelm
parents: 62405
diff changeset
    52
76202
d535db35388e proper filter (amending fb4215da4919);
wenzelm
parents: 76201
diff changeset
    53
    def unfinished: List[String] = sessions.iterator.filterNot(apply(_).ok).toList.sorted
76199
6bf42525f111 tuned signature;
wenzelm
parents: 76198
diff changeset
    54
62406
b5b8fb87447a tuned signature;
wenzelm
parents: 62405
diff changeset
    55
    override def toString: String = rc.toString
62403
1d7aba20a332 explicit class Build_Results;
wenzelm
parents: 62402
diff changeset
    56
  }
1d7aba20a332 explicit class Build_Results;
wenzelm
parents: 62402
diff changeset
    57
77330
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
    58
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
    59
  /* engine */
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
    60
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    61
  object Engine {
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    62
    lazy val services: List[Engine] =
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    63
      Isabelle_System.make_services(classOf[Engine])
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    64
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    65
    def apply(name: String): Engine =
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    66
      services.find(_.name == name).getOrElse(error("Bad build engine " + quote(name)))
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    67
  }
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    68
77411
149cc77f7348 clafified signature: simplify object-oriented reuse;
wenzelm
parents: 77384
diff changeset
    69
  class Engine(val name: String) extends Isabelle_System.Service {
77330
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
    70
    override def toString: String = name
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    71
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    72
    def build_options(options: Options): Options =
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    73
      options + "completion_limit=0" + "editor_tracing_messages=0"
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    74
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    75
    def build_process(build_context: Build_Process.Context, build_progress: Progress): Build_Process =
77505
7ee426daafa3 support progress backed by database;
wenzelm
parents: 77477
diff changeset
    76
      new Build_Process(build_context, build_progress)
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    77
78233
1a12e6246212 clarified signature;
wenzelm
parents: 78232
diff changeset
    78
    final def build_store(options: Options, cache: Term.Cache = Term.Cache.make()): Store = {
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    79
      val store = Store(build_options(options), cache = cache)
78233
1a12e6246212 clarified signature;
wenzelm
parents: 78232
diff changeset
    80
1a12e6246212 clarified signature;
wenzelm
parents: 78232
diff changeset
    81
      Isabelle_System.make_directory(store.output_dir + Path.basic("log"))
1a12e6246212 clarified signature;
wenzelm
parents: 78232
diff changeset
    82
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    83
      Isabelle_Fonts.init()
78233
1a12e6246212 clarified signature;
wenzelm
parents: 78232
diff changeset
    84
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    85
      store
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    86
    }
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    87
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    88
    final def run(context: Build_Process.Context, progress: Progress): Results =
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    89
      Isabelle_Thread.uninterruptible {
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    90
        using(build_process(context, progress)) { build_process =>
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    91
          Results(context, build_process.run())
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    92
        }
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    93
      }
77330
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
    94
  }
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
    95
77411
149cc77f7348 clafified signature: simplify object-oriented reuse;
wenzelm
parents: 77384
diff changeset
    96
  class Default_Engine extends Engine("") { override def toString: String = "<default>" }
77330
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
    97
77558
wenzelm
parents: 77557
diff changeset
    98
wenzelm
parents: 77557
diff changeset
    99
  /* build */
wenzelm
parents: 77557
diff changeset
   100
62641
0b1b7465f2ef always build with full results;
wenzelm
parents: 62638
diff changeset
   101
  def build(
50404
898cac1dad5e avoid startup within GUI thread -- it is only required later for dialog;
wenzelm
parents: 50367
diff changeset
   102
    options: Options,
71981
0be06f99b210 clarified signature;
wenzelm
parents: 71978
diff changeset
   103
    selection: Sessions.Selection = Sessions.Selection.empty,
75942
603852abed8f clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents: 75941
diff changeset
   104
    browser_info: Browser_Info.Config = Browser_Info.Config.none,
71726
a5fda30edae2 clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents: 71718
diff changeset
   105
    progress: Progress = new Progress,
65832
2fb85623c386 implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents: 65831
diff changeset
   106
    check_unknown_files: Boolean = false,
48511
37999ee01156 remove old output heaps, to ensure that result is valid wrt. check_stamps;
wenzelm
parents: 48509
diff changeset
   107
    build_heap: Boolean = false,
48595
231e6fa96dbb added build option -c;
wenzelm
parents: 48594
diff changeset
   108
    clean_build: Boolean = false,
56890
7f120d227ca5 tuned signature;
wenzelm
parents: 56873
diff changeset
   109
    dirs: List[Path] = Nil,
7f120d227ca5 tuned signature;
wenzelm
parents: 56873
diff changeset
   110
    select_dirs: List[Path] = Nil,
66968
9991671c98aa allow to augment session context via explicit session infos;
wenzelm
parents: 66962
diff changeset
   111
    infos: List[Sessions.Info] = Nil,
64265
8eb6365f5916 isabelle build -N;
wenzelm
parents: 64173
diff changeset
   112
    numa_shuffling: Boolean = false,
48509
4854ced3e9d7 support session groups;
wenzelm
parents: 48508
diff changeset
   113
    max_jobs: Int = 1,
48903
1621b3f26095 added build option -l (list files);
wenzelm
parents: 48883
diff changeset
   114
    list_files: Boolean = false,
59891
9ce697050455 added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents: 59811
diff changeset
   115
    check_keywords: Set[String] = Set.empty,
66841
5c32a072ca8b added isablle build option -f;
wenzelm
parents: 66822
diff changeset
   116
    fresh_build: Boolean = false,
48509
4854ced3e9d7 support session groups;
wenzelm
parents: 48508
diff changeset
   117
    no_build: Boolean = false,
66745
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   118
    soft_build: Boolean = false,
73805
b73777a0c076 allow build session setup, e.g. for protocol handlers;
wenzelm
parents: 73804
diff changeset
   119
    export_files: Boolean = false,
76927
da13da82f6f9 treat update_options as part of Sessions.Info meta_digest, for proper re-build of updated sessions;
wenzelm
parents: 76919
diff changeset
   120
    augment_options: String => List[Options.Spec] = _ => Nil,
77559
4ad322ee6025 clarified signature: support all arguments of Sessions.store();
wenzelm
parents: 77558
diff changeset
   121
    session_setup: (String, Session) => Unit = (_, _) => (),
4ad322ee6025 clarified signature: support all arguments of Sessions.store();
wenzelm
parents: 77558
diff changeset
   122
    cache: Term.Cache = Term.Cache.make()
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74845
diff changeset
   123
  ): Results = {
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   124
    val build_engine = Engine(engine_name(options))
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   125
78233
1a12e6246212 clarified signature;
wenzelm
parents: 78232
diff changeset
   126
    val store = build_engine.build_store(options, cache = cache)
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   127
    val build_options = store.options
69369
6ecc85955e04 prefer "Isabelle DejaVu Sans", even for headless batch-build (session_graph.pdf);
wenzelm
parents: 68957
diff changeset
   128
66745
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   129
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   130
    /* session selection and dependencies */
65422
b606c98e6d10 tuned signature;
wenzelm
parents: 65420
diff changeset
   131
66961
wenzelm
parents: 66944
diff changeset
   132
    val full_sessions =
76927
da13da82f6f9 treat update_options as part of Sessions.Info meta_digest, for proper re-build of updated sessions;
wenzelm
parents: 76919
diff changeset
   133
      Sessions.load_structure(build_options, dirs = dirs, select_dirs = select_dirs, infos = infos,
da13da82f6f9 treat update_options as part of Sessions.Info meta_digest, for proper re-build of updated sessions;
wenzelm
parents: 76919
diff changeset
   134
        augment_options = augment_options)
73012
238ddf525da4 clarified HTML presentation, e.g. avoid bulky jobs like HOL or HOL-Analysis in applications;
wenzelm
parents: 72993
diff changeset
   135
    val full_sessions_selection = full_sessions.imports_selection(selection)
238ddf525da4 clarified HTML presentation, e.g. avoid bulky jobs like HOL or HOL-Analysis in applications;
wenzelm
parents: 72993
diff changeset
   136
75948
f0a8b7ae9192 clarified names;
wenzelm
parents: 75947
diff changeset
   137
    val build_deps = {
66745
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   138
      val deps0 =
77521
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77505
diff changeset
   139
        Sessions.deps(full_sessions.selection(selection), progress = progress, inlined_files = true,
66962
e1bde71bace6 clarified signature: global_theories is always required;
wenzelm
parents: 66961
diff changeset
   140
          list_files = list_files, check_keywords = check_keywords).check_errors
66745
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   141
66841
5c32a072ca8b added isablle build option -f;
wenzelm
parents: 66822
diff changeset
   142
      if (soft_build && !fresh_build) {
66745
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   143
        val outdated =
68204
a554da2811f2 clarified signature;
wenzelm
parents: 68198
diff changeset
   144
          deps0.sessions_structure.build_topological_order.flatMap(name =>
72634
5cea0993ee4f clarified access to single database server vs. collection of database files;
wenzelm
parents: 72624
diff changeset
   145
            store.try_open_database(name) match {
68214
b0e2a19df95b more abstract database access;
wenzelm
parents: 68213
diff changeset
   146
              case Some(db) =>
68216
wenzelm
parents: 68214
diff changeset
   147
                using(db)(store.read_build(_, name)) match {
77675
9e5f8f6e58a0 more thorough treatment of build prefs, guarded by system option "build_through": avoid accidental rebuild of HOL etc.;
wenzelm
parents: 77674
diff changeset
   148
                  case Some(build) if build.ok =>
9e5f8f6e58a0 more thorough treatment of build prefs, guarded by system option "build_through": avoid accidental rebuild of HOL etc.;
wenzelm
parents: 77674
diff changeset
   149
                    val session_options = deps0.sessions_structure(name).options
9e5f8f6e58a0 more thorough treatment of build prefs, guarded by system option "build_through": avoid accidental rebuild of HOL etc.;
wenzelm
parents: 77674
diff changeset
   150
                    val session_sources = deps0.sources_shasum(name)
9e5f8f6e58a0 more thorough treatment of build prefs, guarded by system option "build_through": avoid accidental rebuild of HOL etc.;
wenzelm
parents: 77674
diff changeset
   151
                    if (Sessions.eq_sources(session_options, build.sources, session_sources)) None
9e5f8f6e58a0 more thorough treatment of build prefs, guarded by system option "build_through": avoid accidental rebuild of HOL etc.;
wenzelm
parents: 77674
diff changeset
   152
                    else Some(name)
66745
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   153
                  case _ => Some(name)
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   154
                }
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   155
              case None => Some(name)
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   156
            })
68204
a554da2811f2 clarified signature;
wenzelm
parents: 68198
diff changeset
   157
a554da2811f2 clarified signature;
wenzelm
parents: 68198
diff changeset
   158
        Sessions.deps(full_sessions.selection(Sessions.Selection(sessions = outdated)),
70671
cb1776c8e216 clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents: 70509
diff changeset
   159
          progress = progress, inlined_files = true).check_errors
66745
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   160
      }
68204
a554da2811f2 clarified signature;
wenzelm
parents: 68198
diff changeset
   161
      else deps0
66745
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   162
    }
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   163
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   164
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   165
    /* check unknown files */
48504
21dfd6c04482 actually check source vs. target stamps, based on information from log files;
wenzelm
parents: 48494
diff changeset
   166
65832
2fb85623c386 implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents: 65831
diff changeset
   167
    if (check_unknown_files) {
2fb85623c386 implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents: 65831
diff changeset
   168
      val source_files =
2fb85623c386 implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents: 65831
diff changeset
   169
        (for {
75948
f0a8b7ae9192 clarified names;
wenzelm
parents: 75947
diff changeset
   170
          (_, base) <- build_deps.session_bases.iterator
75741
17b1c4fbc008 tuned signature;
wenzelm
parents: 75731
diff changeset
   171
          (path, _) <- base.session_sources.iterator
65832
2fb85623c386 implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents: 65831
diff changeset
   172
        } yield path).toList
76670
b04d45bebbc5 discontinued somewhat pointless dependency: avoid illusion of extra accuracy (see also 09fb749d1a1e and 0f750a6dc754);
wenzelm
parents: 76669
diff changeset
   173
      Mercurial.check_files(source_files)._2 match {
b04d45bebbc5 discontinued somewhat pointless dependency: avoid illusion of extra accuracy (see also 09fb749d1a1e and 0f750a6dc754);
wenzelm
parents: 76669
diff changeset
   174
        case Nil =>
b04d45bebbc5 discontinued somewhat pointless dependency: avoid illusion of extra accuracy (see also 09fb749d1a1e and 0f750a6dc754);
wenzelm
parents: 76669
diff changeset
   175
        case unknown_files =>
b04d45bebbc5 discontinued somewhat pointless dependency: avoid illusion of extra accuracy (see also 09fb749d1a1e and 0f750a6dc754);
wenzelm
parents: 76669
diff changeset
   176
          progress.echo_warning("Unknown files (not part of the underlying Mercurial repository):" +
76883
wenzelm
parents: 76871
diff changeset
   177
            unknown_files.map(File.standard_path).sorted.mkString("\n  ", "\n  ", ""))
65832
2fb85623c386 implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents: 65831
diff changeset
   178
      }
2fb85623c386 implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents: 65831
diff changeset
   179
    }
2fb85623c386 implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents: 65831
diff changeset
   180
51220
e140c8fa485a recover timing information from old log files;
wenzelm
parents: 51218
diff changeset
   181
77257
68a7ad1385bc clarified modules;
wenzelm
parents: 77256
diff changeset
   182
    /* build process and results */
51220
e140c8fa485a recover timing information from old log files;
wenzelm
parents: 51218
diff changeset
   183
77315
f34559b24277 clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents: 77311
diff changeset
   184
    val build_context =
78237
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78233
diff changeset
   185
      Build_Process.Context(store, build_deps, hostname = hostname(build_options),
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78233
diff changeset
   186
        build_heap = build_heap, numa_shuffling = numa_shuffling, max_jobs = max_jobs,
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78233
diff changeset
   187
        fresh_build = fresh_build, no_build = no_build, session_setup = session_setup,
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78233
diff changeset
   188
        master = true)
77254
8d34f53871b4 clarified signature: make dynamic Queue from static Context;
wenzelm
parents: 77253
diff changeset
   189
48595
231e6fa96dbb added build option -c;
wenzelm
parents: 48594
diff changeset
   190
    if (clean_build) {
78213
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78178
diff changeset
   191
      using_optional(store.maybe_open_database_server()) { database_server =>
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78178
diff changeset
   192
        for (name <- full_sessions.imports_descendants(full_sessions_selection)) {
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78178
diff changeset
   193
          store.clean_output(database_server, name) match {
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78178
diff changeset
   194
            case None =>
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78178
diff changeset
   195
            case Some(true) => progress.echo("Cleaned " + name)
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78178
diff changeset
   196
            case Some(false) => progress.echo(name + " FAILED to clean")
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78178
diff changeset
   197
          }
68220
8fc4e3d1df86 clarified store.clean_output: cleanup user_output_dir even in system_mode;
wenzelm
parents: 68219
diff changeset
   198
        }
48595
231e6fa96dbb added build option -c;
wenzelm
parents: 48594
diff changeset
   199
      }
231e6fa96dbb added build option -c;
wenzelm
parents: 48594
diff changeset
   200
    }
231e6fa96dbb added build option -c;
wenzelm
parents: 48594
diff changeset
   201
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   202
    val results = build_engine.run(build_context, progress)
62641
0b1b7465f2ef always build with full results;
wenzelm
parents: 62638
diff changeset
   203
69811
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69777
diff changeset
   204
    if (export_files) {
76196
wenzelm
parents: 75967
diff changeset
   205
      for (name <- full_sessions_selection.iterator if results(name).ok) {
69811
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69777
diff changeset
   206
        val info = results.info(name)
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69777
diff changeset
   207
        if (info.export_files.nonEmpty) {
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69777
diff changeset
   208
          progress.echo("Exporting " + info.name + " ...")
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69777
diff changeset
   209
          for ((dir, prune, pats) <- info.export_files) {
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69777
diff changeset
   210
            Export.export_files(store, name, info.dir + dir,
77521
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77505
diff changeset
   211
              progress = if (progress.verbose) progress else new Progress,
69811
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69777
diff changeset
   212
              export_prune = prune,
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69777
diff changeset
   213
              export_patterns = pats)
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69777
diff changeset
   214
          }
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69777
diff changeset
   215
        }
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69777
diff changeset
   216
      }
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69777
diff changeset
   217
    }
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69777
diff changeset
   218
76901
93ccf8b7a660 clarified signature;
wenzelm
parents: 76883
diff changeset
   219
    val presentation_sessions =
93ccf8b7a660 clarified signature;
wenzelm
parents: 76883
diff changeset
   220
      results.sessions_ok.filter(name => browser_info.enabled(results.info(name)))
76230
fc19de122712 clarified signature;
wenzelm
parents: 76209
diff changeset
   221
    if (presentation_sessions.nonEmpty && !progress.stopped) {
fc19de122712 clarified signature;
wenzelm
parents: 76209
diff changeset
   222
      Browser_Info.build(browser_info, results.store, results.deps, presentation_sessions,
77521
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77505
diff changeset
   223
        progress = progress)
76198
fb4215da4919 clarified presentation_sessions: work with partial results;
wenzelm
parents: 76197
diff changeset
   224
    }
fb4215da4919 clarified presentation_sessions: work with partial results;
wenzelm
parents: 76197
diff changeset
   225
77521
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77505
diff changeset
   226
    if (!results.ok && (progress.verbose || !no_build)) {
76199
6bf42525f111 tuned signature;
wenzelm
parents: 76198
diff changeset
   227
      progress.echo("Unfinished session(s): " + commas(results.unfinished))
62641
0b1b7465f2ef always build with full results;
wenzelm
parents: 62638
diff changeset
   228
    }
0b1b7465f2ef always build with full results;
wenzelm
parents: 62638
diff changeset
   229
0b1b7465f2ef always build with full results;
wenzelm
parents: 62638
diff changeset
   230
    results
48341
752de4e10162 tuned source structure;
wenzelm
parents: 48340
diff changeset
   231
  }
752de4e10162 tuned source structure;
wenzelm
parents: 48340
diff changeset
   232
752de4e10162 tuned source structure;
wenzelm
parents: 48340
diff changeset
   233
77555
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   234
  /* build logic image */
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   235
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   236
  def build_logic(options: Options, logic: String,
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   237
    progress: Progress = new Progress,
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   238
    build_heap: Boolean = false,
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   239
    dirs: List[Path] = Nil,
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   240
    fresh: Boolean = false,
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   241
    strict: Boolean = false
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   242
  ): Int = {
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   243
    val selection = Sessions.Selection.session(logic)
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   244
    val rc =
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   245
      if (!fresh && build(options, selection = selection,
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   246
            build_heap = build_heap, no_build = true, dirs = dirs).ok) Process_Result.RC.ok
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   247
      else {
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   248
        progress.echo("Build started for Isabelle/" + logic + " ...")
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   249
        build(options, selection = selection, progress = progress,
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   250
          build_heap = build_heap, fresh_build = fresh, dirs = dirs).rc
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   251
      }
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   252
    if (strict && rc != Process_Result.RC.ok) error("Failed to build Isabelle/" + logic) else rc
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   253
  }
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   254
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   255
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   256
  /* command-line wrapper */
48341
752de4e10162 tuned source structure;
wenzelm
parents: 48340
diff changeset
   257
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   258
  val isabelle_tool1 = Isabelle_Tool("build", "build and manage Isabelle sessions",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   259
    Scala_Project.here,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   260
    { args =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   261
      var base_sessions: List[String] = Nil
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   262
      var select_dirs: List[Path] = Nil
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   263
      var numa_shuffling = false
75942
603852abed8f clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents: 75941
diff changeset
   264
      var browser_info = Browser_Info.Config.none
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   265
      var requirements = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   266
      var soft_build = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   267
      var exclude_session_groups: List[String] = Nil
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   268
      var all_sessions = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   269
      var build_heap = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   270
      var clean_build = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   271
      var dirs: List[Path] = Nil
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   272
      var export_files = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   273
      var fresh_build = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   274
      var session_groups: List[String] = Nil
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   275
      var max_jobs = 1
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   276
      var check_keywords: Set[String] = Set.empty
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   277
      var list_files = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   278
      var no_build = false
77628
a538dab533ef clarified signature: prefer explicit types;
wenzelm
parents: 77579
diff changeset
   279
      var options = Options.init(specs = Options.Spec.ISABELLE_BUILD_OPTIONS)
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   280
      var verbose = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   281
      var exclude_sessions: List[String] = Nil
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   282
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   283
      val getopts = Getopts("""
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   284
Usage: isabelle build [OPTIONS] [SESSIONS ...]
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   285
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   286
  Options are:
66737
2edc0c42c883 option -B for "isabelle build" and "isabelle imports";
wenzelm
parents: 66736
diff changeset
   287
    -B NAME      include session NAME and all descendants
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   288
    -D DIR       include session directory and select its sessions
64265
8eb6365f5916 isabelle build -N;
wenzelm
parents: 64173
diff changeset
   289
    -N           cyclic shuffling of NUMA CPU nodes (performance tuning)
72648
1cbac4ae934d more explicit presentation directory;
wenzelm
parents: 72640
diff changeset
   290
    -P DIR       enable HTML/PDF presentation in directory (":" for default)
71807
cdfa8f027bb9 tuned messages;
wenzelm
parents: 71727
diff changeset
   291
    -R           refer to requirements of selected sessions
66745
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   292
    -S           soft build: only observe changes of sources, not heap images
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   293
    -X NAME      exclude sessions from group NAME and all descendants
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   294
    -a           select all sessions
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   295
    -b           build heap images
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   296
    -c           clean build
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   297
    -d DIR       include session directory
69811
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69777
diff changeset
   298
    -e           export files from session specification into file-system
66841
5c32a072ca8b added isablle build option -f;
wenzelm
parents: 66822
diff changeset
   299
    -f           fresh build
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   300
    -g NAME      select session group NAME
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   301
    -j INT       maximum number of parallel jobs (default 1)
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   302
    -k KEYWORD   check theory sources for conflicts with proposed keywords
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   303
    -l           list session source files
77554
4465d9dff448 clarified terminology of "session build database", while "build database" is the one underlying Build_Process;
wenzelm
parents: 77553
diff changeset
   304
    -n           no build -- take existing session build databases
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   305
    -o OPTION    override Isabelle system OPTION (via NAME=VAL or NAME)
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   306
    -v           verbose
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   307
    -x NAME      exclude session NAME and all descendants
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   308
77647
c14db5d67400 tuned output;
wenzelm
parents: 77628
diff changeset
   309
  Build and manage Isabelle sessions: ML heaps, session databases, documents.
62596
cf79f8866bc3 tuned messages;
wenzelm
parents: 62595
diff changeset
   310
77647
c14db5d67400 tuned output;
wenzelm
parents: 77628
diff changeset
   311
  Notable system options: see "isabelle options -l -t build"
c14db5d67400 tuned output;
wenzelm
parents: 77628
diff changeset
   312
c14db5d67400 tuned output;
wenzelm
parents: 77628
diff changeset
   313
  Notable system settings:
c14db5d67400 tuned output;
wenzelm
parents: 77628
diff changeset
   314
""" + Library.indent_lines(4,  Build_Log.Settings.show()) + "\n",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   315
        "B:" -> (arg => base_sessions = base_sessions ::: List(arg)),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   316
        "D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   317
        "N" -> (_ => numa_shuffling = true),
75942
603852abed8f clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents: 75941
diff changeset
   318
        "P:" -> (arg => browser_info = Browser_Info.Config.make(arg)),
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   319
        "R" -> (_ => requirements = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   320
        "S" -> (_ => soft_build = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   321
        "X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   322
        "a" -> (_ => all_sessions = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   323
        "b" -> (_ => build_heap = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   324
        "c" -> (_ => clean_build = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   325
        "d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   326
        "e" -> (_ => export_files = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   327
        "f" -> (_ => fresh_build = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   328
        "g:" -> (arg => session_groups = session_groups ::: List(arg)),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   329
        "j:" -> (arg => max_jobs = Value.Int.parse(arg)),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   330
        "k:" -> (arg => check_keywords = check_keywords + arg),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   331
        "l" -> (_ => list_files = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   332
        "n" -> (_ => no_build = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   333
        "o:" -> (arg => options = options + arg),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   334
        "v" -> (_ => verbose = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   335
        "x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg)))
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   336
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   337
      val sessions = getopts(args)
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   338
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   339
      val progress = new Console_Progress(verbose = verbose)
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   340
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   341
      val start_date = Date.now()
64140
96d398871124 modernized date format;
wenzelm
parents: 64115
diff changeset
   342
77521
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77505
diff changeset
   343
      progress.echo(
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77505
diff changeset
   344
        "Started at " + Build_Log.print_date(start_date) +
77719
cbfbf48b0281 tuned signature;
wenzelm
parents: 77677
diff changeset
   345
          " (" + Isabelle_System.ml_identifier() + " on " + hostname(options) +")",
77521
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77505
diff changeset
   346
        verbose = true)
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77505
diff changeset
   347
      progress.echo(Build_Log.Settings.show() + "\n", verbose = true)
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   348
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   349
      val results =
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   350
        progress.interrupt_handler {
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   351
          build(options,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   352
            selection = Sessions.Selection(
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   353
              requirements = requirements,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   354
              all_sessions = all_sessions,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   355
              base_sessions = base_sessions,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   356
              exclude_session_groups = exclude_session_groups,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   357
              exclude_sessions = exclude_sessions,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   358
              session_groups = session_groups,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   359
              sessions = sessions),
75942
603852abed8f clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents: 75941
diff changeset
   360
            browser_info = browser_info,
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   361
            progress = progress,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   362
            check_unknown_files = Mercurial.is_repository(Path.ISABELLE_HOME),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   363
            build_heap = build_heap,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   364
            clean_build = clean_build,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   365
            dirs = dirs,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   366
            select_dirs = select_dirs,
77477
f376aebca9c1 clarified modules;
wenzelm
parents: 77453
diff changeset
   367
            numa_shuffling = Host.numa_check(progress, numa_shuffling),
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   368
            max_jobs = max_jobs,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   369
            list_files = list_files,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   370
            check_keywords = check_keywords,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   371
            fresh_build = fresh_build,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   372
            no_build = no_build,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   373
            soft_build = soft_build,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   374
            export_files = export_files)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   375
        }
77545
4af88aca2a4f clarified database content;
wenzelm
parents: 77536
diff changeset
   376
      val stop_date = Date.now()
4af88aca2a4f clarified database content;
wenzelm
parents: 77536
diff changeset
   377
      val elapsed_time = stop_date.time - start_date.time
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   378
77545
4af88aca2a4f clarified database content;
wenzelm
parents: 77536
diff changeset
   379
      progress.echo("\nFinished at " + Build_Log.print_date(stop_date), verbose = true)
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   380
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   381
      val total_timing =
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   382
        results.sessions.iterator.map(a => results(a).timing).foldLeft(Timing.zero)(_ + _).
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   383
          copy(elapsed = elapsed_time)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   384
      progress.echo(total_timing.message_resources)
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   385
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   386
      sys.exit(results.rc)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   387
    })
68305
5321218147d3 clarified signature;
wenzelm
parents: 68292
diff changeset
   388
5321218147d3 clarified signature;
wenzelm
parents: 68292
diff changeset
   389
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   390
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   391
  /** "isabelle build_worker" **/
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   392
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   393
  /* identified builds */
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   394
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   395
  def read_builds(options: Options): List[Build_Process.Build] =
78223
2d2417a63314 clarified signature: better default;
wenzelm
parents: 78222
diff changeset
   396
    using_option(Store(options).maybe_open_build_database())(
78222
5c91541284cd show only active builds;
wenzelm
parents: 78221
diff changeset
   397
      Build_Process.read_builds).getOrElse(Nil).filter(_.active)
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   398
78221
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   399
  def print_builds(options: Options, builds: List[Build_Process.Build]): String =
78223
2d2417a63314 clarified signature: better default;
wenzelm
parents: 78222
diff changeset
   400
    using_optional(Store(options).maybe_open_build_database()) { build_database =>
78221
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   401
      val print_database =
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   402
        build_database match {
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   403
          case None => ""
78225
5da972859ea6 tuned output;
wenzelm
parents: 78223
diff changeset
   404
          case Some(db) => " (database: " + db + ")"
78221
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   405
        }
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   406
      if (builds.isEmpty) "No build processes available" + print_database
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   407
      else {
78225
5da972859ea6 tuned output;
wenzelm
parents: 78223
diff changeset
   408
        "Available build processes" + print_database +
78221
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   409
          (for ((build, i) <- builds.iterator.zipWithIndex)
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   410
            yield {
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   411
              "\n  " + (i + 1) + ": " + build.build_uuid +
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   412
                " (platform: " + build.ml_platform +
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   413
                ", start: " + Build_Log.print_date(build.start) + ")"
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   414
            }).mkString
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   415
      }
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   416
    }
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   417
78221
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   418
  def id_builds(
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   419
    options: Options,
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   420
    id: String,
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   421
    builds: List[Build_Process.Build]
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   422
  ): Build_Process.Build =
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   423
    (id, builds.length) match {
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   424
      case (Value.Int(i), n) if 1 <= i && i <= n => builds(i - 1)
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   425
      case (UUID(_), _) if builds.exists(_.build_uuid == id) => builds.find(_.build_uuid == id).get
78221
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   426
      case ("", 0) => error(print_builds(options, builds))
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   427
      case ("", 1) => builds.head
78221
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   428
      case _ => cat_error("Cannot identify build process " + quote(id), print_builds(options, builds))
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   429
    }
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   430
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   431
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   432
  /* build_worker */
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   433
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   434
  def build_worker(
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   435
    options: Options,
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   436
    build_master: Build_Process.Build,
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   437
    progress: Progress = new Progress,
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   438
    dirs: List[Path] = Nil,
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   439
    numa_shuffling: Boolean = false,
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   440
    max_jobs: Int = 1,
77559
4ad322ee6025 clarified signature: support all arguments of Sessions.store();
wenzelm
parents: 77558
diff changeset
   441
    cache: Term.Cache = Term.Cache.make()
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   442
  ): Results = {
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   443
    val build_engine = Engine(engine_name(options))
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   444
78233
1a12e6246212 clarified signature;
wenzelm
parents: 78232
diff changeset
   445
    val store = build_engine.build_store(options, cache = cache)
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   446
    val build_options = store.options
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   447
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   448
    val sessions_structure =
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   449
      Sessions.load_structure(build_options, dirs = dirs).
78226
73be8ec88721 clarified signature: more concise data;
wenzelm
parents: 78225
diff changeset
   450
        selection(Sessions.Selection(sessions = build_master.sessions))
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   451
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   452
    val build_deps =
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   453
      Sessions.deps(sessions_structure, progress = progress, inlined_files = true).check_errors
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   454
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   455
    val build_context =
78237
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78233
diff changeset
   456
      Build_Process.Context(store, build_deps, hostname = hostname(build_options),
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78233
diff changeset
   457
        numa_shuffling = numa_shuffling, max_jobs = max_jobs, build_uuid = build_master.build_uuid)
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   458
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   459
    build_engine.run(build_context, progress)
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   460
  }
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   461
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   462
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   463
  /* command-line wrapper */
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   464
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   465
  val isabelle_tool2 = Isabelle_Tool("build_worker", "external worker for session build process",
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   466
    Scala_Project.here,
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   467
    { args =>
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   468
      var build_id = ""
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   469
      var list_builds = false
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   470
      var numa_shuffling = false
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   471
      var dirs: List[Path] = Nil
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   472
      var max_jobs = 1
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   473
      var options =
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   474
        Options.init(specs = Options.Spec.ISABELLE_BUILD_OPTIONS :::
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   475
          List(Options.Spec.make("build_database_test")))
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   476
      var verbose = false
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   477
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   478
      val getopts = Getopts("""
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   479
Usage: isabelle build_worker [OPTIONS]
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   480
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   481
  Options are:
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   482
    -N           cyclic shuffling of NUMA CPU nodes (performance tuning)
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   483
    -d DIR       include session directory
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   484
    -i ID        identify build process, either via index (starting from 1) or
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   485
                 Universally Unique Identifier (UUID)
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   486
    -j INT       maximum number of parallel jobs (default 1)
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   487
    -l           list build processes
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   488
    -o OPTION    override Isabelle system OPTION (via NAME=VAL or NAME)
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   489
    -v           verbose
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   490
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   491
  Run as external worker for session build process, as identified via
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   492
  option -i. The latter can be omitted, if there is exactly one build.
77647
c14db5d67400 tuned output;
wenzelm
parents: 77628
diff changeset
   493
""",
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   494
        "N" -> (_ => numa_shuffling = true),
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   495
        "d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))),
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   496
        "i:" -> (arg => build_id = arg),
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   497
        "j:" -> (arg => max_jobs = Value.Int.parse(arg)),
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   498
        "l" -> (_ => list_builds = true),
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   499
        "o:" -> (arg => options = options + arg),
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   500
        "v" -> (_ => verbose = true))
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   501
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   502
      val more_args = getopts(args)
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   503
      if (more_args.nonEmpty) getopts.usage()
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   504
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   505
      val progress = new Console_Progress(verbose = verbose)
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   506
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   507
      val builds = read_builds(options)
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   508
78221
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   509
      if (list_builds) progress.echo(print_builds(options, builds))
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   510
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   511
      if (!list_builds || build_id.nonEmpty) {
78221
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   512
        val build = id_builds(options, build_id, builds)
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   513
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   514
        val results =
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   515
          progress.interrupt_handler {
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   516
            build_worker(options, build,
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   517
              progress = progress,
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   518
              dirs = dirs,
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   519
              numa_shuffling = Host.numa_check(progress, numa_shuffling),
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   520
              max_jobs = max_jobs)
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   521
          }
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   522
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   523
        sys.exit(results.rc)
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   524
      }
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   525
    })
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   526
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   527
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   528
77563
cbb49fe8e5a2 renamed "isabelle log" to "isabelle build_log";
wenzelm
parents: 77559
diff changeset
   529
  /** "isabelle build_log" **/
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   530
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   531
  /* theory markup/messages from session database */
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   532
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   533
  def read_theory(
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   534
    theory_context: Export.Theory_Context,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   535
    unicode_symbols: Boolean = false
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   536
  ): Option[Document.Snapshot] = {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   537
    def decode_bytes(bytes: Bytes): String =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   538
      Symbol.output(unicode_symbols, UTF8.decode_permissive(bytes))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   539
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   540
    def read(name: String): Export.Entry = theory_context(name, permissive = true)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   541
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   542
    def read_xml(name: String): XML.Body =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   543
      YXML.parse_body(decode_bytes(read(name).bytes), cache = theory_context.cache)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   544
78178
a177f71dc79f clarified modules;
wenzelm
parents: 77719
diff changeset
   545
    def read_source_file(name: String): Store.Source_File =
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   546
      theory_context.session_context.source_file(name)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   547
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   548
    for {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   549
      id <- theory_context.document_id()
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   550
      (thy_file, blobs_files) <- theory_context.files(permissive = true)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   551
    }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   552
    yield {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   553
      val master_dir =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   554
        Path.explode(Url.strip_base_name(thy_file).getOrElse(
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   555
          error("Cannot determine theory master directory: " + quote(thy_file))))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   556
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   557
      val blobs =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   558
        blobs_files.map { name =>
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   559
          val path = Path.explode(name)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   560
          val src_path = File.relative_path(master_dir, path).getOrElse(path)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   561
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   562
          val file = read_source_file(name)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   563
          val bytes = file.bytes
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   564
          val text = decode_bytes(bytes)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   565
          val chunk = Symbol.Text_Chunk(text)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   566
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   567
          Command.Blob(Document.Node.Name(name), src_path, Some((file.digest, chunk))) ->
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   568
            Document.Blobs.Item(bytes, text, chunk, changed = false)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   569
        }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   570
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   571
      val thy_source = decode_bytes(read_source_file(thy_file).bytes)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   572
      val thy_xml = read_xml(Export.MARKUP)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   573
      val blobs_xml =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   574
        for (i <- (1 to blobs.length).toList)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   575
          yield read_xml(Export.MARKUP + i)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   576
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   577
      val markups_index = Command.Markup_Index.make(blobs.map(_._1))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   578
      val markups =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   579
        Command.Markups.make(
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   580
          for ((index, xml) <- markups_index.zip(thy_xml :: blobs_xml))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   581
          yield index -> Markup_Tree.from_XML(xml))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   582
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   583
      val results =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   584
        Command.Results.make(
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   585
          for (elem @ XML.Elem(Markup(_, Markup.Serial(i)), _) <- read_xml(Export.MESSAGES))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   586
            yield i -> elem)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   587
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   588
      val command =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   589
        Command.unparsed(thy_source, theory = true, id = id,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   590
          node_name = Document.Node.Name(thy_file, theory = theory_context.theory),
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   591
          blobs_info = Command.Blobs_Info.make(blobs),
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   592
          markups = markups, results = results)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   593
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   594
      val doc_blobs = Document.Blobs.make(blobs)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   595
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   596
      Document.State.init.snippet(command, doc_blobs)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   597
    }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   598
  }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   599
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   600
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   601
  /* print messages */
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   602
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   603
  def print_log(
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   604
    options: Options,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   605
    sessions: List[String],
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   606
    theories: List[String] = Nil,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   607
    message_head: List[Regex] = Nil,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   608
    message_body: List[Regex] = Nil,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   609
    progress: Progress = new Progress,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   610
    margin: Double = Pretty.default_margin,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   611
    breakgain: Double = Pretty.default_breakgain,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   612
    metric: Pretty.Metric = Symbol.Metric,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   613
    unicode_symbols: Boolean = false
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   614
  ): Unit = {
78178
a177f71dc79f clarified modules;
wenzelm
parents: 77719
diff changeset
   615
    val store = Store(options)
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   616
    val session = new Session(options, Resources.bootstrap)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   617
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   618
    def check(filter: List[Regex], make_string: => String): Boolean =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   619
      filter.isEmpty || {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   620
        val s = Output.clean_yxml(make_string)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   621
        filter.forall(r => r.findFirstIn(Output.clean_yxml(s)).nonEmpty)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   622
      }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   623
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   624
    def print(session_name: String): Unit = {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   625
      using(Export.open_session_context0(store, session_name)) { session_context =>
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   626
        val result =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   627
          for {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   628
            db <- session_context.session_db()
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   629
            theories = store.read_theories(db, session_name)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   630
            errors = store.read_errors(db, session_name)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   631
            info <- store.read_build(db, session_name)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   632
          } yield (theories, errors, info.return_code)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   633
        result match {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   634
          case None => store.error_database(session_name)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   635
          case Some((used_theories, errors, rc)) =>
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   636
            theories.filterNot(used_theories.toSet) match {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   637
              case Nil =>
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   638
              case bad => error("Unknown theories " + commas_quote(bad))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   639
            }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   640
            val print_theories =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   641
              if (theories.isEmpty) used_theories else used_theories.filter(theories.toSet)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   642
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   643
            for (thy <- print_theories) {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   644
              val thy_heading = "\nTheory " + quote(thy) + " (in " + session_name + ")" + ":"
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   645
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   646
              Build_Job.read_theory(session_context.theory(thy), unicode_symbols = unicode_symbols) match {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   647
                case None => progress.echo(thy_heading + " MISSING")
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   648
                case Some(snapshot) =>
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   649
                  val rendering = new Rendering(snapshot, options, session)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   650
                  val messages =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   651
                    rendering.text_messages(Text.Range.full)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   652
                      .filter(message => progress.verbose || Protocol.is_exported(message.info))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   653
                  if (messages.nonEmpty) {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   654
                    val line_document = Line.Document(snapshot.node.source)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   655
                    val buffer = new mutable.ListBuffer[String]
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   656
                    for (Text.Info(range, elem) <- messages) {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   657
                      val line = line_document.position(range.start).line1
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   658
                      val pos = Position.Line_File(line, snapshot.node_name.node)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   659
                      def message_text: String =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   660
                        Protocol.message_text(elem, heading = true, pos = pos,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   661
                          margin = margin, breakgain = breakgain, metric = metric)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   662
                      val ok =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   663
                        check(message_head, Protocol.message_heading(elem, pos)) &&
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   664
                        check(message_body, XML.content(Pretty.unformatted(List(elem))))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   665
                      if (ok) buffer += message_text
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   666
                    }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   667
                    if (buffer.nonEmpty) {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   668
                      progress.echo(thy_heading)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   669
                      buffer.foreach(progress.echo(_))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   670
                    }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   671
                  }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   672
              }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   673
            }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   674
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   675
            if (errors.nonEmpty) {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   676
              val msg = Symbol.output(unicode_symbols, cat_lines(errors))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   677
              progress.echo("\nBuild errors:\n" + Output.error_message_text(msg))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   678
            }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   679
            if (rc != Process_Result.RC.ok) {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   680
              progress.echo("\n" + Process_Result.RC.print_long(rc))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   681
            }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   682
        }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   683
      }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   684
    }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   685
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   686
    val errors = new mutable.ListBuffer[String]
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   687
    for (session_name <- sessions) {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   688
      Exn.interruptible_capture(print(session_name)) match {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   689
        case Exn.Res(_) =>
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   690
        case Exn.Exn(exn) => errors += Exn.message(exn)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   691
      }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   692
    }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   693
    if (errors.nonEmpty) error(cat_lines(errors.toList))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   694
  }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   695
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   696
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   697
  /* command-line wrapper */
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   698
77563
cbb49fe8e5a2 renamed "isabelle log" to "isabelle build_log";
wenzelm
parents: 77559
diff changeset
   699
  val isabelle_tool3 = Isabelle_Tool("build_log", "print messages from session build database",
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   700
    Scala_Project.here,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   701
    { args =>
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   702
      /* arguments */
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   703
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   704
      var message_head = List.empty[Regex]
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   705
      var message_body = List.empty[Regex]
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   706
      var unicode_symbols = false
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   707
      var theories: List[String] = Nil
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   708
      var margin = Pretty.default_margin
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   709
      var options = Options.init()
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   710
      var verbose = false
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   711
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   712
      val getopts = Getopts("""
77563
cbb49fe8e5a2 renamed "isabelle log" to "isabelle build_log";
wenzelm
parents: 77559
diff changeset
   713
Usage: isabelle build_log [OPTIONS] [SESSIONS ...]
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   714
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   715
  Options are:
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   716
    -H REGEX     filter messages by matching against head
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   717
    -M REGEX     filter messages by matching against body
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   718
    -T NAME      restrict to given theories (multiple options possible)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   719
    -U           output Unicode symbols
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   720
    -m MARGIN    margin for pretty printing (default: """ + margin + """)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   721
    -o OPTION    override Isabelle system OPTION (via NAME=VAL or NAME)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   722
    -v           print all messages, including information etc.
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   723
77554
4465d9dff448 clarified terminology of "session build database", while "build database" is the one underlying Build_Process;
wenzelm
parents: 77553
diff changeset
   724
  Print messages from the session build database of the given sessions,
4465d9dff448 clarified terminology of "session build database", while "build database" is the one underlying Build_Process;
wenzelm
parents: 77553
diff changeset
   725
  without any checks against current sources nor session structure: results
4465d9dff448 clarified terminology of "session build database", while "build database" is the one underlying Build_Process;
wenzelm
parents: 77553
diff changeset
   726
  from old sessions or failed builds can be printed as well.
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   727
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   728
  Multiple options -H and -M are conjunctive: all given patterns need to
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   729
  match. Patterns match any substring, but ^ or $ may be used to match the
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   730
  start or end explicitly.
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   731
""",
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   732
        "H:" -> (arg => message_head = message_head ::: List(arg.r)),
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   733
        "M:" -> (arg => message_body = message_body ::: List(arg.r)),
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   734
        "T:" -> (arg => theories = theories ::: List(arg)),
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   735
        "U" -> (_ => unicode_symbols = true),
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   736
        "m:" -> (arg => margin = Value.Double.parse(arg)),
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   737
        "o:" -> (arg => options = options + arg),
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   738
        "v" -> (_ => verbose = true))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   739
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   740
      val sessions = getopts(args)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   741
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   742
      val progress = new Console_Progress(verbose = verbose)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   743
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   744
      if (sessions.isEmpty) progress.echo_warning("No sessions to print")
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   745
      else {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   746
        print_log(options, sessions, theories = theories, message_head = message_head,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   747
          message_body = message_body, margin = margin, progress = progress,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   748
          unicode_symbols = unicode_symbols)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   749
      }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   750
    })
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   751
}