From a89b639fe153ad5ac5aacead2c73ff688fbf2c1d Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Tue, 28 May 2024 18:13:42 -0700 Subject: [PATCH] tc_build: kernel: Disable -Werror configurations For now, we do this only for allmodconfig, as KCFLAGS=-Werror has worked without any issues until this point. Signed-off-by: Nathan Chancellor --- tc_build/kernel.py | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/tc_build/kernel.py b/tc_build/kernel.py index 33f632fd..45b4cf03 100644 --- a/tc_build/kernel.py +++ b/tc_build/kernel.py @@ -4,6 +4,7 @@ from pathlib import Path import shutil import subprocess +from tempfile import NamedTemporaryFile import time from tc_build.builder import Builder @@ -23,7 +24,7 @@ def __init__(self, arch): self.bolt_instrumentation = False self.bolt_sampling_output = None - self.config_targets = None + self.config_targets = [] self.cross_compile = None self.make_variables = { 'ARCH': arch, @@ -60,6 +61,34 @@ def build(self): self.make_variables['LLVM_IAS'] = '0' self.make_variables['O'] = self.folders.build + self.clean_build_folder() + + kconfig_allconfig = None + # allmodconfig enables CONFIG_WERROR and other subsystem specific + # -Werror configurations. Ensure all known configurations get disabled + # via KCONFIG_ALLCONFIG, as they may override KCFLAGS=-Werror. + if 'allmodconfig' in self.config_targets: + self.folders.build.mkdir(parents=True) + + # Using a context manager for this would seriously convolute this + # code, as we need to use the name of the object in make_cmd but + # delete it after actually running the command so the rest of the + # code after this function would need another level of indent. We + # know that from this point forward, the function can only throw an + # exception when calling make_cmd, so we can just wrap that in a + # try: ... finally: ... statement to ensure that this file is + # always cleaned up. + # pylint: disable-next=consider-using-with + kconfig_allconfig = NamedTemporaryFile(dir=self.folders.build) + + configs_to_disable = ['DRM_WERROR', 'WERROR'] + kconfig_allconfig_text = ''.join(f"CONFIG_{val}=n\n" + for val in configs_to_disable).encode('utf-8') + + kconfig_allconfig.write(kconfig_allconfig_text) + kconfig_allconfig.seek(0) + self.make_variables['KCONFIG_ALLCONFIG'] = kconfig_allconfig.name + make_cmd = [] if self.bolt_sampling_output: make_cmd += [ @@ -77,9 +106,12 @@ def build(self): # Ideally, the kernel would always clobber user flags via ':=' but we deal with reality. os.environ.pop('CFLAGS', '') - self.clean_build_folder() build_start = time.time() - self.run_cmd(make_cmd) + try: + self.run_cmd(make_cmd) + finally: + if kconfig_allconfig: + kconfig_allconfig.close() tc_build.utils.print_info(f"Build duration: {tc_build.utils.get_duration(build_start)}") def can_use_ias(self):