Bug 1341207 - Use MachCommandConditions.is_{git,hg} for `mach clobber python`. r?chmanchester
--- a/python/mozbuild/mozbuild/base.py
+++ b/python/mozbuild/mozbuild/base.py
@@ -772,26 +772,32 @@ class MachCommandConditions(object):
return cls.substs.get('MOZ_WIDGET_TOOLKIT') == 'android'
return False
@staticmethod
def is_hg(cls):
"""Must have a mercurial source checkout."""
if hasattr(cls, 'substs'):
top_srcdir = cls.substs.get('top_srcdir')
- return top_srcdir and os.path.isdir(os.path.join(top_srcdir, '.hg'))
- return False
+ elif hasattr(cls, 'topsrcdir'):
+ top_srcdir = cls.topsrcdir
+ else:
+ return False
+ return top_srcdir and os.path.isdir(os.path.join(top_srcdir, '.hg'))
@staticmethod
def is_git(cls):
"""Must have a git source checkout."""
if hasattr(cls, 'substs'):
top_srcdir = cls.substs.get('top_srcdir')
- return top_srcdir and os.path.exists(os.path.join(top_srcdir, '.git'))
- return False
+ elif hasattr(cls, 'topsrcdir'):
+ top_srcdir = cls.topsrcdir
+ else:
+ return False
+ return top_srcdir and os.path.exists(os.path.join(top_srcdir, '.git'))
class PathArgument(object):
"""Parse a filesystem path argument and transform it in various ways."""
def __init__(self, arg, topsrcdir, topobjdir, cwd=None):
self.arg = arg
self.topsrcdir = topsrcdir
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -690,19 +690,19 @@ class Clobber(MachCommandBase):
if isinstance(e, WindowsError) and e.winerror in (5,32):
self.log(logging.ERROR, 'file_access_error', {'error': e},
"Could not clobber because a file was in use. If the "
"application is running, try closing it. {error}")
return 1
raise
if 'python' in what:
- if os.path.isdir(mozpath.join(self.topsrcdir, '.hg')):
+ if conditions.is_hg(self):
cmd = ['hg', 'purge', '--all', '-I', 'glob:**.py[co]']
- elif os.path.isdir(mozpath.join(self.topsrcdir, '.git')):
+ elif conditions.is_git(self):
cmd = ['git', 'clean', '-f', '-x', '*.py[co]']
else:
cmd = ['find', '.', '-type', 'f', '-name', '*.py[co]', '-delete']
ret = subprocess.call(cmd, cwd=self.topsrcdir)
return ret
@CommandProvider
class Logs(MachCommandBase):