2014-02-14 11:58:43 +00:00
#
# Collects debug information in order to create error report files.
#
# Copyright (C) 2013 Intel Corporation
# Author: Andreea Brandusa Proca <andreea.b.proca@intel.com>
#
# Licensed under the MIT license, see COPYING.MIT for details
ERR_REPORT_DIR ?= "${LOG_DIR}/error-report"
def errorreport_getdata(e):
2015-10-01 10:40:46 +00:00
import codecs
2016-12-14 21:13:04 +00:00
logpath = e.data.getVar('ERR_REPORT_DIR')
2014-02-14 11:58:43 +00:00
datafile = os.path.join(logpath, "error-report.txt")
2015-10-01 10:40:46 +00:00
with codecs.open(datafile, 'r', 'utf-8') as f:
2014-02-14 11:58:43 +00:00
data = f.read()
return data
def errorreport_savedata(e, newdata, file):
import json
2015-10-01 10:40:46 +00:00
import codecs
2016-12-14 21:13:04 +00:00
logpath = e.data.getVar('ERR_REPORT_DIR')
2014-02-14 11:58:43 +00:00
datafile = os.path.join(logpath, file)
2015-10-01 10:40:46 +00:00
with codecs.open(datafile, 'w', 'utf-8') as f:
2014-02-14 11:58:43 +00:00
json.dump(newdata, f, indent=4, sort_keys=True)
return datafile
python errorreport_handler () {
import json
2015-10-01 10:40:46 +00:00
import codecs
2014-02-14 11:58:43 +00:00
2016-12-14 21:13:04 +00:00
logpath = e.data.getVar('ERR_REPORT_DIR')
2015-06-26 05:56:00 +00:00
datafile = os.path.join(logpath, "error-report.txt")
2014-02-14 11:58:43 +00:00
if isinstance(e, bb.event.BuildStarted):
2015-06-26 05:56:00 +00:00
bb.utils.mkdirhier(logpath)
2014-02-14 11:58:43 +00:00
data = {}
2016-12-14 21:13:04 +00:00
machine = e.data.getVar("MACHINE")
2014-02-14 11:58:43 +00:00
data['machine'] = machine
2016-12-14 21:13:04 +00:00
data['build_sys'] = e.data.getVar("BUILD_SYS")
data['nativelsb'] = e.data.getVar("NATIVELSBSTRING")
data['distro'] = e.data.getVar("DISTRO")
data['target_sys'] = e.data.getVar("TARGET_SYS")
2014-02-14 11:58:43 +00:00
data['failures'] = []
2016-08-15 17:05:24 +00:00
data['component'] = " ".join(e.getPkgs())
2016-05-20 10:57:44 +00:00
data['branch_commit'] = str(base_detect_branch(e.data)) + ": " + str(base_detect_revision(e.data))
2015-06-26 05:56:00 +00:00
lock = bb.utils.lockfile(datafile + '.lock')
2014-02-14 11:58:43 +00:00
errorreport_savedata(e, data, "error-report.txt")
2015-06-26 05:56:00 +00:00
bb.utils.unlockfile(lock)
2014-02-14 11:58:43 +00:00
elif isinstance(e, bb.build.TaskFailed):
task = e.task
taskdata={}
2016-12-14 21:13:04 +00:00
log = e.data.getVar('BB_LOGFILE')
2014-02-14 11:58:43 +00:00
taskdata['package'] = e.data.expand("${PF}")
taskdata['task'] = task
2014-12-20 11:20:33 +00:00
if log:
2015-02-03 14:20:12 +00:00
try:
2015-10-01 10:40:46 +00:00
logFile = codecs.open(log, 'r', 'utf-8')
logdata = logFile.read()
2016-05-12 13:31:58 +00:00
2016-07-12 09:23:18 +00:00
# Replace host-specific paths so the logs are cleaner
for d in ("TOPDIR", "TMPDIR"):
2016-12-14 21:13:04 +00:00
s = e.data.getVar(d)
2016-07-12 09:23:18 +00:00
if s:
logdata = logdata.replace(s, d)
2016-05-12 13:31:58 +00:00
2015-02-03 14:20:12 +00:00
logFile.close()
except:
2015-09-04 12:22:09 +00:00
logdata = "Unable to read log file"
2015-02-03 14:20:12 +00:00
2014-12-20 11:20:33 +00:00
else:
2015-09-04 12:22:09 +00:00
logdata = "No Log"
# server will refuse failures longer than param specified in project.settings.py
# MAX_UPLOAD_SIZE = "5242880"
# use lower value, because 650 chars can be spent in task, package, version
max_logdata_size = 5242000
# upload last max_logdata_size characters
if len(logdata) > max_logdata_size:
logdata = "..." + logdata[-max_logdata_size:]
taskdata['log'] = logdata
2015-06-26 05:56:00 +00:00
lock = bb.utils.lockfile(datafile + '.lock')
2014-02-14 11:58:43 +00:00
jsondata = json.loads(errorreport_getdata(e))
jsondata['failures'].append(taskdata)
errorreport_savedata(e, jsondata, "error-report.txt")
2015-06-26 05:56:00 +00:00
bb.utils.unlockfile(lock)
2014-02-14 11:58:43 +00:00
elif isinstance(e, bb.event.BuildCompleted):
2015-06-26 05:56:00 +00:00
lock = bb.utils.lockfile(datafile + '.lock')
2014-02-14 11:58:43 +00:00
jsondata = json.loads(errorreport_getdata(e))
2015-06-26 05:56:00 +00:00
bb.utils.unlockfile(lock)
2014-02-14 11:58:43 +00:00
failures = jsondata['failures']
if(len(failures) > 0):
2016-12-14 21:13:04 +00:00
filename = "error_report_" + e.data.getVar("BUILDNAME")+".txt"
2014-02-14 11:58:43 +00:00
datafile = errorreport_savedata(e, jsondata, filename)
2015-02-27 12:15:19 +00:00
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))
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.")
2014-02-14 11:58:43 +00:00
}
addhandler errorreport_handler
errorreport_handler[eventmask] = "bb.event.BuildStarted bb.event.BuildCompleted bb.build.TaskFailed"