|
1 # This Source Code Form is subject to the terms of the Mozilla Public |
|
2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
4 |
|
5 # This file takes the .mk files from an upstream opus repo and generates the |
|
6 # sources.mozbuild file. It is invoked as part of update.sh |
|
7 |
|
8 import sys |
|
9 import re |
|
10 |
|
11 def add_value(values, text): |
|
12 text = text.replace('\\', '') |
|
13 text = text.strip() |
|
14 if text: |
|
15 values.append(text) |
|
16 |
|
17 def write_values(output, values): |
|
18 for value in sorted(values, key=lambda x: x.lower()): |
|
19 output.write(" '%s',\n" % value) |
|
20 output.write(']\n\n') |
|
21 |
|
22 def generate_sources_mozbuild(path): |
|
23 makefiles = [ |
|
24 'celt_sources.mk', |
|
25 'opus_sources.mk', |
|
26 'silk_sources.mk', |
|
27 ] |
|
28 |
|
29 var_definition = re.compile('([A-Z_]*) = (.*)') |
|
30 with open('sources.mozbuild', 'w') as output: |
|
31 |
|
32 output.write('# THIS FILE WAS AUTOMATICALLY GENERATED BY %s. DO NOT EDIT.\n' % sys.argv[0]) |
|
33 for makefile in makefiles: |
|
34 values = [] |
|
35 definition_started = False |
|
36 |
|
37 with open('%s/%s' % (path, makefile), 'r') as mk: |
|
38 for line in mk: |
|
39 line = line.rstrip() |
|
40 result = var_definition.match(line) |
|
41 if result: |
|
42 if definition_started: |
|
43 write_values(output, values) |
|
44 values = [] |
|
45 definition_started = True |
|
46 |
|
47 # Some variable definitions have the first entry on the |
|
48 # first line. Eg: |
|
49 # |
|
50 # CELT_SOURCES = celt/bands.c |
|
51 # |
|
52 # So we treat the first group as the variable name and |
|
53 # the second group as a potential value. |
|
54 # |
|
55 # Note that we write the variable name in lower case (so |
|
56 # "CELT_SOURCES" in the .mk file becomes "celt_sources" |
|
57 # in the .mozbuild file) because moz.build reserves |
|
58 # upper-case variable names for build system outputs. |
|
59 output.write('%s = [\n' % result.group(1).lower()) |
|
60 add_value(values, result.group(2)) |
|
61 else: |
|
62 add_value(values, line) |
|
63 write_values(output, values) |
|
64 |
|
65 if __name__ == '__main__': |
|
66 if len(sys.argv) != 2: |
|
67 print "Usage: %s /path/to/opus" % (sys.argv[0]) |
|
68 sys.exit(1) |
|
69 |
|
70 generate_sources_mozbuild(sys.argv[1]) |