Skip to content

Commit

Permalink
Fix usage of paths.get_relative that was defined in @_builtins only
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 673806805
Change-Id: Iae4cd555837cd483984be296f457e5442df92d75
  • Loading branch information
hvadehra authored and rules_java Copybara committed Sep 12, 2024
1 parent e40342e commit 421c655
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 7 additions & 1 deletion java/common/rules/impl/java_helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _primary_class(ctx):
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 + "/" + (
Expand Down Expand Up @@ -445,6 +445,11 @@ def _is_stamping_enabled(ctx, stamp):
# 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,
Expand All @@ -471,4 +476,5 @@ helper = struct(
detokenize_javacopts = _detokenize_javacopts,
derive_output_file = _derive_output_file,
is_stamping_enabled = _is_stamping_enabled,
get_relative = _get_relative,
)
12 changes: 6 additions & 6 deletions java/common/rules/java_runtime.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ def _default_java_home(label):
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)
return "bin/java.exe" if is_windows else "bin/java"

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")
Expand All @@ -94,9 +94,9 @@ def _java_runtime_rule_impl(ctx):
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
Expand Down

0 comments on commit 421c655

Please sign in to comment.