1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
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)
|