Skip to content

Commit

Permalink
refactor: remove to_workspace_path and to_manifest_path (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan authored and alexeagle committed Oct 8, 2023
1 parent 4b21bcb commit 3c3a0c5
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 96 deletions.
71 changes: 0 additions & 71 deletions docs/paths.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,5 @@ bzl_library(
bzl_library(
name = "windows_utils",
srcs = ["windows_utils.bzl"],
deps = ["//lib/private:paths"],
)
4 changes: 0 additions & 4 deletions lib/paths.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/private/copy_to_directory.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 = []
Expand Down
4 changes: 0 additions & 4 deletions lib/private/paths.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
8 changes: 0 additions & 8 deletions lib/tests/paths_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 3 additions & 7 deletions lib/windows_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3c3a0c5

Please sign in to comment.