summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Sotoudeh <masotoudeh@ucdavis.edu>2020-09-13 16:13:59 -0700
committerGitHub <noreply@github.com>2020-09-13 16:13:59 -0700
commit696252c38a939599cc2f0ea8a05b135120e725d3 (patch)
tree8fcc686e71043195044eab3901d16c34d5b7681e
parent20bf723dffea5aba9eee5101a1bcd9b8c9b2b90b (diff)
Fixes to the arXiv-cleaning rules (#4)
Resolves Issue #3, now the arxiv-latex-cleaner rules should work correctly.
-rw-r--r--BUILD.bazel2
-rw-r--r--README.md9
-rwxr-xr-xget_arxivable.sh7
-rwxr-xr-xget_file.sh5
-rwxr-xr-xget_pdf.sh5
-rw-r--r--latex.bzl72
-rw-r--r--run_latex.py29
7 files changed, 111 insertions, 18 deletions
diff --git a/BUILD.bazel b/BUILD.bazel
index f77cc29..58074f4 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -1,7 +1,7 @@
exports_files([
"run_latex.py",
"view_pdf.sh",
- "get_pdf.sh",
+ "get_file.sh",
"get_arxivable.sh",
"pdfcrop.sh",
])
diff --git a/README.md b/README.md
index a823859..b0ddb92 100644
--- a/README.md
+++ b/README.md
@@ -76,14 +76,17 @@ latex_document(
```
### Step 3: Building your Paper
-Every `latex_document` rule creates three targets:
+Every `latex_document` rule creates multiple targets:
* `bazel build [name]` will build the PDF, but it won't be directly accessible.
* `bazel run [name]_view` will display the PDF in a graphical viewer.
* `bazel run [name]_getpdf` will copy the PDF into the corresponding directory.
-* `bazel run [name]_getarxivable` will create an arXiv-ready version of the
+* `bazel build [name]_arxivable` will create an arXiv-ready version of the
source using
- [arxiv-latex-cleaner](https://github.com/google-research/arxiv-latex-cleaner).
+ [arxiv-latex-cleaner](https://github.com/google-research/arxiv-latex-cleaner),
+ but it won't be directly accessible in this directory.
+* `bazel run [name]_getarxivable` will copy the arXiv-ready version of the
+ source into the current directory.
## Goals
These rules are designed to achieve the following goals:
diff --git a/get_arxivable.sh b/get_arxivable.sh
index dc359ba..8be1495 100755
--- a/get_arxivable.sh
+++ b/get_arxivable.sh
@@ -1,12 +1,11 @@
#!/bin/sh
-out_name=$(basename $0).tar.gz
-build_dir=$BUILD_WORKING_DIRECTORY
+out_name=$PWD/./$1
paper_dir=$(mktemp -d)
-cp -LRr * $paper_dir
+cp -LR * $paper_dir
rm $paper_dir/$(basename $0)
python3 external/arxiv_latex_cleaner/arxiv_latex_cleaner.py $paper_dir
cd $(echo $paper_dir)_arXiv
-tar -czvf $build_dir/$out_name *
+tar -czvf $out_name *
diff --git a/get_file.sh b/get_file.sh
new file mode 100755
index 0000000..6841e5f
--- /dev/null
+++ b/get_file.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+builddir=$BUILD_WORKING_DIRECTORY
+cp $1 $builddir/$1
+chmod -x+w $builddir/$1
diff --git a/get_pdf.sh b/get_pdf.sh
deleted file mode 100755
index 7a0909f..0000000
--- a/get_pdf.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-filename="$(find . -name '*.pdf')"
-builddir=$BUILD_WORKING_DIRECTORY
-cp $filename $builddir/$filename
-chmod -x+w $builddir/$filename
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"],
)
diff --git a/run_latex.py b/run_latex.py
index 2d7d618..9f4b75e 100644
--- a/run_latex.py
+++ b/run_latex.py
@@ -1,5 +1,20 @@
#!/usr/bin/env python
+"""Build a LaTeX project.
+
+Two invocations are supported:
+
+1) run_latex.py [texlive] [latexrun] [jobname] [mainfile].tex [outfile].pdf [sources...]
+2) run_latex.py [texlive] [latexrun] [jobname] [mainfile].tex -- [sources...] -- [command...]
+
+The first will build [outfile].pdf from [mainfile].tex and the [sources...].
+This is used to build the PDF file for the [name]_getpdf rules.
+
+The second will build the paper, place [jobname].bbl in the current directory,
+then call [command...]. This is used to build the bbl file for the
+[name]_getarxivable rules.
+"""
+
import glob
import os
import shutil
@@ -8,6 +23,9 @@ import sys
texlive, latexrun, job_name, main_file, output_file = sys.argv[1:6]
sources = sys.argv[6:]
+if output_file == "--":
+ run_after = sources[sources.index("--"):][1:]
+ sources = sources[:sources.index("--")]
env = dict(os.environ)
# Generated files (eg. outputs of pdfcrop) are placed under bazel-out/*/bin.
@@ -40,4 +58,13 @@ return_code = subprocess.call(
if return_code != 0:
sys.exit(return_code)
-os.rename(job_name + ".pdf", output_file)
+
+if output_file != "--":
+ os.rename(job_name + ".pdf", output_file)
+else:
+ # Run the run_after script.
+ os.rename("latex.out/" + job_name + ".bbl", job_name + ".bbl")
+ return_code = subprocess.call(
+ args=run_after,
+ env=env,
+ )
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback