build/appini_header.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build/appini_header.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,63 @@
     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 +'''Parses a given application.ini file and outputs the corresponding
     1.9 +   XULAppData structure as a C++ header file'''
    1.10 +
    1.11 +import ConfigParser
    1.12 +import sys
    1.13 +
    1.14 +def main(file):
    1.15 +    config = ConfigParser.RawConfigParser()
    1.16 +    config.read(file)
    1.17 +    flags = set()
    1.18 +    try:
    1.19 +        if config.getint('XRE', 'EnableExtensionManager') == 1:
    1.20 +            flags.add('NS_XRE_ENABLE_EXTENSION_MANAGER')
    1.21 +    except: pass
    1.22 +    try:
    1.23 +        if config.getint('XRE', 'EnableProfileMigrator') == 1:
    1.24 +            flags.add('NS_XRE_ENABLE_PROFILE_MIGRATOR')
    1.25 +    except: pass
    1.26 +    try:
    1.27 +        if config.getint('Crash Reporter', 'Enabled') == 1:
    1.28 +            flags.add('NS_XRE_ENABLE_CRASH_REPORTER')
    1.29 +    except: pass
    1.30 +    appdata = dict(("%s:%s" % (s, o), config.get(s, o)) for s in config.sections() for o in config.options(s))
    1.31 +    appdata['flags'] = ' | '.join(flags) if flags else '0'
    1.32 +    appdata['App:profile'] = '"%s"' % appdata['App:profile'] if 'App:profile' in appdata else 'NULL'
    1.33 +    expected = ('App:vendor', 'App:name', 'App:version', 'App:buildid',
    1.34 +                'App:id', 'Gecko:minversion', 'Gecko:maxversion')
    1.35 +    missing = [var for var in expected if var not in appdata]
    1.36 +    if missing:
    1.37 +        print >>sys.stderr, \
    1.38 +            "Missing values in %s: %s" % (file, ', '.join(missing))
    1.39 +        sys.exit(1)
    1.40 +
    1.41 +    if not 'Crash Reporter:serverurl' in appdata:
    1.42 +        appdata['Crash Reporter:serverurl'] = ''
    1.43 +
    1.44 +    print '''#include "nsXREAppData.h"
    1.45 +             static const nsXREAppData sAppData = {
    1.46 +                 sizeof(nsXREAppData),
    1.47 +                 NULL, // directory
    1.48 +                 "%(App:vendor)s",
    1.49 +                 "%(App:name)s",
    1.50 +                 "%(App:version)s",
    1.51 +                 "%(App:buildid)s",
    1.52 +                 "%(App:id)s",
    1.53 +                 NULL, // copyright
    1.54 +                 %(flags)s,
    1.55 +                 NULL, // xreDirectory
    1.56 +                 "%(Gecko:minversion)s",
    1.57 +                 "%(Gecko:maxversion)s",
    1.58 +                 "%(Crash Reporter:serverurl)s",
    1.59 +                 %(App:profile)s
    1.60 +             };''' % appdata
    1.61 +
    1.62 +if __name__ == '__main__':
    1.63 +    if len(sys.argv) != 1:
    1.64 +        main(sys.argv[1])
    1.65 +    else:
    1.66 +        print >>sys.stderr, "Usage: %s /path/to/application.ini" % sys.argv[0]

mercurial