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