| 30 | |
| 31 | |
| 32 | class KernelBuilder(Builder): |
| 33 | # If the user supplies their own kernel source, it must be at least this |
| 34 | # version to ensure that all the build commands work, as the build commands |
| 35 | # were written to target at least this version. |
| 36 | MINIMUM_SUPPORTED_VERSION = (6, 9, 0) |
| 37 | |
| 38 | def __init__(self, arch: str) -> None: |
| 39 | super().__init__() |
| 40 | |
| 41 | self.bolt_instrumentation: bool = False |
| 42 | self.bolt_sampling_output: Path = tc_build.utils.UNINIT_PATH |
| 43 | self.config_targets: list[str] = [] |
| 44 | self.cross_compile: str = '' |
| 45 | self.lsm: LinuxSourceManager = LinuxSourceManager() |
| 46 | self.make_variables: MakeVars = { |
| 47 | 'ARCH': arch, |
| 48 | # We do not want warnings to cause build failures when profiling. |
| 49 | 'KCFLAGS': '-Wno-error', |
| 50 | } |
| 51 | self.needs_binutils: bool = False |
| 52 | self.show_commands: bool = True |
| 53 | self.silent: bool = True |
| 54 | self.toolchain_prefix: Path = tc_build.utils.UNINIT_PATH |
| 55 | self.toolchain_version: tuple[int, ...] = () |
| 56 | self.use_ias: bool = True |
| 57 | |
| 58 | def build(self) -> None: |
| 59 | bin_folder = Path(self.toolchain_prefix, 'bin') |
| 60 | if self.bolt_instrumentation: |
| 61 | self.make_variables['CC'] = Path(bin_folder, 'clang.inst') |
| 62 | # The user may have configured clang without the host target, in which |
| 63 | # case we need to use GCC for compiling the host utilities. |
| 64 | if self.can_use_clang_as_hostcc(): |
| 65 | if 'CC' in self.make_variables: |
| 66 | self.make_variables['HOSTCC'] = self.make_variables['CC'] |
| 67 | if self._test_clang(ld_path := f"--ld-path={bin_folder}/ld.lld"): |
| 68 | self.make_variables['HOSTLDFLAGS'] = ld_path |
| 69 | else: |
| 70 | self.make_variables['HOSTCC'] = 'gcc' |
| 71 | self.make_variables['HOSTCXX'] = 'g++' |
| 72 | if self.needs_binutils or not self.use_ias: |
| 73 | if not shutil.which(f"{self.cross_compile}elfedit"): |
| 74 | tc_build.utils.print_warning( |
| 75 | f"binutils for {self.make_variables['ARCH']} ('{self.cross_compile}') could not be found, skipping kernel build..." |
| 76 | ) |
| 77 | return |
| 78 | self.make_variables['CROSS_COMPILE'] = self.cross_compile |
| 79 | self.make_variables['LLVM'] = f"{bin_folder}/" |
| 80 | if not self.use_ias: |
| 81 | self.make_variables['LLVM_IAS'] = '0' |
| 82 | self.make_variables['O'] = self.folders.build |
| 83 | |
| 84 | self.clean_build_folder() |
| 85 | |
| 86 | kconfig_allconfig = None |
| 87 | # allmodconfig enables CONFIG_WERROR and other subsystem specific |
| 88 | # -Werror configurations. Ensure all known configurations get disabled |
| 89 | # via KCONFIG_ALLCONFIG, as they may override KCFLAGS=-Werror. |
nothing calls this directly
no outgoing calls
no test coverage detected