Bug 1229178: modify --json output to contain a single object r=mshal

MozReview-Commit-ID: DNlxPfQh3o0
This commit is contained in:
Dustin J. Mitchell
2016-06-09 11:15:23 -05:00
parent fad8ae2b71
commit 6d42f5dc86
2 changed files with 17 additions and 11 deletions

View File

@@ -163,8 +163,12 @@ context.
Taskgraph JSON Format
---------------------
Each task in the graph is represented as a JSON object. The output is suitable
for processing with the `jq <https://stedolan.github.io/jq/>`_ utility.
Task graphs -- both the graph artifacts produced by the decision task and those
output by the ``--json`` option to the ``mach taskgraph`` commands -- are JSON
objects, keyed by label, or for optimized task graphs, by taskId. For
convenience, the decision task also writes out ``label-to-taskid.json``
containing a mapping from label to taskId. Each task in the graph is
represented as a JSON object.
Each task has the following properties:
@@ -202,7 +206,11 @@ in the content:
array is populated with the full list of dependency taskIds. All task
references are resolved in the optimized graph.
The graph artifacts produced by the decision task are JSON objects, keyed by
label (``full-task-graph.json`` and ``target-tasks``) or by taskId
(``task-graph.json``). For convenience, the decision task also writes out
``label-to-taskid.json`` containing a mapping from label to taskId.
The output of the ``mach taskgraph`` commands are suitable for processing with
the `jq <https://stedolan.github.io/jq/>`_ utility. For example, to extract all
tasks' labels and their dependencies:
.. code-block:: shell
jq 'to_entries | map({label: .value.label, dependencies: .value.dependencies})'

View File

@@ -37,7 +37,7 @@ class ShowTaskGraphSubCommand(SubCommand):
help="include debug-level logging output"),
CommandArgument('--json', '-J', action="store_const",
dest="format", const="json",
help="Output each task in the task graph as a JSON object"),
help="Output task graph as a JSON object"),
CommandArgument('--labels', '-L', action="store_const",
dest="format", const="labels",
help="Output the label for each task in the task graph (default)"),
@@ -199,10 +199,8 @@ class MachCommands(MachCommandBase):
print(label)
def show_taskgraph_json(self, taskgraph):
# JSON output is a sequence of JSON objects, rather than a single object, so
# disassemble the dictionary
for task in taskgraph.to_json().itervalues():
print(json.dumps(task))
print(json.dumps(taskgraph.to_json(),
sort_keys=True, indent=2, separators=(',', ': ')))
@CommandProvider