Bug 1318318 - Improve clone_libfuzzer.sh and clone_corpus.sh handling of existing checkouts r=franziskus
authorTim Taubert <ttaubert@mozilla.com>
Fri, 18 Nov 2016 12:32:14 +0100
changeset 12881 188ca0d92fb72ba9628c698af6394579eb2ea1a7
parent 12880 7e3bfac855c9c108e929fd37e022e54ffa9193fe
child 12882 c3e654ef3ca4a1eef4548438457e21061ba865c2
push id1799
push userttaubert@mozilla.com
push dateFri, 18 Nov 2016 11:33:25 +0000
reviewersfranziskus
bugs1318318
Bug 1318318 - Improve clone_libfuzzer.sh and clone_corpus.sh handling of existing checkouts r=franziskus Differential Revision: https://nss-review.dev.mozaws.net/D77
build.sh
fuzz/clone_corpus.sh
fuzz/clone_libfuzzer.sh
--- a/build.sh
+++ b/build.sh
@@ -45,16 +45,17 @@ if [ -n "$CCC" ] && [ -z "$CXX" ]; then
 fi
 
 opt_build=0
 build_64=0
 clean=0
 rebuild_gyp=0
 target=Debug
 verbose=0
+fuzz=0
 
 # parse parameters to store in config
 params=$(echo "$*" | perl -pe 's/-c|-v|-g|-j [0-9]*|-h//g' | perl -pe 's/^[ \t]*//')
 params=$(echo "$params $CC $CCC" | tr " " "\n" | perl -pe '/^\s*$/d')
 params=$(echo "${params[*]}" | sort)
 
 cwd=$(cd $(dirname $0); pwd -P)
 dist_dir="$cwd/../dist"
@@ -66,28 +67,26 @@ if [ "$arch" = "x64" -o "$arch" = "aarch
 fi
 
 gyp_params=()
 ninja_params=()
 scanbuild=()
 
 enable_fuzz()
 {
+    fuzz=1
     nspr_sanitizer asan
     nspr_sanitizer ubsan
     nspr_sanitizer sancov edge
     gyp_params+=(-Duse_asan=1)
     gyp_params+=(-Duse_ubsan=1)
     gyp_params+=(-Duse_sancov=edge)
 
     # Adding debug symbols even for opt builds.
     nspr_opt+=(--enable-debug-symbols)
-
-    # Clone libFuzzer repository.
-    $cwd/fuzz/clone_libfuzzer.sh &>/dev/null
 }
 
 # parse command line arguments
 while [ $# -gt 0 ]; do
     case $1 in
         -c) clean=1 ;;
         -g) rebuild_gyp=1 ;;
         -j) ninja_params+=(-j "$2"); shift ;;
@@ -115,16 +114,29 @@ else
 fi
 if [ "$build_64" == "1" ]; then
     nspr_opt+=(--enable-64bit)
 else
     gyp_params+=(-Dtarget_arch=ia32)
     nspr_opt+=(--enable-x32)
 fi
 
+# clone fuzzing stuff
+if [ "$fuzz" = "1" ]; then
+    [ $verbose = 0 ] && exec 3>/dev/null || exec 3>&1
+
+    echo "[1/2] Cloning libFuzzer files ..."
+    $cwd/fuzz/clone_libfuzzer.sh 1>&3 2>&3
+
+    echo "[2/2] Cloning fuzzing corpus ..."
+    $cwd/fuzz/clone_corpus.sh 1>&3 2>&3
+
+    exec 3>&-
+fi
+
 # check if we have to rebuild gyp
 if [ "$params" != "$(cat $cwd/out/config 2>/dev/null)" -o "$rebuild_gyp" == 1 -o "$clean" == 1 ]; then
     rebuild_gyp=1
     rm -rf "$cwd/../nspr/$target" # force NSPR to rebuild
 fi
 
 # set paths
 target_dir="$cwd/out/$target"
--- a/fuzz/clone_corpus.sh
+++ b/fuzz/clone_corpus.sh
@@ -1,4 +1,11 @@
 #!/bin/sh
 
 cd $(dirname $0)
-git clone https://github.com/mozilla/nss-fuzzing-corpus corpus
+
+mkdir tmp/
+git clone --no-checkout --depth 1 https://github.com/mozilla/nss-fuzzing-corpus tmp/
+(cd tmp && git reset --hard master)
+
+mkdir -p corpus
+cp -r tmp/* corpus
+rm -Rf tmp/
--- a/fuzz/clone_libfuzzer.sh
+++ b/fuzz/clone_libfuzzer.sh
@@ -1,9 +1,11 @@
 #!/bin/sh
 
 cd $(dirname $0)
+
 mkdir tmp/
-git clone -q https://chromium.googlesource.com/chromium/llvm-project/llvm/lib/Fuzzer tmp/
-mv tmp/.git libFuzzer/
-rm -fr tmp
-cd libFuzzer
-git reset --hard 1b543d6e5073b56be214394890c9193979a3d7e1
+git clone --no-checkout --depth 1 https://chromium.googlesource.com/chromium/llvm-project/llvm/lib/Fuzzer tmp/
+(cd tmp && git reset --hard 1b543d6e5073b56be214394890c9193979a3d7e1)
+
+mkdir -p libFuzzer
+cp tmp/*.cpp tmp/*.h tmp/*.def libFuzzer
+rm -Rf tmp/