logging.bbclass 2.5 KB

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