Bug 1323901 - Force which to use lowercase extensions on Windows. r=cmanchester+432261

--HG--
extra : rebase_source : 1932e63f7e02a80e5c83ee6bc0963d2c98d7fdd9
This commit is contained in:
Mike Hommey 2016-12-23 06:28:03 +09:00
parent b2b6b5c8d1
commit 74f8bb6e5e
2 changed files with 20 additions and 3 deletions

View File

@ -140,19 +140,36 @@ normalize_path = normalize_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')
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
# (on top of making results not really appealing to the eye).
# Windows has the concept of a list of extensions (PATHEXT env var).
if sys.platform.startswith("win"):
exts = [e.lower()
for e in environ.get("PATHEXT", "").split(pathsep)]
# If '.exe' is not in exts then obviously this is Win9x and
# or a bogus PATHEXT, then use a reasonable default.
if '.exe' not in exts:
exts = ['.com', '.exe', '.bat']
else:
exts = None
try:
if is_absolute_or_relative(file):
return normalize_path(which(os.path.basename(file),
[os.path.dirname(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)))
return normalize_path(which(file, path=paths))
return normalize_path(which(file, path=paths, exts=exts))
except WhichError:
return None

View File

@ -175,7 +175,7 @@ class ConfigureTestSandbox(ConfigureSandbox):
path_out.value = fake_short_path(path_in)
return length
def which(self, command, path=None):
def which(self, command, path=None, exts=None):
for parent in (path or self._search_path):
c = mozpath.abspath(mozpath.join(parent, command))
for candidate in (c, ensure_exe_extension(c)):