author | wenzelm |
Thu, 04 Apr 2019 15:26:18 +0200 | |
changeset 70053 | 997f256c98e3 |
parent 69896 | be7243b97c41 |
child 70640 | 5f4b8a505090 |
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, |
|
13 |
progress: Progress = No_Progress, |
|
14 |
log: Logger = No_Logger, |
|
15 |
dirs: List[Path] = Nil, |
|
16 |
select_dirs: List[Path] = Nil, |
|
17 |
selection: Sessions.Selection = Sessions.Selection.empty) |
|
18 |
{ |
|
19 |
Build.build_logic(options, logic, build_heap = true, progress = progress, |
|
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69603
diff
changeset
|
20 |
dirs = dirs ::: select_dirs, strict = true) |
69557 | 21 |
|
22 |
val dump_options = Dump.make_options(options) |
|
23 |
||
24 |
val deps = |
|
25 |
Dump.dependencies(dump_options, progress = progress, |
|
69856 | 26 |
dirs = dirs, select_dirs = select_dirs, selection = selection) |
69557 | 27 |
|
28 |
val resources = |
|
29 |
Headless.Resources.make(dump_options, logic, progress = progress, log = log, |
|
30 |
session_dirs = dirs ::: select_dirs, |
|
31 |
include_sessions = deps.sessions_structure.imports_topological_order) |
|
32 |
||
69603 | 33 |
val path_cartouches = dump_options.bool("update_path_cartouches") |
34 |
||
69557 | 35 |
def update_xml(xml: XML.Body): XML.Body = |
36 |
xml flatMap { |
|
37 |
case XML.Wrapped_Elem(markup, body1, body2) => |
|
38 |
if (markup.name == Markup.UPDATE) update_xml(body1) else update_xml(body2) |
|
69603 | 39 |
case XML.Elem(Markup.Language(Markup.Language.PATH, _, _, _), body) |
40 |
if path_cartouches => |
|
41 |
Token.read_embedded(Keyword.Keywords.empty, XML.content(body)) match { |
|
42 |
case Some(tok) => List(XML.Text(Symbol.cartouche(tok.content))) |
|
43 |
case None => update_xml(body) |
|
44 |
} |
|
69557 | 45 |
case XML.Elem(_, body) => update_xml(body) |
46 |
case t => List(t) |
|
47 |
} |
|
48 |
||
49 |
Dump.session(deps, resources, progress = progress, |
|
69896 | 50 |
process_theory = (args: Dump.Args) => |
69557 | 51 |
{ |
69896 | 52 |
progress.echo("Processing theory " + args.print_node + " ...") |
69571 | 53 |
|
69896 | 54 |
val snapshot = args.snapshot |
69557 | 55 |
for ((node_name, node) <- snapshot.nodes) { |
56 |
val xml = |
|
57 |
snapshot.state.markup_to_XML(snapshot.version, node_name, |
|
69603 | 58 |
Text.Range.full, Markup.Elements(Markup.UPDATE, Markup.LANGUAGE)) |
69557 | 59 |
|
60 |
val source1 = Symbol.encode(XML.content(update_xml(xml))) |
|
61 |
if (source1 != Symbol.encode(node.source)) { |
|
62 |
progress.echo("Updating " + node_name.path) |
|
63 |
File.write(node_name.path, source1) |
|
64 |
} |
|
65 |
} |
|
66 |
}) |
|
67 |
} |
|
68 |
||
69 |
||
70 |
/* Isabelle tool wrapper */ |
|
71 |
||
72 |
val isabelle_tool = |
|
73 |
Isabelle_Tool("update", "update theory sources based on PIDE markup", args => |
|
74 |
{ |
|
75 |
var base_sessions: List[String] = Nil |
|
76 |
var select_dirs: List[Path] = Nil |
|
77 |
var requirements = false |
|
78 |
var exclude_session_groups: List[String] = Nil |
|
79 |
var all_sessions = false |
|
80 |
var dirs: List[Path] = Nil |
|
81 |
var session_groups: List[String] = Nil |
|
82 |
var logic = Isabelle_System.getenv("ISABELLE_LOGIC") |
|
83 |
var options = Options.init() |
|
84 |
var verbose = false |
|
85 |
var exclude_sessions: List[String] = Nil |
|
86 |
||
87 |
val getopts = Getopts(""" |
|
88 |
Usage: isabelle update [OPTIONS] [SESSIONS ...] |
|
89 |
||
90 |
Options are: |
|
91 |
-B NAME include session NAME and all descendants |
|
92 |
-D DIR include session directory and select its sessions |
|
93 |
-R operate on requirements of selected sessions |
|
94 |
-X NAME exclude sessions from group NAME and all descendants |
|
95 |
-a select all sessions |
|
96 |
-d DIR include session directory |
|
97 |
-g NAME select session group NAME |
|
98 |
-l NAME logic session name (default ISABELLE_LOGIC=""" + quote(logic) + """) |
|
99 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
100 |
-u OPT overide update option: shortcut for "-o update_OPT" |
|
101 |
-v verbose |
|
102 |
-x NAME exclude session NAME and all descendants |
|
103 |
||
104 |
Update theory sources based on PIDE markup. |
|
105 |
""", |
|
106 |
"B:" -> (arg => base_sessions = base_sessions ::: List(arg)), |
|
107 |
"D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))), |
|
108 |
"R" -> (_ => requirements = true), |
|
109 |
"X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)), |
|
110 |
"a" -> (_ => all_sessions = true), |
|
111 |
"d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
|
112 |
"g:" -> (arg => session_groups = session_groups ::: List(arg)), |
|
113 |
"l:" -> (arg => logic = arg), |
|
114 |
"o:" -> (arg => options = options + arg), |
|
115 |
"u:" -> (arg => options = options + ("update_" + arg)), |
|
116 |
"v" -> (_ => verbose = true), |
|
117 |
"x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg))) |
|
118 |
||
119 |
val sessions = getopts(args) |
|
120 |
||
121 |
val progress = new Console_Progress(verbose = verbose) |
|
122 |
||
123 |
progress.interrupt_handler { |
|
124 |
update(options, logic, |
|
125 |
progress = progress, |
|
126 |
dirs = dirs, |
|
127 |
select_dirs = select_dirs, |
|
128 |
selection = Sessions.Selection( |
|
129 |
requirements = requirements, |
|
130 |
all_sessions = all_sessions, |
|
131 |
base_sessions = base_sessions, |
|
132 |
exclude_session_groups = exclude_session_groups, |
|
133 |
exclude_sessions = exclude_sessions, |
|
134 |
session_groups = session_groups, |
|
135 |
sessions = sessions)) |
|
136 |
} |
|
137 |
}) |
|
138 |
} |