-
Notifications
You must be signed in to change notification settings - Fork 238
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
support multiplex worker for jetify #911
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -3,11 +3,27 @@ java_import( | |||
jars = glob(["jetifier-standalone/lib/*.jar"]), | ||||
) | ||||
|
||||
java_import( | ||||
name = "all_android_tools", | ||||
jars = ["@android_tools//:all_android_tools_deploy.jar"], | ||||
) | ||||
|
||||
java_library( | ||||
name = "jetifier_worker_wrapper", | ||||
visibility = ["//visibility:public"], | ||||
srcs = glob(["**/*.java"]), | ||||
deps = [ | ||||
"//third_party/jetifier:jetifier_jars", | ||||
":all_android_tools", | ||||
], | ||||
) | ||||
|
||||
java_binary( | ||||
name = "jetifier", | ||||
main_class = "com.android.tools.build.jetifier.standalone.Main", | ||||
main_class = "com.github.bazelbuild.rules_jvm_external.JetifierWorkerWrapper", | ||||
visibility = ["//visibility:public"], | ||||
runtime_deps = [ | ||||
":jetifier_jars", | ||||
":jetifier_worker_wrapper" | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depending on There is an issue open already against Bazel to have this worker implementation exposed or distributed to some place like maven. bazelbuild/bazel#14556 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it acceptable to copy WorkRequestHandler to this repo for the time being? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's one option, although also not ideal. There is an implementation in the aswb plugin that's much simpler that we could pull into rules_jvm_external if we need to. @SupSaiYaJin Are you using the On a related note, AndroidX has been the default for 6+ years now. We should probably be figuring out how to remove Jetifier entirely from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree on that, we do use rules_jvm_external/private/tools/java/com/github/bazelbuild/rules_jvm_external/jar/BUILD Line 30 in e6c1ff2
They could be disabled by default and enabled with I also found BazelMultiplexWorker with a nicer API |
||||
], | ||||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.github.bazelbuild.rules_jvm_external; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file should live under |
||
|
||
import com.android.tools.build.jetifier.standalone.Main; | ||
import com.google.devtools.build.lib.worker.ProtoWorkerMessageProcessor; | ||
import com.google.devtools.build.lib.worker.WorkRequestHandler; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.time.Duration; | ||
import java.util.List; | ||
|
||
/** | ||
* A Wrapper for jetifier-standalone to support multiplex worker | ||
*/ | ||
public class JetifierWorkerWrapper { | ||
|
||
public static void main(String[] args) { | ||
if (args.length == 1 && args[0].equals("--persistent_worker")) { | ||
WorkRequestHandler workerHandler = | ||
new WorkRequestHandler.WorkRequestHandlerBuilder( | ||
JetifierWorkerWrapper::jetifier, | ||
System.err, | ||
new ProtoWorkerMessageProcessor(System.in, System.out)) | ||
.setCpuUsageBeforeGc(Duration.ofSeconds(10)) | ||
.build(); | ||
int exitCode = 1; | ||
try { | ||
workerHandler.processRequests(); | ||
exitCode = 0; | ||
} catch (IOException e) { | ||
System.err.println(e.getMessage()); | ||
} finally { | ||
// Prevent hanging threads from keeping the worker alive. | ||
System.exit(exitCode); | ||
} | ||
} else { | ||
Main.main(args); | ||
} | ||
} | ||
|
||
private static int jetifier(List<String> args, PrintWriter pw) { | ||
Main.main(args.toArray(new String[0])); | ||
return 0; | ||
} | ||
|
||
} |
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.
This will also need to be added to the
MODULE.bazel