Use OSS-Fuzz provided top-level files (#151)

* Export provided Jazzer files from @rules_fuzzing_oss_fuzz

OSS-Fuzz provides current builds of the Jazzer driver and agent, which
should be used by Java fuzz tests instead of those targets built from
the pinned rules_fuzzing dependency of Jazzer.

This commits exports the files provided in $OUT from the
@rules_fuzzing_oss_fuzz repository.

* Address review comment
diff --git a/fuzzing/private/oss_fuzz/BUILD.tpl b/fuzzing/private/oss_fuzz/BUILD.tpl
index 8735e04..aa41c48 100644
--- a/fuzzing/private/oss_fuzz/BUILD.tpl
+++ b/fuzzing/private/oss_fuzz/BUILD.tpl
@@ -30,5 +30,5 @@
 )
 
 exports_files([
-    "instrum.bzl",
+    "instrum.bzl", %{exported_files}
 ])
\ No newline at end of file
diff --git a/fuzzing/private/oss_fuzz/repository.bzl b/fuzzing/private/oss_fuzz/repository.bzl
index 8f812f6..1565709 100644
--- a/fuzzing/private/oss_fuzz/repository.bzl
+++ b/fuzzing/private/oss_fuzz/repository.bzl
@@ -103,12 +103,46 @@
         instrum_cxxopts = instrum_cxxopts,
     )
 
+# The filename under which the Jazzer agent is available in $OUT.
+_JAZZER_IN_AGENT_DEPLOY_JAR = "jazzer_agent_deploy.jar"
+
+# The filename under which the Jazzer agent is available in
+# @rules_fuzzing_oss_fuzz.
+_JAZZER_OUT_AGENT_DEPLOY_JAR = _JAZZER_IN_AGENT_DEPLOY_JAR
+
+# The filenames under which the Jazzer drivers with various sanitizers are
+# available in $OUT.
+_JAZZER_IN_DRIVER = "jazzer_driver"
+_JAZZER_IN_DRIVER_ADDRESS_SANITIZER = "jazzer_driver_asan"
+
+# The filename under which the Jazzer driver for Java-only projects is available
+# in @rules_fuzzing_oss_fuzz.
+_JAZZER_OUT_DRIVER_NO_SANITIZER = "jazzer_driver_no_sanitizer"
+
+# The filename under which the Jazzer driver with the sanitizer specified by
+# $SANITIZER is available in @rules_fuzzing_oss_fuzz.
+_JAZZER_OUT_DRIVER_WITH_SANITIZER = "jazzer_driver_with_sanitizer"
+
+def _export_jazzer(repository_ctx, out_path, sanitizer):
+    if out_path == None:
+        return []
+    exported_files = []
+    repository_ctx.symlink(out_path + "/" + _JAZZER_IN_AGENT_DEPLOY_JAR, _JAZZER_OUT_AGENT_DEPLOY_JAR)
+    exported_files.append(_JAZZER_OUT_AGENT_DEPLOY_JAR)
+    repository_ctx.symlink(out_path + "/" + _JAZZER_IN_DRIVER, _JAZZER_OUT_DRIVER_NO_SANITIZER)
+    exported_files.append(_JAZZER_OUT_DRIVER_NO_SANITIZER)
+    if sanitizer == "address":
+        repository_ctx.symlink(out_path + "/" + _JAZZER_IN_DRIVER_ADDRESS_SANITIZER, _JAZZER_OUT_DRIVER_WITH_SANITIZER)
+        exported_files.append(_JAZZER_OUT_DRIVER_WITH_SANITIZER)
+    return exported_files
+
 def _oss_fuzz_repository(repository_ctx):
     environ = repository_ctx.os.environ
     fuzzing_engine_library = environ.get("LIB_FUZZING_ENGINE")
     sanitizer = environ.get("SANITIZER")
     cflags = environ.get("FUZZING_CFLAGS") or environ.get("CFLAGS", "")
     cxxflags = environ.get("FUZZING_CXXFLAGS") or environ.get("CXXFLAGS", "")
+    out_path = environ.get("OUT")
 
     build_params = _extract_build_params(
         repository_ctx,
@@ -117,6 +151,7 @@
         cflags.split(" "),
         cxxflags.split(" "),
     )
+    exported_files = _export_jazzer(repository_ctx, out_path, sanitizer)
 
     repository_ctx.template(
         "BUILD",
@@ -124,6 +159,7 @@
         {
             "%{stub_srcs}": _to_list_repr(build_params.stub_srcs),
             "%{stub_linkopts}": _to_list_repr(build_params.stub_linkopts),
+            "%{exported_files}": _to_list_repr(exported_files),
         },
     )
     repository_ctx.template(
@@ -148,6 +184,7 @@
         "CFLAGS",
         "CXXFLAGS",
         "SANITIZER",
+        "OUT",
     ],
     local = True,
     doc = """