From d23bea74a9ab9de30c195839fff0a86fca41d43b Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Thu, 31 Aug 2023 14:11:40 +0200 Subject: [PATCH 1/2] deploy: Fix `jazzer` not being executable Since 4d0c74b18aa73f95be05e3bb9aa6e9c7ab8f9726, the Jazzer jar lacked a `Main-Class` attribute. --- deploy/BUILD.bazel | 15 ++++++++ deploy/jazzer_version_test.sh | 35 +++++++++++++++++++ .../com/code_intelligence/jazzer/BUILD.bazel | 4 ++- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 deploy/jazzer_version_test.sh diff --git a/deploy/BUILD.bazel b/deploy/BUILD.bazel index c6d3bbc08..d5e572a61 100644 --- a/deploy/BUILD.bazel +++ b/deploy/BUILD.bazel @@ -90,6 +90,21 @@ java_export( ], ) +sh_test( + name = "jazzer_version_test", + srcs = ["jazzer_version_test.sh"], + data = [ + ":jazzer", + "@bazel_tools//tools/jdk:current_java_runtime", + ], + env = { + "JAVA_EXECPATH": "$(JAVA)", + "JAZZER_RLOCATIONPATH": "$(rlocationpath :jazzer)", + }, + toolchains = ["@bazel_tools//tools/jdk:current_java_runtime"], + deps = ["@bazel_tools//tools/bash/runfiles"], +) + [ sh_test( name = artifact + "_artifact_test", diff --git a/deploy/jazzer_version_test.sh b/deploy/jazzer_version_test.sh new file mode 100755 index 000000000..8cb9af356 --- /dev/null +++ b/deploy/jazzer_version_test.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# Copyright 2023 Code Intelligence GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# --- begin runfiles.bash initialization v3 --- +# Copy-pasted from the Bazel Bash runfiles library v3. +set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash +source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ + source "$0.runfiles/$f" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ + { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e +# --- end runfiles.bash initialization v3 --- + +# JAZZER_EXECPATH is a path of the form "external/remotejdk_17/bin/java". We need to strip of the +# leading external to get a path we can pass to rlocation. +java_rlocationpath=$(echo "$JAVA_EXECPATH" | cut -d/ -f2-) +java=$(rlocation "$java_rlocationpath") +jazzer=$(rlocation "$JAZZER_RLOCATIONPATH") +[ -f "$jazzer" ] || exit 1 +jazzer_version_output=$("$java" -jar "$jazzer" --version 2>&1) +echo "$jazzer_version_output" +echo "$jazzer_version_output" | tr -d '\n' | grep -q '^Jazzer v[0-9.]*$' || exit 1 diff --git a/src/main/java/com/code_intelligence/jazzer/BUILD.bazel b/src/main/java/com/code_intelligence/jazzer/BUILD.bazel index f000fa309..a5b73bf45 100644 --- a/src/main/java/com/code_intelligence/jazzer/BUILD.bazel +++ b/src/main/java/com/code_intelligence/jazzer/BUILD.bazel @@ -63,7 +63,9 @@ java_binary( "//src/main/java/com/code_intelligence/jazzer/api:api_deploy_env", "//src/main/java/com/code_intelligence/jazzer/runtime:jazzer_bootstrap_env", ], - main_class = "com.code_intelligence.jazzer.Jazzer", + deploy_manifest_lines = [ + "Main-Class: com.code_intelligence.jazzer.Jazzer", + ], runtime_deps = [":jazzer_lib"], ) From 4ee7d7aec94d00b2c9f1aca5707b877710b7ac6e Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Thu, 31 Aug 2023 13:55:45 +0200 Subject: [PATCH 2/2] deploy: Verify that `jazzer.jar` is a valid Jazzer jar Release v0.20.0 failed because the zip containing the Jazzer jar was passed in instead of the Jazzer jar itself. --- deploy/BUILD.bazel | 4 ++++ deploy/deploy.sh | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/deploy/BUILD.bazel b/deploy/BUILD.bazel index d5e572a61..a598fd7eb 100644 --- a/deploy/BUILD.bazel +++ b/deploy/BUILD.bazel @@ -20,6 +20,10 @@ sh_binary( name = "deploy", srcs = ["deploy.sh"], args = [JAZZER_COORDINATES], + data = ["@bazel_tools//tools/jdk:current_host_java_runtime"], + env = {"JAVA_EXECPATH": "$(JAVA)"}, + toolchains = ["@bazel_tools//tools/jdk:current_host_java_runtime"], + deps = ["@bazel_tools//tools/bash/runfiles"], ) java_export( diff --git a/deploy/deploy.sh b/deploy/deploy.sh index edf8b4071..ffd45455f 100755 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash # Copyright 2022 Code Intelligence GmbH # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,6 +33,24 @@ JAZZER_COORDINATES=$1 [ ! -f "${JAZZER_JAR_PATH}" ] && \ fail "JAZZER_JAR_PATH does not exist at '$JAZZER_JAR_PATH'" +# --- begin runfiles.bash initialization v3 --- +# Copy-pasted from the Bazel Bash runfiles library v3. +set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash +source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ + source "$0.runfiles/$f" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ + { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e +# --- end runfiles.bash initialization v3 --- + +# JAZZER_EXECPATH is a path of the form "external/remotejdk_17/bin/java". We need to strip of the +# leading external to get a path we can pass to rlocation. +java_rlocationpath=$(echo "$JAVA_EXECPATH" | cut -d/ -f2-) +java=$(rlocation "$java_rlocationpath") +"$java" -jar "${JAZZER_JAR_PATH}" --version 2>&1 | grep '^Jazzer v' || \ + fail "JAZZER_JAR_PATH is not a valid jazzer.jar" + MAVEN_REPO=https://oss.sonatype.org/service/local/staging/deploy/maven2 # The Jazzer jar itself bundles native libraries for multiple architectures and thus can't be built