6 |
6 |
7 package isabelle |
7 package isabelle |
8 |
8 |
9 |
9 |
10 object Update { |
10 object Update { |
11 def update(options: Options, logic: String, |
11 def update(options: Options, |
|
12 base_logics: List[String] = Nil, |
12 progress: Progress = new Progress, |
13 progress: Progress = new Progress, |
13 log: Logger = No_Logger, |
|
14 dirs: List[Path] = Nil, |
14 dirs: List[Path] = Nil, |
15 select_dirs: List[Path] = Nil, |
15 select_dirs: List[Path] = Nil, |
16 selection: Sessions.Selection = Sessions.Selection.empty |
16 selection: Sessions.Selection = Sessions.Selection.empty |
17 ): Unit = { |
17 ): Build.Results = { |
18 val context = |
18 /* excluded sessions */ |
19 Dump.Context(options, progress = progress, dirs = dirs, select_dirs = select_dirs, |
|
20 selection = selection, skip_base = true) |
|
21 |
19 |
22 context.build_logic(logic) |
20 val exclude: Set[String] = |
|
21 if (base_logics.isEmpty) Set.empty |
|
22 else { |
|
23 val sessions = |
|
24 Sessions.load_structure(options, dirs = dirs, select_dirs = select_dirs) |
|
25 .selection(selection) |
23 |
26 |
24 val path_cartouches = context.options.bool("update_path_cartouches") |
27 for (name <- base_logics if !sessions.defined(name)) { |
|
28 error("Base logic " + quote(name) + " outside of session selection") |
|
29 } |
|
30 |
|
31 sessions.build_requirements(base_logics).toSet |
|
32 } |
|
33 |
|
34 |
|
35 /* build */ |
|
36 |
|
37 val build_results = |
|
38 Build.build(options, progress = progress, dirs = dirs, select_dirs = select_dirs, |
|
39 selection = selection) |
|
40 |
|
41 if (!build_results.ok) error("Build failed") |
|
42 |
|
43 val store = build_results.store |
|
44 val sessions_structure = build_results.deps.sessions_structure |
|
45 |
|
46 |
|
47 /* update */ |
|
48 |
|
49 val path_cartouches = options.bool("update_path_cartouches") |
25 |
50 |
26 def update_xml(xml: XML.Body): XML.Body = |
51 def update_xml(xml: XML.Body): XML.Body = |
27 xml flatMap { |
52 xml flatMap { |
28 case XML.Wrapped_Elem(markup, body1, body2) => |
53 case XML.Wrapped_Elem(markup, body1, body2) => |
29 if (markup.name == Markup.UPDATE) update_xml(body1) else update_xml(body2) |
54 if (markup.name == Markup.UPDATE) update_xml(body1) else update_xml(body2) |
35 } |
60 } |
36 case XML.Elem(_, body) => update_xml(body) |
61 case XML.Elem(_, body) => update_xml(body) |
37 case t => List(t) |
62 case t => List(t) |
38 } |
63 } |
39 |
64 |
40 context.sessions(logic, log = log).foreach(_.process { (args: Dump.Args) => |
65 var seen_theory = Set.empty[String] |
41 progress.echo("Processing theory " + args.print_node + " ...") |
|
42 |
66 |
43 val snapshot = args.snapshot |
67 using(Export.open_database_context(store)) { database_context => |
44 for (node_name <- snapshot.node_files) { |
68 for (session <- sessions_structure.build_topological_order if !exclude(session)) { |
45 val node = snapshot.get_node(node_name) |
69 using(database_context.open_session0(session)) { session_context => |
46 val xml = |
70 for { |
47 snapshot.state.xml_markup(snapshot.version, node_name, |
71 db <- session_context.session_db() |
48 elements = Markup.Elements(Markup.UPDATE, Markup.LANGUAGE)) |
72 theory <- store.read_theories(db, session) |
49 |
73 if !seen_theory(theory) |
50 val source1 = Symbol.encode(XML.content(update_xml(xml))) |
74 } { |
51 if (source1 != Symbol.encode(node.source)) { |
75 seen_theory += theory |
52 progress.echo("Updating " + node_name.path) |
76 val theory_context = session_context.theory(theory) |
53 File.write(node_name.path, source1) |
77 for { |
|
78 theory_snapshot <- Build_Job.read_theory(theory_context) |
|
79 node_name <- theory_snapshot.node_files |
|
80 snapshot = theory_snapshot.switch(node_name) |
|
81 if snapshot.node.is_wellformed_text |
|
82 } { |
|
83 progress.expose_interrupt() |
|
84 val source1 = |
|
85 XML.content(update_xml( |
|
86 snapshot.xml_markup(elements = Markup.Elements(Markup.UPDATE, Markup.LANGUAGE)))) |
|
87 if (source1 != snapshot.node.source) { |
|
88 val path = Path.explode(node_name.node) |
|
89 progress.echo("Updating " + quote(File.standard_path(path))) |
|
90 File.write(path, source1) |
|
91 } |
|
92 } |
|
93 } |
54 } |
94 } |
55 } |
95 } |
56 }) |
96 } |
57 |
97 |
58 context.check_errors |
98 build_results |
59 } |
99 } |
60 |
100 |
61 |
101 |
62 /* Isabelle tool wrapper */ |
102 /* Isabelle tool wrapper */ |
63 |
103 |
69 var requirements = false |
109 var requirements = false |
70 var exclude_session_groups: List[String] = Nil |
110 var exclude_session_groups: List[String] = Nil |
71 var all_sessions = false |
111 var all_sessions = false |
72 var dirs: List[Path] = Nil |
112 var dirs: List[Path] = Nil |
73 var session_groups: List[String] = Nil |
113 var session_groups: List[String] = Nil |
74 var logic = Dump.default_logic |
114 var base_logics: List[String] = Nil |
75 var options = Options.init() |
115 var options = Options.init() |
76 var verbose = false |
116 var verbose = false |
77 var exclude_sessions: List[String] = Nil |
117 var exclude_sessions: List[String] = Nil |
78 |
118 |
79 val getopts = Getopts(""" |
119 val getopts = Getopts(""" |
83 -B NAME include session NAME and all descendants |
123 -B NAME include session NAME and all descendants |
84 -D DIR include session directory and select its sessions |
124 -D DIR include session directory and select its sessions |
85 -R refer to requirements of selected sessions |
125 -R refer to requirements of selected sessions |
86 -X NAME exclude sessions from group NAME and all descendants |
126 -X NAME exclude sessions from group NAME and all descendants |
87 -a select all sessions |
127 -a select all sessions |
88 -b NAME base logic image (default """ + isabelle.quote(Dump.default_logic) + """) |
128 -b NAME additional base logic |
89 -d DIR include session directory |
129 -d DIR include session directory |
90 -g NAME select session group NAME |
130 -g NAME select session group NAME |
91 -o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
131 -o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
92 -u OPT override "update" option: shortcut for "-o update_OPT" |
132 -u OPT override "update" option: shortcut for "-o update_OPT" |
93 -v verbose |
133 -v verbose |
98 "B:" -> (arg => base_sessions = base_sessions ::: List(arg)), |
138 "B:" -> (arg => base_sessions = base_sessions ::: List(arg)), |
99 "D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))), |
139 "D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))), |
100 "R" -> (_ => requirements = true), |
140 "R" -> (_ => requirements = true), |
101 "X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)), |
141 "X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)), |
102 "a" -> (_ => all_sessions = true), |
142 "a" -> (_ => all_sessions = true), |
103 "b:" -> (arg => logic = arg), |
143 "b:" -> (arg => base_logics ::= arg), |
104 "d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
144 "d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
105 "g:" -> (arg => session_groups = session_groups ::: List(arg)), |
145 "g:" -> (arg => session_groups = session_groups ::: List(arg)), |
106 "o:" -> (arg => options = options + arg), |
146 "o:" -> (arg => options = options + arg), |
107 "u:" -> (arg => options = options + ("update_" + arg)), |
147 "u:" -> (arg => options = options + ("update_" + arg)), |
108 "v" -> (_ => verbose = true), |
148 "v" -> (_ => verbose = true), |
110 |
150 |
111 val sessions = getopts(args) |
151 val sessions = getopts(args) |
112 |
152 |
113 val progress = new Console_Progress(verbose = verbose) |
153 val progress = new Console_Progress(verbose = verbose) |
114 |
154 |
115 progress.interrupt_handler { |
155 val results = |
116 update(options, logic, |
156 progress.interrupt_handler { |
117 progress = progress, |
157 update(options, |
118 dirs = dirs, |
158 base_logics = base_logics, |
119 select_dirs = select_dirs, |
159 progress = progress, |
120 selection = Sessions.Selection( |
160 dirs = dirs, |
121 requirements = requirements, |
161 select_dirs = select_dirs, |
122 all_sessions = all_sessions, |
162 selection = Sessions.Selection( |
123 base_sessions = base_sessions, |
163 requirements = requirements, |
124 exclude_session_groups = exclude_session_groups, |
164 all_sessions = all_sessions, |
125 exclude_sessions = exclude_sessions, |
165 base_sessions = base_sessions, |
126 session_groups = session_groups, |
166 exclude_session_groups = exclude_session_groups, |
127 sessions = sessions)) |
167 exclude_sessions = exclude_sessions, |
128 } |
168 session_groups = session_groups, |
|
169 sessions = sessions)) |
|
170 } |
|
171 |
|
172 sys.exit(results.rc) |
129 }) |
173 }) |
130 } |
174 } |