Skip to content

Commit de6bde2

Browse files
roxellbhcopeland
authored andcommitted
build: use user-supplied CROSS_COMPILE in compiler check
The compiler check used the arch default CROSS_COMPILE. When the user passed a different one on the command line, the check failed even though the right compiler was installed. Pass the user-supplied CROSS_COMPILE to is_supported() and keep the ContainerRuntime lru_cache clean by not including it in the cache key. Fixes: 472ce8f ("runtime: null: check if compiler exists on host") Fixes: 9f457b8 ("build: raise CompilerNotFoundError for null runtime") Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
1 parent cee4bf6 commit de6bde2

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

test/test_build.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,19 @@ def test_null_runtime_compiler_not_found(self, linux, mocker):
901901
with pytest.raises(tuxmake.exceptions.CompilerNotFoundError):
902902
Build(tree=linux, target_arch="arc", toolchain="clang")
903903

904+
def test_null_runtime_cross_compile_override(self, linux, mocker):
905+
which = mocker.patch(
906+
"shutil.which", return_value="/usr/bin/arm-linux-gnueabi-gcc"
907+
)
908+
build = Build(
909+
tree=linux,
910+
target_arch="arm",
911+
toolchain="gcc-15",
912+
make_variables={"CROSS_COMPILE": "arm-linux-gnueabi-"},
913+
)
914+
assert build.runtime.name == "null"
915+
which.assert_called_with("arm-linux-gnueabi-gcc")
916+
904917

905918
class TestDebug:
906919
def test_no_debug_without_debug_options(self, linux, capfd):
@@ -1153,7 +1166,8 @@ def test_compression_none(self, linux):
11531166

11541167

11551168
class TestCustomCrossCompile:
1156-
def test_CROSS_COMPILE(self, linux, Popen):
1169+
def test_CROSS_COMPILE(self, linux, Popen, mocker):
1170+
mocker.patch("shutil.which", return_value="/usr/bin/foo-gcc")
11571171
build = Build(
11581172
tree=linux, target_arch="arm64", make_variables={"CROSS_COMPILE": "foo-"}
11591173
)

tuxmake/build.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,14 @@ def __init__(
246246
self.runtime = Runtime.get(runtime)
247247
self.runtime.set_image(get_image(self))
248248

249-
if not self.runtime.is_supported(self.target_arch, self.toolchain):
249+
cross_compile = self.make_variables.get("CROSS_COMPILE")
250+
if not self.runtime.is_supported(
251+
self.target_arch, self.toolchain, cross_compile=cross_compile
252+
):
250253
if self.runtime.name == "null":
251-
compiler = self.toolchain.compiler(self.target_arch)
254+
compiler = self.toolchain.compiler(
255+
self.target_arch, cross_compile=cross_compile
256+
)
252257
raise CompilerNotFoundError(compiler)
253258
raise UnsupportedArchitectureToolchainCombination(
254259
f"{self.target_arch}/{self.toolchain}"

tuxmake/runtime.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def set_group(self, group):
160160
"""
161161
self.__group__ = group
162162

163-
def is_supported(self, arch, toolchain):
163+
def is_supported(self, arch, toolchain, cross_compile=None):
164164
return True
165165

166166
@property
@@ -362,8 +362,8 @@ def run_cmd(
362362
class NullRuntime(Runtime):
363363
name = "null"
364364

365-
def is_supported(self, arch, toolchain):
366-
compiler = toolchain.compiler(arch)
365+
def is_supported(self, arch, toolchain, cross_compile=None):
366+
compiler = toolchain.compiler(arch, cross_compile=cross_compile)
367367
return shutil.which(compiler) is not None
368368

369369

@@ -467,8 +467,11 @@ def volumes(self):
467467
def add_volume(self, source, dest=None, ro=False, device=False):
468468
self.volumes.append((source, dest or source, ro, device))
469469

470+
def is_supported(self, arch, toolchain, cross_compile=None):
471+
return self.__is_supported_cached(arch, toolchain)
472+
470473
@lru_cache(None)
471-
def is_supported(self, arch, toolchain):
474+
def __is_supported_cached(self, arch, toolchain):
472475
image_name = arch.get_image(toolchain) or toolchain.get_image(arch)
473476
image = self.toolchain_images_map.get(image_name)
474477
if toolchain.name.startswith("korg-gcc"):

0 commit comments

Comments
 (0)