Skip to content

Commit 37cdefa

Browse files
pstradomskibrandjon
authored andcommitted
Change code for handling relative short_paths to fix bug bazel-contrib#225. (bazel-contrib#231)
Change code for handling relative short_paths. Fixes bazel-contrib#225.
1 parent 9d68f24 commit 37cdefa

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

experimental/python/wheel.bzl

+12-11
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
"""Rules for building wheels."""
1616

1717
def _path_inside_wheel(input_file):
18-
# input_file.short_path is relative ("../${repository_root}/foobar")
19-
# so it can't be a valid path within a zip file. Thus strip out the root
20-
# manually instead of using short_path here.
21-
root = input_file.root.path
22-
if root != "":
23-
# TODO: '/' is wrong on windows, but the path separator is not available in skylark.
24-
# Fix this once ctx.configuration has directory separator information.
25-
root += "/"
26-
if not input_file.path.startswith(root):
27-
fail("input_file.path '%s' does not start with expected root '%s'" % (input_file.path, root))
28-
return input_file.path[len(root):]
18+
# input_file.short_path is sometimes relative ("../${repository_root}/foobar")
19+
# which is not a valid path within a zip file. Fix that.
20+
short_path = input_file.short_path
21+
if short_path.startswith('..') and len(short_path) >= 3:
22+
# Path separator. '/' on linux.
23+
separator = short_path[2]
24+
# Consume '../' part.
25+
short_path = short_path[3:]
26+
# Find position of next '/' and consume everything up to that character.
27+
pos = short_path.find(separator)
28+
short_path = short_path[pos+1:]
29+
return short_path
2930

3031
def _input_file_to_arg(input_file):
3132
"""Converts a File object to string for --input_file argument to wheelmaker"""

experimental/rules_python/wheelmaker.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,10 @@ def main():
260260
# add_wheelfile and add_metadata currently assume pure-Python.
261261
assert arguments.platform == 'any', "Only pure-Python wheels are supported"
262262

263-
input_files = [i.split(';') for i in arguments.input_file]
263+
if arguments.input_file:
264+
input_files = [i.split(';') for i in arguments.input_file]
265+
else:
266+
input_files = []
264267
all_files = get_files_to_package(input_files)
265268
# Sort the files for reproducible order in the archive.
266269
all_files = sorted(all_files.items())

0 commit comments

Comments
 (0)