diff options
author | 2017-02-22 23:56:28 +0000 | |
---|---|---|
committer | 2017-02-23 11:31:52 +0000 | |
commit | 95dac7050d0d7f0cd2a4c7fad1859daceed556af (patch) | |
tree | f8de130ae943c19abd31fa79261998b597888789 /src/main/java/com | |
parent | 200427651a749540a1589236c48f30a3d9e05c90 (diff) |
Fix python stub_template.txt on Windows
__file__ is not necessarily a absoulte path, fix and rename the function
for adding UNC prefix.
Since UNC prefix doesn't work with Python 2, skip adding it if running
in Python 2
--
Change-Id: I274dc0127c1427740c6824533b15299a066cdd83
Reviewed-on: https://cr.bazel.build/9050
PiperOrigin-RevId: 148281049
MOS_MIGRATED_REVID=148281049
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/bazel/rules/python/stub_template.txt | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/stub_template.txt b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/stub_template.txt index 50bbc9abbd..00ebcc51fc 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/stub_template.txt +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/stub_template.txt @@ -12,19 +12,21 @@ import zipfile def IsWindows(): return os.name == 'nt' -def FixAbsWindowsPath(path): +def GetWindowsPathWithUNCPrefix(path): """Changes the path, so that it uses unicode Windows paths""" path = path.strip() - if not IsWindows(): - return path # Not more to do for non-windows + # No need to add prefix for non-Windows platforms, + # And \\?\ doesn't work in python 2 + if not IsWindows() or sys.version_info[0] < 3: + return path # Lets start the unicode fun unicode_prefix = "\\\\?\\" if path.startswith(unicode_prefix): return path - return unicode_prefix + os.path.normpath(path) + return unicode_prefix + os.path.abspath(path) PYTHON_BINARY = '%python_binary%' if IsWindows() and not PYTHON_BINARY.endswith('.exe'): @@ -92,10 +94,8 @@ def CreateModuleSpace(): ZIP_RUNFILES_DIRECTORY_NAME = "runfiles" temp_dir = tempfile.mkdtemp("", "Bazel.runfiles_") # mkdtemp return absolute name - temp_dir = FixAbsWindowsPath(temp_dir) - # __file__ will be either empty or the absolute path to this script - # Not handling empty, since it was not handled before - zf = zipfile.ZipFile(FixAbsWindowsPath(os.path.dirname(__file__))) + temp_dir = GetWindowsPathWithUNCPrefix(temp_dir) + zf = zipfile.ZipFile(GetWindowsPathWithUNCPrefix(os.path.dirname(__file__))) zf.extractall(temp_dir) return os.path.join(temp_dir, ZIP_RUNFILES_DIRECTORY_NAME) |