Skip to content

Commit

Permalink
Bug 1696251 - Replace self with command_context where possible in exi…
Browse files Browse the repository at this point in the history
…sting mach commands. r=mhentges,webdriver-reviewers,perftest-reviewers,whimboo

This step removes all the dependencies of mach commands to
having a MachCommandBase as the `self` by using the `command_context`
argument instead. This also removes any remaining statefulness from those
classes that implement mach commands, ultimately making it easier to move
existing commands out of classes in a follow-up.

Differential Revision: https://phabricator.services.mozilla.com/D118058
  • Loading branch information
alopezz committed Jul 19, 2021
1 parent 0352953 commit 77ce415
Show file tree
Hide file tree
Showing 53 changed files with 1,815 additions and 1,427 deletions.
24 changes: 13 additions & 11 deletions build/valgrind/mach_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def valgrind_test(self, command_context, suppressions):
from six import string_types
from valgrind.output_handler import OutputHandler

build_dir = os.path.join(self.topsrcdir, "build")
build_dir = os.path.join(command_context.topsrcdir, "build")

# XXX: currently we just use the PGO inputs for Valgrind runs. This may
# change in the future.
Expand All @@ -68,7 +68,9 @@ def valgrind_test(self, command_context, suppressions):

with TemporaryDirectory() as profilePath:
# TODO: refactor this into mozprofile
profile_data_dir = os.path.join(self.topsrcdir, "testing", "profiles")
profile_data_dir = os.path.join(
command_context.topsrcdir, "testing", "profiles"
)
with open(os.path.join(profile_data_dir, "profiles.json"), "r") as fh:
base_profiles = json.load(fh)["valgrind"]

Expand All @@ -89,7 +91,7 @@ def valgrind_test(self, command_context, suppressions):
prefs[k] = Preferences.cast(v)

quitter = os.path.join(
self.topsrcdir, "tools", "quitter", "[email protected]"
command_context.topsrcdir, "tools", "quitter", "[email protected]"
)

locations = ServerLocations()
Expand All @@ -113,7 +115,7 @@ def valgrind_test(self, command_context, suppressions):
env["MOZ_DISABLE_NONLOCAL_CONNECTIONS"] = "1"
env["XPCOM_DEBUG_BREAK"] = "warn"

