Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search for double backslashes in prefix replacement #962

Merged
merged 3 commits into from
May 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ def have_prefix_files(files):
'''
prefix = config.build_prefix
prefix_bytes = prefix.encode('utf-8')
alt_prefix = prefix.replace('\\', '/')
alt_prefix_bytes = alt_prefix.encode('utf-8')
prefix_placeholder_bytes = prefix_placeholder.encode('utf-8')
if on_win:
forward_slash_prefix = prefix.replace('\\', '/')
forward_slash_prefix_bytes = forward_slash_prefix.encode('utf-8')
double_backslash_prefix = prefix.replace('\\', '\\\\')
double_backslash_prefix_bytes = double_backslash_prefix.encode('utf-8')

for f in files:
if f.endswith(('.pyc', '.pyo', '.a')):
continue
Expand Down Expand Up @@ -130,9 +134,12 @@ def have_prefix_files(files):
mm = mmap.mmap(fi.fileno(), 0)
if mm.find(prefix_bytes) != -1:
yield (prefix, mode, f)
if (sys.platform == 'win32') and mm.find(alt_prefix_bytes) != -1:
if on_win and mm.find(forward_slash_prefix_bytes) != -1:
# some windows libraries use unix-style path separators
yield (alt_prefix, mode, f)
yield (forward_slash_prefix, mode, f)
elif on_win and mm.find(double_backslash_prefix_bytes) != -1:
# some windows libraries have double backslashes as escaping
yield (double_backslash_prefix, mode, f)
if mm.find(prefix_placeholder_bytes) != -1:
yield (prefix_placeholder, mode, f)
mm.close() and fi.close()
Expand Down
40 changes: 40 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
This file tests prefix finding for Windows and *nix.
"""

import os
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to write a docstring which gives a high-level overview of the test strategy in here.

import sys

from conda_build import build
from conda.compat import TemporaryDirectory

prefix_tests = {"normal": os.path.sep}
if sys.platform == "win32":
prefix_tests.update({"double_backslash": "\\\\",
"forward_slash": "/"})


def _write_prefix(filename, prefix, replacement):
with open(filename, "w") as f:
f.write(prefix.replace(os.path.sep, replacement))
f.write("\n")


def test_find_prefix_files():
"""
Write test output that has the prefix to be found, then verify that the prefix finding
identified the correct number of files.
"""
# create a temporary folder
prefix = os.path.join(sys.prefix, "envs", "_build")
if not os.path.isdir(prefix):
os.makedirs(prefix)
with TemporaryDirectory(prefix=prefix + os.path.sep) as tmpdir:
# create text files to be replaced
files = []
for slash_style in prefix_tests:
filename = os.path.join(tmpdir, "%s.txt" % slash_style)
_write_prefix(filename, prefix, prefix_tests[slash_style])
files.append(filename)

assert len(list(build.have_prefix_files(files))) == len(files)