Vendor dependencies
Let's see how I like this workflow.
This commit is contained in:
parent
34d1830413
commit
9c435dc440
7500 changed files with 1665121 additions and 99 deletions
77
vendor/cxx/tools/buck/prelude/java/dex.bzl
vendored
Normal file
77
vendor/cxx/tools/buck/prelude/java/dex.bzl
vendored
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
DexLibraryInfo = provider(
|
||||
fields = [
|
||||
# the .dex.jar file. May be None if there were not any Java classes to dex. If None, the
|
||||
# remaining fields should be ignored.
|
||||
"dex", # ["artifact", None]
|
||||
# the names of the .class files that went into the DEX file
|
||||
"class_names", # ["artifact", None]
|
||||
# resources that are referenced by the classes in this DEX file
|
||||
"referenced_resources", # ["artifact", None]
|
||||
# a value that estimates how much space the code represented by this object will take up in
|
||||
# a DEX file. The units for this estimate are not important, as long as they are consistent
|
||||
# with those used when determining how secondary DEX files should be packed.
|
||||
"weight_estimate", # ["artifact", None]
|
||||
],
|
||||
)
|
||||
|
||||
def get_dex_produced_from_java_library(
|
||||
ctx: "context",
|
||||
dex_toolchain: "DexToolchainInfo",
|
||||
jar_to_dex: "artifact",
|
||||
needs_desugar: bool.type = False,
|
||||
desugar_deps: ["artifact"] = [],
|
||||
weight_factor: int.type = 1) -> "DexLibraryInfo":
|
||||
# TODO(T102963008) check whether the java_library actually contains any classes
|
||||
|
||||
d8_cmd = cmd_args(dex_toolchain.d8_command[RunInfo])
|
||||
|
||||
library_path = jar_to_dex.short_path
|
||||
prefix = "dex/{}".format(library_path)
|
||||
output_dex_file = ctx.actions.declare_output(prefix + ".dex.jar")
|
||||
d8_cmd.add(["--output-dex-file", output_dex_file.as_output()])
|
||||
|
||||
d8_cmd.add(["--file-to-dex", jar_to_dex])
|
||||
d8_cmd.add(["--android-jar", dex_toolchain.android_jar])
|
||||
|
||||
d8_cmd.add(["--intermediate", "--no-optimize", "--force-jumbo"])
|
||||
if not needs_desugar:
|
||||
d8_cmd.add("--no-desugar")
|
||||
else:
|
||||
desugar_deps_file = ctx.actions.write(prefix + "_desugar_deps_file.txt", desugar_deps)
|
||||
d8_cmd.add(["--classpath-files", desugar_deps_file])
|
||||
d8_cmd.hidden(desugar_deps)
|
||||
|
||||
referenced_resources_file = ctx.actions.declare_output(prefix + "_referenced_resources.txt")
|
||||
d8_cmd.add(["--referenced-resources-path", referenced_resources_file.as_output()])
|
||||
|
||||
weight_estimate_file = ctx.actions.declare_output(prefix + "_weight_estimate.txt")
|
||||
d8_cmd.add(["--weight-estimate-path", weight_estimate_file.as_output()])
|
||||
|
||||
d8_cmd.add(["--weight-factor", str(weight_factor)])
|
||||
|
||||
class_names_file = ctx.actions.declare_output(prefix + "_class_names.txt")
|
||||
d8_cmd.add(["--class-names-path", class_names_file.as_output()])
|
||||
|
||||
min_sdk_version = getattr(ctx.attrs, "_dex_min_sdk_version", None) or getattr(ctx.attrs, "min_sdk_version", None)
|
||||
if min_sdk_version:
|
||||
d8_cmd.add(["--min-sdk-version", str(min_sdk_version)])
|
||||
|
||||
ctx.actions.run(
|
||||
d8_cmd,
|
||||
category = "d8",
|
||||
identifier = "{}:{} {}".format(ctx.label.package, ctx.label.name, output_dex_file.short_path),
|
||||
)
|
||||
|
||||
return DexLibraryInfo(
|
||||
dex = output_dex_file,
|
||||
class_names = class_names_file,
|
||||
referenced_resources = referenced_resources_file,
|
||||
weight_estimate = weight_estimate_file,
|
||||
)
|
||||
16
vendor/cxx/tools/buck/prelude/java/dex_toolchain.bzl
vendored
Normal file
16
vendor/cxx/tools/buck/prelude/java/dex_toolchain.bzl
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
# TODO(T107163344) These should be part of the Android toolchain!
|
||||
# Move out once we have overlays.
|
||||
DexToolchainInfo = provider(
|
||||
"Dex toolchain info",
|
||||
fields = [
|
||||
"android_jar",
|
||||
"d8_command",
|
||||
],
|
||||
)
|
||||
35
vendor/cxx/tools/buck/prelude/java/jar_genrule.bzl
vendored
Normal file
35
vendor/cxx/tools/buck/prelude/java/jar_genrule.bzl
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
load("@prelude//:genrule.bzl", "process_genrule")
|
||||
load("@prelude//java:java_toolchain.bzl", "JavaToolchainInfo")
|
||||
load("@prelude//utils:utils.bzl", "expect")
|
||||
|
||||
def jar_genrule_impl(ctx: "context") -> ["provider"]:
|
||||
output_name = "{}.jar".format(ctx.label.name)
|
||||
providers = process_genrule(ctx, output_name, None)
|
||||
expect(
|
||||
len(providers) == 1,
|
||||
"expected exactly one provider of type DefaultInfo from {} ({})"
|
||||
.format(ctx.label.name, providers),
|
||||
)
|
||||
|
||||
default_info = providers[0] # DefaultInfo type
|
||||
outputs = default_info.default_outputs
|
||||
expect(
|
||||
len(outputs) == 1,
|
||||
"expected exactly one output from {} ({})"
|
||||
.format(ctx.label.name, outputs),
|
||||
)
|
||||
output_jar = outputs[0]
|
||||
|
||||
java_toolchain = ctx.attrs._java_toolchain[JavaToolchainInfo]
|
||||
java_cmd = cmd_args(java_toolchain.java[RunInfo])
|
||||
java_cmd.add("-jar", output_jar)
|
||||
|
||||
providers.append(RunInfo(args = java_cmd))
|
||||
return providers
|
||||
176
vendor/cxx/tools/buck/prelude/java/java.bzl
vendored
Normal file
176
vendor/cxx/tools/buck/prelude/java/java.bzl
vendored
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
load("@prelude//android:configuration.bzl", "is_building_android_binary_attr")
|
||||
load("@prelude//android:min_sdk_version.bzl", "get_min_sdk_version_constraint_value_name", "get_min_sdk_version_range")
|
||||
load("@prelude//java:dex_toolchain.bzl", "DexToolchainInfo")
|
||||
load(
|
||||
"@prelude//java:java_toolchain.bzl",
|
||||
"JavaPlatformInfo",
|
||||
"JavaTestToolchainInfo",
|
||||
"JavaToolchainInfo",
|
||||
"PrebuiltJarToolchainInfo",
|
||||
)
|
||||
load("@prelude//java/plugins:java_annotation_processor.bzl", "java_annotation_processor_impl")
|
||||
load("@prelude//java/plugins:java_plugin.bzl", "java_plugin_impl")
|
||||
load("@prelude//genrule.bzl", "genrule_attributes")
|
||||
load(":jar_genrule.bzl", "jar_genrule_impl")
|
||||
load(":java_binary.bzl", "java_binary_impl")
|
||||
load(":java_library.bzl", "java_library_impl")
|
||||
load(":java_test.bzl", "java_test_impl")
|
||||
load(":keystore.bzl", "keystore_impl")
|
||||
load(":prebuilt_jar.bzl", "prebuilt_jar_impl")
|
||||
|
||||
def _select_java_toolchain():
|
||||
# FIXME: prelude// should be standalone (not refer to fbcode//, buck// or ovr_config//)
|
||||
return select(
|
||||
{
|
||||
# By default use the fbsource toolchain
|
||||
"DEFAULT": "fbsource//xplat/buck2/platform/java:java",
|
||||
# if target is meant to run on host but with an android environment then use .buckconfig from fbsource cell
|
||||
"ovr_config//runtime/constraints:android-host-test": "fbsource//xplat/buck2/platform/java:java-for-host-tests",
|
||||
# if target is with fbcode constraint then use .buckconfig from fbcode cell
|
||||
"ovr_config//runtime:fbcode": "fbcode//buck2/platform:java_fbcode",
|
||||
# if target is for android (fbsource repo) then use .buckconfig from fbsource cell
|
||||
"ovr_config//toolchain/fb:android-ndk": "fbsource//xplat/buck2/platform/java:java",
|
||||
},
|
||||
)
|
||||
|
||||
def select_dex_toolchain():
|
||||
# FIXME: prelude// should be standalone (not refer to fbsource//, ovr_config//)
|
||||
return select(
|
||||
{
|
||||
# Only need a Dex toolchain for Android builds.
|
||||
"DEFAULT": None,
|
||||
"ovr_config//os/constraints:android": "fbsource//xplat/buck2/platform/java:dex",
|
||||
},
|
||||
)
|
||||
|
||||
def dex_min_sdk_version():
|
||||
min_sdk_version_dict = {"DEFAULT": None}
|
||||
for min_sdk in get_min_sdk_version_range():
|
||||
constraint = "fbsource//xplat/buck2/platform/android:{}".format(get_min_sdk_version_constraint_value_name(min_sdk))
|
||||
min_sdk_version_dict[constraint] = min_sdk
|
||||
|
||||
return select(min_sdk_version_dict)
|
||||
|
||||
def select_java_test_toolchain():
|
||||
# FIXME: prelude// should be standalone (not refer to fbsource//)
|
||||
return "fbsource//xplat/buck2/platform/java:java_test"
|
||||
|
||||
def select_prebuilt_jar_toolchain():
|
||||
# FIXME: prelude// should be standalone (not refer to fbcode//)
|
||||
return "fbcode//buck2/platform:prebuilt_jar"
|
||||
|
||||
def is_build_only_native_code():
|
||||
return select(
|
||||
{
|
||||
"DEFAULT": False,
|
||||
"fbsource//xplat/buck2/platform/android:build_only_native_code": True,
|
||||
},
|
||||
)
|
||||
|
||||
implemented_rules = {
|
||||
"jar_genrule": jar_genrule_impl,
|
||||
"java_annotation_processor": java_annotation_processor_impl,
|
||||
"java_binary": java_binary_impl,
|
||||
"java_library": java_library_impl,
|
||||
"java_plugin": java_plugin_impl,
|
||||
"java_test": java_test_impl,
|
||||
"keystore": keystore_impl,
|
||||
"prebuilt_jar": prebuilt_jar_impl,
|
||||
}
|
||||
|
||||
extra_attributes = {
|
||||
"jar_genrule": genrule_attributes() | {
|
||||
# FIXME: prelude// should be standalone (not refer to fbsource//)
|
||||
"_java_toolchain": attrs.exec_dep(
|
||||
default = _select_java_toolchain(),
|
||||
providers = [
|
||||
JavaToolchainInfo,
|
||||
],
|
||||
),
|
||||
},
|
||||
"java_annotation_processor": {
|
||||
"_build_only_native_code": attrs.default_only(attrs.bool(default = is_build_only_native_code())),
|
||||
},
|
||||
"java_binary": {
|
||||
"java_args_for_run_info": attrs.list(attrs.string(), default = []),
|
||||
"meta_inf_directory": attrs.option(attrs.source(allow_directory = True), default = None),
|
||||
"_build_only_native_code": attrs.default_only(attrs.bool(default = is_build_only_native_code())),
|
||||
"_java_toolchain": attrs.exec_dep(
|
||||
default = _select_java_toolchain(),
|
||||
providers = [
|
||||
JavaPlatformInfo,
|
||||
JavaToolchainInfo,
|
||||
],
|
||||
),
|
||||
},
|
||||
"java_library": {
|
||||
"javac": attrs.option(attrs.one_of(attrs.dep(), attrs.source()), default = None),
|
||||
"resources_root": attrs.option(attrs.string(), default = None),
|
||||
"_build_only_native_code": attrs.default_only(attrs.bool(default = is_build_only_native_code())),
|
||||
"_dex_min_sdk_version": attrs.option(attrs.int(), default = dex_min_sdk_version()),
|
||||
"_dex_toolchain": attrs.option(attrs.exec_dep(
|
||||
providers = [
|
||||
DexToolchainInfo,
|
||||
],
|
||||
), default = select_dex_toolchain()),
|
||||
"_is_building_android_binary": is_building_android_binary_attr(),
|
||||
"_java_toolchain": attrs.exec_dep(
|
||||
default = _select_java_toolchain(),
|
||||
providers = [
|
||||
JavaPlatformInfo,
|
||||
JavaToolchainInfo,
|
||||
],
|
||||
),
|
||||
},
|
||||
"java_plugin": {
|
||||
"_build_only_native_code": attrs.default_only(attrs.bool(default = is_build_only_native_code())),
|
||||
},
|
||||
"java_test": {
|
||||
"javac": attrs.option(attrs.one_of(attrs.dep(), attrs.source()), default = None),
|
||||
"resources_root": attrs.option(attrs.string(), default = None),
|
||||
"_is_building_android_binary": attrs.default_only(attrs.bool(default = False)),
|
||||
"_java_test_toolchain": attrs.exec_dep(
|
||||
default = select_java_test_toolchain(),
|
||||
providers = [
|
||||
JavaTestToolchainInfo,
|
||||
],
|
||||
),
|
||||
"_java_toolchain": attrs.exec_dep(
|
||||
default = _select_java_toolchain(),
|
||||
providers = [
|
||||
JavaPlatformInfo,
|
||||
JavaToolchainInfo,
|
||||
],
|
||||
),
|
||||
},
|
||||
"java_test_runner": {
|
||||
"resources_root": attrs.option(attrs.string(), default = None),
|
||||
},
|
||||
"prebuilt_jar": {
|
||||
"generate_abi": attrs.bool(default = True),
|
||||
# Prebuilt jars are quick to build, and often contain third-party code, which in turn is
|
||||
# often a source of annotations and constants. To ease migration to ABI generation from
|
||||
# source without deps, we have them present during ABI gen by default.
|
||||
"required_for_source_only_abi": attrs.bool(default = True),
|
||||
"_build_only_native_code": attrs.default_only(attrs.bool(default = is_build_only_native_code())),
|
||||
"_dex_min_sdk_version": attrs.option(attrs.int(), default = dex_min_sdk_version()),
|
||||
"_dex_toolchain": attrs.option(attrs.exec_dep(
|
||||
providers = [
|
||||
DexToolchainInfo,
|
||||
],
|
||||
), default = select_dex_toolchain()),
|
||||
"_prebuilt_jar_toolchain": attrs.exec_dep(
|
||||
default = select_prebuilt_jar_toolchain(),
|
||||
providers = [
|
||||
PrebuiltJarToolchainInfo,
|
||||
],
|
||||
),
|
||||
},
|
||||
}
|
||||
175
vendor/cxx/tools/buck/prelude/java/java_binary.bzl
vendored
Normal file
175
vendor/cxx/tools/buck/prelude/java/java_binary.bzl
vendored
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
load("@prelude//java:java_toolchain.bzl", "JavaToolchainInfo")
|
||||
load("@prelude//linking:shared_libraries.bzl", "SharedLibraryInfo", "merge_shared_libraries", "traverse_shared_library_info")
|
||||
load("@prelude//utils:utils.bzl", "expect")
|
||||
load(
|
||||
":java_providers.bzl",
|
||||
"create_template_info",
|
||||
"derive_compiling_deps",
|
||||
"get_java_packaging_info",
|
||||
)
|
||||
|
||||
def _generate_script(generate_wrapper: bool.type, native_libs: {str.type: "SharedLibrary"}) -> bool.type:
|
||||
# if `generate_wrapper` is set and no native libs then it should be a wrapper script as result,
|
||||
# otherwise fat jar will be generated (inner jar or script will be included inside a final fat jar)
|
||||
return generate_wrapper and len(native_libs) == 0
|
||||
|
||||
def _create_fat_jar(
|
||||
ctx: "context",
|
||||
java_toolchain: JavaToolchainInfo.type,
|
||||
jars: "cmd_args",
|
||||
native_libs: {str.type: "SharedLibrary"},
|
||||
generate_wrapper: bool.type) -> ["artifact"]:
|
||||
extension = "sh" if _generate_script(generate_wrapper, native_libs) else "jar"
|
||||
output = ctx.actions.declare_output("{}.{}".format(ctx.label.name, extension))
|
||||
|
||||
args = [
|
||||
java_toolchain.fat_jar[RunInfo],
|
||||
"--jar_tool",
|
||||
java_toolchain.jar,
|
||||
"--jar_builder_tool",
|
||||
cmd_args(java_toolchain.jar_builder, delimiter = " "),
|
||||
"--output",
|
||||
output.as_output(),
|
||||
"--jars_file",
|
||||
ctx.actions.write("jars_file", jars),
|
||||
]
|
||||
|
||||
if native_libs:
|
||||
expect(
|
||||
java_toolchain.is_bootstrap_toolchain == False,
|
||||
"Bootstrap java toolchain could not be used for java_binary() with native code.",
|
||||
)
|
||||
args += [
|
||||
"--fat_jar_lib",
|
||||
java_toolchain.fat_jar_main_class_lib,
|
||||
"--native_libs_file",
|
||||
ctx.actions.write("native_libs", [cmd_args([so_name, native_lib.lib.output], delimiter = " ") for so_name, native_lib in native_libs.items()]),
|
||||
# fat jar's main class
|
||||
"--fat_jar_main_class",
|
||||
"com.facebook.buck.jvm.java.FatJarMain",
|
||||
# native libraries directory name. Main class expects to find libraries packed inside this directory.
|
||||
"--fat_jar_native_libs_directory_name",
|
||||
"nativelibs",
|
||||
]
|
||||
|
||||
main_class = ctx.attrs.main_class
|
||||
if main_class:
|
||||
args += ["--main_class", main_class]
|
||||
|
||||
manifest_file = ctx.attrs.manifest_file
|
||||
if manifest_file:
|
||||
args += ["--manifest", manifest_file]
|
||||
|
||||
blocklist = ctx.attrs.blacklist
|
||||
if blocklist:
|
||||
args += ["--blocklist", ctx.actions.write("blocklist_args", blocklist)]
|
||||
|
||||
if ctx.attrs.meta_inf_directory:
|
||||
args += ["--meta_inf_directory", ctx.attrs.meta_inf_directory]
|
||||
|
||||
outputs = [output]
|
||||
if generate_wrapper:
|
||||
classpath_args_output = ctx.actions.declare_output("classpath_args")
|
||||
args += [
|
||||
"--generate_wrapper",
|
||||
"--classpath_args_output",
|
||||
classpath_args_output.as_output(),
|
||||
"--java_tool",
|
||||
java_toolchain.java[RunInfo],
|
||||
"--script_marker_file_name",
|
||||
"wrapper_script",
|
||||
]
|
||||
outputs.append(classpath_args_output)
|
||||
|
||||
fat_jar_cmd = cmd_args(args)
|
||||
fat_jar_cmd.hidden(jars, [native_lib.lib.output for native_lib in native_libs.values()])
|
||||
|
||||
ctx.actions.run(fat_jar_cmd, category = "fat_jar")
|
||||
|
||||
if generate_wrapper == False:
|
||||
expect(
|
||||
len(outputs) == 1,
|
||||
"expected exactly one output when creating a fat jar",
|
||||
)
|
||||
|
||||
# If `generate_wrapper` is not set then the result will contain only 1 item that represent fat jar artifact.
|
||||
# Else if `generate_wrapper` is set then the first item in the result list will be script or far jar, and the second one is for @classpath_args file
|
||||
return outputs
|
||||
|
||||
def _get_run_cmd(
|
||||
attrs: struct.type,
|
||||
script_mode: bool.type,
|
||||
main_artifact: "artifact",
|
||||
java_toolchain: JavaToolchainInfo.type) -> "cmd_args":
|
||||
if script_mode:
|
||||
return cmd_args(["/bin/bash", main_artifact])
|
||||
else:
|
||||
return cmd_args([java_toolchain.java[RunInfo]] + attrs.java_args_for_run_info + ["-jar", main_artifact])
|
||||
|
||||
def _get_java_tool_artifacts(java_toolchain: JavaToolchainInfo.type) -> ["artifact"]:
|
||||
default_info = java_toolchain.java[DefaultInfo]
|
||||
return default_info.default_outputs + default_info.other_outputs
|
||||
|
||||
def java_binary_impl(ctx: "context") -> ["provider"]:
|
||||
"""
|
||||
java_binary() rule implementation
|
||||
|
||||
Args:
|
||||
ctx: rule analysis context
|
||||
Returns:
|
||||
list of created providers (DefaultInfo and RunInfo)
|
||||
"""
|
||||
|
||||
if ctx.attrs._build_only_native_code:
|
||||
return [
|
||||
DefaultInfo(default_outputs = [ctx.actions.write("unused.jar", [])]),
|
||||
RunInfo(),
|
||||
]
|
||||
|
||||
packaging_info = get_java_packaging_info(ctx, ctx.attrs.deps, None)
|
||||
|
||||
first_order_deps = derive_compiling_deps(ctx.actions, None, ctx.attrs.deps)
|
||||
first_order_libs = [dep.full_library for dep in (list(first_order_deps.traverse()) if first_order_deps else [])]
|
||||
|
||||
shared_library_info = merge_shared_libraries(
|
||||
ctx.actions,
|
||||
deps = filter(None, [x.get(SharedLibraryInfo) for x in ctx.attrs.deps]),
|
||||
)
|
||||
native_deps = traverse_shared_library_info(shared_library_info)
|
||||
|
||||
java_toolchain = ctx.attrs._java_toolchain[JavaToolchainInfo]
|
||||
need_to_generate_wrapper = ctx.attrs.generate_wrapper == True
|
||||
packaging_jar_args = packaging_info.packaging_deps.project_as_args("full_jar_args")
|
||||
outputs = _create_fat_jar(ctx, java_toolchain, cmd_args(packaging_jar_args), native_deps, need_to_generate_wrapper)
|
||||
|
||||
main_artifact = outputs[0]
|
||||
other_outputs = []
|
||||
|
||||
run_cmd = _get_run_cmd(
|
||||
attrs = ctx.attrs,
|
||||
script_mode = _generate_script(need_to_generate_wrapper, native_deps),
|
||||
main_artifact = main_artifact,
|
||||
java_toolchain = java_toolchain,
|
||||
)
|
||||
|
||||
if need_to_generate_wrapper:
|
||||
classpath_file = outputs[1]
|
||||
run_cmd.hidden(
|
||||
java_toolchain.java[RunInfo],
|
||||
classpath_file,
|
||||
packaging_jar_args,
|
||||
)
|
||||
other_outputs = [classpath_file] + [packaging_jar_args] + _get_java_tool_artifacts(java_toolchain)
|
||||
|
||||
return [
|
||||
DefaultInfo(default_outputs = [main_artifact], other_outputs = other_outputs),
|
||||
RunInfo(args = run_cmd),
|
||||
create_template_info(packaging_info, first_order_libs),
|
||||
]
|
||||
639
vendor/cxx/tools/buck/prelude/java/java_library.bzl
vendored
Normal file
639
vendor/cxx/tools/buck/prelude/java/java_library.bzl
vendored
Normal file
|
|
@ -0,0 +1,639 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
load("@prelude//:paths.bzl", "paths")
|
||||
load("@prelude//android:android_providers.bzl", "merge_android_packageable_info")
|
||||
load(
|
||||
"@prelude//java:java_providers.bzl",
|
||||
"JavaLibraryInfo",
|
||||
"JavaPackagingDepTSet",
|
||||
"JavaProviders",
|
||||
"create_abi",
|
||||
"create_java_library_providers",
|
||||
"create_native_providers",
|
||||
"derive_compiling_deps",
|
||||
"make_compile_outputs",
|
||||
"to_list",
|
||||
)
|
||||
load("@prelude//java:java_resources.bzl", "get_resources_map")
|
||||
load("@prelude//java:java_toolchain.bzl", "JavaToolchainInfo")
|
||||
load("@prelude//java:javacd_jar_creator.bzl", "create_jar_artifact_javacd")
|
||||
load("@prelude//java/plugins:java_annotation_processor.bzl", "create_ap_params")
|
||||
load("@prelude//java/plugins:java_plugin.bzl", "PluginParams", "create_plugin_params")
|
||||
load("@prelude//java/utils:java_utils.bzl", "derive_javac", "get_abi_generation_mode", "get_default_info", "get_java_version_attributes", "get_path_separator", "to_java_version")
|
||||
load("@prelude//linking:shared_libraries.bzl", "SharedLibraryInfo")
|
||||
load("@prelude//utils:utils.bzl", "expect")
|
||||
|
||||
_JAVA_FILE_EXTENSION = [".java"]
|
||||
_SUPPORTED_ARCHIVE_SUFFIXES = [".src.zip", "-sources.jar"]
|
||||
|
||||
def _process_classpath(
|
||||
actions: "actions",
|
||||
classpath_args: "cmd_args",
|
||||
cmd: "cmd_args",
|
||||
args_file_name: "string",
|
||||
option_name: "string"):
|
||||
# write joined classpath string into args file
|
||||
classpath_args_file, _ = actions.write(
|
||||
args_file_name,
|
||||
classpath_args,
|
||||
allow_args = True,
|
||||
)
|
||||
|
||||
# mark classpath artifacts as input
|
||||
cmd.hidden(classpath_args)
|
||||
|
||||
# add classpath args file to cmd
|
||||
cmd.add(option_name, classpath_args_file)
|
||||
|
||||
def classpath_args(args):
|
||||
return cmd_args(args, delimiter = get_path_separator())
|
||||
|
||||
def _process_plugins(
|
||||
actions: "actions",
|
||||
actions_prefix: str.type,
|
||||
ap_params: ["AnnotationProcessorParams"],
|
||||
plugin_params: ["PluginParams", None],
|
||||
javac_args: "cmd_args",
|
||||
cmd: "cmd_args"):
|
||||
processors_classpath_tsets = []
|
||||
|
||||
# Process Annotation processors
|
||||
if ap_params:
|
||||
# For external javac, we can't preserve separate classpaths for separate processors. So we just concat everything.
|
||||
javac_args.add("-processor")
|
||||
joined_processors_string = ",".join([p for ap in ap_params for p in ap.processors])
|
||||
|
||||
javac_args.add(joined_processors_string)
|
||||
|
||||
for ap in ap_params:
|
||||
for param in ap.params:
|
||||
javac_args.add("-A{}".format(param))
|
||||
if ap.deps:
|
||||
processors_classpath_tsets.append(ap.deps)
|
||||
|
||||
else:
|
||||
javac_args.add("-proc:none")
|
||||
|
||||
# Process Javac Plugins
|
||||
if plugin_params:
|
||||
plugin = plugin_params.processors[0]
|
||||
args = plugin_params.args.get(plugin, cmd_args())
|
||||
|
||||
# Produces "-Xplugin:PluginName arg1 arg2 arg3", as a single argument
|
||||
plugin_and_args = cmd_args(plugin)
|
||||
plugin_and_args.add(args)
|
||||
plugin_arg = cmd_args(format = "-Xplugin:{}", quote = "shell")
|
||||
plugin_arg.add(cmd_args(plugin_and_args, delimiter = " "))
|
||||
|
||||
javac_args.add(plugin_arg)
|
||||
if plugin_params.deps:
|
||||
processors_classpath_tsets.append(plugin_params.deps)
|
||||
|
||||
if len(processors_classpath_tsets) > 1:
|
||||
processors_classpath_tset = actions.tset(JavaPackagingDepTSet, children = processors_classpath_tsets)
|
||||
elif len(processors_classpath_tsets) == 1:
|
||||
processors_classpath_tset = processors_classpath_tsets[0]
|
||||
else:
|
||||
processors_classpath_tset = None
|
||||
|
||||
if processors_classpath_tset:
|
||||
processors_classpath = classpath_args(processors_classpath_tset.project_as_args("full_jar_args"))
|
||||
_process_classpath(
|
||||
actions,
|
||||
processors_classpath,
|
||||
cmd,
|
||||
"{}plugin_cp_args".format(actions_prefix),
|
||||
"--javac_processors_classpath_file",
|
||||
)
|
||||
|
||||
def _build_classpath(actions: "actions", deps: ["dependency"], additional_classpath_entries: ["artifact"], classpath_args_projection: "string") -> ["cmd_args", None]:
|
||||
compiling_deps_tset = derive_compiling_deps(actions, None, deps)
|
||||
|
||||
if additional_classpath_entries or compiling_deps_tset:
|
||||
args = cmd_args()
|
||||
if compiling_deps_tset:
|
||||
args.add(compiling_deps_tset.project_as_args(classpath_args_projection))
|
||||
args.add(additional_classpath_entries)
|
||||
return args
|
||||
|
||||
return None
|
||||
|
||||
def _build_bootclasspath(bootclasspath_entries: ["artifact"], source_level: int.type, java_toolchain: "JavaToolchainInfo") -> ["artifact"]:
|
||||
bootclasspath_list = []
|
||||
if source_level in [7, 8]:
|
||||
if bootclasspath_entries:
|
||||
bootclasspath_list = bootclasspath_entries
|
||||
elif source_level == 7:
|
||||
bootclasspath_list = java_toolchain.bootclasspath_7
|
||||
elif source_level == 8:
|
||||
bootclasspath_list = java_toolchain.bootclasspath_8
|
||||
return bootclasspath_list
|
||||
|
||||
def _append_javac_params(
|
||||
actions: "actions",
|
||||
actions_prefix: str.type,
|
||||
java_toolchain: "JavaToolchainInfo",
|
||||
srcs: ["artifact"],
|
||||
remove_classes: [str.type],
|
||||
annotation_processor_params: ["AnnotationProcessorParams"],
|
||||
javac_plugin_params: ["PluginParams", None],
|
||||
source_level: int.type,
|
||||
target_level: int.type,
|
||||
deps: ["dependency"],
|
||||
extra_arguments: ["string"],
|
||||
additional_classpath_entries: ["artifact"],
|
||||
bootclasspath_entries: ["artifact"],
|
||||
cmd: "cmd_args",
|
||||
generated_sources_dir: "artifact"):
|
||||
javac_args = cmd_args(
|
||||
"-encoding",
|
||||
"utf-8",
|
||||
# Set the sourcepath to stop us reading source files out of jars by mistake.
|
||||
"-sourcepath",
|
||||
'""',
|
||||
)
|
||||
javac_args.add(*extra_arguments)
|
||||
|
||||
# we want something that looks nice when prepended to another string, so add "_" to non-empty prefixes.
|
||||
if actions_prefix:
|
||||
actions_prefix += "_"
|
||||
|
||||
compiling_classpath = _build_classpath(actions, deps, additional_classpath_entries, "args_for_compiling")
|
||||
if compiling_classpath:
|
||||
_process_classpath(
|
||||
actions,
|
||||
classpath_args(compiling_classpath),
|
||||
cmd,
|
||||
"{}classpath_args".format(actions_prefix),
|
||||
"--javac_classpath_file",
|
||||
)
|
||||
else:
|
||||
javac_args.add("-classpath ''")
|
||||
|
||||
javac_args.add("-source")
|
||||
javac_args.add(str(source_level))
|
||||
javac_args.add("-target")
|
||||
javac_args.add(str(target_level))
|
||||
|
||||
bootclasspath_list = _build_bootclasspath(bootclasspath_entries, source_level, java_toolchain)
|
||||
if bootclasspath_list:
|
||||
_process_classpath(
|
||||
actions,
|
||||
classpath_args(bootclasspath_list),
|
||||
cmd,
|
||||
"{}bootclasspath_args".format(actions_prefix),
|
||||
"--javac_bootclasspath_file",
|
||||
)
|
||||
|
||||
_process_plugins(
|
||||
actions,
|
||||
actions_prefix,
|
||||
annotation_processor_params,
|
||||
javac_plugin_params,
|
||||
javac_args,
|
||||
cmd,
|
||||
)
|
||||
|
||||
cmd.add("--generated_sources_dir", generated_sources_dir.as_output())
|
||||
|
||||
zipped_sources, plain_sources = split_on_archives_and_plain_files(srcs, _JAVA_FILE_EXTENSION)
|
||||
|
||||
javac_args.add(*plain_sources)
|
||||
args_file, _ = actions.write(
|
||||
"{}javac_args".format(actions_prefix),
|
||||
javac_args,
|
||||
allow_args = True,
|
||||
)
|
||||
cmd.hidden(javac_args)
|
||||
|
||||
# mark plain srcs artifacts as input
|
||||
cmd.hidden(plain_sources)
|
||||
|
||||
cmd.add("--javac_args_file", args_file)
|
||||
|
||||
if zipped_sources:
|
||||
cmd.add("--zipped_sources_file", actions.write("{}zipped_source_args".format(actions_prefix), zipped_sources))
|
||||
cmd.hidden(zipped_sources)
|
||||
|
||||
if remove_classes:
|
||||
cmd.add("--remove_classes", actions.write("{}remove_classes_args".format(actions_prefix), remove_classes))
|
||||
|
||||
def split_on_archives_and_plain_files(
|
||||
srcs: ["artifact"],
|
||||
plain_file_extensions: [str.type]) -> (["artifact"], ["artifact"]):
|
||||
archives = []
|
||||
plain_sources = []
|
||||
|
||||
for src in srcs:
|
||||
if src.extension in plain_file_extensions:
|
||||
plain_sources.append(src)
|
||||
elif _is_supported_archive(src):
|
||||
archives.append(src)
|
||||
else:
|
||||
fail("Provided java source is not supported: {}".format(src))
|
||||
|
||||
return (archives, plain_sources)
|
||||
|
||||
def _is_supported_archive(src: "artifact") -> bool.type:
|
||||
basename = src.basename
|
||||
for supported_suffix in _SUPPORTED_ARCHIVE_SUFFIXES:
|
||||
if basename.endswith(supported_suffix):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _copy_resources(
|
||||
actions: "actions",
|
||||
actions_prefix: str.type,
|
||||
java_toolchain: JavaToolchainInfo.type,
|
||||
package: str.type,
|
||||
resources: ["artifact"],
|
||||
resources_root: [str.type, None]) -> "artifact":
|
||||
resources_to_copy = get_resources_map(java_toolchain, package, resources, resources_root)
|
||||
resource_output = actions.symlinked_dir("{}resources".format(actions_prefix), resources_to_copy)
|
||||
return resource_output
|
||||
|
||||
def _jar_creator(
|
||||
javac_tool: ["", None],
|
||||
java_toolchain: JavaToolchainInfo.type) -> "function":
|
||||
if javac_tool or java_toolchain.javac_protocol == "classic":
|
||||
return _create_jar_artifact
|
||||
elif java_toolchain.javac_protocol == "javacd":
|
||||
return create_jar_artifact_javacd
|
||||
else:
|
||||
fail("unrecognized javac protocol `{}`".format(java_toolchain.javac_protocol))
|
||||
|
||||
def compile_to_jar(
|
||||
ctx: "context",
|
||||
srcs: ["artifact"],
|
||||
*,
|
||||
abi_generation_mode: ["AbiGenerationMode", None] = None,
|
||||
output: ["artifact", None] = None,
|
||||
actions_prefix: [str.type, None] = None,
|
||||
javac_tool: ["", None] = None,
|
||||
resources: [["artifact"], None] = None,
|
||||
resources_root: [str.type, None] = None,
|
||||
remove_classes: [[str.type], None] = None,
|
||||
manifest_file: ["artifact", None] = None,
|
||||
ap_params: [["AnnotationProcessorParams"], None] = None,
|
||||
plugin_params: ["PluginParams", None] = None,
|
||||
source_level: [int.type, None] = None,
|
||||
target_level: [int.type, None] = None,
|
||||
deps: [["dependency"], None] = None,
|
||||
required_for_source_only_abi: bool.type = False,
|
||||
source_only_abi_deps: [["dependency"], None] = None,
|
||||
extra_arguments: [["string"], None] = None,
|
||||
additional_classpath_entries: [["artifact"], None] = None,
|
||||
additional_compiled_srcs: ["artifact", None] = None,
|
||||
bootclasspath_entries: [["artifact"], None] = None) -> "JavaCompileOutputs":
|
||||
if not additional_classpath_entries:
|
||||
additional_classpath_entries = []
|
||||
if not bootclasspath_entries:
|
||||
bootclasspath_entries = []
|
||||
if not extra_arguments:
|
||||
extra_arguments = []
|
||||
if not resources:
|
||||
resources = []
|
||||
if not deps:
|
||||
deps = []
|
||||
if not remove_classes:
|
||||
remove_classes = []
|
||||
if not actions_prefix:
|
||||
actions_prefix = ""
|
||||
if not ap_params:
|
||||
ap_params = []
|
||||
if not source_only_abi_deps:
|
||||
source_only_abi_deps = []
|
||||
|
||||
# TODO(cjhopman): Should verify that source_only_abi_deps are contained within the normal classpath.
|
||||
|
||||
java_toolchain = ctx.attrs._java_toolchain[JavaToolchainInfo]
|
||||
if not source_level:
|
||||
source_level = to_java_version(java_toolchain.source_level)
|
||||
if not target_level:
|
||||
target_level = to_java_version(java_toolchain.target_level)
|
||||
|
||||
is_building_android_binary = ctx.attrs._is_building_android_binary
|
||||
|
||||
return _jar_creator(javac_tool, java_toolchain)(
|
||||
ctx.actions,
|
||||
actions_prefix,
|
||||
abi_generation_mode,
|
||||
java_toolchain,
|
||||
ctx.label,
|
||||
output,
|
||||
javac_tool,
|
||||
srcs,
|
||||
remove_classes,
|
||||
resources,
|
||||
resources_root,
|
||||
manifest_file,
|
||||
ap_params,
|
||||
plugin_params,
|
||||
source_level,
|
||||
target_level,
|
||||
deps,
|
||||
required_for_source_only_abi,
|
||||
source_only_abi_deps,
|
||||
extra_arguments,
|
||||
additional_classpath_entries,
|
||||
additional_compiled_srcs,
|
||||
bootclasspath_entries,
|
||||
is_building_android_binary,
|
||||
)
|
||||
|
||||
def _create_jar_artifact(
|
||||
actions: "actions",
|
||||
actions_prefix: str.type,
|
||||
_abi_generation_mode: ["AbiGenerationMode", None],
|
||||
java_toolchain: JavaToolchainInfo.type,
|
||||
label: "label",
|
||||
output: ["artifact", None],
|
||||
javac_tool: ["", None],
|
||||
srcs: ["artifact"],
|
||||
remove_classes: [str.type],
|
||||
resources: ["artifact"],
|
||||
resources_root: [str.type, None],
|
||||
manifest_file: ["artifact", None],
|
||||
ap_params: ["AnnotationProcessorParams"],
|
||||
plugin_params: ["PluginParams", None],
|
||||
source_level: int.type,
|
||||
target_level: int.type,
|
||||
deps: ["dependency"],
|
||||
required_for_source_only_abi: bool.type,
|
||||
_source_only_abi_deps: ["dependency"],
|
||||
extra_arguments: ["string"],
|
||||
additional_classpath_entries: ["artifact"],
|
||||
additional_compiled_srcs: ["artifact", None],
|
||||
bootclasspath_entries: ["artifact"],
|
||||
_is_building_android_binary: bool.type) -> "JavaCompileOutputs":
|
||||
"""
|
||||
Creates jar artifact.
|
||||
|
||||
Returns a single artifacts that represents jar output file
|
||||
"""
|
||||
javac_tool = javac_tool or java_toolchain.javac
|
||||
jar_out = output or actions.declare_output(paths.join(actions_prefix or "jar", "lib.jar"))
|
||||
|
||||
args = [
|
||||
java_toolchain.compile_and_package[RunInfo],
|
||||
"--jar_builder_tool",
|
||||
cmd_args(java_toolchain.jar_builder, delimiter = " "),
|
||||
"--output",
|
||||
jar_out.as_output(),
|
||||
]
|
||||
|
||||
skip_javac = False if srcs or ap_params or plugin_params else True
|
||||
if skip_javac:
|
||||
args.append("--skip_javac_run")
|
||||
else:
|
||||
args += ["--javac_tool", javac_tool]
|
||||
|
||||
if resources:
|
||||
resource_dir = _copy_resources(actions, actions_prefix, java_toolchain, label.package, resources, resources_root)
|
||||
args += ["--resources_dir", resource_dir]
|
||||
|
||||
if manifest_file:
|
||||
args += ["--manifest", manifest_file]
|
||||
|
||||
if additional_compiled_srcs:
|
||||
args += ["--additional_compiled_srcs", additional_compiled_srcs]
|
||||
|
||||
compile_and_package_cmd = cmd_args(args)
|
||||
|
||||
generated_sources_dir = None
|
||||
if not skip_javac:
|
||||
generated_sources_dir = actions.declare_output("{}generated_sources".format(actions_prefix))
|
||||
_append_javac_params(
|
||||
actions,
|
||||
actions_prefix,
|
||||
java_toolchain,
|
||||
srcs,
|
||||
remove_classes,
|
||||
ap_params,
|
||||
plugin_params,
|
||||
source_level,
|
||||
target_level,
|
||||
deps,
|
||||
extra_arguments,
|
||||
additional_classpath_entries,
|
||||
bootclasspath_entries,
|
||||
compile_and_package_cmd,
|
||||
generated_sources_dir,
|
||||
)
|
||||
|
||||
actions.run(compile_and_package_cmd, category = "javac_and_jar", identifier = actions_prefix)
|
||||
|
||||
abi = None if java_toolchain.is_bootstrap_toolchain else create_abi(actions, java_toolchain.class_abi_generator, jar_out)
|
||||
|
||||
return make_compile_outputs(
|
||||
full_library = jar_out,
|
||||
class_abi = abi,
|
||||
required_for_source_only_abi = required_for_source_only_abi,
|
||||
annotation_processor_output = generated_sources_dir,
|
||||
)
|
||||
|
||||
def _check_dep_types(deps: ["dependency"]):
|
||||
for dep in deps:
|
||||
if JavaLibraryInfo not in dep and SharedLibraryInfo not in dep:
|
||||
fail("Received dependency {} is not supported. `java_library`, `prebuilt_jar` and native libraries are supported.".format(dep))
|
||||
|
||||
def _check_provided_deps(provided_deps: ["dependency"], attr_name: str.type):
|
||||
for provided_dep in provided_deps:
|
||||
expect(
|
||||
JavaLibraryInfo in provided_dep or SharedLibraryInfo not in provided_dep,
|
||||
"Java code does not need native libs in order to compile, so not valid as {}: {}".format(attr_name, provided_dep),
|
||||
)
|
||||
|
||||
def _check_exported_deps(exported_deps: ["dependency"], attr_name: str.type):
|
||||
for exported_dep in exported_deps:
|
||||
expect(
|
||||
JavaLibraryInfo in exported_dep,
|
||||
"Exported deps are meant to be forwarded onto the classpath for dependents, so only " +
|
||||
"make sense for a target that emits Java bytecode, {} in {} does not.".format(exported_dep, attr_name),
|
||||
)
|
||||
|
||||
# TODO(T108258238) remove need for this
|
||||
def _skip_java_library_dep_checks(ctx: "context") -> bool.type:
|
||||
return "skip_buck2_java_library_dep_checks" in ctx.attrs.labels
|
||||
|
||||
def java_library_impl(ctx: "context") -> ["provider"]:
|
||||
"""
|
||||
java_library() rule implementation
|
||||
|
||||
Args:
|
||||
ctx: rule analysis context
|
||||
Returns:
|
||||
list of created providers
|
||||
"""
|
||||
packaging_deps = ctx.attrs.deps + ctx.attrs.exported_deps + ctx.attrs.runtime_deps
|
||||
if ctx.attrs._build_only_native_code:
|
||||
shared_library_info, cxx_resource_info = create_native_providers(ctx.actions, ctx.label, packaging_deps)
|
||||
return [
|
||||
shared_library_info,
|
||||
cxx_resource_info,
|
||||
# Add an unused default output in case this target is used an an attr.source() anywhere.
|
||||
DefaultInfo(default_outputs = [ctx.actions.write("unused.jar", [])]),
|
||||
TemplatePlaceholderInfo(keyed_variables = {
|
||||
"classpath": "unused_but_needed_for_analysis",
|
||||
}),
|
||||
]
|
||||
|
||||
if not _skip_java_library_dep_checks(ctx):
|
||||
_check_dep_types(ctx.attrs.deps)
|
||||
_check_dep_types(ctx.attrs.provided_deps)
|
||||
_check_dep_types(ctx.attrs.exported_deps)
|
||||
_check_dep_types(ctx.attrs.exported_provided_deps)
|
||||
_check_dep_types(ctx.attrs.runtime_deps)
|
||||
|
||||
java_providers = build_java_library(ctx, ctx.attrs.srcs)
|
||||
|
||||
return to_list(java_providers) + [
|
||||
# TODO(T107163344) this shouldn't be in java_library itself, use overlays to remove it.
|
||||
merge_android_packageable_info(
|
||||
ctx.label,
|
||||
ctx.actions,
|
||||
ctx.attrs.deps + ctx.attrs.exported_deps + ctx.attrs.runtime_deps,
|
||||
),
|
||||
]
|
||||
|
||||
def build_java_library(
|
||||
ctx: "context",
|
||||
srcs: ["artifact"],
|
||||
run_annotation_processors = True,
|
||||
additional_classpath_entries: ["artifact"] = [],
|
||||
bootclasspath_entries: ["artifact"] = [],
|
||||
additional_compiled_srcs: ["artifact", None] = None,
|
||||
generated_sources: ["artifact"] = [],
|
||||
override_abi_generation_mode: ["AbiGenerationMode", None] = None) -> JavaProviders.type:
|
||||
expect(
|
||||
not getattr(ctx.attrs, "_build_only_native_code", False),
|
||||
"Shouldn't call build_java_library if we're only building native code!",
|
||||
)
|
||||
|
||||
_check_provided_deps(ctx.attrs.provided_deps, "provided_deps")
|
||||
_check_provided_deps(ctx.attrs.exported_provided_deps, "exported_provided_deps")
|
||||
_check_exported_deps(ctx.attrs.exported_deps, "exported_deps")
|
||||
_check_exported_deps(ctx.attrs.exported_provided_deps, "exported_provided_deps")
|
||||
|
||||
deps_query = getattr(ctx.attrs, "deps_query", []) or []
|
||||
provided_deps_query = getattr(ctx.attrs, "provided_deps_query", []) or []
|
||||
first_order_deps = (
|
||||
ctx.attrs.deps +
|
||||
deps_query +
|
||||
ctx.attrs.exported_deps +
|
||||
ctx.attrs.provided_deps +
|
||||
provided_deps_query +
|
||||
ctx.attrs.exported_provided_deps
|
||||
)
|
||||
|
||||
resources = ctx.attrs.resources
|
||||
ap_params = create_ap_params(
|
||||
ctx,
|
||||
ctx.attrs.plugins,
|
||||
ctx.attrs.annotation_processors,
|
||||
ctx.attrs.annotation_processor_params,
|
||||
ctx.attrs.annotation_processor_deps,
|
||||
) if run_annotation_processors else None
|
||||
plugin_params = create_plugin_params(ctx, ctx.attrs.plugins) if run_annotation_processors else None
|
||||
manifest_file = ctx.attrs.manifest_file
|
||||
source_level, target_level = get_java_version_attributes(ctx)
|
||||
javac_tool = derive_javac(ctx.attrs.javac) if ctx.attrs.javac else None
|
||||
|
||||
outputs = None
|
||||
common_compile_kwargs = None
|
||||
sub_targets = {}
|
||||
if srcs or additional_compiled_srcs or resources or ap_params or plugin_params or manifest_file:
|
||||
abi_generation_mode = override_abi_generation_mode or get_abi_generation_mode(ctx.attrs.abi_generation_mode)
|
||||
|
||||
common_compile_kwargs = {
|
||||
"abi_generation_mode": abi_generation_mode,
|
||||
"additional_classpath_entries": additional_classpath_entries,
|
||||
"additional_compiled_srcs": additional_compiled_srcs,
|
||||
"ap_params": ap_params,
|
||||
"bootclasspath_entries": bootclasspath_entries,
|
||||
"deps": first_order_deps,
|
||||
"extra_arguments": ctx.attrs.extra_arguments,
|
||||
"manifest_file": manifest_file,
|
||||
"remove_classes": ctx.attrs.remove_classes,
|
||||
"required_for_source_only_abi": ctx.attrs.required_for_source_only_abi,
|
||||
"resources": resources,
|
||||
"resources_root": ctx.attrs.resources_root,
|
||||
"source_level": source_level,
|
||||
"source_only_abi_deps": ctx.attrs.source_only_abi_deps,
|
||||
"srcs": srcs,
|
||||
"target_level": target_level,
|
||||
}
|
||||
|
||||
outputs = compile_to_jar(
|
||||
ctx,
|
||||
javac_tool = javac_tool,
|
||||
plugin_params = plugin_params,
|
||||
**common_compile_kwargs
|
||||
)
|
||||
|
||||
java_toolchain = ctx.attrs._java_toolchain[JavaToolchainInfo]
|
||||
if (
|
||||
common_compile_kwargs and
|
||||
srcs and
|
||||
not java_toolchain.is_bootstrap_toolchain and
|
||||
not ctx.attrs._is_building_android_binary
|
||||
):
|
||||
ast_dumper = java_toolchain.ast_dumper
|
||||
|
||||
# Replace whatever compiler plugins are present with the AST dumper instead
|
||||
ast_output = ctx.actions.declare_output("ast_json")
|
||||
dump_ast_args = cmd_args(ast_output.as_output(), "--target-label", '"{}"'.format(ctx.label))
|
||||
for dep in _build_bootclasspath(bootclasspath_entries, source_level, java_toolchain):
|
||||
dump_ast_args.add("--dependency", '"{}"'.format(dep.owner), dep)
|
||||
classpath_args = _build_classpath(ctx.actions, first_order_deps, additional_classpath_entries, "args_for_ast_dumper")
|
||||
if classpath_args:
|
||||
dump_ast_args.add(classpath_args)
|
||||
ast_dumping_plugin_params = create_plugin_params(ctx, [ast_dumper])
|
||||
ast_dumper_args_file = ctx.actions.write("dump_ast_args", dump_ast_args)
|
||||
ast_dumping_plugin_params = PluginParams(
|
||||
processors = ast_dumping_plugin_params.processors,
|
||||
deps = ast_dumping_plugin_params.deps,
|
||||
args = {
|
||||
"DumpAstPlugin": cmd_args(ast_dumper_args_file).hidden(dump_ast_args),
|
||||
},
|
||||
)
|
||||
|
||||
# We don't actually care about the jar output this time; we just want the AST from the
|
||||
# plugin
|
||||
compile_to_jar(
|
||||
ctx,
|
||||
actions_prefix = "ast",
|
||||
plugin_params = ast_dumping_plugin_params,
|
||||
javac_tool = java_toolchain.fallback_javac,
|
||||
**common_compile_kwargs
|
||||
)
|
||||
|
||||
sub_targets["ast"] = [DefaultInfo(default_outputs = [ast_output])]
|
||||
|
||||
java_library_info, java_packaging_info, shared_library_info, cxx_resource_info, template_placeholder_info, intellij_info = create_java_library_providers(
|
||||
ctx,
|
||||
library_output = outputs.classpath_entry if outputs else None,
|
||||
declared_deps = ctx.attrs.deps + deps_query,
|
||||
exported_deps = ctx.attrs.exported_deps,
|
||||
provided_deps = ctx.attrs.provided_deps + provided_deps_query,
|
||||
exported_provided_deps = ctx.attrs.exported_provided_deps,
|
||||
runtime_deps = ctx.attrs.runtime_deps,
|
||||
needs_desugar = source_level > 7 or target_level > 7,
|
||||
generated_sources = generated_sources + [outputs.annotation_processor_output] if outputs and outputs.annotation_processor_output else [],
|
||||
)
|
||||
|
||||
default_info = get_default_info(outputs, sub_targets)
|
||||
return JavaProviders(
|
||||
java_library_info = java_library_info,
|
||||
java_library_intellij_info = intellij_info,
|
||||
java_packaging_info = java_packaging_info,
|
||||
shared_library_info = shared_library_info,
|
||||
cxx_resource_info = cxx_resource_info,
|
||||
template_placeholder_info = template_placeholder_info,
|
||||
default_info = default_info,
|
||||
)
|
||||
451
vendor/cxx/tools/buck/prelude/java/java_providers.bzl
vendored
Normal file
451
vendor/cxx/tools/buck/prelude/java/java_providers.bzl
vendored
Normal file
|
|
@ -0,0 +1,451 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
load(
|
||||
"@prelude//:resources.bzl",
|
||||
"ResourceInfo",
|
||||
"gather_resources",
|
||||
)
|
||||
load("@prelude//java:dex.bzl", "get_dex_produced_from_java_library")
|
||||
load("@prelude//java:dex_toolchain.bzl", "DexToolchainInfo")
|
||||
load("@prelude//java/utils:java_utils.bzl", "get_path_separator")
|
||||
load(
|
||||
"@prelude//linking:shared_libraries.bzl",
|
||||
"SharedLibraryInfo",
|
||||
"merge_shared_libraries",
|
||||
)
|
||||
load("@prelude//utils:utils.bzl", "expect")
|
||||
|
||||
# JAVA PROVIDER DOCS
|
||||
#
|
||||
# Our core Java provider is JavaLibraryInfo. At a basic level, this provider needs to give
|
||||
# its dependents the ability to do two things: compilation and packaging.
|
||||
#
|
||||
# Compilation
|
||||
#
|
||||
# When we compile, we need to add all of our dependencies to the classpath. That includes
|
||||
# anything in `deps`, `exported_deps`, `provided_deps` and `exported_provided_deps`, (but
|
||||
# not `runtime_deps`). Additionally, it includes anything that these dependencies export
|
||||
# (via `exported_deps` or `exported_provided_deps`). For example, if A depends upon B,
|
||||
# and B has an exported dependency on C, then we need to add both B and C to the classpath
|
||||
# when compiling A, i.e. both B and C need to be part of B's `compiling_deps`.
|
||||
#
|
||||
# Therefore, the `compiling_deps` consist of the library's own output (if it exists) plus
|
||||
# the `compiling_deps` of any `exported_deps` and `exported_provided_deps`.
|
||||
#
|
||||
# When we compile, we don't need to compile against the full library - instead, we just
|
||||
# compile against the library's public interface, or ABI.
|
||||
#
|
||||
# Packaging
|
||||
#
|
||||
# When we package our Java code into a `java_binary`, we need to include all of the Java
|
||||
# code that is need to run the application - i.e. all the transitive dependencies. That
|
||||
# includes anything in `deps`, `exported_deps` and `runtime_deps` (but not `provided_deps`
|
||||
# or `exported_provided_deps`). For example, if A depends upon B, and B has a `dep` on C
|
||||
# and a `provided_dep` on D, then if we package A we also need to include B and C, but
|
||||
# not D.
|
||||
#
|
||||
# Therefore, the `packaging_deps` consist of the library's own output (if it exists) plus
|
||||
# the `packaging_deps` of any `deps`, `exported_deps` and `runtime_deps`.
|
||||
#
|
||||
# When we package, we need to use the full library (since we are actually going to be
|
||||
# running the code contained in the library).
|
||||
#
|
||||
# We also need to package up any native code that is declared transitively. The
|
||||
# `SharedLibraryInfo` also consists of the `SharedLibraryInfo` of any `deps`,
|
||||
# `exported_deps` and `runtime_deps`.
|
||||
#
|
||||
# Android
|
||||
#
|
||||
# Because Android uses Java, and we don't currently have the ability to "overlay" our
|
||||
# providers, the core Java providers are extended to support Android's requirements.
|
||||
# This introduces some additional complexity.
|
||||
#
|
||||
# Android doesn't package Java bytecode, but instead it converts the Java bytecode
|
||||
# .dex (Dalvik Executable) files that are packaged into the Android binary (either an
|
||||
# APK or an AAB). Therefore, our `packaging_deps` contain not just a `jar` field but
|
||||
# also a `dex` field. If the `dex` field is empty, then the dep should not be
|
||||
# packaged into the APK - this is useful for things like `android_build_config` where
|
||||
# we want the output (.jar) to be present in any Java annotation processors that we
|
||||
# run, but not in the final binary (since we rewrite the build config at the binary
|
||||
# level anyway).
|
||||
#
|
||||
# Android also provides the ability to run Proguard on your binary in order to
|
||||
# remove unused classes etc. Each Java library can specify any classes that it wants
|
||||
# to always keep etc, via a `proguard_config`. This config also needs to be added to
|
||||
# the `packaging_deps`.
|
||||
#
|
||||
# Java-like rules also provide a "special" function that can be used inside queries:
|
||||
# "classpath". `classpath(A)` returns all of the packaging deps of A, while
|
||||
# `classpath(A, 1)` returns all of the first-order packaging deps of A.
|
||||
|
||||
JavaClasspathEntry = record(
|
||||
full_library = field("artifact"),
|
||||
abi = field("artifact"),
|
||||
required_for_source_only_abi = field(bool.type),
|
||||
)
|
||||
|
||||
def _args_for_ast_dumper(entry: JavaClasspathEntry.type):
|
||||
return [
|
||||
"--dependency",
|
||||
'"{}"'.format(entry.abi.owner),
|
||||
entry.abi,
|
||||
]
|
||||
|
||||
def _args_for_compiling(entry: JavaClasspathEntry.type):
|
||||
return entry.abi
|
||||
|
||||
def _javacd_json(v):
|
||||
return struct(path = v.abi)
|
||||
|
||||
JavaCompilingDepsTSet = transitive_set(
|
||||
args_projections = {
|
||||
"args_for_ast_dumper": _args_for_ast_dumper,
|
||||
"args_for_compiling": _args_for_compiling,
|
||||
},
|
||||
json_projections = {
|
||||
"javacd_json": _javacd_json,
|
||||
},
|
||||
)
|
||||
|
||||
JavaPackagingDep = record(
|
||||
label = "label",
|
||||
jar = ["artifact", None],
|
||||
dex = ["DexLibraryInfo", None],
|
||||
is_prebuilt_jar = bool.type,
|
||||
proguard_config = ["artifact", None],
|
||||
|
||||
# An output that is used solely by the system to have an artifact bound to the target (that the core can then use to find
|
||||
# the right target from the given artifact).
|
||||
output_for_classpath_macro = "artifact",
|
||||
)
|
||||
|
||||
def _full_jar_args(dep: JavaPackagingDep.type):
|
||||
if dep.jar:
|
||||
return [dep.jar]
|
||||
return []
|
||||
|
||||
def _args_for_classpath_macro(dep: JavaPackagingDep.type):
|
||||
return dep.output_for_classpath_macro
|
||||
|
||||
def _packaging_dep_javacd_json(dep: JavaPackagingDep.type):
|
||||
if dep.jar:
|
||||
return struct(path = dep.jar)
|
||||
|
||||
return struct()
|
||||
|
||||
JavaPackagingDepTSet = transitive_set(
|
||||
args_projections = {
|
||||
"args_for_classpath_macro": _args_for_classpath_macro,
|
||||
"full_jar_args": _full_jar_args,
|
||||
},
|
||||
json_projections = {
|
||||
"javacd_json": _packaging_dep_javacd_json,
|
||||
},
|
||||
)
|
||||
|
||||
JavaLibraryInfo = provider(
|
||||
"Information about a java library and its dependencies",
|
||||
fields = [
|
||||
# Java dependencies exposed to dependent targets and supposed to be used during compilation.
|
||||
# Consisting of this library's own output, and the "compiling_deps" of any exported_deps and exported_provided_deps.
|
||||
#
|
||||
"compiling_deps", # ["JavaCompilingDepsTSet", None]
|
||||
|
||||
# An output of the library. If present then already included into `compiling_deps` field.
|
||||
"library_output", # ["JavaClasspathEntry", None]
|
||||
|
||||
# An output that is used solely by the system to have an artifact bound to the target (that the core can then use to find
|
||||
# the right target from the given artifact).
|
||||
"output_for_classpath_macro", # "artifact"
|
||||
],
|
||||
)
|
||||
|
||||
JavaLibraryIntellijInfo = provider(
|
||||
"Information about a java library that is required for Intellij project generation",
|
||||
fields = [
|
||||
# All the artifacts that were used in order to compile this library
|
||||
"compiling_classpath", # ["artifact"]
|
||||
"generated_sources", # ["artifact"]
|
||||
# Directory containing external annotation jars
|
||||
"annotation_jars_dir", # ["artifact", None]
|
||||
],
|
||||
)
|
||||
|
||||
JavaPackagingInfo = provider(
|
||||
fields = [
|
||||
# Presents all java dependencies used to build this library and it's dependencies (all transitive deps except provided ones).
|
||||
# These deps must be included into the final artifact.
|
||||
"packaging_deps", # ["JavaPackagingDepTSet", None],
|
||||
],
|
||||
)
|
||||
|
||||
KeystoreInfo = provider(
|
||||
fields = [
|
||||
"store", # artifact
|
||||
"properties", # artifact
|
||||
],
|
||||
)
|
||||
|
||||
JavaCompileOutputs = record(
|
||||
full_library = "artifact",
|
||||
class_abi = ["artifact", None],
|
||||
source_abi = ["artifact", None],
|
||||
source_only_abi = ["artifact", None],
|
||||
classpath_entry = JavaClasspathEntry.type,
|
||||
annotation_processor_output = ["artifact", None],
|
||||
)
|
||||
|
||||
JavaProviders = record(
|
||||
java_library_info = JavaLibraryInfo.type,
|
||||
java_library_intellij_info = JavaLibraryIntellijInfo.type,
|
||||
java_packaging_info = JavaPackagingInfo.type,
|
||||
shared_library_info = SharedLibraryInfo.type,
|
||||
cxx_resource_info = ResourceInfo.type,
|
||||
template_placeholder_info = TemplatePlaceholderInfo.type,
|
||||
default_info = DefaultInfo.type,
|
||||
)
|
||||
|
||||
def to_list(java_providers: JavaProviders.type) -> ["provider"]:
|
||||
return [
|
||||
java_providers.java_library_info,
|
||||
java_providers.java_library_intellij_info,
|
||||
java_providers.java_packaging_info,
|
||||
java_providers.shared_library_info,
|
||||
java_providers.cxx_resource_info,
|
||||
java_providers.template_placeholder_info,
|
||||
java_providers.default_info,
|
||||
]
|
||||
|
||||
# Creates a JavaCompileOutputs. `classpath_abi` can be set to specify a
|
||||
# specific artifact to be used as the abi for the JavaClasspathEntry.
|
||||
def make_compile_outputs(
|
||||
full_library: "artifact",
|
||||
class_abi: ["artifact", None] = None,
|
||||
source_abi: ["artifact", None] = None,
|
||||
source_only_abi: ["artifact", None] = None,
|
||||
classpath_abi: ["artifact", None] = None,
|
||||
required_for_source_only_abi: bool.type = False,
|
||||
annotation_processor_output: ["artifact", None] = None) -> JavaCompileOutputs.type:
|
||||
return JavaCompileOutputs(
|
||||
full_library = full_library,
|
||||
class_abi = class_abi,
|
||||
source_abi = source_abi,
|
||||
source_only_abi = source_only_abi,
|
||||
classpath_entry = JavaClasspathEntry(
|
||||
full_library = full_library,
|
||||
abi = classpath_abi or class_abi or full_library,
|
||||
required_for_source_only_abi = required_for_source_only_abi,
|
||||
),
|
||||
annotation_processor_output = annotation_processor_output,
|
||||
)
|
||||
|
||||
def create_abi(actions: "actions", class_abi_generator: "dependency", library: "artifact") -> "artifact":
|
||||
# It's possible for the library to be created in a subdir that is
|
||||
# itself some actions output artifact, so we replace directory
|
||||
# separators to get a path that we can uniquely own.
|
||||
# TODO(cjhopman): This probably should take in the output path.
|
||||
class_abi = actions.declare_output("{}-class-abi.jar".format(library.short_path.replace("/", "_")))
|
||||
actions.run(
|
||||
[
|
||||
class_abi_generator[RunInfo],
|
||||
library,
|
||||
class_abi.as_output(),
|
||||
],
|
||||
category = "class_abi_generation",
|
||||
identifier = library.short_path,
|
||||
)
|
||||
return class_abi
|
||||
|
||||
# Accumulate deps necessary for compilation, which consist of this library's output and compiling_deps of its exported deps
|
||||
def derive_compiling_deps(
|
||||
actions: "actions",
|
||||
library_output: [JavaClasspathEntry.type, None],
|
||||
children: ["dependency"]) -> ["JavaCompilingDepsTSet", None]:
|
||||
if children:
|
||||
filtered_children = filter(
|
||||
None,
|
||||
[exported_dep.compiling_deps for exported_dep in filter(None, [x.get(JavaLibraryInfo) for x in children])],
|
||||
)
|
||||
children = filtered_children
|
||||
|
||||
if not library_output and not children:
|
||||
return None
|
||||
|
||||
if library_output:
|
||||
return actions.tset(JavaCompilingDepsTSet, children = children, value = library_output)
|
||||
else:
|
||||
return actions.tset(JavaCompilingDepsTSet, children = children)
|
||||
|
||||
def create_java_packaging_dep(
|
||||
ctx: "context",
|
||||
library_jar: ["artifact", None] = None,
|
||||
output_for_classpath_macro: ["artifact", None] = None,
|
||||
needs_desugar: bool.type = False,
|
||||
desugar_deps: ["artifact"] = [],
|
||||
is_prebuilt_jar: bool.type = False,
|
||||
dex_weight_factor: int.type = 1) -> "JavaPackagingDep":
|
||||
dex_toolchain = getattr(ctx.attrs, "_dex_toolchain", None)
|
||||
if library_jar != None and dex_toolchain != None and ctx.attrs._dex_toolchain[DexToolchainInfo].d8_command != None:
|
||||
dex = get_dex_produced_from_java_library(
|
||||
ctx,
|
||||
ctx.attrs._dex_toolchain[DexToolchainInfo],
|
||||
library_jar,
|
||||
needs_desugar,
|
||||
desugar_deps,
|
||||
dex_weight_factor,
|
||||
)
|
||||
else:
|
||||
dex = None
|
||||
|
||||
expect(library_jar != None or output_for_classpath_macro != None, "Must provide an output_for_classpath_macro if no library_jar is provided!")
|
||||
|
||||
return JavaPackagingDep(
|
||||
label = ctx.label,
|
||||
jar = library_jar,
|
||||
dex = dex,
|
||||
is_prebuilt_jar = is_prebuilt_jar,
|
||||
proguard_config = getattr(ctx.attrs, "proguard_config", None),
|
||||
output_for_classpath_macro = output_for_classpath_macro or library_jar,
|
||||
)
|
||||
|
||||
def get_all_java_packaging_deps(ctx: "context", deps: ["dependency"]) -> ["JavaPackagingDep"]:
|
||||
return get_all_java_packaging_deps_from_packaging_infos(ctx, filter(None, [x.get(JavaPackagingInfo) for x in deps]))
|
||||
|
||||
def get_all_java_packaging_deps_from_packaging_infos(ctx: "context", infos: ["JavaPackagingInfo"]) -> ["JavaPackagingDep"]:
|
||||
children = filter(None, [info.packaging_deps for info in infos])
|
||||
if not children:
|
||||
return []
|
||||
|
||||
tset = ctx.actions.tset(JavaPackagingDepTSet, children = children)
|
||||
|
||||
return list(tset.traverse())
|
||||
|
||||
def get_all_java_packaging_deps_tset(
|
||||
ctx: "context",
|
||||
java_packaging_infos: ["JavaPackagingInfo"],
|
||||
java_packaging_dep: [JavaPackagingDep.type, None] = None) -> [JavaPackagingDepTSet.type, None]:
|
||||
packaging_deps_kwargs = {}
|
||||
if java_packaging_dep:
|
||||
packaging_deps_kwargs["value"] = java_packaging_dep
|
||||
|
||||
packaging_deps_children = filter(None, [info.packaging_deps for info in java_packaging_infos])
|
||||
if packaging_deps_children:
|
||||
packaging_deps_kwargs["children"] = packaging_deps_children
|
||||
|
||||
return ctx.actions.tset(JavaPackagingDepTSet, **packaging_deps_kwargs) if packaging_deps_kwargs else None
|
||||
|
||||
# Accumulate deps necessary for packaging, which consist of all transitive java deps (except provided ones)
|
||||
def get_java_packaging_info(
|
||||
ctx: "context",
|
||||
raw_deps: ["dependency"],
|
||||
java_packaging_dep: [JavaPackagingDep.type, None] = None) -> JavaPackagingInfo.type:
|
||||
java_packaging_infos = filter(None, [x.get(JavaPackagingInfo) for x in raw_deps])
|
||||
packaging_deps = get_all_java_packaging_deps_tset(ctx, java_packaging_infos, java_packaging_dep)
|
||||
return JavaPackagingInfo(packaging_deps = packaging_deps)
|
||||
|
||||
def create_native_providers(actions: "actions", label: "label", packaging_deps: ["dependency"]) -> (SharedLibraryInfo.type, ResourceInfo.type):
|
||||
shared_library_info = merge_shared_libraries(
|
||||
actions,
|
||||
deps = filter(None, [x.get(SharedLibraryInfo) for x in packaging_deps]),
|
||||
)
|
||||
cxx_resource_info = ResourceInfo(resources = gather_resources(
|
||||
label,
|
||||
deps = packaging_deps,
|
||||
))
|
||||
return shared_library_info, cxx_resource_info
|
||||
|
||||
def _create_non_template_providers(
|
||||
ctx: "context",
|
||||
library_output: [JavaClasspathEntry.type, None],
|
||||
declared_deps: ["dependency"] = [],
|
||||
exported_deps: ["dependency"] = [],
|
||||
exported_provided_deps: ["dependency"] = [],
|
||||
runtime_deps: ["dependency"] = [],
|
||||
needs_desugar: bool.type = False,
|
||||
desugar_classpath: ["artifact"] = [],
|
||||
is_prebuilt_jar: bool.type = False) -> (JavaLibraryInfo.type, JavaPackagingInfo.type, SharedLibraryInfo.type, ResourceInfo.type):
|
||||
"""Creates java library providers of type `JavaLibraryInfo` and `JavaPackagingInfo`.
|
||||
|
||||
Args:
|
||||
library_output: optional JavaClasspathEntry that represents library output
|
||||
declared_deps: declared dependencies (usually comes from `deps` field of the rule)
|
||||
exported_deps: dependencies that are exposed to dependent rules as compiling deps
|
||||
exported_provided_deps: dependencies that are are exposed to dependent rules and not be included into packaging
|
||||
runtime_deps: dependencies that are used for packaging only
|
||||
"""
|
||||
packaging_deps = declared_deps + exported_deps + runtime_deps
|
||||
shared_library_info, cxx_resource_info = create_native_providers(ctx.actions, ctx.label, packaging_deps)
|
||||
|
||||
output_for_classpath_macro = library_output.abi if (library_output and library_output.abi.owner != None) else ctx.actions.write("dummy_output_for_classpath_macro.txt", "Unused")
|
||||
java_packaging_dep = create_java_packaging_dep(ctx, library_output.full_library if library_output else None, output_for_classpath_macro, needs_desugar, desugar_classpath, is_prebuilt_jar)
|
||||
|
||||
java_packaging_info = get_java_packaging_info(
|
||||
ctx,
|
||||
raw_deps = packaging_deps,
|
||||
java_packaging_dep = java_packaging_dep,
|
||||
)
|
||||
|
||||
return (
|
||||
JavaLibraryInfo(
|
||||
compiling_deps = derive_compiling_deps(ctx.actions, library_output, exported_deps + exported_provided_deps),
|
||||
library_output = library_output,
|
||||
output_for_classpath_macro = output_for_classpath_macro,
|
||||
),
|
||||
java_packaging_info,
|
||||
shared_library_info,
|
||||
cxx_resource_info,
|
||||
)
|
||||
|
||||
def create_template_info(packaging_info: JavaPackagingInfo.type, first_order_classpath_libs: ["artifact"]) -> TemplatePlaceholderInfo.type:
|
||||
return TemplatePlaceholderInfo(keyed_variables = {
|
||||
"classpath": cmd_args(packaging_info.packaging_deps.project_as_args("full_jar_args"), delimiter = get_path_separator()) if packaging_info.packaging_deps else cmd_args(),
|
||||
"classpath_including_targets_with_no_output": cmd_args(packaging_info.packaging_deps.project_as_args("args_for_classpath_macro"), delimiter = get_path_separator()),
|
||||
"first_order_classpath": cmd_args(first_order_classpath_libs, delimiter = get_path_separator()),
|
||||
})
|
||||
|
||||
def create_java_library_providers(
|
||||
ctx: "context",
|
||||
library_output: [JavaClasspathEntry.type, None],
|
||||
declared_deps: ["dependency"] = [],
|
||||
exported_deps: ["dependency"] = [],
|
||||
provided_deps: ["dependency"] = [],
|
||||
exported_provided_deps: ["dependency"] = [],
|
||||
runtime_deps: ["dependency"] = [],
|
||||
needs_desugar: bool.type = False,
|
||||
is_prebuilt_jar: bool.type = False,
|
||||
generated_sources: ["artifact"] = [],
|
||||
annotation_jars_dir: ["artifact", None] = None) -> (JavaLibraryInfo.type, JavaPackagingInfo.type, SharedLibraryInfo.type, ResourceInfo.type, TemplatePlaceholderInfo.type, JavaLibraryIntellijInfo.type):
|
||||
first_order_classpath_deps = filter(None, [x.get(JavaLibraryInfo) for x in declared_deps + exported_deps + runtime_deps])
|
||||
first_order_classpath_libs = [dep.output_for_classpath_macro for dep in first_order_classpath_deps]
|
||||
|
||||
compiling_deps = derive_compiling_deps(ctx.actions, None, declared_deps + exported_deps + provided_deps + exported_provided_deps)
|
||||
compiling_classpath = [dep.full_library for dep in (list(compiling_deps.traverse()) if compiling_deps else [])]
|
||||
desugar_classpath = compiling_classpath if needs_desugar else []
|
||||
|
||||
library_info, packaging_info, shared_library_info, cxx_resource_info = _create_non_template_providers(
|
||||
ctx,
|
||||
library_output = library_output,
|
||||
declared_deps = declared_deps,
|
||||
exported_deps = exported_deps,
|
||||
exported_provided_deps = exported_provided_deps,
|
||||
runtime_deps = runtime_deps,
|
||||
needs_desugar = needs_desugar,
|
||||
desugar_classpath = desugar_classpath,
|
||||
is_prebuilt_jar = is_prebuilt_jar,
|
||||
)
|
||||
|
||||
first_order_libs = first_order_classpath_libs + [library_info.library_output.full_library] if library_info.library_output else first_order_classpath_libs
|
||||
template_info = create_template_info(packaging_info, first_order_libs)
|
||||
|
||||
intellij_info = JavaLibraryIntellijInfo(
|
||||
compiling_classpath = compiling_classpath,
|
||||
generated_sources = generated_sources,
|
||||
annotation_jars_dir = annotation_jars_dir,
|
||||
)
|
||||
|
||||
return (library_info, packaging_info, shared_library_info, cxx_resource_info, template_info, intellij_info)
|
||||
61
vendor/cxx/tools/buck/prelude/java/java_resources.bzl
vendored
Normal file
61
vendor/cxx/tools/buck/prelude/java/java_resources.bzl
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
load("@prelude//:paths.bzl", "paths")
|
||||
|
||||
def get_resources_map(
|
||||
java_toolchain: "JavaToolchainInfo",
|
||||
package: str.type,
|
||||
resources: ["artifact"],
|
||||
resources_root: [str.type, None]) -> {str.type: "artifact"}:
|
||||
# As in v1, root the resource root via the current package.
|
||||
if resources_root != None:
|
||||
resources_root = paths.normalize(paths.join(package, resources_root))
|
||||
|
||||
java_package_finder = _get_java_package_finder(java_toolchain)
|
||||
|
||||
resources_to_copy = {}
|
||||
for resource in resources:
|
||||
# Create the full resource path.
|
||||
full_resource = paths.join(
|
||||
resource.owner.package if resource.owner else package,
|
||||
resource.short_path,
|
||||
)
|
||||
|
||||
# As in v1 (https://fburl.com/code/j2vwny56, https://fburl.com/code/9era0xpz),
|
||||
# if this resource starts with the resource root, relativize and insert it as
|
||||
# is.
|
||||
if resources_root != None and paths.starts_with(full_resource, resources_root):
|
||||
resource_name = paths.relativize(
|
||||
full_resource,
|
||||
resources_root,
|
||||
)
|
||||
else:
|
||||
resource_name = java_package_finder(full_resource)
|
||||
resources_to_copy[resource_name] = resource
|
||||
return resources_to_copy
|
||||
|
||||
def _get_java_package_finder(java_toolchain: "JavaToolchainInfo") -> "function":
|
||||
src_root_prefixes = java_toolchain.src_root_prefixes
|
||||
src_root_elements = java_toolchain.src_root_elements
|
||||
|
||||
def finder(path):
|
||||
for prefix in src_root_prefixes:
|
||||
if path.startswith(prefix):
|
||||
return paths.relativize(
|
||||
path,
|
||||
prefix,
|
||||
)
|
||||
parts = path.split("/")
|
||||
for i in range(len(parts) - 1, -1, -1):
|
||||
part = parts[i]
|
||||
if part in src_root_elements:
|
||||
return "/".join(parts[i + 1:])
|
||||
|
||||
return path
|
||||
|
||||
return finder
|
||||
136
vendor/cxx/tools/buck/prelude/java/java_test.bzl
vendored
Normal file
136
vendor/cxx/tools/buck/prelude/java/java_test.bzl
vendored
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
load("@prelude//java:java_library.bzl", "build_java_library")
|
||||
load("@prelude//java:java_providers.bzl", "get_all_java_packaging_deps_tset")
|
||||
load("@prelude//java:java_toolchain.bzl", "JavaTestToolchainInfo", "JavaToolchainInfo")
|
||||
load("@prelude//java/utils:java_utils.bzl", "get_path_separator")
|
||||
load("@prelude//linking:shared_libraries.bzl", "SharedLibraryInfo", "merge_shared_libraries", "traverse_shared_library_info")
|
||||
load("@prelude//test/inject_test_run_info.bzl", "inject_test_run_info")
|
||||
|
||||
def java_test_impl(ctx: "context") -> ["provider"]:
|
||||
java_providers = build_java_library(ctx, ctx.attrs.srcs)
|
||||
external_runner_test_info = build_junit_test(ctx, java_providers.java_library_info, java_providers.java_packaging_info)
|
||||
|
||||
return inject_test_run_info(ctx, external_runner_test_info) + [
|
||||
java_providers.java_library_info,
|
||||
java_providers.java_packaging_info,
|
||||
java_providers.template_placeholder_info,
|
||||
java_providers.default_info,
|
||||
]
|
||||
|
||||
def build_junit_test(
|
||||
ctx: "context",
|
||||
tests_java_library_info: "JavaLibraryInfo",
|
||||
tests_java_packaging_info: "JavaPackagingInfo",
|
||||
extra_cmds: list.type = [],
|
||||
extra_classpath_entries: ["artifact"] = []) -> ExternalRunnerTestInfo.type:
|
||||
java_test_toolchain = ctx.attrs._java_test_toolchain[JavaTestToolchainInfo]
|
||||
|
||||
cmd = [ctx.attrs._java_toolchain[JavaToolchainInfo].java_for_tests] + extra_cmds + ctx.attrs.vm_args
|
||||
classpath = []
|
||||
|
||||
if java_test_toolchain.use_java_custom_class_loader:
|
||||
cmd.append("-Djava.system.class.loader=" + java_test_toolchain.java_custom_class_loader_class)
|
||||
cmd.extend(java_test_toolchain.java_custom_class_loader_vm_args)
|
||||
classpath.append(java_test_toolchain.java_custom_class_loader_library_jar)
|
||||
|
||||
classpath.extend(
|
||||
[java_test_toolchain.test_runner_library_jar] +
|
||||
[
|
||||
get_all_java_packaging_deps_tset(ctx, java_packaging_infos = [tests_java_packaging_info])
|
||||
.project_as_args("full_jar_args", ordering = "bfs"),
|
||||
] +
|
||||
extra_classpath_entries,
|
||||
)
|
||||
|
||||
labels = ctx.attrs.labels or []
|
||||
run_from_cell_root = "buck2_run_from_cell_root" in labels
|
||||
uses_java8 = "run_with_java8" in labels
|
||||
|
||||
classpath_args = cmd_args()
|
||||
if run_from_cell_root:
|
||||
classpath_args.relative_to(ctx.label.cell_root)
|
||||
|
||||
if uses_java8:
|
||||
# Java 8 does not support using argfiles, and these tests can have huge classpaths so we need another
|
||||
# mechanism to write the classpath to a file.
|
||||
# We add "FileClassPathRunner" to the classpath, and then write a line-separated classpath file which we pass
|
||||
# to the "FileClassPathRunner" as a system variable. The "FileClassPathRunner" then loads all the jars
|
||||
# from that file onto the classpath, and delegates running the test to the junit test runner.
|
||||
cmd.extend(["-classpath", cmd_args(java_test_toolchain.test_runner_library_jar)])
|
||||
classpath_args.add(cmd_args(classpath))
|
||||
classpath_args_file = ctx.actions.write("classpath_args_file", classpath_args)
|
||||
cmd.append(cmd_args(classpath_args_file, format = "-Dbuck.classpath_file={}").hidden(classpath_args))
|
||||
else:
|
||||
# Java 9+ supports argfiles, so just write the classpath to an argsfile. "FileClassPathRunner" will delegate
|
||||
# immediately to the junit test runner.
|
||||
classpath_args.add("-classpath")
|
||||
classpath_args.add(cmd_args(classpath, delimiter = get_path_separator()))
|
||||
classpath_args_file = ctx.actions.write("classpath_args_file", classpath_args)
|
||||
cmd.append(cmd_args(classpath_args_file, format = "@{}").hidden(classpath_args))
|
||||
|
||||
if (ctx.attrs.test_type == "junit5"):
|
||||
cmd.extend(java_test_toolchain.junit5_test_runner_main_class_args)
|
||||
elif (ctx.attrs.test_type == "testng"):
|
||||
cmd.extend(java_test_toolchain.testng_test_runner_main_class_args)
|
||||
else:
|
||||
cmd.extend(java_test_toolchain.junit_test_runner_main_class_args)
|
||||
|
||||
if ctx.attrs.test_case_timeout_ms:
|
||||
cmd.extend(["--default_test_timeout", ctx.attrs.test_case_timeout_ms])
|
||||
|
||||
class_names = ctx.actions.declare_output("class_names")
|
||||
list_class_names_cmd = cmd_args([
|
||||
java_test_toolchain.list_class_names[RunInfo],
|
||||
"--jar",
|
||||
tests_java_library_info.library_output.full_library,
|
||||
"--output",
|
||||
class_names.as_output(),
|
||||
])
|
||||
ctx.actions.run(list_class_names_cmd, category = "list_class_names")
|
||||
|
||||
cmd.extend(["--test-class-names-file", class_names])
|
||||
|
||||
native_libs_env = _get_native_libs_env(ctx)
|
||||
env = {}
|
||||
for d in [ctx.attrs.env, native_libs_env]:
|
||||
for key, value in d.items():
|
||||
if key in env:
|
||||
fail("Duplicate key for java_test env: '{}'".format(key))
|
||||
env[key] = value
|
||||
|
||||
test_info = ExternalRunnerTestInfo(
|
||||
type = "junit",
|
||||
command = cmd,
|
||||
env = env,
|
||||
labels = ctx.attrs.labels,
|
||||
contacts = ctx.attrs.contacts,
|
||||
run_from_project_root = not run_from_cell_root,
|
||||
use_project_relative_paths = not run_from_cell_root,
|
||||
)
|
||||
return test_info
|
||||
|
||||
def _get_native_libs_env(ctx: "context") -> dict.type:
|
||||
if not ctx.attrs.use_cxx_libraries:
|
||||
return {}
|
||||
|
||||
if ctx.attrs.cxx_library_whitelist:
|
||||
shared_library_infos = filter(None, [x.get(SharedLibraryInfo) for x in ctx.attrs.cxx_library_whitelist])
|
||||
else:
|
||||
shared_library_infos = filter(None, [x.get(SharedLibraryInfo) for x in ctx.attrs.deps])
|
||||
|
||||
shared_library_info = merge_shared_libraries(
|
||||
ctx.actions,
|
||||
deps = shared_library_infos,
|
||||
)
|
||||
|
||||
native_linkables = traverse_shared_library_info(shared_library_info)
|
||||
cxx_library_symlink_tree_dict = {so_name: shared_lib.lib.output for so_name, shared_lib in native_linkables.items()}
|
||||
cxx_library_symlink_tree = ctx.actions.symlinked_dir("cxx_library_symlink_tree", cxx_library_symlink_tree_dict)
|
||||
|
||||
return {"BUCK_LD_SYMLINK_TREE": cxx_library_symlink_tree}
|
||||
73
vendor/cxx/tools/buck/prelude/java/java_toolchain.bzl
vendored
Normal file
73
vendor/cxx/tools/buck/prelude/java/java_toolchain.bzl
vendored
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
AbiGenerationMode = enum("class", "source", "source_only")
|
||||
|
||||
JavacProtocol = enum("classic", "javacd")
|
||||
|
||||
JavaPlatformInfo = provider(
|
||||
"Java platform info",
|
||||
fields = [
|
||||
"name",
|
||||
],
|
||||
)
|
||||
|
||||
JavaToolchainInfo = provider(
|
||||
"Java toolchain info",
|
||||
fields = [
|
||||
"abi_generation_mode",
|
||||
"ast_dumper",
|
||||
"bootclasspath_7",
|
||||
"bootclasspath_8",
|
||||
"class_abi_generator",
|
||||
"compile_and_package",
|
||||
"dep_files",
|
||||
"fallback_javac",
|
||||
"fat_jar",
|
||||
"fat_jar_main_class_lib",
|
||||
"jar",
|
||||
"jar_builder",
|
||||
"java",
|
||||
"java_for_tests",
|
||||
"javac",
|
||||
"javac_protocol",
|
||||
"src_dir_helper",
|
||||
"source_level",
|
||||
"src_root_elements",
|
||||
"src_root_prefixes",
|
||||
"target_level",
|
||||
"used_classes_to_dep_file",
|
||||
"zip_scrubber",
|
||||
"is_bootstrap_toolchain",
|
||||
],
|
||||
)
|
||||
|
||||
JavaTestToolchainInfo = provider(
|
||||
"Java test toolchain info",
|
||||
fields = [
|
||||
"java_custom_class_loader_class",
|
||||
"java_custom_class_loader_library_jar",
|
||||
"java_custom_class_loader_vm_args",
|
||||
"test_runner_library_jar",
|
||||
"junit_test_runner_main_class_args",
|
||||
"junit5_test_runner_main_class_args",
|
||||
"testng_test_runner_main_class_args",
|
||||
"list_class_names",
|
||||
"use_java_custom_class_loader",
|
||||
],
|
||||
)
|
||||
|
||||
# prebuilt_jar needs so little of the Java toolchain that it's worth
|
||||
# giving it its own to reduce the occurrence of cycles as we add
|
||||
# more Java- and Kotlin-built tools to the Java and Kotlin toolchains
|
||||
PrebuiltJarToolchainInfo = provider(
|
||||
"prebuilt_jar toolchain info",
|
||||
fields = [
|
||||
"class_abi_generator",
|
||||
"is_bootstrap_toolchain",
|
||||
],
|
||||
)
|
||||
231
vendor/cxx/tools/buck/prelude/java/javacd_jar_creator.bzl
vendored
Normal file
231
vendor/cxx/tools/buck/prelude/java/javacd_jar_creator.bzl
vendored
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
load(
|
||||
"@prelude//java:java_providers.bzl",
|
||||
"make_compile_outputs",
|
||||
)
|
||||
load("@prelude//java:java_resources.bzl", "get_resources_map")
|
||||
load("@prelude//java:java_toolchain.bzl", "AbiGenerationMode")
|
||||
load(
|
||||
"@prelude//jvm:cd_jar_creator_util.bzl",
|
||||
"OutputPaths",
|
||||
"TargetType",
|
||||
"add_java_7_8_bootclasspath",
|
||||
"add_output_paths_to_cmd_args",
|
||||
"base_qualified_name",
|
||||
"declare_prefixed_output",
|
||||
"define_output_paths",
|
||||
"encode_base_jar_command",
|
||||
"encode_jar_params",
|
||||
"encode_path",
|
||||
"generate_abi_jars",
|
||||
"get_abi_generation_mode",
|
||||
"prepare_final_jar",
|
||||
)
|
||||
|
||||
def create_jar_artifact_javacd(
|
||||
actions: "actions",
|
||||
actions_prefix: str.type,
|
||||
abi_generation_mode: [AbiGenerationMode.type, None],
|
||||
java_toolchain: "JavaToolchainInfo",
|
||||
label,
|
||||
output: ["artifact", None],
|
||||
javac_tool: ["", None],
|
||||
srcs: ["artifact"],
|
||||
remove_classes: [str.type],
|
||||
resources: ["artifact"],
|
||||
resources_root: [str.type, None],
|
||||
manifest_file: ["artifact", None],
|
||||
ap_params: ["AnnotationProcessorParams"],
|
||||
plugin_params: ["PluginParams", None],
|
||||
source_level: int.type,
|
||||
target_level: int.type,
|
||||
deps: ["dependency"],
|
||||
required_for_source_only_abi: bool.type,
|
||||
source_only_abi_deps: ["dependency"],
|
||||
extra_arguments: ["string"],
|
||||
additional_classpath_entries: ["artifact"],
|
||||
additional_compiled_srcs: ["artifact", None],
|
||||
bootclasspath_entries: ["artifact"],
|
||||
is_building_android_binary: bool.type) -> "JavaCompileOutputs":
|
||||
if javac_tool != None:
|
||||
# TODO(cjhopman): We can probably handle this better. I think we should be able to just use the non-javacd path.
|
||||
fail("cannot set explicit javac on library when using javacd")
|
||||
|
||||
resources_map = get_resources_map(java_toolchain, label.package, resources, resources_root)
|
||||
|
||||
# TODO(cjhopman): Handle manifest file.
|
||||
_ = manifest_file
|
||||
_ = AbiGenerationMode("class")
|
||||
|
||||
bootclasspath_entries = add_java_7_8_bootclasspath(target_level, bootclasspath_entries, java_toolchain)
|
||||
abi_generation_mode = get_abi_generation_mode(abi_generation_mode, java_toolchain, srcs, ap_params)
|
||||
|
||||
# now prefix is just used for categories and prefixes of path segments, so we want it either non-empty or w/ a trailing underscore
|
||||
if actions_prefix:
|
||||
actions_prefix += "_"
|
||||
|
||||
output_paths = define_output_paths(actions, actions_prefix)
|
||||
path_to_class_hashes_out = declare_prefixed_output(actions, actions_prefix, "classes.txt")
|
||||
|
||||
def encode_library_command(output_paths: OutputPaths.type, path_to_class_hashes: "artifact") -> struct.type:
|
||||
target_type = TargetType("library")
|
||||
|
||||
base_jar_command = encode_base_jar_command(
|
||||
target_type,
|
||||
output_paths,
|
||||
remove_classes,
|
||||
label,
|
||||
actions,
|
||||
deps,
|
||||
additional_classpath_entries,
|
||||
source_only_abi_deps,
|
||||
bootclasspath_entries,
|
||||
source_level,
|
||||
target_level,
|
||||
abi_generation_mode,
|
||||
srcs,
|
||||
resources_map,
|
||||
ap_params,
|
||||
plugin_params,
|
||||
extra_arguments,
|
||||
track_class_usage = True,
|
||||
build_target_value_extra_params = None,
|
||||
)
|
||||
|
||||
return struct(
|
||||
baseCommandParams = struct(
|
||||
withDownwardApi = True,
|
||||
spoolMode = "DIRECT_TO_JAR",
|
||||
),
|
||||
libraryJarCommand = struct(
|
||||
baseJarCommand = base_jar_command,
|
||||
libraryJarBaseCommand = struct(
|
||||
pathToClasses = encode_path(output_paths.jar.as_output()),
|
||||
rootOutput = encode_path(output_paths.jar_parent.as_output()),
|
||||
pathToClassHashes = encode_path(path_to_class_hashes.as_output()),
|
||||
annotationsPath = encode_path(output_paths.annotations.as_output()),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
def encode_abi_command(output_paths: OutputPaths.type, target_type: TargetType.type) -> struct.type:
|
||||
base_jar_command = encode_base_jar_command(
|
||||
target_type,
|
||||
output_paths,
|
||||
remove_classes,
|
||||
label,
|
||||
actions,
|
||||
deps,
|
||||
additional_classpath_entries,
|
||||
source_only_abi_deps,
|
||||
bootclasspath_entries,
|
||||
source_level,
|
||||
target_level,
|
||||
abi_generation_mode,
|
||||
srcs,
|
||||
resources_map,
|
||||
ap_params,
|
||||
plugin_params,
|
||||
extra_arguments,
|
||||
track_class_usage = True,
|
||||
build_target_value_extra_params = None,
|
||||
)
|
||||
abi_params = encode_jar_params(remove_classes, output_paths)
|
||||
|
||||
abi_command = struct(
|
||||
baseJarCommand = base_jar_command,
|
||||
abiJarParameters = abi_params,
|
||||
)
|
||||
|
||||
return struct(
|
||||
baseCommandParams = struct(
|
||||
withDownwardApi = True,
|
||||
spoolMode = "DIRECT_TO_JAR",
|
||||
),
|
||||
abiJarCommand = abi_command,
|
||||
)
|
||||
|
||||
# buildifier: disable=uninitialized
|
||||
def define_javacd_action(actions_prefix: str.type, encoded_command: struct.type, qualified_name: str.type, output_paths: OutputPaths.type, path_to_class_hashes: ["artifact", None]):
|
||||
proto = declare_prefixed_output(actions, actions_prefix, "jar_command.proto.json")
|
||||
|
||||
classpath_jars_tag = actions.artifact_tag()
|
||||
|
||||
proto_with_inputs = classpath_jars_tag.tag_inputs(actions.write_json(proto, encoded_command, with_inputs = True))
|
||||
|
||||
cmd = cmd_args([
|
||||
java_toolchain.javac,
|
||||
"--action-id",
|
||||
qualified_name,
|
||||
"--command-file",
|
||||
proto_with_inputs,
|
||||
])
|
||||
cmd = add_output_paths_to_cmd_args(cmd, output_paths, path_to_class_hashes)
|
||||
|
||||
# TODO(cjhopman): make sure this works both locally and remote.
|
||||
event_pipe_out = declare_prefixed_output(actions, actions_prefix, "events.data")
|
||||
|
||||
dep_files = {}
|
||||
if srcs and java_toolchain.dep_files == "simple":
|
||||
dep_files["classpath_jars"] = classpath_jars_tag
|
||||
used_classes_json = output_paths.jar_parent.project("used-classes.json")
|
||||
dep_file = declare_prefixed_output(actions, actions_prefix, "dep_file.txt")
|
||||
|
||||
# TODO(T134944772) We won't need this once we can do tag_artifacts on a JSON projection,
|
||||
# but for now we have to tag all the inputs on the .proto definition, and so we need to
|
||||
# tell the dep file to include all the inputs that the compiler won't report.
|
||||
srcs_and_resources = actions.write(
|
||||
declare_prefixed_output(actions, actions_prefix, "srcs_and_resources"),
|
||||
srcs + resources_map.values(),
|
||||
)
|
||||
|
||||
cmd = cmd_args([
|
||||
java_toolchain.used_classes_to_dep_file[RunInfo],
|
||||
srcs_and_resources,
|
||||
used_classes_json.as_output(),
|
||||
classpath_jars_tag.tag_artifacts(dep_file.as_output()),
|
||||
cmd,
|
||||
])
|
||||
|
||||
actions.run(
|
||||
cmd,
|
||||
env = {
|
||||
"BUCK_EVENT_PIPE": event_pipe_out.as_output(),
|
||||
"JAVACD_ABSOLUTE_PATHS_ARE_RELATIVE_TO_CWD": "1",
|
||||
},
|
||||
category = "{}javacd_jar".format(actions_prefix),
|
||||
dep_files = dep_files,
|
||||
)
|
||||
|
||||
command = encode_library_command(output_paths, path_to_class_hashes_out)
|
||||
define_javacd_action(actions_prefix, command, base_qualified_name(label), output_paths, path_to_class_hashes_out)
|
||||
final_jar = prepare_final_jar(actions, actions_prefix, output, output_paths, additional_compiled_srcs, java_toolchain.jar_builder)
|
||||
class_abi, source_abi, source_only_abi, classpath_abi = generate_abi_jars(
|
||||
actions,
|
||||
actions_prefix,
|
||||
label,
|
||||
abi_generation_mode,
|
||||
additional_compiled_srcs,
|
||||
is_building_android_binary,
|
||||
java_toolchain.class_abi_generator,
|
||||
final_jar,
|
||||
encode_abi_command,
|
||||
define_javacd_action,
|
||||
)
|
||||
|
||||
result = make_compile_outputs(
|
||||
full_library = final_jar,
|
||||
class_abi = class_abi,
|
||||
source_abi = source_abi,
|
||||
source_only_abi = source_only_abi,
|
||||
classpath_abi = classpath_abi,
|
||||
required_for_source_only_abi = required_for_source_only_abi,
|
||||
annotation_processor_output = output_paths.annotations,
|
||||
)
|
||||
return result
|
||||
18
vendor/cxx/tools/buck/prelude/java/keystore.bzl
vendored
Normal file
18
vendor/cxx/tools/buck/prelude/java/keystore.bzl
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
load("@prelude//java:java_providers.bzl", "KeystoreInfo")
|
||||
|
||||
def keystore_impl(ctx: "context") -> ["provider"]:
|
||||
sub_targets = {}
|
||||
sub_targets["keystore"] = [DefaultInfo(default_outputs = [ctx.attrs.store])]
|
||||
sub_targets["properties"] = [DefaultInfo(default_outputs = [ctx.attrs.properties])]
|
||||
|
||||
return [
|
||||
KeystoreInfo(store = ctx.attrs.store, properties = ctx.attrs.properties),
|
||||
DefaultInfo(default_outputs = [ctx.attrs.store, ctx.attrs.properties], sub_targets = sub_targets),
|
||||
]
|
||||
135
vendor/cxx/tools/buck/prelude/java/plugins/java_annotation_processor.bzl
vendored
Normal file
135
vendor/cxx/tools/buck/prelude/java/plugins/java_annotation_processor.bzl
vendored
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
load("@prelude//java:java_providers.bzl", "JavaLibraryInfo", "JavaPackagingDepTSet", "JavaPackagingInfo")
|
||||
|
||||
JavaProcessorsType = enum(
|
||||
"java_annotation_processor",
|
||||
"ksp_annotation_processor",
|
||||
"plugin",
|
||||
)
|
||||
|
||||
JavaProcessorsInfo = provider(
|
||||
"Information about java annotation processor/ java compiler plugins and their dependencies",
|
||||
fields = [
|
||||
# Type of processor
|
||||
"type", # "JavaProcessorsType"
|
||||
|
||||
# Names of processors
|
||||
"processors", # ["string"]
|
||||
|
||||
# Java dependencies exposed to dependent targets and supposed to be used during compilation.
|
||||
"deps", # ["JavaPackagingDepTSet", None]
|
||||
"affects_abi",
|
||||
"supports_source_only_abi",
|
||||
],
|
||||
)
|
||||
|
||||
AnnotationProcessorParams = record(
|
||||
affects_abi = field(bool.type),
|
||||
supports_source_only_abi = field(bool.type),
|
||||
processors = field(["string"]),
|
||||
params = field(["string"]),
|
||||
deps = field(["JavaPackagingDepTSet", None]),
|
||||
)
|
||||
|
||||
# Every transitive java annotation processors dependency has to be included into processor classpath for AP/Java Plugin run
|
||||
def derive_transitive_deps(ctx: "context", deps: ["dependency"]) -> ["JavaPackagingDepTSet", None]:
|
||||
for dep in deps:
|
||||
if not dep[JavaLibraryInfo]:
|
||||
fail("Dependency must have a type of `java_library` or `prebuilt_jar`. Deps: {}".format(deps))
|
||||
|
||||
return ctx.actions.tset(
|
||||
JavaPackagingDepTSet,
|
||||
children = [dep[JavaPackagingInfo].packaging_deps for dep in deps],
|
||||
) if deps else None
|
||||
|
||||
def create_ap_params(
|
||||
ctx: "context",
|
||||
plugins: ["dependency"],
|
||||
annotation_processors: ["string"],
|
||||
annotation_processor_params: ["string"],
|
||||
annotation_processor_deps: ["dependency"]) -> [AnnotationProcessorParams.type]:
|
||||
ap_params = []
|
||||
has_annotation_processors = bool(annotation_processors)
|
||||
|
||||
# Extend `ap_processor_deps` with java deps from `annotation_processor_deps`
|
||||
if annotation_processors or annotation_processor_params or annotation_processor_deps:
|
||||
for ap_dep in [x.get(JavaLibraryInfo) for x in annotation_processor_deps]:
|
||||
if not ap_dep:
|
||||
fail("Dependency must have a type of `java_library` or `prebuilt_jar`. Deps: {}".format(annotation_processor_deps))
|
||||
|
||||
# "legacy" annotation processors have no mechanism for indicating if they affect abi or if they support source_only
|
||||
ap_params.append(AnnotationProcessorParams(
|
||||
affects_abi = True,
|
||||
supports_source_only_abi = False,
|
||||
processors = annotation_processors,
|
||||
params = annotation_processor_params,
|
||||
# using packaging deps to have all transitive deps collected for processors classpath
|
||||
deps = derive_transitive_deps(ctx, annotation_processor_deps),
|
||||
))
|
||||
|
||||
# APs derived from `plugins` attribute
|
||||
for ap_plugin in filter(None, [x.get(JavaProcessorsInfo) for x in plugins]):
|
||||
has_annotation_processors = True
|
||||
if not ap_plugin:
|
||||
fail("Plugin must have a type of `java_annotation_processor` or `java_plugin`. Plugins: {}".format(plugins))
|
||||
if ap_plugin.type == JavaProcessorsType("java_annotation_processor"):
|
||||
ap_params.append(AnnotationProcessorParams(
|
||||
affects_abi = ap_plugin.affects_abi,
|
||||
supports_source_only_abi = ap_plugin.supports_source_only_abi,
|
||||
processors = ap_plugin.processors,
|
||||
params = [],
|
||||
deps = ap_plugin.deps,
|
||||
))
|
||||
|
||||
return ap_params if has_annotation_processors else []
|
||||
|
||||
def create_ksp_ap_params(ctx: "context", plugins: ["dependency"]) -> [AnnotationProcessorParams.type, None]:
|
||||
ap_processors = []
|
||||
ap_processor_deps = []
|
||||
|
||||
# APs derived from `plugins` attribute
|
||||
for ap_plugin in filter(None, [x.get(JavaProcessorsInfo) for x in plugins]):
|
||||
if not ap_plugin:
|
||||
fail("Plugin must have a type of `java_annotation_processor` or `java_plugin`. Plugins: {}".format(plugins))
|
||||
if ap_plugin.type == JavaProcessorsType("ksp_annotation_processor"):
|
||||
ap_processors += ap_plugin.processors
|
||||
if ap_plugin.deps:
|
||||
ap_processor_deps.append(ap_plugin.deps)
|
||||
|
||||
if not ap_processors:
|
||||
return None
|
||||
|
||||
return AnnotationProcessorParams(
|
||||
processors = dedupe(ap_processors),
|
||||
params = [],
|
||||
deps = ctx.actions.tset(JavaPackagingDepTSet, children = ap_processor_deps) if ap_processor_deps else None,
|
||||
affects_abi = True,
|
||||
supports_source_only_abi = False,
|
||||
)
|
||||
|
||||
def _get_processor_type(processor_class: str.type) -> JavaProcessorsType.type:
|
||||
if processor_class.startswith("KSP:"):
|
||||
return JavaProcessorsType("ksp_annotation_processor")
|
||||
|
||||
return JavaProcessorsType("java_annotation_processor")
|
||||
|
||||
def java_annotation_processor_impl(ctx: "context") -> ["provider"]:
|
||||
if ctx.attrs._build_only_native_code:
|
||||
return [DefaultInfo()]
|
||||
|
||||
return [
|
||||
JavaProcessorsInfo(
|
||||
deps = derive_transitive_deps(ctx, ctx.attrs.deps),
|
||||
processors = [ctx.attrs.processor_class],
|
||||
type = _get_processor_type(ctx.attrs.processor_class),
|
||||
affects_abi = not ctx.attrs.does_not_affect_abi,
|
||||
supports_source_only_abi = ctx.attrs.supports_abi_generation_from_source,
|
||||
),
|
||||
DefaultInfo(default_outputs = []),
|
||||
]
|
||||
57
vendor/cxx/tools/buck/prelude/java/plugins/java_plugin.bzl
vendored
Normal file
57
vendor/cxx/tools/buck/prelude/java/plugins/java_plugin.bzl
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
load("@prelude//java:java_providers.bzl", "JavaPackagingDepTSet")
|
||||
load(
|
||||
"@prelude//java/plugins:java_annotation_processor.bzl",
|
||||
"JavaProcessorsInfo",
|
||||
"JavaProcessorsType",
|
||||
"derive_transitive_deps",
|
||||
)
|
||||
|
||||
PluginParams = record(
|
||||
processors = field(["string"]),
|
||||
args = field({
|
||||
str.type: "cmd_args",
|
||||
}),
|
||||
deps = field(["JavaPackagingDepTSet", None]),
|
||||
)
|
||||
|
||||
def create_plugin_params(ctx: "context", plugins: ["dependency"]) -> [PluginParams.type, None]:
|
||||
processors = []
|
||||
plugin_deps = []
|
||||
|
||||
# Compiler plugin derived from `plugins` attribute
|
||||
for plugin in filter(None, [x.get(JavaProcessorsInfo) for x in plugins]):
|
||||
if plugin.type == JavaProcessorsType("plugin"):
|
||||
if len(plugin.processors) > 1:
|
||||
fail("Only 1 java compiler plugin is expected. But received: {}".format(plugin.processors))
|
||||
processors.append(plugin.processors[0])
|
||||
if plugin.deps:
|
||||
plugin_deps.append(plugin.deps)
|
||||
|
||||
if not processors:
|
||||
return None
|
||||
|
||||
return PluginParams(
|
||||
processors = dedupe(processors),
|
||||
deps = ctx.actions.tset(JavaPackagingDepTSet, children = plugin_deps) if plugin_deps else None,
|
||||
args = {},
|
||||
)
|
||||
|
||||
def java_plugin_impl(ctx: "context") -> ["provider"]:
|
||||
if ctx.attrs._build_only_native_code:
|
||||
return [DefaultInfo()]
|
||||
|
||||
return [
|
||||
JavaProcessorsInfo(
|
||||
deps = derive_transitive_deps(ctx, ctx.attrs.deps),
|
||||
processors = [ctx.attrs.plugin_name],
|
||||
type = JavaProcessorsType("plugin"),
|
||||
),
|
||||
DefaultInfo(default_outputs = []),
|
||||
]
|
||||
79
vendor/cxx/tools/buck/prelude/java/prebuilt_jar.bzl
vendored
Normal file
79
vendor/cxx/tools/buck/prelude/java/prebuilt_jar.bzl
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
load("@prelude//android:android_providers.bzl", "merge_android_packageable_info")
|
||||
load(
|
||||
":java_providers.bzl",
|
||||
"JavaClasspathEntry",
|
||||
"create_abi",
|
||||
"create_java_library_providers",
|
||||
)
|
||||
load(":java_toolchain.bzl", "PrebuiltJarToolchainInfo")
|
||||
|
||||
def prebuilt_jar_impl(ctx: "context") -> ["provider"]:
|
||||
"""
|
||||
prebuilt_jar() rule implementation
|
||||
|
||||
Args:
|
||||
ctx: rule analysis context
|
||||
Returns:
|
||||
list of created providers
|
||||
"""
|
||||
|
||||
expected_extension = ".jar"
|
||||
binary_jar = ctx.attrs.binary_jar
|
||||
extension = binary_jar.extension
|
||||
if extension != expected_extension:
|
||||
fail("Extension of the binary_jar attribute has to be equal to '{}' but '{}' has an extension '{}'".format(
|
||||
expected_extension,
|
||||
binary_jar,
|
||||
extension,
|
||||
))
|
||||
|
||||
output = ctx.actions.declare_output("symlink/{}".format(binary_jar.short_path))
|
||||
ctx.actions.symlink_file(output, binary_jar)
|
||||
|
||||
abi = None
|
||||
if ctx.attrs.generate_abi:
|
||||
prebuilt_jar_toolchain = ctx.attrs._prebuilt_jar_toolchain[PrebuiltJarToolchainInfo]
|
||||
if not prebuilt_jar_toolchain.is_bootstrap_toolchain:
|
||||
abi = create_abi(ctx.actions, prebuilt_jar_toolchain.class_abi_generator, output)
|
||||
|
||||
library_output_classpath_entry = JavaClasspathEntry(
|
||||
full_library = output,
|
||||
abi = abi or output,
|
||||
required_for_source_only_abi = ctx.attrs.required_for_source_only_abi,
|
||||
)
|
||||
|
||||
java_library_info, java_packaging_info, shared_library_info, cxx_resource_info, template_placeholder_info, _ = create_java_library_providers(
|
||||
ctx,
|
||||
library_output = library_output_classpath_entry,
|
||||
declared_deps = ctx.attrs.deps,
|
||||
exported_deps = ctx.attrs.deps,
|
||||
needs_desugar = True,
|
||||
is_prebuilt_jar = True,
|
||||
)
|
||||
|
||||
# TODO(T107163344) this shouldn't be in prebuilt_jar itself, use overlays to remove it.
|
||||
android_packageable_info = merge_android_packageable_info(ctx.label, ctx.actions, ctx.attrs.deps)
|
||||
|
||||
sub_targets = {}
|
||||
sub_targets["abi"] = [
|
||||
java_library_info,
|
||||
template_placeholder_info,
|
||||
DefaultInfo(default_outputs = [library_output_classpath_entry.abi]),
|
||||
]
|
||||
|
||||
return [
|
||||
java_library_info,
|
||||
java_packaging_info,
|
||||
shared_library_info,
|
||||
cxx_resource_info,
|
||||
android_packageable_info,
|
||||
template_placeholder_info,
|
||||
DefaultInfo(default_outputs = [output], sub_targets = sub_targets),
|
||||
]
|
||||
7
vendor/cxx/tools/buck/prelude/java/tools/TARGETS.v2
vendored
Normal file
7
vendor/cxx/tools/buck/prelude/java/tools/TARGETS.v2
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
prelude = native
|
||||
|
||||
prelude.python_bootstrap_binary(
|
||||
name = "used_classes_to_dep_file",
|
||||
main = "used_classes_to_dep_file.py",
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
49
vendor/cxx/tools/buck/prelude/java/tools/used_classes_to_dep_file.py
vendored
Normal file
49
vendor/cxx/tools/buck/prelude/java/tools/used_classes_to_dep_file.py
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env fbpython
|
||||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
# pyre-unsafe
|
||||
|
||||
import json
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def rewrite_dep_file(always_used_files_path, used_classes_path, dst_path):
|
||||
"""
|
||||
Convert a used_classes.json to a depfile suitable for use by Buck2. The files we
|
||||
rewrite are JSON where the keys are the jars that were used.
|
||||
"""
|
||||
shutil.copyfile(always_used_files_path, dst_path)
|
||||
|
||||
with open(used_classes_path) as f:
|
||||
used_classes_body = f.read()
|
||||
|
||||
used_classes_map = json.loads(used_classes_body)
|
||||
|
||||
with open(dst_path, "a") as f:
|
||||
f.write("\n")
|
||||
f.write("\n".join(used_classes_map.keys()))
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
First argument is a file containing a list of files that should be put directly
|
||||
into the dep file.
|
||||
Second argument is a "used_classes.json" file.
|
||||
Third argument is where the dep file should be written.
|
||||
The command follows the third argument.
|
||||
"""
|
||||
ret = subprocess.call(sys.argv[4:])
|
||||
if ret == 0:
|
||||
rewrite_dep_file(sys.argv[1], sys.argv[2], sys.argv[3])
|
||||
sys.exit(ret)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
94
vendor/cxx/tools/buck/prelude/java/utils/java_utils.bzl
vendored
Normal file
94
vendor/cxx/tools/buck/prelude/java/utils/java_utils.bzl
vendored
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under both the MIT license found in the
|
||||
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
||||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
||||
# of this source tree.
|
||||
|
||||
load("@prelude//java:java_toolchain.bzl", "AbiGenerationMode", "JavaToolchainInfo")
|
||||
load("@prelude//utils:utils.bzl", "expect")
|
||||
|
||||
def get_path_separator() -> "string":
|
||||
# TODO: msemko : replace with system-dependent path-separator character
|
||||
# On UNIX systems, this character is ':'; on Microsoft Windows systems it is ';'.
|
||||
return ":"
|
||||
|
||||
def derive_javac(javac_attribute: [str.type, "dependency", "artifact"]) -> [str.type, "RunInfo", "artifact"]:
|
||||
javac_attr_type = type(javac_attribute)
|
||||
if javac_attr_type == "dependency":
|
||||
javac_run_info = javac_attribute.get(RunInfo)
|
||||
if javac_run_info:
|
||||
return javac_run_info
|
||||
outputs = javac_attribute[DefaultInfo].default_outputs
|
||||
expect(len(outputs) == 1, "Expect one default output from build dep of attr javac!")
|
||||
return outputs[0]
|
||||
|
||||
if javac_attr_type == "artifact":
|
||||
return javac_attribute
|
||||
|
||||
if javac_attr_type == str.type:
|
||||
return javac_attribute
|
||||
|
||||
fail("Type of attribute javac {} that equals to {} is not supported.\n Supported types are \"dependency\", \"artifact\" and \"string\".".format(javac_attr_type, javac_attribute))
|
||||
|
||||
def get_java_version_attributes(ctx: "context") -> (int.type, int.type):
|
||||
java_toolchain = ctx.attrs._java_toolchain[JavaToolchainInfo]
|
||||
java_version = ctx.attrs.java_version
|
||||
java_source = ctx.attrs.source
|
||||
java_target = ctx.attrs.target
|
||||
|
||||
if java_version:
|
||||
if java_source or java_target:
|
||||
fail("No need to set 'source' and/or 'target' attributes when 'java_version' is present")
|
||||
java_version = to_java_version(java_version)
|
||||
return (java_version, java_version)
|
||||
|
||||
source = java_source or java_toolchain.source_level
|
||||
target = java_target or java_toolchain.target_level
|
||||
|
||||
expect(bool(source) and bool(target), "Java source level and target level must be set!")
|
||||
|
||||
source = to_java_version(source)
|
||||
target = to_java_version(target)
|
||||
|
||||
expect(source <= target, "java library source level {} is higher than target {} ", source, target)
|
||||
|
||||
return (source, target)
|
||||
|
||||
def to_java_version(java_version: str.type) -> int.type:
|
||||
if java_version.startswith("1."):
|
||||
expect(len(java_version) == 3, "Supported java version number format is 1.X, where X is a single digit numnber, but it was set to {}", java_version)
|
||||
java_version_number = int(java_version[2:])
|
||||
expect(java_version_number < 9, "Supported java version number format is 1.X, where X is a single digit numnber that is less than 9, but it was set to {}", java_version)
|
||||
return java_version_number
|
||||
else:
|
||||
return int(java_version)
|
||||
|
||||
def get_abi_generation_mode(abi_generation_mode):
|
||||
return {
|
||||
None: None,
|
||||
"class": AbiGenerationMode("class"),
|
||||
"migrating_to_source_only": AbiGenerationMode("source"),
|
||||
"source": AbiGenerationMode("source"),
|
||||
"source_only": AbiGenerationMode("source_only"),
|
||||
}[abi_generation_mode]
|
||||
|
||||
def get_default_info(
|
||||
outputs: ["JavaCompileOutputs", None],
|
||||
extra_sub_targets: dict.type = {}) -> DefaultInfo.type:
|
||||
sub_targets = {}
|
||||
default_info = DefaultInfo()
|
||||
if outputs:
|
||||
abis = [
|
||||
("class-abi", outputs.class_abi),
|
||||
("source-abi", outputs.source_abi),
|
||||
("source-only-abi", outputs.source_only_abi),
|
||||
]
|
||||
for (name, artifact) in abis:
|
||||
if artifact != None:
|
||||
sub_targets[name] = [DefaultInfo(default_outputs = [artifact])]
|
||||
default_info = DefaultInfo(
|
||||
default_outputs = [outputs.full_library],
|
||||
sub_targets = extra_sub_targets | sub_targets,
|
||||
)
|
||||
return default_info
|
||||
Loading…
Add table
Add a link
Reference in a new issue