Skip to content

Commit

Permalink
Don't special case current directory relative paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasvl committed Mar 7, 2018
1 parent a60d9f8 commit dd4cdb9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/paths.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ def _relativize(path, start):
will fail if `path` is not beneath `start` (rather than use parent segments to
walk up to the common file system root).
Relativizing paths that start with parent directory references is not allowed.
Relativizing paths that start with parent directory references only works if
the path both start with the same initial parent references.
Args:
path: The path to relativize.
Expand All @@ -176,9 +177,6 @@ def _relativize(path, start):
start_segments = []
start_length = len(start_segments)

if (path.startswith("..") or start.startswith("..")):
fail("Cannot relativize paths above the current (unknown) directory")

if (path.startswith("/") != start.startswith("/") or
len(segments) < start_length):
fail("Path '%s' is not beneath '%s'" % (path, start))
Expand Down
4 changes: 4 additions & 0 deletions tests/paths_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ def _relativize_test(ctx):
# Try a case where a parent directory is normalized away.
asserts.equals(env, "baz", paths.relativize("foo/bar/../baz", "foo"))

# Relative paths work, as long as they share a common start.
asserts.equals(env, "file", paths.relativize("../foo/bar/baz/file", "../foo/bar/baz"))
asserts.equals(env, "baz/file", paths.relativize("../foo/bar/baz/file", "../foo/bar"))

# TODO(allevato): Test failure cases, once that is possible.

unittest.end(env)
Expand Down

0 comments on commit dd4cdb9

Please sign in to comment.