2012-05-21 11:12:37 +00: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 07:05:59 +00:00
|
|
|
|
|
|
|
"""Parses a given application.ini file and outputs the corresponding
|
2016-12-02 14:07:24 +00:00
|
|
|
StaticXREAppData structure as a C++ header file"""
|
2011-11-22 07:05:59 +00:00
|
|
|
|
2020-03-05 17:06:08 +00:00
|
|
|
import configparser
|
2011-11-22 07:05:59 +00:00
|
|
|
import sys
|
|
|
|
|
2017-10-07 14:45:22 +00:00
|
|
|
|
2016-04-29 17:45:07 +00:00
|
|
|
def main(output, file):
|
2020-03-05 17:06:08 +00:00
|
|
|
config = configparser.RawConfigParser()
|
2011-11-22 07:05:59 +00:00
|
|
|
config.read(file)
|
|
|
|
flags = set()
|
|
|
|
try:
|
|
|
|
if config.getint("XRE", "EnableProfileMigrator") == 1:
|
|
|
|
flags.add("NS_XRE_ENABLE_PROFILE_MIGRATOR")
|
2018-01-31 19:32:08 +00:00
|
|
|
except Exception:
|
2017-10-07 14:45:22 +00:00
|
|
|
pass
|
2011-11-22 07:05:59 +00:00
|
|
|
try:
|
|
|
|
if config.getint("Crash Reporter", "Enabled") == 1:
|
|
|
|
flags.add("NS_XRE_ENABLE_CRASH_REPORTER")
|
2018-01-31 19:32:08 +00:00
|
|
|
except Exception:
|
2017-10-07 14:45:22 +00:00
|
|
|
pass
|
|
|
|
appdata = dict(
|
|
|
|
("%s:%s" % (s, o), config.get(s, o))
|
|
|
|
for s in config.sections()
|
|
|
|
for o in config.options(s)
|
2020-10-26 18:34:53 +00:00
|
|
|
)
|
2020-03-13 14:09:42 +00:00
|
|
|
appdata["flags"] = " | ".join(sorted(flags)) if flags else "0"
|
2022-11-01 23:51:51 +00:00
|
|
|
for key in ("App:vendor", "App:profile"):
|
|
|
|
# Set to NULL when not present or falsy such as an empty string
|
|
|
|
appdata[key] = '"%s"' % appdata[key] if appdata.get(key, None) else "NULL"
|
2014-09-23 18:49:03 +00:00
|
|
|
expected = (
|
|
|
|
"App:vendor",
|
|
|
|
"App:name",
|
|
|
|
"App:remotingname",
|
|
|
|
"App:version",
|
|
|
|
"App:buildid",
|
2020-03-31 21:11:10 +00:00
|
|
|
"App:id",
|
|
|
|
"Gecko:minversion",
|
|
|
|
"Gecko:maxversion",
|
|
|
|
)
|
2013-08-31 01:20:37 +00:00
|
|
|
missing = [var for var in expected if var not in appdata]
|
|
|
|
if missing:
|
2020-03-27 14:52:34 +00:00
|
|
|
print("Missing values in %s: %s" % (file, ", ".join(missing)), file=sys.stderr)
|
2013-08-31 01:20:37 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2017-10-07 14:45:22 +00:00
|
|
|
if "Crash Reporter:serverurl" not in appdata:
|
2013-08-31 01:20:37 +00:00
|
|
|
appdata["Crash Reporter:serverurl"] = ""
|
2011-11-22 07:05:59 +00:00
|
|
|
|
2018-05-15 23:44:44 +00:00
|
|
|
if "App:sourcerepository" in appdata and "App:sourcestamp" in appdata:
|
|
|
|
appdata["App:sourceurl"] = (
|
|
|
|
'"%(App:sourcerepository)s/rev/%(App:sourcestamp)s"' % appdata
|
2020-10-26 18:34:53 +00:00
|
|
|
)
|
2018-05-15 23:44:44 +00:00
|
|
|
else:
|
|
|
|
appdata["App:sourceurl"] = "NULL"
|
|
|
|
|
2020-03-31 21:11:10 +00:00
|
|
|
if "AppUpdate:url" not in appdata:
|
|
|
|
appdata["AppUpdate:url"] = ""
|
|
|
|
|
2016-12-02 14:07:24 +00:00
|
|
|
output.write(
|
|
|
|
"""#include "mozilla/XREAppData.h"
|
|
|
|
static const mozilla::StaticXREAppData sAppData = {
|
2022-11-01 23:51:51 +00:00
|
|
|
%(App:vendor)s,
|
2011-11-22 07:05:59 +00:00
|
|
|
"%(App:name)s",
|
2014-09-23 18:49:03 +00:00
|
|
|
"%(App:remotingname)s",
|
2011-11-22 07:05:59 +00: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-15 23:44:44 +00:00
|
|
|
%(App:profile)s,
|
|
|
|
NULL, // UAName
|
2020-03-26 00:57:13 +00:00
|
|
|
%(App:sourceurl)s,
|
|
|
|
"%(AppUpdate:url)s"
|
2016-04-29 17:45:07 +00:00
|
|
|
};"""
|
|
|
|
% appdata
|
|
|
|
)
|
2011-11-22 07:05:59 +00:00
|
|
|
|
2017-10-07 14:45:22 +00:00
|
|
|
|
2011-11-22 07:05:59 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
if len(sys.argv) != 1:
|
2016-04-29 17:45:07 +00:00
|
|
|
main(sys.stdout, sys.argv[1])
|
2011-11-22 07:05:59 +00:00
|
|
|
else:
|
2020-03-27 14:52:34 +00:00
|
|
|
print("Usage: %s /path/to/application.ini" % sys.argv[0], file=sys.stderr)
|