This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
/
banal.bzl
56 lines (50 loc) · 1.72 KB
/
banal.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
# Defining rule for banal command.
def _banal(ctx):
cmd = ctx.attr.banal_cmd
if cmd != None:
cmd = ("PDFTOHTML="+ctx.attr.banal_pdftohtml+
" " + ctx.attr.banal_cmd)
return struct(command=cmd)
banal = rule(
implementation=_banal,
attrs={
"banal_cmd": attr.string(mandatory=False,
default="banal"),
"banal_pdftohtml": attr.string(mandatory=False),
},
)
# Defining rule to judge using banal.
def _banal_judge(ctx):
pdffile = ctx.file.pdffile
banalcmd = ctx.attr.banalcmd.command
output = ctx.outputs.out
options=ctx.attr.options
opt_string = ""
for k in options:
opt_string += " -%s=%s" % (k,options[k])
ctx.action(
inputs = [pdffile],
outputs = [output],
command="""%s -judge %s %s | \
tee %s""" % (banalcmd,
opt_string,
pdffile.path,
output.path))
banal_judge = rule(
implementation=_banal_judge,
attrs={
"pdffile": attr.label(mandatory=True,
allow_files=True,
single_file=True),
"banalcmd": attr.label(mandatory=True,
providers=["command"]),
"options": attr.string_dict(mandatory=False,
default={"paper": "letter",
"pages": "12",
"font": "10",
"leading": "12",
"width": "6.99",
"height": "9.25"}),
},
outputs={"out":"%{name}.banal_judge"},
)