/
sca-file-filter.bbclass
55 lines (44 loc) · 1.4 KB
/
sca-file-filter.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
## SPDX-License-Identifier: BSD-2-Clause
## Copyright (c) 2019, Konrad Weihmann
inherit sca-license-filter
## Global file filter
SCA_FILE_FILTER ?= "\
.pc/* \
.git/* \
tests/* \
test/* \
doc/* \
testsuite/* \
**/tests/* \
**/test/* \
**/doc/* \
**/testsuite/* \
"
## Local file filter
SCA_FILE_FILTER_EXTRA ??= ""
def sca_filter_files(d, path, addfilter=[]):
import os
import subprocess
res = []
_filter = [x for x in d.getVar("SCA_FILE_FILTER").split(" ") if x] + addfilter
for item in _filter:
_pattern = os.path.join(d.getVar("SCA_SOURCES_DIR"), item)
try:
cmd_out = subprocess.check_output(["find", path, "-type", "f", "-wholename", _pattern])
except subprocess.CalledProcessError as e:
cmd_out = e.output or ""
if not isinstance(cmd_out, str):
cmd_out = cmd_out.decode('utf-8')
res += [x for x in cmd_out.split("\n") if x]
res += sca_filter_by_license(d)
return sorted(list(set(res)))
def sca_get_installed_pkgs(d):
import os
import json
try:
with open(d.getVar("SCA_IMAGE_PKG_LIST")) as i:
_json = json.load(i)
return _json.keys()
except:
pass
return []