build/appini_header.py
author Jonathan Watt <jwatt@jwatt.org>
Mon, 09 Jan 2017 19:12:02 +0000
changeset 340973 b6959c93a4f797df7a6ce95e79a5490bc9004f04
parent 325744 a0e38abdcdd86d611d979dd7b64654da1f455494
child 385817 6074db12d685655fe5692d59471b3c32cc967dc9
permissions -rw-r--r--
Bug 1058040, part 6 - When copying SVGImageContexts use the copy ctor. r=dholbert Prior to this patch whenever we wanted to pass on a modified SVGImageContext we would pass on a new object initialized with some of the data of the object we were given and with the new data we wanted to change. Unfortunately we were sometimes failing to faithfully copy member data that we do not want to modify (because of default arguments). This patch fixes that by making us fully copy the object we were given using its copy constructor and then explicitly override the data we want to change.

# 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
   StaticXREAppData structure as a C++ header file'''

import ConfigParser
import sys

def main(output, file):
    config = ConfigParser.RawConfigParser()
    config.read(file)
    flags = set()
    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'
    expected = ('App:vendor', 'App:name', 'App:remotingname', 'App:version', 'App:buildid',
                'App:id', 'Gecko:minversion', 'Gecko:maxversion')
    missing = [var for var in expected if var not in appdata]
    if missing:
        print >>sys.stderr, \
            "Missing values in %s: %s" % (file, ', '.join(missing))
        sys.exit(1)

    if not 'Crash Reporter:serverurl' in appdata:
        appdata['Crash Reporter:serverurl'] = ''

    output.write('''#include "mozilla/XREAppData.h"
             static const mozilla::StaticXREAppData sAppData = {
                 "%(App:vendor)s",
                 "%(App:name)s",
                 "%(App:remotingname)s",
                 "%(App:version)s",
                 "%(App:buildid)s",
                 "%(App:id)s",
                 NULL, // copyright
                 %(flags)s,
                 "%(Gecko:minversion)s",
                 "%(Gecko:maxversion)s",
                 "%(Crash Reporter:serverurl)s",
                 %(App:profile)s
             };''' % appdata)

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