Skip to content
This repository was archived by the owner on Feb 4, 2020. It is now read-only.

Commit 653ac12

Browse files
committed
Add msbuild integration tests
* test incremental build with VS2013 * test incremental build with VS2015 * test clean target with VS2015 causing clcache files removed
1 parent 93b989b commit 653ac12

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
entry_points={
2323
'console_scripts': [
2424
'clcache = clcache.__main__:main',
25+
'cl.cache = clcache.__main__:main',
2526
'clcache-server = clcache.server.__main__:main',
2627
]
2728
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int somefunc() { return 1; }
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Release|Win32">
5+
<Configuration>Release</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
</ItemGroup>
9+
10+
<PropertyGroup Label="Configuration">
11+
<ConfigurationType>Application</ConfigurationType>
12+
</PropertyGroup>
13+
14+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
15+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
16+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
17+
18+
<ItemDefinitionGroup>
19+
<ClCompile>
20+
<DebugInformationFormat>OldStyle</DebugInformationFormat>
21+
</ClCompile>
22+
</ItemDefinitionGroup>
23+
<ItemGroup>
24+
<ClCompile Include="another.cpp">
25+
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
26+
</ClCompile>
27+
<ClCompile Include="../minimal.cpp" />
28+
<ClCompile Include="../fibonacci.cpp" />
29+
</ItemGroup>
30+
</Project>

tests/test_integration.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,109 @@ def testEvictedManifest(self):
11821182
self.assertEqual(subprocess.call(cmd, env=customEnv), 0)
11831183

11841184

1185+
@pytest.mark.skipif(os.environ["VisualStudioVersion"] < "14.0", reason="Require newer visual studio")
1186+
class TestMSBuildV140(unittest.TestCase):
1187+
def _clean(self):
1188+
cmd = self.getBuildCmd()
1189+
subprocess.check_call(cmd + ["/t:Clean"])
1190+
1191+
def setUp(self):
1192+
with cd(os.path.join(ASSETS_DIR, "msbuild")):
1193+
self._clean()
1194+
1195+
def getBuildCmd(self):
1196+
return ["msbuild", "/p:Configuration=Release", "/nologo", "/verbosity:minimal",
1197+
"/p:PlatformToolset=v140", "/p:ClToolExe=clcache.exe"]
1198+
1199+
def testClean(self):
1200+
with tempfile.TemporaryDirectory(dir=os.path.join(ASSETS_DIR, "msbuild")) as tempDir:
1201+
customEnv = dict(os.environ, CLCACHE_DIR=tempDir)
1202+
1203+
with cd(os.path.join(ASSETS_DIR, "msbuild")):
1204+
cmd = self.getBuildCmd()
1205+
1206+
# Compile once to insert the objects in the cache
1207+
subprocess.check_call(cmd, env=customEnv)
1208+
1209+
# build Clean target
1210+
subprocess.check_call(cmd + ["/t:Clean"], env=customEnv)
1211+
1212+
cache = clcache.Cache(tempDir)
1213+
with cache.statistics as stats:
1214+
self.assertEqual(stats.numCallsForExternalDebugInfo(), 1)
1215+
self.assertEqual(stats.numCacheEntries(), 2)
1216+
1217+
def testIncrementalBuild(self):
1218+
with tempfile.TemporaryDirectory(dir=os.path.join(ASSETS_DIR, "msbuild")) as tempDir:
1219+
customEnv = dict(os.environ, CLCACHE_DIR=tempDir)
1220+
cmd = self.getBuildCmd()
1221+
1222+
with cd(os.path.join(ASSETS_DIR, "msbuild")):
1223+
# Compile once to insert the objects in the cache
1224+
subprocess.check_call(cmd, env=customEnv)
1225+
1226+
output = subprocess.check_output(cmd, env=customEnv, stderr=subprocess.STDOUT)
1227+
output = output.decode("utf-8")
1228+
1229+
1230+
self.assertTrue("another.cpp" not in output)
1231+
self.assertTrue("minimal.cpp" not in output)
1232+
self.assertTrue("fibonacci.cpp" not in output)
1233+
1234+
1235+
class TestMSBuildV120(unittest.TestCase):
1236+
def _clean(self):
1237+
cmd = self.getBuildCmd()
1238+
subprocess.check_call(cmd + ["/t:Clean"])
1239+
1240+
# workaround due to cl.cache.exe is not frozen it create no cl.read.1.tlog, but
1241+
# this file is important for v120 toolchain, see comment at getMSBuildCmd
1242+
try:
1243+
os.makedirs(os.path.join("Release", "test.tlog"))
1244+
except FileExistsError:
1245+
pass
1246+
with open(os.path.join("Release", "test.tlog", "cl.read.1.tlog"), "w"),\
1247+
open(os.path.join("Release", "test.tlog", "cl.write.1.tlog"), "w"):
1248+
pass
1249+
1250+
def setUp(self):
1251+
with cd(os.path.join(ASSETS_DIR, "msbuild")):
1252+
self._clean()
1253+
1254+
def getBuildCmd(self):
1255+
# v120 toolchain hardcoded "cl.read.1.tlog" and "cl.*.read.1.tlog"
1256+
# file names to inspect as input dependency.
1257+
# The best way to use clcache with v120 toolchain is to froze clcache to cl.exe
1258+
# and then specify ClToolPath property.
1259+
1260+
# There is no frozen cl.exe in tests available, as workaround we would use cl.cache.exe
1261+
# and manually create cl.read.1.tlog empty file, without this file msbuild think that
1262+
# FileTracker created wrong tlogs.
1263+
return ["msbuild", "/p:Configuration=Release", "/nologo", "/verbosity:minimal",
1264+
"/p:PlatformToolset=v120", "/p:ClToolExe=cl.cache.exe"]
1265+
1266+
def testIncrementalBuild(self):
1267+
with tempfile.TemporaryDirectory(dir=os.path.join(ASSETS_DIR, "msbuild")) as tempDir:
1268+
customEnv = dict(os.environ, CLCACHE_DIR=tempDir)
1269+
cmd = self.getBuildCmd()
1270+
1271+
with cd(os.path.join(ASSETS_DIR, "msbuild")):
1272+
# Compile once to insert the objects in the cache
1273+
subprocess.check_call(cmd, env=customEnv)
1274+
1275+
self._clean()
1276+
1277+
# Compile using cached objects
1278+
subprocess.check_call(cmd, env=customEnv)
1279+
1280+
output = subprocess.check_output(cmd, env=customEnv, stderr=subprocess.STDOUT)
1281+
output = output.decode("utf-8")
1282+
1283+
self.assertTrue("another.cpp" not in output)
1284+
self.assertTrue("minimal.cpp" not in output)
1285+
self.assertTrue("fibonacci.cpp" not in output)
1286+
1287+
11851288
if __name__ == '__main__':
11861289
unittest.TestCase.longMessage = True
11871290
unittest.main()

0 commit comments

Comments
 (0)