forked from ProdriveTechnologies/bazel-latex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatex.bzl
78 lines (74 loc) · 2.36 KB
/
latex.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
70
71
72
73
74
75
76
77
78
def _latex_pdf_impl(ctx):
toolchain = ctx.toolchains["@bazel_latex//:latex_toolchain_type"].latexinfo
ctx.actions.run(
mnemonic = "LuaLatex",
use_default_shell_env = True,
executable = ctx.executable.tool,
arguments = [
toolchain.kpsewhich.files.to_list()[0].path,
toolchain.luatex.files.to_list()[0].path,
toolchain.bibtex.files.to_list()[0].path,
toolchain.biber.files.to_list()[0].path,
ctx.files._latexrun[0].path,
ctx.label.name,
ctx.files.main[0].path,
ctx.outputs.out.path,
] + ctx.attr.cmd_flags,
inputs = depset(
direct = ctx.files.main + ctx.files.srcs + ctx.files._latexrun,
transitive = [
toolchain.kpsewhich.files,
toolchain.luatex.files,
toolchain.bibtex.files,
toolchain.biber.files,
],
),
outputs = [ctx.outputs.out],
tools = [ctx.executable.tool],
)
_latex_pdf = rule(
attrs = {
"main": attr.label(allow_files = True),
"srcs": attr.label_list(allow_files = True),
"cmd_flags": attr.string_list(
allow_empty = True,
default = [],
),
"tool": attr.label(
default = Label("//:run_lualatex"),
executable = True,
cfg = "host",
),
"_latexrun": attr.label(
allow_files = True,
default = "@bazel_latex_latexrun//:latexrun",
),
},
outputs = {"out": "%{name}.pdf"},
toolchains = ["@bazel_latex//:latex_toolchain_type"],
implementation = _latex_pdf_impl,
)
def latex_document(name, main, srcs = [], tags = [], cmd_flags = []):
# PDF generation.
_latex_pdf(
name = name,
srcs = srcs + ["@bazel_latex//:core_dependencies"],
main = main,
tags = tags,
cmd_flags = cmd_flags,
)
# Convenience rule for viewing PDFs.
native.sh_binary(
name = name + "_view_output",
srcs = ["@bazel_latex//:view_pdf.sh"],
data = [name + ".pdf"],
tags = tags,
)
# Convenience rule for viewing PDFs.
native.sh_binary(
name = name + "_view",
srcs = ["@bazel_latex//:view_pdf.sh"],
data = [name + ".pdf"],
args = ["None"],
tags = tags,
)