Skip to content

Commit

Permalink
Add _repo_mapping file if supported
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Mar 8, 2024
1 parent f1a3d5d commit 404cf5c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions fuzzing/private/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Provider for storing information about a fuzz test binary.
fields = {
"binary_file": "The instrumented fuzz test executable.",
"binary_runfiles": "The runfiles of the fuzz test executable.",
"binary_repo_mapping_manifest": "The _repo_mapping file of the fuzz " +
"test executable.",
"corpus_dir": "The directory of the corpus files used as input seeds.",
"dictionary_file": "The dictionary file to use in fuzzing runs.",
"engine_info": "The `FuzzingEngineInfo` provider of the fuzzing " +
Expand Down Expand Up @@ -108,9 +110,11 @@ def _fuzzing_binary_impl(ctx):
)
if ctx.attr._instrument_binary:
# The attribute is a list if a transition is attached.
binary_runfiles = ctx.attr.binary[0][DefaultInfo].default_runfiles
default_info = ctx.attr.binary[0][DefaultInfo]
else:
binary_runfiles = ctx.attr.binary[DefaultInfo].default_runfiles
default_info = ctx.attr.binary[DefaultInfo]
binary_runfiles = default_info.default_runfiles
binary_repo_mapping_manifest = getattr(default_info.files_to_run, "repo_mapping_manifest")
other_runfiles = []
if ctx.file.corpus:
other_runfiles.append(ctx.file.corpus)
Expand All @@ -126,6 +130,7 @@ def _fuzzing_binary_impl(ctx):
FuzzingBinaryInfo(
binary_file = ctx.executable.binary,
binary_runfiles = binary_runfiles,
binary_repo_mapping_manifest = binary_repo_mapping_manifest,
corpus_dir = ctx.file.corpus,
dictionary_file = ctx.file.dictionary,
engine_info = ctx.attr.engine[FuzzingEngineInfo],
Expand Down
6 changes: 6 additions & 0 deletions fuzzing/private/oss_fuzz/package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def _oss_fuzz_package_impl(ctx):
ctx.actions.write(runfiles_manifest, runfiles_manifest_content, False)
archive_inputs.append(runfiles_manifest)

if binary_info.binary_repo_mapping_manifest:
archive_inputs.append(binary_info.binary_repo_mapping_manifest)
if binary_info.corpus_dir:
archive_inputs.append(binary_info.corpus_dir)
if binary_info.dictionary_file:
Expand All @@ -61,6 +63,9 @@ def _oss_fuzz_package_impl(ctx):
mkdir -p "$(dirname "$STAGING_DIR/{binary_runfiles_dir}/$link")"
ln -s "$(pwd)/$target" "$STAGING_DIR/{binary_runfiles_dir}/$link"
done <{runfiles_manifest_path}
if [[ -n "{binary_repo_mapping_manifest}" ]]; then
ln -s "$(pwd)/{binary_repo_mapping_manifest}" "$STAGING_DIR/{binary_runfiles_dir}/_repo_mapping"
fi
if [[ -n "{corpus_dir}" ]]; then
pushd "{corpus_dir}" >/dev/null
zip --quiet -r "$STAGING_DIR/{base_name}_seed_corpus.zip" ./*
Expand All @@ -77,6 +82,7 @@ def _oss_fuzz_package_impl(ctx):
base_name = ctx.attr.base_name,
binary_path = binary_info.binary_file.path,
binary_runfiles_dir = ctx.attr.base_name + ".runfiles",
binary_repo_mapping_manifest = binary_info.binary_repo_mapping_manifest.path if binary_info.binary_repo_mapping_manifest else "",
corpus_dir = binary_info.corpus_dir.path if binary_info.corpus_dir else "",
dictionary_path = binary_info.dictionary_file.path if binary_info.dictionary_file else "",
options_path = binary_info.options_file.path if binary_info.options_file else "",
Expand Down

0 comments on commit 404cf5c

Please sign in to comment.