author ffxbld <>
Fri, 28 Nov 2014 10:39:09 -0500
changeset 217973 b7b1b66574398f1dcd50ff1a50ba340c8b63c034
parent 164545 2a98d3ec8f9215e512625eebd01414dc1ffcd276
child 278547 a2033de17d559eea167c1f3600172a70f3de0ffa
permissions -rw-r--r--
Update configs. IGNORE BROKEN CHANGESETS CLOSED TREE NO BUG a=release ba=release

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at

# This file takes the .mk files from an upstream opus repo and generates the
# sources.mozbuild file. It is invoked as part of

import sys
import re

def add_value(values, text):
    text = text.replace('\\', '')
    text = text.strip()
    if text:

def write_values(output, values):
    for value in sorted(values, key=lambda x: x.lower()):
        output.write("    '%s',\n" % value)

def generate_sources_mozbuild(path):
    makefiles = [

    var_definition = re.compile('([A-Z_]*) = (.*)')
    with open('sources.mozbuild', 'w') as output:

        output.write('# THIS FILE WAS AUTOMATICALLY GENERATED BY %s. DO NOT EDIT.\n' % sys.argv[0])
        for makefile in makefiles:
            values = []
            definition_started = False

            with open('%s/%s' % (path, makefile), 'r') as mk:
                for line in mk:
                    line = line.rstrip()
                    result = var_definition.match(line)
                    if result:
                        if definition_started:
                            write_values(output, values)
                            values = []
                        definition_started = True

                        # Some variable definitions have the first entry on the
                        # first line. Eg:
                        # CELT_SOURCES = celt/bands.c
                        # So we treat the first group as the variable name and
                        # the second group as a potential value.
                        # Note that we write the variable name in lower case (so
                        # "CELT_SOURCES" in the .mk file becomes "celt_sources"
                        # in the .mozbuild file) because reserves
                        # upper-case variable names for build system outputs.
                        output.write('%s = [\n' %
                        add_value(values, line)
            write_values(output, values)

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print "Usage: %s /path/to/opus" % (sys.argv[0])