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