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

Commit 1613f3a

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 1613f3a

4 files changed

Lines changed: 133 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)