-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-many-glibcs.py
executable file
·1992 lines (1868 loc) · 88 KB
/
build-many-glibcs.py
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python3
# Build many configurations of glibc.
# Copyright (C) 2016-2024 Free Software Foundation, Inc.
# Copyright The GNU Toolchain Authors.
# This file is part of the GNU C Library.
#
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, see
# <https://www.gnu.org/licenses/>.
"""Build many configurations of glibc.
This script takes as arguments a directory name (containing a src
subdirectory with sources of the relevant toolchain components) and a
description of what to do: 'checkout', to check out sources into that
directory, 'bot-cycle', to run a series of checkout and build steps,
'bot', to run 'bot-cycle' repeatedly, 'host-libraries', to build
libraries required by the toolchain, 'compilers', to build
cross-compilers for various configurations, or 'glibcs', to build
glibc for various configurations and run the compilation parts of the
testsuite. Subsequent arguments name the versions of components to
check out (<component>-<version), for 'checkout', or, for actions
other than 'checkout' and 'bot-cycle', name configurations for which
compilers or glibc are to be built.
The 'list-compilers' command prints the name of each available
compiler configuration, without building anything. The 'list-glibcs'
command prints the name of each glibc compiler configuration, followed
by the space, followed by the name of the compiler configuration used
for building this glibc variant.
"""
import argparse
import datetime
import email.mime.text
import email.utils
import json
import os
import re
import shutil
import smtplib
import stat
import subprocess
import sys
import time
import urllib.request
# This is a list of system utilities that are expected to be available
# to this script, and, if a non-zero version is included, the minimum
# version required to work with this sccript.
def get_list_of_required_tools():
global REQUIRED_TOOLS
REQUIRED_TOOLS = {
'awk' : (get_version_awk, (0,0,0)),
'bison' : (get_version, (0,0)),
'flex' : (get_version, (0,0,0)),
'git' : (get_version, (1,8,3)),
'make' : (get_version, (4,0)),
'makeinfo' : (get_version, (0,0)),
'patch' : (get_version, (0,0,0)),
'sed' : (get_version, (0,0)),
'tar' : (get_version, (0,0,0)),
'gzip' : (get_version, (0,0)),
'bzip2' : (get_version_bzip2, (0,0,0)),
'xz' : (get_version, (0,0,0)),
}
try:
subprocess.run
except:
class _CompletedProcess:
def __init__(self, args, returncode, stdout=None, stderr=None):
self.args = args
self.returncode = returncode
self.stdout = stdout
self.stderr = stderr
def _run(*popenargs, input=None, timeout=None, check=False, **kwargs):
assert(timeout is None)
with subprocess.Popen(*popenargs, **kwargs) as process:
try:
stdout, stderr = process.communicate(input)
except:
process.kill()
process.wait()
raise
returncode = process.poll()
if check and returncode:
raise subprocess.CalledProcessError(returncode, popenargs)
return _CompletedProcess(popenargs, returncode, stdout, stderr)
subprocess.run = _run
class Context(object):
"""The global state associated with builds in a given directory."""
def __init__(self, topdir, parallelism, keep, replace_sources, strip,
full_gcc, action, shallow=False):
"""Initialize the context."""
self.topdir = topdir
self.parallelism = parallelism
self.keep = keep
self.replace_sources = replace_sources
self.strip = strip
self.full_gcc = full_gcc
self.shallow = shallow
self.srcdir = os.path.join(topdir, 'src')
self.versions_json = os.path.join(self.srcdir, 'versions.json')
self.build_state_json = os.path.join(topdir, 'build-state.json')
self.bot_config_json = os.path.join(topdir, 'bot-config.json')
self.installdir = os.path.join(topdir, 'install')
self.host_libraries_installdir = os.path.join(self.installdir,
'host-libraries')
self.builddir = os.path.join(topdir, 'build')
self.logsdir = os.path.join(topdir, 'logs')
self.logsdir_old = os.path.join(topdir, 'logs-old')
self.makefile = os.path.join(self.builddir, 'Makefile')
self.wrapper = os.path.join(self.builddir, 'wrapper')
self.save_logs = os.path.join(self.builddir, 'save-logs')
self.script_text = self.get_script_text()
if action not in ('checkout', 'list-compilers', 'list-glibcs'):
self.build_triplet = self.get_build_triplet()
self.glibc_version = self.get_glibc_version()
self.configs = {}
self.glibc_configs = {}
self.makefile_pieces = ['.PHONY: all\n']
self.add_all_configs()
self.load_versions_json()
self.load_build_state_json()
self.status_log_list = []
self.email_warning = False
def get_script_text(self):
"""Return the text of this script."""
with open(sys.argv[0], 'r') as f:
return f.read()
def exec_self(self):
"""Re-execute this script with the same arguments."""
sys.stdout.flush()
os.execv(sys.executable, [sys.executable] + sys.argv)
def get_build_triplet(self):
"""Determine the build triplet with config.guess."""
config_guess = os.path.join(self.component_srcdir('gcc'),
'config.guess')
cg_out = subprocess.run([config_guess], stdout=subprocess.PIPE,
check=True, universal_newlines=True).stdout
return cg_out.rstrip()
def get_glibc_version(self):
"""Determine the glibc version number (major.minor)."""
version_h = os.path.join(self.component_srcdir('glibc'), 'version.h')
with open(version_h, 'r') as f:
lines = f.readlines()
starttext = '#define VERSION "'
for l in lines:
if l.startswith(starttext):
l = l[len(starttext):]
l = l.rstrip('"\n')
m = re.fullmatch(r'([0-9]+)\.([0-9]+)[.0-9]*', l)
return '%s.%s' % m.group(1, 2)
print('error: could not determine glibc version')
exit(1)
def add_all_configs(self):
"""Add all known glibc build configurations."""
self.add_config(arch='aarch64',
os_name='linux-gnu',
extra_glibcs=[{'variant': 'disable-multi-arch',
'cfg': ['--disable-multi-arch']}])
self.add_config(arch='aarch64_be',
os_name='linux-gnu')
self.add_config(arch='arc',
os_name='linux-gnu',
gcc_cfg=['--disable-multilib', '--with-cpu=hs38'])
self.add_config(arch='arc',
os_name='linux-gnuhf',
gcc_cfg=['--disable-multilib', '--with-cpu=hs38_linux'])
self.add_config(arch='arceb',
os_name='linux-gnu',
gcc_cfg=['--disable-multilib', '--with-cpu=hs38'])
self.add_config(arch='alpha',
os_name='linux-gnu')
self.add_config(arch='arm',
os_name='linux-gnueabi',
extra_glibcs=[{'variant': 'v4t',
'ccopts': '-march=armv4t'}])
self.add_config(arch='armeb',
os_name='linux-gnueabi')
self.add_config(arch='armeb',
os_name='linux-gnueabi',
variant='be8',
gcc_cfg=['--with-arch=armv7-a'])
self.add_config(arch='arm',
os_name='linux-gnueabihf',
gcc_cfg=['--with-float=hard', '--with-cpu=arm926ej-s'],
extra_glibcs=[{'variant': 'v7a',
'ccopts': '-march=armv7-a -mfpu=vfpv3'},
{'variant': 'thumb',
'ccopts':
'-mthumb -march=armv7-a -mfpu=vfpv3'},
{'variant': 'v7a-disable-multi-arch',
'ccopts': '-march=armv7-a -mfpu=vfpv3',
'cfg': ['--disable-multi-arch']}])
self.add_config(arch='armeb',
os_name='linux-gnueabihf',
gcc_cfg=['--with-float=hard', '--with-cpu=arm926ej-s'])
self.add_config(arch='armeb',
os_name='linux-gnueabihf',
variant='be8',
gcc_cfg=['--with-float=hard', '--with-arch=armv7-a',
'--with-fpu=vfpv3'])
self.add_config(arch='csky',
os_name='linux-gnuabiv2',
variant='soft',
gcc_cfg=['--disable-multilib'])
self.add_config(arch='csky',
os_name='linux-gnuabiv2',
gcc_cfg=['--with-float=hard', '--disable-multilib'])
self.add_config(arch='hppa',
os_name='linux-gnu')
self.add_config(arch='i686',
os_name='gnu')
self.add_config(arch='loongarch64',
os_name='linux-gnu',
variant='lp64d',
gcc_cfg=['--with-abi=lp64d','--disable-multilib'])
self.add_config(arch='loongarch64',
os_name='linux-gnu',
variant='lp64s',
gcc_cfg=['--with-abi=lp64s','--disable-multilib'])
self.add_config(arch='m68k',
os_name='linux-gnu',
gcc_cfg=['--disable-multilib'])
self.add_config(arch='m68k',
os_name='linux-gnu',
variant='coldfire',
gcc_cfg=['--with-arch=cf', '--disable-multilib'])
self.add_config(arch='m68k',
os_name='linux-gnu',
variant='coldfire-soft',
gcc_cfg=['--with-arch=cf', '--with-cpu=54455',
'--disable-multilib'])
self.add_config(arch='microblaze',
os_name='linux-gnu',
gcc_cfg=['--disable-multilib'])
self.add_config(arch='microblazeel',
os_name='linux-gnu',
gcc_cfg=['--disable-multilib'])
self.add_config(arch='mips64',
os_name='linux-gnu',
gcc_cfg=['--with-mips-plt'],
glibcs=[{'variant': 'n32'},
{'arch': 'mips',
'ccopts': '-mabi=32'},
{'variant': 'n64',
'ccopts': '-mabi=64'}])
self.add_config(arch='mips64',
os_name='linux-gnu',
variant='soft',
gcc_cfg=['--with-mips-plt', '--with-float=soft'],
glibcs=[{'variant': 'n32-soft'},
{'variant': 'soft',
'arch': 'mips',
'ccopts': '-mabi=32'},
{'variant': 'n64-soft',
'ccopts': '-mabi=64'}])
self.add_config(arch='mips64',
os_name='linux-gnu',
variant='nan2008',
gcc_cfg=['--with-mips-plt', '--with-nan=2008',
'--with-arch-64=mips64r2',
'--with-arch-32=mips32r2'],
glibcs=[{'variant': 'n32-nan2008'},
{'variant': 'nan2008',
'arch': 'mips',
'ccopts': '-mabi=32'},
{'variant': 'n64-nan2008',
'ccopts': '-mabi=64'}])
self.add_config(arch='mips64',
os_name='linux-gnu',
variant='nan2008-soft',
gcc_cfg=['--with-mips-plt', '--with-nan=2008',
'--with-arch-64=mips64r2',
'--with-arch-32=mips32r2',
'--with-float=soft'],
glibcs=[{'variant': 'n32-nan2008-soft'},
{'variant': 'nan2008-soft',
'arch': 'mips',
'ccopts': '-mabi=32'},
{'variant': 'n64-nan2008-soft',
'ccopts': '-mabi=64'}])
self.add_config(arch='mips64el',
os_name='linux-gnu',
gcc_cfg=['--with-mips-plt'],
glibcs=[{'variant': 'n32'},
{'arch': 'mipsel',
'ccopts': '-mabi=32'},
{'variant': 'n64',
'ccopts': '-mabi=64'}])
self.add_config(arch='mips64el',
os_name='linux-gnu',
variant='soft',
gcc_cfg=['--with-mips-plt', '--with-float=soft'],
glibcs=[{'variant': 'n32-soft'},
{'variant': 'soft',
'arch': 'mipsel',
'ccopts': '-mabi=32'},
{'variant': 'n64-soft',
'ccopts': '-mabi=64'}])
self.add_config(arch='mips64el',
os_name='linux-gnu',
variant='nan2008',
gcc_cfg=['--with-mips-plt', '--with-nan=2008',
'--with-arch-64=mips64r2',
'--with-arch-32=mips32r2'],
glibcs=[{'variant': 'n32-nan2008'},
{'variant': 'nan2008',
'arch': 'mipsel',
'ccopts': '-mabi=32'},
{'variant': 'n64-nan2008',
'ccopts': '-mabi=64'}])
self.add_config(arch='mips64el',
os_name='linux-gnu',
variant='nan2008-soft',
gcc_cfg=['--with-mips-plt', '--with-nan=2008',
'--with-arch-64=mips64r2',
'--with-arch-32=mips32r2',
'--with-float=soft'],
glibcs=[{'variant': 'n32-nan2008-soft'},
{'variant': 'nan2008-soft',
'arch': 'mipsel',
'ccopts': '-mabi=32'},
{'variant': 'n64-nan2008-soft',
'ccopts': '-mabi=64'}])
self.add_config(arch='mipsisa64r6el',
os_name='linux-gnu',
gcc_cfg=['--with-mips-plt', '--with-nan=2008',
'--with-arch-64=mips64r6',
'--with-arch-32=mips32r6',
'--with-float=hard'],
glibcs=[{'variant': 'n32'},
{'arch': 'mipsisa32r6el',
'ccopts': '-mabi=32'},
{'variant': 'n64',
'ccopts': '-mabi=64'}])
self.add_config(arch='nios2',
os_name='linux-gnu')
self.add_config(arch='or1k',
os_name='linux-gnu',
variant='soft',
gcc_cfg=['--with-multilib-list=mcmov'])
self.add_config(arch='powerpc',
os_name='linux-gnu',
gcc_cfg=['--disable-multilib', '--enable-secureplt'],
extra_glibcs=[{'variant': 'power4',
'ccopts': '-mcpu=power4',
'cfg': ['--with-cpu=power4']}])
self.add_config(arch='powerpc',
os_name='linux-gnu',
variant='soft',
gcc_cfg=['--disable-multilib', '--with-float=soft',
'--enable-secureplt'])
self.add_config(arch='powerpc64',
os_name='linux-gnu',
gcc_cfg=['--disable-multilib', '--enable-secureplt'])
self.add_config(arch='powerpc64le',
os_name='linux-gnu',
gcc_cfg=['--disable-multilib', '--enable-secureplt'],
extra_glibcs=[{'variant': 'disable-multi-arch',
'cfg': ['--disable-multi-arch']}])
self.add_config(arch='riscv32',
os_name='linux-gnu',
variant='rv32imac-ilp32',
gcc_cfg=['--with-arch=rv32imac', '--with-abi=ilp32',
'--disable-multilib'])
self.add_config(arch='riscv32',
os_name='linux-gnu',
variant='rv32imafdc-ilp32',
gcc_cfg=['--with-arch=rv32imafdc', '--with-abi=ilp32',
'--disable-multilib'])
self.add_config(arch='riscv32',
os_name='linux-gnu',
variant='rv32imafdc-ilp32d',
gcc_cfg=['--with-arch=rv32imafdc', '--with-abi=ilp32d',
'--disable-multilib'])
self.add_config(arch='riscv64',
os_name='linux-gnu',
variant='rv64imac-lp64',
gcc_cfg=['--with-arch=rv64imac', '--with-abi=lp64',
'--disable-multilib'])
self.add_config(arch='riscv64',
os_name='linux-gnu',
variant='rv64imafdc-lp64',
gcc_cfg=['--with-arch=rv64imafdc', '--with-abi=lp64',
'--disable-multilib'])
self.add_config(arch='riscv64',
os_name='linux-gnu',
variant='rv64imafdc-lp64d',
gcc_cfg=['--with-arch=rv64imafdc', '--with-abi=lp64d',
'--disable-multilib'])
self.add_config(arch='s390x',
os_name='linux-gnu',
glibcs=[{},
{'arch': 's390', 'ccopts': '-m31'}],
extra_glibcs=[{'variant': 'O3',
'cflags': '-O3'},
{'variant': 'zEC12',
'ccopts': '-march=zEC12'},
{'variant': 'z13',
'ccopts': '-march=z13'},
{'variant': 'z15',
'ccopts': '-march=z15'},
{'variant': 'zEC12-disable-multi-arch',
'ccopts': '-march=zEC12',
'cfg': ['--disable-multi-arch']},
{'variant': 'z13-disable-multi-arch',
'ccopts': '-march=z13',
'cfg': ['--disable-multi-arch']},
{'variant': 'z15-disable-multi-arch',
'ccopts': '-march=z15',
'cfg': ['--disable-multi-arch']}])
self.add_config(arch='sh3',
os_name='linux-gnu')
self.add_config(arch='sh3eb',
os_name='linux-gnu')
self.add_config(arch='sh4',
os_name='linux-gnu')
self.add_config(arch='sh4eb',
os_name='linux-gnu')
self.add_config(arch='sh4',
os_name='linux-gnu',
variant='soft',
gcc_cfg=['--without-fp'])
self.add_config(arch='sh4eb',
os_name='linux-gnu',
variant='soft',
gcc_cfg=['--without-fp'])
self.add_config(arch='sparc64',
os_name='linux-gnu',
glibcs=[{'cfg' : ['--disable-default-pie']},
{'cfg' : ['--disable-default-pie'],
'arch': 'sparcv9',
'ccopts': '-m32 -mlong-double-128 -mcpu=v9'}],
extra_glibcs=[{'variant': 'leon3',
'cfg' : ['--disable-default-pie'],
'arch' : 'sparcv8',
'ccopts' : '-m32 -mlong-double-128 -mcpu=leon3'},
{'variant': 'disable-multi-arch',
'cfg': ['--disable-multi-arch', '--disable-default-pie']},
{'variant': 'disable-multi-arch',
'arch': 'sparcv9',
'ccopts': '-m32 -mlong-double-128 -mcpu=v9',
'cfg': ['--disable-multi-arch', '--disable-default-pie']}])
self.add_config(arch='x86_64',
os_name='linux-gnu',
gcc_cfg=['--with-multilib-list=m64,m32,mx32'],
glibcs=[{},
{'variant': 'x32', 'ccopts': '-mx32'},
{'arch': 'i686', 'ccopts': '-m32 -march=i686'}],
extra_glibcs=[{'variant': 'disable-multi-arch',
'cfg': ['--disable-multi-arch']},
{'variant': 'minimal',
'cfg': ['--disable-multi-arch',
'--disable-profile',
'--disable-timezone-tools',
'--disable-mathvec',
'--disable-build-nscd',
'--disable-nscd']},
{'variant': 'no-pie',
'cfg': ['--disable-default-pie']},
{'variant': 'x32-no-pie',
'ccopts': '-mx32',
'cfg': ['--disable-default-pie']},
{'variant': 'no-pie',
'arch': 'i686',
'ccopts': '-m32 -march=i686',
'cfg': ['--disable-default-pie']},
{'variant': 'disable-multi-arch',
'arch': 'i686',
'ccopts': '-m32 -march=i686',
'cfg': ['--disable-multi-arch']},
{'arch': 'i486',
'ccopts': '-m32 -march=i486'},
{'arch': 'i586',
'ccopts': '-m32 -march=i586'},
{'variant': 'enable-fortify-source',
'cfg': ['--enable-fortify-source']}])
self.add_config(arch='x86_64',
os_name='gnu',
gcc_cfg=['--disable-multilib'])
def add_config(self, **args):
"""Add an individual build configuration."""
cfg = Config(self, **args)
if cfg.name in self.configs:
print('error: duplicate config %s' % cfg.name)
exit(1)
self.configs[cfg.name] = cfg
for c in cfg.all_glibcs:
if c.name in self.glibc_configs:
print('error: duplicate glibc config %s' % c.name)
exit(1)
self.glibc_configs[c.name] = c
def component_srcdir(self, component):
"""Return the source directory for a given component, e.g. gcc."""
return os.path.join(self.srcdir, component)
def component_builddir(self, action, config, component, subconfig=None):
"""Return the directory to use for a build."""
if config is None:
# Host libraries.
assert subconfig is None
return os.path.join(self.builddir, action, component)
if subconfig is None:
return os.path.join(self.builddir, action, config, component)
else:
# glibc build as part of compiler build.
return os.path.join(self.builddir, action, config, component,
subconfig)
def compiler_installdir(self, config):
"""Return the directory in which to install a compiler."""
return os.path.join(self.installdir, 'compilers', config)
def compiler_bindir(self, config):
"""Return the directory in which to find compiler binaries."""
return os.path.join(self.compiler_installdir(config), 'bin')
def compiler_sysroot(self, config):
"""Return the sysroot directory for a compiler."""
return os.path.join(self.compiler_installdir(config), 'sysroot')
def glibc_installdir(self, config):
"""Return the directory in which to install glibc."""
return os.path.join(self.installdir, 'glibcs', config)
def run_builds(self, action, configs):
"""Run the requested builds."""
if action == 'checkout':
self.checkout(configs)
return
if action == 'bot-cycle':
if configs:
print('error: configurations specified for bot-cycle')
exit(1)
self.bot_cycle()
return
if action == 'bot':
if configs:
print('error: configurations specified for bot')
exit(1)
self.bot()
return
if action in ('host-libraries', 'list-compilers',
'list-glibcs') and configs:
print('error: configurations specified for ' + action)
exit(1)
if action == 'list-compilers':
for name in sorted(self.configs.keys()):
print(name)
return
if action == 'list-glibcs':
for config in sorted(self.glibc_configs.values(),
key=lambda c: c.name):
print(config.name, config.compiler.name)
return
self.clear_last_build_state(action)
build_time = datetime.datetime.now(datetime.timezone.utc)
if action == 'host-libraries':
build_components = ('gmp', 'mpfr', 'mpc')
old_components = ()
old_versions = {}
self.build_host_libraries()
elif action == 'compilers':
build_components = ('binutils', 'gcc', 'glibc', 'linux', 'mig',
'gnumach', 'hurd')
old_components = ('gmp', 'mpfr', 'mpc')
old_versions = self.build_state['host-libraries']['build-versions']
self.build_compilers(configs)
else:
build_components = ('glibc',)
old_components = ('gmp', 'mpfr', 'mpc', 'binutils', 'gcc', 'linux',
'mig', 'gnumach', 'hurd')
old_versions = self.build_state['compilers']['build-versions']
if action == 'update-syscalls':
self.update_syscalls(configs)
else:
self.build_glibcs(configs)
self.write_files()
self.do_build()
if configs:
# Partial build, do not update stored state.
return
build_versions = {}
for k in build_components:
if k in self.versions:
build_versions[k] = {'version': self.versions[k]['version'],
'revision': self.versions[k]['revision']}
for k in old_components:
if k in old_versions:
build_versions[k] = {'version': old_versions[k]['version'],
'revision': old_versions[k]['revision']}
self.update_build_state(action, build_time, build_versions)
@staticmethod
def remove_dirs(*args):
"""Remove directories and their contents if they exist."""
for dir in args:
shutil.rmtree(dir, ignore_errors=True)
@staticmethod
def remove_recreate_dirs(*args):
"""Remove directories if they exist, and create them as empty."""
Context.remove_dirs(*args)
for dir in args:
os.makedirs(dir, exist_ok=True)
def add_makefile_cmdlist(self, target, cmdlist, logsdir):
"""Add makefile text for a list of commands."""
commands = cmdlist.makefile_commands(self.wrapper, logsdir)
self.makefile_pieces.append('all: %s\n.PHONY: %s\n%s:\n%s\n' %
(target, target, target, commands))
self.status_log_list.extend(cmdlist.status_logs(logsdir))
def write_files(self):
"""Write out the Makefile and wrapper script."""
mftext = ''.join(self.makefile_pieces)
with open(self.makefile, 'w') as f:
f.write(mftext)
wrapper_text = (
'#!/bin/sh\n'
'prev_base=$1\n'
'this_base=$2\n'
'desc=$3\n'
'dir=$4\n'
'path=$5\n'
'shift 5\n'
'prev_status=$prev_base-status.txt\n'
'this_status=$this_base-status.txt\n'
'this_log=$this_base-log.txt\n'
'date > "$this_log"\n'
'echo >> "$this_log"\n'
'echo "Description: $desc" >> "$this_log"\n'
'printf "%s" "Command:" >> "$this_log"\n'
'for word in "$@"; do\n'
' if expr "$word" : "[]+,./0-9@A-Z_a-z-]\\\\{1,\\\\}\\$" > /dev/null; then\n'
' printf " %s" "$word"\n'
' else\n'
' printf " \'"\n'
' printf "%s" "$word" | sed -e "s/\'/\'\\\\\\\\\'\'/"\n'
' printf "\'"\n'
' fi\n'
'done >> "$this_log"\n'
'echo >> "$this_log"\n'
'echo "Directory: $dir" >> "$this_log"\n'
'echo "Path addition: $path" >> "$this_log"\n'
'echo >> "$this_log"\n'
'record_status ()\n'
'{\n'
' echo >> "$this_log"\n'
' echo "$1: $desc" > "$this_status"\n'
' echo "$1: $desc" >> "$this_log"\n'
' echo >> "$this_log"\n'
' date >> "$this_log"\n'
' echo "$1: $desc"\n'
' exit 0\n'
'}\n'
'check_error ()\n'
'{\n'
' if [ "$1" != "0" ]; then\n'
' record_status FAIL\n'
' fi\n'
'}\n'
'if [ "$prev_base" ] && ! grep -q "^PASS" "$prev_status"; then\n'
' record_status UNRESOLVED\n'
'fi\n'
'if [ "$dir" ]; then\n'
' cd "$dir"\n'
' check_error "$?"\n'
'fi\n'
'if [ "$path" ]; then\n'
' PATH=$path:$PATH\n'
'fi\n'
'"$@" < /dev/null >> "$this_log" 2>&1\n'
'check_error "$?"\n'
'record_status PASS\n')
with open(self.wrapper, 'w') as f:
f.write(wrapper_text)
# Mode 0o755.
mode_exec = (stat.S_IRWXU|stat.S_IRGRP|stat.S_IXGRP|
stat.S_IROTH|stat.S_IXOTH)
os.chmod(self.wrapper, mode_exec)
save_logs_text = (
'#!/bin/sh\n'
'if ! [ -f tests.sum ]; then\n'
' echo "No test summary available."\n'
' exit 0\n'
'fi\n'
'save_file ()\n'
'{\n'
' echo "Contents of $1:"\n'
' echo\n'
' cat "$1"\n'
' echo\n'
' echo "End of contents of $1."\n'
' echo\n'
'}\n'
'save_file tests.sum\n'
'non_pass_tests=$(grep -v "^PASS: " tests.sum | sed -e "s/^PASS: //")\n'
'for t in $non_pass_tests; do\n'
' if [ -f "$t.out" ]; then\n'
' save_file "$t.out"\n'
' fi\n'
'done\n')
with open(self.save_logs, 'w') as f:
f.write(save_logs_text)
os.chmod(self.save_logs, mode_exec)
def do_build(self):
"""Do the actual build."""
cmd = ['make', '-O', '-j%d' % self.parallelism]
subprocess.run(cmd, cwd=self.builddir, check=True)
def build_host_libraries(self):
"""Build the host libraries."""
installdir = self.host_libraries_installdir
builddir = os.path.join(self.builddir, 'host-libraries')
logsdir = os.path.join(self.logsdir, 'host-libraries')
self.remove_recreate_dirs(installdir, builddir, logsdir)
cmdlist = CommandList('host-libraries', self.keep)
self.build_host_library(cmdlist, 'gmp')
self.build_host_library(cmdlist, 'mpfr',
['--with-gmp=%s' % installdir])
self.build_host_library(cmdlist, 'mpc',
['--with-gmp=%s' % installdir,
'--with-mpfr=%s' % installdir])
cmdlist.add_command('done', ['touch', os.path.join(installdir, 'ok')])
self.add_makefile_cmdlist('host-libraries', cmdlist, logsdir)
def build_host_library(self, cmdlist, lib, extra_opts=None):
"""Build one host library."""
srcdir = self.component_srcdir(lib)
builddir = self.component_builddir('host-libraries', None, lib)
installdir = self.host_libraries_installdir
cmdlist.push_subdesc(lib)
cmdlist.create_use_dir(builddir)
cfg_cmd = [os.path.join(srcdir, 'configure'),
'--prefix=%s' % installdir,
'--disable-shared']
if extra_opts:
cfg_cmd.extend (extra_opts)
cmdlist.add_command('configure', cfg_cmd)
cmdlist.add_command('build', ['make'])
cmdlist.add_command('check', ['make', 'check'])
cmdlist.add_command('install', ['make', 'install'])
cmdlist.cleanup_dir()
cmdlist.pop_subdesc()
def build_compilers(self, configs):
"""Build the compilers."""
if not configs:
self.remove_dirs(os.path.join(self.builddir, 'compilers'))
self.remove_dirs(os.path.join(self.installdir, 'compilers'))
self.remove_dirs(os.path.join(self.logsdir, 'compilers'))
configs = sorted(self.configs.keys())
for c in configs:
self.configs[c].build()
def build_glibcs(self, configs):
"""Build the glibcs."""
if not configs:
self.remove_dirs(os.path.join(self.builddir, 'glibcs'))
self.remove_dirs(os.path.join(self.installdir, 'glibcs'))
self.remove_dirs(os.path.join(self.logsdir, 'glibcs'))
configs = sorted(self.glibc_configs.keys())
for c in configs:
self.glibc_configs[c].build()
def update_syscalls(self, configs):
"""Update the glibc syscall lists."""
if not configs:
self.remove_dirs(os.path.join(self.builddir, 'update-syscalls'))
self.remove_dirs(os.path.join(self.logsdir, 'update-syscalls'))
configs = sorted(self.glibc_configs.keys())
for c in configs:
self.glibc_configs[c].update_syscalls()
def load_versions_json(self):
"""Load information about source directory versions."""
if not os.access(self.versions_json, os.F_OK):
self.versions = {}
return
with open(self.versions_json, 'r') as f:
self.versions = json.load(f)
def store_json(self, data, filename):
"""Store information in a JSON file."""
filename_tmp = filename + '.tmp'
with open(filename_tmp, 'w') as f:
json.dump(data, f, indent=2, sort_keys=True)
os.rename(filename_tmp, filename)
def store_versions_json(self):
"""Store information about source directory versions."""
self.store_json(self.versions, self.versions_json)
def set_component_version(self, component, version, explicit, revision):
"""Set the version information for a component."""
self.versions[component] = {'version': version,
'explicit': explicit,
'revision': revision}
self.store_versions_json()
def checkout(self, versions):
"""Check out the desired component versions."""
default_versions = {'binutils': 'vcs-2.42',
'gcc': 'vcs-13',
'glibc': 'vcs-mainline',
'gmp': '6.3.0',
'linux': '6.8',
'mpc': '1.3.1',
'mpfr': '4.2.1',
'mig': 'vcs-mainline',
'gnumach': 'vcs-mainline',
'hurd': 'vcs-mainline'}
use_versions = {}
explicit_versions = {}
for v in versions:
found_v = False
for k in default_versions.keys():
kx = k + '-'
if v.startswith(kx):
vx = v[len(kx):]
if k in use_versions:
print('error: multiple versions for %s' % k)
exit(1)
use_versions[k] = vx
explicit_versions[k] = True
found_v = True
break
if not found_v:
print('error: unknown component in %s' % v)
exit(1)
for k in default_versions.keys():
if k not in use_versions:
if k in self.versions and self.versions[k]['explicit']:
use_versions[k] = self.versions[k]['version']
explicit_versions[k] = True
else:
use_versions[k] = default_versions[k]
explicit_versions[k] = False
os.makedirs(self.srcdir, exist_ok=True)
for k in sorted(default_versions.keys()):
update = os.access(self.component_srcdir(k), os.F_OK)
v = use_versions[k]
if (update and
k in self.versions and
v != self.versions[k]['version']):
if not self.replace_sources:
print('error: version of %s has changed from %s to %s, '
'use --replace-sources to check out again' %
(k, self.versions[k]['version'], v))
exit(1)
shutil.rmtree(self.component_srcdir(k))
update = False
if v.startswith('vcs-'):
revision = self.checkout_vcs(k, v[4:], update)
else:
self.checkout_tar(k, v, update)
revision = v
self.set_component_version(k, v, explicit_versions[k], revision)
if self.get_script_text() != self.script_text:
# Rerun the checkout process in case the updated script
# uses different default versions or new components.
self.exec_self()
def checkout_vcs(self, component, version, update):
"""Check out the given version of the given component from version
control. Return a revision identifier."""
if component == 'binutils':
git_url = 'https://sourceware.org/git/binutils-gdb.git'
if version == 'mainline':
git_branch = 'master'
else:
trans = str.maketrans({'.': '_'})
git_branch = 'binutils-%s-branch' % version.translate(trans)
return self.git_checkout(component, git_url, git_branch, update)
elif component == 'gcc':
if version == 'mainline':
branch = 'master'
else:
branch = 'releases/gcc-%s' % version
return self.gcc_checkout(branch, update)
elif component == 'glibc':
git_url = 'https://sourceware.org/git/glibc.git'
if version == 'mainline':
git_branch = 'master'
else:
git_branch = 'release/%s/master' % version
r = self.git_checkout(component, git_url, git_branch, update)
self.fix_glibc_timestamps()
return r
elif component == 'gnumach':
git_url = 'git://git.savannah.gnu.org/hurd/gnumach.git'
git_branch = 'master'
r = self.git_checkout(component, git_url, git_branch, update)
subprocess.run(['autoreconf', '-i'],
cwd=self.component_srcdir(component), check=True)
return r
elif component == 'mig':
git_url = 'git://git.savannah.gnu.org/hurd/mig.git'
git_branch = 'master'
r = self.git_checkout(component, git_url, git_branch, update)
subprocess.run(['autoreconf', '-i'],
cwd=self.component_srcdir(component), check=True)
return r
elif component == 'hurd':
git_url = 'git://git.savannah.gnu.org/hurd/hurd.git'
git_branch = 'master'
r = self.git_checkout(component, git_url, git_branch, update)
subprocess.run(['autoconf'],
cwd=self.component_srcdir(component), check=True)
return r
else:
print('error: component %s coming from VCS' % component)
exit(1)
def git_checkout(self, component, git_url, git_branch, update):
"""Check out a component from git. Return a commit identifier."""
if update:
subprocess.run(['git', 'remote', 'prune', 'origin'],
cwd=self.component_srcdir(component), check=True)
if self.replace_sources:
subprocess.run(['git', 'clean', '-dxfq'],
cwd=self.component_srcdir(component), check=True)
subprocess.run(['git', 'pull', '-q'],
cwd=self.component_srcdir(component), check=True)
else:
if self.shallow:
depth_arg = ('--depth', '1')
else:
depth_arg = ()
subprocess.run(['git', 'clone', '-q', '-b', git_branch,
*depth_arg, git_url,
self.component_srcdir(component)], check=True)
r = subprocess.run(['git', 'rev-parse', 'HEAD'],
cwd=self.component_srcdir(component),
stdout=subprocess.PIPE,
check=True, universal_newlines=True).stdout
return r.rstrip()
def fix_glibc_timestamps(self):
"""Fix timestamps in a glibc checkout."""
# Ensure that builds do not try to regenerate generated files
# in the source tree.
srcdir = self.component_srcdir('glibc')
# These files have Makefile dependencies to regenerate them in
# the source tree that may be active during a normal build.
# Some other files have such dependencies but do not need to
# be touched because nothing in a build depends on the files
# in question.
for f in ('sysdeps/mach/hurd/bits/errno.h',):
to_touch = os.path.join(srcdir, f)
subprocess.run(['touch', '-c', to_touch], check=True)
for dirpath, dirnames, filenames in os.walk(srcdir):
for f in filenames:
if (f == 'configure' or
f == 'preconfigure' or
f.endswith('-kw.h')):
to_touch = os.path.join(dirpath, f)
subprocess.run(['touch', to_touch], check=True)
def gcc_checkout(self, branch, update):
"""Check out GCC from git. Return the commit identifier."""
if os.access(os.path.join(self.component_srcdir('gcc'), '.svn'),
os.F_OK):
if not self.replace_sources:
print('error: GCC has moved from SVN to git, use '
'--replace-sources to check out again')
exit(1)
shutil.rmtree(self.component_srcdir('gcc'))
update = False
if not update:
self.git_checkout('gcc', 'https://gcc.gnu.org/git/gcc.git',
branch, update)