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 sys
7
8import package_version_interval
9
10if len(sys.argv) < 3:
11  print ('Usage: %s output_deps_file input1_deps_file input2_deps_file ...' %
12         sys.argv[0])
13  sys.exit(1)
14
15output_filename = sys.argv[1]
16input_filenames = sys.argv[2:]
17
18package_interval_sets = []
19for input_filename in input_filenames:
20  for line in open(input_filename):
21    # Ignore blank lines
22    if not line.strip():
23      continue
24    # Allow comments starting with '#'
25    if line.startswith('#'):
26      continue
27    line = line.rstrip('\n')
28    interval_set = package_version_interval.parse_interval_set(line)
29    should_append_interval_set = True
30    for i in range(len(package_interval_sets)):
31      if package_interval_sets[i].implies(interval_set):
32        should_append_interval_set = False
33        break
34      if interval_set.implies(package_interval_sets[i]):
35        should_append_interval_set = False
36        package_interval_sets[i] = interval_set
37        break
38    if should_append_interval_set:
39      package_interval_sets.append(interval_set)
40
41with open(output_filename, 'w') as output_file:
42  lines = [interval_set.formatted() + '\n'
43           for interval_set in package_interval_sets]
44  output_file.write(''.join(sorted(lines)))
45