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 | 3fa62a8 | 2023-10-25 15:00:25 -0400 | [diff] [blame] | 41 | printTimestamps=false |
| 42 | timestampsArgument="-Pandroidx.printTimestamps" |
| 43 | if [[ " ${@} " =~ " ${timestampsArgument} " ]]; then |
| 44 | printTimestamps=true |
| 45 | fi |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 46 | |
Jeff Gaston | 86b3c82 | 2021-11-16 12:32:49 -0500 | [diff] [blame] | 47 | # identify some filepaths |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 48 | SCRIPT_PATH="$(cd $(dirname $0) && pwd)" |
Jeff Gaston | 8f9e840 | 2020-09-02 11:09:18 -0400 | [diff] [blame] | 49 | CHECKOUT="$(cd "$SCRIPT_PATH/../../.." && pwd)" |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 50 | if [ -n "$DIST_DIR" ]; then |
Jeff Gaston | 639e7f9 | 2020-11-04 11:35:12 -0500 | [diff] [blame] | 51 | LOG_DIR="$DIST_DIR/logs" |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 52 | else |
Jeff Gaston | 639e7f9 | 2020-11-04 11:35:12 -0500 | [diff] [blame] | 53 | LOG_DIR="$CHECKOUT/out/dist/logs" |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 54 | fi |
| 55 | |
| 56 | mkdir -p "$LOG_DIR" |
| 57 | logFile="$LOG_DIR/gradle.log" |
Jeff Gaston | 639e7f9 | 2020-11-04 11:35:12 -0500 | [diff] [blame] | 58 | |
| 59 | # Move any preexisting $logFile to make room for a new one |
| 60 | # After moving $logFile several times it eventually gets deleted |
| 61 | function rotateLogs() { |
| 62 | iPlus1="10" |
| 63 | for i in $(seq 9 -1 1); do |
| 64 | mv "$LOG_DIR/gradle.${i}.log" "$LOG_DIR/gradle.${iPlus1}.log" 2>/dev/null || true |
| 65 | iPlus1=$i |
| 66 | done |
| 67 | mv $logFile "$LOG_DIR/gradle.1.log" 2>/dev/null || true |
| 68 | } |
Jeff Gaston | 86b3c82 | 2021-11-16 12:32:49 -0500 | [diff] [blame] | 69 | rotateLogs |
Jeff Gaston | 639e7f9 | 2020-11-04 11:35:12 -0500 | [diff] [blame] | 70 | |
Jeff Gaston | 7dcd83f | 2020-08-24 14:52:09 -0400 | [diff] [blame] | 71 | # Save OUT_DIR and some other variables into the log file so build_log_simplifier.py can |
| 72 | # identify them later |
| 73 | echo "OUT_DIR=$OUT_DIR" | tee -a $logFile |
| 74 | if [ "$DIST_DIR" == "" ]; then |
| 75 | DIST_DIR="$OUT_DIR/dist" |
| 76 | fi |
| 77 | echo "DIST_DIR=$DIST_DIR" | tee -a $logFile |
Jeff Gaston | 8f9e840 | 2020-09-02 11:09:18 -0400 | [diff] [blame] | 78 | echo "CHECKOUT=$CHECKOUT" | tee -a $logFile |
Jeff Gaston | ed941e5 | 2020-10-30 14:35:37 -0400 | [diff] [blame] | 79 | if [ "$GRADLE_USER_HOME" == "" ]; then |
| 80 | GRADLE_USER_HOME="$(cd && pwd)/.gradle" |
| 81 | fi |
| 82 | echo "GRADLE_USER_HOME=$GRADLE_USER_HOME" | tee -a $logFile |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 83 | programName="$1" |
| 84 | shift |
Jeff Gaston | 86b3c82 | 2021-11-16 12:32:49 -0500 | [diff] [blame] | 85 | |
Jeff Gaston | 3fa62a8 | 2023-10-25 15:00:25 -0400 | [diff] [blame] | 86 | if [ "$printTimestamps" == "true" ]; then |
| 87 | # this program adds a timestamp to each line of input, and echos the result |
| 88 | timestampPrinter="$SCRIPT_PATH/ts.py" |
| 89 | else |
| 90 | # this program just echos its input |
| 91 | timestampPrinter=cat |
| 92 | fi |
| 93 | |
| 94 | if "$programName" "$@" > >(tee -a "$logFile" | "$timestampPrinter") 2>&1; then |
Jeff Gaston | e4b4b87 | 2020-08-25 09:02:13 -0400 | [diff] [blame] | 95 | if [ "$validateNoUnrecognizedMessagesOnSuccess" == "true" ]; then |
Jeff Gaston | dc52fd5 | 2020-10-01 09:48:07 -0400 | [diff] [blame] | 96 | if $SCRIPT_PATH/build_log_simplifier.py --validate $logFile >&2; then |
Jeff Gaston | a3b73b1 | 2020-10-16 12:49:02 -0400 | [diff] [blame] | 97 | echo No unrecognized messages found in build log |
Jeff Gaston | dc52fd5 | 2020-10-01 09:48:07 -0400 | [diff] [blame] | 98 | else |
Jeff Gaston | dc52fd5 | 2020-10-01 09:48:07 -0400 | [diff] [blame] | 99 | exit 1 |
| 100 | fi |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 101 | fi |
| 102 | else |
Jeff Gaston | 4ac304c | 2022-06-16 14:35:30 -0400 | [diff] [blame] | 103 | echo >&2 |
| 104 | echo "############################################################################" >&2 |
| 105 | echo "Attempting to locate the relevant error messages via build_log_simplifier.py" >&2 |
| 106 | echo "############################################################################" >&2 |
| 107 | echo >&2 |
| 108 | # Try to identify the most relevant lines of output, and put them at the bottom of the |
| 109 | # output where they will also be placed into the build failure email. |
| 110 | # TODO: We may be able to stop cleaning up Gradle's output after Gradle can do this on its own: |
| 111 | # https://github.com/gradle/gradle/issues/1005 |
| 112 | # and https://github.com/gradle/gradle/issues/13090 |
| 113 | summaryLog="$LOG_DIR/error_summary.log" |
| 114 | $SCRIPT_PATH/build_log_simplifier.py $logFile | tee "$summaryLog" >&2 |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 115 | exit 1 |
| 116 | fi |