forked from SCons/scons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
1801 lines (1511 loc) · 65.3 KB
/
__init__.py
File metadata and controls
1801 lines (1511 loc) · 65.3 KB
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
# MIT License
#
# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""The Node package for the SCons software construction utility.
This is, in many ways, the heart of SCons.
A Node is where we encapsulate all of the dependency information about
any thing that SCons can build, or about any thing which SCons can use
to build some other thing. The canonical "thing," of course, is a file,
but a Node can also represent something remote (like a web page) or
something completely abstract (like an Alias).
Each specific type of "thing" is specifically represented by a subclass
of the Node base class: Node.FS.File for files, Node.Alias for aliases,
etc. Dependency information is kept here in the base class, and
information specific to files/aliases/etc. is in the subclass. The
goal, if we've done this correctly, is that any type of "thing" should
be able to depend on any other type of "thing."
"""
from __future__ import annotations
import collections
import copy
from itertools import chain, zip_longest
from typing import Any, Callable, TYPE_CHECKING
import SCons.Debug
import SCons.Executor
import SCons.Memoize
from SCons.compat import NoSlotsPyPy
from SCons.Debug import logInstanceCreation, Trace
from SCons.Executor import Executor
from SCons.Util import hash_signature, is_List, UniqueList, render_tree
if TYPE_CHECKING:
from SCons.Builder import BuilderBase
from SCons.Environment import Base as Environment
from SCons.Scanner import ScannerBase
from SCons.SConsign import SConsignEntry
print_duplicate = 0
def classname(obj):
return str(obj.__class__).split('.')[-1]
# Set to false if we're doing a dry run. There's more than one of these
# little treats
do_store_info = True
# Node states
#
# These are in "priority" order, so that the maximum value for any
# child/dependency of a node represents the state of that node if
# it has no builder of its own. The canonical example is a file
# system directory, which is only up to date if all of its children
# were up to date.
no_state = 0
pending = 1
executing = 2
up_to_date = 3
executed = 4
failed = 5
StateString = {
0 : "no_state",
1 : "pending",
2 : "executing",
3 : "up_to_date",
4 : "executed",
5 : "failed",
}
# controls whether implicit dependencies are cached:
implicit_cache = 0
# controls whether implicit dep changes are ignored:
implicit_deps_unchanged = 0
# controls whether the cached implicit deps are ignored:
implicit_deps_changed = 0
# A variable that can be set to an interface-specific function be called
# to annotate a Node with information about its creation.
def do_nothing_node(node) -> None: pass
Annotate = do_nothing_node
# global set for recording all processed SContruct/SConscript nodes
SConscriptNodes: set[Node] = set()
# Gets set to 'True' if we're running in interactive mode. Is
# currently used to release parts of a target's info during
# clean builds and update runs (see release_target_info).
interactive = False
def is_derived_none(node):
raise NotImplementedError
def is_derived_node(node) -> bool:
"""
Returns true if this node is derived (i.e. built).
"""
return node.has_builder() or node.side_effect
_is_derived_map = {0 : is_derived_none,
1 : is_derived_node}
def exists_none(node) -> bool:
raise NotImplementedError
def exists_always(node) -> bool:
return True
def exists_base(node) -> bool:
return node.stat() is not None
def exists_entry(node) -> bool:
"""Return if the Entry exists. Check the file system to see
what we should turn into first. Assume a file if there's no
directory."""
node.disambiguate()
return _exists_map[node._func_exists](node)
def exists_file(node) -> bool:
# Duplicate from source path if we are set up to do this.
if node.duplicate and not node.is_derived() and not node.linked:
src = node.srcnode()
if src is not node:
# At this point, src is meant to be copied in a variant directory.
src = src.rfile()
if src.get_abspath() != node.get_abspath():
if src.exists():
node.do_duplicate(src)
# Can't return 1 here because the duplication might
# not actually occur if the -n option is being used.
else:
# The source file does not exist. Make sure no old
# copy remains in the variant directory.
if print_duplicate:
print("dup: no src for %s, unlinking old variant copy" % node)
if exists_base(node) or node.islink():
node.fs.unlink(node.get_internal_path())
# Return None explicitly because the Base.exists() call
# above will have cached its value if the file existed.
return None
return exists_base(node)
_exists_map = {0 : exists_none,
1 : exists_always,
2 : exists_base,
3 : exists_entry,
4 : exists_file}
def rexists_none(node):
raise NotImplementedError
def rexists_node(node):
return node.exists()
def rexists_base(node):
return node.rfile().exists()
_rexists_map = {0 : rexists_none,
1 : rexists_node,
2 : rexists_base}
def get_contents_none(node):
raise NotImplementedError
def get_contents_entry(node):
"""Fetch the contents of the entry. Returns the exact binary
contents of the file."""
try:
node = node.disambiguate(must_exist=True)
except SCons.Errors.UserError:
# There was nothing on disk with which to disambiguate
# this entry. Leave it as an Entry, but return a null
# string so calls to get_contents() in emitters and the
# like (e.g. in qt.py) don't have to disambiguate by hand
# or catch the exception.
return ''
else:
return _get_contents_map[node._func_get_contents](node)
def get_contents_dir(node):
"""Return content signatures and names of all our children
separated by new-lines. Ensure that the nodes are sorted."""
contents = []
for n in sorted(node.children(), key=lambda t: t.name):
contents.append('%s %s\n' % (n.get_csig(), n.name))
return ''.join(contents)
def get_contents_file(node):
if not node.rexists():
return b''
fname = node.rfile().get_abspath()
try:
with open(fname, "rb") as fp:
contents = fp.read()
except OSError as e:
if not e.filename:
e.filename = fname
raise
return contents
_get_contents_map = {0 : get_contents_none,
1 : get_contents_entry,
2 : get_contents_dir,
3 : get_contents_file}
def target_from_source_none(node, prefix, suffix, splitext):
raise NotImplementedError
def target_from_source_base(node, prefix, suffix, splitext):
return node.dir.Entry(prefix + splitext(node.name)[0] + suffix)
_target_from_source_map = {0 : target_from_source_none,
1 : target_from_source_base}
#
# The new decider subsystem for Nodes
#
# We would set and overwrite the changed_since_last_build function
# before, but for being able to use slots (less memory!) we now have
# a dictionary of the different decider functions. Then in the Node
# subclasses we simply store the index to the decider that should be
# used by it.
#
#
# First, the single decider functions
#
def changed_since_last_build_node(node, target, prev_ni, repo_node=None) -> bool:
"""
Must be overridden in a specific subclass to return True if this
Node (a dependency) has changed since the last time it was used
to build the specified target. prev_ni is this Node's state (for
example, its file timestamp, length, maybe content signature)
as of the last time the target was built.
Note that this method is called through the dependency, not the
target, because a dependency Node must be able to use its own
logic to decide if it changed. For example, File Nodes need to
obey if we're configured to use timestamps, but Python Value Nodes
never use timestamps and always use the content. If this method
were called through the target, then each Node's implementation
of this method would have to have more complicated logic to
handle all the different Node types on which it might depend.
"""
raise NotImplementedError
def changed_since_last_build_alias(node, target, prev_ni, repo_node=None) -> bool:
cur_csig = node.get_csig()
try:
return cur_csig != prev_ni.csig
except AttributeError:
return True
def changed_since_last_build_entry(node, target, prev_ni, repo_node=None) -> bool:
node.disambiguate()
return _decider_map[node.changed_since_last_build](node, target, prev_ni, repo_node)
def changed_since_last_build_state_changed(node, target, prev_ni, repo_node=None) -> bool:
return node.state != SCons.Node.up_to_date
def decide_source(node, target, prev_ni, repo_node=None) -> bool:
return target.get_build_env().decide_source(node, target, prev_ni, repo_node)
def decide_target(node, target, prev_ni, repo_node=None) -> bool:
return target.get_build_env().decide_target(node, target, prev_ni, repo_node)
def changed_since_last_build_python(node, target, prev_ni, repo_node=None) -> bool:
cur_csig = node.get_csig()
try:
return cur_csig != prev_ni.csig
except AttributeError:
return True
#
# Now, the mapping from indices to decider functions
#
_decider_map = {0 : changed_since_last_build_node,
1 : changed_since_last_build_alias,
2 : changed_since_last_build_entry,
3 : changed_since_last_build_state_changed,
4 : decide_source,
5 : decide_target,
6 : changed_since_last_build_python}
do_store_info = True
#
# The new store_info subsystem for Nodes
#
# We would set and overwrite the store_info function
# before, but for being able to use slots (less memory!) we now have
# a dictionary of the different functions. Then in the Node
# subclasses we simply store the index to the info method that should be
# used by it.
#
#
# First, the single info functions
#
def store_info_pass(node) -> None:
pass
def store_info_file(node) -> None:
# Merge our build information into the already-stored entry.
# This accommodates "chained builds" where a file that's a target
# in one build (SConstruct file) is a source in a different build.
# See test/chained-build.py for the use case.
if do_store_info:
node.dir.sconsign().store_info(node.name, node)
store_info_map = {0 : store_info_pass,
1 : store_info_file}
# Classes for signature info for Nodes.
class NodeInfoBase:
"""
The generic base class for signature information for a Node.
Node subclasses should subclass NodeInfoBase to provide their own
logic for dealing with their own Node-specific signature information.
"""
__slots__ = ('__weakref__',)
current_version_id = 2
def update(self, node: Node) -> None:
try:
field_list = self.field_list
except AttributeError:
return
for f in field_list:
try:
delattr(self, f)
except AttributeError:
pass
try:
func = getattr(node, 'get_' + f)
except AttributeError:
pass
else:
setattr(self, f, func())
def convert(self, node, val) -> None:
pass
def merge(self, other: NodeInfoBase) -> None:
"""
Merge the fields of another object into this object. Already existing
information is overwritten by the other instance's data.
WARNING: If a '__dict__' slot is added, it should be updated instead of
replaced.
"""
state = other.__getstate__()
self.__setstate__(state)
def format(self, field_list: list[str] | None = None, names: bool = False):
if field_list is None:
try:
field_list = self.field_list
except AttributeError:
field_list = list(getattr(self, '__dict__', {}).keys())
for obj in type(self).mro():
for slot in getattr(obj, '__slots__', ()):
if slot not in ('__weakref__', '__dict__'):
field_list.append(slot)
field_list.sort()
fields = []
for field in field_list:
try:
f = getattr(self, field)
except AttributeError:
f = None
f = str(f)
if names:
f = field + ': ' + f
fields.append(f)
return fields
def __getstate__(self) -> dict[str, Any]:
"""
Return all fields that shall be pickled. Walk the slots in the class
hierarchy and add those to the state dictionary. If a '__dict__' slot is
available, copy all entries to the dictionary. Also include the version
id, which is fixed for all instances of a class.
"""
state = getattr(self, '__dict__', {}).copy()
for obj in type(self).mro():
for name in getattr(obj,'__slots__',()):
if hasattr(self, name):
state[name] = getattr(self, name)
state['_version_id'] = self.current_version_id
try:
del state['__weakref__']
except KeyError:
pass
return state
def __setstate__(self, state: dict[str, Any]) -> None:
"""
Restore the attributes from a pickled state. The version is discarded.
"""
# TODO check or discard version
del state['_version_id']
for key, value in state.items():
if key not in ('__weakref__',):
setattr(self, key, value)
class BuildInfoBase:
"""
The generic base class for build information for a Node.
This is what gets stored in a .sconsign file for each target file.
It contains a NodeInfo instance for this node (signature information
that's specific to the type of Node) and direct attributes for the
generic build stuff we have to track: sources, explicit dependencies,
implicit dependencies, and action information.
"""
__slots__ = ("bsourcesigs", "bdependsigs", "bimplicitsigs", "bactsig",
"bsources", "bdepends", "bact", "bimplicit", "__weakref__")
current_version_id = 2
def __init__(self) -> None:
# Create an object attribute from the class attribute so it ends up
# in the pickled data in the .sconsign file.
self.bsourcesigs: list[BuildInfoBase] = []
self.bdependsigs: list[BuildInfoBase] = []
self.bimplicitsigs: list[BuildInfoBase] = []
self.bactsig: str | None = None
def merge(self, other: BuildInfoBase) -> None:
"""
Merge the fields of another object into this object. Already existing
information is overwritten by the other instance's data.
WARNING: If a '__dict__' slot is added, it should be updated instead of
replaced.
"""
state = other.__getstate__()
self.__setstate__(state)
def __getstate__(self) -> dict[str, Any]:
"""
Return all fields that shall be pickled. Walk the slots in the class
hierarchy and add those to the state dictionary. If a '__dict__' slot is
available, copy all entries to the dictionary. Also include the version
id, which is fixed for all instances of a class.
"""
state = getattr(self, '__dict__', {}).copy()
for obj in type(self).mro():
for name in getattr(obj,'__slots__',()):
if hasattr(self, name):
state[name] = getattr(self, name)
state['_version_id'] = self.current_version_id
try:
del state['__weakref__']
except KeyError:
pass
return state
def __setstate__(self, state: dict[str, Any]) -> None:
"""
Restore the attributes from a pickled state.
"""
# TODO check or discard version
del state['_version_id']
for key, value in state.items():
if key not in ('__weakref__',):
setattr(self, key, value)
class Node(metaclass=NoSlotsPyPy):
"""The base Node class, for entities that we know how to
build, or use to build other Nodes.
"""
__slots__ = ['sources',
'sources_set',
'target_peers',
'_specific_sources',
'depends',
'depends_set',
'ignore',
'ignore_set',
'prerequisites',
'implicit',
'waiting_parents',
'waiting_s_e',
'ref_count',
'wkids',
'env',
'state',
'precious',
'noclean',
'nocache',
'cached',
'always_build',
'includes',
'attributes',
'side_effect',
'side_effects',
'linked',
'_memo',
'executor',
'binfo',
'ninfo',
'builder',
'is_explicit',
'implicit_set',
'changed_since_last_build',
'store_info',
'pseudo',
'_tags',
'_func_is_derived',
'_func_exists',
'_func_rexists',
'_func_get_contents',
'_func_target_from_source']
class Attrs:
__slots__ = ('shared', '__dict__')
def __init__(self) -> None:
if SCons.Debug.track_instances: logInstanceCreation(self, 'Node.Node')
# Note that we no longer explicitly initialize a self.builder
# attribute to None here. That's because the self.builder
# attribute may be created on-the-fly later by a subclass (the
# canonical example being a builder to fetch a file from a
# source code system like CVS or Subversion).
# Each list of children that we maintain is accompanied by a
# dictionary used to look up quickly whether a node is already
# present in the list. Empirical tests showed that it was
# fastest to maintain them as side-by-side Node attributes in
# this way, instead of wrapping up each list+dictionary pair in
# a class. (Of course, we could always still do that in the
# future if we had a good reason to...).
self.sources: list[Node] = [] # source files used to build node
self.sources_set: set[Node] = set()
self._specific_sources = False
self.depends: list[Node] = [] # explicit dependencies (from Depends)
self.depends_set: set[Node] = set()
self.ignore: list[Node] = [] # dependencies to ignore
self.ignore_set: set[Node] = set()
self.prerequisites: UniqueList | None = None
self.implicit: list[Node] | None = None # implicit (scanned) dependencies (None means not scanned yet)
self.waiting_parents: set[Node] = set()
self.waiting_s_e: set[Node] = set()
self.ref_count = 0
self.wkids: list[Node] | None = None # Kids yet to walk, when it's an array
self.env: Environment | None = None
self.state = no_state
self.precious = False
self.pseudo = False
self.noclean = False
self.nocache = False
self.cached = False # is this node pulled from cache?
self.always_build = False
self.includes: list[str] | None = None
self.attributes = self.Attrs() # Generic place to stick information about the Node.
self.side_effect = False # true iff this node is a side effect
self.side_effects: list[Node] = [] # the side effects of building this target
self.linked = False # is this node linked to the variant directory?
self.changed_since_last_build = 0 # Index for "_decider_map".
self.store_info = 0 # Index for "store_info_map".
self._tags: dict[str, Any] | None = None
self._func_is_derived = 1 # Index for "_is_derived_map".
self._func_exists = 1 # Index for "_exists_map"
self._func_rexists = 1 # Index for "_rexists_map"
self._func_get_contents = 0 # Index for "_get_contents_map"
self._func_target_from_source = 0 # Index for "_target_from_source_map"
self.ninfo: NodeInfoBase | None = None
self.clear_memoized_values()
# Let the interface in which the build engine is embedded
# annotate this Node with its own info (like a description of
# what line in what file created the node, for example).
Annotate(self)
def __fspath__(self) -> str:
return str(self)
def disambiguate(self, must_exist: bool = False):
return self
def get_suffix(self) -> str:
return ''
@SCons.Memoize.CountMethodCall
def get_build_env(self) -> Environment:
"""Fetch the appropriate Environment to build this node.
"""
try:
return self._memo['get_build_env']
except KeyError:
pass
result = self.get_executor().get_build_env()
self._memo['get_build_env'] = result
return result
def get_build_scanner_path(self, scanner: ScannerBase):
"""Fetch the appropriate scanner path for this node."""
return self.get_executor().get_build_scanner_path(scanner)
def set_executor(self, executor: Executor) -> None:
"""Set the action executor for this node."""
self.executor = executor
def get_executor(self, create: bool = True) -> Executor:
"""Fetch the action executor for this node. Create one if
there isn't already one, and requested to do so."""
try:
executor = self.executor
except AttributeError:
if not create:
raise
try:
act = self.builder.action
except AttributeError:
executor = SCons.Executor.Null(targets=[self]) # type: ignore[assignment]
else:
executor = SCons.Executor.Executor(act,
self.env or self.builder.env,
[self.builder.overrides],
[self],
self.sources)
self.executor = executor
return executor
def executor_cleanup(self) -> None:
"""Let the executor clean up any cached information."""
try:
executor = self.get_executor(create=False)
except AttributeError:
pass
else:
if executor is not None:
executor.cleanup()
def reset_executor(self) -> None:
"""Remove cached executor; forces recompute when needed."""
try:
delattr(self, 'executor')
except AttributeError:
pass
def push_to_cache(self) -> bool:
"""Try to push a node into a cache
"""
return False
def retrieve_from_cache(self) -> bool:
"""Try to retrieve the node's content from a cache
This method is called from multiple threads in a parallel build,
so only do thread safe stuff here. Do thread unsafe stuff
in :meth:`built`.
Returns true if the node was successfully retrieved.
"""
return False
#
# Taskmaster interface subsystem
#
def make_ready(self) -> None:
"""Get a Node ready for evaluation.
This is called before the Taskmaster decides if the Node is
up-to-date or not. Overriding this method allows for a Node
subclass to be disambiguated if necessary, or for an implicit
source builder to be attached.
"""
pass
def prepare(self) -> None:
"""Prepare for this Node to be built.
This is called after the Taskmaster has decided that the Node
is out-of-date and must be rebuilt, but before actually calling
the method to build the Node.
This default implementation checks that explicit or implicit
dependencies either exist or are derived, and initializes the
BuildInfo structure that will hold the information about how
this node is, uh, built.
(The existence of source files is checked separately by the
Executor, which aggregates checks for all of the targets built
by a specific action.)
Overriding this method allows for for a Node subclass to remove
the underlying file from the file system. Note that subclass
methods should call this base class method to get the child
check and the BuildInfo structure.
"""
if self.depends is not None:
for d in self.depends:
if d.missing():
msg = "Explicit dependency `%s' not found, needed by target `%s'."
raise SCons.Errors.StopError(msg % (d, self))
if self.implicit is not None:
for i in self.implicit:
if i.missing():
msg = "Implicit dependency `%s' not found, needed by target `%s'."
raise SCons.Errors.StopError(msg % (i, self))
self.binfo = self.get_binfo()
def build(self, **kw) -> None:
"""Actually build the node.
This is called by the Taskmaster after it's decided that the
Node is out-of-date and must be rebuilt, and after the
:meth:`prepare` method has gotten everything, uh, prepared.
This method is called from multiple threads in a parallel build,
so only do thread safe stuff here. Do thread unsafe stuff
in :meth:`built`.
"""
try:
self.get_executor()(self, **kw)
except SCons.Errors.BuildError as e:
e.node = self
raise
def built(self) -> None:
"""Called just after this node is successfully built."""
# Clear the implicit dependency caches of any Nodes
# waiting for this Node to be built.
for parent in self.waiting_parents:
parent.implicit = None
# Handle issue where builder emits more than one target and
# the source file for the builder is generated.
# in that case only the first target was getting it's .implicit
# cleared when the source file is built (second scan).
# leaving only partial implicits from scan before source file is generated
# typically the compiler only. Then scanned files are appended
# This is persisted to sconsign and rebuild causes false rebuilds
# because the ordering of the implicit list then changes to what it
# should have been.
# This is at least the following bugs
# https://github.com/SCons/scons/issues/2811
# https://jira.mongodb.org/browse/SERVER-33111
try:
for peer in parent.target_peers:
peer.implicit = None
except AttributeError:
pass
self.clear()
if self.pseudo:
if self.exists():
raise SCons.Errors.UserError("Pseudo target " + str(self) + " must not exist")
else:
if not self.exists() and do_store_info:
SCons.Warnings.warn(SCons.Warnings.TargetNotBuiltWarning,
"Cannot find target " + str(self) + " after building")
self.ninfo.update(self)
def visited(self) -> None:
"""Called just after this node has been visited (with or
without a build)."""
try:
binfo = self.binfo
except AttributeError:
# Apparently this node doesn't need build info, so
# don't bother calculating or storing it.
pass
else:
self.ninfo.update(self)
SCons.Node.store_info_map[self.store_info](self)
def release_target_info(self) -> None:
"""Called just after this node has been marked
up-to-date or was built completely.
This is where we try to release as many target node infos
as possible for clean builds and update runs, in order
to minimize the overall memory consumption.
By purging attributes that aren't needed any longer after
a Node (=File) got built, we don't have to care that much how
many KBytes a Node actually requires...as long as we free
the memory shortly afterwards.
@see: built() and File.release_target_info()
"""
pass
def add_to_waiting_s_e(self, node: Node) -> None:
self.waiting_s_e.add(node)
def add_to_waiting_parents(self, node: Node) -> int:
"""
Returns the number of nodes added to our waiting parents list:
1 if we add a unique waiting parent, 0 if not. (Note that the
returned values are intended to be used to increment a reference
count, so don't think you can "clean up" this function by using
True and False instead...)
"""
wp = self.waiting_parents
if node in wp:
return 0
wp.add(node)
return 1
def postprocess(self) -> None:
"""Clean up anything we don't need to hang onto after we've
been built."""
self.executor_cleanup()
self.waiting_parents = set()
def clear(self) -> None:
"""Completely clear a Node of all its cached state (so that it
can be re-evaluated by interfaces that do continuous integration
builds).
"""
# The del_binfo() call here isn't necessary for normal execution,
# but is for interactive mode, where we might rebuild the same
# target and need to start from scratch.
self.del_binfo()
self.clear_memoized_values()
self.ninfo = self.new_ninfo()
self.executor_cleanup()
for attr in ['cachedir_csig', 'cachesig', 'contentsig']:
try:
delattr(self, attr)
except AttributeError:
pass
self.cached = False
self.includes = None
def clear_memoized_values(self) -> None:
self._memo = {}
def builder_set(self, builder: BuilderBase | None) -> None:
self.builder = builder
try:
del self.executor
except AttributeError:
pass
def has_builder(self) -> bool:
"""Return whether this Node has a builder or not.
In Boolean tests, this turns out to be a *lot* more efficient
than simply examining the builder attribute directly ("if
node.builder: ..."). When the builder attribute is examined
directly, it ends up calling __getattr__ for both the __len__
and __bool__ attributes on instances of our Builder Proxy
class(es), generating a bazillion extra calls and slowing
things down immensely.
"""
try:
b = self.builder
except AttributeError:
# There was no explicit builder for this Node, so initialize
# the self.builder attribute to None now.
b = self.builder = None
return b is not None
def set_explicit(self, is_explicit: bool) -> None:
self.is_explicit = is_explicit
def has_explicit_builder(self) -> bool:
"""Return whether this Node has an explicit builder.
This allows an internal Builder created by SCons to be marked
non-explicit, so that it can be overridden by an explicit
builder that the user supplies (the canonical example being
directories)."""
try:
return self.is_explicit
except AttributeError:
self.is_explicit = False
return False
def get_builder(self, default_builder: BuilderBase | None = None) -> BuilderBase | None:
"""Return the set builder, or a specified default value"""
try:
return self.builder
except AttributeError:
return default_builder
multiple_side_effect_has_builder = has_builder
def is_derived(self) -> bool:
"""
Returns true if this node is derived (i.e. built).
This should return true only for nodes whose path should be in
the variant directory when duplicate=0 and should contribute their build
signatures when they are used as source files to other derived files. For
example: source with source builders are not derived in this sense,
and hence should not return true.
"""
return _is_derived_map[self._func_is_derived](self)
def is_sconscript(self) -> bool:
""" Returns true if this node is an sconscript """
return self in SConscriptNodes
def is_conftest(self) -> bool:
""" Returns true if this node is an conftest node"""
try:
self.attributes.conftest_node
except AttributeError:
return False
return True
def check_attributes(self, name: str) -> Any | None:
""" Simple API to check if the node.attributes for name has been set"""
return getattr(getattr(self, "attributes", None), name, None)
def alter_targets(self):
"""Return a list of alternate targets for this Node.
"""
return [], None
def get_found_includes(self, env: Environment, scanner: ScannerBase | None, path) -> list[Node]:
"""Return the scanned include lines (implicit dependencies)
found in this node.
The default is no implicit dependencies. We expect this method
to be overridden by any subclass that can be scanned for
implicit dependencies.
"""
return []
def get_implicit_deps(self, env: Environment, initial_scanner: ScannerBase | None, path_func, kw = {}) -> list[Node]:
"""Return a list of implicit dependencies for this node.
This method exists to handle recursive invocation of the scanner
on the implicit dependencies returned by the scanner, if the
scanner's recursive flag says that we should.
"""
nodes = [self]
seen = set(nodes)
dependencies = []
path_memo = {}
root_node_scanner = self._get_scanner(env, initial_scanner, None, kw)
while nodes:
node = nodes.pop(0)
scanner = node._get_scanner(env, initial_scanner, root_node_scanner, kw)
if not scanner:
continue