1#!/bin/bash -eu 2# Copyright 2021 Google Inc. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16################################################################################ 17 18# Move seed corpus and dictionary. 19mv $SRC/{*.zip,*.dict} $OUT 20 21PROJECTS="compress imaging geometry" 22GEOMETRY_MODULE="commons-geometry-io-euclidean" 23 24for project in $PROJECTS; do 25 cd $SRC/commons-$project 26 MAVEN_ARGS="-Dmaven.test.skip=true -Djavac.src.version=15 -Djavac.target.version=15 -Djdk.version=15" 27 CURRENT_VERSION=$($MVN org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate \ 28 -Dexpression=project.version -q -DforceStdout) 29 30 if [ $project = 'geometry' ]; then 31 # commons-geometry is a multi-module project and requires special handling in order 32 # to build and extract the proper module (commons-geometry-io-euclidean) 33 $MVN package org.apache.maven.plugins:maven-shade-plugin:3.2.4:shade -am -pl $GEOMETRY_MODULE $MAVEN_ARGS 34 cp "$GEOMETRY_MODULE/target/$GEOMETRY_MODULE-$CURRENT_VERSION.jar" $OUT/commons-$project.jar 35 else 36 $MVN package org.apache.maven.plugins:maven-shade-plugin:3.2.4:shade $MAVEN_ARGS 37 cp "target/commons-$project-$CURRENT_VERSION.jar" $OUT/commons-$project.jar 38 fi 39 40 ALL_JARS="commons-$project.jar" 41 42 # The classpath at build-time includes the project jars in $OUT as well as the 43 # Jazzer API. 44 BUILD_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "$OUT/%s:"):$JAZZER_API_PATH 45 46 # All .jar and .class files lie in the same directory as the fuzzer at runtime. 47 RUNTIME_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "\$this_dir/%s:"):\$this_dir 48 49 for fuzzer in $(find $SRC -iname "$project"'*Fuzzer.java'); do 50 fuzzer_basename=$(basename -s .java $fuzzer) 51 javac -cp $BUILD_CLASSPATH $fuzzer 52 cp $SRC/$fuzzer_basename.class $OUT/ 53 54 # Create an execution wrapper that executes Jazzer with the correct arguments. 55 echo "#!/bin/sh 56# LLVMFuzzerTestOneInput for fuzzer detection. 57this_dir=\$(dirname \"\$0\") 58LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\":\$this_dir \ 59\$this_dir/jazzer_driver --agent_path=\$this_dir/jazzer_agent_deploy.jar \ 60--cp=$RUNTIME_CLASSPATH \ 61--target_class=$fuzzer_basename \ 62--jvm_args=\"-Xmx2048m;-Djava.awt.headless=true\" \ 63\$@" > $OUT/$fuzzer_basename 64 chmod +x $OUT/$fuzzer_basename 65 done 66done 67