outputHandler = OutputHandler(self.log)
outputHandler = OutputHandler(command_context.log)
kp_kwargs = {
"processOutputLine": [outputHandler],
"universal_newlines": True,
Expand Down Expand Up @@ -171,7 +173,7 @@ def valgrind_test(self, command_context, suppressions):
try:
runner = FirefoxRunner(
profile=profile,
binary=self.get_binary_path(),
binary=command_context.get_binary_path(),
cmdargs=firefox_args,
env=env,
process_args=kp_kwargs,
Expand All @@ -185,7 +187,7 @@ def valgrind_test(self, command_context, suppressions):
supps = outputHandler.suppression_count
if errs != supps:
status = 1 # turns the TBPL job orange
self.log(
command_context.log(
logging.ERROR,
"valgrind-fail-parsing",
{"errs": errs, "supps": supps},
Expand All @@ -195,7 +197,7 @@ def valgrind_test(self, command_context, suppressions):

elif errs == 0:
status = 0
self.log(
command_context.log(
logging.INFO,
"valgrind-pass",
{},
Expand All @@ -207,21 +209,21 @@ def valgrind_test(self, command_context, suppressions):

if binary_not_found_exception:
status = 2 # turns the TBPL job red
self.log(
command_context.log(
logging.ERROR,
"valgrind-fail-errors",
{"error": str(binary_not_found_exception)},
"TEST-UNEXPECTED-FAIL | valgrind-test | {error}",
)
self.log(
command_context.log(
logging.INFO,
"valgrind-fail-errors",
{"help": binary_not_found_exception.help()},
"{help}",
)
elif exitcode is None:
status = 2 # turns the TBPL job red
self.log(
command_context.log(
logging.ERROR,
"valgrind-fail-timeout",
{"timeout": timeout},
Expand All @@ -230,7 +232,7 @@ def valgrind_test(self, command_context, suppressions):
)
elif exitcode != 0:
status = 2 # turns the TBPL job red
self.log(
command_context.log(
logging.ERROR,
"valgrind-fail-errors",
{"exitcode": exitcode},
Expand Down
27 changes: 16 additions & 11 deletions devtools/shared/css/generated/mach_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,39 @@ def generate_css_db(self, command_context):
"""Generate the static css properties database for devtools and write it to file."""

print("Re-generating the css properties database...")
db = self.get_properties_db_from_xpcshell()
db = self.get_properties_db_from_xpcshell(command_context)
if not db:
return 1

self.output_template(
command_context,
{
"preferences": stringify(db["preferences"]),
"cssProperties": stringify(db["cssProperties"]),
"pseudoElements": stringify(db["pseudoElements"]),
}
},
)

def get_properties_db_from_xpcshell(self):
def get_properties_db_from_xpcshell(self, command_context):
"""Generate the static css properties db for devtools from an xpcshell script."""
build = MozbuildObject.from_environment()

# Get the paths
script_path = resolve_path(
self.topsrcdir, "devtools/shared/css/generated/generate-properties-db.js"
command_context.topsrcdir,
"devtools/shared/css/generated/generate-properties-db.js",
)
gre_path = resolve_path(self.topobjdir, "dist/bin")
browser_path = resolve_path(self.topobjdir, "dist/bin/browser")
gre_path = resolve_path(command_context.topobjdir, "dist/bin")
browser_path = resolve_path(command_context.topobjdir, "dist/bin/browser")
try:
xpcshell_path = build.get_binary_path(what="xpcshell")
except BinaryNotFoundException as e:
self.log(
command_context.log(
logging.ERROR, "devtools-css-db", {"error": str(e)}, "ERROR: {error}"
)
self.log(logging.INFO, "devtools-css-db", {"help": e.help()}, "{help}")
command_context.log(
logging.INFO, "devtools-css-db", {"help": e.help()}, "{help}"
)
return None

print(browser_path)
Expand All @@ -98,13 +102,14 @@ def get_properties_db_from_xpcshell(self):

return json.loads(contents)

def output_template(self, substitutions):
def output_template(self, command_context, substitutions):
"""Output a the properties-db.js from a template."""
js_template_path = resolve_path(
self.topsrcdir, "devtools/shared/css/generated/properties-db.js.in"
command_context.topsrcdir,
"devtools/shared/css/generated/properties-db.js.in",
)
destination_path = resolve_path(
self.topsrcdir, "devtools/shared/css/generated/properties-db.js"
command_context.topsrcdir, "devtools/shared/css/generated/properties-db.js"
)

with open(js_template_path, "rb") as handle:
Expand Down
12 changes: 7 additions & 5 deletions dom/bindings/mach_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class WebIDLProvider(MachCommandBase):
def webidl_example(self, command_context, interface):
from mozwebidlcodegen import BuildSystemWebIDL

manager = self._spawn(BuildSystemWebIDL).manager
manager = command_context._spawn(BuildSystemWebIDL).manager
for i in interface:
manager.generate_example_files(i)

Expand All @@ -47,15 +47,17 @@ def webidl_example(self, command_context, interface):
description="Run WebIDL tests (Interface Browser parser).",
)
def webidl_test(self, command_context, **kwargs):
sys.path.insert(0, os.path.join(self.topsrcdir, "other-licenses", "ply"))
sys.path.insert(
0, os.path.join(command_context.topsrcdir, "other-licenses", "ply")
)

# Ensure the topobjdir exists. On a Taskcluster test run there won't be
# an objdir yet.
mkdir(self.topobjdir)
mkdir(command_context.topobjdir)

# Make sure we drop our cached grammar bits in the objdir, not
# wherever we happen to be running from.
os.chdir(self.topobjdir)
os.chdir(command_context.topobjdir)

if kwargs["verbose"] is None:
kwargs["verbose"] = False
Expand All @@ -64,7 +66,7 @@ def webidl_test(self, command_context, **kwargs):
# objdir. But we're going to try loading it as a python
# module, so we need to make sure the objdir is in our search
# path.
sys.path.insert(0, self.topobjdir)
sys.path.insert(0, command_context.topobjdir)

import runtests

Expand Down
Loading

0 comments on commit 77ce415

Please sign in to comment.