1 """SCons.Node
2
3 The Node package for the SCons software construction utility.
4
5 This is, in many ways, the heart of SCons.
6
7 A Node is where we encapsulate all of the dependency information about
8 any thing that SCons can build, or about any thing which SCons can use
9 to build some other thing. The canonical "thing," of course, is a file,
10 but a Node can also represent something remote (like a web page) or
11 something completely abstract (like an Alias).
12
13 Each specific type of "thing" is specifically represented by a subclass
14 of the Node base class: Node.FS.File for files, Node.Alias for aliases,
15 etc. Dependency information is kept here in the base class, and
16 information specific to files/aliases/etc. is in the subclass. The
17 goal, if we've done this correctly, is that any type of "thing" should
18 be able to depend on any other type of "thing."
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 __revision__ = "src/engine/SCons/Node/__init__.py 2725 2008/03/31 12:52:02 knight"
46
47 import SCons.compat
48
49 import copy
50 import string
51 import UserList
52
53 from SCons.Debug import logInstanceCreation
54 import SCons.Executor
55 import SCons.Memoize
56 import SCons.Util
57
58 from SCons.Debug import Trace
59
62
63
64
65
66
67
68
69
70 no_state = 0
71 pending = 1
72 executing = 2
73 up_to_date = 3
74 executed = 4
75 failed = 5
76
77 StateString = {
78 0 : "0",
79 1 : "pending",
80 2 : "executing",
81 3 : "up_to_date",
82 4 : "executed",
83 5 : "failed",
84 }
85
86
87 implicit_cache = 0
88
89
90 implicit_deps_unchanged = 0
91
92
93 implicit_deps_changed = 0
94
95
96
98
99 Annotate = do_nothing
100
101
102
104 """
105 The generic base class for signature information for a Node.
106
107 Node subclasses should subclass NodeInfoBase to provide their own
108 logic for dealing with their own Node-specific signature information.
109 """
110 current_version_id = 1
116 try:
117 field_list = self.field_list
118 except AttributeError:
119 return
120 for f in field_list:
121 try:
122 delattr(self, f)
123 except AttributeError:
124 pass
125 try:
126 func = getattr(node, 'get_' + f)
127 except AttributeError:
128 pass
129 else:
130 setattr(self, f, func())
134 self.__dict__.update(other.__dict__)
153
155 """
156 The generic base class for build information for a Node.
157
158 This is what gets stored in a .sconsign file for each target file.
159 It contains a NodeInfo instance for this node (signature information
160 that's specific to the type of Node) and direct attributes for the
161 generic build stuff we have to track: sources, explicit dependencies,
162 implicit dependencies, and action information.
163 """
164 current_version_id = 1
166
167
168 self._version_id = self.current_version_id
169 self.bsourcesigs = []
170 self.bdependsigs = []
171 self.bimplicitsigs = []
172 self.bactsig = None
174 self.__dict__.update(other.__dict__)
175
177 """The base Node class, for entities that we know how to
178 build, or use to build other Nodes.
179 """
180
181 if SCons.Memoize.use_memoizer:
182 __metaclass__ = SCons.Memoize.Memoized_Metaclass
183
184 memoizer_counters = []
185
188
190 if __debug__: logInstanceCreation(self, 'Node.Node')
191
192
193
194
195
196
197
198
199
200
201
202
203
204 self.sources = []
205 self.sources_dict = {}
206 self.depends = []
207 self.depends_dict = {}
208 self.ignore = []
209 self.ignore_dict = {}
210 self.prerequisites = SCons.Util.UniqueList()
211 self.implicit = None
212 self.waiting_parents = {}
213 self.waiting_s_e = {}
214 self.ref_count = 0
215 self.wkids = None
216
217 self.env = None
218 self.state = no_state
219 self.precious = None
220 self.noclean = 0
221 self.nocache = 0
222 self.always_build = None
223 self.found_includes = {}
224 self.includes = None
225 self.attributes = self.Attrs()
226 self.side_effect = 0
227 self.side_effects = []
228 self.linked = 0
229
230 self.clear_memoized_values()
231
232
233
234
235 Annotate(self)
236
239
242
243 memoizer_counters.append(SCons.Memoize.CountValue('get_build_env'))
244
246 """Fetch the appropriate Environment to build this node.
247 """
248 try:
249 return self._memo['get_build_env']
250 except KeyError:
251 pass
252 result = self.get_executor().get_build_env()
253 self._memo['get_build_env'] = result
254 return result
255
259
261 """Set the action executor for this node."""
262 self.executor = executor
263
265 """Fetch the action executor for this node. Create one if
266 there isn't already one, and requested to do so."""
267 try:
268 executor = self.executor
269 except AttributeError:
270 if not create:
271 raise
272 try:
273 act = self.builder.action
274 except AttributeError:
275 executor = SCons.Executor.Null(targets=[self])
276 else:
277 executor = SCons.Executor.Executor(act,
278 self.env or self.builder.env,
279 [self.builder.overrides],
280 [self],
281 self.sources)
282 self.executor = executor
283 return executor
284
286 """Let the executor clean up any cached information."""
287 try:
288 executor = self.get_executor(create=None)
289 except AttributeError:
290 pass
291 else:
292 executor.cleanup()
293
295 "Remove cached executor; forces recompute when needed."
296 try:
297 delattr(self, 'executor')
298 except AttributeError:
299 pass
300
302 """Try to retrieve the node's content from a cache
303
304 This method is called from multiple threads in a parallel build,
305 so only do thread safe stuff here. Do thread unsafe stuff in
306 built().
307
308 Returns true iff the node was successfully retrieved.
309 """
310 return 0
311
312
313
314
315
317 """Get a Node ready for evaluation.
318
319 This is called before the Taskmaster decides if the Node is
320 up-to-date or not. Overriding this method allows for a Node
321 subclass to be disambiguated if necessary, or for an implicit
322 source builder to be attached.
323 """
324 pass
325
327 """Prepare for this Node to be built.
328
329 This is called after the Taskmaster has decided that the Node
330 is out-of-date and must be rebuilt, but before actually calling
331 the method to build the Node.
332
333 This default implemenation checks that all children either exist
334 or are derived, and initializes the BuildInfo structure that
335 will hold the information about how this node is, uh, built.
336
337 Overriding this method allows for for a Node subclass to remove
338 the underlying file from the file system. Note that subclass
339 methods should call this base class method to get the child
340 check and the BuildInfo structure.
341 """
342 l = self.depends
343 if not self.implicit is None:
344 l = l + self.implicit
345 missing_sources = self.get_executor().get_missing_sources() \
346 + filter(lambda c: c.missing(), l)
347 if missing_sources:
348 desc = "Source `%s' not found, needed by target `%s'." % (missing_sources[0], self)
349 raise SCons.Errors.StopError, desc
350
351 self.binfo = self.get_binfo()
352
354 """Actually build the node.
355
356 This is called by the Taskmaster after it's decided that the
357 Node is out-of-date and must be rebuilt, and after the prepare()
358 method has gotten everything, uh, prepared.
359
360 This method is called from multiple threads in a parallel build,
361 so only do thread safe stuff here. Do thread unsafe stuff
362 in built().
363
364 """
365 try:
366 apply(self.get_executor(), (self,), kw)
367 except SCons.Errors.BuildError, e:
368 e.node = self
369 raise
370
372 """Called just after this node is successfully built."""
373
374
375
376 for parent in self.waiting_parents.keys():
377 parent.implicit = None
378
379 self.clear()
380
381 self.ninfo.update(self)
382
384 """Called just after this node has been visited (with or
385 without a build)."""
386 try:
387 binfo = self.binfo
388 except AttributeError:
389
390
391 pass
392 else:
393 self.ninfo.update(self)
394 self.store_info()
395
396
397
398
399
401 self.waiting_s_e[node] = 1
402
404 """
405 Returns the number of nodes added to our waiting parents list:
406 1 if we add a unique waiting parent, 0 if not. (Note that the
407 returned values are intended to be used to increment a reference
408 count, so don't think you can "clean up" this function by using
409 True and False instead...)
410 """
411 wp = self.waiting_parents
412 if wp.has_key(node):
413 result = 0
414 else:
415 result = 1
416 wp[node] = 1
417 return result
418
423
424 - def postprocess(self):
425 """Clean up anything we don't need to hang onto after we've
426 been built."""
427 self.executor_cleanup()
428 self.waiting_parents = {}
429
431 """Completely clear a Node of all its cached state (so that it
432 can be re-evaluated by interfaces that do continuous integration
433 builds).
434 """
435
436
437
438 self.del_binfo()
439 self.clear_memoized_values()
440 self.ninfo = self.new_ninfo()
441 self.executor_cleanup()
442 try:
443 delattr(self, '_calculated_sig')
444 except AttributeError:
445 pass
446 self.includes = None
447 self.found_includes = {}
448
451
453 self.builder = builder
454 try:
455 del self.executor
456 except AttributeError:
457 pass
458
460 """Return whether this Node has a builder or not.
461
462 In Boolean tests, this turns out to be a *lot* more efficient
463 than simply examining the builder attribute directly ("if
464 node.builder: ..."). When the builder attribute is examined
465 directly, it ends up calling __getattr__ for both the __len__
466 and __nonzero__ attributes on instances of our Builder Proxy
467 class(es), generating a bazillion extra calls and slowing
468 things down immensely.
469 """
470 try:
471 b = self.builder
472 except AttributeError:
473
474
475 b = self.builder = None
476 return not b is None
477
479 self.is_explicit = is_explicit
480
482 """Return whether this Node has an explicit builder
483
484 This allows an internal Builder created by SCons to be marked
485 non-explicit, so that it can be overridden by an explicit
486 builder that the user supplies (the canonical example being
487 directories)."""
488 try:
489 return self.is_explicit
490 except AttributeError:
491 self.is_explicit = None
492 return self.is_explicit
493
495 """Return the set builder, or a specified default value"""
496 try:
497 return self.builder
498 except AttributeError:
499 return default_builder
500
501 multiple_side_effect_has_builder = has_builder
502
504 """
505 Returns true iff this node is derived (i.e. built).
506
507 This should return true only for nodes whose path should be in
508 the variant directory when duplicate=0 and should contribute their build
509 signatures when they are used as source files to other derived files. For
510 example: source with source builders are not derived in this sense,
511 and hence should not return true.
512 """
513 return self.has_builder() or self.side_effect
514
516 """Return a list of alternate targets for this Node.
517 """
518 return [], None
519
521 """Return the scanned include lines (implicit dependencies)
522 found in this node.
523
524 The default is no implicit dependencies. We expect this method
525 to be overridden by any subclass that can be scanned for
526 implicit dependencies.
527 """
528 return []
529
531 """Return a list of implicit dependencies for this node.
532
533 This method exists to handle recursive invocation of the scanner
534 on the implicit dependencies returned by the scanner, if the
535 scanner's recursive flag says that we should.
536 """
537 if not scanner:
538 return []
539
540
541
542
543
544 nodes = [self]
545 seen = {}
546 seen[self] = 1
547 deps = []
548 while nodes:
549 n = nodes.pop(0)
550 d = filter(lambda x, seen=seen: not seen.has_key(x),
551 n.get_found_includes(env, scanner, path))
552 if d:
553 deps.extend(d)
554 for n in d:
555 seen[n] = 1
556 nodes.extend(scanner.recurse_nodes(d))
557
558 return deps
559
562
564 return self.builder.target_scanner
565
567 """Fetch the source scanner for the specified node
568
569 NOTE: "self" is the target being built, "node" is
570 the source file for which we want to fetch the scanner.
571
572 Implies self.has_builder() is true; again, expect to only be
573 called from locations where this is already verified.
574
575 This function may be called very often; it attempts to cache
576 the scanner found to improve performance.
577 """
578 scanner = None
579 try:
580 scanner = self.builder.source_scanner
581 except AttributeError:
582 pass
583 if not scanner:
584
585
586
587 scanner = self.get_env_scanner(self.get_build_env())
588 if scanner:
589 scanner = scanner.select(node)
590 return scanner
591
593 if not hasattr(self, 'implicit') or self.implicit is None:
594 self.implicit = []
595 self.implicit_dict = {}
596 self._children_reset()
597 self._add_child(self.implicit, self.implicit_dict, deps)
598
646
649
651 """Selects a scanner for this Node.
652
653 This is a separate method so it can be overridden by Node
654 subclasses (specifically, Node.FS.Dir) that *must* use their
655 own Scanner and don't select one the Scanner.Selector that's
656 configured for the target.
657 """
658 return scanner.select(self)
659
661 if safe and self.env:
662 return
663 self.env = env
664
665
666
667
668
669 NodeInfo = NodeInfoBase
670 BuildInfo = BuildInfoBase
671
673 ninfo = self.NodeInfo(self)
674 return ninfo
675
677 try:
678 return self.ninfo
679 except AttributeError:
680 self.ninfo = self.new_ninfo()
681 return self.ninfo
682
684 binfo = self.BuildInfo(self)
685 return binfo
686
688 """
689 Fetch a node's build information.
690
691 node - the node whose sources will be collected
692 cache - alternate node to use for the signature cache
693 returns - the build signature
694
695 This no longer handles the recursive descent of the
696 node's children's signatures. We expect that they're
697 already built and updated by someone else, if that's
698 what's wanted.
699 """
700 try:
701 return self.binfo
702 except AttributeError:
703 pass
704
705 binfo = self.new_binfo()
706 self.binfo = binfo
707
708 executor = self.get_executor()
709
710 sources = executor.get_unignored_sources(self.ignore)
711
712 depends = self.depends
713 implicit = self.implicit or []
714
715 if self.ignore:
716 depends = filter(self.do_not_ignore, depends)
717 implicit = filter(self.do_not_ignore, implicit)
718
719 def get_ninfo(node):
720 return node.get_ninfo()
721
722 sourcesigs = map(get_ninfo, sources)
723 dependsigs = map(get_ninfo, depends)
724 implicitsigs = map(get_ninfo, implicit)
725
726 if self.has_builder():
727 binfo.bact = str(executor)
728 binfo.bactsig = SCons.Util.MD5signature(executor.get_contents())
729
730 binfo.bsources = sources
731 binfo.bdepends = depends
732 binfo.bimplicit = implicit
733
734 binfo.bsourcesigs = sourcesigs
735 binfo.bdependsigs = dependsigs
736 binfo.bimplicitsigs = implicitsigs
737
738 return binfo
739
741 """Delete the build info from this node."""
742 try:
743 delattr(self, 'binfo')
744 except AttributeError:
745 pass
746
748 try:
749 return self.ninfo.csig
750 except AttributeError:
751 ninfo = self.get_ninfo()
752 ninfo.csig = SCons.Util.MD5signature(self.get_contents())
753 return self.ninfo.csig
754
757
759 """Make the build signature permanent (that is, store it in the
760 .sconsign file or equivalent)."""
761 pass
762
765
768
770 """Fetch the stored implicit dependencies"""
771 return None
772
773
774
775
776
778 """Set the Node's precious value."""
779 self.precious = precious
780
782 """Set the Node's noclean value."""
783
784
785 self.noclean = noclean and 1 or 0
786
788 """Set the Node's nocache value."""
789
790
791 self.nocache = nocache and 1 or 0
792
794 """Set the Node's always_build value."""
795 self.always_build = always_build
796
798 """Does this node exists?"""
799
800 return 1
801
803 """Does this node exist locally or in a repositiory?"""
804
805 return self.exists()
806
808 return not self.is_derived() and \
809 not self.linked and \
810 not self.rexists()
811
813 """Remove this Node: no-op by default."""
814 return None
815
817 """Adds dependencies."""
818 try:
819 self._add_child(self.depends, self.depends_dict, depend)
820 except TypeError, e:
821 e = e.args[0]
822 if SCons.Util.is_List(e):
823 s = map(str, e)
824 else:
825 s = str(e)
826 raise SCons.Errors.UserError("attempted to add a non-Node dependency to %s:\n\t%s is a %s, not a Node" % (str(self), s, type(e)))
827
832
834 """Adds dependencies to ignore."""
835 try:
836 self._add_child(self.ignore, self.ignore_dict, depend)
837 except TypeError, e:
838 e = e.args[0]
839 if SCons.Util.is_List(e):
840 s = map(str, e)
841 else:
842 s = str(e)
843 raise SCons.Errors.UserError("attempted to ignore a non-Node dependency of %s:\n\t%s is a %s, not a Node" % (str(self), s, type(e)))
844
846 """Adds sources."""
847 try:
848 self._add_child(self.sources, self.sources_dict, source)
849 except TypeError, e:
850 e = e.args[0]
851 if SCons.Util.is_List(e):
852 s = map(str, e)
853 else:
854 s = str(e)
855 raise SCons.Errors.UserError("attempted to add a non-Node as source of %s:\n\t%s is a %s, not a Node" % (str(self), s, type(e)))
856
858 """Adds 'child' to 'collection', first checking 'dict' to see
859 if it's already present."""
860
861
862
863
864
865 added = None
866 for c in child:
867 if not dict.has_key(c):
868 collection.append(c)
869 dict[c] = 1
870 added = 1
871 if added:
872 self._children_reset()
873
875 """Add a node to the list of kids waiting to be evaluated"""
876 if self.wkids != None:
877 self.wkids.append(wkid)
878
884
886 return node not in self.ignore
887
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906 if self.implicit is None:
907 return self.sources + self.depends
908 else:
909 return self.sources + self.depends + self.implicit
910
911 memoizer_counters.append(SCons.Memoize.CountValue('_children_get'))
912
923
929
931 """Return a list of the node's direct children, minus those
932 that are ignored by this node."""
933 if scan:
934 self.scan()
935 return self._children_get()
936
939
942
945
952
954 """
955
956 Must be overridden in a specific subclass to return True if this
957 Node (a dependency) has changed since the last time it was used
958 to build the specified target. prev_ni is this Node's state (for
959 example, its file timestamp, length, maybe content signature)
960 as of the last time the target was built.
961
962 Note that this method is called through the dependency, not the
963 target, because a dependency Node must be able to use its own
964 logic to decide if it changed. For example, File Nodes need to
965 obey if we're configured to use timestamps, but Python Value Nodes
966 never use timestamps and always use the content. If this method
967 were called through the target, then each Node's implementation
968 of this method would have to have more complicated logic to
969 handle all the different Node types on which it might depend.
970 """
971 raise NotImplementedError
972
975
977 """
978 Returns if the node is up-to-date with respect to the BuildInfo
979 stored last time it was built. The default behavior is to compare
980 it against our own previously stored BuildInfo, but the stored
981 BuildInfo from another Node (typically one in a Repository)
982 can be used instead.
983
984 Note that we now *always* check every dependency. We used to
985 short-circuit the check by returning as soon as we detected
986 any difference, but we now rely on checking every dependency
987 to make sure that any necessary Node information (for example,
988 the content signature of an #included .h file) is updated.
989 """
990 t = 0
991 if t: Trace('changed(%s [%s], %s)' % (self, classname(self), node))
992 if node is None:
993 node = self
994
995 result = False
996
997 bi = node.get_stored_info().binfo
998 then = bi.bsourcesigs + bi.bdependsigs + bi.bimplicitsigs
999 children = self.children()
1000
1001 diff = len(children) - len(then)
1002 if diff:
1003
1004
1005
1006
1007
1008 then.extend([None] * diff)
1009 if t: Trace(': old %s new %s' % (len(then), len(children)))
1010 result = True
1011
1012 for child, prev_ni in zip(children, then):
1013 if child.changed_since_last_build(self, prev_ni):
1014 if t: Trace(': %s changed' % child)
1015 result = True
1016
1017 contents = self.get_executor().get_contents()
1018 if self.has_builder():
1019 import SCons.Util
1020 newsig = SCons.Util.MD5signature(contents)
1021 if bi.bactsig != newsig:
1022 if t: Trace(': bactsig %s != newsig %s' % (bi.bactsig, newsig))
1023 result = True
1024
1025 if not result:
1026 if t: Trace(': up to date')
1027
1028 if t: Trace('\n')
1029
1030 return result
1031
1033 """Default check for whether the Node is current: unknown Node
1034 subtypes are always out of date, so they will always get built."""
1035 return None
1036
1038 """Alternate check for whether the Node is current: If all of
1039 our children were up-to-date, then this Node was up-to-date, too.
1040
1041 The SCons.Node.Alias and SCons.Node.Python.Value subclasses
1042 rebind their current() method to this method."""
1043
1044 self.binfo = self.get_binfo()
1045 if self.always_build:
1046 return None
1047 state = 0
1048 for kid in self.children(None):
1049 s = kid.get_state()
1050 if s and (not state or s > state):
1051 state = s
1052 return (state == 0 or state == SCons.Node.up_to_date)
1053
1055 """Always pass the string representation of a Node to
1056 the command interpreter literally."""
1057 return 1
1058
1071 return SCons.Util.render_tree(s, f, 1)
1072 else:
1073 return None
1074
1076 """
1077 Return an absolute path to the Node. This will return simply
1078 str(Node) by default, but for Node types that have a concept of
1079 relative path, this might return something different.
1080 """
1081 return str(self)
1082
1084 """
1085 Return a string representation of the Node that will always
1086 be the same for this particular Node, no matter what. This
1087 is by contrast to the __str__() method, which might, for
1088 instance, return a relative path for a file Node. The purpose
1089 of this method is to generate a value to be used in signature
1090 calculation for the command line used to build a target, and
1091 we use this method instead of str() to avoid unnecessary
1092 rebuilds. This method does not need to return something that
1093 would actually work in a command line; it can return any kind of
1094 nonsense, so long as it does not change.
1095 """
1096 return str(self)
1097
1099 """This is a convenience function designed primarily to be
1100 used in command generators (i.e., CommandGeneratorActions or
1101 Environment variables that are callable), which are called
1102 with a for_signature argument that is nonzero if the command
1103 generator is being called to generate a signature for the
1104 command line, which determines if we should rebuild or not.
1105
1106 Such command generators should use this method in preference
1107 to str(Node) when converting a Node to a string, passing
1108 in the for_signature parameter, such that we will call
1109 Node.for_signature() or str(Node) properly, depending on whether
1110 we are calculating a signature or actually constructing a
1111 command line."""
1112 if for_signature:
1113 return self.for_signature()
1114 return str(self)
1115
1117 """
1118 This method is expected to return an object that will function
1119 exactly like this Node, except that it implements any additional
1120 special features that we would like to be in effect for
1121 Environment variable substitution. The principle use is that
1122 some Nodes would like to implement a __getattr__() method,
1123 but putting that in the Node type itself has a tendency to kill
1124 performance. We instead put it in a proxy and return it from
1125 this method. It is legal for this method to return self
1126 if no new functionality is needed for Environment substitution.
1127 """
1128 return self
1129
1131 if not self.exists():
1132 return "building `%s' because it doesn't exist\n" % self
1133
1134 if self.always_build:
1135 return "rebuilding `%s' because AlwaysBuild() is specified\n" % self
1136
1137 old = self.get_stored_info()
1138 if old is None:
1139 return None
1140
1141 old = old.binfo
1142 old.prepare_dependencies()
1143
1144 try:
1145 old_bkids = old.bsources + old.bdepends + old.bimplicit
1146 old_bkidsigs = old.bsourcesigs + old.bdependsigs + old.bimplicitsigs
1147 except AttributeError:
1148 return "Cannot explain why `%s' is being rebuilt: No previous build information found\n" % self
1149
1150 new = self.get_binfo()
1151
1152 new_bkids = new.bsources + new.bdepends + new.bimplicit
1153 new_bkidsigs = new.bsourcesigs + new.bdependsigs + new.bimplicitsigs
1154
1155 osig = dict(zip(old_bkids, old_bkidsigs))
1156 nsig = dict(zip(new_bkids, new_bkidsigs))
1157
1158
1159
1160
1161
1162
1163
1164 def stringify( s, E=self.dir.Entry ) :
1165 if hasattr( s, 'dir' ) :
1166 return str(E(s))
1167 return str(s)
1168
1169 lines = []
1170
1171 removed = filter(lambda x, nk=new_bkids: not x in nk, old_bkids)
1172 if removed:
1173 removed = map(stringify, removed)
1174 fmt = "`%s' is no longer a dependency\n"
1175 lines.extend(map(lambda s, fmt=fmt: fmt % s, removed))
1176
1177 for k in new_bkids:
1178 if not k in old_bkids:
1179 lines.append("`%s' is a new dependency\n" % stringify(k))
1180 elif k.changed_since_last_build(self, osig[k]):
1181 lines.append("`%s' changed\n" % stringify(k))
1182
1183 if len(lines) == 0 and old_bkids != new_bkids:
1184 lines.append("the dependency order changed:\n" +
1185 "%sold: %s\n" % (' '*15, map(stringify, old_bkids)) +
1186 "%snew: %s\n" % (' '*15, map(stringify, new_bkids)))
1187
1188 if len(lines) == 0:
1189 def fmt_with_title(title, strlines):
1190 lines = string.split(strlines, '\n')
1191 sep = '\n' + ' '*(15 + len(title))
1192 return ' '*15 + title + string.join(lines, sep) + '\n'
1193 if old.bactsig != new.bactsig:
1194 if old.bact == new.bact:
1195 lines.append("the contents of the build action changed\n" +
1196 fmt_with_title('action: ', new.bact))
1197 else:
1198 lines.append("the build action changed:\n" +
1199 fmt_with_title('old: ', old.bact) +
1200 fmt_with_title('new: ', new.bact))
1201
1202 if len(lines) == 0:
1203 return "rebuilding `%s' for unknown reasons\n" % self
1204
1205 preamble = "rebuilding `%s' because" % self
1206 if len(lines) == 1:
1207 return "%s %s" % (preamble, lines[0])
1208 else:
1209 lines = ["%s:\n" % preamble] + lines
1210 return string.join(lines, ' '*11)
1211
1212 try:
1213 [].extend(UserList.UserList([]))
1214 except TypeError:
1215
1216
1217
1220 else:
1223 return str(map(str, self.data))
1224
1228
1230 """An iterator for walking a Node tree.
1231
1232 This is depth-first, children are visited before the parent.
1233 The Walker object can be initialized with any node, and
1234 returns the next node on the descent with each next() call.
1235 'kids_func' is an optional function that will be called to
1236 get the children of a node instead of calling 'children'.
1237 'cycle_func' is an optional function that will be called
1238 when a cycle is detected.
1239
1240 This class does not get caught in node cycles caused, for example,
1241 by C header file include loops.
1242 """
1243 - def __init__(self, node, kids_func=get_children,
1244 cycle_func=ignore_cycle,
1245 eval_func=do_nothing):
1246 self.kids_func = kids_func
1247 self.cycle_func = cycle_func
1248 self.eval_func = eval_func
1249 node.wkids = copy.copy(kids_func(node, None))
1250 self.stack = [node]
1251 self.history = {}
1252 self.history[node] = None
1253
1255 """Return the next node for this walk of the tree.
1256
1257 This function is intentionally iterative, not recursive,
1258 to sidestep any issues of stack size limitations.
1259 """
1260
1261 while self.stack:
1262 if self.stack[-1].wkids:
1263 node = self.stack[-1].wkids.pop(0)
1264 if not self.stack[-1].wkids:
1265 self.stack[-1].wkids = None
1266 if self.history.has_key(node):
1267 self.cycle_func(node, self.stack)
1268 else:
1269 node.wkids = copy.copy(self.kids_func(node, self.stack[-1]))
1270 self.stack.append(node)
1271 self.history[node] = None
1272 else:
1273 node = self.stack.pop()
1274 del self.history[node]
1275 if node:
1276 if self.stack:
1277 parent = self.stack[-1]
1278 else:
1279 parent = None
1280 self.eval_func(node, parent)
1281 return node
1282 return None
1283
1285 return not self.stack
1286
1287
1288 arg2nodes_lookups = []
1289