Bug 1696251 - Turn all properties in MachCommandBase subclasses into methods. r=mhentges,perftest-reviewers,sparky

As a step towards moving mach commands outside of classes, this converts all
properties into methods so that they can later become top-level helper functions.

Differential Revision: https://phabricator.services.mozilla.com/D112196
This commit is contained in:
Alex Lopez 2021-04-22 19:44:52 +00:00
parent 4f3a068f09
commit 41687360e8
5 changed files with 41 additions and 55 deletions

View File

@ -58,11 +58,9 @@ def inherit_command_args(command, subcommand=None):
@CommandProvider
class MachCommands(MachCommandBase):
@property
def state_dir(self):
return os.environ.get("MOZBUILD_STATE_PATH", os.path.expanduser("~/.mozbuild"))
@property
def tools_dir(self):
if os.environ.get("MOZ_FETCHES_DIR"):
# In automation, tools are provided by toolchain dependencies.
@ -72,17 +70,14 @@ class MachCommands(MachCommandBase):
# to avoid colliding with the "main" compiler versions, which can
# change separately (and the precompiled sixgill and compiler version
# must match exactly).
return os.path.join(self.state_dir, "hazard-tools")
return os.path.join(self.state_dir(), "hazard-tools")
@property
def sixgill_dir(self):
return os.path.join(self.tools_dir, "sixgill")
return os.path.join(self.tools_dir(), "sixgill")
@property
def gcc_dir(self):
return os.path.join(self.tools_dir, "gcc")
return os.path.join(self.tools_dir(), "gcc")
@property
def script_dir(self):
return os.path.join(self.topsrcdir, "js/src/devtools/rootAnalysis")
@ -97,13 +92,13 @@ class MachCommands(MachCommandBase):
# Force the use of hazard-compatible installs of tools.
def setup_env_for_tools(self, env):
gccbin = os.path.join(self.gcc_dir, "bin")
gccbin = os.path.join(self.gcc_dir(), "bin")
env["CC"] = os.path.join(gccbin, "gcc")
env["CXX"] = os.path.join(gccbin, "g++")
env["PATH"] = "{sixgill_dir}/usr/bin:{gccbin}:{PATH}".format(
sixgill_dir=self.sixgill_dir, gccbin=gccbin, PATH=env["PATH"]
sixgill_dir=self.sixgill_dir(), gccbin=gccbin, PATH=env["PATH"]
)
env["LD_LIBRARY_PATH"] = "{}/lib64".format(self.gcc_dir)
env["LD_LIBRARY_PATH"] = "{}/lib64".format(self.gcc_dir())
@Command(
"hazards",
@ -123,7 +118,7 @@ class MachCommands(MachCommandBase):
)
def bootstrap(self, command_context, **kwargs):
orig_dir = os.getcwd()
os.chdir(self.ensure_dir_exists(self.tools_dir))
os.chdir(self.ensure_dir_exists(self.tools_dir()))
try:
kwargs["from_build"] = ("linux64-gcc-sixgill", "linux64-gcc-8")
self._mach_context.commands.dispatch(
@ -237,11 +232,11 @@ no shell found in %s -- must build the JS shell with `mach hazards build-shell`
gcc_bin = "{gcc_dir}/bin"
"""
).format(
script_dir=self.script_dir,
script_dir=self.script_dir(),
objdir=objdir,
srcdir=self.topsrcdir,
sixgill_dir=self.sixgill_dir,
gcc_dir=self.gcc_dir,
sixgill_dir=self.sixgill_dir(),
gcc_dir=self.gcc_dir(),
)
fh.write(data)
@ -253,7 +248,7 @@ no shell found in %s -- must build the JS shell with `mach hazards build-shell`
]
)
args = [
os.path.join(self.script_dir, "analyze.py"),
os.path.join(self.script_dir(), "analyze.py"),
"dbs",
"--upto",
"dbs",
@ -316,7 +311,7 @@ no shell found in %s -- must build the JS shell with `mach hazards build-shell`
env["MOZCONFIG"] = os.path.join(self.topsrcdir, mozconfig_path)
# hazard mozconfigs need to find binaries in .mozbuild
env["MOZBUILD_STATE_PATH"] = self.state_dir
env["MOZBUILD_STATE_PATH"] = self.state_dir()
# Suppress the gathering of sources, to save disk space and memory.
env["XGILL_NO_SOURCE"] = "1"
@ -351,7 +346,7 @@ no shell found in %s -- must build the JS shell with `mach hazards build-shell`
shell = self.ensure_shell(shell_objdir)
args = [
os.path.join(self.script_dir, "analyze.py"),
os.path.join(self.script_dir(), "analyze.py"),
"--js",
shell,
"gcTypes",
@ -378,14 +373,14 @@ no shell found in %s -- must build the JS shell with `mach hazards build-shell`
"""Analyzed gathered data for rooting hazards"""
shell = self.ensure_shell(shell_objdir)
args = [
os.path.join(self.script_dir, "run-test.py"),
os.path.join(self.script_dir(), "run-test.py"),
"-v",
"--js",
shell,
"--sixgill",
os.path.join(self.tools_dir, "sixgill"),
os.path.join(self.tools_dir(), "sixgill"),
"--gccdir",
self.gcc_dir,
self.gcc_dir(),
]
self.setup_env_for_tools(os.environ)

View File

@ -272,7 +272,7 @@ class Clobber(MachCommandBase):
from mozbuild.controller.clobber import Clobberer
try:
Clobberer(self.topsrcdir, self.topobjdir, self.substs).remove_objdir(
Clobberer(self.topsrcdir, self.topobjdir, self.substs()).remove_objdir(
full
)
except OSError as e:
@ -336,7 +336,6 @@ class Clobber(MachCommandBase):
return ret
@property
def substs(self):
try:
return super(Clobber, self).substs
@ -412,15 +411,13 @@ class Logs(MachCommandBase):
class Warnings(MachCommandBase):
"""Provide commands for inspecting warnings."""
@property
def database_path(self):
return self._get_state_filename("warnings.json")
@property
def database(self):
from mozbuild.compilation.warnings import WarningsDatabase
path = self.database_path
path = self.database_path()
database = WarningsDatabase()
@ -448,7 +445,7 @@ class Warnings(MachCommandBase):
"recent report.",
)
def summary(self, command_context, directory=None, report=None):
database = self.database
database = self.database()
if directory:
dirpath = self.join_ensure_dir(self.topsrcdir, directory)
@ -489,7 +486,7 @@ class Warnings(MachCommandBase):
"recent report.",
)
def list(self, command_context, directory=None, flags=None, report=None):
database = self.database
database = self.database()
by_name = sorted(database.warnings)

View File

@ -154,13 +154,11 @@ host_fetches = {
@CommandProvider
class MachBrowsertime(MachCommandBase):
@property
def artifact_cache_path(self):
r"""Downloaded artifacts will be kept here."""
# The convention is $MOZBUILD_STATE_PATH/cache/$FEATURE.
return mozpath.join(self._mach_context.state_dir, "cache", "browsertime")
@property
def state_path(self):
r"""Unpacked artifacts will be kept here."""
# The convention is $MOZBUILD_STATE_PATH/$FEATURE.
@ -195,7 +193,7 @@ class MachBrowsertime(MachCommandBase):
# Download the visualmetrics.py requirements.
artifact_cache = ArtifactCache(
self.artifact_cache_path, log=self.log, skip_cache=False
self.artifact_cache_path(), log=self.log, skip_cache=False
)
fetches = host_fetches[host_platform()]
@ -206,8 +204,8 @@ class MachBrowsertime(MachCommandBase):
if fetch.get("unpack", True):
cwd = os.getcwd()
try:
mkdir(self.state_path)
os.chdir(self.state_path)
mkdir(self.state_path())
os.chdir(self.state_path())
self.log(
logging.INFO,
"browsertime",
@ -219,14 +217,14 @@ class MachBrowsertime(MachCommandBase):
# Windows archive does not contain a subfolder
# so we make one for it here
mkdir(fetch.get("path"))
os.chdir(os.path.join(self.state_path, fetch.get("path")))
os.chdir(os.path.join(self.state_path(), fetch.get("path")))
unpack_file(archive)
os.chdir(self.state_path)
os.chdir(self.state_path())
else:
unpack_file(archive)
# Make sure the expected path exists after extraction
path = os.path.join(self.state_path, fetch.get("path"))
path = os.path.join(self.state_path(), fetch.get("path"))
if not os.path.exists(path):
raise Exception("Cannot find an extracted directory: %s" % path)
@ -343,12 +341,12 @@ class MachBrowsertime(MachCommandBase):
# script doesn't take these as configuration, so we do this (for now).
# We should update the script itself to accept this configuration.
path = os.environ.get("PATH", "").split(os.pathsep) if append_path else []
path_to_ffmpeg = mozpath.join(self.state_path, fetches["ffmpeg"]["path"])
path_to_ffmpeg = mozpath.join(self.state_path(), fetches["ffmpeg"]["path"])
path_to_imagemagick = None
if "ImageMagick" in fetches:
path_to_imagemagick = mozpath.join(
self.state_path, fetches["ImageMagick"]["path"]
self.state_path(), fetches["ImageMagick"]["path"]
)
if path_to_imagemagick:
@ -356,7 +354,7 @@ class MachBrowsertime(MachCommandBase):
# want to ensure that our ffmpeg goes first, just in case.
path.insert(
0,
self.state_path
self.state_path()
if host_platform().startswith("win")
else mozpath.join(path_to_imagemagick, "bin"),
) # noqa

View File

@ -151,7 +151,7 @@ class Documentation(MachCommandBase):
from livereload import Server
from moztreedocs.package import create_tarball
unique_id = "%s/%s" % (self.project, str(uuid.uuid1()))
unique_id = "%s/%s" % (self.project(), str(uuid.uuid1()))
outdir = outdir or os.path.join(self.topobjdir, "docs")
savedir = os.path.join(outdir, fmt)
@ -187,12 +187,12 @@ class Documentation(MachCommandBase):
print("Generated " + write_url)
if archive:
archive_path = os.path.join(outdir, "%s.tar.gz" % self.project)
archive_path = os.path.join(outdir, "%s.tar.gz" % self.project())
create_tarball(archive_path, savedir)
print("Archived to %s" % archive_path)
if upload:
self._s3_upload(savedir, self.project, unique_id, self.version)
self._s3_upload(savedir, self.project(), unique_id, self.version())
if not serve:
index_path = os.path.join(savedir, "index.html")
@ -210,7 +210,7 @@ class Documentation(MachCommandBase):
server = Server()
sphinx_trees = self.manager.trees or {savedir: docdir}
sphinx_trees = self.manager().trees or {savedir: docdir}
for _, src in sphinx_trees.items():
run_sphinx = partial(
self._run_sphinx, src, savedir, fmt=fmt, jobs=jobs, verbose=verbose
@ -253,7 +253,7 @@ class Documentation(MachCommandBase):
):
import sphinx.cmd.build
config = config or self.manager.conf_py_path
config = config or self.manager().conf_py_path
args = [
"-T",
"-b",
@ -271,7 +271,6 @@ class Documentation(MachCommandBase):
print(args)
return sphinx.cmd.build.build_main(args)
@property
def manager(self):
if not self._manager:
from moztreedocs import manager
@ -282,7 +281,7 @@ class Documentation(MachCommandBase):
def _read_project_properties(self):
import imp
path = os.path.normpath(self.manager.conf_py_path)
path = os.path.normpath(self.manager().conf_py_path)
with open(path, "r") as fh:
conf = imp.load_module("doc_conf", fh, path, (".py", "r", imp.PY_SOURCE))
@ -295,13 +294,11 @@ class Documentation(MachCommandBase):
self._project = project
self._version = getattr(conf, "version", None)
@property
def project(self):
if not self._project:
self._read_project_properties()
return self._project
@property
def version(self):
if not self._version:
self._read_project_properties()

View File

@ -80,7 +80,6 @@ class TrySelect(MachCommandBase):
self.parser = self._mach_context.handler.parser
self._presets = None
@property
def presets(self):
if self._presets:
return self._presets
@ -111,9 +110,9 @@ class TrySelect(MachCommandBase):
"""
from tryselect.util.dicttools import merge
user_presets = self.presets.handlers[0]
user_presets = self.presets().handlers[0]
if preset_action == "list":
self.presets.list()
self.presets().list()
sys.exit()
if preset_action == "edit":
@ -134,11 +133,11 @@ class TrySelect(MachCommandBase):
sys.exit()
if preset:
if preset not in self.presets:
if preset not in self.presets():
self.parser.error("preset '{}' does not exist".format(preset))
name = preset
preset = self.presets[name]
preset = self.presets()[name]
selector = preset.pop("selector")
preset.pop("description", None) # description isn't used by any selectors
@ -218,10 +217,10 @@ class TrySelect(MachCommandBase):
# works no matter what subcommand 'foo' was saved with.
preset = kwargs["preset"]
if preset:
if preset not in self.presets:
if preset not in self.presets():
self.parser.error("preset '{}' does not exist".format(preset))
self.subcommand = self.presets[preset]["selector"]
self.subcommand = self.presets()[preset]["selector"]
sub = self.subcommand or self._mach_context.settings["try"]["default"]
return self._mach_context.commands.dispatch(