Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2300)

Unified Diff: scripts/common/chromium_utils.py

Issue 2094713002: Include PowerShell in Windows PATH, if available. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Don't use Python reserved word... Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | slave/run_slave.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/common/chromium_utils.py
diff --git a/scripts/common/chromium_utils.py b/scripts/common/chromium_utils.py
index 89bee7a154060c32dca5725109bb8ff01f004618..07b0d5d709541707ad680cd128052b8498469be2 100644
--- a/scripts/common/chromium_utils.py
+++ b/scripts/common/chromium_utils.py
@@ -2039,3 +2039,59 @@ def IsClangWinBuild(build_dir, target):
if m:
return 'clang' in m.group('compiler_path')
return False
+
+# Everything below this point has been copied from the Python-3.3 sources with
+# the following modifications:
+#
+# The variable, "dir", was renamed to "pathcomp", since "dir" is a Python
+# reserved word.
+def Which(cmd, mode=os.F_OK | os.X_OK, path=None):
+ """Given a command, mode, and a PATH string, return the path which
+ conforms to the given mode on the PATH, or None if there is no such
+ file.
+ `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
+ of os.environ.get("PATH"), or can be overridden with a custom search
+ path.
+ """
+ # Check that a given file can be accessed with the correct mode.
+ # Additionally check that `file` is not a directory, as on Windows
+ # directories pass the os.access check.
+ def _access_check(fn, mode):
+ return (os.path.exists(fn) and os.access(fn, mode)
+ and not os.path.isdir(fn))
+
+ # Short circuit. If we're given a full path which matches the mode
+ # and it exists, we're done here.
+ if _access_check(cmd, mode):
+ return cmd
+
+ path = (path or os.environ.get("PATH", os.defpath)).split(os.pathsep)
+
+ if sys.platform == "win32":
+ # The current directory takes precedence on Windows.
+ if not os.curdir in path:
+ path.insert(0, os.curdir)
+
+ # PATHEXT is necessary to check on Windows.
+ pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
+ # See if the given file matches any of the expected path extensions.
+ # This will allow us to short circuit when given "python.exe".
+ matches = [cmd for ext in pathext if cmd.lower().endswith(ext.lower())]
+ # If it does match, only test that one, otherwise we have to try
+ # others.
+ files = [cmd] if matches else [cmd + ext.lower() for ext in pathext]
+ else:
+ # On other platforms you don't have things like PATHEXT to tell you
+ # what file suffixes are executable, so just pass on cmd as-is.
+ files = [cmd]
+
+ seen = set()
+ for pathcomp in path:
+ pathcomp = os.path.normcase(pathcomp)
+ if not pathcomp in seen:
+ seen.add(pathcomp)
+ for thefile in files:
+ name = os.path.join(pathcomp, thefile)
+ if _access_check(name, mode):
+ return name
+ return None
« no previous file with comments | « no previous file | slave/run_slave.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698