| author | wenzelm | 
| Sun, 16 May 2021 23:22:03 +0200 | |
| changeset 73710 | 241cfa881788 | 
| parent 73340 | 0ffcad1f6130 | 
| child 75161 | 95612f330c93 | 
| permissions | -rw-r--r-- | 
| 69557 | 1 | /* Title: Pure/Tools/update.scala | 
| 2 | Author: Makarius | |
| 3 | ||
| 4 | Update theory sources based on PIDE markup. | |
| 5 | */ | |
| 6 | ||
| 7 | package isabelle | |
| 8 | ||
| 9 | ||
| 10 | object Update | |
| 11 | {
 | |
| 12 | def update(options: Options, logic: String, | |
| 71726 
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
 wenzelm parents: 
71573diff
changeset | 13 | progress: Progress = new Progress, | 
| 69557 | 14 | log: Logger = No_Logger, | 
| 15 | dirs: List[Path] = Nil, | |
| 16 | select_dirs: List[Path] = Nil, | |
| 73340 | 17 | selection: Sessions.Selection = Sessions.Selection.empty): Unit = | 
| 69557 | 18 |   {
 | 
| 70856 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 wenzelm parents: 
70640diff
changeset | 19 | val context = | 
| 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 wenzelm parents: 
70640diff
changeset | 20 | Dump.Context(options, progress = progress, dirs = dirs, select_dirs = select_dirs, | 
| 71573 
c67076c07fb8
avoid accidental update of base session sources (following documentation in "system" manual);
 wenzelm parents: 
70876diff
changeset | 21 | selection = selection, skip_base = true) | 
| 69557 | 22 | |
| 70864 | 23 | context.build_logic(logic) | 
| 24 | ||
| 70868 | 25 |     val path_cartouches = context.options.bool("update_path_cartouches")
 | 
| 69603 | 26 | |
| 69557 | 27 | def update_xml(xml: XML.Body): XML.Body = | 
| 28 |       xml flatMap {
 | |
| 29 | case XML.Wrapped_Elem(markup, body1, body2) => | |
| 30 | if (markup.name == Markup.UPDATE) update_xml(body1) else update_xml(body2) | |
| 72842 
6aae62f55c2b
clarified markup: support more completion, e.g. within ROOTS;
 wenzelm parents: 
72823diff
changeset | 31 | case XML.Elem(Markup.Language.Path(_), body) | 
| 69603 | 32 | if path_cartouches => | 
| 33 |           Token.read_embedded(Keyword.Keywords.empty, XML.content(body)) match {
 | |
| 34 | case Some(tok) => List(XML.Text(Symbol.cartouche(tok.content))) | |
| 35 | case None => update_xml(body) | |
| 36 | } | |
| 69557 | 37 | case XML.Elem(_, body) => update_xml(body) | 
| 38 | case t => List(t) | |
| 39 | } | |
| 40 | ||
| 70864 | 41 | context.sessions(logic, log = log).foreach(_.process((args: Dump.Args) => | 
| 70640 
5f4b8a505090
more explicit type Dump.Session, with context information;
 wenzelm parents: 
69896diff
changeset | 42 |       {
 | 
| 
5f4b8a505090
more explicit type Dump.Session, with context information;
 wenzelm parents: 
69896diff
changeset | 43 |         progress.echo("Processing theory " + args.print_node + " ...")
 | 
| 69571 | 44 | |
| 70640 
5f4b8a505090
more explicit type Dump.Session, with context information;
 wenzelm parents: 
69896diff
changeset | 45 | val snapshot = args.snapshot | 
| 72822 | 46 |         for (node_name <- snapshot.node_files) {
 | 
| 72823 | 47 | val node = snapshot.get_node(node_name) | 
| 70640 
5f4b8a505090
more explicit type Dump.Session, with context information;
 wenzelm parents: 
69896diff
changeset | 48 | val xml = | 
| 72723 | 49 | snapshot.state.xml_markup(snapshot.version, node_name, | 
| 50 | elements = Markup.Elements(Markup.UPDATE, Markup.LANGUAGE)) | |
| 69557 | 51 | |
| 70640 
5f4b8a505090
more explicit type Dump.Session, with context information;
 wenzelm parents: 
69896diff
changeset | 52 | val source1 = Symbol.encode(XML.content(update_xml(xml))) | 
| 
5f4b8a505090
more explicit type Dump.Session, with context information;
 wenzelm parents: 
69896diff
changeset | 53 |           if (source1 != Symbol.encode(node.source)) {
 | 
| 
5f4b8a505090
more explicit type Dump.Session, with context information;
 wenzelm parents: 
69896diff
changeset | 54 |             progress.echo("Updating " + node_name.path)
 | 
| 
5f4b8a505090
more explicit type Dump.Session, with context information;
 wenzelm parents: 
69896diff
changeset | 55 | File.write(node_name.path, source1) | 
| 69557 | 56 | } | 
| 70640 
5f4b8a505090
more explicit type Dump.Session, with context information;
 wenzelm parents: 
69896diff
changeset | 57 | } | 
| 70864 | 58 | })) | 
| 70876 | 59 | |
| 60 | context.check_errors | |
| 69557 | 61 | } | 
| 62 | ||
| 63 | ||
| 64 | /* Isabelle tool wrapper */ | |
| 65 | ||
| 66 | val isabelle_tool = | |
| 72763 | 67 |     Isabelle_Tool("update", "update theory sources based on PIDE markup", Scala_Project.here,
 | 
| 68 | args => | |
| 69557 | 69 |     {
 | 
| 70 | var base_sessions: List[String] = Nil | |
| 71 | var select_dirs: List[Path] = Nil | |
| 72 | var requirements = false | |
| 73 | var exclude_session_groups: List[String] = Nil | |
| 74 | var all_sessions = false | |
| 75 | var dirs: List[Path] = Nil | |
| 76 | var session_groups: List[String] = Nil | |
| 70863 
d1299774543d
clarified "isabelle update" options -- more like "isabelle dump";
 wenzelm parents: 
70856diff
changeset | 77 | var logic = Dump.default_logic | 
| 69557 | 78 | var options = Options.init() | 
| 79 | var verbose = false | |
| 80 | var exclude_sessions: List[String] = Nil | |
| 81 | ||
| 82 |       val getopts = Getopts("""
 | |
| 83 | Usage: isabelle update [OPTIONS] [SESSIONS ...] | |
| 84 | ||
| 85 | Options are: | |
| 86 | -B NAME include session NAME and all descendants | |
| 87 | -D DIR include session directory and select its sessions | |
| 71807 | 88 | -R refer to requirements of selected sessions | 
| 69557 | 89 | -X NAME exclude sessions from group NAME and all descendants | 
| 90 | -a select all sessions | |
| 70863 
d1299774543d
clarified "isabelle update" options -- more like "isabelle dump";
 wenzelm parents: 
70856diff
changeset | 91 | -b NAME base logic image (default """ + isabelle.quote(Dump.default_logic) + """) | 
| 69557 | 92 | -d DIR include session directory | 
| 93 | -g NAME select session group NAME | |
| 94 | -o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) | |
| 95 | -u OPT overide update option: shortcut for "-o update_OPT" | |
| 96 | -v verbose | |
| 97 | -x NAME exclude session NAME and all descendants | |
| 98 | ||
| 99 | Update theory sources based on PIDE markup. | |
| 100 | """, | |
| 101 | "B:" -> (arg => base_sessions = base_sessions ::: List(arg)), | |
| 102 | "D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))), | |
| 103 | "R" -> (_ => requirements = true), | |
| 104 | "X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)), | |
| 105 | "a" -> (_ => all_sessions = true), | |
| 70863 
d1299774543d
clarified "isabelle update" options -- more like "isabelle dump";
 wenzelm parents: 
70856diff
changeset | 106 | "b:" -> (arg => logic = arg), | 
| 69557 | 107 | "d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), | 
| 108 | "g:" -> (arg => session_groups = session_groups ::: List(arg)), | |
| 109 | "o:" -> (arg => options = options + arg), | |
| 110 |       "u:" -> (arg => options = options + ("update_" + arg)),
 | |
| 111 | "v" -> (_ => verbose = true), | |
| 112 | "x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg))) | |
| 113 | ||
| 114 | val sessions = getopts(args) | |
| 115 | ||
| 116 | val progress = new Console_Progress(verbose = verbose) | |
| 117 | ||
| 118 |       progress.interrupt_handler {
 | |
| 119 | update(options, logic, | |
| 120 | progress = progress, | |
| 121 | dirs = dirs, | |
| 122 | select_dirs = select_dirs, | |
| 123 | selection = Sessions.Selection( | |
| 124 | requirements = requirements, | |
| 125 | all_sessions = all_sessions, | |
| 126 | base_sessions = base_sessions, | |
| 127 | exclude_session_groups = exclude_session_groups, | |
| 128 | exclude_sessions = exclude_sessions, | |
| 129 | session_groups = session_groups, | |
| 130 | sessions = sessions)) | |
| 131 | } | |
| 132 | }) | |
| 133 | } |