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 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 13 | logpath = e.data.getVar('ERR_REPORT_DIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 22 | logpath = e.data.getVar('ERR_REPORT_DIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 32 | def nativelsb(): |
| 33 | nativelsbstr = e.data.getVar("NATIVELSBSTRING") |
| 34 | # provide a bit more host info in case of uninative build |
| 35 | if e.data.getVar('UNINATIVE_URL') != 'unset': |
| 36 | return '/'.join([nativelsbstr, lsb_distro_identifier(e.data)]) |
| 37 | return nativelsbstr |
| 38 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 39 | logpath = e.data.getVar('ERR_REPORT_DIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | datafile = os.path.join(logpath, "error-report.txt") |
| 41 | |
| 42 | if isinstance(e, bb.event.BuildStarted): |
| 43 | bb.utils.mkdirhier(logpath) |
| 44 | data = {} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 45 | machine = e.data.getVar("MACHINE") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | data['machine'] = machine |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 47 | data['build_sys'] = e.data.getVar("BUILD_SYS") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 48 | data['nativelsb'] = nativelsb() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 49 | data['distro'] = e.data.getVar("DISTRO") |
| 50 | data['target_sys'] = e.data.getVar("TARGET_SYS") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | data['failures'] = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 52 | data['component'] = " ".join(e.getPkgs()) |
| 53 | data['branch_commit'] = str(base_detect_branch(e.data)) + ": " + str(base_detect_revision(e.data)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | lock = bb.utils.lockfile(datafile + '.lock') |
| 55 | errorreport_savedata(e, data, "error-report.txt") |
| 56 | bb.utils.unlockfile(lock) |
| 57 | |
| 58 | elif isinstance(e, bb.build.TaskFailed): |
| 59 | task = e.task |
| 60 | taskdata={} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 61 | log = e.data.getVar('BB_LOGFILE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 62 | taskdata['package'] = e.data.expand("${PF}") |
| 63 | taskdata['task'] = task |
| 64 | if log: |
| 65 | try: |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 66 | logFile = codecs.open(log, 'r', 'utf-8') |
| 67 | logdata = logFile.read() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 68 | |
| 69 | # Replace host-specific paths so the logs are cleaner |
| 70 | for d in ("TOPDIR", "TMPDIR"): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 71 | s = e.data.getVar(d) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 72 | if s: |
| 73 | logdata = logdata.replace(s, d) |
| 74 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 75 | logFile.close() |
| 76 | except: |
| 77 | logdata = "Unable to read log file" |
| 78 | |
| 79 | else: |
| 80 | logdata = "No Log" |
| 81 | |
| 82 | # server will refuse failures longer than param specified in project.settings.py |
| 83 | # MAX_UPLOAD_SIZE = "5242880" |
| 84 | # use lower value, because 650 chars can be spent in task, package, version |
| 85 | max_logdata_size = 5242000 |
| 86 | # upload last max_logdata_size characters |
| 87 | if len(logdata) > max_logdata_size: |
| 88 | logdata = "..." + logdata[-max_logdata_size:] |
| 89 | taskdata['log'] = logdata |
| 90 | lock = bb.utils.lockfile(datafile + '.lock') |
| 91 | jsondata = json.loads(errorreport_getdata(e)) |
| 92 | jsondata['failures'].append(taskdata) |
| 93 | errorreport_savedata(e, jsondata, "error-report.txt") |
| 94 | bb.utils.unlockfile(lock) |
| 95 | |
| 96 | elif isinstance(e, bb.event.BuildCompleted): |
| 97 | lock = bb.utils.lockfile(datafile + '.lock') |
| 98 | jsondata = json.loads(errorreport_getdata(e)) |
| 99 | bb.utils.unlockfile(lock) |
| 100 | failures = jsondata['failures'] |
| 101 | if(len(failures) > 0): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 102 | filename = "error_report_" + e.data.getVar("BUILDNAME")+".txt" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 103 | datafile = errorreport_savedata(e, jsondata, filename) |
| 104 | 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)) |
| 105 | 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.") |
| 106 | } |
| 107 | |
| 108 | addhandler errorreport_handler |
| 109 | errorreport_handler[eventmask] = "bb.event.BuildStarted bb.event.BuildCompleted bb.build.TaskFailed" |