Skip to content

Commit

Permalink
Use javacd_worker/kotlincd_worker in buck2 prelude
Browse files Browse the repository at this point in the history
Summary:
Add worker tools to java/kotlin toolchains and configure them for javacd/kotlincd actions, when not passing debug args.

Currently disabled but can be tested with `-c build.use_persistent_workers=True` (falls back to `exe` arg in `WorkerRunInfo`)

Reviewed By: navidqar

Differential Revision: D45648186

fbshipit-source-id: 2ffbb5ce1d2e8c4968b46abd78725c9f906a5f32
  • Loading branch information
christolliday authored and facebook-github-bot committed May 31, 2023
1 parent 4fd12b0 commit d7f58b3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions prelude/java/java_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ JavaToolchainInfo = provider(
"javacd_debug_port",
"javacd_debug_target",
"javacd_jvm_args",
"javacd_worker",
"java_for_tests",
"javac",
"javac_protocol",
Expand Down
5 changes: 4 additions & 1 deletion prelude/java/javacd_jar_creator.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,12 @@ def create_jar_artifact_javacd(
qualified_name,
java = java_toolchain.java[RunInfo],
compiler = java_toolchain.javac[DefaultInfo].default_outputs[0],
worker = java_toolchain.javacd_worker[RunInfo],
debug_port = java_toolchain.javacd_debug_port,
debug_target = java_toolchain.javacd_debug_target,
extra_jvm_args = java_toolchain.javacd_jvm_args,
)

args = cmd_args()
args.add(
"--action-id",
Expand Down Expand Up @@ -253,14 +255,15 @@ def create_jar_artifact_javacd(
dep_files["classpath_jars"] = classpath_jars_tag

actions.run(
cmd_args(exe, args),
args,
env = {
"BUCK_EVENT_PIPE": event_pipe_out.as_output(),
"JAVACD_ABSOLUTE_PATHS_ARE_RELATIVE_TO_CWD": "1",
},
category = "{}javacd_jar".format(category_prefix),
identifier = actions_identifier or "",
dep_files = dep_files,
exe = exe,
)

library_classpath_jars_tag = actions.artifact_tag()
Expand Down
21 changes: 16 additions & 5 deletions prelude/jvm/cd_jar_creator_util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,26 @@ def prepare_cd_exe(
qualified_name: str.type,
java: RunInfo.type,
compiler: "artifact",
worker: RunInfo.type,
debug_port: [int.type, None],
debug_target: ["label", None],
extra_jvm_args: [str.type]) -> cmd_args.type:
debug_args = []
extra_jvm_args: [str.type]) -> [WorkerRunInfo.type, RunInfo.type]:
jvm_args = extra_jvm_args + ["-XX:-MaxFDLimit"]
if debug_port and qualified_name.startswith(base_qualified_name(debug_target)):
# Do not use a worker when debugging is enabled
debug_args = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address={}".format(debug_port)]
jvm_args = extra_jvm_args + ["-XX:-MaxFDLimit"]

return cmd_args([java, debug_args, jvm_args, "-jar", compiler])
return cmd_args([java, debug_args, jvm_args, "-jar", compiler])
else:
worker_run_info = WorkerRunInfo(
# Specifies the command to compile using a non-worker process, on RE or if workers are disabled
exe = cmd_args([java, jvm_args, "-jar", compiler]),
worker = WorkerInfo(
# Specifies the command to initialize a new worker process.
# This is used for local execution if `build.use_persistent_workers=True`
exe = worker,
),
)
return worker_run_info

# If there's additional compiled srcs, we need to merge them in and if the
# caller specified an output artifact we need to make sure the jar is in that
Expand Down
1 change: 1 addition & 0 deletions prelude/kotlin/kotlin_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ KotlinToolchainInfo = provider(
"kotlincd_debug_port",
"kotlincd_debug_target",
"kotlincd_jvm_args",
"kotlincd_worker",
"kotlin_stdlib",
"kotlin_home_libraries",
"kosabi_stubs_gen_plugin",
Expand Down
5 changes: 4 additions & 1 deletion prelude/kotlin/kotlincd_jar_creator.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ def create_jar_artifact_kotlincd(
qualified_name,
java = java_toolchain.java[RunInfo],
compiler = kotlin_toolchain.kotlinc[DefaultInfo].default_outputs[0],
worker = kotlin_toolchain.kotlincd_worker[RunInfo],
debug_port = kotlin_toolchain.kotlincd_debug_port,
debug_target = kotlin_toolchain.kotlincd_debug_target,
extra_jvm_args = kotlin_toolchain.kotlincd_jvm_args,
)

args = cmd_args()
args.add(
"--action-id",
Expand Down Expand Up @@ -277,14 +279,15 @@ def create_jar_artifact_kotlincd(
dep_files["classpath_jars"] = classpath_jars_tag

actions.run(
cmd_args(exe, args),
args,
env = {
"BUCK_EVENT_PIPE": event_pipe_out.as_output(),
"JAVACD_ABSOLUTE_PATHS_ARE_RELATIVE_TO_CWD": "1",
},
category = "{}kotlincd_jar".format(category_prefix),
identifier = actions_identifier,
dep_files = dep_files,
exe = exe,
)

library_classpath_jars_tag = actions.artifact_tag()
Expand Down

0 comments on commit d7f58b3

Please sign in to comment.