-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
osgi.bzl
51 lines (46 loc) · 1.79 KB
/
osgi.bzl
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
""" Custom rule to generate OSGi Manifest """
load("@rules_java//java:defs.bzl", "JavaInfo")
def _osgi_jar_impl(ctx):
output = ctx.outputs.osgi_jar.path
pom_version = ctx.var.get("pom_version", "LOCAL-SNAPSHOT")
input_jar = ctx.attr.target[JavaInfo].outputs.jars[0].class_jar
classpath_jars = ctx.attr.target[JavaInfo].compilation_info.compilation_classpath
args = ctx.actions.args()
args.add_joined("--classpath", classpath_jars, join_with = ":")
args.add("--output_jar", output)
args.add("--bundle_version", pom_version)
args.add("--bundle_name", ctx.attr.bundle_name)
args.add("--symbolic_name", ctx.attr.symbolic_name)
if ctx.attr.fragment:
args.add("--fragment")
args.add_joined("--import_package", ctx.attr.import_package, join_with = ",")
args.add_joined("--export_package", ctx.attr.export_package, join_with = ",")
args.add("--input_jar", input_jar.path)
ctx.actions.run(
inputs = [input_jar] + classpath_jars.to_list(),
executable = ctx.executable._osgi_wrapper_exe,
arguments = [args],
outputs = [ctx.outputs.osgi_jar],
progress_message = "Generating OSGi bundle Manifest for %s" % ctx.attr.target.label,
)
osgi_jar = rule(
attrs = {
"target": attr.label(),
"export_package": attr.string_list(),
"import_package": attr.string_list(),
"bundle_name": attr.string(),
"fragment": attr.bool(),
"symbolic_name": attr.string(),
"_osgi_wrapper_exe": attr.label(
executable = True,
cfg = "exec",
allow_files = True,
default = Label("//tools:osgi_wrapper"),
),
},
fragments = ["java"],
outputs = {
"osgi_jar": "lib%{name}.jar",
},
implementation = _osgi_jar_impl,
)