Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """ Set of basic operations/utilities that are used by the build. """ | 5 """ Set of basic operations/utilities that are used by the build. """ |
| 6 | 6 |
| 7 from contextlib import contextmanager | 7 from contextlib import contextmanager |
| 8 import ast | 8 import ast |
| 9 import base64 | 9 import base64 |
| 10 import cStringIO | 10 import cStringIO |
| (...skipping 2021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2032 return False | 2032 return False |
| 2033 # Matches e.g. "cl_x86 = path/to/clang-cl.exe" | 2033 # Matches e.g. "cl_x86 = path/to/clang-cl.exe" |
| 2034 clang_cl_re = re.compile( | 2034 clang_cl_re = re.compile( |
| 2035 r'^cl_x\d\d\s+\=\s+(?P<compiler_path>[^ ]+)\s.*$', | 2035 r'^cl_x\d\d\s+\=\s+(?P<compiler_path>[^ ]+)\s.*$', |
| 2036 re.VERBOSE) | 2036 re.VERBOSE) |
| 2037 for line in open(build_file): | 2037 for line in open(build_file): |
| 2038 m = clang_cl_re.match(line) | 2038 m = clang_cl_re.match(line) |
| 2039 if m: | 2039 if m: |
| 2040 return 'clang' in m.group('compiler_path') | 2040 return 'clang' in m.group('compiler_path') |
| 2041 return False | 2041 return False |
| 2042 | |
| 2043 # Everything below this point has been copied from the Python-3.3 sources. | |
| 2044 def Which(cmd, mode=os.F_OK | os.X_OK, path=None): | |
| 2045 """Given a command, mode, and a PATH string, return the path which | |
| 2046 conforms to the given mode on the PATH, or None if there is no such | |
| 2047 file. | |
| 2048 `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result | |
| 2049 of os.environ.get("PATH"), or can be overridden with a custom search | |
| 2050 path. | |
| 2051 """ | |
| 2052 # Check that a given file can be accessed with the correct mode. | |
| 2053 # Additionally check that `file` is not a directory, as on Windows | |
| 2054 # directories pass the os.access check. | |
| 2055 def _access_check(fn, mode): | |
| 2056 return (os.path.exists(fn) and os.access(fn, mode) | |
| 2057 and not os.path.isdir(fn)) | |
| 2058 | |
| 2059 # Short circuit. If we're given a full path which matches the mode | |
| 2060 # and it exists, we're done here. | |
| 2061 if _access_check(cmd, mode): | |
| 2062 return cmd | |
|
hinoka
2016/06/24 18:47:33
This returns "powershell.exe" if it's in cwd
| |
| 2063 | |
| 2064 path = (path or os.environ.get("PATH", os.defpath)).split(os.pathsep) | |
| 2065 | |
| 2066 if sys.platform == "win32": | |
| 2067 # The current directory takes precedence on Windows. | |
| 2068 if not os.curdir in path: | |
| 2069 path.insert(0, os.curdir) | |
| 2070 | |
| 2071 # PATHEXT is necessary to check on Windows. | |
| 2072 pathext = os.environ.get("PATHEXT", "").split(os.pathsep) | |
| 2073 # See if the given file matches any of the expected path extensions. | |
| 2074 # This will allow us to short circuit when given "python.exe". | |
| 2075 matches = [cmd for ext in pathext if cmd.lower().endswith(ext.lower())] | |
| 2076 # If it does match, only test that one, otherwise we have to try | |
| 2077 # others. | |
| 2078 files = [cmd] if matches else [cmd + ext.lower() for ext in pathext] | |
| 2079 else: | |
| 2080 # On other platforms you don't have things like PATHEXT to tell you | |
| 2081 # what file suffixes are executable, so just pass on cmd as-is. | |
| 2082 files = [cmd] | |
| 2083 | |
| 2084 seen = set() | |
| 2085 for dir in path: | |
|
hinoka
2016/06/24 18:47:33
funky choice of varname...
| |
| 2086 dir = os.path.normcase(dir) | |
| 2087 if not dir in seen: | |
| 2088 seen.add(dir) | |
| 2089 for thefile in files: | |
| 2090 name = os.path.join(dir, thefile) | |
| 2091 if _access_check(name, mode): | |
| 2092 return name | |
| 2093 return None | |
| OLD | NEW |