author | wenzelm |
Wed, 22 Apr 2020 18:37:09 +0200 | |
changeset 71784 | 8a5da740e388 |
parent 71726 | a5fda30edae2 |
child 71807 | cdfa8f027bb9 |
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:
71573
diff
changeset
|
13 |
progress: Progress = new Progress, |
69557 | 14 |
log: Logger = No_Logger, |
15 |
dirs: List[Path] = Nil, |
|
16 |
select_dirs: List[Path] = Nil, |
|
17 |
selection: Sessions.Selection = Sessions.Selection.empty) |
|
18 |
{ |
|
70856
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70640
diff
changeset
|
19 |
val context = |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70640
diff
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:
70876
diff
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) |
|
69603 | 31 |
case XML.Elem(Markup.Language(Markup.Language.PATH, _, _, _), body) |
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:
69896
diff
changeset
|
42 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
69896
diff
changeset
|
43 |
progress.echo("Processing theory " + args.print_node + " ...") |
69571 | 44 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
69896
diff
changeset
|
45 |
val snapshot = args.snapshot |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
69896
diff
changeset
|
46 |
for ((node_name, node) <- snapshot.nodes) { |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
69896
diff
changeset
|
47 |
val xml = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
69896
diff
changeset
|
48 |
snapshot.state.markup_to_XML(snapshot.version, node_name, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
69896
diff
changeset
|
49 |
Text.Range.full, Markup.Elements(Markup.UPDATE, Markup.LANGUAGE)) |
69557 | 50 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
69896
diff
changeset
|
51 |
val source1 = Symbol.encode(XML.content(update_xml(xml))) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
69896
diff
changeset
|
52 |
if (source1 != Symbol.encode(node.source)) { |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
69896
diff
changeset
|
53 |
progress.echo("Updating " + node_name.path) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
69896
diff
changeset
|
54 |
File.write(node_name.path, source1) |
69557 | 55 |
} |
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
69896
diff
changeset
|
56 |
} |
70864 | 57 |
})) |
70876 | 58 |
|
59 |
context.check_errors |
|
69557 | 60 |
} |
61 |
||
62 |
||
63 |
/* Isabelle tool wrapper */ |
|
64 |
||
65 |
val isabelle_tool = |
|
66 |
Isabelle_Tool("update", "update theory sources based on PIDE markup", args => |
|
67 |
{ |
|
68 |
var base_sessions: List[String] = Nil |
|
69 |
var select_dirs: List[Path] = Nil |
|
70 |
var requirements = false |
|
71 |
var exclude_session_groups: List[String] = Nil |
|
72 |
var all_sessions = false |
|
73 |
var dirs: List[Path] = Nil |
|
74 |
var session_groups: List[String] = Nil |
|
70863
d1299774543d
clarified "isabelle update" options -- more like "isabelle dump";
wenzelm
parents:
70856
diff
changeset
|
75 |
var logic = Dump.default_logic |
69557 | 76 |
var options = Options.init() |
77 |
var verbose = false |
|
78 |
var exclude_sessions: List[String] = Nil |
|
79 |
||
80 |
val getopts = Getopts(""" |
|
81 |
Usage: isabelle update [OPTIONS] [SESSIONS ...] |
|
82 |
||
83 |
Options are: |
|
84 |
-B NAME include session NAME and all descendants |
|
85 |
-D DIR include session directory and select its sessions |
|
86 |
-R operate on requirements of selected sessions |
|
87 |
-X NAME exclude sessions from group NAME and all descendants |
|
88 |
-a select all sessions |
|
70863
d1299774543d
clarified "isabelle update" options -- more like "isabelle dump";
wenzelm
parents:
70856
diff
changeset
|
89 |
-b NAME base logic image (default """ + isabelle.quote(Dump.default_logic) + """) |
69557 | 90 |
-d DIR include session directory |
91 |
-g NAME select session group NAME |
|
92 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
93 |
-u OPT overide update option: shortcut for "-o update_OPT" |
|
94 |
-v verbose |
|
95 |
-x NAME exclude session NAME and all descendants |
|
96 |
||
97 |
Update theory sources based on PIDE markup. |
|
98 |
""", |
|
99 |
"B:" -> (arg => base_sessions = base_sessions ::: List(arg)), |
|
100 |
"D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))), |
|
101 |
"R" -> (_ => requirements = true), |
|
102 |
"X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)), |
|
103 |
"a" -> (_ => all_sessions = true), |
|
70863
d1299774543d
clarified "isabelle update" options -- more like "isabelle dump";
wenzelm
parents:
70856
diff
changeset
|
104 |
"b:" -> (arg => logic = arg), |
69557 | 105 |
"d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
106 |
"g:" -> (arg => session_groups = session_groups ::: List(arg)), |
|
107 |
"o:" -> (arg => options = options + arg), |
|
108 |
"u:" -> (arg => options = options + ("update_" + arg)), |
|
109 |
"v" -> (_ => verbose = true), |
|
110 |
"x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg))) |
|
111 |
||
112 |
val sessions = getopts(args) |
|
113 |
||
114 |
val progress = new Console_Progress(verbose = verbose) |
|
115 |
||
116 |
progress.interrupt_handler { |
|
117 |
update(options, logic, |
|
118 |
progress = progress, |
|
119 |
dirs = dirs, |
|
120 |
select_dirs = select_dirs, |
|
121 |
selection = Sessions.Selection( |
|
122 |
requirements = requirements, |
|
123 |
all_sessions = all_sessions, |
|
124 |
base_sessions = base_sessions, |
|
125 |
exclude_session_groups = exclude_session_groups, |
|
126 |
exclude_sessions = exclude_sessions, |
|
127 |
session_groups = session_groups, |
|
128 |
sessions = sessions)) |
|
129 |
} |
|
130 |
}) |
|
131 |
} |