Use downloaded pandoc instead of relying on it to be installed

Change-Id: I6477b14bafd04b4d44257526c99d816e77661bb0
diff --git a/WORKSPACE b/WORKSPACE
index 21b41f3..f256eb3 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -12,6 +12,10 @@
     "//debian:patch.bzl",
     patch_debs = "files",
 )
+load(
+    "//debian:pandoc.bzl",
+    pandoc_debs = "files",
+)
 load("//debian:packages.bzl", "generate_repositories_for_debs")
 
 generate_repositories_for_debs(python_debs)
@@ -20,6 +24,8 @@
 
 generate_repositories_for_debs(patch_debs)
 
+generate_repositories_for_debs(pandoc_debs)
+
 new_http_archive(
     name = "python_repo",
     build_file = "debian/python.BUILD",
@@ -184,3 +190,10 @@
     sha256 = "b5ce139648a2e04f5585948ddad2fdae24dd4ee7976ac5a22d6ae7bd5674631e",
     url = "http://frc971.org/Build-Dependencies/patch.tar.gz",
 )
+
+new_http_archive(
+    name = "pandoc",
+    build_file = "debian/pandoc.BUILD",
+    sha256 = "9f7a7adb3974a1f14715054c349ff3edc2909e920dbe3438fca437a83845f3c4",
+    url = "http://frc971.org/Build-Dependencies/pandoc.tar.gz",
+)
diff --git a/debian/BUILD b/debian/BUILD
index e9d3823..a571b2d 100644
--- a/debian/BUILD
+++ b/debian/BUILD
@@ -12,6 +12,10 @@
     ":patch.bzl",
     patch_debs = "files",
 )
+load(
+    ":pandoc.bzl",
+    pandoc_debs = "files",
+)
 load("//debian:packages.bzl", "download_packages", "generate_deb_tarball")
 
 py_binary(
@@ -62,6 +66,13 @@
     ],
 )
 
+download_packages(
+    name = "download_pandoc_deps",
+    packages = [
+        "pandoc",
+    ],
+)
+
 generate_deb_tarball(
     name = "python",
     files = python_debs,
@@ -76,3 +87,8 @@
     name = "patch",
     files = patch_debs,
 )
+
+generate_deb_tarball(
+    name = "pandoc",
+    files = pandoc_debs,
+)
diff --git a/debian/pandoc.BUILD b/debian/pandoc.BUILD
new file mode 100644
index 0000000..7e3084e
--- /dev/null
+++ b/debian/pandoc.BUILD
@@ -0,0 +1,25 @@
+genrule(
+    name = "gen_wrapper",
+    outs = ["pandoc_wrapper"],
+    cmd = "\n".join([
+        "cat > $@ <<END",
+        "#!/bin/bash",
+        "export LD_LIBRARY_PATH=external/pandoc/usr/lib/x86_64-linux-gnu:external/pandoc/lib/x86_64-linux-gnu",
+        "exec external/pandoc/usr/bin/pandoc \"\\$$@\"",
+        "END",
+    ]),
+    executable = True,
+)
+
+filegroup(
+    name = "pandoc",
+    srcs = ["pandoc_wrapper"],
+    data = glob(["**"]),
+    visibility = ["//visibility:public"],
+)
+
+filegroup(
+    name = "all_files",
+    srcs = glob(["**"]),
+    visibility = ["//visibility:public"],
+)
diff --git a/debian/pandoc.bzl b/debian/pandoc.bzl
new file mode 100644
index 0000000..f203db0
--- /dev/null
+++ b/debian/pandoc.bzl
@@ -0,0 +1,10 @@
+files = {
+    "libffi6_3.1-2+deb8u1_amd64.deb": "100343fca79ff265abc62467c7085fca68b8764e8c2551302ab741c771e7f0aa",
+    "libgmp10_6.0.0+dfsg-6_amd64.deb": "155a31b0f716aa3dcd7ee68e9bd57e0b76a6b31f4e41fb2d953e986315437082",
+    "libicu52_52.1-8+deb8u7_amd64.deb": "708d4499e2f6344a77d903c2c03a958f5edac32f9adf5ff3da7b572bf307e980",
+    "liblua5.1-0_5.1.5-7.1_amd64.deb": "91dfecba874f9330c8a67f17060594ed148c34c44532b60cdc10a480060e38a9",
+    "libstdc++6_4.9.2-10+deb8u1_amd64.deb": "a8f4ef6773b90bb39a8a8a0a5e3e20ca8501de6896204f665eb114d5b79f164f",
+    "libyaml-0-2_0.1.6-3_amd64.deb": "5885db15ac425eb7231c436903525b78381e034bcc53928a97997a745295d222",
+    "pandoc-data_1.12.4.2~dfsg-1_all.deb": "52c4cebd39582e3c2636febd40806a5f1ec71c7be9653addcabbe2732f52a730",
+    "pandoc_1.12.4.2~dfsg-1+b14_amd64.deb": "e2e2a33d398d92ead214391c93afdbd3f590f6ab50d9a88492e2421826484d1c",
+}
diff --git a/motors/BUILD b/motors/BUILD
index 50a4bce..395765e 100644
--- a/motors/BUILD
+++ b/motors/BUILD
@@ -43,7 +43,7 @@
         "NOTES.html",
     ],
     cmd = " ".join([
-        "pandoc",
+        "$(location @pandoc)",
         "-f",
         "markdown_github-hard_line_breaks",
         "-t",
@@ -52,6 +52,10 @@
         "$@",
         "$<",
     ]),
+    tools = [
+        "@pandoc",
+        "@pandoc//:all_files",
+    ],
 )
 
 cc_library(