Skip to content

Commit

Permalink
Fix dead_code_report and paths in j2objc_aspect
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 541914572
Change-Id: I5a5e1242c3cd60d655ca3a9bcbe0ca00a28f02d5
  • Loading branch information
kotlaja authored and copybara-github committed Jun 20, 2023
1 parent dae94a8 commit e43b5e5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main/starlark/builtins_bzl/common/objc/j2objc_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ def _exported_j2objc_mapping_file_provider(target, ctx, direct_j2objc_mapping_fi
archive_source_mapping_files = depset([], transitive = transitive_archive_source_mapping_files),
)

def _get_file_path_with_suffix(objc_srcs, suffix):
for src in objc_srcs:
if src.path.endswith(suffix):
return src.path
fail("File with %s suffix must exist inside objc_sources.", suffix)

def _create_j2objc_transpilation_action(
ctx,
java_source_files,
Expand Down Expand Up @@ -247,8 +253,8 @@ def _create_j2objc_transpilation_action(

if java_source_jars:
args.add_joined("--src_jars", java_source_jars, join_with = ",")
args.add("--output_gen_source_dir", ctx.bin_dir.path + "/" + j2objc_source.objc_srcs[0].short_path)
args.add("--output_gen_header_dir", ctx.bin_dir.path + "/" + j2objc_source.objc_hdrs[0].short_path)
args.add("--output_gen_source_dir", _get_file_path_with_suffix(j2objc_source.objc_srcs, "source_files"))
args.add("--output_gen_header_dir", _get_file_path_with_suffix(j2objc_source.objc_hdrs, "header_files"))

args.add_all(ctx.fragments.j2objc.translation_flags)

Expand Down Expand Up @@ -280,7 +286,7 @@ def _create_j2objc_transpilation_action(
args.add("--system", file.dirname)
break

dead_code_report = ctx.attr._dead_code_report
dead_code_report = ctx.file._dead_code_report
if dead_code_report:
args.add("--dead-code-report", dead_code_report)

Expand Down Expand Up @@ -354,7 +360,7 @@ def _java(target, ctx):
for src in ctx.rule.files.srcs:
src_path = src.path
if src_path.endswith(".srcjar"):
java_source_jars.append()(src)
java_source_jars.append(src)
if src_path.endswith(".java"):
java_source_files.append(src)

Expand Down Expand Up @@ -547,6 +553,8 @@ j2objc_aspect = aspect(
default = Label("@//third_party/java/j2objc:jre_emul_module"),
),
"_dead_code_report": attr.label(
allow_single_file = True,
cfg = "exec",
default = configuration_field(
name = "dead_code_report",
fragment = "j2objc",
Expand Down

0 comments on commit e43b5e5

Please sign in to comment.