Bug 1639153 - Part 6.6: Add tls dependency for truncate i32. r=lth
[gecko.git] / build / appini_header.py
blob1cbfe90e202875a5eab7034c610641c6fb35e71b
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 '''Parses a given application.ini file and outputs the corresponding
6 StaticXREAppData structure as a C++ header file'''
8 import configparser
9 import sys
12 def main(output, file):
13 config = configparser.RawConfigParser()
14 config.read(file)
15 flags = set()
16 try:
17 if config.getint('XRE', 'EnableProfileMigrator') == 1:
18 flags.add('NS_XRE_ENABLE_PROFILE_MIGRATOR')
19 except Exception:
20 pass
21 try:
22 if config.getint('Crash Reporter', 'Enabled') == 1:
23 flags.add('NS_XRE_ENABLE_CRASH_REPORTER')
24 except Exception:
25 pass
26 appdata = dict(("%s:%s" % (s, o), config.get(s, o))
27 for s in config.sections() for o in config.options(s))
28 appdata['flags'] = ' | '.join(sorted(flags)) if flags else '0'
29 appdata['App:profile'] = ('"%s"' % appdata['App:profile']
30 if 'App:profile' in appdata else 'NULL')
31 expected = ('App:vendor', 'App:name', 'App:remotingname', 'App:version', 'App:buildid',
32 'App:id', 'Gecko:minversion', 'Gecko:maxversion')
33 missing = [var for var in expected if var not in appdata]
34 if missing:
35 print("Missing values in %s: %s" % (file, ', '.join(missing)),
36 file=sys.stderr)
37 sys.exit(1)
39 if 'Crash Reporter:serverurl' not in appdata:
40 appdata['Crash Reporter:serverurl'] = ''
42 if 'App:sourcerepository' in appdata and 'App:sourcestamp' in appdata:
43 appdata['App:sourceurl'] = '"%(App:sourcerepository)s/rev/%(App:sourcestamp)s"' % appdata
44 else:
45 appdata['App:sourceurl'] = 'NULL'
47 if 'AppUpdate:url' not in appdata:
48 appdata['AppUpdate:url'] = ''
50 output.write('''#include "mozilla/XREAppData.h"
51 static const mozilla::StaticXREAppData sAppData = {
52 "%(App:vendor)s",
53 "%(App:name)s",
54 "%(App:remotingname)s",
55 "%(App:version)s",
56 "%(App:buildid)s",
57 "%(App:id)s",
58 NULL, // copyright
59 %(flags)s,
60 "%(Gecko:minversion)s",
61 "%(Gecko:maxversion)s",
62 "%(Crash Reporter:serverurl)s",
63 %(App:profile)s,
64 NULL, // UAName
65 %(App:sourceurl)s,
66 "%(AppUpdate:url)s"
67 };''' % appdata)
70 if __name__ == '__main__':
71 if len(sys.argv) != 1:
72 main(sys.stdout, sys.argv[1])
73 else:
74 print("Usage: %s /path/to/application.ini" % sys.argv[0],
75 file=sys.stderr)