Bug 1341207 - Use MachCommandConditions.is_{git,hg} for `mach clobber python`. r=chmanchester
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 21 Feb 2017 16:04:08 +0900
changeset 390743 b819211e52a441b4edee1d32e448da80b20ee310
parent 390742 b26e27c14e49f0c025dadc61b3ea6d9aa58ca67f
child 390744 f872b2b4adee721a649b8dadd950d1a19403ce69
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1341207
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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):