Bug 1439727 - Purge untracked files in python/ and third_party/python/; r?build draft
authorGregory Szorc <gps@mozilla.com>
Wed, 07 Mar 2018 15:06:21 -0800
changeset 764647 6de5c21f8d86391b4437176f45b4e1c9bd5ac099
parent 764317 78d0267c15f7960520c899e80cd824b21f258bdc
child 764648 ed299c2c4b1c67b3cc1a23e35ab7e856c25478ea
push id101807
push userbmo:gps@mozilla.com
push dateWed, 07 Mar 2018 23:06:39 +0000
Bug 1439727 - Purge untracked files in python/ and third_party/python/; r?build `mach clobber python` currently purges Python files with known extensions globally. The python/ and third_party/python/ directories may also contain random ignored/untracked files. Let's purge those as well. Note: if someone has untracked but not ignored files, this will delete them. This is possibly unwanted. But people shouldn't have untracked but not ignored files sitting around in VCS. We don't run this command by default, so I think it is safe to be aggressive in our purging of these untracked files. MozReview-Commit-ID: 8ql8QR6lP6j
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -349,18 +349,22 @@ class Clobber(MachCommandBase):
         things work again. This command can be used to perform that cleanup.
         By default, this command removes most files in the current object
         directory (where build output is stored). Some files (like Visual
         Studio project files) are not removed by default. If you would like
         to remove the object directory in its entirety, run with `--full`.
         The `python` target will clean up various generated Python files from
-        the source directory. Run this to remove .pyc files, compiled C
-        extensions, etc.
+        the source directory and will remove untracked files from well-known
+        directories containing Python packages. Run this to remove .pyc files,
+        compiled C extensions, etc. Note: all files not tracked or ignored by
+        version control in well-known Python package directories will be
+        deleted. Run the `status` command of your VCS to see if any untracked
+        files you haven't committed yet will be deleted.
         invalid = set(what) - set(self.CLOBBER_CHOICES)
         if invalid:
             print('Unknown clobber target(s): {}'.format(', '.join(invalid)))
             return 1
         ret = 0
         if 'objdir' in what:
@@ -373,21 +377,26 @@ class Clobber(MachCommandBase):
                         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
         if 'python' in what:
             if conditions.is_hg(self):
-                cmd = ['hg', 'purge', '--all', '-I', 'glob:**.py[cdo]']
+                cmd = ['hg', 'purge', '--all', '-I', 'glob:**.py[cdo]',
+                       '-I', 'path:python/', '-I', 'path:third_party/python/']
             elif conditions.is_git(self):
-                cmd = ['git', 'clean', '-f', '-x', '*.py[cdo]']
+                cmd = ['git', 'clean', '-f', '-x', '*.py[cdo]', 'python/',
+                       'third_party/python/']
-                cmd = ['find', '.', '-type', 'f', '-name', '*.py[cdo]', '-delete']
+                # We don't know what is tracked/untracked if we don't have VCS.
+                # So we can't clean python/ and third_party/python/.
+                cmd = ['find', '.', '-type', 'f', '-name', '*.py[cdo]',
+                       '-delete']
             ret = subprocess.call(cmd, cwd=self.topsrcdir)
         return ret
     def substs(self):
             return super(Clobber, self).substs
         except BuildEnvironmentNotFoundException: