@@ -106,18 +106,18 @@ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/
106106
107107# Export the env variables required for subprocesses to find their runfiles.
108108runfiles_export_envvars
109+ """
109110
111+ script_format_part = """
110112# Determine the path to load libjvm.so from, either relative to the location of
111113# the java binary or to $JAVA_HOME, if set. On OSS-Fuzz, the path is provided in
112114# JVM_LD_LIBRARY_PATH.
113- JAVA_BIN=$(python3 -c 'import os, sys; print(os.path. realpath(sys.argv[1]))' "$(which java)")
114- JAVA_HOME=${JAVA_HOME:-${JAVA_BIN%/bin/java}}
115+ JAVA_BIN=$("$(rlocation { realpath})" "$(which java)")
116+ JAVA_HOME=${{ JAVA_HOME:-${{ JAVA_BIN%/bin/java}} }}
115117# The location of libjvm.so relative to the JDK differs between JDK <= 8 and 9+.
116- JVM_LD_LIBRARY_PATH=${JVM_LD_LIBRARY_PATH:-"$JAVA_HOME/lib/server:$JAVA_HOME/lib/amd64/server"}
117- export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$JVM_LD_LIBRARY_PATH
118- """
118+ JVM_LD_LIBRARY_PATH=${{JVM_LD_LIBRARY_PATH:-"$JAVA_HOME/lib/server:$JAVA_HOME/lib/amd64/server"}}
119+ export LD_LIBRARY_PATH=${{LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}}$JVM_LD_LIBRARY_PATH
119120
120- script_format_part = """
121121source "$(rlocation {sanitizer_options})"
122122exec "$(rlocation {driver})" \
123123 --agent_path="$(rlocation {agent})" \
@@ -136,6 +136,7 @@ exec "$(rlocation {driver})" \
136136 deploy_jar = runfile_path (ctx , ctx .file .target_deploy_jar ),
137137 driver = runfile_path (ctx , driver ),
138138 native_dirs = ":" .join (native_dirs ),
139+ realpath = runfile_path (ctx , ctx .executable ._realpath ),
139140 sanitizer_options = runfile_path (ctx , ctx .file .sanitizer_options ),
140141 )
141142 ctx .actions .write (script , script_content , is_executable = True )
@@ -232,6 +233,9 @@ def _jazzer_fuzz_binary_impl(ctx):
232233
233234 runfiles = runfiles .merge (ctx .runfiles ([ctx .file .sanitizer_options ]))
234235
236+ runfiles = runfiles .merge (ctx .runfiles ([ctx .executable ._realpath ]))
237+ runfiles = runfiles .merge (ctx .attr ._realpath [DefaultInfo ].default_runfiles )
238+
235239 script = _jazzer_fuzz_binary_script (ctx , native_libs , driver )
236240 return [DefaultInfo (executable = script , runfiles = runfiles )]
237241
@@ -283,6 +287,12 @@ Rule that creates a binary that invokes Jazzer on the specified target.
283287 allow_single_file = [".jar" ],
284288 mandatory = True ,
285289 ),
290+ "_realpath" : attr .label (
291+ doc = "The realpath util needed by the binary script." ,
292+ default = "//fuzzing/tools:realpath" ,
293+ executable = True ,
294+ cfg = "target" ,
295+ ),
286296 "_allowlist_function_transition" : attr .label (
287297 default = "@bazel_tools//tools/allowlists/function_transition_allowlist" ,
288298 ),
0 commit comments