Bug 1568277 - [tasgraph] Add ability to redirect |mach taskgraph|'s output to a file, r=tomprince
☠☠ backed out by 8da8443e0bcb ☠ ☠
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Thu, 15 Aug 2019 19:36:15 +0000
changeset 488339 632d943c947b359b68d7d29626ef3c51744572fd
parent 488338 d7e8f80e2c85288a5f59135f147475fe7ac73ce0
child 488340 056d9515483cd593dc1a931b4ade7ba7b143b540
push id36440
push userncsoregi@mozilla.com
push dateFri, 16 Aug 2019 03:57:48 +0000
treeherdermozilla-central@a58b7dc85887 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstomprince
bugs1568277
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1568277 - [tasgraph] Add ability to redirect |mach taskgraph|'s output to a file, r=tomprince Differential Revision: https://phabricator.services.mozilla.com/D42172
taskcluster/mach_commands.py
--- a/taskcluster/mach_commands.py
+++ b/taskcluster/mach_commands.py
@@ -54,16 +54,18 @@ class ShowTaskGraphSubCommand(SubCommand
             CommandArgument('--tasks-regex', '--tasks', default=None,
                             help="only return tasks with labels matching this regular "
                             "expression."),
             CommandArgument('--target-kind', default=None,
                             help="only return tasks that are of the given kind, "
                                  "or their dependencies."),
             CommandArgument('-F', '--fast', dest='fast', default=False, action='store_true',
                             help="enable fast task generation for local debugging."),
+            CommandArgument('-o', '--output-file', default=None,
+                            help="file path to store generated output."),
 
         ]
         for arg in args:
             after = arg(after)
         return after
 
 
 @CommandProvider
@@ -373,28 +375,33 @@ class MachCommands(MachCommandBase):
                 parameters=parameters,
                 target_kind=options.get('target_kind'),
             )
 
             tg = getattr(tgg, graph_attr)
 
             show_method = getattr(self, 'show_taskgraph_' + (options['format'] or 'labels'))
             tg = self.get_filtered_taskgraph(tg, options["tasks_regex"])
-            show_method(tg)
+
+            fh = options['output_file']
+            if fh:
+                fh = open(fh, 'w')
+            show_method(tg, file=fh)
         except Exception:
             traceback.print_exc()
             sys.exit(1)
 
-    def show_taskgraph_labels(self, taskgraph):
+    def show_taskgraph_labels(self, taskgraph, file=None):
         for index in taskgraph.graph.visit_postorder():
-            print(taskgraph.tasks[index].label)
+            print(taskgraph.tasks[index].label, file=file)
 
-    def show_taskgraph_json(self, taskgraph):
+    def show_taskgraph_json(self, taskgraph, file=None):
         print(json.dumps(taskgraph.to_json(),
-              sort_keys=True, indent=2, separators=(',', ': ')))
+              sort_keys=True, indent=2, separators=(',', ': ')),
+              file=file)
 
     def get_filtered_taskgraph(self, taskgraph, tasksregex):
         from taskgraph.graph import Graph
         from taskgraph.taskgraph import TaskGraph
         """
         This class method filters all the tasks on basis of a regular expression
         and returns a new TaskGraph object
         """