Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # The following logging mechanisms are to be used in bash functions of recipes. |
| 2 | # They are intended to map one to one in intention and output format with the |
| 3 | # python recipe logging functions of a similar naming convention: bb.plain(), |
| 4 | # bb.note(), etc. |
| 5 | |
| 6 | LOGFIFO = "${T}/fifo.${@os.getpid()}" |
| 7 | |
| 8 | # Print the output exactly as it is passed in. Typically used for output of |
| 9 | # tasks that should be seen on the console. Use sparingly. |
| 10 | # Output: logs console |
| 11 | bbplain() { |
| 12 | if [ -p ${LOGFIFO} ] ; then |
| 13 | printf "%b\0" "bbplain $*" > ${LOGFIFO} |
| 14 | else |
| 15 | echo "$*" |
| 16 | fi |
| 17 | } |
| 18 | |
| 19 | # Notify the user of a noteworthy condition. |
| 20 | # Output: logs |
| 21 | bbnote() { |
| 22 | if [ -p ${LOGFIFO} ] ; then |
| 23 | printf "%b\0" "bbnote $*" > ${LOGFIFO} |
| 24 | else |
| 25 | echo "NOTE: $*" |
| 26 | fi |
| 27 | } |
| 28 | |
| 29 | # Print a warning to the log. Warnings are non-fatal, and do not |
| 30 | # indicate a build failure. |
| 31 | # Output: logs console |
| 32 | bbwarn() { |
| 33 | if [ -p ${LOGFIFO} ] ; then |
| 34 | printf "%b\0" "bbwarn $*" > ${LOGFIFO} |
| 35 | else |
| 36 | echo "WARNING: $*" |
| 37 | fi |
| 38 | } |
| 39 | |
| 40 | # Print an error to the log. Errors are non-fatal in that the build can |
| 41 | # continue, but they do indicate a build failure. |
| 42 | # Output: logs console |
| 43 | bberror() { |
| 44 | if [ -p ${LOGFIFO} ] ; then |
| 45 | printf "%b\0" "bberror $*" > ${LOGFIFO} |
| 46 | else |
| 47 | echo "ERROR: $*" |
| 48 | fi |
| 49 | } |
| 50 | |
| 51 | # Print a fatal error to the log. Fatal errors indicate build failure |
| 52 | # and halt the build, exiting with an error code. |
| 53 | # Output: logs console |
| 54 | bbfatal() { |
| 55 | if [ -p ${LOGFIFO} ] ; then |
| 56 | printf "%b\0" "bbfatal $*" > ${LOGFIFO} |
| 57 | else |
| 58 | echo "ERROR: $*" |
| 59 | fi |
| 60 | exit 1 |
| 61 | } |
| 62 | |
| 63 | # Like bbfatal, except prevents the suppression of the error log by |
| 64 | # bitbake's UI. |
| 65 | # Output: logs console |
| 66 | bbfatal_log() { |
| 67 | if [ -p ${LOGFIFO} ] ; then |
| 68 | printf "%b\0" "bbfatal_log $*" > ${LOGFIFO} |
| 69 | else |
| 70 | echo "ERROR: $*" |
| 71 | fi |
| 72 | exit 1 |
| 73 | } |
| 74 | |
| 75 | # Print debug messages. These are appropriate for progress checkpoint |
| 76 | # messages to the logs. Depending on the debug log level, they may also |
| 77 | # go to the console. |
| 78 | # Output: logs console |
| 79 | # Usage: bbdebug 1 "first level debug message" |
| 80 | # bbdebug 2 "second level debug message" |
| 81 | bbdebug() { |
| 82 | USAGE='Usage: bbdebug [123] "message"' |
| 83 | if [ $# -lt 2 ]; then |
| 84 | bbfatal "$USAGE" |
| 85 | fi |
| 86 | |
| 87 | # Strip off the debug level and ensure it is an integer |
| 88 | DBGLVL=$1; shift |
| 89 | NONDIGITS=$(echo "$DBGLVL" | tr -d [:digit:]) |
| 90 | if [ "$NONDIGITS" ]; then |
| 91 | bbfatal "$USAGE" |
| 92 | fi |
| 93 | |
| 94 | # All debug output is printed to the logs |
| 95 | if [ -p ${LOGFIFO} ] ; then |
| 96 | printf "%b\0" "bbdebug $DBGLVL $*" > ${LOGFIFO} |
| 97 | else |
| 98 | echo "DEBUG: $*" |
| 99 | fi |
| 100 | } |
| 101 | |