logging.bbclass 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. # Notify the user of a noteworthy condition.
  31. # Output: logs console
  32. bbverbnote() {
  33. if [ -p ${LOGFIFO} ]; then
  34. printf "%b\0" "bbverbnote $*" > ${LOGFIFO}
  35. else
  36. echo "NOTE: $*"
  37. fi
  38. }
  39. # Print a warning to the log. Warnings are non-fatal, and do not
  40. # indicate a build failure.
  41. # Output: logs console
  42. bbwarn() {
  43. if [ -p ${LOGFIFO} ] ; then
  44. printf "%b\0" "bbwarn $*" > ${LOGFIFO}
  45. else
  46. echo "WARNING: $*"
  47. fi
  48. }
  49. # Print an error to the log. Errors are non-fatal in that the build can
  50. # continue, but they do indicate a build failure.
  51. # Output: logs console
  52. bberror() {
  53. if [ -p ${LOGFIFO} ] ; then
  54. printf "%b\0" "bberror $*" > ${LOGFIFO}
  55. else
  56. echo "ERROR: $*"
  57. fi
  58. }
  59. # Print a fatal error to the log. Fatal errors indicate build failure
  60. # and halt the build, exiting with an error code.
  61. # Output: logs console
  62. bbfatal() {
  63. if [ -p ${LOGFIFO} ] ; then
  64. printf "%b\0" "bbfatal $*" > ${LOGFIFO}
  65. else
  66. echo "ERROR: $*"
  67. fi
  68. exit 1
  69. }
  70. # Like bbfatal, except prevents the suppression of the error log by
  71. # bitbake's UI.
  72. # Output: logs console
  73. bbfatal_log() {
  74. if [ -p ${LOGFIFO} ] ; then
  75. printf "%b\0" "bbfatal_log $*" > ${LOGFIFO}
  76. else
  77. echo "ERROR: $*"
  78. fi
  79. exit 1
  80. }
  81. # Print debug messages. These are appropriate for progress checkpoint
  82. # messages to the logs. Depending on the debug log level, they may also
  83. # go to the console.
  84. # Output: logs console
  85. # Usage: bbdebug 1 "first level debug message"
  86. # bbdebug 2 "second level debug message"
  87. bbdebug() {
  88. USAGE='Usage: bbdebug [123] "message"'
  89. if [ $# -lt 2 ]; then
  90. bbfatal "$USAGE"
  91. fi
  92. # Strip off the debug level and ensure it is an integer
  93. DBGLVL=$1; shift
  94. NONDIGITS=$(echo "$DBGLVL" | tr -d "[:digit:]")
  95. if [ "$NONDIGITS" ]; then
  96. bbfatal "$USAGE"
  97. fi
  98. # All debug output is printed to the logs
  99. if [ -p ${LOGFIFO} ] ; then
  100. printf "%b\0" "bbdebug $DBGLVL $*" > ${LOGFIFO}
  101. else
  102. echo "DEBUG: $*"
  103. fi
  104. }