Bug 803400 - Add clobber mach command; r=glandium
authorGregory Szorc <gps@mozilla.com>
Wed, 05 Dec 2012 22:46:01 -0800
changeset 116571 051613fd8775ca08852db74e244aff2324ae2146
parent 116568 7dcc0be8d4aa8d113092e30599b4e6e0cacd8d89
child 116572 5f626f86b374315531fa35e68492d3475976c162
push idunknown
push userunknown
push dateunknown
reviewersglandium
bugs803400
milestone20.0a1
Bug 803400 - Add clobber mach command; r=glandium DONTBUILD (NPOTB)
mach
python/mozbuild/mozbuild/base.py
python/mozbuild/mozbuild/mach_commands.py
--- a/mach
+++ b/mach
@@ -27,16 +27,17 @@ SEARCH_PATHS = [
     'python/blessings',
     'python/psutil',
     'python/which',
     'other-licenses/ply',
     'xpcom/idl-parser',
     'testing',
     'testing/xpcshell',
     'testing/mozbase/mozprocess',
+    'testing/mozbase/mozfile',
     'testing/mozbase/mozinfo',
 ]
 
 # Individual files providing mach commands.
 MACH_MODULES = [
     'layout/tools/reftest/mach_commands.py',
     'python/mozboot/mozboot/mach_commands.py',
     'python/mozbuild/mozbuild/config.py',
--- a/python/mozbuild/mozbuild/base.py
+++ b/python/mozbuild/mozbuild/base.py
@@ -8,16 +8,18 @@ import logging
 import os
 import subprocess
 import sys
 import which
 
 from mach.mixin.logging import LoggingMixin
 from mach.mixin.process import ProcessExecutionMixin
 
+from mozfile.mozfile import rmtree
+
 from .config import BuildConfig
 from .mozconfig import (
     MozconfigFindException,
     MozconfigLoadException,
     MozconfigLoader,
 )
 
 
@@ -77,16 +79,23 @@ class MozbuildObject(ProcessExecutionMix
     @property
     def bindir(self):
         return os.path.join(self.topobjdir, 'dist', 'bin')
 
     @property
     def statedir(self):
         return os.path.join(self.topobjdir, '.mozbuild')
 
+    def remove_objdir(self):
+        """Remove the entire object directory."""
+
+        # We use mozfile because it is faster than shutil.rmtree().
+        # mozfile doesn't like unicode arguments (bug 818783).
+        rmtree(self.topobjdir.encode('utf-8'))
+
     @property
     def _config_guess(self):
         if self._config_guess_output is None:
             p = os.path.join(self.topsrcdir, 'build', 'autoconf',
                 'config.guess')
             args = self._normalize_command([p], True)
             self._config_guess_output = subprocess.check_output(args,
                 cwd=self.topsrcdir).strip()
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -56,16 +56,21 @@ class Build(MachCommandBase):
         self.log(logging.WARNING, 'warning_summary',
             {'count': len(warnings_collector.database)},
             '{count} compiler warnings present.')
 
         warnings_database.save_to_file(warnings_path)
 
         return status
 
+    @Command('clobber', help='Clobber the tree (delete the object directory).')
+    def clobber(self):
+        self.remove_objdir()
+        return 0
+
 
 @CommandProvider
 class Warnings(MachCommandBase):
     """Provide commands for inspecting warnings."""
 
     @property
     def database_path(self):
         return self._get_state_filename('warnings.json')