Bug 1341207 - Use MachCommandConditions.is_{git,hg} for `mach clobber python`. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 21 Feb 2017 16:04:08 +0900
changeset 487247 6ec6bdbed4f104ca9a19e2d1fd88d10869df85b3
parent 487246 faec268abbe3c6fd80a57a724a1a61b6f9afc9f9
child 546415 0ebc021e9472f098f0b14e649826e68004405a9c
push id46175
push userbmo:mh+mozilla@glandium.org
push dateTue, 21 Feb 2017 07:05:14 +0000
reviewerschmanchester
bugs1341207
milestone54.0a1
Bug 1341207 - Use MachCommandConditions.is_{git,hg} for `mach clobber python`. r?chmanchester
python/mozbuild/mozbuild/base.py
python/mozbuild/mozbuild/mach_commands.py
--- 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):