summaryrefslogtreecommitdiff
path: root/pdfcrop.bzl
blob: b463f986b5938c093cbce574afb3412588c1eedf (plain)
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
def _pdf_crop_impl(ctx):
    texlive_path = ctx.var.get("TEXLIVE_FULL_DIR", None)
    if texlive_path == None:
        fail("Please run setup_texlive.sh to set TEXLIVE_FULL_DIR.")
    uncropped = ctx.attr.uncropped.files.to_list()[0]
    ctx.actions.run(
        mnemonic = "PDFCrop",
        executable = "bash",
        use_default_shell_env = True,
        arguments = [
            ctx.files._pdf_crop_wrapper[0].path,
            ctx.files._pdf_crop_script[0].path,
            texlive_path,
            uncropped.path,
            ctx.outputs.output.path,
        ],
        inputs = depset(
            direct = (ctx.files._pdf_crop_script + ctx.files._pdf_crop_wrapper +
                      [uncropped]),
        ),
        outputs = [ctx.outputs.output],
    )

_pdf_crop = rule(
    attrs = {
        "uncropped": attr.label(
            allow_files = True,
        ),
        "output": attr.output(),
        "_pdf_crop_wrapper": attr.label(
            allow_files = True,
            default = "@bazel_latex//:pdfcrop.sh",
        ),
        "_pdf_crop_script": attr.label(
            allow_files = True,
            default = "@pdfcrop//:pdfcrop.pl",
        ),
    },
    implementation = _pdf_crop_impl,
)

def pdfcrop(name = "pdfcrop", visibility = [], uncropped = []):
    for path in uncropped:
        if not path.endswith(".pdf"):
            fail
    for i, path in enumerate(uncropped):
        _pdf_crop(
            name = path[:-4] + "-cropper",
            uncropped = path,
            output = path[:-4] + "-crop.pdf",
            visibility = visibility,
        )
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback