report-error.bbclass: Added file syncronization.

errorreport_handler would fail if several errors are
triggered at the same time because of two proccess
writting to the same file. This patch add the required
syncronization to handle concurrent process.

[YP #7899]

(From OE-Core rev: 8b20eaf7cbadd0cd87cfa192d60ca1b7da435216)

Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Mariano Lopez
2015-06-26 05:56:00 +00:00
committed by Richard Purdie
parent 046f1ab727
commit cd379328b9

View File

@@ -18,7 +18,6 @@ def errorreport_getdata(e):
def errorreport_savedata(e, newdata, file): def errorreport_savedata(e, newdata, file):
import json import json
logpath = e.data.getVar('ERR_REPORT_DIR', True) logpath = e.data.getVar('ERR_REPORT_DIR', True)
bb.utils.mkdirhier(logpath)
datafile = os.path.join(logpath, file) datafile = os.path.join(logpath, file)
with open(datafile, "w") as f: with open(datafile, "w") as f:
json.dump(newdata, f, indent=4, sort_keys=True) json.dump(newdata, f, indent=4, sort_keys=True)
@@ -27,7 +26,11 @@ def errorreport_savedata(e, newdata, file):
python errorreport_handler () { python errorreport_handler () {
import json import json
logpath = e.data.getVar('ERR_REPORT_DIR', True)
datafile = os.path.join(logpath, "error-report.txt")
if isinstance(e, bb.event.BuildStarted): if isinstance(e, bb.event.BuildStarted):
bb.utils.mkdirhier(logpath)
data = {} data = {}
machine = e.data.getVar("MACHINE", False) machine = e.data.getVar("MACHINE", False)
data['machine'] = machine data['machine'] = machine
@@ -38,7 +41,9 @@ python errorreport_handler () {
data['failures'] = [] data['failures'] = []
data['component'] = e.getPkgs()[0] data['component'] = e.getPkgs()[0]
data['branch_commit'] = base_detect_branch(e.data) + ": " + base_detect_revision(e.data) data['branch_commit'] = base_detect_branch(e.data) + ": " + base_detect_revision(e.data)
lock = bb.utils.lockfile(datafile + '.lock')
errorreport_savedata(e, data, "error-report.txt") errorreport_savedata(e, data, "error-report.txt")
bb.utils.unlockfile(lock)
elif isinstance(e, bb.build.TaskFailed): elif isinstance(e, bb.build.TaskFailed):
task = e.task task = e.task
@@ -56,12 +61,16 @@ python errorreport_handler () {
else: else:
taskdata['log'] = "No Log" taskdata['log'] = "No Log"
lock = bb.utils.lockfile(datafile + '.lock')
jsondata = json.loads(errorreport_getdata(e)) jsondata = json.loads(errorreport_getdata(e))
jsondata['failures'].append(taskdata) jsondata['failures'].append(taskdata)
errorreport_savedata(e, jsondata, "error-report.txt") errorreport_savedata(e, jsondata, "error-report.txt")
bb.utils.unlockfile(lock)
elif isinstance(e, bb.event.BuildCompleted): elif isinstance(e, bb.event.BuildCompleted):
lock = bb.utils.lockfile(datafile + '.lock')
jsondata = json.loads(errorreport_getdata(e)) jsondata = json.loads(errorreport_getdata(e))
bb.utils.unlockfile(lock)
failures = jsondata['failures'] failures = jsondata['failures']
if(len(failures) > 0): if(len(failures) > 0):
filename = "error_report_" + e.data.getVar("BUILDNAME", False)+".txt" filename = "error_report_" + e.data.getVar("BUILDNAME", False)+".txt"