From 96e12c8a274ea3e08648116f3fb052e3de005560 Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Mon, 13 Apr 2020 08:40:01 -0700 Subject: Initial code release --- pdfcrop.bzl | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 pdfcrop.bzl (limited to 'pdfcrop.bzl') 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, + ) -- cgit v1.2.3