| OLD | NEW |
| 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 | |
| 17 | 16 |
| 18 import utils | 17 import utils |
| 19 | 18 |
| 20 | 19 |
| 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 | |
| 58 def main(): | 20 def main(): |
| 59 apprtc_dir = os.path.join('apprtc', 'src') | 21 apprtc_dir = os.path.join('apprtc', 'src') |
| 60 golang_workspace = os.path.join('src', 'out', 'go-workspace') | 22 golang_workspace = os.path.join('src', 'out', 'go-workspace') |
| 61 RemoveDirectory(golang_workspace) | 23 utils.RemoveDirectory(golang_workspace) |
| 62 | 24 |
| 63 golang_workspace_src = os.path.join(golang_workspace, 'src') | 25 golang_workspace_src = os.path.join(golang_workspace, 'src') |
| 64 | 26 |
| 65 collider_dir = os.path.join(apprtc_dir, 'collider') | 27 collider_dir = os.path.join(apprtc_dir, 'collider') |
| 66 shutil.copytree(collider_dir, golang_workspace_src, | 28 shutil.copytree(collider_dir, golang_workspace_src, |
| 67 ignore=shutil.ignore_patterns('.svn', '.git')) | 29 ignore=shutil.ignore_patterns('.svn', '.git')) |
| 68 | 30 |
| 69 golang_binary = 'go%s' % ('.exe' if utils.GetPlatform() == 'win' else '') | 31 golang_binary = 'go%s' % ('.exe' if utils.GetPlatform() == 'win' else '') |
| 70 golang_path = os.path.join('go', 'bin', golang_binary) | 32 golang_path = os.path.join('go', 'bin', golang_binary) |
| 71 | 33 |
| 72 golang_env = os.environ.copy() | 34 golang_env = os.environ.copy() |
| 73 golang_env['GOROOT'] = os.path.abspath('go') | 35 golang_env['GOROOT'] = os.path.abspath('go') |
| 74 golang_env['GOPATH'] = os.path.abspath(golang_workspace) | 36 golang_env['GOPATH'] = os.path.abspath(golang_workspace) |
| 75 golang_env['PATH'] += os.pathsep + os.path.abspath('mercurial') | 37 golang_env['PATH'] += os.pathsep + os.path.abspath('mercurial') |
| 76 subprocess.check_call([golang_path, 'get', 'collidermain'], | 38 subprocess.check_call([golang_path, 'get', 'collidermain'], |
| 77 env=golang_env) | 39 env=golang_env) |
| 78 subprocess.check_call([golang_path, 'build', 'collidermain'], | 40 subprocess.check_call([golang_path, 'build', 'collidermain'], |
| 79 env=golang_env) | 41 env=golang_env) |
| 80 | 42 |
| 81 if __name__ == '__main__': | 43 if __name__ == '__main__': |
| 82 sys.exit(main()) | 44 sys.exit(main()) |
| 83 | 45 |
| OLD | NEW |