Skip to content

Commit

Permalink
Merge bazelbuild#64 by mauriciogg: [SNAP FORK][UPSTREAMED] enable sup…
Browse files Browse the repository at this point in the history
…port multiplex workers in busybox actions

bazelbuild#64
Closes bazelbuild#64

COPYBARA_INTEGRATE_REVIEW=bazelbuild#64 from mauriciogg:mgalindo-busybox-workers 761207e
PiperOrigin-RevId: 601199913
Change-Id: I5ecc0b549b405f27fcde3582bf2494ce3c3a9e8d
  • Loading branch information
Mauricio Galindo authored and Bencodes committed Mar 4, 2024
1 parent 63bcd52 commit 8a7ca84
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 42 deletions.
90 changes: 51 additions & 39 deletions rules/busybox.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ def _make_resources_flag(
],
)

def _disable_warnings(ctx, args):
if (ctx.fragments.android.persistent_busybox_tools or
ctx.fragments.android.persistent_multiplex_busybox_tools):
# Disable warnings - this are output to stdin/stderr which breaks worker mode
args.add("--logWarnings=false")

def _path(f):
return f.path

Expand Down Expand Up @@ -280,7 +286,7 @@ def _package(
transitive_input_files = []

args = ctx.actions.args()
args.use_param_file("@%s", use_always=True)
args.use_param_file("@%s", use_always = True)
args.set_param_file_format("multiline")
args.add("--tool", "AAPT2_PACKAGE")
args.add("--")
Expand Down Expand Up @@ -395,7 +401,9 @@ def _package(
)
transitive_input_files.append(resource_apks)

_java.run(
_disable_warnings(ctx, args)

_java_run(
ctx = ctx,
host_javabase = host_javabase,
executable = busybox,
Expand All @@ -405,8 +413,6 @@ def _package(
outputs = output_files,
mnemonic = "PackageAndroidResources",
progress_message = "Packaging Android Resources in %s" % ctx.label,
supports_workers = True,
supports_multiplex_workers = True,
)

def _parse(
Expand All @@ -427,7 +433,7 @@ def _parse(
host_javabase: Target. The host javabase.
"""
args = ctx.actions.args()
args.use_param_file("@%s", use_always=True)
args.use_param_file("@%s", use_always = True)
args.set_param_file_format("multiline")
args.add("--tool", "PARSE")
args.add("--")
Expand All @@ -440,7 +446,9 @@ def _parse(
)
args.add("--output", out_symbols)

_java.run(
_disable_warnings(ctx, args)

_java_run(
ctx = ctx,
host_javabase = host_javabase,
executable = busybox,
Expand All @@ -449,8 +457,6 @@ def _parse(
outputs = [out_symbols],
mnemonic = "ParseAndroidResources",
progress_message = "Parsing Android Resources in %s" % out_symbols.short_path,
supports_workers = True,
supports_multiplex_workers = True,
)

def _make_merge_assets_flags(resources_node):
Expand Down Expand Up @@ -496,7 +502,7 @@ def _merge_assets(
host_javabase: Target. The host javabase.
"""
args = ctx.actions.args()
args.use_param_file("@%s", use_always=True)
args.use_param_file("@%s", use_always = True)
args.set_param_file_format("multiline")
args.add("--tool", "MERGE_ASSETS")
args.add("--")
Expand All @@ -523,7 +529,9 @@ def _merge_assets(
join_with = "&",
)

_java.run(
_disable_warnings(ctx, args)

_java_run(
ctx = ctx,
host_javabase = host_javabase,
executable = busybox,
Expand All @@ -537,8 +545,6 @@ def _merge_assets(
mnemonic = "MergeAndroidAssets",
progress_message =
"Merging Android Assets in %s" % out_assets_zip.short_path,
supports_workers = True,
supports_multiplex_workers = True,
)

def _validate_and_link(
Expand Down Expand Up @@ -580,7 +586,7 @@ def _validate_and_link(

# Retrieves the list of files at runtime when a directory is passed.
args = ctx.actions.args()
args.use_param_file("@%s", use_always=True)
args.use_param_file("@%s", use_always = True)
args.set_param_file_format("multiline")
args.add("--tool", "LINK_STATIC_LIBRARY")
args.add("--")
Expand Down Expand Up @@ -612,7 +618,9 @@ def _validate_and_link(
)
input_files.extend(resource_apks)

_java.run(
_disable_warnings(ctx, args)

_java_run(
ctx = ctx,
host_javabase = host_javabase,
executable = busybox,
Expand All @@ -623,8 +631,6 @@ def _validate_and_link(
mnemonic = "LinkAndroidResources",
progress_message =
"Linking Android Resources in " + out_file.short_path,
supports_workers = True,
supports_multiplex_workers = True,
)

def _compile(
Expand Down Expand Up @@ -658,7 +664,7 @@ def _compile(

# Retrieves the list of files at runtime when a directory is passed.
args = ctx.actions.args()
args.use_param_file("@%s", use_always=True)
args.use_param_file("@%s", use_always = True)
args.set_param_file_format("multiline")
args.add("--tool", "COMPILE_LIBRARY_RESOURCES")
args.add("--")
Expand Down Expand Up @@ -690,18 +696,18 @@ def _compile(
args.add("--androidJar", android_jar)
optional_inputs.append(android_jar)

_disable_warnings(ctx, args)

_java.run(
ctx = ctx,
host_javabase = host_javabase,
executable = busybox,
tools = [aapt],
arguments = [args],
inputs = resource_files + assets + optional_inputs,
inputs = resource_files + assets + optional_inputs,
outputs = [out_file] + optional_outputs,
mnemonic = "CompileAndroidResources",
progress_message = "Compiling Android Resources in %s" % out_file.short_path,
supports_workers = True,
supports_multiplex_workers = True,
)

def _make_merge_compiled_flags(resources_node_info):
Expand Down Expand Up @@ -754,7 +760,7 @@ def _merge_compiled(
transitive_input_files = []

args = ctx.actions.args()
args.use_param_file("@%s", use_always=True)
args.use_param_file("@%s", use_always = True)
args.set_param_file_format("multiline")
args.add("--tool", "MERGE_COMPILED")
args.add("--")
Expand Down Expand Up @@ -794,7 +800,9 @@ def _merge_compiled(
)
transitive_input_files.append(transitive_compiled_resources)

_java.run(
_disable_warnings(ctx, args)

_java_run(
ctx = ctx,
host_javabase = host_javabase,
executable = busybox,
Expand All @@ -805,10 +813,14 @@ def _merge_compiled(
mnemonic = "StarlarkMergeCompiledAndroidResources",
progress_message =
"Merging compiled Android Resources in " + out_class_jar.short_path,
supports_workers = True,
supports_multiplex_workers = True,
)

def _java_run(ctx, mnemonic = None, *args, **kwargs):
enable_workers = ctx.fragments.android.persistent_busybox_tools
multiplex_workers = ctx.fragments.android.persistent_multiplex_busybox_tools

_java.run(ctx, mnemonic = mnemonic, supports_workers = enable_workers, supports_multiplex_workers = multiplex_workers, *args, **kwargs)

def _escape_mv(s):
"""Escapes `:` and `,` in manifest values so they can be used as a busybox flag."""
return s.replace(":", "\\:").replace(",", "\\,")
Expand Down Expand Up @@ -917,7 +929,9 @@ def _merge_manifests(
args.add("--log", out_log_file)
outputs.append(out_log_file)

_java.run(
_disable_warnings(ctx, args)

_java_run(
ctx = ctx,
host_javabase = host_javabase,
executable = busybox,
Expand All @@ -927,8 +941,6 @@ def _merge_manifests(
outputs = outputs,
mnemonic = "MergeManifests",
progress_message = "Merging Android Manifests in %s" % out_file.short_path,
supports_workers = True,
supports_multiplex_workers = True,
)

def _process_databinding(
Expand Down Expand Up @@ -963,7 +975,7 @@ def _process_databinding(
res_dirs = _get_unique_res_dirs(resource_files)

args = ctx.actions.args()
args.use_param_file("@%s", use_always=True)
args.use_param_file("@%s", use_always = True)
args.set_param_file_format("multiline")
args.add("--tool", "PROCESS_DATABINDING")
args.add("--")
Expand All @@ -972,7 +984,9 @@ def _process_databinding(
args.add("--dataBindingInfoOut", out_databinding_info)
args.add("--appId", java_package)

_java.run(
_disable_warnings(ctx, args)

_java_run(
ctx = ctx,
host_javabase = host_javabase,
executable = busybox,
Expand All @@ -981,8 +995,6 @@ def _process_databinding(
outputs = [out_databinding_info] + out_databinding_processed_resources,
mnemonic = "StarlarkProcessDatabinding",
progress_message = "Processing data binding",
supports_workers = True,
supports_multiplex_workers = True,
)

def _make_generate_binay_r_flags(resources_node):
Expand Down Expand Up @@ -1021,7 +1033,7 @@ def _generate_binary_r(
host_javabase: A Target. The host javabase.
"""
args = ctx.actions.args()
args.use_param_file("@%s", use_always=True)
args.use_param_file("@%s", use_always = True)
args.set_param_file_format("multiline")
args.add("--tool", "GENERATE_BINARY_R")
args.add("--")
Expand All @@ -1043,7 +1055,9 @@ def _generate_binary_r(
args.add("--classJarOutput", out_class_jar)
args.add("--targetLabel", str(ctx.label))

_java.run(
_disable_warnings(ctx, args)

_java_run(
ctx = ctx,
host_javabase = host_javabase,
executable = busybox,
Expand All @@ -1053,8 +1067,6 @@ def _generate_binary_r(
outputs = [out_class_jar],
mnemonic = "StarlarkRClassGenerator",
progress_message = "Generating R classes",
supports_workers = True,
supports_multiplex_workers = True,
)

def _make_aar(
Expand Down Expand Up @@ -1089,7 +1101,7 @@ def _make_aar(
when a resource conflict occurs.
"""
args = ctx.actions.args()
args.use_param_file("@%s", use_always=True)
args.use_param_file("@%s", use_always = True)
args.set_param_file_format("multiline")
args.add("--tool", "GENERATE_AAR")
args.add("--")
Expand All @@ -1110,7 +1122,9 @@ def _make_aar(
if should_throw_on_conflict:
args.add("--throwOnResourceConflict")

_java.run(
_disable_warnings(ctx, args)

_java_run(
ctx = ctx,
host_javabase = host_javabase,
executable = busybox,
Expand All @@ -1125,8 +1139,6 @@ def _make_aar(
outputs = [out_aar],
mnemonic = "StarlarkAARGenerator",
progress_message = "Generating AAR package for %s" % ctx.label,
supports_workers = True,
supports_multiplex_workers = True,
)

def _shrink(
Expand Down
9 changes: 6 additions & 3 deletions rules/java.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,19 @@ def _run(
ctx,
host_javabase,
jvm_flags = [],
mnemonic = None,
supports_workers = False,
supports_multiplex_workers = False,
**args):
"""Run a java binary
Args:
ctx: The context.
host_javabase: Target. The host_javabase.
jvm_flags: Additional arguments to the JVM itself.
mnemonic: A description of the action being executed.
supports_workers: This action is worker-compatible (enabled with --strategy=MyAction=worker).
supports_multiplex_workers: This action is multiplex worker-compatible.
**args: Additional arguments to pass to ctx.actions.run(). Some will get modified.
"""

Expand Down Expand Up @@ -469,9 +475,6 @@ def _run(

args["arguments"] = jvm_flags + [jar_args] + args.get("arguments", default = [])

mnemonic = args.get("mnemonic")
supports_workers = args.pop("supports_workers", False)
supports_multiplex_workers = args.pop("supports_multiplex_workers", False)
execution_requirements = args.pop("execution_requirements", dict())
if supports_workers:
execution_requirements["worker-key-mnemonic"] = mnemonic
Expand Down

0 comments on commit 8a7ca84

Please sign in to comment.