Reorganize the fuzzing dependency import code. (#115)
The new organization makes it easier to import dependencies piece by piece, as needed by the workspace using it. This simplifies dependency management in codebases with dependency provenance tracking, such as Envoy.
diff --git a/WORKSPACE b/WORKSPACE
index 72c8f98..5fb274d 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -16,26 +16,28 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-# Downloads dependencies.
-load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies")
+# Load all external library dependencies.
+
+load(
+ "@rules_fuzzing//fuzzing:repositories.bzl",
+ "honggfuzz_dependencies",
+ "oss_fuzz_dependencies",
+ "rules_fuzzing_dependencies",
+)
rules_fuzzing_dependencies()
-# Imports the transitive dependencies.
-load("@rules_fuzzing//fuzzing:dependency_imports.bzl", "fuzzing_dependency_imports")
+honggfuzz_dependencies()
-fuzzing_dependency_imports()
+oss_fuzz_dependencies()
-http_archive(
- name = "io_bazel_stardoc",
- sha256 = "9b09b3ee6181aa4b56c8bc863b1f1c922725298047d243cf19bc69e455ffa7c3",
- strip_prefix = "stardoc-5986d24c478e81242627c6d688fdc547567bc93c",
- url = "https://github.com/bazelbuild/stardoc/archive/5986d24c478e81242627c6d688fdc547567bc93c.zip",
-)
+# Initialize Bazel Skylib.
-load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")
+load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
-stardoc_repositories()
+bazel_skylib_workspace()
+
+# The support for running the examples and unit tests.
http_archive(
name = "re2",
@@ -50,3 +52,28 @@
strip_prefix = "googletest-389cb68b87193358358ae87cc56d257fd0d80189",
urls = ["https://github.com/google/googletest/archive/389cb68b87193358358ae87cc56d257fd0d80189.zip"],
)
+
+# Python dependencies.
+
+load("@rules_python//python:pip.bzl", "pip_install")
+load("@rules_python//python:repositories.bzl", "py_repositories")
+
+py_repositories()
+
+pip_install(
+ name = "fuzzing_py_deps",
+ requirements = "@rules_fuzzing//fuzzing:requirements.txt",
+)
+
+# Stardoc dependencies.
+
+http_archive(
+ name = "io_bazel_stardoc",
+ sha256 = "9b09b3ee6181aa4b56c8bc863b1f1c922725298047d243cf19bc69e455ffa7c3",
+ strip_prefix = "stardoc-5986d24c478e81242627c6d688fdc547567bc93c",
+ url = "https://github.com/bazelbuild/stardoc/archive/5986d24c478e81242627c6d688fdc547567bc93c.zip",
+)
+
+load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")
+
+stardoc_repositories()
diff --git a/fuzzing/dependency_imports.bzl b/fuzzing/dependency_imports.bzl
deleted file mode 100644
index beb28b0..0000000
--- a/fuzzing/dependency_imports.bzl
+++ /dev/null
@@ -1,29 +0,0 @@
-# Copyright 2020 Google LLC
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# https://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Provides fuzzing dependencies."""
-
-load("@rules_python//python:pip.bzl", "pip_install")
-load("@rules_python//python:repositories.bzl", "py_repositories")
-load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
-
-def fuzzing_dependency_imports():
- """Imports the dependencies of the external repositories."""
- py_repositories()
- bazel_skylib_workspace()
-
- pip_install(
- name = "fuzzing_py_deps",
- requirements = "@rules_fuzzing//fuzzing:requirements.txt",
- )
diff --git a/fuzzing/repositories.bzl b/fuzzing/repositories.bzl
index d897f5e..bb6b502 100644
--- a/fuzzing/repositories.bzl
+++ b/fuzzing/repositories.bzl
@@ -27,7 +27,6 @@
url = "https://github.com/bazelbuild/rules_python/releases/download/0.1.0/rules_python-0.1.0.tar.gz",
sha256 = "b6d46438523a3ec0f3cead544190ee13223a52f6a6765a29eae7b7cc24cc83a0",
)
-
maybe(
http_archive,
name = "bazel_skylib",
@@ -37,7 +36,6 @@
],
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
)
-
maybe(
http_archive,
name = "com_google_absl",
@@ -46,9 +44,9 @@
sha256 = "f4f2d3d01c3cc99eebc9f370ea626c43a54b386913aef393bf8201b2c42a9e2f",
)
- # TODO(sbucur): Since Honggfuzz has its own set of dependencies, look into
- # making them optional, so developers only import them if they decide to
- # use Honggfuzz.
+def honggfuzz_dependencies():
+ """The extra dependencies needed for Honggfuzz support."""
+
maybe(
http_archive,
name = "honggfuzz",
@@ -58,6 +56,10 @@
strip_prefix = "honggfuzz-e0670137531242d66c9cf8a6dee677c055a8aacb",
)
- oss_fuzz_repository(
+def oss_fuzz_dependencies():
+ """The extra dependencies needed for OSS-Fuzz support."""
+
+ maybe(
+ oss_fuzz_repository,
name = "rules_fuzzing_oss_fuzz",
)