1#!/usr/bin/env python
2# Copyright 2017 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import argparse
7import json
8import sys
9
10import results_merger
11
12
13def StandardIsolatedScriptMerge(output_json, jsons_to_merge):
14  """Merge the contents of one or more results JSONs into a single JSON.
15
16  Args:
17    output_json: A path to a JSON file to which the merged results should be
18      written.
19    jsons_to_merge: A list of paths to JSON files that should be merged.
20  """
21  shard_results_list = []
22  for j in jsons_to_merge:
23    with open(j) as f:
24      shard_results_list.append(json.load(f))
25  merged_results = results_merger.merge_test_results(shard_results_list)
26
27  with open(output_json, 'w') as f:
28    json.dump(merged_results, f)
29
30  return 0
31
32
33def main():
34  parser = argparse.ArgumentParser()
35  parser.add_argument('-o', '--output-json', required=True)
36  parser.add_argument('--build-properties', help=argparse.SUPPRESS)
37  parser.add_argument('--summary-json', help=argparse.SUPPRESS)
38  parser.add_argument('jsons_to_merge', nargs='*')
39
40  args = parser.parse_args()
41  return StandardIsolatedScriptMerge(args.output_json, args.jsons_to_merge)
42
43
44if __name__ == '__main__':
45  sys.exit(main())
46