-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SNAP FORK][UPSTREAMED] enable support multiplex workers in busybox actions #64
[SNAP FORK][UPSTREAMED] enable support multiplex workers in busybox actions #64
Conversation
…ctions - Disable warnings for busybox actions Warnings go to stdout/stderr which makes it incompatible with workers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TL;DR we need to be able to optionally enable/disable workers and multiplex workers. It would also be ideal to add a test for this, but we haven't open-sourced the tests yet, so it's acceptable to omit for now.
rules/busybox.bzl
Outdated
arguments = [args], | ||
inputs = depset(input_files, transitive = transitive_input_files), | ||
outputs = output_files, | ||
mnemonic = "PackageAndroidResources", | ||
progress_message = "Packaging Android Resources in %s" % ctx.label, | ||
supports_workers = True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to enable worker mode conditionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Default nos is false. Can be enabled using --define=persistent_android_resource_processor=true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like the supports_workers
and supports_multiplex_workers
arguments to java_run()
no longer do anything. Maybe we can remove these from the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
rules/busybox.bzl
Outdated
arguments = [args], | ||
inputs = depset(input_files, transitive = transitive_input_files), | ||
outputs = output_files, | ||
mnemonic = "PackageAndroidResources", | ||
progress_message = "Packaging Android Resources in %s" % ctx.label, | ||
supports_workers = True, | ||
supports_multiplex_workers = True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to enable multiplex worker mode conditionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
rules/busybox.bzl
Outdated
@@ -388,16 +393,20 @@ def _package( | |||
if java_package: | |||
args.add("--packageForR", java_package) | |||
|
|||
_disable_warnings(args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should disable warnings conditionally based on if worker mode is enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Default nos is false. Can be enabled using --define=persistent_android_resource_processor=true
rules/busybox.bzl
Outdated
@@ -118,6 +118,10 @@ def _make_resources_flag( | |||
], | |||
) | |||
|
|||
def _disable_warnings(args): | |||
# Disable warnings - this are output to stdin/stderr which breaks worker mode | |||
args.add("--logWarnings=false") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens to warnings in worker mode? I think we'd still want to know about them. Would they get dumped to a non-stdout/stderr file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is just mirroring the existing behavior inside BusyBoxActionBuilder
https://github.com/bazelbuild/bazel/blob/84c1ed430405b154b6e9eb2c28281f450e250eff/src/main/java/com/google/devtools/build/lib/rules/android/BusyBoxActionBuilder.java#L369
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense I suppose, but I'm still curious where the warnings go even in the native implementation. We can shelf this discussion for later since it's slightly out of scope (and no one has complained about this yet 😄)
Would you mind rebasing this PR? There are merge conflicts with pre-alpha HEAD now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LMK if my proposed changes make sense to you. I'll also discuss this more internally.
rules/busybox.bzl
Outdated
@@ -118,6 +119,12 @@ def _make_resources_flag( | |||
], | |||
) | |||
|
|||
def _disable_warnings(ctx, args): | |||
if (_flags.get(ctx).persistent_android_resource_processor or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out that we have some internal test rules that directly call into the busybox. It was a pain to manually add _flags = [...]
to each of those rules, so I decided to add an early-fail here:
if not hasattr(ctx, "_flags"):
return
rules/busybox.bzl
Outdated
enable_workers = _flags.get(ctx).persistent_android_resource_processor | ||
multiplex_workers = _flags.get(ctx).persistent_multiplex_android_resource_processor | ||
kwargs["supports_workers"] = enable_workers or multiplex_workers | ||
kwargs["supports_multiplex_workers"] = multiplex_workers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put these in an if-block:
enable_workers = False
multiplex_workers = False
if hasattr(ctx, "_flags"):
enable_workers = [...]
multiplex_workers = [...]
kwargs[...]
kwargs[...]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also discussed this internally: there is a general preference that for flag-related features, we use the existing design pattern here: https://github.com/bazelbuild/rules_android/blob/pre-alpha/rules/dex.bzl#L49-L52
So instead of doing bazel build [...] --define=persistent_android_resource_processor
, you can use the existing flags: bazel build [...] --persistent_android_dex_desugar
etc.
makes sense. I deleted the use of the flags and replaced with maybe it makes sense to replace this logic and add the starlark actions to the expansion in https://github.com/bazelbuild/bazel/blob/56fd3dc889717a8428843137e18016c906129924/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java#L863 |
The updated changes look good. At a high level, we'd like to move as much Android-related stuff out of bazel as possible (which is really one of the major motivations behind having this separate Android rules codebase), so I think it's better for now to keep all the logic inside rules_android. @ahumesky, thoughts? |
I'm actually getting this error when integrating into google3:
@mauriciogg Have you tested this change out locally to see if it works with Bazel? I don't see persistent_android_resource_processor in AndroidConfigurationApi.java, which is where flags are publicly exposed and ultimately hooked up to ctx.fragments. Example here. I think to merge this change, we'll first have to expose persistent_android_resource_processor to AndroidConfigurationApi, wait for that change to propagate to both a Bazel prerelease and a Blaze release, and only then will this cleanly integrate with internal code. |
@@ -118,6 +118,12 @@ def _make_resources_flag( | |||
], | |||
) | |||
|
|||
def _disable_warnings(ctx, args): | |||
if (ctx.fragments.android.persistent_android_resource_processor or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed these fragment flags to ctx.fragments.android.persistent_busybox_tools
and ctx.fragments.android.persistent_multiplex_busybox_tools
internally and tests are passing. Those flags also seem more appropriate than the resource_processor ones; what do you think?
Unfortunately the fragments.android
data structure can't accept Void
expansion flags such as persistent_android_resource_processor, and changing the return type of that flag handler to boolean
causes some other kind of sanity check error. I think in Bazel/Blaze, expansion flags must return Void, so there's somewhat of an impedance mismatch.
This has been merged. |
Looks like this was reverted f49f2e3 |
Yes - the root cause was that in google3, there can be spaces in manifest_values, i.e. |
…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
…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
…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
…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
…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
…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
Conditionally enable worker and multiples support for resource processing actions using flags
--define=persistent_android_resource_processor
--define=persistent_multiplex_android_resource_processor
-> this flag will implicitly enable thepersistent_android_resource_processor
fixes: #30