Skip to content

Commit

Permalink
[WASM] Avoid depending j2wasm_application optimized target.
Browse files Browse the repository at this point in the history
Existing code was always depending j2wasm_application optimized target regardless of testing with optimized or not.

PiperOrigin-RevId: 570813054
  • Loading branch information
gkdn authored and copybara-github committed Oct 4, 2023
1 parent e493f5c commit 98153a5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
13 changes: 9 additions & 4 deletions build_defs/internal_do_not_use/j2cl_test_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def j2cl_test_common(
# j2cl_test for the compiled mode to pick it up (otherwise dropped
# in jsunit_test if user provided only in bootstrap_files).
":%s_testlib" % name,
":%s_generated_suite_lib" % name,
":%s_lib" % generated_suite_name,
Label("//build_defs/internal_do_not_use:closure_testsuite"),
Label("//build_defs/internal_do_not_use:closure_testcase"),
Label("//build_defs/internal_do_not_use:internal_parametrized_test_suite"),
Expand All @@ -246,23 +246,28 @@ def j2cl_test_common(
)

# Trigger our code generation
exec_properties = (kwargs.get("exec_properties") or {})
j2wasm_generate_jsunit_suite(
name = generated_suite_name,
test_class = test_class,
deps = [":%s_testlib" % name],
tags = tags,
optimize = optimize_wasm,
defines = wasm_defs,
exec_properties = exec_properties,
exec_properties = kwargs.get("exec_properties") or {},
use_legacy_wasm_spec = use_legacy_wasm_spec,
)

deps = [
":%s_dep" % generated_suite_name,
Label("//build_defs/internal_do_not_use:closure_testsuite"),
Label("//build_defs/internal_do_not_use:closure_testcase"),
":%s_j2wasm_application" % generated_suite_name,
]

# Open-source currently needs the explicit data dependency to wasm target.
data = data + [
":%s_dep" % generated_suite_name,
]

else:
fail("Unknown platform: " + platform)

Expand Down
12 changes: 8 additions & 4 deletions build_defs/internal_do_not_use/j2wasm_generate_jsunit_suite.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,25 @@ def j2wasm_generate_jsunit_suite(
".*_Adapter#tearDown.*",
],
testonly = 1,
tags = tags + ["manual", "notap"],
exec_properties = exec_properties,
use_legacy_wasm_spec = use_legacy_wasm_spec,
)

# Re-expose the target as "_dep" for test infra to depend on.
wasm_target = j2wasm_application_name + ("" if optimize else "_dev")
native.alias(name = name + "_dep", actual = wasm_target)

# This genrule takes the jar file as input and creates
# a new zip file that only contains the generated javascript (.testsuite
# renamed to .js) and the test_summary.json file.
# This is the format that jsunit_test will later expect.
# extracting files from jar (output js zip can include all the required
# files.)

wasm_optimized_suffix = "" if optimize else "_dev"
wasm_path = "/" + native.package_name() + "/" + j2wasm_application_name + wasm_optimized_suffix + ".wasm"
wasm_path = "/" + native.package_name() + "/" + wasm_target + ".wasm"

wasm_module_name = j2wasm_application_name.replace("-", "_") + ".j2wasm"
wasm_module_name = wasm_target.replace("-", "_") + ".j2wasm"
processed_wasm_path = wasm_path.replace("/", "\\/")

native.genrule(
Expand All @@ -130,5 +134,5 @@ def j2wasm_generate_jsunit_suite(
"zip -q -r ../$@ .",
]),
testonly = 1,
tags = ["manual", "notap"],
tags = tags + ["manual", "notap"],
)
5 changes: 1 addition & 4 deletions build_defs/internal_do_not_use/j2wasm_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ def j2wasm_test(
optimize: Flag indicating if wasm compilation is optimized or not.
"""

is_optimized_suffix = "" if optimize else "_dev"
extra_data = [":" + name + "_generated_suite_j2wasm_application" + is_optimized_suffix]

j2cl_test_common(
name = name,
data = data + extra_data,
data = data,
compile = 0,
enable_rta = False,
platform = "WASM",
Expand Down

0 comments on commit 98153a5

Please sign in to comment.