Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / build / appini_header.py
blob4cf9481ea099c98ecaf9f3454b0a06cee35bbf1f
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(
27 ("%s:%s" % (s, o), config.get(s, o))
28 for s in config.sections()
29 for o in config.options(s)
31 appdata["flags"] = " | ".join(sorted(flags)) if flags else "0"
32 for key in ("App:vendor", "App:profile"):
33 # Set to NULL when not present or falsy such as an empty string
34 appdata[key] = '"%s"' % appdata[key] if appdata.get(key, None) else "NULL"
35 expected = (
36 "App:vendor",
37 "App:name",
38 "App:remotingname",
39 "App:version",
40 "App:buildid",
41 "App:id",
42 "Gecko:minversion",
43 "Gecko:maxversion",
45 missing = [var for var in expected if var not in appdata]
46 if missing:
47 print("Missing values in %s: %s" % (file, ", ".join(missing)), file=sys.stderr)
48 sys.exit(1)
50 if "Crash Reporter:serverurl" not in appdata:
51 appdata["Crash Reporter:serverurl"] = ""
53 if "App:sourcerepository" in appdata and "App:sourcestamp" in appdata:
54 appdata["App:sourceurl"] = (
55 '"%(App:sourcerepository)s/rev/%(App:sourcestamp)s"' % appdata
57 else:
58 appdata["App:sourceurl"] = "NULL"
60 if "AppUpdate:url" not in appdata:
61 appdata["AppUpdate:url"] = ""
63 output.write(
64 """#include "mozilla/XREAppData.h"
65 static const mozilla::StaticXREAppData sAppData = {
66 %(App:vendor)s,
67 "%(App:name)s",
68 "%(App:remotingname)s",
69 "%(App:version)s",
70 "%(App:buildid)s",
71 "%(App:id)s",
72 NULL, // copyright
73 %(flags)s,
74 "%(Gecko:minversion)s",
75 "%(Gecko:maxversion)s",
76 "%(Crash Reporter:serverurl)s",
77 %(App:profile)s,
78 NULL, // UAName
79 %(App:sourceurl)s,
80 "%(AppUpdate:url)s"
81 };"""
82 % appdata
86 if __name__ == "__main__":
87 if len(sys.argv) != 1:
88 main(sys.stdout, sys.argv[1])
89 else:
90 print("Usage: %s /path/to/application.ini" % sys.argv[0], file=sys.stderr)