зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1563797 - Use 'backports.shutil_which' instead of 'which' in configure r=glandium
This gets rid of the last use of the 'which' module left in the tree. So not only will this help 'configure' become a little more Python 3 compatible, but we can now remove 'third_party/python/which'. Differential Revision: https://phabricator.services.mozilla.com/D37427 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
4697628b6e
Коммит
ab88ef1f24
|
@ -162,12 +162,10 @@ normalize_path = normalize_path()
|
|||
# exists.
|
||||
# The `paths` parameter may be passed to search the given paths instead of
|
||||
# $PATH.
|
||||
@imports(_from='which', _import='which')
|
||||
@imports(_from='which', _import='WhichError')
|
||||
@imports('itertools')
|
||||
@imports('sys')
|
||||
@imports(_from='os', _import='pathsep')
|
||||
@imports(_from='os', _import='environ')
|
||||
@imports(_from='mozfile', _import='which')
|
||||
def find_program(file, paths=None):
|
||||
# The following snippet comes from `which` itself, with a slight
|
||||
# modification to use lowercase extensions, because it's confusing rustup
|
||||
|
@ -184,21 +182,18 @@ def find_program(file, paths=None):
|
|||
else:
|
||||
exts = None
|
||||
|
||||
try:
|
||||
if is_absolute_or_relative(file):
|
||||
return normalize_path(which(os.path.basename(file),
|
||||
[os.path.dirname(file)], exts=exts))
|
||||
if paths:
|
||||
if not isinstance(paths, (list, tuple)):
|
||||
die("Paths provided to find_program must be a list of strings, "
|
||||
"not %r", paths)
|
||||
paths = list(itertools.chain(
|
||||
*(p.split(pathsep) for p in paths if p)))
|
||||
else:
|
||||
paths = environ['PATH'].split(pathsep)
|
||||
return normalize_path(which(file, path=paths, exts=exts))
|
||||
except WhichError:
|
||||
return None
|
||||
if is_absolute_or_relative(file):
|
||||
path = which(os.path.basename(file), path=os.path.dirname(file), exts=exts)
|
||||
return normalize_path(path) if path else None
|
||||
|
||||
if paths:
|
||||
if not isinstance(paths, (list, tuple)):
|
||||
die("Paths provided to find_program must be a list of strings, "
|
||||
"not %r", paths)
|
||||
paths = pathsep.join(paths)
|
||||
|
||||
path = which(file, path=paths, exts=exts)
|
||||
return normalize_path(path) if path else None
|
||||
|
||||
|
||||
@imports('os')
|
||||
|
|
|
@ -11,13 +11,12 @@ import subprocess
|
|||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from StringIO import StringIO
|
||||
|
||||
from mozbuild.configure import ConfigureSandbox
|
||||
from mozbuild.util import ReadOnlyNamespace
|
||||
from mozpack import path as mozpath
|
||||
|
||||
from StringIO import StringIO
|
||||
from which import WhichError
|
||||
from six import string_types
|
||||
|
||||
from buildconfig import (
|
||||
topobjdir,
|
||||
|
@ -110,13 +109,12 @@ class ConfigureTestSandbox(ConfigureSandbox):
|
|||
if what in self.modules:
|
||||
return self.modules[what]
|
||||
|
||||
if what == 'which.which':
|
||||
if what == 'mozfile.which':
|
||||
return self.which
|
||||
|
||||
if what == 'which':
|
||||
if what == 'mozfile':
|
||||
return ReadOnlyNamespace(
|
||||
which=self.which,
|
||||
WhichError=WhichError,
|
||||
)
|
||||
|
||||
if what == 'subprocess.Popen':
|
||||
|
@ -186,18 +184,20 @@ class ConfigureTestSandbox(ConfigureSandbox):
|
|||
path_out.value = fake_short_path(path_in)
|
||||
return length
|
||||
|
||||
def which(self, command, path=None, exts=None):
|
||||
def which(self, command, mode=None, path=None, exts=None):
|
||||
if isinstance(path, string_types):
|
||||
path = path.split(os.pathsep)
|
||||
|
||||
for parent in (path or self._search_path):
|
||||
c = mozpath.abspath(mozpath.join(parent, command))
|
||||
for candidate in (c, ensure_exe_extension(c)):
|
||||
if self.imported_os.path.exists(candidate):
|
||||
return candidate
|
||||
raise WhichError()
|
||||
return None
|
||||
|
||||
def Popen(self, args, stdin=None, stdout=None, stderr=None, **kargs):
|
||||
try:
|
||||
program = self.which(args[0])
|
||||
except WhichError:
|
||||
program = self.which(args[0])
|
||||
if not program:
|
||||
raise OSError(errno.ENOENT, 'File not found')
|
||||
|
||||
func = self._subprocess_paths.get(program)
|
||||
|
|
Загрузка…
Ссылка в новой задаче