Fix usage of `paths.get_relative` that was defined in `@_builtins` only PiperOrigin-RevId: 673806805 Change-Id: Iae4cd555837cd483984be296f457e5442df92d75
diff --git a/java/common/rules/impl/java_helper.bzl b/java/common/rules/impl/java_helper.bzl index 82897db..c819075 100644 --- a/java/common/rules/impl/java_helper.bzl +++ b/java/common/rules/impl/java_helper.bzl
@@ -94,7 +94,7 @@ for src in ctx.files.srcs: if src.basename == main: return _full_classname(_strip_extension(src)) - return _full_classname(paths.get_relative(ctx.label.package, ctx.label.name)) + return _full_classname(_get_relative(ctx.label.package, ctx.label.name)) def _strip_extension(file): return file.dirname + "/" + ( @@ -445,6 +445,11 @@ # stamp == -1 / auto return int(ctx.configuration.stamp_binaries()) +def _get_relative(path_a, path_b): + if paths.is_absolute(path_b): + return path_b + return paths.normalize(paths.join(path_a, path_b)) + helper = struct( collect_all_targets_as_deps = _collect_all_targets_as_deps, filter_launcher_for_target = _filter_launcher_for_target, @@ -471,4 +476,5 @@ detokenize_javacopts = _detokenize_javacopts, derive_output_file = _derive_output_file, is_stamping_enabled = _is_stamping_enabled, + get_relative = _get_relative, )
diff --git a/java/common/rules/java_runtime.bzl b/java/common/rules/java_runtime.bzl index 7991d5e..43cb7c6 100644 --- a/java/common/rules/java_runtime.bzl +++ b/java/common/rules/java_runtime.bzl
@@ -60,7 +60,7 @@ if _is_main_repo(label): return label.package else: - return paths.get_relative(label.workspace_root, label.package) + return helper.get_relative(label.workspace_root, label.package) def _get_bin_java(ctx): is_windows = helper.is_target_platform_windows(ctx) @@ -68,10 +68,10 @@ def _get_runfiles_java_executable(ctx, java_home, label): if paths.is_absolute(java_home) or _is_main_repo(label): - return paths.get_relative(java_home, _get_bin_java(ctx)) + return helper.get_relative(java_home, _get_bin_java(ctx)) else: - repo_runfiles_path = "" if _is_main_repo(label) else paths.get_relative("..", label.workspace_name) - return paths.get_relative(repo_runfiles_path, _get_bin_java(ctx)) + repo_runfiles_path = "" if _is_main_repo(label) else helper.get_relative("..", label.workspace_name) + return helper.get_relative(repo_runfiles_path, _get_bin_java(ctx)) def _is_java_binary(path): return path.endswith("bin/java") or path.endswith("bin/java.exe") @@ -94,9 +94,9 @@ java_home_attr = ctx.expand_make_variables("java_home", ctx.attr.java_home, {}) if ctx.files.srcs and paths.is_absolute(java_home_attr): fail("'java_home' with an absolute path requires 'srcs' to be empty.") - java_home = paths.get_relative(java_home, java_home_attr) + java_home = helper.get_relative(java_home, java_home_attr) - java_binary_exec_path = paths.get_relative(java_home, _get_bin_java(ctx)) + java_binary_exec_path = helper.get_relative(java_home, _get_bin_java(ctx)) java_binary_runfiles_path = _get_runfiles_java_executable(ctx, java_home, ctx.label) java = ctx.file.java