2012-05-21 15:12:37 +04:00
|
|
|
# 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/.
|
2011-11-22 11:05:59 +04:00
|
|
|
|
|
|
|
'''Parses a given application.ini file and outputs the corresponding
|
2016-12-02 17:07:24 +03:00
|
|
|
StaticXREAppData structure as a C++ header file'''
|
2011-11-22 11:05:59 +04:00
|
|
|
|
|
|
|
import ConfigParser
|
|
|
|
import sys
|
|
|
|
|
2017-10-07 17:45:22 +03:00
|
|
|
|
2016-04-29 20:45:07 +03:00
|
|
|
def main(output, file):
|
2011-11-22 11:05:59 +04:00
|
|
|
config = ConfigParser.RawConfigParser()
|
|
|
|
config.read(file)
|
|
|
|
flags = set()
|
|
|
|
try:
|
|
|
|
if config.getint('XRE', 'EnableProfileMigrator') == 1:
|
|
|
|
flags.add('NS_XRE_ENABLE_PROFILE_MIGRATOR')
|
2018-01-31 22:32:08 +03:00
|
|
|
except Exception:
|
2017-10-07 17:45:22 +03:00
|
|
|
pass
|
2011-11-22 11:05:59 +04:00
|
|
|
try:
|
|
|
|
if config.getint('Crash Reporter', 'Enabled') == 1:
|
|
|
|
flags.add('NS_XRE_ENABLE_CRASH_REPORTER')
|
2018-01-31 22:32:08 +03:00
|
|
|
except Exception:
|
2017-10-07 17:45:22 +03:00
|
|
|
pass
|
|
|
|
appdata = dict(("%s:%s" % (s, o), config.get(s, o))
|
|
|
|
for s in config.sections() for o in config.options(s))
|
2011-11-22 11:05:59 +04:00
|
|
|
appdata['flags'] = ' | '.join(flags) if flags else '0'
|
2017-10-07 17:45:22 +03:00
|
|
|
appdata['App:profile'] = ('"%s"' % appdata['App:profile']
|
|
|
|
if 'App:profile' in appdata else 'NULL')
|
2014-09-23 22:49:03 +04:00
|
|
|
expected = ('App:vendor', 'App:name', 'App:remotingname', 'App:version', 'App:buildid',
|
2013-08-31 05:20:37 +04:00
|
|
|
'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)
|
|
|
|
|
2017-10-07 17:45:22 +03:00
|
|
|
if 'Crash Reporter:serverurl' not in appdata:
|
2013-08-31 05:20:37 +04:00
|
|
|
appdata['Crash Reporter:serverurl'] = ''
|
2011-11-22 11:05:59 +04:00
|
|
|
|
2018-05-16 02:44:44 +03:00
|
|
|
if 'App:sourcerepository' in appdata and 'App:sourcestamp' in appdata:
|
|
|
|
appdata['App:sourceurl'] = '"%(App:sourcerepository)s/rev/%(App:sourcestamp)s"' % appdata
|
|
|
|
else:
|
|
|
|
appdata['App:sourceurl'] = 'NULL'
|
|
|
|
|
2016-12-02 17:07:24 +03:00
|
|
|
output.write('''#include "mozilla/XREAppData.h"
|
|
|
|
static const mozilla::StaticXREAppData sAppData = {
|
2011-11-22 11:05:59 +04:00
|
|
|
"%(App:vendor)s",
|
|
|
|
"%(App:name)s",
|
2014-09-23 22:49:03 +04:00
|
|
|
"%(App:remotingname)s",
|
2011-11-22 11:05:59 +04:00
|
|
|
"%(App:version)s",
|
|
|
|
"%(App:buildid)s",
|
|
|
|
"%(App:id)s",
|
|
|
|
NULL, // copyright
|
|
|
|
%(flags)s,
|
|
|
|
"%(Gecko:minversion)s",
|
|
|
|
"%(Gecko:maxversion)s",
|
|
|
|
"%(Crash Reporter:serverurl)s",
|
2018-05-16 02:44:44 +03:00
|
|
|
%(App:profile)s,
|
|
|
|
NULL, // UAName
|
|
|
|
%(App:sourceurl)s
|
2016-04-29 20:45:07 +03:00
|
|
|
};''' % appdata)
|
2011-11-22 11:05:59 +04:00
|
|
|
|
2017-10-07 17:45:22 +03:00
|
|
|
|
2011-11-22 11:05:59 +04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
if len(sys.argv) != 1:
|
2016-04-29 20:45:07 +03:00
|
|
|
main(sys.stdout, sys.argv[1])
|
2011-11-22 11:05:59 +04:00
|
|
|
else:
|
|
|
|
print >>sys.stderr, "Usage: %s /path/to/application.ini" % sys.argv[0]
|