Skip to content

Commit

Permalink
Bug 1323901 - Force which to use lowercase extensions on Windows. r…
Browse files Browse the repository at this point in the history
…=cmanchester+432261

--HG--
extra : rebase_source : 1932e63f7e02a80e5c83ee6bc0963d2c98d7fdd9
  • Loading branch information
glandium committed Dec 22, 2016
1 parent b2b6b5c commit 74f8bb6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions build/moz.configure/util.configure
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion python/mozbuild/mozbuild/test/configure/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def GetShortPathNameW(self, path_in, path_out, length):
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)):
Expand Down

0 comments on commit 74f8bb6

Please sign in to comment.