1#!/bin/bash 2# Runs tests that are defined in the protobuf crate using Cargo. 3# This is not a hermetic task because Cargo will fetch the needed 4# dependencies from crates.io 5 6# --- begin runfiles.bash initialization --- 7# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). 8set -euo pipefail 9if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then 10 if [[ -f "$0.runfiles_manifest" ]]; then 11 export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" 12 elif [[ -f "$0.runfiles/MANIFEST" ]]; then 13 export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" 14 elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then 15 export RUNFILES_DIR="$0.runfiles" 16 fi 17fi 18if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then 19 source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" 20elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then 21 source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ 22 "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" 23else 24 echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" 25 exit 1 26fi 27# --- end runfiles.bash initialization --- 28 29TMP_DIR=$(mktemp -d) 30trap 'rm -rf -- "$TMP_DIR"' EXIT 31 32CARGO_HOME=$TMP_DIR/cargo_home 33mkdir $CARGO_HOME 34 35CRATE_ROOT=$TMP_DIR/protobuf 36mkdir $CRATE_ROOT 37 38PROTOBUF_ZIP=$(rlocation com_google_protobuf/rust/rust_crate.zip) 39 40unzip -d $CRATE_ROOT $PROTOBUF_ZIP 41 42CODEGEN_ROOT=$TMP_DIR/protobuf_codegen 43mkdir $CODEGEN_ROOT 44 45CODEGEN_ZIP=$(rlocation com_google_protobuf/rust/codegen_crate.zip) 46 47unzip -d $CODEGEN_ROOT $CODEGEN_ZIP 48 49EXAMPLE_ROOT=$TMP_DIR/codegen_example 50mkdir $EXAMPLE_ROOT 51 52EXAMPLE_ZIP=$(rlocation com_google_protobuf/rust/codegen_example.zip) 53 54unzip -d $EXAMPLE_ROOT $EXAMPLE_ZIP 55 56cd $CRATE_ROOT 57# Run all tests except doctests 58CARGO_HOME=$CARGO_HOME cargo test --lib --bins --tests 59 60cd $CODEGEN_ROOT 61CARGO_HOME=$CARGO_HOME cargo test --lib --bins --tests 62 63PROTOC=$(rlocation com_google_protobuf/protoc) 64PROTOC_GEN_UPB_MINITABLE=$(rlocation com_google_protobuf/upb_generator/minitable/protoc-gen-upb_minitable) 65 66cd $EXAMPLE_ROOT 67CARGO_HOME=$CARGO_HOME PROTOC=$PROTOC PROTOC_GEN_UPB_MINITABLE=$PROTOC_GEN_UPB_MINITABLE cargo test 68