Skip to content

Commit 170197a

Browse files
authored
Split the BUILD of //docs (#649)
* Split BUILD file for //docs/md
1 parent 4afcc74 commit 170197a

File tree

4 files changed

+51
-57
lines changed

4 files changed

+51
-57
lines changed

docs/BUILD

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,13 @@
22

33
load("@bazel_pandoc//:pandoc.bzl", "pandoc")
44
load("@bazel_latex//:latex.bzl", "latex_document")
5-
load(":docs.bzl", "jflex_doc_tex", "replace_placeholders")
6-
7-
GENRULE_CONCATENATE = "cat $(SRCS) > $@"
8-
9-
DOC_SECTIONS = [
10-
"intro",
11-
"installing",
12-
"maven-plugin",
13-
"ant-task",
14-
"example",
15-
"lex-specs",
16-
"encodings",
17-
"performance",
18-
"porting-and-parsers",
19-
"end",
20-
]
21-
22-
MD_SRCS = ["md/head.md"] + ["md/" + src + ".md" for src in DOC_SECTIONS]
23-
24-
TEX_SRCS = [":" + section + "_tex" for section in DOC_SECTIONS]
5+
load("//docs:docs.bzl", "DOC_SECTIONS", "replace_placeholders")
256

267
# TODO(regisd) Add `output` attribute
278
# https://github.com/ProdriveTechnologies/bazel-pandoc/pull/1
289
pandoc(
2910
name = "html",
30-
src = ":manual_md",
11+
src = "//docs/md:concatenated_md",
3112
from_format = "markdown",
3213
# TODO: Add "--css manual.css" when the rule accepts data files
3314
#
@@ -39,31 +20,21 @@ pandoc(
3920
to_format = "html",
4021
)
4122

42-
replace_placeholders(
43-
name = "manual_md",
44-
src = ":concatenated_manual",
45-
)
46-
47-
# Concatenates all pages in a single document.
48-
genrule(
49-
name = "concatenated_manual",
50-
srcs = MD_SRCS,
51-
outs = ["concatenated_manual.md"],
52-
cmd = GENRULE_CONCATENATE,
53-
)
23+
TEX_SRCS = ["//docs/md:" + section + "_tex" for section in DOC_SECTIONS]
5424

5525
latex_document(
5626
name = "manual",
5727
srcs = [
5828
":fig/jflex-black.png",
5929
":first_page",
6030
":latex_content",
31+
] + TEX_SRCS + [
6132
"@bazel_latex//packages:geometry",
6233
"@bazel_latex//packages:graphicx",
6334
"@bazel_latex//packages:hyperref",
6435
"@bazel_latex//packages:microtype",
6536
"@bazel_latex//packages:upquote",
66-
] + TEX_SRCS,
37+
],
6738
main = "manual_full.tex",
6839
)
6940

@@ -74,13 +45,10 @@ replace_placeholders(
7445
output_to_bindir = True, # that's where pdf_latex looks into
7546
)
7647

77-
# Generates :section_tex (with substituted variables)
78-
[jflex_doc_tex(name = section) for section in DOC_SECTIONS]
79-
8048
genrule(
8149
name = "latex_content",
8250
srcs = TEX_SRCS,
8351
outs = ["_content.tex"],
84-
cmd = "echo '" + ("\n".join(["\\input{docs/" + section + "_tex}" for section in DOC_SECTIONS])) + "' > $@",
52+
cmd = "echo '" + ("\n".join(["\\input{docs/md/" + section + "_tex}" for section in DOC_SECTIONS])) + "' > $@",
8553
output_to_bindir = True, # that's where pdf_latex looks into
8654
)

docs/docs.bzl

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ RELEASE_DATE = "21 September 2018"
88

99
UNICODE_VER = "12.0"
1010

11+
DOC_SECTIONS = [
12+
"intro",
13+
"installing",
14+
"maven-plugin",
15+
"ant-task",
16+
"example",
17+
"lex-specs",
18+
"encodings",
19+
"performance",
20+
"porting-and-parsers",
21+
"end",
22+
]
23+
1124
def replace_placeholders(name, src = "", out = None, **kwargs):
1225
"""Replaces placeholders by their respective value."""
1326
if not out:
@@ -23,20 +36,3 @@ def replace_placeholders(name, src = "", out = None, **kwargs):
2336
" $< > $@",
2437
**kwargs
2538
)
26-
27-
def jflex_doc_tex(name, src = None):
28-
"""Generates the tex for a section"""
29-
if not src:
30-
src = "md/" + name + ".md"
31-
pandoc(
32-
name = name + "_tex",
33-
src = ":" + name + "_md",
34-
from_format = "markdown",
35-
to_format = "latex",
36-
options = ["--biblatex"],
37-
)
38-
39-
replace_placeholders(
40-
name = name + "_md",
41-
src = src,
42-
)

docs/md/BUILD

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
load("@bazel_pandoc//:pandoc.bzl", "pandoc")
2+
load("//docs:docs.bzl", "DOC_SECTIONS", "replace_placeholders")
3+
4+
ALL_SECTIONS = ["head"] + DOC_SECTIONS
5+
6+
GENRULE_CONCATENATE = "cat $(SRCS) > $@"
7+
8+
[replace_placeholders(
9+
name = section + "_md",
10+
src = section + ".md",
11+
) for section in ALL_SECTIONS]
12+
13+
# Concatenates all pages in a single document.
14+
genrule(
15+
name = "concatenated_md",
16+
srcs = [":%s_md" % section for section in ALL_SECTIONS],
17+
outs = ["concatenated_manual.md"],
18+
cmd = GENRULE_CONCATENATE,
19+
visibility = ["//docs:__pkg__"],
20+
)
21+
22+
# Generates :section_tex (with substituted variables)
23+
[pandoc(
24+
name = section + "_tex",
25+
src = ":" + section + "_md",
26+
from_format = "markdown",
27+
options = ["--biblatex"],
28+
to_format = "latex",
29+
visibility = ["//docs:__pkg__"],
30+
) for section in DOC_SECTIONS]

docs/md/head.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ bibliography: manual.bib
77

88
The Fast Lexical Analyser Generator
99

10-
Copyright © 1998–2018 by
11-
[Gerwin Klein](http://www.doclsf.de), Steve Rowe, and
10+
Copyright © 1998–2019 by
11+
[Gerwin Klein](http://www.doclsf.de/), Steve Rowe, and
1212
[Régis Décamps](http://regis.decamps.info/).
1313

1414
Version $VERSION, $RELEASE_DATE

0 commit comments

Comments
 (0)