Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: build_apprtc_collider.py

Issue 1514533002: Add retries for deletion on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/webrtc/webrtc.DEPS@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Builds the AppRTC collider using the golang toolchain. 6 """Builds the AppRTC collider using the golang toolchain.
7 7
8 The golang toolchain is downloaded by download_golang.py. We use that here 8 The golang toolchain is downloaded by download_golang.py. We use that here
9 to build the AppRTC collider server. 9 to build the AppRTC collider server.
10 """ 10 """
11 11
12 import os 12 import os
13 import shutil 13 import shutil
14 import subprocess 14 import subprocess
15 import sys 15 import sys
16 import time
16 17
17 import utils 18 import utils
18 19
19 20
21 # Code partially copied from
22 # https://cs.chromium.org#chromium/build/scripts/common/chromium_utils.py
23 def RemoveDirectory(*path):
24 """Recursively removes a directory, even if it's marked read-only.
25
26 Remove the directory located at *path, if it exists.
27
28 shutil.rmtree() doesn't work on Windows if any of the files or directories
29 are read-only, which svn repositories and some .svn files are. We need to
30 be able to force the files to be writable (i.e., deletable) as we traverse
31 the tree.
32
33 Even with all this, Windows still sometimes fails to delete a file, citing
34 a permission error (maybe something to do with antivirus scans or disk
35 indexing). The best suggestion any of the user forums had was to wait a
36 bit and try again, so we do that too. It's hand-waving, but sometimes it
37 works. :/
38 """
39 file_path = os.path.join(*path)
40 if not os.path.exists(file_path):
41 return
42
43 if sys.platform == 'win32':
44 # Give up and use cmd.exe's rd command.
45 file_path = os.path.normcase(file_path)
46 for _ in xrange(3):
47 print 'RemoveDirectory running %s' % (' '.join(
48 ['cmd.exe', '/c', 'rd', '/q', '/s', file_path]))
49 if not subprocess.call(['cmd.exe', '/c', 'rd', '/q', '/s', file_path]):
50 break
51 print ' Failed'
52 time.sleep(3)
53 return
54 else:
55 shutil.rmtree(file_path, ignore_errors=True)
56
57
20 def main(): 58 def main():
21 apprtc_dir = os.path.join('apprtc', 'src') 59 apprtc_dir = os.path.join('apprtc', 'src')
22 golang_workspace = os.path.join('src', 'out', 'go-workspace') 60 golang_workspace = os.path.join('src', 'out', 'go-workspace')
23 shutil.rmtree(golang_workspace, ignore_errors=True) 61 RemoveDirectory(golang_workspace)
62
24 golang_workspace_src = os.path.join(golang_workspace, 'src') 63 golang_workspace_src = os.path.join(golang_workspace, 'src')
25 64
26 collider_dir = os.path.join(apprtc_dir, 'collider') 65 collider_dir = os.path.join(apprtc_dir, 'collider')
27 shutil.copytree(collider_dir, golang_workspace_src, 66 shutil.copytree(collider_dir, golang_workspace_src,
28 ignore=shutil.ignore_patterns('.svn', '.git')) 67 ignore=shutil.ignore_patterns('.svn', '.git'))
29 68
30 golang_binary = 'go%s' % ('.exe' if utils.GetPlatform() == 'win' else '') 69 golang_binary = 'go%s' % ('.exe' if utils.GetPlatform() == 'win' else '')
31 golang_path = os.path.join('go', 'bin', golang_binary) 70 golang_path = os.path.join('go', 'bin', golang_binary)
32 71
33 golang_env = os.environ.copy() 72 golang_env = os.environ.copy()
34 golang_env['GOROOT'] = os.path.abspath('go') 73 golang_env['GOROOT'] = os.path.abspath('go')
35 golang_env['GOPATH'] = os.path.abspath(golang_workspace) 74 golang_env['GOPATH'] = os.path.abspath(golang_workspace)
36 golang_env['PATH'] += os.pathsep + os.path.abspath('mercurial') 75 golang_env['PATH'] += os.pathsep + os.path.abspath('mercurial')
37 subprocess.check_call([golang_path, 'get', 'collidermain'], 76 subprocess.check_call([golang_path, 'get', 'collidermain'],
38 env=golang_env) 77 env=golang_env)
39 subprocess.check_call([golang_path, 'build', 'collidermain'], 78 subprocess.check_call([golang_path, 'build', 'collidermain'],
40 env=golang_env) 79 env=golang_env)
41 80
42 if __name__ == '__main__': 81 if __name__ == '__main__':
43 sys.exit(main()) 82 sys.exit(main())
83
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698