interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / apps / hop / Linux / build.om

608 lines · 11212 bytes Raw Blame History
1om2
2note Linux build driver. Compiler inputs, concatenation and subprocesses are owned by Omega.
3note Bootstrap this file with OMEGA_MV/seed/out/omc; run it from Hop's source root.
4text hb_usage "Usage: linux-build OMEGA_MV [install]\n"
5text hb_error "Hop Linux build failed. The failing tool's diagnostic is above.\n"
6text hb_done "Built build/linux/hop and its matching helper.\n"
7text hb_root "/seed/out/omc"
8text hb_ngsrc "build/linux/ngbuild.om"
9text hb_ngboot "build/linux/ngbuild"
10text hb_ng "build/linux/ng"
11text hb_units "seed/ng/ng.units"
12text hb_sha "/seed/ng/sha256.om"
13text hb_builder "/seed/ng/ngbuild.om"
14text hb_ngunits "/seed/ng/ng.units"
15text hb_s1 "Linux/window.om"
16text hb_s2 "Linux/apps.om"
17text hb_s3 "Linux/core.om"
18text hb_s4 "Linux/main.om"
19text hb_s5 "Linux/chat.om"
20text hb_s6 "Linux/files.om"
21text hb_join "build/linux/hop.om"
22text hb_hop "build/linux/hop"
23text hb_core "Omega/hopcore.om"
24text hb_front "@ng front-ir\n"
25text hb_opt "@ng opt\n"
26text hb_a64 "@ng a64\n"
27text hb_ci "build/linux/core-input.om"
28text hb_ir "build/linux/core.ir"
29text hb_oi "build/linux/opt-input"
30text hb_or "build/linux/core.opt.ir"
31text hb_ai "build/linux/elf-input"
32text hb_co "build/linux/hopcore"
33text hb_build "build"
34text hb_dir "build/linux"
35text hb_empty ""
36text hb_slash "/"
37text hb_gio "/usr/bin/gio"
38text hb_env "/usr/bin/env"
39text hb_curl "/usr/bin/curl"
40text hb_version "version"
41text hb_vflag "--version"
42text hb_glog "build/linux/dependency-gio.txt"
43text hb_elog "build/linux/dependency-env.txt"
44text hb_clog "build/linux/dependency-curl.txt"
45text hb_isrc "Linux/install.om"
46text hb_ibin "build/linux/install"
47text hb_iarg "install"
48text hb_dd "--"
49text hb_git "/usr/bin/git"
50text hb_status "status"
51text hb_porcelain "--porcelain=v1"
52text hb_all "--untracked-files=all"
53text hb_statuslog "build/linux/SOURCE_STATUS"
54text hb_headlog "build/linux/SOURCE_HEAD"
55text hb_revparse "rev-parse"
56text hb_head "HEAD"
57text hb_privatekey "HOP_API_KEY="
58text hb_record "build/linux/BUILD_RECORD"
59text hb_recordtmp "build/linux/BUILD_RECORD.pending"
60text hb_magic "HOPBUILD1\n"
61text hb_compilerhead "/source-commit"
62text hb_sum "/usr/bin/sha256sum"
63text hb_sumlog "build/linux/build-hash.txt"
64text hb_sumversion "build/linux/dependency-sha256sum.txt"
65text hb_newline "\n"
66global hb_tree uchar 4096
67global hb_tn ulong 1
68global hb_cwd uchar 4096
69global hb_cn ulong 1
70global hb_tool uchar 4096
71global hb_tl ulong 1
72global hb_out uchar 4096
73global hb_on ulong 1
74global hb_src uchar 4096
75global hb_sn ulong 1
76global hb_pkt uchar 65536
77global hb_pn ulong 1
78global hb_ac ulong 1
79global hb_input uchar 4096
80global hb_in ulong 1
81global hb_cd ulong 1
82global hb_doins ulong 1
83global hb_initial uchar 128
84global hb_initialn ulong 1
85
86fn hb_fail to void
87k = write 2 hb_error 0 len hb_error
88exit 1
89end
90
91fn hb_path dest int suffix view uchar * to void
92n = get hb_tn 0
93if gt add n len suffix 4096
94hb_fail
95end
96for i ulong n
97if eq dest 0
98put hb_tool i get hb_tree i
99else
100put hb_src i get hb_tree i
101end
102end
103for i ulong len suffix
104if eq dest 0
105put hb_tool add n i get suffix i
106else
107put hb_src add n i get suffix i
108end
109end
110if eq dest 0
111put hb_tl 0 add n len suffix
112else
113put hb_sn 0 add n len suffix
114end
115end
116
117fn hb_arg a view uchar * to void
118p = get hb_pn 0
119if gt add add p 2 len a len hb_pkt
120hb_fail
121end
122put hb_pkt p uchar and len a 255
123put hb_pkt add p 1 uchar shr len a 8
124p = add p 2
125for i ulong len a
126put hb_pkt add p i get a i
127end
128put hb_pn 0 add p len a
129put hb_ac 0 add get hb_ac 0 1
130end
131
132fn hb_absarg a view uchar * to void
133b = new uchar 4096 0
134n = get hb_cn 0
135if gt add add n 1 len a len b
136hb_fail
137end
138for i ulong n
139put b i get hb_cwd i
140end
141put b n 47
142for i ulong len a
143put b add add n 1 i get a i
144end
145hb_arg part b 0 add add n 1 len a
146end
147
148fn hb_reset to void
149put hb_pn 0 2
150put hb_ac 0 0
151put hb_cd 0 0
152put hb_in 0 0
153put hb_on 0 0
154end
155
156fn hb_addtool to void
157b = new uchar 4096 0
158n = get hb_tl 0
159for i ulong n
160put b i get hb_tool i
161end
162hb_arg part b 0 n
163end
164
165fn hb_redirect path view uchar * input bool to void
166if input
167for i ulong len path
168put hb_input i get path i
169end
170put hb_in 0 len path
171else
172for i ulong len path
173put hb_out i get path i
174end
175put hb_on 0 len path
176end
177end
178
179fn hb_run to void
180st = new uchar 4 0
181put hb_pkt 0 uchar and get hb_ac 0 255
182put hb_pkt 1 uchar shr get hb_ac 0 8
183pid = fork
184if eq pid 0
185if gt get hb_in 0 0
186fd = fopen hb_input 0 get hb_in 0 0 0
187if lt fd 0
188exit 126
189end
190k = dupfd int fd 0 0
191if lt k 0
192exit 126
193end
194end
195if gt get hb_on 0 0
196fd = fopen hb_out 0 get hb_on 0 577 420
197if lt fd 0
198exit 126
199end
200k = dupfd int fd 1 0
201if lt k 0
202exit 126
203end
204end
205if ne get hb_cd 0 0
206k = chdir hb_tree 0 get hb_tn 0
207if ne k 0
208exit 126
209end
210end
211k = execprog hb_pkt 0 get hb_pn 0
212exit 127
213end
214if lt pid 0
215hb_fail
216end
217k = waitpid int pid st 0 4 0
218if ne k pid
219hb_fail
220end
221if ne get st 0 0
222hb_fail
223end
224if ne get st 1 0
225hb_fail
226end
227end
228
229fn hb_copy fd int path view uchar * to void
230buf = new uchar 65536 0
231src = fopen path 0 len path 0 0
232if lt src 0
233k = write 2 path 0 len path
234hb_fail
235end
236while true bound 9223372036854775807
237n = read int src buf 0 len buf
238if lt n 0
239hb_fail
240end
241if eq n 0
242break
243end
244p = ulong 0
245while lt p ulong n bound 65536
246k = write fd buf p sub ulong n p
247if le k 0
248hb_fail
249end
250p = add p ulong k
251end
252end
253k = fclose int src
254end
255
256fn hb_sourcecopy fd int to void
257b = new uchar 4096 0
258n = get hb_sn 0
259for i ulong n
260put b i get hb_src i
261end
262hb_copy fd part b 0 n
263end
264
265fn hb_chmod path view uchar * to void
266fd = fopen path 0 len path 0 0
267if lt fd 0
268hb_fail
269end
270k = fchmod int fd 493
271if ne k 0
272hb_fail
273end
274k = fclose int fd
275end
276
277fn hb_compile input view uchar * output view uchar * to void
278hb_reset
279hb_path 0 hb_root
280hb_addtool
281hb_redirect input true
282hb_redirect output false
283hb_run
284hb_chmod output
285end
286
287fn hb_stage prefix view uchar * input view uchar * feed view uchar * to void
288fd = fopen feed 0 len feed 577 420
289if lt fd 0
290hb_fail
291end
292k = write int fd prefix 0 len prefix
293if ne k long len prefix
294hb_fail
295end
296hb_copy int fd input
297k = fclose int fd
298end
299
300fn hb_ngrun feed view uchar * output view uchar * to void
301hb_reset
302hb_absarg hb_ng
303hb_redirect feed true
304hb_redirect output false
305hb_run
306end
307
308fn hb_dependency tool view uchar * arg view uchar * output view uchar * to void
309hb_reset
310hb_arg tool
311hb_arg arg
312hb_redirect output false
313hb_run
314end
315
316fn hb_session to void
317e = new uchar 131072 0
318hb_arg hb_env
319hb_arg hb_dd
320for i ulong ulong envcnt bound 9223372036854775807
321n = envread i e 0 len e
322if lt n 0
323hb_fail
324end
325privatev = ge ulong n len hb_privatekey
326if privatev
327for j ulong len hb_privatekey
328if ne get e j get hb_privatekey j
329privatev = false
330break
331end
332end
333end
334if not privatev
335hb_arg part e 0 ulong n
336end
337end
338end
339
340fn hb_provenance to void
341statusv = new uchar 1 0
342hb_reset
343hb_arg hb_git
344hb_arg hb_status
345hb_arg hb_porcelain
346hb_arg hb_all
347hb_redirect hb_statuslog false
348hb_run
349fd = fopen hb_statuslog 0 len hb_statuslog 0 0
350if lt fd 0
351hb_fail
352end
353n = read int fd statusv 0 1
354k = fclose int fd
355if lt n 0
356hb_fail
357end
358if ne n 0
359note Development builds are useful but must never acquire an installable source stamp.
360fd = fopen hb_headlog 0 len hb_headlog 577 420
361if lt fd 0
362hb_fail
363end
364k = fclose int fd
365ret
366end
367hb_reset
368hb_arg hb_git
369hb_arg hb_revparse
370hb_arg hb_head
371hb_redirect hb_headlog false
372hb_run
373end
374
375fn hb_hash fd int path view uchar * to void
376hb_reset
377hb_arg hb_sum
378hb_redirect path true
379hb_redirect hb_sumlog false
380hb_run
381b = new uchar 66 0
382src = fopen hb_sumlog 0 len hb_sumlog 0 0
383if lt src 0
384hb_fail
385end
386n = read int src b 0 len b
387k = fclose int src
388if ne n 66
389hb_fail
390end
391for i ulong 64
392c = get b i
393digit = and ge c 48 le c 57
394letter = and ge c 97 le c 102
395if not or digit letter
396hb_fail
397end
398end
399k = write fd b 0 64
400if ne k 64
401hb_fail
402end
403k = write fd hb_newline 0 1
404if ne k 1
405hb_fail
406end
407end
408
409fn hb_recordbuild to void
410b = new uchar 1 0
411src = fopen hb_headlog 0 len hb_headlog 0 0
412if lt src 0
413hb_fail
414end
415n = read int src b 0 1
416k = fclose int src
417if eq n 0
418ret
419end
420if lt n 0
421hb_fail
422end
423fd = fopen hb_recordtmp 0 len hb_recordtmp 577 420
424if lt fd 0
425hb_fail
426end
427k = write int fd hb_magic 0 len hb_magic
428if ne k long len hb_magic
429hb_fail
430end
431hb_copy int fd hb_headlog
432hb_path 1 hb_compilerhead
433hb_sourcecopy int fd
434hb_path 1 hb_root
435p = new uchar 4096 0
436for i ulong get hb_sn 0
437put p i get hb_src i
438end
439hb_hash int fd part p 0 get hb_sn 0
440hb_hash int fd hb_hop
441hb_hash int fd hb_co
442k = fsync int fd
443if ne k 0
444hb_fail
445end
446k = fclose int fd
447if ne k 0
448hb_fail
449end
450hb_reset
451hb_arg hb_recordtmp
452hb_arg hb_record
453put hb_pkt 0 2
454put hb_pkt 1 0
455k = renames hb_pkt 0 get hb_pn 0 0
456if ne k 0
457hb_fail
458end
459end
460
461fn hb_checksource first bool to void
462b = new uchar 128 0
463src = fopen hb_headlog 0 len hb_headlog 0 0
464if lt src 0
465hb_fail
466end
467n = read int src b 0 len b
468k = fclose int src
469if or lt n 0 ge n long len b
470hb_fail
471end
472if first
473put hb_initialn 0 ulong n
474for i ulong ulong n
475put hb_initial i get b i
476end
477else
478stable = eq ulong n get hb_initialn 0
479if stable
480for i ulong ulong n
481if ne get hb_initial i get b i
482stable = false
483end
484end
485end
486if not stable
487note A source change during compilation cannot acquire a successful proof.
488fd = fopen hb_headlog 0 len hb_headlog 577 420
489if lt fd 0
490hb_fail
491end
492k = fclose int fd
493end
494end
495end
496
497fn main to int
498b = new uchar 4096 0
499if and ne argcnt 2 ne argcnt 3
500k = write 2 hb_usage 0 len hb_usage
501ret 2
502end
503n = argread 1 b 0 len b
504if or le n 0 ge n long len b
505hb_fail
506end
507if ne get b 0 47
508hb_fail
509end
510for i ulong ulong n
511put hb_tree i get b i
512end
513put hb_tn 0 ulong n
514if eq argcnt 3
515n = argread 2 b 0 len b
516if ne n long len hb_iarg
517k = write 2 hb_usage 0 len hb_usage
518ret 2
519end
520for i ulong len hb_iarg
521if ne get b i get hb_iarg i
522k = write 2 hb_usage 0 len hb_usage
523ret 2
524end
525end
526put hb_doins 0 1
527end
528n = cwd b 0 len b
529if le n 0
530hb_fail
531end
532put hb_cn 0 sub ulong n 1
533for i ulong get hb_cn 0
534put hb_cwd i get b i
535end
536k = makedir hb_build 0 len hb_build 493
537if and lt k 0 ne k -17
538hb_fail
539end
540k = makedir hb_dir 0 len hb_dir 493
541if and lt k 0 ne k -17
542hb_fail
543end
544note Invalidate the previous proof before any executable can be overwritten.
545fd = fopen hb_record 0 len hb_record 577 420
546if lt fd 0
547hb_fail
548end
549k = fclose int fd
550hb_provenance
551hb_checksource true
552fd = fopen hb_ngsrc 0 len hb_ngsrc 577 420
553if lt fd 0
554hb_fail
555end
556hb_path 1 hb_sha
557hb_sourcecopy int fd
558hb_path 1 hb_builder
559hb_sourcecopy int fd
560k = fclose int fd
561hb_compile hb_ngsrc hb_ngboot
562hb_reset
563hb_absarg hb_ngboot
564hb_arg hb_build
565hb_path 0 hb_root
566hb_addtool
567hb_arg hb_units
568hb_absarg hb_ng
569put hb_cd 0 1
570hb_run
571hb_chmod hb_ng
572hb_stage hb_front hb_core hb_ci
573hb_ngrun hb_ci hb_ir
574hb_stage hb_opt hb_ir hb_oi
575hb_ngrun hb_oi hb_or
576hb_stage hb_a64 hb_or hb_ai
577hb_ngrun hb_ai hb_co
578hb_chmod hb_co
579fd = fopen hb_join 0 len hb_join 577 420
580if lt fd 0
581hb_fail
582end
583hb_copy int fd hb_s1
584hb_copy int fd hb_s2
585hb_copy int fd hb_s3
586hb_copy int fd hb_s5
587hb_copy int fd hb_s6
588hb_copy int fd hb_s4
589k = fclose int fd
590hb_compile hb_join hb_hop
591hb_compile hb_isrc hb_ibin
592hb_dependency hb_gio hb_version hb_glog
593hb_dependency hb_env hb_vflag hb_elog
594hb_dependency hb_curl hb_vflag hb_clog
595hb_dependency hb_sum hb_vflag hb_sumversion
596hb_provenance
597hb_checksource false
598hb_recordbuild
599k = write 1 hb_done 0 len hb_done
600if ne get hb_doins 0 0
601hb_reset
602hb_session
603hb_absarg hb_ibin
604hb_absarg hb_empty
605hb_run
606end
607ret 0
608end