| from modules.llvm import LLVMBuildConfig |
| |
| from os import makedirs |
| from shutil import rmtree |
| |
| from unittest import TestCase |
| from unittest.mock import MagicMock |
| from uuid import uuid4 |
| |
| |
| class TestLLVMBuildConfig(TestCase): |
| testdirprefix = "BuildConfigUT" |
| |
| def setUp(self): |
| self.sourcePath = "llvm" + str(uuid4()) |
| self.buildPath = "build" + str(uuid4()) |
| |
| sourceConfigAttrs = {"get_path.return_value": self.sourcePath} |
| self.sourceConfig = MagicMock(**sourceConfigAttrs) |
| |
| makedirs(self.buildPath) |
| |
| def tearDown(self): |
| rmtree(self.buildPath) |
| |
| def test_configure_generator(self): |
| """Test that we can use a custom generator for our CMake command.""" |
| consumer = MagicMock() |
| buildConfig = LLVMBuildConfig(self.sourceConfig, self.buildPath, |
| consumer) |
| |
| buildConfig.cmake([], "Unix Makefiles") |
| command, directory = consumer.consume.call_args[0] |
| |
| self.assertEqual(directory, self.buildPath) |
| |
| self.assertEqual(command[0], "cmake") |
| self.assertIn(self.sourcePath, command) |
| self.assertEqual( |
| command.index("-G") + 1, |
| command.index("Unix Makefiles")) |
| |
| def test_configure_definitions(self): |
| """Test that we can define custom CMake variables.""" |
| consumer = MagicMock() |
| buildConfig = LLVMBuildConfig(self.sourceConfig, self.buildPath, |
| consumer) |
| flags = ["-DCMAKE_BUILD_TYPE=Release", |
| "-DCMAKE_CXX_FLAGS=\"-Oz -g\""] |
| |
| buildConfig.cmake(flags, "Ninja") |
| command, directory = consumer.consume.call_args[0] |
| |
| self.assertEqual(directory, self.buildPath) |
| |
| self.assertEqual(command[0], "cmake") |
| self.assertEqual(command.index("-G") + 1, command.index("Ninja")) |
| self.assertIn(self.sourcePath, command) |
| self.assertEqual(command.index(flags[0]) + 1, command.index(flags[1])) |
| |
| def test_update_projects(self): |
| """ |
| Test that we explicitly enable/disable subprojects based on what is |
| enabled in the source config. |
| """ |
| |
| def for_each_subproj(action): |
| # Pretend that clang is enabled and lld isn't. |
| clang_subproj = MagicMock() |
| clang_subproj.cmake_var = "BUILD_CLANG" |
| action(clang_subproj, True) |
| |
| lld_subproj = MagicMock() |
| lld_subproj.cmake_var = "BUILD_LLD" |
| action(lld_subproj, False) |
| |
| self.sourceConfig.for_each_subproj.side_effect = for_each_subproj |
| |
| consumer = MagicMock() |
| buildConfig = LLVMBuildConfig(self.sourceConfig, self.buildPath, |
| consumer) |
| |
| buildConfig.cmake([], "Ninja") |
| command, directory = consumer.consume.call_args[0] |
| |
| self.assertEqual(directory, self.buildPath) |
| |
| self.assertEqual(command[0], "cmake") |
| self.assertEqual(command.index("-G") + 1, command.index("Ninja")) |
| self.assertIn(self.sourcePath, command) |
| self.assertIn("-DBUILD_CLANG=ON", command) |
| self.assertIn("-DBUILD_LLD=OFF", command) |