summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorFranklinDM <mrmineshafter17@gmail.com>2022-08-17 15:17:18 +0800
committerFranklinDM <mrmineshafter17@gmail.com>2023-02-20 17:32:40 +0800
commitae476cc42cd5c95c5e1ff20146de84386d89dc83 (patch)
tree8292c2a4bd436092ffc31c70a705df3b8e617f60 /python
parent97f69387f47baaa051e8f8da20cb6126d4cc51ab (diff)
downloaduxp-ae476cc42cd5c95c5e1ff20146de84386d89dc83.tar.gz
No issue - Improve fallback handling and resolve PATH issues with python clobber command
Diffstat (limited to 'python')
-rw-r--r--python/mozbuild/mozbuild/mach_commands.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/python/mozbuild/mozbuild/mach_commands.py b/python/mozbuild/mozbuild/mach_commands.py
index a6d704300b..a423692c75 100644
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -707,15 +707,36 @@ class Clobber(MachCommandBase):
raise
if 'python' in what:
+ # TODO: Once we move to Python 3, we should probably use
+ # shutil.which to get the fully qualified path for these commands.
+ cmd = ''
if os.path.isdir(mozpath.join(self.topsrcdir, '.hg')):
cmd = ['hg', 'purge', '--all', '-I', 'glob:**.py[co]']
elif os.path.isdir(mozpath.join(self.topsrcdir, '.git')):
cmd = ['git', 'clean', '-f', '-x', '*.py[co]']
+
+ if not cmd:
+ ret = self.clobber_python_fallback()
else:
- cmd = ['find', '.', '-type', 'f', '-name', '*.py[co]', '-delete']
- ret = subprocess.call(cmd, cwd=self.topsrcdir)
+ # It is possible that git or hg is either not installed or
+ # excluded from PATH despite the existence of their data
+ # directories, so use a fallback instead of failing early.
+ try:
+ ret = subprocess.call(cmd, cwd=self.topsrcdir)
+ except OSError as e:
+ ret = self.clobber_python_fallback()
+
return ret
+ def clobber_python_fallback(self):
+ cmd = ['find', '.', '-type', 'f', '-name', '*.py[co]', '-delete']
+ # Execute the command through the shell if we're on Windows to ensure
+ # that our copy of `find` is run rather than the OS default.
+ # This is because on Windows, Popen (and by extension, subprocess.call)
+ # ignores PATH and looks only at the current working directory.
+ use_shell = sys.platform.startswith('win')
+ return subprocess.call(cmd, cwd=self.topsrcdir, shell=use_shell)
+
@CommandProvider
class Logs(MachCommandBase):
"""Provide commands to read mach logs."""