Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2020 The Android Open Source Project |
| 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 -e |
| 18 | |
| 19 | usage() { |
| 20 | echo "usage: $0 <command> <arguments> [options]" |
| 21 | echo |
| 22 | echo "Executes <command> <arguments> and then runs build_log_simplifier.py against its output" |
| 23 | echo |
Jeff Gaston | e4b4b87 | 2020-08-25 09:02:13 -0400 | [diff] [blame] | 24 | echo "-Pandroidx.validateNoUnrecognizedMessages" |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 25 | echo " Run build_log_simplifier.py --validate on success to confirm that the build generated no unrecognized messages" |
| 26 | exit 1 |
| 27 | } |
| 28 | |
| 29 | if [[ "$1" == "" ]]; then |
| 30 | usage |
| 31 | fi |
| 32 | |
Jeff Gaston | e4b4b87 | 2020-08-25 09:02:13 -0400 | [diff] [blame] | 33 | validateNoUnrecognizedMessagesOnSuccess=false |
Jeff Gaston | dc52fd5 | 2020-10-01 09:48:07 -0400 | [diff] [blame] | 34 | validateArgument="-Pandroidx.validateNoUnrecognizedMessages" |
| 35 | if [[ " ${@} " =~ " $validateArgument " ]]; then |
Jeff Gaston | e4b4b87 | 2020-08-25 09:02:13 -0400 | [diff] [blame] | 36 | validateNoUnrecognizedMessagesOnSuccess=true |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 37 | fi |
Jeff Gaston | 27fcfa0 | 2021-01-15 15:32:37 -0500 | [diff] [blame] | 38 | if [[ " ${@} " =~ " ${validateArgument}=false " ]]; then |
| 39 | validateNoUnrecognizedMessagesOnSuccess=false |
| 40 | fi |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 41 | |
Jeff Gaston | 86b3c82 | 2021-11-16 12:32:49 -0500 | [diff] [blame] | 42 | # identify some filepaths |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 43 | SCRIPT_PATH="$(cd $(dirname $0) && pwd)" |
Jeff Gaston | 8f9e840 | 2020-09-02 11:09:18 -0400 | [diff] [blame] | 44 | CHECKOUT="$(cd "$SCRIPT_PATH/../../.." && pwd)" |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 45 | if [ -n "$DIST_DIR" ]; then |
Jeff Gaston | 639e7f9 | 2020-11-04 11:35:12 -0500 | [diff] [blame] | 46 | LOG_DIR="$DIST_DIR/logs" |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 47 | else |
Jeff Gaston | 639e7f9 | 2020-11-04 11:35:12 -0500 | [diff] [blame] | 48 | LOG_DIR="$CHECKOUT/out/dist/logs" |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 49 | fi |
| 50 | |
| 51 | mkdir -p "$LOG_DIR" |
| 52 | logFile="$LOG_DIR/gradle.log" |
Jeff Gaston | 639e7f9 | 2020-11-04 11:35:12 -0500 | [diff] [blame] | 53 | |
| 54 | # Move any preexisting $logFile to make room for a new one |
| 55 | # After moving $logFile several times it eventually gets deleted |
| 56 | function rotateLogs() { |
| 57 | iPlus1="10" |
| 58 | for i in $(seq 9 -1 1); do |
| 59 | mv "$LOG_DIR/gradle.${i}.log" "$LOG_DIR/gradle.${iPlus1}.log" 2>/dev/null || true |
| 60 | iPlus1=$i |
| 61 | done |
| 62 | mv $logFile "$LOG_DIR/gradle.1.log" 2>/dev/null || true |
| 63 | } |
Jeff Gaston | 86b3c82 | 2021-11-16 12:32:49 -0500 | [diff] [blame] | 64 | rotateLogs |
Jeff Gaston | 639e7f9 | 2020-11-04 11:35:12 -0500 | [diff] [blame] | 65 | |
Jeff Gaston | 7dcd83f | 2020-08-24 14:52:09 -0400 | [diff] [blame] | 66 | # Save OUT_DIR and some other variables into the log file so build_log_simplifier.py can |
| 67 | # identify them later |
| 68 | echo "OUT_DIR=$OUT_DIR" | tee -a $logFile |
| 69 | if [ "$DIST_DIR" == "" ]; then |
| 70 | DIST_DIR="$OUT_DIR/dist" |
| 71 | fi |
| 72 | echo "DIST_DIR=$DIST_DIR" | tee -a $logFile |
Jeff Gaston | 8f9e840 | 2020-09-02 11:09:18 -0400 | [diff] [blame] | 73 | echo "CHECKOUT=$CHECKOUT" | tee -a $logFile |
Jeff Gaston | ed941e5 | 2020-10-30 14:35:37 -0400 | [diff] [blame] | 74 | if [ "$GRADLE_USER_HOME" == "" ]; then |
| 75 | GRADLE_USER_HOME="$(cd && pwd)/.gradle" |
| 76 | fi |
| 77 | echo "GRADLE_USER_HOME=$GRADLE_USER_HOME" | tee -a $logFile |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 78 | programName="$1" |
| 79 | shift |
Jeff Gaston | 86b3c82 | 2021-11-16 12:32:49 -0500 | [diff] [blame] | 80 | |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 81 | if "$programName" "$@" > >(tee -a "$logFile") 2>&1; then |
Jeff Gaston | e4b4b87 | 2020-08-25 09:02:13 -0400 | [diff] [blame] | 82 | if [ "$validateNoUnrecognizedMessagesOnSuccess" == "true" ]; then |
Jeff Gaston | dc52fd5 | 2020-10-01 09:48:07 -0400 | [diff] [blame] | 83 | if $SCRIPT_PATH/build_log_simplifier.py --validate $logFile >&2; then |
Jeff Gaston | a3b73b1 | 2020-10-16 12:49:02 -0400 | [diff] [blame] | 84 | echo No unrecognized messages found in build log |
Jeff Gaston | dc52fd5 | 2020-10-01 09:48:07 -0400 | [diff] [blame] | 85 | else |
Jeff Gaston | dc52fd5 | 2020-10-01 09:48:07 -0400 | [diff] [blame] | 86 | exit 1 |
| 87 | fi |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 88 | fi |
| 89 | else |
Jeff Gaston | 4ac304c | 2022-06-16 14:35:30 -0400 | [diff] [blame] | 90 | echo >&2 |
| 91 | echo "############################################################################" >&2 |
| 92 | echo "Attempting to locate the relevant error messages via build_log_simplifier.py" >&2 |
| 93 | echo "############################################################################" >&2 |
| 94 | echo >&2 |
| 95 | # Try to identify the most relevant lines of output, and put them at the bottom of the |
| 96 | # output where they will also be placed into the build failure email. |
| 97 | # TODO: We may be able to stop cleaning up Gradle's output after Gradle can do this on its own: |
| 98 | # https://github.com/gradle/gradle/issues/1005 |
| 99 | # and https://github.com/gradle/gradle/issues/13090 |
| 100 | summaryLog="$LOG_DIR/error_summary.log" |
| 101 | $SCRIPT_PATH/build_log_simplifier.py $logFile | tee "$summaryLog" >&2 |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 102 | exit 1 |
| 103 | fi |