From 696252c38a939599cc2f0ea8a05b135120e725d3 Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Sun, 13 Sep 2020 16:13:59 -0700 Subject: Fixes to the arXiv-cleaning rules (#4) Resolves Issue #3, now the arxiv-latex-cleaner rules should work correctly. --- latex.bzl | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 4 deletions(-) (limited to 'latex.bzl') diff --git a/latex.bzl b/latex.bzl index dc79e4e..d496397 100644 --- a/latex.bzl +++ b/latex.bzl @@ -43,6 +43,61 @@ _latex_pdf = rule( implementation = _latex_pdf_impl, ) +def _arxivable_impl(ctx): + """Rule to run arxiv-latex-cleaner and produce a .tar.gz of the sources. + """ + texlive_path = ctx.var.get("TEXLIVE_FULL_DIR", None) + if texlive_path == None: + fail("Please run setup_texlive.sh to set TEXLIVE_FULL_DIR.") + ctx.actions.run( + mnemonic = "Cleaning", + executable = "python", + use_default_shell_env = True, + arguments = [ + ctx.files._run_script[0].path, + texlive_path, + ctx.files._latexrun[0].path, + ctx.files.main[0].path.replace(".tex", ""), + ctx.files.main[0].path, + "--", + ] + [src.path for src in ctx.files.srcs] + [ + "--", + ctx.files._arxiv_script[0].path, + ctx.outputs.out.path, + ], + inputs = depset( + direct = (ctx.files.main + ctx.files.srcs + ctx.files._latexrun + + ctx.files._run_script + ctx.files._arxiv_script + + ctx.files._arxiv_latex_cleaner), + ), + outputs = [ctx.outputs.out], + ) + +_arxivable = rule( + attrs = { + "main": attr.label(allow_files = True), + "srcs": attr.label_list(allow_files = True), + "_latexrun": attr.label( + allow_files = True, + default = "@bazel_latex_latexrun//:latexrun", + ), + "_run_script": attr.label( + allow_files = True, + default = "@bazel_latex//:run_latex.py", + ), + "_arxiv_script": attr.label( + allow_files = True, + default = "@bazel_latex//:get_arxivable.sh", + ), + "_arxiv_latex_cleaner": attr.label( + allow_files = True, + default = "@arxiv_latex_cleaner//:all", + ), + }, + outputs = {"out": "%{name}.tar.gz"}, + implementation = _arxivable_impl, +) + def latex_document(name, main, srcs = []): """Given a TeX file, add rules for compiling and archiving it. """ @@ -64,13 +119,22 @@ def latex_document(name, main, srcs = []): # Copy the PDF into the main working directory. native.sh_binary( name = name + "_getpdf", - srcs = ["@bazel_latex//:get_pdf.sh"], + srcs = ["@bazel_latex//:get_file.sh"], + args = [name + ".pdf"], data = [name + ".pdf"], ) # Create an arXiv-ready version of the source. - native.sh_binary( + _arxivable( name = name + "_arxivable", - srcs = ["@bazel_latex//:get_arxivable.sh"], - data = srcs + ["@arxiv_latex_cleaner//:all"], + srcs = srcs, + main = main, + ) + + # Copy the .tar.gz into the main working directory. + native.sh_binary( + name = name + "_getarxivable", + srcs = ["@bazel_latex//:get_file.sh"], + args = [name + "_arxivable.tar.gz"], + data = [name + "_arxivable.tar.gz"], ) -- cgit v1.2.3