This repository was archived by the owner on Dec 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjava_library.bzl
More file actions
74 lines (67 loc) · 3.19 KB
/
Copy pathjava_library.bzl
File metadata and controls
74 lines (67 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'''Defines the `java_library` rule.
'''
load("//java:providers/JavaCompilationInfo.bzl", "JavaCompilationInfo")
load("//java:providers/JavaDependencyInfo.bzl", "JavaDependencyInfo")
load("//java:toolchain_rules/java_compiler_toolchain.bzl", "JavaCompilerToolchainInfo")
load("//java:common/actions/compile_java_jar.bzl", "compile_java_jar_for_target")
load(
"//java:common/providers.bzl",
"make_standard_java_target_java_dependency_info",
"make_legacy_java_info",
)
def _java_library_impl(ctx):
java_compilation_info = compile_java_jar_for_target(ctx)
output_jar = java_compilation_info.class_files_output_jar
return [
DefaultInfo(files = depset(direct = [output_jar])),
java_compilation_info,
make_standard_java_target_java_dependency_info(ctx, output_jar),
make_legacy_java_info(java_compilation_info, ctx.attr.deps),
]
java_library = rule(
implementation = _java_library_impl,
attrs = {
"srcs": attr.label_list(
# TODO(dwtj): Consider supporting empty `srcs` list once `exports`
# is supported.
allow_empty = False,
doc = "A list of Java source files whose derived class files should be included in this library (and any of its dependents).",
allow_files = [".java"],
default = list(),
),
"deps": attr.label_list(
providers = [
JavaDependencyInfo,
JavaInfo,
],
default = list(),
),
"additional_jar_manifest_attributes": attr.string_list(
doc = "A list of strings; each will be added as a line of the output JAR's manifest file.",
default = list(),
),
"resources": attr.label_keyed_string_dict(
allow_files = True,
default = dict(),
),
"javac_flags": attr.string_list(
doc = """A list of strings. Each will be added as a flag to the `javac` command invocation used to compile and process this rule's Java source files. These flags will be ordered just as they appear in this list. These flags will be in addition to the options automatically added to the `javac` invocation (e.g. `--class-path`). Example: By setting this attibute to the list `['-Asome_name_option="J. Smith"']` will add one annotation processing option to the `javac` invocation whose option name is `some_name_option` and whose value is "J. Smith".)""",
default = list(),
),
"output_jar": attr.output(
doc = "The name of the JAR file generated by this target. This JAR contains the class files generated by this target's Java compiler invocation.",
),
"java_compiler_toolchain": attr.label(
doc = "This optional attribute can override the global Java compiler toolchain. This expects a label for a `java_compiler_toolchain` target (or more precisely, a target providing `JavaCompilerToolchainInfo`).",
providers = [JavaCompilerToolchainInfo],
),
},
provides = [
JavaCompilationInfo,
JavaDependencyInfo,
JavaInfo,
],
toolchains = [
"@dwtj_rules_java//java/toolchains/java_compiler_toolchain:toolchain_type",
],
)