summaryrefslogtreecommitdiffstats
path: root/meta/classes/report-error.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/report-error.bbclass')
-rw-r--r--meta/classes/report-error.bbclass70
1 files changed, 70 insertions, 0 deletions
diff --git a/meta/classes/report-error.bbclass b/meta/classes/report-error.bbclass
new file mode 100644
index 0000000000..8b30422edf
--- /dev/null
+++ b/meta/classes/report-error.bbclass
@@ -0,0 +1,70 @@
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
9ERR_REPORT_DIR ?= "${LOG_DIR}/error-report"
10
11def errorreport_getdata(e):
12 logpath = e.data.getVar('ERR_REPORT_DIR', True)
13 datafile = os.path.join(logpath, "error-report.txt")
14 with open(datafile) as f:
15 data = f.read()
16 return data
17
18def errorreport_savedata(e, newdata, file):
19 import json
20 logpath = e.data.getVar('ERR_REPORT_DIR', True)
21 bb.utils.mkdirhier(logpath)
22 datafile = os.path.join(logpath, file)
23 with open(datafile, "w") as f:
24 json.dump(newdata, f, indent=4, sort_keys=True)
25 return datafile
26
27python errorreport_handler () {
28 import json
29
30 if isinstance(e, bb.event.BuildStarted):
31 data = {}
32 machine = e.data.getVar("MACHINE")
33 data['machine'] = machine
34 data['build_sys'] = e.data.getVar("BUILD_SYS", True)
35 data['nativelsb'] = e.data.getVar("NATIVELSBSTRING")
36 data['distro'] = e.data.getVar("DISTRO")
37 data['target_sys'] = e.data.getVar("TARGET_SYS", True)
38 data['failures'] = []
39 data['component'] = e.getPkgs()[0]
40 data['branch_commit'] = base_detect_branch(e.data) + ": " + base_detect_revision(e.data)
41 errorreport_savedata(e, data, "error-report.txt")
42
43 elif isinstance(e, bb.build.TaskFailed):
44 task = e.task
45 taskdata={}
46 log = e.data.getVar('BB_LOGFILE', True)
47 taskdata['package'] = e.data.expand("${PF}")
48 taskdata['task'] = task
49 if log:
50 logFile = open(log, 'r')
51 taskdata['log'] = logFile.read()
52 logFile.close()
53 else:
54 taskdata['log'] = "No Log"
55 jsondata = json.loads(errorreport_getdata(e))
56 jsondata['failures'].append(taskdata)
57 errorreport_savedata(e, jsondata, "error-report.txt")
58
59 elif isinstance(e, bb.event.BuildCompleted):
60 jsondata = json.loads(errorreport_getdata(e))
61 failures = jsondata['failures']
62 if(len(failures) > 0):
63 filename = "error_report_" + e.data.getVar("BUILDNAME")+".txt"
64 datafile = errorreport_savedata(e, jsondata, filename)
65 bb.note("The errors for this build are stored in %s\nYou can send the errors to an upstream server by running:\n send-error-report %s [server]" % (datafile, datafile))
66 bb.note("The contents of these logs will be posted in public if you use the above command with the default server. If you need to do so, please ensure you remove any identifying or proprietary information before sending.")
67}
68
69addhandler errorreport_handler
70errorreport_handler[eventmask] = "bb.event.BuildStarted bb.event.BuildCompleted bb.build.TaskFailed"