Skip to content

Commit

Permalink
Change code for handling relative short_paths to fix bug bazelbuild#225
Browse files Browse the repository at this point in the history
…. (bazelbuild#231)

Change code for handling relative short_paths.

Fixes bazelbuild#225.
  • Loading branch information
pstradomski authored and brandjon committed Sep 3, 2019
1 parent 9d68f24 commit 37cdefa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
23 changes: 12 additions & 11 deletions experimental/python/wheel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
"""Rules for building wheels."""

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

def _input_file_to_arg(input_file):
"""Converts a File object to string for --input_file argument to wheelmaker"""
Expand Down
5 changes: 4 additions & 1 deletion experimental/rules_python/wheelmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ def main():
# add_wheelfile and add_metadata currently assume pure-Python.
assert arguments.platform == 'any', "Only pure-Python wheels are supported"

input_files = [i.split(';') for i in arguments.input_file]
if arguments.input_file:
input_files = [i.split(';') for i in arguments.input_file]
else:
input_files = []
all_files = get_files_to_package(input_files)
# Sort the files for reproducible order in the archive.
all_files = sorted(all_files.items())
Expand Down

0 comments on commit 37cdefa

Please sign in to comment.