blob: 82b5bcd69054e9027ba7233eb310b5aa34833610 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#
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
9ERR_REPORT_DIR ?= "${LOG_DIR}/error-report"
10
11def errorreport_getdata(e):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050012 import codecs
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013 logpath = e.data.getVar('ERR_REPORT_DIR', True)
14 datafile = os.path.join(logpath, "error-report.txt")
Patrick Williamsf1e5d692016-03-30 15:21:19 -050015 with codecs.open(datafile, 'r', 'utf-8') as f:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016 data = f.read()
17 return data
18
19def errorreport_savedata(e, newdata, file):
20 import json
Patrick Williamsf1e5d692016-03-30 15:21:19 -050021 import codecs
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022 logpath = e.data.getVar('ERR_REPORT_DIR', True)
23 datafile = os.path.join(logpath, file)
Patrick Williamsf1e5d692016-03-30 15:21:19 -050024 with codecs.open(datafile, 'w', 'utf-8') as f:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025 json.dump(newdata, f, indent=4, sort_keys=True)
26 return datafile
27
28python errorreport_handler () {
29 import json
Patrick Williamsf1e5d692016-03-30 15:21:19 -050030 import codecs
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031
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 Williamsf1e5d692016-03-30 15:21:19 -050059 logFile = codecs.open(log, 'r', 'utf-8')
60 logdata = logFile.read()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050061 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
94addhandler errorreport_handler
95errorreport_handler[eventmask] = "bb.event.BuildStarted bb.event.BuildCompleted bb.build.TaskFailed"