Bug 1237739 - Use set and sort graph scopes; r?garndt draft
authorGregory Szorc <gps@mozilla.com>
Thu, 07 Jan 2016 12:37:14 -0800
changeset 319774 c8bb1f0159c287ab103d55f55122b3e046c1898f
parent 319773 5f4968b8d45b3ecf58796762c2a72a2aab449eec
child 512644 7c1667d4efe51795302bb065b4c2a0cf7f579fff
push id9087
push usergszorc@mozilla.com
push dateThu, 07 Jan 2016 20:39:53 +0000
reviewersgarndt
bugs1237739
milestone46.0a1
Bug 1237739 - Use set and sort graph scopes; r?garndt We're already casting the list of scopes to a set later. So we might as well use a set from the beginning. While we're here, sort the final value so output is more deterministic and easier to read. This sort shouldn't matter since the existing set() would have lost ordering.
testing/taskcluster/mach_commands.py
testing/taskcluster/taskcluster_graph/image_builder.py
--- a/testing/taskcluster/mach_commands.py
+++ b/testing/taskcluster/mach_commands.py
@@ -360,25 +360,25 @@ class Graph(object):
         with open(routes_file) as f:
             contents = json.load(f)
             json_routes = contents['routes']
             # TODO: Nightly and/or l10n routes
 
         # Task graph we are generating for taskcluster...
         graph = {
             'tasks': [],
-            'scopes': []
+            'scopes': set(),
         }
 
         if params['revision_hash']:
             for env in routes_transform.TREEHERDER_ROUTES:
                 route = 'queue:route:{}.{}'.format(
                             routes_transform.TREEHERDER_ROUTES[env],
                             treeherder_route)
-                graph['scopes'].append(route)
+                graph['scopes'].add(route)
 
         graph['metadata'] = {
             'source': 'http://todo.com/what/goes/here',
             'owner': params['owner'],
             # TODO: Add full mach commands to this example?
             'description': 'Task graph generated via ./mach taskcluster-graph',
             'name': 'task graph local'
         }
@@ -436,20 +436,20 @@ class Graph(object):
                 if route.startswith('index.gecko.v2') and route in all_routes:
                     raise Exception("Error: route '%s' is in use by multiple tasks: '%s' and '%s'" % (
                         route,
                         build_task['task']['metadata']['name'],
                         all_routes[route],
                     ))
                 all_routes[route] = build_task['task']['metadata']['name']
 
-            graph['scopes'].append(define_task)
-            graph['scopes'].extend(build_task['task'].get('scopes', []))
+            graph['scopes'].add(define_task)
+            graph['scopes'] |= set(build_task['task'].get('scopes', []))
             route_scopes = map(lambda route: 'queue:route:' + route, build_task['task'].get('routes', []))
-            graph['scopes'].extend(route_scopes)
+            graph['scopes'] |= set(route_scopes)
 
             # Treeherder symbol configuration for the graph required for each
             # build so tests know which platform they belong to.
             build_treeherder_config = build_task['task']['extra']['treeherder']
 
             if 'machine' not in build_treeherder_config:
                 message = '({}), extra.treeherder.machine required for all builds'
                 raise ValueError(message.format(build['task']))
@@ -534,20 +534,20 @@ class Graph(object):
                         )
 
                     graph['tasks'].append(test_task)
 
                     define_task = DEFINE_TASK.format(
                         test_task['task']['workerType']
                     )
 
-                    graph['scopes'].append(define_task)
-                    graph['scopes'].extend(test_task['task'].get('scopes', []))
+                    graph['scopes'].add(define_task)
+                    graph['scopes'] |= set(test_task['task'].get('scopes', []))
 
-        graph['scopes'] = list(set(graph['scopes']))
+        graph['scopes'] = sorted(graph['scopes'])
 
         if params['print_names_only']:
             tIDs = defaultdict(list)
 
             def print_task(task, indent=0):
                 print('{}- {}'.format(' ' * indent, task['task']['metadata']['name']))
 
                 for child in tIDs[task['taskId']]:
--- a/testing/taskcluster/taskcluster_graph/image_builder.py
+++ b/testing/taskcluster/taskcluster_graph/image_builder.py
@@ -212,14 +212,14 @@ def normalize_image_details(graph, task,
 
     graph['tasks'].append(image_task);
     task['requires'].append(details['taskId'])
 
     define_task = DEFINE_TASK.format(
         image_task['task']['workerType']
     )
 
-    graph['scopes'].append(define_task)
-    graph['scopes'].extend(image_task['task'].get('scopes', []))
+    graph['scopes'].add(define_task)
+    graph['scopes'] |= set(image_task['task'].get('scopes', []))
     route_scopes = map(lambda route: 'queue:route:' + route, image_task['task'].get('routes', []))
-    graph['scopes'].extend(route_scopes)
+    graph['scopes'] |= set(route_scopes)
 
     details['required'] = True