-
Notifications
You must be signed in to change notification settings - Fork 2
/
classpath_validator.bzl
69 lines (57 loc) · 2.62 KB
/
classpath_validator.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def _label_as_string(label):
return "{workspace_name}//{package}:{name}".format(
workspace_name = "" if (not label.workspace_name) else "@" + label.workspace_name,
package = label.package,
name = label.name,
)
def _construct_args(args, argument_name, values):
for value in values:
args.append(
'''"{0}={1}"'''.format(argument_name, value)
)
def _construct_file(ctx, contents, file_name):
file = ctx.actions.declare_file(file_name)
ctx.actions.write(
output = file,
content = "\n".join(contents),
)
return file
def _impl(ctx):
target = ctx.attr.target
runtime_jars = target[java_common.provider].transitive_runtime_jars.to_list()
jars = [(_label_as_string(j.owner) + " " + j.short_path) for j in runtime_jars]
jar_file = _construct_file(ctx, jars, "{0}_jars.txt".format(ctx.label.name))
arguments = []
_construct_args(arguments, "--ignore-prefix", ctx.attr.ignore_prefixes)
_construct_args(arguments, "--ignore-suffix", ctx.attr.ignore_suffixes)
_construct_args(arguments, "--include-prefix", ctx.attr.include_prefixes)
_construct_args(arguments, "--include-suffix", ctx.attr.include_suffixes)
_construct_args(arguments, "--jar-targets", [jar_file.short_path])
# generate executable command
validator_exectuable = ctx.attr._validator[DefaultInfo].files_to_run.executable.short_path
cmd = "{validator_exectuable} {arguments}".format(
validator_exectuable = validator_exectuable,
arguments = " ".join(arguments),
)
exec = ctx.actions.declare_file(ctx.label.name + "_test_run.sh")
ctx.actions.write(
output = exec,
content = cmd,
is_executable = True,
)
# compute runfiles
runfiles = ctx.runfiles(files = [exec, jar_file] + runtime_jars) \
.merge(ctx.attr._validator[DefaultInfo].default_runfiles)
return [DefaultInfo(executable = exec, runfiles = runfiles)]
classpath_collision_test = rule(
implementation = _impl,
attrs = {
"target": attr.label(providers = [JavaInfo]),
"ignore_prefixes": attr.string_list(doc = "prefixes of jar entries to ignore", default = []),
"ignore_suffixes": attr.string_list(doc = "suffixes of jar entries to ignore", default = []),
"include_prefixes": attr.string_list(doc = "prefixes of jar entries to check", default = []),
"include_suffixes": attr.string_list(doc = "suffixes of jar entries to check", default = []),
"_validator": attr.label(providers = [DefaultInfo], default = "//src/main/com/bazelbuild/java/classpath:classpath_run"),
},
test = True,
)