summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oe')
-rw-r--r--meta/lib/oe/__init__.py2
-rw-r--r--meta/lib/oe/go.py6
-rw-r--r--meta/lib/oe/license.py15
-rw-r--r--meta/lib/oe/reproducible.py5
-rw-r--r--meta/lib/oe/rust.py2
-rw-r--r--meta/lib/oe/spdx30_tasks.py45
-rw-r--r--meta/lib/oe/spdx_common.py41
-rw-r--r--meta/lib/oe/tune.py81
-rw-r--r--meta/lib/oe/utils.py43
9 files changed, 179 insertions, 61 deletions
diff --git a/meta/lib/oe/__init__.py b/meta/lib/oe/__init__.py
index dd094a874a..73de774266 100644
--- a/meta/lib/oe/__init__.py
+++ b/meta/lib/oe/__init__.py
@@ -12,4 +12,4 @@ __path__ = extend_path(__path__, __name__)
12BBIMPORTS = ["qa", "data", "path", "utils", "types", "package", "packagedata", \ 12BBIMPORTS = ["qa", "data", "path", "utils", "types", "package", "packagedata", \
13 "packagegroup", "sstatesig", "lsb", "cachedpath", "license", "qemu", \ 13 "packagegroup", "sstatesig", "lsb", "cachedpath", "license", "qemu", \
14 "reproducible", "rust", "buildcfg", "go", "spdx30_tasks", "spdx_common", \ 14 "reproducible", "rust", "buildcfg", "go", "spdx30_tasks", "spdx_common", \
15 "cve_check"] 15 "cve_check", "tune"]
diff --git a/meta/lib/oe/go.py b/meta/lib/oe/go.py
index dfd957d157..4559dc63b2 100644
--- a/meta/lib/oe/go.py
+++ b/meta/lib/oe/go.py
@@ -7,6 +7,10 @@
7import re 7import re
8 8
9def map_arch(a): 9def map_arch(a):
10 """
11 Map our architecture names to Go's GOARCH names.
12 See https://github.com/golang/go/blob/master/src/internal/syslist/syslist.go for the complete list.
13 """
10 if re.match('i.86', a): 14 if re.match('i.86', a):
11 return '386' 15 return '386'
12 elif a == 'x86_64': 16 elif a == 'x86_64':
@@ -31,4 +35,4 @@ def map_arch(a):
31 return 'riscv64' 35 return 'riscv64'
32 elif a == 'loongarch64': 36 elif a == 'loongarch64':
33 return 'loong64' 37 return 'loong64'
34 return '' 38 raise KeyError(f"Cannot map architecture {a}")
diff --git a/meta/lib/oe/license.py b/meta/lib/oe/license.py
index 6f882c3812..6e55fa1e7f 100644
--- a/meta/lib/oe/license.py
+++ b/meta/lib/oe/license.py
@@ -462,3 +462,18 @@ def skip_incompatible_package_licenses(d, pkgs):
462 skipped_pkgs[pkg] = incompatible_lic 462 skipped_pkgs[pkg] = incompatible_lic
463 463
464 return skipped_pkgs 464 return skipped_pkgs
465
466def tidy_licenses(value):
467 """
468 Flat, split and sort licenses.
469 """
470 from oe.license import flattened_licenses
471
472 def _choose(a, b):
473 str_a, str_b = sorted((" & ".join(a), " & ".join(b)), key=str.casefold)
474 return ["(%s | %s)" % (str_a, str_b)]
475
476 if not isinstance(value, str):
477 value = " & ".join(value)
478
479 return sorted(list(set(flattened_licenses(value, _choose))), key=str.casefold)
diff --git a/meta/lib/oe/reproducible.py b/meta/lib/oe/reproducible.py
index cdb38d5aa4..0270024a83 100644
--- a/meta/lib/oe/reproducible.py
+++ b/meta/lib/oe/reproducible.py
@@ -75,10 +75,11 @@ def get_source_date_epoch_from_known_files(d, sourcedir):
75 return source_date_epoch 75 return source_date_epoch
76 76
77def find_git_folder(d, sourcedir): 77def find_git_folder(d, sourcedir):
78 # First guess: UNPACKDIR/git 78 # First guess: UNPACKDIR/BB_GIT_DEFAULT_DESTSUFFIX
79 # This is the default git fetcher unpack path 79 # This is the default git fetcher unpack path
80 unpackdir = d.getVar('UNPACKDIR') 80 unpackdir = d.getVar('UNPACKDIR')
81 gitpath = os.path.join(unpackdir, "git/.git") 81 default_destsuffix = d.getVar('BB_GIT_DEFAULT_DESTSUFFIX')
82 gitpath = os.path.join(unpackdir, default_destsuffix, ".git")
82 if os.path.isdir(gitpath): 83 if os.path.isdir(gitpath):
83 return gitpath 84 return gitpath
84 85
diff --git a/meta/lib/oe/rust.py b/meta/lib/oe/rust.py
index 185553eeeb..1dc9cf150d 100644
--- a/meta/lib/oe/rust.py
+++ b/meta/lib/oe/rust.py
@@ -8,6 +8,4 @@
8def arch_to_rust_arch(arch): 8def arch_to_rust_arch(arch):
9 if arch == "ppc64le": 9 if arch == "ppc64le":
10 return "powerpc64le" 10 return "powerpc64le"
11 if arch in ('riscv32', 'riscv64'):
12 return arch + 'gc'
13 return arch 11 return arch
diff --git a/meta/lib/oe/spdx30_tasks.py b/meta/lib/oe/spdx30_tasks.py
index 61d7ba45e3..c352dab152 100644
--- a/meta/lib/oe/spdx30_tasks.py
+++ b/meta/lib/oe/spdx30_tasks.py
@@ -156,6 +156,11 @@ def add_package_files(
156 bb.note(f"Skip {topdir}") 156 bb.note(f"Skip {topdir}")
157 return spdx_files 157 return spdx_files
158 158
159 check_compiled_sources = d.getVar("SPDX_INCLUDE_COMPILED_SOURCES") == "1"
160 if check_compiled_sources:
161 compiled_sources, types = oe.spdx_common.get_compiled_sources(d)
162 bb.debug(1, f"Total compiled files: {len(compiled_sources)}")
163
159 for subdir, dirs, files in os.walk(topdir, onerror=walk_error): 164 for subdir, dirs, files in os.walk(topdir, onerror=walk_error):
160 dirs[:] = [d for d in dirs if d not in ignore_dirs] 165 dirs[:] = [d for d in dirs if d not in ignore_dirs]
161 if subdir == str(topdir): 166 if subdir == str(topdir):
@@ -171,6 +176,11 @@ def add_package_files(
171 filename = str(filepath.relative_to(topdir)) 176 filename = str(filepath.relative_to(topdir))
172 file_purposes = get_purposes(filepath) 177 file_purposes = get_purposes(filepath)
173 178
179 # Check if file is compiled
180 if check_compiled_sources:
181 if not oe.spdx_common.is_compiled_source(filename, compiled_sources, types):
182 continue
183
174 spdx_file = objset.new_file( 184 spdx_file = objset.new_file(
175 get_spdxid(file_counter), 185 get_spdxid(file_counter),
176 filename, 186 filename,
@@ -542,7 +552,7 @@ def create_spdx(d):
542 ) 552 )
543 build_objset.new_relationship( 553 build_objset.new_relationship(
544 source_files, 554 source_files,
545 oe.spdx30.RelationshipType.hasConcludedLicense, 555 oe.spdx30.RelationshipType.hasDeclaredLicense,
546 [oe.sbom30.get_element_link_id(recipe_spdx_license)], 556 [oe.sbom30.get_element_link_id(recipe_spdx_license)],
547 ) 557 )
548 558
@@ -714,24 +724,23 @@ def create_spdx(d):
714 impact_statement=description, 724 impact_statement=description,
715 ) 725 )
716 726
717 if detail in ( 727 vex_just_type = d.getVarFlag(
718 "ignored", 728 "CVE_CHECK_VEX_JUSTIFICATION", detail
719 "cpe-incorrect", 729 )
720 "disputed", 730 if vex_just_type:
721 "upstream-wontfix", 731 if (
722 ): 732 vex_just_type
723 # VEX doesn't have justifications for this 733 not in oe.spdx30.security_VexJustificationType.NAMED_INDIVIDUALS
724 pass 734 ):
725 elif detail in ( 735 bb.fatal(
726 "not-applicable-config", 736 f"Unknown vex justification '{vex_just_type}', detail '{detail}', for ignored {cve}"
727 "not-applicable-platform",
728 ):
729 for v in spdx_vex:
730 v.security_justificationType = (
731 oe.spdx30.security_VexJustificationType.vulnerableCodeNotPresent
732 ) 737 )
733 else: 738
734 bb.fatal(f"Unknown detail '{detail}' for ignored {cve}") 739 for v in spdx_vex:
740 v.security_justificationType = oe.spdx30.security_VexJustificationType.NAMED_INDIVIDUALS[
741 vex_just_type
742 ]
743
735 elif status == "Unknown": 744 elif status == "Unknown":
736 bb.note(f"Skipping {cve} with status 'Unknown'") 745 bb.note(f"Skipping {cve} with status 'Unknown'")
737 else: 746 else:
diff --git a/meta/lib/oe/spdx_common.py b/meta/lib/oe/spdx_common.py
index 4caefc7673..c2dec65563 100644
--- a/meta/lib/oe/spdx_common.py
+++ b/meta/lib/oe/spdx_common.py
@@ -242,3 +242,44 @@ def fetch_data_to_uri(fd, name):
242 uri = uri + "@" + fd.revision 242 uri = uri + "@" + fd.revision
243 243
244 return uri 244 return uri
245
246def is_compiled_source (filename, compiled_sources, types):
247 """
248 Check if the file is a compiled file
249 """
250 import os
251 # If we don't have compiled source, we assume all are compiled.
252 if not compiled_sources:
253 return True
254
255 # We return always true if the file type is not in the list of compiled files.
256 # Some files in the source directory are not compiled, for example, Makefiles,
257 # but also python .py file. We need to include them in the SPDX.
258 basename = os.path.basename(filename)
259 ext = basename.partition(".")[2]
260 if ext not in types:
261 return True
262 # Check that the file is in the list
263 return filename in compiled_sources
264
265def get_compiled_sources(d):
266 """
267 Get list of compiled sources from debug information and normalize the paths
268 """
269 import itertools
270 source_info = oe.package.read_debugsources_info(d)
271 if not source_info:
272 bb.debug(1, "Do not have debugsources.list. Skipping")
273 return [], []
274
275 # Sources are not split now in SPDX, so we aggregate them
276 sources = set(itertools.chain.from_iterable(source_info.values()))
277 # Check extensions of files
278 types = set()
279 for src in sources:
280 basename = os.path.basename(src)
281 ext = basename.partition(".")[2]
282 if ext not in types and ext:
283 types.add(ext)
284 bb.debug(1, f"Num of sources: {len(sources)} and types: {len(types)} {str(types)}")
285 return sources, types
diff --git a/meta/lib/oe/tune.py b/meta/lib/oe/tune.py
new file mode 100644
index 0000000000..7fda19430d
--- /dev/null
+++ b/meta/lib/oe/tune.py
@@ -0,0 +1,81 @@
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: GPL-2.0-only
5#
6
7# riscv_isa_to_tune(isa)
8#
9# Automatically translate a RISC-V ISA string to TUNE_FEATURES
10#
11# Abbreviations, such as rv32g -> rv32imaffd_zicsr_zifencei are supported.
12#
13# Profiles, such as rva22u64, are NOT supported, you must use ISA strings.
14#
15def riscv_isa_to_tune(isa):
16 _isa = isa.lower()
17
18 feature = []
19 iter = 0
20
21 # rv or riscv
22 if _isa[iter:].startswith('rv'):
23 feature.append('rv')
24 iter = iter + 2
25 elif _isa[iter:].startswith('riscv'):
26 feature.append('rv')
27 iter = iter + 5
28 else:
29 # Not a risc-v ISA!
30 return _isa
31
32 while (_isa[iter:]):
33 # Skip _ and whitespace
34 if _isa[iter] == '_' or _isa[iter].isspace():
35 iter = iter + 1
36 continue
37
38 # Length, just capture numbers here
39 if _isa[iter].isdigit():
40 iter_end = iter
41 while iter_end < len(_isa) and _isa[iter_end].isdigit():
42 iter_end = iter_end + 1
43
44 feature.append(_isa[iter:iter_end])
45 iter = iter_end
46 continue
47
48 # Typically i, e or g is next, followed by extensions.
49 # Extensions are single character, except for Z, Ss, Sh, Sm, Sv, and X
50
51 # If the extension starts with 'Z', 'S' or 'X' use the name until the next _, whitespace or end
52 if _isa[iter] in ['z', 's', 'x']:
53 ext_type = _isa[iter]
54 iter_end = iter + 1
55
56 # Multicharacter extension, these are supposed to have a _ before the next multicharacter extension
57 # See 37.4 and 37.5:
58 # 37.4: Underscores "_" may be used to separate ISA extensions...
59 # 37.5: All multi-letter extensions ... must be separated from other multi-letter extensions by an underscore...
60 # Some extensions permit only alphabetic characters, while others allow alphanumeric chartacters
61 while iter_end < len(_isa) and _isa[iter_end] != "_" and not _isa[iter_end].isspace():
62 iter_end = iter_end + 1
63
64 feature.append(_isa[iter:iter_end])
65 iter = iter_end
66 continue
67
68 # 'g' is special, it's an abbreviation for imafd_zicsr_zifencei
69 # When expanding the abbreviation, any additional letters must appear before the _z* extensions
70 if _isa[iter] == 'g':
71 _isa = 'imafd' + _isa[iter+1:] + '_zicsr_zifencei'
72 iter = 0
73 continue
74
75 feature.append(_isa[iter])
76 iter = iter + 1
77 continue
78
79 # Eliminate duplicates, but preserve the order
80 feature = list(dict.fromkeys(feature))
81 return ' '.join(feature)
diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
index a11db5f3cd..779c5e593f 100644
--- a/meta/lib/oe/utils.py
+++ b/meta/lib/oe/utils.py
@@ -415,60 +415,29 @@ def format_pkg_list(pkg_dict, ret_format=None, pkgdata_dir=None):
415 return output_str 415 return output_str
416 416
417 417
418# Helper function to get the host compiler version 418# Helper function to get the host gcc version
419# Do not assume the compiler is gcc 419def get_host_gcc_version(d, taskcontextonly=False):
420def get_host_compiler_version(d, taskcontextonly=False):
421 import re, subprocess 420 import re, subprocess
422 421
423 if taskcontextonly and d.getVar('BB_WORKERCONTEXT') != '1': 422 if taskcontextonly and d.getVar('BB_WORKERCONTEXT') != '1':
424 return 423 return
425 424
426 compiler = d.getVar("BUILD_CC")
427 # Get rid of ccache since it is not present when parsing.
428 if compiler.startswith('ccache '):
429 compiler = compiler[7:]
430 try: 425 try:
431 env = os.environ.copy() 426 env = os.environ.copy()
432 # datastore PATH does not contain session PATH as set by environment-setup-... 427 # datastore PATH does not contain session PATH as set by environment-setup-...
433 # this breaks the install-buildtools use-case 428 # this breaks the install-buildtools use-case
434 # env["PATH"] = d.getVar("PATH") 429 # env["PATH"] = d.getVar("PATH")
435 output = subprocess.check_output("%s --version" % compiler, \ 430 output = subprocess.check_output("gcc --version", \
436 shell=True, env=env, stderr=subprocess.STDOUT).decode("utf-8") 431 shell=True, env=env, stderr=subprocess.STDOUT).decode("utf-8")
437 except subprocess.CalledProcessError as e: 432 except subprocess.CalledProcessError as e:
438 bb.fatal("Error running %s --version: %s" % (compiler, e.output.decode("utf-8"))) 433 bb.fatal("Error running gcc --version: %s" % (e.output.decode("utf-8")))
439 434
440 match = re.match(r".* (\d+\.\d+)\.\d+.*", output.split('\n')[0]) 435 match = re.match(r".* (\d+\.\d+)\.\d+.*", output.split('\n')[0])
441 if not match: 436 if not match:
442 bb.fatal("Can't get compiler version from %s --version output" % compiler) 437 bb.fatal("Can't get compiler version from gcc --version output")
443 438
444 version = match.group(1) 439 version = match.group(1)
445 return compiler, version 440 return version
446
447
448def host_gcc_version(d, taskcontextonly=False):
449 import re, subprocess
450
451 if taskcontextonly and d.getVar('BB_WORKERCONTEXT') != '1':
452 return
453
454 compiler = d.getVar("BUILD_CC")
455 # Get rid of ccache since it is not present when parsing.
456 if compiler.startswith('ccache '):
457 compiler = compiler[7:]
458 try:
459 env = os.environ.copy()
460 env["PATH"] = d.getVar("PATH")
461 output = subprocess.check_output("%s --version" % compiler, \
462 shell=True, env=env, stderr=subprocess.STDOUT).decode("utf-8")
463 except subprocess.CalledProcessError as e:
464 bb.fatal("Error running %s --version: %s" % (compiler, e.output.decode("utf-8")))
465
466 match = re.match(r".* (\d+\.\d+)\.\d+.*", output.split('\n')[0])
467 if not match:
468 bb.fatal("Can't get compiler version from %s --version output" % compiler)
469
470 version = match.group(1)
471 return "-%s" % version if version in ("4.8", "4.9") else ""
472 441
473@bb.parse.vardepsexclude("DEFAULTTUNE_MULTILIB_ORIGINAL", "OVERRIDES") 442@bb.parse.vardepsexclude("DEFAULTTUNE_MULTILIB_ORIGINAL", "OVERRIDES")
474def get_multilib_datastore(variant, d): 443def get_multilib_datastore(variant, d):