aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/build_defs/docker/path.bzl
diff options
context:
space:
mode:
Diffstat (limited to 'tools/build_defs/docker/path.bzl')
-rw-r--r--tools/build_defs/docker/path.bzl84
1 files changed, 40 insertions, 44 deletions
diff --git a/tools/build_defs/docker/path.bzl b/tools/build_defs/docker/path.bzl
index 03cd4155d1..4e9f13aac2 100644
--- a/tools/build_defs/docker/path.bzl
+++ b/tools/build_defs/docker/path.bzl
@@ -13,57 +13,53 @@
# limitations under the License.
"""Rules for manipulating paths."""
-
def dirname(path):
- """Returns the directory's name."""
- last_sep = path.rfind("/")
- if last_sep == -1:
- return "" # The artifact is at the top level.
- return path[:last_sep]
-
+ """Returns the directory's name."""
+ last_sep = path.rfind("/")
+ if last_sep == -1:
+ return "" # The artifact is at the top level.
+ return path[:last_sep]
def join(directory, path):
- """Compute the relative data path prefix from the data_path attribute."""
- if not path:
- return directory
- if path[0] == "/":
- return path[1:]
- if directory == "/":
- return path
- return directory + "/" + path
-
+ """Compute the relative data path prefix from the data_path attribute."""
+ if not path:
+ return directory
+ if path[0] == "/":
+ return path[1:]
+ if directory == "/":
+ return path
+ return directory + "/" + path
def canonicalize(path):
- """Canonicalize the input path."""
- if not path:
- return path
- # Strip ./ from the beginning if specified.
- # There is no way to handle .// correctly (no function that would make
- # that possible and Skylark is not turing complete) so just consider it
- # as an absolute path. A path of / should preserve the entire
- # path up to the repository root.
- if path == "/":
- return path
- if len(path) >= 2 and path[0:2] == "./":
- path = path[2:]
- if not path or path == ".": # Relative to current package
- return ""
- elif path[0] == "/": # Absolute path
- return path
- else: # Relative to a sub-directory
- return path
+ """Canonicalize the input path."""
+ if not path:
+ return path
+ # Strip ./ from the beginning if specified.
+ # There is no way to handle .// correctly (no function that would make
+ # that possible and Skylark is not turing complete) so just consider it
+ # as an absolute path. A path of / should preserve the entire
+ # path up to the repository root.
+ if path == "/":
+ return path
+ if len(path) >= 2 and path[0:2] == "./":
+ path = path[2:]
+ if not path or path == ".": # Relative to current package
+ return ""
+ elif path[0] == "/": # Absolute path
+ return path
+ else: # Relative to a sub-directory
+ return path
def strip_prefix(path, prefix):
- """Returns the path with the specified prefix removed."""
- if path.startswith(prefix):
- return path[len(prefix):]
- return path
-
+ """Returns the path with the specified prefix removed."""
+ if path.startswith(prefix):
+ return path[len(prefix):]
+ return path
def runfile(ctx, f):
- """Return the runfiles relative path of f."""
- if ctx.workspace_name:
- return ctx.workspace_name + "/" + f.short_path
- else:
- return f.short_path
+ """Return the runfiles relative path of f."""
+ if ctx.workspace_name:
+ return ctx.workspace_name + "/" + f.short_path
+ else:
+ return f.short_path