@@ -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+
11851288if __name__ == '__main__' :
11861289 unittest .TestCase .longMessage = True
11871290 unittest .main ()
0 commit comments