author | wenzelm |
Fri, 16 Mar 2018 22:20:09 +0100 | |
changeset 67884 | 43af581d7d8e |
parent 67883 | 171e7735ce25 |
child 67885 | 839a624aabb9 |
permissions | -rw-r--r-- |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Pure/Tools/server_commands.scala |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
3 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
4 |
Miscellaneous Isabelle server commands. |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
6 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
8 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
9 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
10 |
object Server_Commands |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
11 |
{ |
67863 | 12 |
def default_preferences: String = Options.read_prefs() |
67883 | 13 |
def default_qualifier: String = Sessions.DRAFT |
14 |
||
15 |
def unapply_name_pos(json: JSON.T): Option[(String, Position.T)] = |
|
16 |
json match { |
|
17 |
case JSON.Value.String(name) => Some((name, Position.none)) |
|
18 |
case JSON.Object(map) if map.keySet == Set("name", "pos") => |
|
19 |
(map("name"), map("pos")) match { |
|
20 |
case (JSON.Value.String(name), Position.JSON(pos)) => Some((name, pos)) |
|
21 |
case _ => None |
|
22 |
} |
|
23 |
case _ => None |
|
24 |
} |
|
67863 | 25 |
|
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
26 |
object Session_Build |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
27 |
{ |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
28 |
sealed case class Args( |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
29 |
session: String, |
67863 | 30 |
preferences: String = default_preferences, |
67862 | 31 |
options: List[String] = Nil, |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
32 |
dirs: List[String] = Nil, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
33 |
ancestor_session: String = "", |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
34 |
all_known: Boolean = false, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
35 |
focus_session: Boolean = false, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
36 |
required_session: Boolean = false, |
67853 | 37 |
system_mode: Boolean = false, |
38 |
verbose: Boolean = false) |
|
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
39 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
40 |
def unapply(json: JSON.T): Option[Args] = |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
41 |
for { |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
42 |
session <- JSON.string(json, "session") |
67863 | 43 |
preferences <- JSON.string_default(json, "preferences", default_preferences) |
67862 | 44 |
options <- JSON.list_default(json, "options", JSON.Value.String.unapply _) |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
45 |
dirs <- JSON.list_default(json, "dirs", JSON.Value.String.unapply _) |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
46 |
ancestor_session <- JSON.string_default(json, "ancestor_session") |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
47 |
all_known <- JSON.bool_default(json, "all_known") |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
48 |
focus_session <- JSON.bool_default(json, "focus_session") |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
49 |
required_session <- JSON.bool_default(json, "required_session") |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
50 |
system_mode <- JSON.bool_default(json, "system_mode") |
67853 | 51 |
verbose <- JSON.bool_default(json, "verbose") |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
52 |
} |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
53 |
yield { |
67862 | 54 |
Args(session, preferences = preferences, options = options, dirs = dirs, |
55 |
ancestor_session = ancestor_session, all_known = all_known, focus_session = focus_session, |
|
56 |
required_session = required_session, system_mode = system_mode, verbose = verbose) |
|
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
57 |
} |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
58 |
|
67861 | 59 |
def command(progress: Progress, args: Args) |
60 |
: (JSON.Object.T, Build.Results, Sessions.Base_Info) = |
|
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
61 |
{ |
67862 | 62 |
val options = Options.init(prefs = args.preferences, opts = args.options) |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
63 |
val dirs = args.dirs.map(Path.explode(_)) |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
64 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
65 |
val base_info = |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
66 |
Sessions.base_info(options, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
67 |
args.session, |
67852
f701a1d5d852
allow cancellation of Sessions.deps/base_info via progress.stopped (progress.echo only happens for options like "verbose");
wenzelm
parents:
67850
diff
changeset
|
68 |
progress = progress, |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
69 |
dirs = dirs, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
70 |
ancestor_session = proper_string(args.ancestor_session), |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
71 |
all_known = args.all_known, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
72 |
focus_session = args.focus_session, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
73 |
required_session = args.required_session) |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
74 |
val base = base_info.check_base |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
75 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
76 |
val results = |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
77 |
Build.build(options, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
78 |
progress = progress, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
79 |
build_heap = true, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
80 |
system_mode = args.system_mode, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
81 |
dirs = dirs, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
82 |
infos = base_info.infos, |
67853 | 83 |
verbose = args.verbose, |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
84 |
sessions = List(args.session)) |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
85 |
|
67858 | 86 |
val sessions_order = |
87 |
base_info.sessions_structure.imports_topological_order.zipWithIndex. |
|
88 |
toMap.withDefaultValue(-1) |
|
89 |
||
90 |
val results_json = |
|
91 |
JSON.Object( |
|
92 |
"return_code" -> results.rc, |
|
93 |
"sessions" -> |
|
94 |
results.sessions.toList.sortBy(sessions_order).map(session => |
|
95 |
JSON.Object( |
|
96 |
"session" -> session, |
|
97 |
"return_code" -> results(session).rc, |
|
98 |
"timeout" -> results(session).timeout, |
|
99 |
"timing" -> results(session).timing.json))) |
|
100 |
||
101 |
if (results.ok) (results_json, results, base_info) |
|
102 |
else throw new Server.Error("Session build failed: return code " + results.rc, results_json) |
|
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
103 |
} |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
104 |
} |
67869 | 105 |
|
106 |
object Session_Start |
|
107 |
{ |
|
108 |
sealed case class Args( |
|
109 |
build: Session_Build.Args, |
|
110 |
print_mode: List[String] = Nil) |
|
111 |
||
112 |
def unapply(json: JSON.T): Option[Args] = |
|
113 |
for { |
|
114 |
build <- Session_Build.unapply(json) |
|
115 |
print_mode <- JSON.list_default(json, "print_mode", JSON.Value.String.unapply _) |
|
116 |
} |
|
117 |
yield Args(build = build, print_mode = print_mode) |
|
118 |
||
119 |
def command(progress: Progress, args: Args, log: Logger = No_Logger) |
|
67878 | 120 |
: (JSON.Object.T, (String, Thy_Resources.Session)) = |
67869 | 121 |
{ |
122 |
val base_info = Session_Build.command(progress, args.build)._3 |
|
123 |
||
124 |
val session = |
|
125 |
Thy_Resources.start_session( |
|
126 |
base_info.options, |
|
127 |
base_info.session, |
|
128 |
session_dirs = base_info.dirs, |
|
129 |
session_base = Some(base_info.check_base), |
|
130 |
print_mode = args.print_mode, |
|
131 |
progress = progress, |
|
132 |
log = log) |
|
133 |
||
134 |
val id = Library.UUID() |
|
135 |
val res = JSON.Object("session_name" -> base_info.session, "session_id" -> id) |
|
136 |
||
67871
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
137 |
(res, id -> session) |
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
138 |
} |
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
139 |
} |
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
140 |
|
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
141 |
object Session_Stop |
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
142 |
{ |
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
143 |
def unapply(json: JSON.T): Option[String] = |
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
144 |
JSON.string(json, "session_id") |
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
145 |
|
67878 | 146 |
def command(session: Thy_Resources.Session): (JSON.Object.T, Process_Result) = |
67871
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
147 |
{ |
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
148 |
val result = session.stop() |
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
149 |
val result_json = JSON.Object("return_code" -> result.rc) |
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
150 |
|
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
151 |
if (result.ok) (result_json, result) |
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
152 |
else throw new Server.Error("Session shutdown failed: return code " + result.rc, result_json) |
67869 | 153 |
} |
154 |
} |
|
67883 | 155 |
|
156 |
object Use_Theories |
|
157 |
{ |
|
158 |
sealed case class Args( |
|
159 |
session_id: String, |
|
160 |
theories: List[(String, Position.T)], |
|
161 |
qualifier: String = default_qualifier, |
|
162 |
master_dir: String = "") |
|
163 |
||
164 |
def unapply(json: JSON.T): Option[Args] = |
|
165 |
for { |
|
166 |
session_id <- JSON.string(json, "session_id") |
|
167 |
theories <- JSON.list(json, "theories", unapply_name_pos _) |
|
168 |
qualifier <- JSON.string_default(json, "qualifier", default_qualifier) |
|
169 |
master_dir <- JSON.string_default(json, "master_dir") |
|
170 |
} |
|
171 |
yield Args(session_id, theories, qualifier = qualifier, master_dir = master_dir) |
|
172 |
||
67884
43af581d7d8e
unload_theories after consolidation -- reset node_required;
wenzelm
parents:
67883
diff
changeset
|
173 |
def command(args: Args, |
43af581d7d8e
unload_theories after consolidation -- reset node_required;
wenzelm
parents:
67883
diff
changeset
|
174 |
session: Thy_Resources.Session, |
43af581d7d8e
unload_theories after consolidation -- reset node_required;
wenzelm
parents:
67883
diff
changeset
|
175 |
id: String = Library.UUID(), |
43af581d7d8e
unload_theories after consolidation -- reset node_required;
wenzelm
parents:
67883
diff
changeset
|
176 |
progress: Progress = No_Progress): (JSON.Object.T, Thy_Resources.Theories_Result) = |
67883 | 177 |
{ |
178 |
val result = |
|
179 |
session.use_theories(args.theories, qualifier = args.qualifier, |
|
67884
43af581d7d8e
unload_theories after consolidation -- reset node_required;
wenzelm
parents:
67883
diff
changeset
|
180 |
master_dir = args.master_dir, id = id, progress = progress) |
67883 | 181 |
|
182 |
val result_json = |
|
183 |
JSON.Object( |
|
184 |
"ok" -> result.ok, |
|
185 |
"nodes" -> |
|
186 |
(for ((name, st) <- result.nodes) yield |
|
187 |
JSON.Object("node_name" -> name.node, "theory" -> name.theory, "status" -> st.json))) |
|
188 |
||
189 |
(result_json, result) |
|
190 |
} |
|
191 |
} |
|
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
192 |
} |