config/expandlibs_gen.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/config/expandlibs_gen.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,50 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +'''Given a list of object files and library names, prints a library
     1.9 +descriptor to standard output'''
    1.10 +
    1.11 +from __future__ import with_statement
    1.12 +import sys
    1.13 +import os
    1.14 +import expandlibs_config as conf
    1.15 +from expandlibs import LibDescriptor, isObject, ensureParentDir, ExpandLibsDeps
    1.16 +from optparse import OptionParser
    1.17 +
    1.18 +def generate(args):
    1.19 +    desc = LibDescriptor()
    1.20 +    for arg in args:
    1.21 +        if isObject(arg):
    1.22 +            if os.path.exists(arg):
    1.23 +                desc['OBJS'].append(os.path.abspath(arg))
    1.24 +            else:
    1.25 +                raise Exception("File not found: %s" % arg)
    1.26 +        elif os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
    1.27 +            if os.path.exists(arg) or os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
    1.28 +                desc['LIBS'].append(os.path.abspath(arg))
    1.29 +            else:
    1.30 +                raise Exception("File not found: %s" % arg)
    1.31 +    return desc
    1.32 +
    1.33 +if __name__ == '__main__':
    1.34 +    parser = OptionParser()
    1.35 +    parser.add_option("--depend", dest="depend", metavar="FILE",
    1.36 +        help="generate dependencies for the given execution and store it in the given file")
    1.37 +    parser.add_option("-o", dest="output", metavar="FILE",
    1.38 +        help="send output to the given file")
    1.39 +
    1.40 +    (options, args) = parser.parse_args()
    1.41 +    if not options.output:
    1.42 +        raise Exception("Missing option: -o")
    1.43 +
    1.44 +    ensureParentDir(options.output)
    1.45 +    with open(options.output, 'w') as outfile:
    1.46 +        print >>outfile, generate(args)
    1.47 +    if options.depend:
    1.48 +        ensureParentDir(options.depend)
    1.49 +        with open(options.depend, 'w') as depfile:
    1.50 +            deps = ExpandLibsDeps(args)
    1.51 +            depfile.write("%s : %s\n" % (options.output, ' '.join(deps)))
    1.52 +            for dep in deps:
    1.53 +                depfile.write("%s :\n" % dep)

mercurial