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

Commit

Permalink
Add msbuild integration tests
Browse files Browse the repository at this point in the history
* test incremental build with VS2013
* test incremental build with VS2015
* test clean target with VS2015 causing clcache files removed
  • Loading branch information
izmmisha committed Aug 15, 2018
1 parent 93b989b commit 1613f3a
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
entry_points={
'console_scripts': [
'clcache = clcache.__main__:main',
'cl.cache = clcache.__main__:main',
'clcache-server = clcache.server.__main__:main',
]
},
Expand Down
1 change: 1 addition & 0 deletions tests/integrationtests/msbuild/another.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int somefunc() { return 1; }
30 changes: 30 additions & 0 deletions tests/integrationtests/msbuild/test.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>

<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
</PropertyGroup>

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

<ItemDefinitionGroup>
<ClCompile>
<DebugInformationFormat>OldStyle</DebugInformationFormat>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="another.cpp">
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ClCompile Include="../minimal.cpp" />
<ClCompile Include="../fibonacci.cpp" />
</ItemGroup>
</Project>
101 changes: 101 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,107 @@ def testEvictedManifest(self):
self.assertEqual(subprocess.call(cmd, env=customEnv), 0)


@pytest.mark.skipif(os.environ["VisualStudioVersion"] < "14.0", reason="Require newer visual studio")
class TestMSBuildV140(unittest.TestCase):
def _clean(self):
cmd = self.getBuildCmd()
subprocess.check_call(cmd + ["/t:Clean"])

def setUp(self):
with cd(os.path.join(ASSETS_DIR, "msbuild")):
self._clean()

def getBuildCmd(self):
return ["msbuild", "/p:Configuration=Release", "/nologo", "/verbosity:minimal", "/p:PlatformToolset=v140", "/p:ClToolExe=clcache.exe"]

def testClean(self):
with tempfile.TemporaryDirectory(dir=os.path.join(ASSETS_DIR, "msbuild")) as tempDir:
customEnv = dict(os.environ, CLCACHE_DIR=tempDir)

with cd(os.path.join(ASSETS_DIR, "msbuild")):
cmd = self.getBuildCmd()

# Compile once to insert the objects in the cache
subprocess.check_call(cmd, env=customEnv)

# build Clean target
subprocess.check_call(cmd + ["/t:Clean"], env=customEnv)

cache = clcache.Cache(tempDir)
with cache.statistics as stats:
self.assertEqual(stats.numCallsForExternalDebugInfo(), 1)
self.assertEqual(stats.numCacheEntries(), 2)

def testIncrementalBuild(self):
with tempfile.TemporaryDirectory(dir=os.path.join(ASSETS_DIR, "msbuild")) as tempDir:
customEnv = dict(os.environ, CLCACHE_DIR=tempDir)
cmd = self.getBuildCmd()

with cd(os.path.join(ASSETS_DIR, "msbuild")):
# Compile once to insert the objects in the cache
subprocess.check_call(cmd, env=customEnv)

output = subprocess.check_output(cmd, env=customEnv, stderr=subprocess.STDOUT)
output = output.decode("utf-8")


self.assertTrue("another.cpp" not in output)
self.assertTrue("minimal.cpp" not in output)
self.assertTrue("fibonacci.cpp" not in output)


class TestMSBuildV120(unittest.TestCase):
def _clean(self):
cmd = self.getBuildCmd()
subprocess.check_call(cmd + ["/t:Clean"])

# workaround due to cl.cache.exe is not frozen it create no cl.read.1.tlog, but
# this file is important for v120 toolchain, see comment at getMSBuildCmd
try:
os.makedirs(os.path.join("Release", "test.tlog"))
except FileExistsError:
pass
with open(os.path.join("Release", "test.tlog", "cl.read.1.tlog"), "w"),\
open(os.path.join("Release", "test.tlog", "cl.write.1.tlog"), "w"):
pass

def setUp(self):
with cd(os.path.join(ASSETS_DIR, "msbuild")):
self._clean()

def getBuildCmd(self):
# v120 toolchain hardcoded "cl.read.1.tlog" and "cl.*.read.1.tlog"
# file names to inspect as input dependency.
# The best way to use clcache with v120 toolchain is to froze clcache to cl.exe
# and then specify ClToolPath property.

# There is no frozen cl.exe in tests available, as workaround we would use cl.cache.exe
# and manually create cl.read.1.tlog empty file, without this file msbuild think that
# FileTracker created wrong tlogs.
return ["msbuild", "/p:Configuration=Release", "/nologo", "/verbosity:minimal", "/p:PlatformToolset=v120", "/p:ClToolExe=cl.cache.exe"]

def testIncrementalBuild(self):
with tempfile.TemporaryDirectory(dir=os.path.join(ASSETS_DIR, "msbuild")) as tempDir:
customEnv = dict(os.environ, CLCACHE_DIR=tempDir)
cmd = self.getBuildCmd()

with cd(os.path.join(ASSETS_DIR, "msbuild")):
# Compile once to insert the objects in the cache
subprocess.check_call(cmd, env=customEnv)

self._clean()

# Compile using cached objects
subprocess.check_call(cmd, env=customEnv)

output = subprocess.check_output(cmd, env=customEnv, stderr=subprocess.STDOUT)
output = output.decode("utf-8")

self.assertTrue("another.cpp" not in output)
self.assertTrue("minimal.cpp" not in output)
self.assertTrue("fibonacci.cpp" not in output)


if __name__ == '__main__':
unittest.TestCase.longMessage = True
unittest.main()

0 comments on commit 1613f3a

Please sign in to comment.