-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathlatex_engine_cmds.bzl
136 lines (119 loc) · 3.96 KB
/
latex_engine_cmds.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"""
This module contains the specializations of commands
depending on tool or engine.
"""
def add_flags(ctx, fmt, output_path, bib_tool):
"""
Set flags for supplying arguments to latexrun and the engine.
Args:
ctx: For accessing the flags
fmt: Format file
output_path: path of the output artifact
bib_tool: bib tool of choice
Returns:
Flags for the latexrun command
"""
cmd = [
"--latex-args=--progname={}".format(ctx.attr._progname),
"--output-format={}".format(ctx.attr.format),
"--shell-escape",
"--jobname={}".format(ctx.label.name),
"--fmt={}".format(fmt.path),
]
flags = [
" ".join(cmd),
]
for value in ctx.attr.cmd_flags:
if "output-format" in value and ctx.attr.format not in value:
fail(
"Value of attr format ({}), ".format(ctx.attr.format) +
"conflicts with value of flag {}".format(value),
)
flags.append(value)
dir_count = len(output_path.split("/")) - 1
dir_pos = dir_count * "../"
flags.append("--bibtex-cmd=" + dir_pos + bib_tool.path)
flags.append("--bibtex-args=" + "--input-directory=" + dir_pos)
return flags
def lualatex_engine_cmd_gen(ctx, bib_tool, latex_tool):
"""
Generate commands specific for the lualatex engine.
This function generates these commands:
- generate format file
- call latex to build the document
Args:
ctx: For accessing the inputs parameters.
bib_tool: bib tool of choice.
latex_tool: The latex engine to use, in this case we make the
assumption that it is the luahbtex binary (This should be
enforced more strongly).
Returns:
A list of the commands
"""
fmt = ctx.actions.declare_file(
ctx.label.name + "/" + ctx.attr._progname + ".fmt",
)
ini_args = ctx.actions.args()
ini_files_path = ctx.files.ini_files[0].dirname
ini_args.add("-ini")
ini_args.add(
"--output-directory",
ctx.outputs.out.dirname + "/" + ctx.label.name,
)
ini_args.add("{}/{}.ini".format(ini_files_path, ctx.attr._progname))
args = ctx.actions.args()
args.add(
"--latex-cmd={}".format(
latex_tool.files.to_list()[0].path,
),
)
args.add("-Wall")
if ctx.attr.format == "dvi":
absolute_font_path_dvi = ctx.actions.declare_file(
ctx.label.name + "/" + ctx.outputs.out.basename,
)
args.add("-O=" + absolute_font_path_dvi.dirname)
args.add_all(add_flags(ctx, fmt, absolute_font_path_dvi.path, bib_tool))
args.add(ctx.file.main.path)
post_process_dvi_args = ctx.actions.args()
post_process_dvi_args.add(absolute_font_path_dvi)
post_process_dvi_args.add(ctx.outputs.out)
engine_cmds = [
{
"cmd": [ini_args],
"in": [],
"out": [fmt],
"tool": latex_tool.files.to_list()[0],
},
{
"cmd": [args],
"in": [fmt],
"out": [absolute_font_path_dvi],
"tool": ctx.executable._latexrun,
},
{
"cmd": [post_process_dvi_args],
"in": [absolute_font_path_dvi],
"out": [ctx.outputs.out],
"tool": ctx.executable._dvi_sub,
},
]
else:
args.add("-O=" + ctx.outputs.out.dirname)
args.add_all(add_flags(ctx, fmt, ctx.outputs.out.path, bib_tool))
args.add(ctx.file.main.path)
engine_cmds = [
{
"cmd": [ini_args],
"in": [],
"out": [fmt],
"tool": latex_tool.files.to_list()[0],
},
{
"cmd": [args],
"in": [fmt],
"out": [ctx.outputs.out],
"tool": ctx.executable._latexrun,
},
]
return engine_cmds