Home | History | Annotate | Download | only in resources
      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 
      6 import argparse
      7 import json
      8 import shutil
      9 import sys
     10 
     11 
     12 def noop_merge(output_json, jsons_to_merge):
     13   """Use the first supplied JSON as the output JSON.
     14 
     15   Primarily intended for unsharded tasks.
     16 
     17   Args:
     18     output_json: A path to a JSON file to which the results should be written.
     19     jsons_to_merge: A list of paths to JSON files.
     20   """
     21   if len(jsons_to_merge) > 1:
     22     print >> sys.stderr, (
     23         'Multiple JSONs provided: %s' % ','.join(jsons_to_merge))
     24     return 1
     25   if jsons_to_merge:
     26     shutil.copyfile(jsons_to_merge[0], output_json)
     27   else:
     28     with open(output_json, 'w') as f:
     29       json.dump({}, f)
     30   return 0
     31 
     32 
     33 def main(raw_args):
     34   parser = argparse.ArgumentParser()
     35   parser.add_argument('--build-properties', help=argparse.SUPPRESS)
     36   parser.add_argument('--summary-json', help=argparse.SUPPRESS)
     37   parser.add_argument('-o', '--output-json', required=True)
     38   parser.add_argument('jsons_to_merge', nargs='*')
     39 
     40   args = parser.parse_args(raw_args)
     41 
     42   return noop_merge(args.output_json, args.jsons_to_merge)
     43 
     44 
     45 if __name__ == '__main__':
     46   sys.exit(main(sys.argv[1:]))
     47