|
| 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