[go: nahoru, domu]

blob: 5590942f45f89208d3d398b6873de63e9f5ce396 [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 Gaston3fa62a82023-10-25 15:00:25 -040041printTimestamps=false
42timestampsArgument="-Pandroidx.printTimestamps"
43if [[ " ${@} " =~ " ${timestampsArgument} " ]]; then
44 printTimestamps=true
45fi
Jeff Gaston41b90222020-08-18 11:09:55 -040046
Jeff Gaston86b3c822021-11-16 12:32:49 -050047# identify some filepaths
Jeff Gaston41b90222020-08-18 11:09:55 -040048SCRIPT_PATH="$(cd $(dirname $0) && pwd)"
Jeff Gaston8f9e8402020-09-02 11:09:18 -040049CHECKOUT="$(cd "$SCRIPT_PATH/../../.." && pwd)"
Jeff Gaston41b90222020-08-18 11:09:55 -040050if [ -n "$DIST_DIR" ]; then
Jeff Gaston639e7f92020-11-04 11:35:12 -050051 LOG_DIR="$DIST_DIR/logs"
Jeff Gaston41b90222020-08-18 11:09:55 -040052else
Jeff Gaston639e7f92020-11-04 11:35:12 -050053 LOG_DIR="$CHECKOUT/out/dist/logs"
Jeff Gaston41b90222020-08-18 11:09:55 -040054fi
55
56mkdir -p "$LOG_DIR"
57logFile="$LOG_DIR/gradle.log"
Jeff Gaston639e7f92020-11-04 11:35:12 -050058
59# Move any preexisting $logFile to make room for a new one
60# After moving $logFile several times it eventually gets deleted
61function 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 Gaston86b3c822021-11-16 12:32:49 -050069rotateLogs
Jeff Gaston639e7f92020-11-04 11:35:12 -050070
Jeff Gaston7dcd83f2020-08-24 14:52:09 -040071# Save OUT_DIR and some other variables into the log file so build_log_simplifier.py can
72# identify them later
73echo "OUT_DIR=$OUT_DIR" | tee -a $logFile
74if [ "$DIST_DIR" == "" ]; then
75 DIST_DIR="$OUT_DIR/dist"
76fi
77echo "DIST_DIR=$DIST_DIR" | tee -a $logFile
Jeff Gaston8f9e8402020-09-02 11:09:18 -040078echo "CHECKOUT=$CHECKOUT" | tee -a $logFile
Jeff Gastoned941e52020-10-30 14:35:37 -040079if [ "$GRADLE_USER_HOME" == "" ]; then
80 GRADLE_USER_HOME="$(cd && pwd)/.gradle"
81fi
82echo "GRADLE_USER_HOME=$GRADLE_USER_HOME" | tee -a $logFile
Jeff Gaston41b90222020-08-18 11:09:55 -040083programName="$1"
84shift
Jeff Gaston86b3c822021-11-16 12:32:49 -050085
Jeff Gaston3fa62a82023-10-25 15:00:25 -040086if [ "$printTimestamps" == "true" ]; then
87 # this program adds a timestamp to each line of input, and echos the result
88 timestampPrinter="$SCRIPT_PATH/ts.py"
89else
90 # this program just echos its input
91 timestampPrinter=cat
92fi
93
94if "$programName" "$@" > >(tee -a "$logFile" | "$timestampPrinter") 2>&1; then
Jeff Gastone4b4b872020-08-25 09:02:13 -040095 if [ "$validateNoUnrecognizedMessagesOnSuccess" == "true" ]; then
Jeff Gastondc52fd52020-10-01 09:48:07 -040096 if $SCRIPT_PATH/build_log_simplifier.py --validate $logFile >&2; then
Jeff Gastona3b73b12020-10-16 12:49:02 -040097 echo No unrecognized messages found in build log
Jeff Gastondc52fd52020-10-01 09:48:07 -040098 else
Jeff Gastondc52fd52020-10-01 09:48:07 -040099 exit 1
100 fi
Jeff Gaston41b90222020-08-18 11:09:55 -0400101 fi
102else
Jeff Gaston4ac304c2022-06-16 14:35:30 -0400103 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 Gaston41b90222020-08-18 11:09:55 -0400115 exit 1
116fi