-
Notifications
You must be signed in to change notification settings - Fork 36
/
sca-dennis.bbclass
executable file
·105 lines (84 loc) · 3.68 KB
/
sca-dennis.bbclass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
## SPDX-License-Identifier: BSD-2-Clause
## Copyright (c) 2019, Konrad Weihmann
## Add ids to suppress on a recipe level
SCA_DENNIS_EXTRA_SUPPRESS ?= ""
## Add ids to lead to a fatal on a recipe level
SCA_DENNIS_EXTRA_FATAL ?= ""
SCA_RAW_RESULT_FILE[dennis] = "txt"
inherit sca-conv-to-export
inherit sca-datamodel
inherit sca-global
inherit sca-helper
inherit sca-suppress
inherit sca-image-backtrack
inherit python3native
def do_sca_conv_dennis(d):
import os
import re
package_name = d.getVar("PN")
buildpath = d.getVar("SCA_SOURCES_DIR")
items = []
pattern = r"^(?P<file>.*):\s+(?P<severity>W|E)(?P<id>\d+)\:\s+(?P<msg>.*)\n.*:\s+(?P<line>\d+)"
severity_map = {
"E" : "error",
"W" : "warning",
}
__suppress = sca_suppress_init(d, "SCA_DENNIS_EXTRA_SUPPRESS",
d.expand("${STAGING_DATADIR_NATIVE}/dennis-${SCA_MODE}-suppress"),
file_trace=False)
_findings = []
if os.path.exists(sca_raw_result_file(d, "dennis")):
with open(sca_raw_result_file(d, "dennis"), "r") as f:
for m in re.finditer(pattern, f.read(), re.MULTILINE):
try:
g = sca_get_model_class(d,
PackageName=package_name,
Tool="dennis",
BuildPath=buildpath,
File = m.group("file"),
Line=m.group("line"),
Message=m.group("msg"),
ID=m.group("id"),
Severity=severity_map[m.group("severity")])
if __suppress.Suppressed(g):
continue
if g.Scope not in clean_split(d, "SCA_SCOPE_FILTER"):
continue
if g.Severity in sca_allowed_warning_level(d):
_findings += sca_backtrack_findings(d, g)
except Exception as exp:
sca_log_note(d, str(exp))
sca_add_model_class_list(d, _findings)
return sca_save_model_to_string(d)
python do_sca_dennis() {
import os
import subprocess
allrun_output = ""
_args = ["dennis-cmd"]
_args += ["lint"]
_files = get_files_by_extention(d, d.getVar("SCA_SOURCES_DIR"), ".po .pot", \
sca_filter_files(d, d.getVar("SCA_SOURCES_DIR"), clean_split(d, "SCA_FILE_FILTER_EXTRA")))
for f in _files:
try:
_targs = _args + [f]
cmd_output = subprocess.check_output(_targs, universal_newlines=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
## manually add syntax or similar error
cmd_output = "E999: Parsing Error.\n1"
if cmd_output:
prefix = "{}: ".format(f)
cmd_output = prefix + prefix.join(cmd_output.splitlines(True))
allrun_output += cmd_output
with open(sca_raw_result_file(d, "dennis"), "w") as o:
o.write(allrun_output)
## Create data model
d.setVar("SCA_DATAMODEL_STORAGE", "{}/dennis.dm".format(d.getVar("T")))
dm_output = do_sca_conv_dennis(d)
with open(d.getVar("SCA_DATAMODEL_STORAGE"), "w") as o:
o.write(dm_output)
sca_task_aftermath(d, "dennis", get_fatal_entries(d, "SCA_DENNIS_EXTRA_FATAL",
d.expand("${STAGING_DATADIR_NATIVE}/dennis-${SCA_MODE}-fatal")))
}
do_sca_dennis[doc] = "Lint i18n files"
addtask do_sca_dennis after do_configure before do_sca_deploy
DEPENDS += "python3-dennis-native sca-recipe-dennis-rules-native"