Skip to content

Commit

Permalink
Bug 1749385 - Generate CrashManager.jsm from template r=gsvelto,nalex…
Browse files Browse the repository at this point in the history
…ander

Differential Revision: https://phabricator.services.mozilla.com/D136109
  • Loading branch information
Alexandre Lissy committed Jan 18, 2022
1 parent f65bde9 commit f1d6617
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 78 deletions.
3 changes: 0 additions & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,5 @@ tools/update-packaging/**/*refs.js
# Ignore backgroundtasks preferences files.
toolkit/components/backgroundtasks/defaults

# Uses preprocessing
toolkit/components/crashes/CrashManager.jsm

# Ignore pre-generated webpack and typescript transpiled files for translations
browser/extensions/translations/extension/
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ var CrashManager = function(options) {
};

CrashManager.prototype = Object.freeze({
#includesubst @OBJDIR@/GeckoProcessTypes_CrashManager_map.js
// gen_CrashManager.py will input the proper process map informations.
/* SUBST: CRASH_MANAGER_PROCESS_MAP */

// A real crash.
CRASH_TYPE_CRASH: "crash",
Expand Down Expand Up @@ -506,7 +507,9 @@ CrashManager.prototype = Object.freeze({
* @return boolean True or False depending on whether ping is allowed
**/
isPingAllowed(processType) {
#includesubst @OBJDIR@/GeckoProcessTypes_CrashManager_pings.js
// gen_CrashManager.py will input the proper process pings informations.

/* SUBST: CRASH_MANAGER_PROCESS_PINGS */

// Should not even reach this because of isValidProcessType() but just in
// case we try to be cautious
Expand Down
57 changes: 57 additions & 0 deletions toolkit/components/crashes/gen_CrashManager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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/.

from geckoprocesstypes import process_types


def process_name(string_name):
if string_name == "default":
string_name = "main"
if string_name == "tab":
string_name = "content"
return string_name


def gen_process_map():
kIdentifier = "/* SUBST: CRASH_MANAGER_PROCESS_MAP */"
crashManagerMap = """
processTypes: {"""

for p in process_types:
crashManagerMap += """
// A crash in the %(procname)s process.
%(proctype)d: "%(procname)s",""" % {
"proctype": p.enum_value,
"procname": process_name(p.string_name),
}
crashManagerMap += """
},"""

return (kIdentifier, crashManagerMap)


def gen_process_pings():
kIdentifier = "/* SUBST: CRASH_MANAGER_PROCESS_PINGS */"
crashManagerPing = """let processPings = {"""

for p in process_types:
crashManagerPing += """
"%(proctype)s": %(crashping)s,""" % {
"proctype": process_name(p.string_name),
"crashping": "true" if p.crash_ping else "false",
}
crashManagerPing += """
};"""

return (kIdentifier, crashManagerPing)


def main(o, crashManager):
subst = [gen_process_map(), gen_process_pings()]
with open(crashManager, "r") as src:
for l in src.readlines():
for (id, value) in subst:
if id in l:
l = l.replace(id, value)
o.write(l)
32 changes: 0 additions & 32 deletions toolkit/components/crashes/gen_process_map.py

This file was deleted.

29 changes: 0 additions & 29 deletions toolkit/components/crashes/gen_process_pings.py

This file was deleted.

15 changes: 4 additions & 11 deletions toolkit/components/crashes/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,14 @@ XPIDL_SOURCES += [

if CONFIG["MOZ_CRASHREPORTER"]:
GeneratedFile(
"GeckoProcessTypes_CrashManager_map.js",
script="gen_process_map.py",
entry_point="main",
)
GeneratedFile(
"GeckoProcessTypes_CrashManager_pings.js",
script="gen_process_pings.py",
"CrashManager.jsm",
script="gen_CrashManager.py",
entry_point="main",
inputs=["CrashManager.jsm.in"],
)

EXTRA_PP_JS_MODULES += [
"CrashManager.jsm",
]

EXTRA_JS_MODULES += [
"!CrashManager.jsm",
"CrashService.jsm",
]

Expand Down
2 changes: 1 addition & 1 deletion tools/lint/rejected-words.yml
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ avoid-blacklist-and-whitelist:
- toolkit/components/antitracking/test/browser/browser_siteSpecificWorkArounds.js
- toolkit/components/antitracking/test/browser/browser_socialtracking_save_image.js
- toolkit/components/antitracking/test/xpcshell/test_rejectForeignAllowList.js
- toolkit/components/crashes/CrashManager.jsm
- toolkit/components/crashes/CrashManager.jsm.in
- toolkit/components/crashes/tests/xpcshell/test_crash_manager.js
- toolkit/components/extensions/Extension.jsm
- toolkit/components/extensions/test/xpcshell/test_WebExtensionPolicy.js
Expand Down

0 comments on commit f1d6617

Please sign in to comment.