kythe.io@v0.0.68-0.20240422202219-7225dbc01741/tools/build_rules/verifier_test/verifier_test.sh.in (about) 1 #!/bin/bash -e 2 # 3 # Copyright 2016 The Kythe Authors. All rights reserved. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # 17 set -euo pipefail 18 export RUNFILES_DIR="${RUNFILES_DIR:-${TEST_SRCDIR:-${0}.runfiles}}" 19 export WORKSPACE_NAME="${TEST_WORKSPACE:-@WORKSPACE_NAME@}" 20 cd "${RUNFILES_DIR}/${WORKSPACE_NAME}" 21 22 ENTRIES=(@ENTRIES@) 23 ENTRIES_GZ=(@ENTRIES_GZ@) 24 25 # Dir that will contain output files useful for debugging: logs, JSON entries. 26 # It will use TEST_UNDECLARED_OUTPUTS_DIR if defined or TEST_TMPDIR otherwise. 27 TEST_OUT_DIR="${TEST_UNDECLARED_OUTPUTS_DIR:-$TEST_TMPDIR}" 28 29 # Copy logs passed in providers from other targets. INDEXER_LOGS is a list of 30 # 'log:outputname' strings. 31 for log in @INDEXER_LOGS@; do 32 parts=(${log//:/ }) 33 echo Copying file "${parts[0]}" to "${parts[1]}" >&2 34 cat "${parts[0]}" > "${TEST_OUT_DIR}/${parts[1]}" 35 done 36 37 # Convert entries to JSON and store later for debugging. 38 # ENTRIES_TO_LOG is a list of 'entryfile:outputname' strings. 39 for entry in @ENTRIES_TO_LOG@; do 40 parts=(${entry//:/ }) 41 @ENTRYSTREAM@ --write_format=json < "${parts[0]}" >> "${TEST_OUT_DIR}/${parts[1]}" 42 done 43 44 # Run indexer shell commands, if any. For each indexer we store its logs to 45 # a separate file in TEST_OUT_DIR. 46 ENTRIES_FROM_INLINE_INDEXERS=() 47 for indexer in @INDEXERS@; do 48 parts=(${indexer//:/ }) 49 log="${TEST_OUT_DIR}/${parts[1]}.log" 50 # Save entries to in tmp dir and not to TEST_OUT_DIR. Some indexers, e.g. 51 # C++ that runs inline, produce 800MB+ of entries. We don't want to log them 52 # in undeclared outputs which might be stored for a long time. 53 entries="${TEST_TMPDIR}/${parts[1]}.entries" 54 echo "Running indexer: ${parts[0]}. Log file ${parts[1]}.log" >&2 55 ${parts[0]} > "$entries" 2> "$log" 56 ENTRIES_FROM_INLINE_INDEXERS+=("$entries") 57 done 58 59 echo "Running verifier" >&2 60 ( 61 if (( ${#ENTRIES_FROM_INLINE_INDEXERS[@]} )); then cat "${ENTRIES_FROM_INLINE_INDEXERS[@]}"; fi 62 if (( ${#ENTRIES[@]} )); then cat "${ENTRIES[@]}"; fi 63 if (( ${#ENTRIES_GZ[@]} )); then gunzip -c "${ENTRIES_GZ[@]}"; fi 64 ) | ( 65 if [[ -z "@REWRITE@" ]]; then 66 @MARKEDSOURCE@ --rewrite 67 else 68 cat 69 fi 70 ) | ( 71 if @INVERT@ @VERIFIER@ @ARGS@ "$@"; then exit 0; else exit 1; fi 72 )