blob: b55ad128f0df4b954661354ba647a381298a1012 [file] [log] [blame]
Jeff Gaston41b90222020-08-18 11:09:55 -04001#!/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
17set -e
18
19usage() {
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 Gastone4b4b872020-08-25 09:02:13 -040024 echo "-Pandroidx.validateNoUnrecognizedMessages"
Jeff Gaston41b90222020-08-18 11:09:55 -040025 echo " Run build_log_simplifier.py --validate on success to confirm that the build generated no unrecognized messages"
26 exit 1
27}
28
29if [[ "$1" == "" ]]; then
30 usage
31fi
32
Jeff Gastone4b4b872020-08-25 09:02:13 -040033validateNoUnrecognizedMessagesOnSuccess=false
Jeff Gastondc52fd52020-10-01 09:48:07 -040034validateArgument="-Pandroidx.validateNoUnrecognizedMessages"
35if [[ " ${@} " =~ " $validateArgument " ]]; then
Jeff Gastone4b4b872020-08-25 09:02:13 -040036 validateNoUnrecognizedMessagesOnSuccess=true
Jeff Gaston41b90222020-08-18 11:09:55 -040037fi
Jeff Gaston27fcfa02021-01-15 15:32:37 -050038if [[ " ${@} " =~ " ${validateArgument}=false " ]]; then
39 validateNoUnrecognizedMessagesOnSuccess=false
40fi
Jeff Gaston41b90222020-08-18 11:09:55 -040041
Jeff Gaston86b3c822021-11-16 12:32:49 -050042# identify some filepaths
Jeff Gaston41b90222020-08-18 11:09:55 -040043SCRIPT_PATH="$(cd $(dirname $0) && pwd)"
Jeff Gaston8f9e8402020-09-02 11:09:18 -040044CHECKOUT="$(cd "$SCRIPT_PATH/../../.." && pwd)"
Jeff Gaston41b90222020-08-18 11:09:55 -040045if [ -n "$DIST_DIR" ]; then
Jeff Gaston639e7f92020-11-04 11:35:12 -050046 LOG_DIR="$DIST_DIR/logs"
Jeff Gaston41b90222020-08-18 11:09:55 -040047else
Jeff Gaston639e7f92020-11-04 11:35:12 -050048 LOG_DIR="$CHECKOUT/out/dist/logs"
Jeff Gaston41b90222020-08-18 11:09:55 -040049fi
50
51mkdir -p "$LOG_DIR"
52logFile="$LOG_DIR/gradle.log"
Jeff Gaston639e7f92020-11-04 11:35:12 -050053
54# Move any preexisting $logFile to make room for a new one
55# After moving $logFile several times it eventually gets deleted
56function 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 Gaston86b3c822021-11-16 12:32:49 -050064rotateLogs
Jeff Gaston639e7f92020-11-04 11:35:12 -050065
Jeff Gaston7dcd83f2020-08-24 14:52:09 -040066# Save OUT_DIR and some other variables into the log file so build_log_simplifier.py can
67# identify them later
68echo "OUT_DIR=$OUT_DIR" | tee -a $logFile
69if [ "$DIST_DIR" == "" ]; then
70 DIST_DIR="$OUT_DIR/dist"
71fi
72echo "DIST_DIR=$DIST_DIR" | tee -a $logFile
Jeff Gaston8f9e8402020-09-02 11:09:18 -040073echo "CHECKOUT=$CHECKOUT" | tee -a $logFile
Jeff Gastoned941e52020-10-30 14:35:37 -040074if [ "$GRADLE_USER_HOME" == "" ]; then
75 GRADLE_USER_HOME="$(cd && pwd)/.gradle"
76fi
77echo "GRADLE_USER_HOME=$GRADLE_USER_HOME" | tee -a $logFile
Jeff Gaston41b90222020-08-18 11:09:55 -040078programName="$1"
79shift
Jeff Gaston86b3c822021-11-16 12:32:49 -050080
Jeff Gaston41b90222020-08-18 11:09:55 -040081if "$programName" "$@" > >(tee -a "$logFile") 2>&1; then
Jeff Gastone4b4b872020-08-25 09:02:13 -040082 if [ "$validateNoUnrecognizedMessagesOnSuccess" == "true" ]; then
Jeff Gastondc52fd52020-10-01 09:48:07 -040083 if $SCRIPT_PATH/build_log_simplifier.py --validate $logFile >&2; then
Jeff Gastona3b73b12020-10-16 12:49:02 -040084 echo No unrecognized messages found in build log
Jeff Gastondc52fd52020-10-01 09:48:07 -040085 else
Jeff Gastondc52fd52020-10-01 09:48:07 -040086 exit 1
87 fi
Jeff Gaston41b90222020-08-18 11:09:55 -040088 fi
89else
Jeff Gaston4ac304c2022-06-16 14:35:30 -040090 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 Gaston41b90222020-08-18 11:09:55 -0400102 exit 1
103fi