summaryrefslogtreecommitdiff
path: root/pdfcrop.bzl
diff options
context:
space:
mode:
Diffstat (limited to 'pdfcrop.bzl')
-rw-r--r--pdfcrop.bzl52
1 files changed, 52 insertions, 0 deletions
diff --git a/pdfcrop.bzl b/pdfcrop.bzl
new file mode 100644
index 0000000..b463f98
--- /dev/null
+++ b/pdfcrop.bzl
@@ -0,0 +1,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