Skip to content

Commit 454add7

Browse files
Add test for testing get_linux_sysroot when cross-compiling LLVM
1 parent 514acac commit 454add7

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 shutil
15+
import sys
16+
import tempfile
17+
import unittest
18+
from io import StringIO
19+
20+
from swift_build_support import shell
21+
from swift_build_support.products import LLVM
22+
from swift_build_support.toolchain import host_toolchain
23+
from swift_build_support.workspace import Workspace
24+
25+
class LLVMLinuxCrossCompileTestCase(unittest.TestCase):
26+
def setUp(self):
27+
# Setup workspace
28+
tmpdir1 = os.path.realpath(tempfile.mkdtemp())
29+
tmpdir2 = os.path.realpath(tempfile.mkdtemp())
30+
os.makedirs(os.path.join(tmpdir1, 'llvm'))
31+
32+
# Setup toolchain
33+
self.toolchain = host_toolchain()
34+
self.toolchain.cc = '/path/to/cc'
35+
self.toolchain.cxx = '/path/to/cxx'
36+
37+
# Setup args
38+
self.args = argparse.Namespace(
39+
llvm_targets_to_build='X86;ARM;AArch64',
40+
llvm_assertions='true',
41+
compiler_vendor='none',
42+
clang_compiler_version=None,
43+
clang_user_visible_version=None,
44+
cross_compile_hosts='linux-aarch64',
45+
cross_compile_deps_path='sysroot'
46+
)
47+
48+
# Setup shell
49+
shell.dry_run = True
50+
self._orig_stdout = sys.stdout
51+
self._orig_stderr = sys.stderr
52+
self.stdout = StringIO()
53+
self.stderr = StringIO()
54+
sys.stdout = self.stdout
55+
sys.stderr = self.stderr
56+
57+
def tearDown(self):
58+
sys.stdout = self._orig_stdout
59+
sys.stderr = self._orig_stderr
60+
shell.dry_run = False
61+
self.toolchain = None
62+
self.args = None
63+
64+
def test_llvm_get_linux_sysroot(self):
65+
llvm = LLVM(
66+
args=self.args,
67+
toolchain=self.toolchain,
68+
source_dir='/path/to/src',
69+
build_dir='/path/to/build')
70+
expected_arg = '/usr/aarch64-linux-gnu'
71+
self.assertIn(expected_arg, llvm.get_linux_sysroot("linux", "aarch64"))

0 commit comments

Comments
 (0)