forked from jrmarino/synth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
synth.adb
378 lines (340 loc) · 13.1 KB
/
synth.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: License.txt
with Ada.Command_Line;
with Ada.Text_IO;
with Actions;
with PortScan.Pilot;
with Parameters;
with Unix;
procedure synth
is
type mandate_type is (unset, status, help, configure, version, up_system,
prep_system, purge, everything, build, install, force,
just_build, test, status_everything, gen_repo);
mandate : mandate_type := unset;
package CLI renames Ada.Command_Line;
package TIO renames Ada.Text_IO;
package ACT renames Actions;
package PIL renames PortScan.Pilot;
begin
if CLI.Argument_Count = 0 then
ACT.print_version;
return;
end if;
declare
first : constant String := CLI.Argument (1);
comerr : constant String := "Synth command error: ";
badcfg : constant String := "Configuration failed to load.";
regjoe : constant String := "Only the root user can execute that.";
holdon : constant String := "Synth is already running on this system.";
badmnt : constant String := "Builder mounts detected; attempting to " &
"remove them automatically ...";
badwrk : constant String := "Old work directories detected; attempting " &
"to remove them automatically ...";
badcwd : constant String := "Please change the current directory; " &
"Synth is unable to launch from here.";
begin
if first = "help" then
mandate := help;
elsif first = "status" then
mandate := status;
elsif first = "version" then
mandate := version;
elsif first = "configure" then
mandate := configure;
elsif first = "install" then
mandate := install;
elsif first = "build" then
mandate := build;
elsif first = "force" then
mandate := force;
elsif first = "just-build" then
mandate := just_build;
elsif first = "upgrade-system" then
mandate := up_system;
elsif first = "prepare-system" then
mandate := prep_system;
elsif first = "rebuild-repository" then
mandate := gen_repo;
elsif first = "purge-distfiles" then
mandate := purge;
elsif first = "everything" then
mandate := everything;
elsif first = "status-everything" then
mandate := status_everything;
elsif first = "test" then
mandate := test;
end if;
if CLI.Argument_Count > 1 then
case mandate is
when unset =>
ACT.print_version;
TIO.Put_Line (comerr & "'" & first & "' is not a valid keyword.");
return;
when help | configure | version | prep_system | up_system | purge |
everything | status_everything =>
ACT.print_version;
TIO.Put_Line (comerr & "'" & first & "' keyword uses no arguments.");
return;
when others => null;
end case;
PortScan.set_cores;
if Parameters.load_configuration (PortScan.cores_available) then
PIL.set_replicant_platform;
else
TIO.Put_Line (badcfg);
return;
end if;
if not Parameters.all_paths_valid then
return;
end if;
if not PIL.valid_system_root then
return;
end if;
if not PIL.TERM_defined_in_environment then
return;
end if;
if PIL.synth_launch_clash then
TIO.Put_Line (badcwd);
return;
end if;
if PIL.insufficient_privileges then
TIO.Put_Line (regjoe);
return;
end if;
if PIL.already_running then
TIO.Put_Line (holdon);
return;
end if;
if PIL.previous_run_mounts_detected then
TIO.Put_Line (badmnt);
if not PIL.old_mounts_successfully_removed then
return;
end if;
end if;
if PIL.previous_realfs_work_detected then
TIO.Put_Line (badwrk);
if not PIL.old_realfs_work_successfully_removed then
return;
end if;
end if;
if PIL.synthexec_missing then
return;
end if;
if not PIL.ensure_port_index then
-- error messages emitted by ensure_port_index
return;
end if;
if not PIL.store_origins then
-- error messages emitted by store_origins, just exit now
return;
end if;
PIL.create_pidfile;
Unix.ignore_background_tty;
Unix.cone_of_silence (deploy => True);
----------------------------------
-- Multiple argument commands --
----------------------------------
case mandate is
when help | configure | version | prep_system | up_system | purge |
everything | status_everything | gen_repo | unset =>
-- Handled above. Don't use "others" here;
-- we don't want to disable full coverage
null;
when status =>
if PIL.prerequisites_available and then
PIL.scan_stack_of_single_ports (testmode => False) and then
PIL.sanity_check_then_prefail (delete_first => False, dry_run => True)
then
PIL.display_results_of_dry_run;
end if;
when just_build =>
if PIL.prerequisites_available and then
PIL.scan_stack_of_single_ports (testmode => False) and then
PIL.sanity_check_then_prefail
then
PIL.perform_bulk_run (testmode => False);
end if;
when build =>
if PIL.prerequisites_available and then
PIL.scan_stack_of_single_ports (testmode => False) and then
PIL.sanity_check_then_prefail
then
PIL.perform_bulk_run (testmode => False);
if PIL.verify_desire_to_rebuild_repository and then
PIL.write_pkg_repos_configuration_file and then
PIL.rebuild_local_respository (remove_invalid_packages => False) and then
PIL.verify_desire_to_install_packages
then
PIL.upgrade_system_exactly;
end if;
end if;
when force =>
if PIL.prerequisites_available and then
PIL.scan_stack_of_single_ports (testmode => False, always_build => True) and then
PIL.sanity_check_then_prefail (delete_first => True)
then
PIL.perform_bulk_run (testmode => False);
if PIL.verify_desire_to_rebuild_repository and then
PIL.write_pkg_repos_configuration_file and then
PIL.rebuild_local_respository (remove_invalid_packages => False) and then
PIL.verify_desire_to_install_packages
then
PIL.upgrade_system_exactly;
end if;
end if;
when install =>
if PIL.prerequisites_available and then
PIL.scan_stack_of_single_ports (testmode => False) and then
PIL.sanity_check_then_prefail
then
PIL.perform_bulk_run (testmode => False);
if PIL.write_pkg_repos_configuration_file and then
PIL.rebuild_local_respository (remove_invalid_packages => False)
then
PIL.upgrade_system_exactly;
end if;
end if;
when test =>
if PIL.prerequisites_available and then
PIL.scan_stack_of_single_ports (testmode => True, always_build => True) and then
PIL.sanity_check_then_prefail (delete_first => True)
then
if PIL.interact_with_single_builder then
PIL.bulk_run_then_interact_with_final_port;
else
PIL.perform_bulk_run (testmode => True);
end if;
end if;
end case;
else
--------------------------------
-- Single argument commands --
--------------------------------
case mandate is
when build | force | just_build | install | test =>
ACT.print_version;
TIO.Put_Line (comerr & "'" & first &
"' requires at least one argument.");
return;
when version =>
ACT.print_version;
return;
when help =>
ACT.print_help;
return;
when unset =>
ACT.print_version;
TIO.Put_Line (comerr & "'" & first &
"' is not a valid keyword.");
return;
when others => null;
end case;
if PIL.insufficient_privileges then
TIO.Put_Line (regjoe);
return;
end if;
if PIL.already_running then
TIO.Put_Line (holdon);
return;
end if;
PortScan.set_cores;
if Parameters.load_configuration (PortScan.cores_available) then
PIL.set_replicant_platform;
else
TIO.Put_Line (badcfg);
return;
end if;
if not PIL.TERM_defined_in_environment then
return;
end if;
if PIL.synth_launch_clash then
TIO.Put_Line (badcwd);
return;
end if;
if not (mandate = configure) then
if not Parameters.all_paths_valid then
return;
end if;
if not PIL.valid_system_root then
return;
end if;
end if;
if PIL.previous_run_mounts_detected then
TIO.Put_Line (badmnt);
if not PIL.old_mounts_successfully_removed then
return;
end if;
end if;
if PIL.previous_realfs_work_detected then
TIO.Put_Line (badwrk);
if not PIL.old_realfs_work_successfully_removed then
return;
end if;
end if;
if PIL.synthexec_missing then
return;
end if;
if mandate /= configure then
if not PIL.ensure_port_index then
-- error messages emitted by ensure_port_index
return;
end if;
end if;
PIL.create_pidfile;
Unix.ignore_background_tty;
if mandate /= configure then
Unix.cone_of_silence (deploy => True);
end if;
case mandate is
when build | just_build | install | test | version | help |
force | unset =>
-- Handled above. Don't use "others" here;
-- we don't want to disable full coverage
null;
when configure =>
ACT.launch_configure_menu (PortScan.cores_available);
when status =>
PIL.upgrade_system_everything (skip_installation => True, dry_run => True);
when up_system =>
if PIL.write_pkg_repos_configuration_file then
PIL.upgrade_system_everything;
end if;
when prep_system =>
PIL.upgrade_system_everything (skip_installation => True);
when gen_repo =>
if PIL.prerequisites_available and then
PIL.rebuild_local_respository (remove_invalid_packages => True)
then
if PIL.host_pkg8_conservative_upgrade_set then
TIO.Put_Line ("Note: This system's pkg(8) is configured " &
"with CONSERVATIVE_UPGRADE = true");
TIO.Put_Line (" You may wish to toggle that " &
"setting if this is a local repository.");
end if;
end if;
when purge =>
PIL.purge_distfiles;
when everything =>
if PIL.prerequisites_available and then
PIL.fully_scan_ports_tree and then
PIL.sanity_check_then_prefail
then
PIL.perform_bulk_run (testmode => False);
if PIL.rebuild_local_respository (remove_invalid_packages => True) then
null;
end if;
end if;
when status_everything =>
if PIL.prerequisites_available and then
PIL.fully_scan_ports_tree and then
PIL.sanity_check_then_prefail (delete_first => False, dry_run => True)
then
PIL.display_results_of_dry_run;
end if;
end case;
end if;
end;
Unix.cone_of_silence (deploy => False);
PIL.destroy_pidfile;
end synth;