mirror of
https://github.com/astral-sh/ruff.git
synced 2026-10-28 10:45:37 +08:00
## Summary Continues #28197 by lifting `cargo-fuzz` into the dev toolchain. <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan NFC, internal only. I confirmed that `./init-fuzzer.sh` still runs as expected. I'm less positive about the CI changes. <!-- How was it tested? --> --------- Signed-off-by: William Woodruff <william@yossarian.net> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
49 lines
1.7 KiB
Bash
Executable File
49 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
set -eu
|
|
|
|
# https://stackoverflow.com/a/246128/3549270
|
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
|
|
cd "$SCRIPT_DIR"
|
|
|
|
if [ ! -d corpus/common ]; then
|
|
mkdir -p corpus/common
|
|
|
|
echo "Creating symlinks for fuzz targets to the common corpus directory..."
|
|
for target in fuzz_targets/*; do
|
|
corpus_dir="$(basename "$target" .rs)"
|
|
ln -vs "./common" "corpus/$corpus_dir"
|
|
done
|
|
|
|
(
|
|
cd corpus/common
|
|
|
|
read -p "Would you like to build a corpus from a python source code dataset? (this will take a long time!) [Y/n] " -n 1 -r
|
|
echo
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
echo "Downloading the Python source code dataset..."
|
|
curl -L 'https://zenodo.org/record/3628784/files/python-corpus.tar.gz?download=1' | tar xz
|
|
fi
|
|
|
|
# Build a smaller corpus in addition to the (optional) larger corpus
|
|
echo "Building a smaller corpus dataset..."
|
|
curl -L 'https://github.com/python/cpython/archive/refs/tags/v3.13.0.tar.gz' | tar xz
|
|
cp -r "../../../crates/ty_python_semantic/resources/corpus" "ty_python_semantic"
|
|
cp -r "../../../crates/ruff_linter/resources/test/fixtures" "ruff_linter"
|
|
cp -r "../../../crates/ruff_python_formatter/resources/test/fixtures" "ruff_python_formatter"
|
|
cp -r "../../../crates/ruff_python_parser/resources" "ruff_python_parser"
|
|
|
|
# Delete all non-Python files
|
|
find . -type f -not -name "*.py" -delete
|
|
)
|
|
|
|
echo "Minifying the corpus dataset..."
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
uv run --only-dev cargo +nightly fuzz cmin ruff_fix_validity corpus/common -- -timeout=5
|
|
else
|
|
uv run --only-dev cargo fuzz cmin -s none ruff_fix_validity corpus/common -- -timeout=5
|
|
fi
|
|
fi
|
|
|
|
echo "Done! You are ready to fuzz"
|