Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # Collects debug information in order to create error report files. |
| 3 | # |
| 4 | # Copyright (C) 2013 Intel Corporation |
| 5 | # Author: Andreea Brandusa Proca <andreea.b.proca@intel.com> |
| 6 | # |
| 7 | # Licensed under the MIT license, see COPYING.MIT for details |
| 8 | |
| 9 | ERR_REPORT_DIR ?= "${LOG_DIR}/error-report" |
| 10 | |
| 11 | def errorreport_getdata(e): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 12 | import codecs |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | logpath = e.data.getVar('ERR_REPORT_DIR', True) |
| 14 | datafile = os.path.join(logpath, "error-report.txt") |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 15 | with codecs.open(datafile, 'r', 'utf-8') as f: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 16 | data = f.read() |
| 17 | return data |
| 18 | |
| 19 | def errorreport_savedata(e, newdata, file): |
| 20 | import json |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 21 | import codecs |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 22 | logpath = e.data.getVar('ERR_REPORT_DIR', True) |
| 23 | datafile = os.path.join(logpath, file) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 24 | with codecs.open(datafile, 'w', 'utf-8') as f: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 25 | json.dump(newdata, f, indent=4, sort_keys=True) |
| 26 | return datafile |
| 27 | |
| 28 | python errorreport_handler () { |
| 29 | import json |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 30 | import codecs |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 31 | |
| 32 | logpath = e.data.getVar('ERR_REPORT_DIR', True) |
| 33 | datafile = os.path.join(logpath, "error-report.txt") |
| 34 | |
| 35 | if isinstance(e, bb.event.BuildStarted): |
| 36 | bb.utils.mkdirhier(logpath) |
| 37 | data = {} |
| 38 | machine = e.data.getVar("MACHINE", True) |
| 39 | data['machine'] = machine |
| 40 | data['build_sys'] = e.data.getVar("BUILD_SYS", True) |
| 41 | data['nativelsb'] = e.data.getVar("NATIVELSBSTRING", True) |
| 42 | data['distro'] = e.data.getVar("DISTRO", True) |
| 43 | data['target_sys'] = e.data.getVar("TARGET_SYS", True) |
| 44 | data['failures'] = [] |
| 45 | data['component'] = e.getPkgs()[0] |
| 46 | data['branch_commit'] = base_detect_branch(e.data) + ": " + base_detect_revision(e.data) |
| 47 | lock = bb.utils.lockfile(datafile + '.lock') |
| 48 | errorreport_savedata(e, data, "error-report.txt") |
| 49 | bb.utils.unlockfile(lock) |
| 50 | |
| 51 | elif isinstance(e, bb.build.TaskFailed): |
| 52 | task = e.task |
| 53 | taskdata={} |
| 54 | log = e.data.getVar('BB_LOGFILE', True) |
| 55 | taskdata['package'] = e.data.expand("${PF}") |
| 56 | taskdata['task'] = task |
| 57 | if log: |
| 58 | try: |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 59 | logFile = codecs.open(log, 'r', 'utf-8') |
| 60 | logdata = logFile.read() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 61 | logFile.close() |
| 62 | except: |
| 63 | logdata = "Unable to read log file" |
| 64 | |
| 65 | else: |
| 66 | logdata = "No Log" |
| 67 | |
| 68 | # server will refuse failures longer than param specified in project.settings.py |
| 69 | # MAX_UPLOAD_SIZE = "5242880" |
| 70 | # use lower value, because 650 chars can be spent in task, package, version |
| 71 | max_logdata_size = 5242000 |
| 72 | # upload last max_logdata_size characters |
| 73 | if len(logdata) > max_logdata_size: |
| 74 | logdata = "..." + logdata[-max_logdata_size:] |
| 75 | taskdata['log'] = logdata |
| 76 | lock = bb.utils.lockfile(datafile + '.lock') |
| 77 | jsondata = json.loads(errorreport_getdata(e)) |
| 78 | jsondata['failures'].append(taskdata) |
| 79 | errorreport_savedata(e, jsondata, "error-report.txt") |
| 80 | bb.utils.unlockfile(lock) |
| 81 | |
| 82 | elif isinstance(e, bb.event.BuildCompleted): |
| 83 | lock = bb.utils.lockfile(datafile + '.lock') |
| 84 | jsondata = json.loads(errorreport_getdata(e)) |
| 85 | bb.utils.unlockfile(lock) |
| 86 | failures = jsondata['failures'] |
| 87 | if(len(failures) > 0): |
| 88 | filename = "error_report_" + e.data.getVar("BUILDNAME", True)+".txt" |
| 89 | datafile = errorreport_savedata(e, jsondata, filename) |
| 90 | bb.note("The errors for this build are stored in %s\nYou can send the errors to a reports server by running:\n send-error-report %s [-s server]" % (datafile, datafile)) |
| 91 | bb.note("The contents of these logs will be posted in public if you use the above command with the default server. Please ensure you remove any identifying or proprietary information when prompted before sending.") |
| 92 | } |
| 93 | |
| 94 | addhandler errorreport_handler |
| 95 | errorreport_handler[eventmask] = "bb.event.BuildStarted bb.event.BuildCompleted bb.build.TaskFailed" |