diff options
author | Matthew Sotoudeh <matthewsot@outlook.com> | 2020-04-13 08:40:01 -0700 |
---|---|---|
committer | Matthew Sotoudeh <matthewsot@outlook.com> | 2020-04-13 08:40:01 -0700 |
commit | 96e12c8a274ea3e08648116f3fb052e3de005560 (patch) | |
tree | cc419696e4e062fc7173876073598c98cae0aa63 /pdfcrop.bzl | |
parent | 229b0f318e0160013c9c5700a22cc13da37fdcd8 (diff) |
Initial code release
Diffstat (limited to 'pdfcrop.bzl')
-rw-r--r-- | pdfcrop.bzl | 52 |
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, + ) |