3535import nimp .sys .process
3636
3737
38- def _try_excecute (command , max_attemtps = 3 , delay = 5 , time_out = 120 ):
38+ def _try_excecute (command , cwd = '.' , capture_output = True , max_attemtps = 5 , delay = 5 , time_out = 120 ):
3939 ''' retry in case autoSDK or devenv cache fails us '''
40- attempt = 1
40+ attempt = 0
4141 while attempt <= max_attemtps :
4242 retry = False
4343 start_time = time .time ()
44- result , output , err = nimp .sys .process .call (command , capture_output = True )
44+ result , output , err = nimp .sys .process .call (command , cwd = cwd , capture_output = True )
4545 time_passed = time .time () - start_time
4646
4747 if result != 0 :
@@ -50,22 +50,25 @@ def _try_excecute(command, max_attemtps=3, delay=5, time_out=120):
5050 logging .error ('Visual Studio appears to have failed' )
5151 return False
5252
53- if attempt > max_attemtps :
54- logging .error ('Max attempts reached, bailing...' )
55- return result
5653 if "ERROR: Unhandled exception: System." in output and ":\\ autoSDK\\ HostWin64\\ " in output :
5754 logging .warn (f'AutoSDK error.' )
5855 retry = True
59- if "Package 'RoslynPackage' failed to load." in output or "Package 'Visual Studio Build Manager Package' failed to load." in output :
56+ if "Package 'RoslynPackage' failed to load" in output :
57+ logging .warn (f'Devenv cache error' )
58+ retry = True
59+ if "Package 'Visual Studio Build Manager Package' failed to load" in output :
6060 logging .warn (f'Devenv cache error' )
6161 retry = True
6262
6363 if retry :
64+ if attempt >= max_attemtps :
65+ logging .error ('Max attempts reached, bailing...' )
66+ return result
6467 if time_passed > time_out :
6568 logging .warn (f'Not retrying error that happened late in the process' )
6669 return result
67- logging .warn (f'Retrying : attempt { attempt } out of { max_attemtps } ...' )
6870 attempt += 1
71+ logging .warn (f'Retrying : attempt { attempt } out of { max_attemtps } ...' )
6972 time .sleep (delay )
7073 else :
7174 return result
@@ -111,11 +114,7 @@ def msbuild(project_file, platform_name, configuration, project=None,
111114 if additional_flags is not None :
112115 command += additional_flags
113116
114- result , output , _ = nimp .sys .process .call (command , capture_output = needCapture )
115-
116- if nimp .sys .platform .is_windows () and 'Cannot run if when setup is in progress.' in output :
117- logging .error ('Visual Studio appears to have failed' )
118- return False
117+ result = _try_excecute (command , capture_output = needCapture )
119118
120119 return result == 0
121120
0 commit comments