Skip to content

Commit 8dc4c56

Browse files
authored
Merge pull request #78909 from xtremekforever/#75341-fix-swift-build-support-typo
Fix typo in get_linux_sysroot that makes cross-compilation fail
2 parents b73b90f + 57dc1d1 commit 8dc4c56

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

utils/swift_build_support/swift_build_support/products/product.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def get_linux_target_components(self, arch):
379379
def get_linux_sysroot(self, platform, arch):
380380
if not self.is_cross_compile_target('{}-{}'.format(platform, arch)):
381381
return None
382-
sysroot_arch, abi = self.get_linux_target_components(arch)
382+
sysroot_arch, _, abi = self.get_linux_target_components(arch)
383383
# $ARCH-$PLATFORM-$ABI
384384
# E.x.: aarch64-linux-gnu
385385
sysroot_dirname = '{}-{}-{}'.format(sysroot_arch, platform, abi)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# tests/products/test_llvm_linux_cross_compile.py ---------------*- python -*-
2+
#
3+
# This source file is part of the LLVM.org open source project
4+
#
5+
# Copyright (c) 2014 - 2025 Apple Inc. and the LLVM project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of LLVM project authors
10+
# ----------------------------------------------------------------------------
11+
12+
import argparse
13+
import os
14+
import sys
15+
import tempfile
16+
import unittest
17+
from io import StringIO
18+
19+
from swift_build_support import shell
20+
from swift_build_support.products import LLVM
21+
from swift_build_support.toolchain import host_toolchain
22+
23+
24+
class LLVMLinuxCrossCompileTestCase(unittest.TestCase):
25+
def setUp(self):
26+
# Setup workspace
27+
tmpdir1 = os.path.realpath(tempfile.mkdtemp())
28+
os.makedirs(os.path.join(tmpdir1, 'llvm'))
29+
30+
# Setup toolchain
31+
self.toolchain = host_toolchain()
32+
self.toolchain.cc = '/path/to/cc'
33+
self.toolchain.cxx = '/path/to/cxx'
34+
35+
# Setup args
36+
self.args = argparse.Namespace(
37+
llvm_targets_to_build='X86;ARM;AArch64',
38+
llvm_assertions='true',
39+
compiler_vendor='none',
40+
clang_compiler_version=None,
41+
clang_user_visible_version=None,
42+
cross_compile_hosts='linux-aarch64',
43+
cross_compile_deps_path='sysroot'
44+
)
45+
46+
# Setup shell
47+
shell.dry_run = True
48+
self._orig_stdout = sys.stdout
49+
self._orig_stderr = sys.stderr
50+
self.stdout = StringIO()
51+
self.stderr = StringIO()
52+
sys.stdout = self.stdout
53+
sys.stderr = self.stderr
54+
55+
def tearDown(self):
56+
sys.stdout = self._orig_stdout
57+
sys.stderr = self._orig_stderr
58+
shell.dry_run = False
59+
self.toolchain = None
60+
self.args = None
61+
62+
def test_llvm_get_linux_sysroot(self):
63+
llvm = LLVM(
64+
args=self.args,
65+
toolchain=self.toolchain,
66+
source_dir='/path/to/src',
67+
build_dir='/path/to/build')
68+
expected_arg = '/usr/aarch64-linux-gnu'
69+
self.assertIn(expected_arg, llvm.get_linux_sysroot("linux", "aarch64"))

0 commit comments

Comments
 (0)