def test_found_executables_match(self): # Test that the raw invocation of _first_common_executables # either returns None or matching paths. suffixes = ['', '-3.8', '-3.7', '-3.6'] toolchain = host_toolchain(suffixes=suffixes) self.assertTrue(len(toolchain.tools) == 2) exec_names = {'foo': 'a-tool-that-does-not-exist'} toolchain = host_toolchain(tools=exec_names, suffixes=suffixes) self.assertIsNone(toolchain)
def setUp(self): # Setup workspace tmpdir1 = os.path.realpath(tempfile.mkdtemp()) tmpdir2 = os.path.realpath(tempfile.mkdtemp()) os.makedirs(os.path.join(tmpdir1, 'swift')) self.workspace = Workspace(source_root=tmpdir1, build_root=tmpdir2) # Setup toolchain self.toolchain = host_toolchain() self.toolchain.cc = '/path/to/cc' self.toolchain.cxx = '/path/to/cxx' # Setup args self.args = argparse.Namespace(enable_tsan_runtime=False, compiler_vendor='none', swift_compiler_version=None, clang_compiler_version=None, swift_user_visible_version=None, darwin_deployment_version_osx="10.9", benchmark=False, benchmark_num_onone_iterations=3, benchmark_num_o_iterations=3, enable_sil_ownership=False) # Setup shell shell.dry_run = True self._orig_stdout = sys.stdout self._orig_stderr = sys.stderr self.stdout = StringIO() self.stderr = StringIO() sys.stdout = self.stdout sys.stderr = self.stderr
def setUp(self): # Setup workspace tmpdir1 = os.path.realpath(tempfile.mkdtemp()) tmpdir2 = os.path.realpath(tempfile.mkdtemp()) os.makedirs(os.path.join(tmpdir1, 'swift')) self.workspace = Workspace(source_root=tmpdir1, build_root=tmpdir2) # Setup toolchain self.toolchain = host_toolchain() self.toolchain.cc = '/path/to/cc' self.toolchain.cxx = '/path/to/cxx' # Setup args self.args = argparse.Namespace( enable_tsan_runtime=False, compiler_vendor='none', swift_compiler_version=None, clang_compiler_version=None, swift_user_visible_version=None, darwin_deployment_version_osx="10.9", benchmark=False, benchmark_num_onone_iterations=3, benchmark_num_o_iterations=3, enable_sil_ownership=False) # Setup shell shell.dry_run = True self._orig_stdout = sys.stdout self._orig_stderr = sys.stderr self.stdout = StringIO() self.stderr = StringIO() sys.stdout = self.stdout sys.stderr = self.stderr
def setUp(self): # Setup workspace tmpdir1 = os.path.realpath(tempfile.mkdtemp()) tmpdir2 = os.path.realpath(tempfile.mkdtemp()) os.makedirs(os.path.join(tmpdir1, 'llvm')) self.workspace = Workspace(source_root=tmpdir1, build_root=tmpdir2) # Setup toolchain self.toolchain = host_toolchain() self.toolchain.cc = '/path/to/cc' self.toolchain.cxx = '/path/to/cxx' # Setup args self.args = argparse.Namespace( llvm_targets_to_build='X86;ARM;AArch64;PowerPC;SystemZ', llvm_assertions='true', compiler_vendor='none', clang_compiler_version=None, clang_user_visible_version=None, darwin_deployment_version_osx='10.9') # Setup shell shell.dry_run = True self._orig_stdout = sys.stdout self._orig_stderr = sys.stderr self.stdout = StringIO() self.stderr = StringIO() sys.stdout = self.stdout sys.stderr = self.stderr
def setUp(self): # Setup workspace tmpdir1 = os.path.realpath(tempfile.mkdtemp()) tmpdir2 = os.path.realpath(tempfile.mkdtemp()) os.makedirs(os.path.join(tmpdir1, "llvm")) self.workspace = Workspace(source_root=tmpdir1, build_root=tmpdir2) # Setup toolchain self.toolchain = host_toolchain() self.toolchain.cc = "/path/to/cc" self.toolchain.cxx = "/path/to/cxx" # Setup args self.args = argparse.Namespace( llvm_targets_to_build="X86;ARM;AArch64;PowerPC;SystemZ", llvm_assertions="true", compiler_vendor="none", clang_compiler_version=None, clang_user_visible_version=None, darwin_deployment_version_osx="10.9", ) # Setup shell shell.dry_run = True self._orig_stdout = sys.stdout self._orig_stderr = sys.stderr self.stdout = StringIO() self.stderr = StringIO() sys.stdout = self.stdout sys.stderr = self.stderr
def setUp(self): # Setup workspace tmpdir1 = os.path.realpath(tempfile.mkdtemp()) tmpdir2 = os.path.realpath(tempfile.mkdtemp()) os.makedirs(os.path.join(tmpdir1, 'cmark')) self.workspace = Workspace(source_root=tmpdir1, build_root=tmpdir2) self.host = StdlibDeploymentTarget.host_target() # Setup toolchain self.toolchain = host_toolchain() self.toolchain.cc = '/path/to/cc' self.toolchain.cxx = '/path/to/cxx' self.cross_compile_hosts = ["macosx-arm64", "linux-x86_64", "linux-aarch64"] # Setup args self.args = argparse.Namespace( cross_compile_hosts=self.cross_compile_hosts) # Setup shell shell.dry_run = True self._orig_stdout = sys.stdout self._orig_stderr = sys.stderr self.stdout = StringIO() self.stderr = StringIO() sys.stdout = self.stdout sys.stderr = self.stderr
def test_tools_suffix_match(self): tc = host_toolchain() # CC and CXX must have consistent suffix cc_suffix = get_suffix(tc.cc, 'clang') cxx_suffix = get_suffix(tc.cxx, 'clang++') self.assertEqual(cc_suffix, cxx_suffix)
def which_ninja(self, args): toolchain = host_toolchain() if toolchain.ninja is not None: return '/path/to/installed/ninja' # Maybe we'll build a ninja, maybe we wont. # Fake it anyway for the tests. return '/path/to/built/ninja'
def setUp(self): # Setup workspace tmpdir1 = os.path.realpath(tempfile.mkdtemp()) tmpdir2 = os.path.realpath(tempfile.mkdtemp()) os.makedirs(os.path.join(tmpdir1, 'ninja')) self.workspace = Workspace(source_root=tmpdir1, build_root=tmpdir2) # Setup toolchain self.toolchain = host_toolchain() self.toolchain.cc = '/path/to/cc' self.toolchain.cxx = '/path/to/cxx' # Setup args self.args = argparse.Namespace(build_ninja=True, darwin_deployment_version_osx="10.9") # Setup shell shell.dry_run = True self._orig_stdout = sys.stdout self._orig_stderr = sys.stderr self.stdout = StringIO() self.stderr = StringIO() sys.stdout = self.stdout sys.stderr = self.stderr
def test_tools_suffix_match(self): tc = host_toolchain() # CC and CXX must have consistent suffix cc_suffix = get_suffix(tc.cc, self._platform_cc_name()) cxx_suffix = get_suffix(tc.cxx, self._platform_cxx_name()) self.assertEqual(cc_suffix, cxx_suffix)
def setUp(self): # Setup workspace tmpdir1 = os.path.realpath(tempfile.mkdtemp()) tmpdir2 = os.path.realpath(tempfile.mkdtemp()) os.makedirs(os.path.join(tmpdir1, 'ninja')) self.workspace = Workspace(source_root=tmpdir1, build_root=tmpdir2) # Setup toolchain self.toolchain = host_toolchain() self.toolchain.cc = '/path/to/cc' self.toolchain.cxx = '/path/to/cxx' # Setup args self.args = argparse.Namespace( build_ninja=True, darwin_deployment_version_osx="10.9") # Setup shell shell.dry_run = True self._orig_stdout = sys.stdout self._orig_stderr = sys.stderr self.stdout = StringIO() self.stderr = StringIO() sys.stdout = self.stdout sys.stderr = self.stderr
def test_llvm_tools(self): tc = host_toolchain() self.assertTrue( tc.llvm_profdata is None or os.path.isabs(tc.llvm_profdata) and os.path.basename(tc.llvm_profdata).startswith('llvm-profdata')) self.assertTrue( tc.llvm_cov is None or os.path.isabs(tc.llvm_cov) and os.path.basename(tc.llvm_cov).startswith('llvm-cov'))
def cmake(self, args): """Return new CMake object initialized with given args """ toolchain = host_toolchain() toolchain.cc = args.host_cc toolchain.cxx = args.host_cxx if args.distcc: toolchain.distcc = self.mock_distcc_path() return CMake(args=args, toolchain=toolchain)
def cmake(self, args): """Return new CMake object initialized with given args """ toolchain = host_toolchain() toolchain.cc = args.cmake_c_compiler toolchain.cxx = args.cmake_cxx_compiler if args.distcc: toolchain.distcc = self.mock_distcc_path() toolchain.ninja = self.which_ninja(args) return CMake(args=args, toolchain=toolchain)
def cmake(self, args): """Return new CMake object initialized with given args """ toolchain = host_toolchain() toolchain.cc = args.host_cc toolchain.cxx = args.host_cxx if args.distcc: toolchain.distcc = self.mock_distcc_path() if args.build_ninja: toolchain.ninja = '/path/to/built/ninja' return CMake(args=args, toolchain=toolchain)
def test_find_tool(self): tc = host_toolchain() # Toolchain.find_tool(path) can find arbitrary tool in PATH sh = tc.find_tool('sh') self.assertTrue(sh is not None and os.path.isabs(sh) and os.path.basename(sh) == 'sh') tar = tc.find_tool('tar') self.assertTrue(tar is not None and os.path.isabs(tar) and os.path.basename(tar) == 'tar')
def test_can_find_llvm_cov(self): suffixes = ['', '-3.8', '-3.7', '-3.6'] exec_names = {'llvm_cov': 'llvm-cov'} toolchain = host_toolchain(tools=exec_names, suffixes=suffixes) # must have clang, clang++, and llvm-cov self.assertTrue(len(toolchain.tools) == 3) try: toolchain.llvm_cov except AttributeError: self.fail("toolchain does not have llvm_cov")
def test_clang_tools(self): tc = host_toolchain() self.assertIsNotNone(tc.cc) self.assertIsNotNone(tc.cxx) self.assertTrue( os.path.isabs(tc.cc) and os.path.basename(tc.cc).startswith('clang')) self.assertTrue( os.path.isabs(tc.cxx) and os.path.basename(tc.cxx).startswith('clang++'))
def test_clang_tools(self): tc = host_toolchain() self.assertIsNotNone(tc.cc) self.assertIsNotNone(tc.cxx) self.assertTrue( os.path.isabs(tc.cc) and os.path.basename(tc.cc).startswith(self._platform_cc_name())) self.assertTrue( os.path.isabs(tc.cxx) and os.path.basename(tc.cxx).startswith(self._platform_cxx_name()))
def cmake(self, args): """Return new CMake object initialized with given args """ toolchain = host_toolchain() toolchain.cc = args.host_cc toolchain.cxx = args.host_cxx toolchain.libtool = args.host_libtool if args.distcc: toolchain.distcc = self.mock_distcc_path() if args.sccache: toolchain.sccache = self.mock_sccache_path() toolchain.ninja = self.which_ninja(args) return CMake(args=args, toolchain=toolchain)
def setUp(self): # Setup workspace tmpdir1 = os.path.realpath(tempfile.mkdtemp()) tmpdir2 = os.path.realpath(tempfile.mkdtemp()) os.makedirs(os.path.join(tmpdir1, 'cmark')) self.workspace = Workspace(source_root=tmpdir1, build_root=tmpdir2) self.host = StdlibDeploymentTarget.host_target() # Setup toolchain self.toolchain = host_toolchain() self.toolchain.cc = '/path/to/cc' self.toolchain.cxx = '/path/to/cxx' # Setup args self.args = argparse.Namespace( build_cmark=True, cmake_generator="Ninja", cmark_build_type="Release", rebuild=False, extra_cmake_options=[], skip_build=False, darwin_deployment_version_osx="10.9", cmark_build_variant="Debug", export_compile_commands=False, reconfigure=False, distcc=None, sccache=None, cmake_c_launcher=None, cmake_cxx_launcher=None, clang_user_visible_version=None, build_ninja=False, enable_asan=False, enable_lsan=False, enable_sanitize_coverage=False, enable_tsan=False, enable_ubsan=False) # Setup shell shell.dry_run = True self._orig_stdout = sys.stdout self._orig_stderr = sys.stderr self.stdout = StringIO() self.stderr = StringIO() sys.stdout = self.stdout sys.stderr = self.stderr
def test_misc_tools(self): tc = host_toolchain() # CMake self.assertIsNotNone(tc.cmake) self.assertTrue(os.path.basename(tc.cmake).startswith('cmake')) # Ninja self.assertTrue(tc.ninja is None or os.path.basename(tc.ninja) == 'ninja' or os.path.basename(tc.ninja) == 'ninja-build') # distcc self.assertTrue(tc.distcc is None or os.path.basename(tc.distcc) == 'distcc') # pump self.assertTrue(tc.distcc_pump is None or os.path.basename(tc.distcc_pump) == 'pump' or os.path.basename(tc.distcc_pump) == 'distcc-pump')
def setUp(self): # Setup workspace tmpdir1 = os.path.realpath(tempfile.mkdtemp()) tmpdir2 = os.path.realpath(tempfile.mkdtemp()) os.makedirs(os.path.join(tmpdir1, 'swift')) self.workspace = Workspace(source_root=tmpdir1, build_root=tmpdir2) # Setup toolchain self.toolchain = host_toolchain() self.toolchain.cc = '/path/to/cc' self.toolchain.cxx = '/path/to/cxx' # Setup args self.args = argparse.Namespace( enable_tsan_runtime=False, compiler_vendor='none', swift_compiler_version=None, clang_compiler_version=None, swift_user_visible_version=None, darwin_deployment_version_osx="10.9", benchmark=False, benchmark_num_onone_iterations=3, benchmark_num_o_iterations=3, disable_guaranteed_normal_arguments=True, force_optimized_typechecker=False, enable_stdlibcore_exclusivity_checking=False, enable_experimental_differentiable_programming=False, enable_experimental_concurrency=False, enable_experimental_distributed=False, build_swift_stdlib_static_print=False, build_swift_stdlib_unicode_data=True, swift_freestanding_is_darwin=False, build_swift_private_stdlib=True, swift_tools_ld64_lto_codegen_only_for_supporting_targets=False) # Setup shell shell.dry_run = True self._orig_stdout = sys.stdout self._orig_stderr = sys.stderr self.stdout = StringIO() self.stderr = StringIO() sys.stdout = self.stdout sys.stderr = self.stderr
def test_misc_tools(self): tc = host_toolchain() # CMake self.assertIsNotNone(tc.cmake) self.assertTrue( os.path.basename(tc.cmake).startswith('cmake')) # Ninja self.assertTrue(tc.ninja is None or os.path.basename(tc.ninja) == 'ninja' or os.path.basename(tc.ninja) == 'ninja-build') # distcc self.assertTrue(tc.distcc is None or os.path.basename(tc.distcc) == 'distcc') # pump self.assertTrue(tc.distcc_pump is None or os.path.basename(tc.distcc_pump) == 'pump' or os.path.basename(tc.distcc_pump) == 'distcc-pump')
def test_tools_llvm_suffix(self): tc = host_toolchain() cov_suffix = None profdata_suffix = None if tc.llvm_cov: cov_suffix = get_suffix(tc.llvm_cov, 'llvm-cov') if tc.llvm_profdata: profdata_suffix = get_suffix(tc.llvm_profdata, 'llvm-profdata') if profdata_suffix is not None and cov_suffix is not None: self.assertEqual(profdata_suffix, cov_suffix) # If we have suffixed clang, llvm tools must have the same suffix. cc_suffix = get_suffix(tc.cc, 'clang') if cc_suffix != '': if cov_suffix is not None: self.assertEqual(cc_suffix, cov_suffix) if profdata_suffix is not None: self.assertEqual(cc_suffix, profdata_suffix)
import logging import os import pipes import sys from multiprocessing import Process # hack to import SwiftBuildSupport and swift_build_support parent_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..') sys.path.append(parent_dir) support_dir = os.path.join(parent_dir, 'swift_build_support') sys.path.append(support_dir) from swift_build_support.toolchain import host_toolchain # noqa (E402) from SwiftBuildSupport import check_output, check_call # noqa (E402) toolchain = host_toolchain() LLVM_PROFDATA_PATH = toolchain.llvm_profdata _profdata_help = check_output([LLVM_PROFDATA_PATH, 'merge', '-help']) LLVM_PROFDATA_SUPPORTS_SPARSE = 'sparse' in _profdata_help class ProfdataMergerProcess(Process): def __init__(self, config, file_queue): super(ProfdataMergerProcess, self).__init__() self.config = config self.file_queue = file_queue self.filename_buffer = [] self.profdata_path = os.path.join(config.tmp_dir, "%s.profdata" % self.name) self.profdata_tmp_path = self.profdata_path + ".copy"
import logging import os import pipes import sys from multiprocessing import Process # Allow importing swift_build_support. sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'swift_build_support')) from swift_build_support import shell # noqa (E402) from swift_build_support.toolchain import host_toolchain # noqa (E402) toolchain = host_toolchain() LLVM_PROFDATA_PATH = toolchain.llvm_profdata _profdata_help = shell.capture([LLVM_PROFDATA_PATH, 'merge', '-help'], echo=False) LLVM_PROFDATA_SUPPORTS_SPARSE = 'sparse' in _profdata_help class ProfdataMergerProcess(Process): def __init__(self, config, file_queue): super(ProfdataMergerProcess, self).__init__() self.config = config self.file_queue = file_queue self.filename_buffer = [] self.profdata_path = os.path.join(config.tmp_dir, "%s.profdata" % self.name) self.profdata_tmp_path = self.profdata_path + ".copy"