build/appini_header.py
author L. David Baron <dbaron@dbaron.org>
Thu, 21 Feb 2013 18:10:59 -0800
changeset 122588 b968708558b928354922880cb98501cb80ae3338
parent 94484 f4157e8c410708d76703f19e4dfb61859bfe32d8
child 145146 c59d6e7fdee5310c270e82ecde0ed62fb8de1e80
permissions -rw-r--r--
Bug 839809: Make counter-increments and list counting that would go past our internal (int32_t) limit keep the counter at its current value rather than wrapping. r=dholbert Per CSS WG resolution regarding counter-styles-3, afternoon of 2013-02-05: http://krijnhoetmer.nl/irc-logs/css/20130205#l-1590 http://lists.w3.org/Archives/Public/www-style/2013Feb/0392.html Note that this patch depends on signed integer overflow behavior in C++, which I believe is portable despite being unspecified.

# 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/.

'''Parses a given application.ini file and outputs the corresponding
   XULAppData structure as a C++ header file'''

import ConfigParser
import sys

def main(file):
    config = ConfigParser.RawConfigParser()
    config.read(file)
    flags = set()
    try:
        if config.getint('XRE', 'EnableExtensionManager') == 1:
            flags.add('NS_XRE_ENABLE_EXTENSION_MANAGER')
    except: pass
    try:
        if config.getint('XRE', 'EnableProfileMigrator') == 1:
            flags.add('NS_XRE_ENABLE_PROFILE_MIGRATOR')
    except: pass
    try:
        if config.getint('Crash Reporter', 'Enabled') == 1:
            flags.add('NS_XRE_ENABLE_CRASH_REPORTER')
    except: pass
    appdata = dict(("%s:%s" % (s, o), config.get(s, o)) for s in config.sections() for o in config.options(s))
    appdata['flags'] = ' | '.join(flags) if flags else '0'
    appdata['App:profile'] = '"%s"' % appdata['App:profile'] if 'App:profile' in appdata else 'NULL'

    print '''#include "nsXREAppData.h"
             static const nsXREAppData sAppData = {
                 sizeof(nsXREAppData),
                 NULL, // directory
                 "%(App:vendor)s",
                 "%(App:name)s",
                 "%(App:version)s",
                 "%(App:buildid)s",
                 "%(App:id)s",
                 NULL, // copyright
                 %(flags)s,
                 NULL, // xreDirectory
                 "%(Gecko:minversion)s",
                 "%(Gecko:maxversion)s",
                 "%(Crash Reporter:serverurl)s",
                 %(App:profile)s
             };''' % appdata

if __name__ == '__main__':
    if len(sys.argv) != 1:
        main(sys.argv[1])
    else:
        print >>sys.stderr, "Usage: %s /path/to/application.ini" % sys.argv[0]