From a4b2f12cf5c0747b42ad98c71bc0e9b796796151 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Fri, 6 Oct 2023 07:50:29 -0700 Subject: [PATCH] refactor: remove to_workspace_path and to_manifest_path --- docs/paths.md | 71 ------------------------------- lib/BUILD.bazel | 1 + lib/paths.bzl | 4 -- lib/private/copy_to_directory.bzl | 4 +- lib/private/paths.bzl | 4 -- lib/tests/paths_test.bzl | 8 ---- lib/windows_utils.bzl | 10 ++--- 7 files changed, 6 insertions(+), 96 deletions(-) diff --git a/docs/paths.md b/docs/paths.md index 293c28650..c6f21b08b 100644 --- a/docs/paths.md +++ b/docs/paths.md @@ -32,49 +32,6 @@ For example, 'relative_file("../foo/foo.txt", "bar/bar.txt")' will return '../.. The relative path from frm_file to to_file, including the file name - - -## to_manifest_path - -
-to_manifest_path(ctx, file)
-
- -The rlocation path for a `File` - -This produces the same value as the `rlocationpath` predefined source/output path variable. - -From https://bazel.build/reference/be/make-variables#predefined_genrule_variables: - -> `rlocationpath`: The path a built binary can pass to the `Rlocation` function of a runfiles -> library to find a dependency at runtime, either in the runfiles directory (if available) -> or using the runfiles manifest. - -> This is similar to root path (a.k.a. [short_path](https://bazel.build/rules/lib/File#short_path)) -> in that it does not contain configuration prefixes, but differs in that it always starts with the -> name of the repository. - -> The rlocation path of a `File` in an external repository repo will start with `repo/`, followed by the -> repository-relative path. - -> Passing this path to a binary and resolving it to a file system path using the runfiles libraries -> is the preferred approach to find dependencies at runtime. Compared to root path, it has the -> advantage that it works on all platforms and even if the runfiles directory is not available. - - -**PARAMETERS** - - -| Name | Description | Default Value | -| :------------- | :------------- | :------------- | -| ctx | starlark rule execution context | none | -| file | a File object | none | - -**RETURNS** - -The rlocationpath for the `File` - - ## to_output_relative_path @@ -168,31 +125,3 @@ From https://bazel.build/reference/be/make-variables#predefined_genrule_variable The rlocationpath for the `File` - - -## to_workspace_path - -
-to_workspace_path(file)
-
- -The repository relative path for a `File` - -This is the full runfiles path of a `File` excluding its workspace name. - -This differs from root path (a.k.a. [short_path](https://bazel.build/rules/lib/File#short_path)) and -rlocation path as it does not include the repository name if the `File` is from an external repository. - - -**PARAMETERS** - - -| Name | Description | Default Value | -| :------------- | :------------- | :------------- | -| file | a File object | none | - -**RETURNS** - -The repository relative path for the `File` - - diff --git a/lib/BUILD.bazel b/lib/BUILD.bazel index 0456649c0..3f1b13491 100644 --- a/lib/BUILD.bazel +++ b/lib/BUILD.bazel @@ -292,4 +292,5 @@ bzl_library( bzl_library( name = "windows_utils", srcs = ["windows_utils.bzl"], + deps = ["//lib/private:paths"], ) diff --git a/lib/paths.bzl b/lib/paths.bzl index 69055d6a2..7a38069f2 100644 --- a/lib/paths.bzl +++ b/lib/paths.bzl @@ -7,10 +7,6 @@ to_output_relative_path = paths.to_output_relative_path to_repository_relative_path = paths.to_repository_relative_path to_rlocation_path = paths.to_rlocation_path -# deprecated namings -to_manifest_path = paths.to_manifest_path # equivalent to to_rlocation_path -to_workspace_path = paths.to_workspace_path # equivalent to to_repository_relative_path - # Bash helper function for looking up runfiles. # See windows_utils.bzl for the cmd.exe equivalent. # Vendored from diff --git a/lib/private/copy_to_directory.bzl b/lib/private/copy_to_directory.bzl index f0a7c49ad..160f77737 100644 --- a/lib/private/copy_to_directory.bzl +++ b/lib/private/copy_to_directory.bzl @@ -456,7 +456,7 @@ def copy_to_directory_bin_action( path = f.path, root_path = f.root.path, short_path = f.short_path, - workspace_path = paths.to_workspace_path(f), + workspace_path = paths.to_repository_relative_path(f), )) for t in targets: if not DirectoryPathInfo in t: @@ -466,7 +466,7 @@ def copy_to_directory_bin_action( path = "/".join([t[DirectoryPathInfo].directory.path, t[DirectoryPathInfo].path]), root_path = t[DirectoryPathInfo].directory.root.path, short_path = "/".join([t[DirectoryPathInfo].directory.short_path, t[DirectoryPathInfo].path]), - workspace_path = "/".join([paths.to_workspace_path(t[DirectoryPathInfo].directory), t[DirectoryPathInfo].path]), + workspace_path = "/".join([paths.to_repository_relative_path(t[DirectoryPathInfo].directory), t[DirectoryPathInfo].path]), )) file_infos = [] diff --git a/lib/private/paths.bzl b/lib/private/paths.bzl index 856f66039..02f591a53 100644 --- a/lib/private/paths.bzl +++ b/lib/private/paths.bzl @@ -136,8 +136,4 @@ paths = struct( to_output_relative_path = _to_output_relative_path, to_repository_relative_path = _to_repository_relative_path, to_rlocation_path = _to_rlocation_path, - # TODO(2.0): remove to_workspace_path? it is replaced by to_repository_relative_path - to_workspace_path = _to_repository_relative_path, - # TODO(2.0): remove to_manifest_path? it is replaced by to_rlocation_path - to_manifest_path = _to_rlocation_path, ) diff --git a/lib/tests/paths_test.bzl b/lib/tests/paths_test.bzl index 2c11ecb6d..257dfbb88 100644 --- a/lib/tests/paths_test.bzl +++ b/lib/tests/paths_test.bzl @@ -193,20 +193,12 @@ def _rlocation_path_test_impl(ctx): env = unittest.begin(ctx) asserts.equals(env, "bazel_skylib/LICENSE", paths.to_rlocation_path(ctx, ctx.file.f1)) asserts.equals(env, "aspect_bazel_lib/lib/paths.bzl", paths.to_rlocation_path(ctx, ctx.file.f2)) - - # deprecated naming - asserts.equals(env, "bazel_skylib/LICENSE", paths.to_manifest_path(ctx, ctx.file.f1)) - asserts.equals(env, "aspect_bazel_lib/lib/paths.bzl", paths.to_manifest_path(ctx, ctx.file.f2)) return unittest.end(env) def _repository_relative_path_test_impl(ctx): env = unittest.begin(ctx) asserts.equals(env, "LICENSE", paths.to_repository_relative_path(ctx.file.f1)) asserts.equals(env, "lib/paths.bzl", paths.to_repository_relative_path(ctx.file.f2)) - - # deprecated naming - asserts.equals(env, "LICENSE", paths.to_workspace_path(ctx.file.f1)) - asserts.equals(env, "lib/paths.bzl", paths.to_workspace_path(ctx.file.f2)) return unittest.end(env) def _output_relative_path_test_impl(ctx): diff --git a/lib/windows_utils.bzl b/lib/windows_utils.bzl index edd62afc6..f08f2d76b 100644 --- a/lib/windows_utils.bzl +++ b/lib/windows_utils.bzl @@ -14,6 +14,8 @@ "Helpers for rules running on windows" +load("//lib/private:paths.bzl", "paths") + # cmd.exe function for looking up runfiles. # Equivalent of the BASH_RLOCATION_FUNCTION in paths.bzl. # Use this to write actions that don't require bash. @@ -65,12 +67,6 @@ exit /b 0 :: End of rlocation """ -def _to_manifest_path(ctx, file): - if file.short_path.startswith("../"): - return file.short_path[3:] - else: - return ctx.workspace_name + "/" + file.short_path - def create_windows_native_launcher_script(ctx, shell_script): """Create a Windows Batch file to launch the given shell script. @@ -106,7 +102,7 @@ if defined args ( "{bash_bin}" -c "!run_script! !args!" """.format( bash_bin = ctx.toolchains["@bazel_tools//tools/sh:toolchain_type"].path, - sh_script = _to_manifest_path(ctx, shell_script), + sh_script = paths.to_rlocation_path(ctx, shell_script), rlocation_function = BATCH_RLOCATION_FUNCTION, ), is_executable = True,