Skip to content

Commit 7ef9b32

Browse files
committed
[build-script] Fix CMake sccache test
1 parent 6d92486 commit 7ef9b32

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

utils/swift_build_support/tests/test_cmake.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ def mock_distcc_path(self):
3333
executable = 'mock-distcc'
3434
return os.path.join(os.path.dirname(__file__), executable)
3535

36+
def mock_sccache_path(self):
37+
"""Return a path string of a mock sccache executable
38+
"""
39+
if platform.system() == 'Windows':
40+
executable = 'sccache.cmd'
41+
else:
42+
executable = 'sccache'
43+
return os.path.join(os.path.dirname(__file__), executable)
44+
3645
def default_args(self):
3746
"""Return new args object with default values
3847
"""
@@ -46,6 +55,7 @@ def default_args(self):
4655
enable_sanitize_coverage=False,
4756
export_compile_commands=False,
4857
distcc=False,
58+
sccache=False,
4959
cmake_generator="Ninja",
5060
cmake_c_launcher=None,
5161
cmake_cxx_launcher=None,
@@ -73,6 +83,8 @@ def cmake(self, args):
7383
toolchain.libtool = args.host_libtool
7484
if args.distcc:
7585
toolchain.distcc = self.mock_distcc_path()
86+
if args.sccache:
87+
toolchain.sccache = self.mock_sccache_path()
7688
toolchain.ninja = self.which_ninja(args)
7789
return CMake(args=args, toolchain=toolchain)
7890

@@ -120,7 +132,7 @@ def test_common_options_tsan(self):
120132
self.assertEqual(
121133
list(cmake.common_options()),
122134
["-G", "Ninja",
123-
"-DLLVM_USE_SANITIZER=Thread",
135+
"-DLLVM_USE_SANITIZER=Thread",
124136
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
125137
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++",
126138
"-DCMAKE_LIBTOOL:PATH=/path/to/libtool",
@@ -222,6 +234,20 @@ def test_common_options_distcc(self):
222234
"-DCMAKE_LIBTOOL:PATH=/path/to/libtool",
223235
"-DCMAKE_MAKE_PROGRAM=" + self.which_ninja(args)])
224236

237+
def test_common_options_sccache(self):
238+
args = self.default_args()
239+
args.sccache = True
240+
cmake = self.cmake(args)
241+
self.assertEqual(
242+
list(cmake.common_options()),
243+
["-G", "Ninja",
244+
"-DCMAKE_C_COMPILER_LAUNCHER:PATH=" + self.mock_sccache_path(),
245+
"-DCMAKE_CXX_COMPILER_LAUNCHER:PATH=" + self.mock_sccache_path(),
246+
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
247+
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++",
248+
"-DCMAKE_LIBTOOL:PATH=/path/to/libtool",
249+
"-DCMAKE_MAKE_PROGRAM=" + self.which_ninja(args)])
250+
225251
def test_common_options_launcher(self):
226252
args = self.default_args()
227253
cmake_c_launcher = "/path/to/c_launcher"

0 commit comments

Comments
 (0)