forked from RTEMS/rtems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wscript
executable file
·1685 lines (1413 loc) · 54.3 KB
/
wscript
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/env python
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (C) 2020 Hesham Almatary <[email protected]>
# Copyright (C) 2019, 2020 embedded brains GmbH (http://www.embedded-brains.de)
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
import pickle
import os
import re
import stat
import string
import sys
try:
import configparser
except:
import ConfigParser as configparser
from waflib.TaskGen import after, before_method, feature
is_windows_host = os.name == "nt" or sys.platform in ["msys", "cygwin"]
default_prefix = "/opt/rtems/6"
compilers = ["gcc", "clang"]
items = {}
bsps = {}
def no_unicode(value):
if sys.version_info[0] > 2:
return value
if isinstance(value, unicode):
return str(value)
return value
class VersionControlKeyHeader:
_content = None
@staticmethod
def write(bld, filename):
if VersionControlKeyHeader._content is None:
from waflib.Build import Context
from waflib.Errors import WafError
content = """/*
* Automatically generated. Do not edit.
*/
#if !defined(_RTEMS_VERSION_VC_KEY_H_)
#define _RTEMS_VERSION_VC_KEY_H_
"""
try:
rev = bld.cmd_and_log("git rev-parse HEAD",
quiet=Context.STDOUT).strip()
content += """#define RTEMS_VERSION_VC_KEY "{}"
""".format(rev)
except WafError:
content += """/* No version control key found; release? */
"""
content += """#endif
"""
VersionControlKeyHeader._content = content
f = bld.bldnode.make_node(filename)
f.parent.mkdir()
try:
if content != f.read():
f.write(VersionControlKeyHeader._content)
except:
f.write(VersionControlKeyHeader._content)
class EnvWrapper(object):
def __init__(self, env):
self._env = env
def __getitem__(self, name):
fields = name.split(":")
v = self._env[fields[0]]
try:
fmt = "{:" + fields[1] + "}"
except IndexError:
fmt = "{}"
if isinstance(v, list):
return " ".join([fmt.format(w) for w in v])
return fmt.format(v)
class Template(string.Template):
idpattern = "[_A-Za-z][_A-Za-z0-9:#]*"
_VAR_PATTERN = re.compile("\$\{?(" + Template.idpattern + ")\}?$")
def _is_enabled_op_and(enabled, enabled_by):
for next_enabled_by in enabled_by:
if not _is_enabled(enabled, next_enabled_by):
return False
return True
def _is_enabled_op_not(enabled, enabled_by):
return not _is_enabled(enabled, enabled_by)
def _is_enabled_op_or(enabled, enabled_by):
for next_enabled_by in enabled_by:
if _is_enabled(enabled, next_enabled_by):
return True
return False
_IS_ENABLED_OP = {
"and": _is_enabled_op_and,
"not": _is_enabled_op_not,
"or": _is_enabled_op_or,
}
def _is_enabled(enabled, enabled_by):
if isinstance(enabled_by, bool):
return enabled_by
if isinstance(enabled_by, list):
return _is_enabled_op_or(enabled, enabled_by)
if isinstance(enabled_by, dict):
key, value = next(iter(enabled_by.items()))
return _IS_ENABLED_OP[key](enabled, value)
return enabled_by in enabled
def _asm_explicit_target(self, node):
task = self.create_task("asm", node,
self.bld.bldnode.make_node(self.target))
try:
self.compiled_tasks.append(task)
except AttributeError:
self.compiled_tasks = [task]
return task
@feature("asm_explicit_target")
@before_method("process_source")
def _enable_asm_explicit_target(self):
self.mappings = dict(self.mappings) # Copy
self.mappings[".S"] = _asm_explicit_target
@after("apply_link")
@feature("cprogram", "cxxprogram")
def process_start_files(self):
if getattr(self, "start_files", False):
self.link_task.dep_nodes.extend(self.bld.start_files)
class Item(object):
def __init__(self, uid, data):
self.uid = uid
self.data = data
self.links = self._init_links
def _init_links(self):
self._links = []
for link in self.data["links"]:
if link["role"] == "build-dependency":
uid = link["uid"]
if not os.path.isabs(uid):
uid = os.path.normpath(
os.path.join(os.path.dirname(self.uid), uid))
self._links.append(items[uid])
self.links = self._yield_links
for link in self._links:
yield link
def _yield_links(self):
for link in self._links:
yield link
def get_enabled_by(self):
return self.data["enabled-by"]
def defaults(self, enabled):
if _is_enabled(enabled, self.get_enabled_by()):
for p in self.links():
p.defaults(enabled)
self.do_defaults(enabled)
def configure(self, conf, cic):
if _is_enabled(conf.env.ENABLE, self.get_enabled_by()):
self.prepare_configure(conf, cic)
for p in self.links():
p.configure(conf, cic)
try:
self.do_configure(conf, cic)
except Exception as e:
raise type(e)(
"Configuration error related to item spec:{}: {}".format(
self.uid, str(e)))
def build(self, bld, bic):
if _is_enabled(bld.env.ENABLE, self.get_enabled_by()):
bic = self.prepare_build(bld, bic)
for p in self.links():
p.build(bld, bic)
try:
self.do_build(bld, bic)
except Exception as e:
raise type(e)(
"Build error related to item spec:{}: {}".format(
self.uid, str(e)))
def do_defaults(self, enabled):
return
def prepare_configure(self, conf, cic):
return
def do_configure(self, conf, cic):
return
def prepare_build(self, bld, bic):
return bic
def do_build(self, bld, bic):
return
def substitute(self, ctx, value):
if isinstance(value, str):
try:
return Template(value).substitute(EnvWrapper(ctx.env))
except Exception as e:
ctx.fatal(
"In item '{}' substitution in '{}' failed: {}".format(
self.uid, value, e))
if isinstance(value, list):
more = []
for item in value:
if isinstance(item, str):
m = _VAR_PATTERN.match(item)
else:
m = None
if m:
more.extend(ctx.env[m.group(1).strip("{}")])
else:
more.append(self.substitute(ctx, item))
return more
return value
def get(self, ctx, name):
return self.substitute(ctx, self.data[name])
def install_target(self, bld):
install_path = self.data["install-path"]
if install_path:
bld.install_files(install_path, self.get(bld, "target"))
def install_files(self, bld):
for install in self.data["install"]:
bld.install_files(install["destination"], install["source"])
def asm(self, bld, bic, source, target=None):
if target is None:
target = os.path.splitext(source)[0] + ".o"
bld(
asflags=self.substitute(bld, self.data["asflags"]),
cppflags=self.substitute(bld, self.data["cppflags"]),
features="asm_explicit_target asm c",
includes=bic.includes +
self.substitute(bld, self.data["includes"]),
source=[source],
target=target,
)
return target
def cc(self, bld, bic, source, target=None, deps=[], cppflags=[]):
if target is None:
target = os.path.splitext(source)[0] + ".o"
bld(
cflags=self.substitute(bld, self.data["cflags"]),
cppflags=cppflags + self.substitute(bld, self.data["cppflags"]),
features="c",
includes=bic.includes +
self.substitute(bld, self.data["includes"]),
rule=
"${CC} ${CFLAGS} ${CPPFLAGS} ${DEFINES_ST:DEFINES} ${CPPPATH_ST:INCPATHS} -c ${SRC[0]} -o ${TGT}",
source=[source] + deps,
target=target,
)
return target
def cxx(self, bld, bic, source, target=None, deps=[], cppflags=[]):
if target is None:
target = os.path.splitext(source)[0] + ".o"
bld(
cppflags=cppflags + self.substitute(bld, self.data["cppflags"]),
cxxflags=self.substitute(bld, self.data["cxxflags"]),
features="cxx",
includes=bic.includes +
self.substitute(bld, self.data["includes"]),
rule=
"${CXX} ${CXXFLAGS} ${CPPFLAGS} ${DEFINES_ST:DEFINES} ${CPPPATH_ST:INCPATHS} -c ${SRC[0]} -o ${TGT}",
source=[source] + deps,
target=target,
)
return target
def link(self, bld, bic, cmd, source, target):
from waflib.Task import Task
class link(Task):
def __init__(self, item, bic, cmd, env):
super(link, self).__init__(self, env=env)
self.cmd = cmd
self.ldflags = bic.ldflags + item.data["ldflags"]
self.stlib = item.data["stlib"]
self.use = (item.data["use-before"] + bic.use +
item.data["use-after"])
def run(self):
cmd = [self.cmd]
cmd.extend(self.env.LINKFLAGS)
cmd.extend([i.abspath() for i in self.inputs])
cmd.append("-o" + self.outputs[0].abspath())
cmd.append("-L.")
cmd.extend(["-l" + l for l in self.stlib])
cmd.extend(["-l" + l for l in self.use])
cmd.extend(self.env.LDFLAGS)
cmd.extend(self.ldflags)
return self.exec_command(cmd)
def scan(self):
return (
[
self.generator.bld.bldnode.make_node("lib" + u + ".a")
for u in self.use
],
[],
)
tsk = link(self, bic, cmd, bld.env)
tsk.set_inputs([bld.bldnode.make_node(s) for s in source])
tsk.set_outputs(bld.bldnode.make_node(target))
bld.add_to_group(tsk)
return target
def link_cc(self, bld, bic, source, target):
return self.link(bld, bic, bld.env.LINK_CC[0], source, target)
def link_cxx(self, bld, bic, source, target):
return self.link(bld, bic, bld.env.LINK_CXX[0], source, target)
def gnatmake(self, bld, bic, objdir, objs, main, target):
from waflib.Task import Task
class gnatmake(Task):
def __init__(self, bld, bic, objdir, objs, main, target, item):
super(gnatmake, self).__init__(self, env=bld.env)
self.objdir = objdir
self.objs = [bld.bldnode.make_node(o) for o in objs]
self.main = bld.path.make_node(main)
self.set_inputs(self.objs + [self.main])
self.set_outputs(bld.bldnode.make_node(target))
self.adaflags = item.data["adaflags"]
self.adaincludes = []
for i in item.data["adaincludes"]:
self.adaincludes.append(bld.bldnode.make_node(i))
self.adaincludes.append(bld.path.make_node(i))
self.ldflags = bic.ldflags + item.data["ldflags"]
self.stlib = item.data["stlib"]
self.use = (item.data["use-before"] + bic.use +
item.data["use-after"])
def run(self):
cwd = self.get_cwd()
cmd = [
self.env.GNATMAKE[0],
"-D",
self.objdir,
"-bargs",
"-Mgnat_main",
"-margs",
]
cmd.extend(self.adaflags)
cmd.extend(["-I" + i.path_from(cwd) for i in self.adaincludes])
cmd.append("-cargs")
cmd.extend(self.env.ABI_FLAGS)
cmd.append("-largs")
cmd.extend([o.path_from(cwd) for o in self.objs])
cmd.extend(self.env.LINKFLAGS)
cmd.extend(self.ldflags)
cmd.append("-L.")
cmd.extend(["-l" + l for l in self.stlib])
cmd.extend(["-l" + l for l in self.use])
cmd.extend(self.env.LDFLAGS)
cmd.extend(["-margs", "-a"])
cmd.append(self.main.abspath())
cmd.append("-o")
cmd.append(self.outputs[0].abspath())
return self.exec_command(cmd)
def scan(self):
return (
[
self.generator.bld.bldnode.make_node("lib" + u + ".a")
for u in self.use
],
[],
)
tsk = gnatmake(bld, bic, objdir, objs, main, target, self)
bld.add_to_group(tsk)
return target
def ar(self, bld, source, target):
bld(rule="${AR} ${ARFLAGS} ${TGT} ${SRC}",
source=source,
target=target)
return target
def gzip(self, bld, source):
target = source + ".gz"
bld(rule="${GZIP} < ${SRC} > ${TGT}", source=source, target=target)
return target
def xz(self, bld, source):
target = source + ".xz"
bld(rule="${XZ} < ${SRC} > ${TGT}", source=source, target=target)
return target
def tar(self, bld, source, remove, target):
def run(task):
import tarfile
tar = tarfile.TarFile(task.outputs[0].abspath(),
"w",
format=tarfile.USTAR_FORMAT)
srcpath = bld.path.abspath() + "/"
bldpath = bld.bldnode.abspath() + "/"
for src in task.inputs:
src = src.abspath()
dst = src
for r in remove:
dst = src.replace(srcpath + r, "").replace(bldpath + r, "")
tar.add(src, dst)
tar.close()
return 0
bld(rule=run, source=source, target=target)
return target
def bin2c(self, bld, source, name=None, target=None):
def run(task):
cmd = [bld.env.BIN2C[0]]
if name is not None:
cmd.extend(["-N", name])
cmd.append(task.inputs[0].abspath())
cmd.append(task.outputs[0].abspath())
return task.exec_command(cmd)
path, base = os.path.split(source)
if target is None:
target = path + "/" + base.replace(".", "-")
target_c = target + ".c"
target_h = target + ".h"
bld(rule=run, source=source, target=[target_c, target_h])
return target_c, target_h
def rtems_syms(self, bld, source, target):
bld(
rule='${RTEMS_SYMS} -e -C ${CC} -c "${CFLAGS}" -o ${TGT} ${SRC}',
source=source,
target=target,
)
return target
def rtems_rap(self, bld, base, objects, libs, target):
def run(task):
cmd = [
bld.env.RTEMS_LD[0],
"-C",
bld.env.CC[0],
"-c",
" ".join(bld.env.CFLAGS),
"-O",
"rap",
"-b",
task.inputs[0].abspath(),
"-e",
"rtems_main",
"-s",
"-o",
]
cmd.append(task.outputs[0].abspath())
cmd.extend([i.abspath() for i in task.inputs[1:]])
cmd.extend(["-l" + l for l in libs])
return task.exec_command(cmd)
bld(rule=run, source=[base] + objects, target=target)
return target
class GroupItem(Item):
def __init__(self, uid, data):
super(GroupItem, self).__init__(uid, data)
def prepare_build(self, bld, bic):
return BuildItemContext(
bic.includes + self.substitute(bld, self.data["includes"]),
bic.cppflags + self.substitute(bld, self.data["cppflags"]),
bic.cflags + self.substitute(bld, self.data["cflags"]),
bic.cxxflags + self.substitute(bld, self.data["cxxflags"]),
self.data["use-before"] + bic.use + self.data["use-after"],
bic.ldflags + self.substitute(bld, self.data["ldflags"]),
bic.objects,
)
def do_build(self, bld, bic):
self.install_files(bld)
class ConfigFileItem(Item):
def __init__(self, uid, data):
super(ConfigFileItem, self).__init__(uid, data)
def do_configure(self, conf, cic):
content = self.substitute(conf, self.data["content"])
f = conf.bldnode.make_node(conf.env.VARIANT + "/" +
self.get(conf, "target"))
f.parent.mkdir()
f.write(content)
conf.env.append_value("cfg_files", f.abspath())
def do_build(self, bld, bic):
self.install_target(bld)
class ConfigHeaderItem(Item):
def __init__(self, uid, data):
super(ConfigHeaderItem, self).__init__(uid, data)
def do_configure(self, conf, cic):
conf.env.include_key = self.data["include-headers"]
conf.write_config_header(
conf.env.VARIANT + "/" + self.get(conf, "target"),
guard=self.data["guard"],
headers=True,
)
conf.env.include_key = None
def do_build(self, bld, bic):
self.install_target(bld)
class StartFileItem(Item):
def __init__(self, uid, data):
super(StartFileItem, self).__init__(uid, data)
def do_build(self, bld, bic):
source = self.data["source"]
if os.path.splitext(source[0])[1] == ".S":
tgt = self.asm(bld, bic, source, self.get(bld, "target"))
else:
tgt = self.cc(bld, bic, source, self.get(bld, "target"))
node = bld.bldnode.make_node(tgt)
try:
bld.start_files.append(node)
except AttributeError:
bld.start_files = [node]
self.install_target(bld)
class ObjectsItem(Item):
def __init__(self, uid, data):
super(ObjectsItem, self).__init__(uid, data)
def prepare_build(self, bld, bic):
return BuildItemContext(
bic.includes + self.substitute(bld, self.data["includes"]),
bic.cppflags + self.substitute(bld, self.data["cppflags"]),
bic.cflags + self.substitute(bld, self.data["cflags"]),
bic.cxxflags + self.substitute(bld, self.data["cxxflags"]),
bic.use,
bic.ldflags,
bic.objects,
)
def do_build(self, bld, bic):
bld.objects(
asflags=bic.cppflags,
cflags=bic.cflags,
cppflags=bic.cppflags,
cxxflags=bic.cxxflags,
includes=bic.includes,
source=self.data["source"],
target=self.uid,
)
bic.objects.append(self.uid)
self.install_files(bld)
class BSPItem(Item):
def __init__(self, uid, data):
super(BSPItem, self).__init__(uid, data)
arch_bsps = bsps.setdefault(data["arch"].strip(), {})
arch_bsps[data["bsp"].strip()] = self
def prepare_build(self, bld, bic):
return BuildItemContext(
bic.includes + bld.env.BSP_INCLUDES +
self.substitute(bld, self.data["includes"]),
self.substitute(bld, self.data["cppflags"]),
bld.env.BSP_CFLAGS + self.substitute(bld, self.data["cflags"]),
[],
[],
[],
[],
)
def do_build(self, bld, bic):
bld(
cflags=bic.cflags,
cppflags=bic.cppflags,
features="c cstlib",
includes=bic.includes,
install_path="${BSP_LIBDIR}",
source=self.data["source"],
target="rtemsbsp",
use=bic.objects,
)
self.install_files(bld)
class LibraryItem(Item):
def __init__(self, uid, data):
super(LibraryItem, self).__init__(uid, data)
def prepare_build(self, bld, bic):
return BuildItemContext(
bic.includes + self.substitute(bld, self.data["includes"]),
bic.cppflags + self.substitute(bld, self.data["cppflags"]),
bic.cflags + self.substitute(bld, self.data["cflags"]),
bic.cxxflags + self.substitute(bld, self.data["cxxflags"]),
bic.use,
bic.ldflags,
[],
)
def do_build(self, bld, bic):
bld(
cflags=bic.cflags,
cppflags=bic.cppflags,
cxxflags=bic.cxxflags,
features="c cxx cstlib",
includes=bic.includes,
install_path=self.data["install-path"],
source=self.data["source"],
target=self.get(bld, "target"),
use=bic.objects,
)
self.install_files(bld)
class TestProgramItem(Item):
def __init__(self, uid, data):
super(TestProgramItem, self).__init__(uid, data)
name = uid.split("/")[-1].upper().replace("-", "_")
self.exclude = "TEST_" + name + "_EXCLUDE"
self.cppflags = "TEST_" + name + "_CPPFLAGS"
def get_enabled_by(self):
return [{"and": [{"not": self.exclude}, self.data["enabled-by"]]}]
def prepare_build(self, bld, bic):
return BuildItemContext(
bic.includes + self.substitute(bld, self.data["includes"]),
bic.cppflags + bld.env[self.cppflags] +
self.substitute(bld, self.data["cppflags"]),
bic.cflags + self.substitute(bld, self.data["cflags"]),
bic.cxxflags + self.substitute(bld, self.data["cxxflags"]),
self.data["use-before"] + bic.use + self.data["use-after"],
bic.ldflags + self.substitute(bld, self.data["ldflags"]),
[],
)
def do_build(self, bld, bic):
bld(
cflags=bic.cflags,
cppflags=bic.cppflags,
cxxflags=bic.cxxflags,
features=self.data["features"],
includes=bic.includes,
install_path=None,
ldflags=bic.ldflags,
source=self.data["source"],
start_files=True,
stlib=self.data["stlib"],
target=self.get(bld, "target"),
use=bic.objects + bic.use,
)
class AdaTestProgramItem(TestProgramItem):
def __init__(self, uid, data):
super(AdaTestProgramItem, self).__init__(uid, data)
def do_build(self, bld, bic):
objs = []
for s in self.data["source"]:
objs.append(self.cc(bld, bic, s))
self.gnatmake(
bld,
bic,
self.data["ada-object-directory"],
objs,
self.data["ada-main"],
self.data["target"],
)
class OptionItem(Item):
def __init__(self, uid, data):
super(OptionItem, self).__init__(uid, data)
def default_value(self, enabled):
value = None
for default in self.data["default"]:
if _is_enabled(enabled, default["enabled-by"]):
value = default["value"]
break
if value is None:
return value
if isinstance(value, list):
return " ".join(value)
if isinstance(value, bool):
return value
return self.data["format"].format(value)
def do_defaults(self, enabled):
value = self.default_value(enabled)
if value is None:
return
description = self.data["description"]
if description:
import textwrap
tw = textwrap.TextWrapper()
tw.drop_whitespace = True
tw.initial_indent = "# "
tw.subsequent_indent = "# "
for line in tw.wrap(description):
print(line)
print("{} = {}".format(self.data["name"], value))
def _do_append_test_cppflags(self, conf, name, state):
conf.env.append_value(
"TEST_" + name.upper().replace("-", "_") + "_CPPFLAGS", state)
def _append_test_cppflags(self, conf, cic, value, arg):
self._do_append_test_cppflags(conf, arg, value)
return value
def _assert_aligned(self, conf, cic, value, arg):
if value is not None and value % arg != 0:
conf.fatal(
"Value '{}' for option '{}' is not aligned by '{}'".format(
value, self.data["name"], arg))
return value
def _assert_eq(self, conf, cic, value, arg):
if value is not None and value != arg:
conf.fatal("Value '{}' for option '{}' is not equal to {}".format(
value, self.data["name"], arg))
return value
def _assert_ge(self, conf, cic, value, arg):
if value is not None and value < arg:
conf.fatal(
"Value '{}' for option '{}' is not greater than or equal to {}"
.format(value, self.data["name"], arg))
return value
def _assert_gt(self, conf, cic, value, arg):
if value is not None and value <= arg:
conf.fatal(
"Value '{}' for option '{}' is not greater than {}".format(
value, self.data["name"], arg))
return value
def _assert_in_interval(self, conf, cic, value, arg):
if value is not None and (value < arg[0] or value > arg[1]):
conf.fatal(
"Value '{}' for option '{}' is not in closed interval [{}, {}]"
.format(value, self.data["name"], arg[0], arg[1]))
return value
def _assert_int8(self, conf, cic, value, arg):
return self._assert_in_interval(conf, cic, value, [-128, 127])
def _assert_int16(self, conf, cic, value, arg):
return self._assert_in_interval(conf, cic, value, [-32768, 32767])
def _assert_int32(self, conf, cic, value, arg):
return self._assert_in_interval(conf, cic, value,
[-2147483648, 2147483647])
def _assert_int64(self, conf, cic, value, arg):
return self._assert_in_interval(
conf, cic, value, [-9223372036854775808, 9223372036854775807])
def _assert_le(self, conf, cic, value, arg):
if value is not None and value > arg:
conf.fatal(
"Value '{}' for option '{}' is not less than or equal to {}".
format(value, self.data["name"], arg))
return value
def _assert_lt(self, conf, cic, value, arg):
if value is not None and value >= arg:
conf.fatal("Value '{}' for option '{}' is not less than {}".format(
value, self.data["name"], arg))
return value
def _assert_ne(self, conf, cic, value, arg):
if value is not None and value == arg:
conf.fatal(
"Value '{}' for option '{}' is not unequal to {}".format(
value, self.data["name"], arg))
return value
def _assert_power_of_two(self, conf, cic, value, arg):
if value is not None and (value <= 0 or (value & (value - 1)) != 0):
conf.fatal(
"Value '{}' for option '{}' is not a power of two".format(
value, self.data["name"]))
return value
def _assert_uint8(self, conf, cic, value, arg):
return self._assert_in_interval(conf, cic, value, [0, 255])
def _assert_uint16(self, conf, cic, value, arg):
return self._assert_in_interval(conf, cic, value, [0, 65535])
def _assert_uint32(self, conf, cic, value, arg):
return self._assert_in_interval(conf, cic, value, [0, 4294967295])
def _assert_uint64(self, conf, cic, value, arg):
return self._assert_in_interval(conf, cic, value,
[0, 18446744073709551615])
def _check_cc(self, conf, cic, value, arg):
result = conf.check_cc(
fragment=arg["fragment"],
cflags=arg["cflags"],
msg="Checking for " + arg["message"],
mandatory=False,
)
return value and result
def _check_cxx(self, conf, cic, value, arg):
result = conf.check_cxx(
fragment=arg["fragment"],
cxxflags=arg["cxxflags"],
msg="Checking for " + arg["message"],
mandatory=False,
)
return value and result
def _define_condition(self, conf, cic, value, arg):
name = self.data["name"] if arg is None else arg
conf.define_cond(name, value)
return value
def _define(self, conf, cic, value, arg):
name = self.data["name"] if arg is None else arg
if value is not None:
conf.define(name, value)
else:
conf.define_cond(name, False)
return value
def _define_unquoted(self, conf, cic, value, arg):
name = self.data["name"] if arg is None else arg
if value is not None:
conf.define(name, value, quote=False)
else:
conf.define_cond(name, False)
return value
def _env_append(self, conf, cic, value, arg):
name = self.data["name"] if arg is None else arg
conf.env.append_value(name, value)
return value
def _env_assign(self, conf, cic, value, arg):
name = self.data["name"] if arg is None else arg
conf.env[name] = value
return value
def _env_enable(self, conf, cic, value, arg):
if value:
name = self.data["name"] if arg is None else arg
conf.env.append_value("ENABLE", name)
return value
def _find_program(self, conf, cic, value, arg):
return conf.find_program(value, path_list=cic.path_list)
def _format_and_define(self, conf, cic, value, arg):
name = self.data["name"] if arg is None else arg
if value is not None:
conf.define(name, self.data["format"].format(value), quote=False)
else:
conf.define_cond(name, False)
return value
def _get_boolean(self, conf, cic, value, arg):
name = self.data["name"]
try:
value = cic.cp.getboolean(conf.variant, name)
cic.add_option(name)
except configparser.NoOptionError:
value = self.default_value(conf.env.ENABLE)
except ValueError as ve:
conf.fatal("Invalid value for configuration option {}: {}".format(
name, ve))
return value
def _get_env(self, conf, cic, value, arg):
return conf.env[arg]
def _get_integer(self, conf, cic, value, arg):
name = self.data["name"]
try:
value = cic.cp.get(conf.variant, name)
cic.add_option(name)
except configparser.NoOptionError:
value = self.default_value(conf.env.ENABLE)
if value is None:
return value
try:
return eval(value)
except Exception as e:
conf.fatal(
"Value '{}' for option '{}' is an invalid integer expression: {}"
.format(value, name, e))
def _get_string(self, conf, cic, value, arg):
name = self.data["name"]
try:
value = cic.cp.get(conf.variant, name)
cic.add_option(name)
value = no_unicode(value)
except configparser.NoOptionError:
value = self.default_value(conf.env.ENABLE)
return value
def _get_string_command_line(self, conf, cic, value, arg):
name = self.data["name"]
try:
value = conf.rtems_options[name]
del conf.rtems_options[name]