Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(727)

Side by Side Diff: pylib/gyp/input.py

Issue 1506733002: GYP: Make GYP build deterministic (Closed) Base URL: https://chromium.googlesource.com/external/gyp.git@master
Patch Set: Shrinks test case down, more thorough testing. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (c) 2012 Google Inc. All rights reserved. 1 # Copyright (c) 2012 Google Inc. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from compiler.ast import Const 5 from compiler.ast import Const
6 from compiler.ast import Dict 6 from compiler.ast import Dict
7 from compiler.ast import Discard 7 from compiler.ast import Discard
8 from compiler.ast import List 8 from compiler.ast import List
9 from compiler.ast import Module 9 from compiler.ast import Module
10 from compiler.ast import Node 10 from compiler.ast import Node
(...skipping 1521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 def __repr__(self): 1532 def __repr__(self):
1533 return '<DependencyGraphNode: %r>' % self.ref 1533 return '<DependencyGraphNode: %r>' % self.ref
1534 1534
1535 def FlattenToList(self): 1535 def FlattenToList(self):
1536 # flat_list is the sorted list of dependencies - actually, the list items 1536 # flat_list is the sorted list of dependencies - actually, the list items
1537 # are the "ref" attributes of DependencyGraphNodes. Every target will 1537 # are the "ref" attributes of DependencyGraphNodes. Every target will
1538 # appear in flat_list after all of its dependencies, and before all of its 1538 # appear in flat_list after all of its dependencies, and before all of its
1539 # dependents. 1539 # dependents.
1540 flat_list = OrderedSet() 1540 flat_list = OrderedSet()
1541 1541
1542 def ExtractNodeRef(node):
1543 """Extracts the object that the node represents from the given node."""
1544 return node.ref
1545
1542 # in_degree_zeros is the list of DependencyGraphNodes that have no 1546 # in_degree_zeros is the list of DependencyGraphNodes that have no
1543 # dependencies not in flat_list. Initially, it is a copy of the children 1547 # dependencies not in flat_list. Initially, it is a copy of the children
1544 # of this node, because when the graph was built, nodes with no 1548 # of this node, because when the graph was built, nodes with no
1545 # dependencies were made implicit dependents of the root node. 1549 # dependencies were made implicit dependents of the root node.
1546 in_degree_zeros = set(self.dependents[:]) 1550 # Note that we sort this list to ensure we have deterministic output.
1551 in_degree_zeros = sorted(self.dependents[:], key=ExtractNodeRef)
1547 1552
1548 while in_degree_zeros: 1553 while in_degree_zeros:
1549 # Nodes in in_degree_zeros have no dependencies not in flat_list, so they 1554 # Nodes in in_degree_zeros have no dependencies not in flat_list, so they
1550 # can be appended to flat_list. Take these nodes out of in_degree_zeros 1555 # can be appended to flat_list. Take these nodes out of in_degree_zeros
1551 # as work progresses, so that the next node to process from the list can 1556 # as work progresses, so that the next node to process from the list can
1552 # always be accessed at a consistent position. 1557 # always be accessed at a consistent position.
1553 node = in_degree_zeros.pop() 1558 node = in_degree_zeros.pop()
1554 flat_list.add(node.ref) 1559 flat_list.add(node.ref)
1555 1560
1556 # Look at dependents of the node just added to flat_list. Some of them 1561 # Look at dependents of the node just added to flat_list. Some of them
1557 # may now belong in in_degree_zeros. 1562 # may now belong in in_degree_zeros.
1558 for node_dependent in node.dependents: 1563 # Note that we sort this list to ensure we have deterministic output.
1564 for node_dependent in sorted(node.dependents, key=ExtractNodeRef):
1559 is_in_degree_zero = True 1565 is_in_degree_zero = True
1560 # TODO: We want to check through the 1566 # TODO: We want to check through the
1561 # node_dependent.dependencies list but if it's long and we 1567 # node_dependent.dependencies list but if it's long and we
1562 # always start at the beginning, then we get O(n^2) behaviour. 1568 # always start at the beginning, then we get O(n^2) behaviour.
1563 for node_dependent_dependency in node_dependent.dependencies: 1569 # Note that we sort this list to ensure we have deterministic output.
1570 for node_dependent_dependency in sorted(node_dependent.dependencies,
1571 key=ExtractNodeRef):
1564 if not node_dependent_dependency.ref in flat_list: 1572 if not node_dependent_dependency.ref in flat_list:
1565 # The dependent one or more dependencies not in flat_list. There 1573 # The dependent one or more dependencies not in flat_list. There
1566 # will be more chances to add it to flat_list when examining 1574 # will be more chances to add it to flat_list when examining
1567 # it again as a dependent of those other dependencies, provided 1575 # it again as a dependent of those other dependencies, provided
1568 # that there are no cycles. 1576 # that there are no cycles.
1569 is_in_degree_zero = False 1577 is_in_degree_zero = False
1570 break 1578 break
1571 1579
1572 if is_in_degree_zero: 1580 if is_in_degree_zero:
1573 # All of the dependent's dependencies are already in flat_list. Add 1581 # All of the dependent's dependencies are already in flat_list. Add
1574 # it to in_degree_zeros where it will be processed in a future 1582 # it to in_degree_zeros where it will be processed in a future
1575 # iteration of the outer loop. 1583 # iteration of the outer loop.
1576 in_degree_zeros.add(node_dependent) 1584 in_degree_zeros += [node_dependent]
1577 1585
1578 return list(flat_list) 1586 return list(flat_list)
1579 1587
1580 def FindCycles(self): 1588 def FindCycles(self):
1581 """ 1589 """
1582 Returns a list of cycles in the graph, where each cycle is its own list. 1590 Returns a list of cycles in the graph, where each cycle is its own list.
1583 """ 1591 """
1584 results = [] 1592 results = []
1585 visited = set() 1593 visited = set()
1586 1594
(...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after
2885 ValidateRunAsInTarget(target, target_dict, build_file) 2893 ValidateRunAsInTarget(target, target_dict, build_file)
2886 ValidateActionsInTarget(target, target_dict, build_file) 2894 ValidateActionsInTarget(target, target_dict, build_file)
2887 2895
2888 # Generators might not expect ints. Turn them into strs. 2896 # Generators might not expect ints. Turn them into strs.
2889 TurnIntIntoStrInDict(data) 2897 TurnIntIntoStrInDict(data)
2890 2898
2891 # TODO(mark): Return |data| for now because the generator needs a list of 2899 # TODO(mark): Return |data| for now because the generator needs a list of
2892 # build files that came in. In the future, maybe it should just accept 2900 # build files that came in. In the future, maybe it should just accept
2893 # a list, and not the whole data dict. 2901 # a list, and not the whole data dict.
2894 return [flat_list, targets, data] 2902 return [flat_list, targets, data]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698