config/expandlibs_gen.py
author Neil Rashbrook <neil@parkwaycc.co.uk>
Sat, 02 Mar 2013 14:23:20 +0000
changeset 123926 1cd1a9fdf8fba4c777b4cb044cad1641c0186010
parent 123804 8f83edc05fa4d458d82668a95853c907544d0b8d
child 124287 92824d900e2576622751f1f51ea2ece1408b805a
permissions -rw-r--r--
Bug 738952 Make it possible for a stream converter to propagate the actual MIME type to the document r=bz

# 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 http://mozilla.org/MPL/2.0/.
from __future__ import print_function
'''Given a list of object files and library names, prints a library
descriptor to standard output'''

import sys
import os
import expandlibs_config as conf
from expandlibs import LibDescriptor, isObject, ensureParentDir, ExpandLibsDeps
from optparse import OptionParser

def generate(args):
    desc = LibDescriptor()
    for arg in args:
        if isObject(arg):
            if os.path.exists(arg):
                desc['OBJS'].append(os.path.abspath(arg))
            else:
                raise Exception("File not found: {0}".format(arg))
        elif os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
            if os.path.exists(arg) or os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
                desc['LIBS'].append(os.path.abspath(arg))
            else:
                raise Exception("File not found: {0}".format(arg))
    return desc

if __name__ == '__main__':
    parser = OptionParser()
    parser.add_option("--depend", dest="depend", metavar="FILE",
        help="generate dependencies for the given execution and store it in the given file")
    parser.add_option("-o", dest="output", metavar="FILE",
        help="send output to the given file")

    (options, args) = parser.parse_args()
    if not options.output:
        raise Exception("Missing option: -o")

    ensureParentDir(options.output)
    with open(options.output, 'w') as outfile:
        print(generate(args), file=outfile)
    if options.depend:
        ensureParentDir(options.depend)
        with open(options.depend, 'w') as depfile:
            depfile.write("{0} : {1}\n".format(options.output, 
                                               ' '.join(ExpandLibsDeps(args))))