OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 """Invokes grunt build on AppRTC. | 6 """Invokes grunt build on AppRTC. |
7 | 7 |
8 The AppRTC javascript code must be closure-compiled. This script uses | 8 The AppRTC javascript code must be closure-compiled. This script uses |
9 the node toolchain we downloaded earlier. | 9 the node toolchain we downloaded earlier. |
10 """ | 10 """ |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 for line in fileinput.input(package_json, inplace=True): | 29 for line in fileinput.input(package_json, inplace=True): |
30 if not 'phantomjs' in line: | 30 if not 'phantomjs' in line: |
31 sys.stdout.write(line) | 31 sys.stdout.write(line) |
32 | 32 |
33 | 33 |
34 def _WorkAroundMacNpmCorruptedDataOnInstall(command): | 34 def _WorkAroundMacNpmCorruptedDataOnInstall(command): |
35 print 'Wiping .npm folder and trying again...' | 35 print 'Wiping .npm folder and trying again...' |
36 npm_storage = os.path.expanduser('~/.npm') | 36 npm_storage = os.path.expanduser('~/.npm') |
37 assert npm_storage.endswith('.npm') | 37 assert npm_storage.endswith('.npm') |
38 shutil.rmtree(npm_storage, ignore_errors=True) | 38 utils.RemoveDirectory(npm_storage) |
39 utils.RunSubprocessWithRetry(command) | 39 utils.RunSubprocessWithRetry(command) |
40 | 40 |
41 | 41 |
42 def main(): | 42 def main(): |
43 node_path = os.path.abspath('node') | 43 node_path = os.path.abspath('node') |
44 if not os.path.exists(node_path): | 44 if not os.path.exists(node_path): |
45 return 'Expected node at %s.' % node_path | 45 return 'Expected node at %s.' % node_path |
46 apprtc_path = os.path.join('src', 'out', 'apprtc') | 46 apprtc_path = os.path.join('src', 'out', 'apprtc') |
47 if not os.path.exists(apprtc_path): | 47 if not os.path.exists(apprtc_path): |
48 return 'Expected apprtc at %s.' % os.path.abspath(apprtc_path) | 48 return 'Expected apprtc at %s.' % os.path.abspath(apprtc_path) |
49 | 49 |
50 _WorkaroundPhantomJsOnWin(apprtc_path) | 50 _WorkaroundPhantomJsOnWin(apprtc_path) |
51 os.chdir(apprtc_path) | 51 os.chdir(apprtc_path) |
52 | 52 |
53 if utils.GetPlatform() is 'win': | 53 if utils.GetPlatform() is 'win': |
54 npm_bin = os.path.join(node_path, 'npm.cmd') | 54 npm_bin = os.path.join(node_path, 'npm.cmd') |
55 node_bin = os.path.join(node_path, 'node.exe') | 55 node_bin = os.path.join(node_path, 'node.exe') |
56 else: | 56 else: |
57 npm_bin = os.path.join(node_path, 'bin', 'npm') | 57 npm_bin = os.path.join(node_path, 'bin', 'npm') |
58 node_bin = os.path.join(node_path, 'bin', 'node') | 58 node_bin = os.path.join(node_path, 'bin', 'node') |
59 | 59 |
60 command = [npm_bin, 'install'] | 60 command = [npm_bin, 'install'] |
61 try: | 61 try: |
62 utils.RunSubprocessWithRetry(command) | 62 utils.RunSubprocessWithRetry(command) |
63 except subprocess.CalledProcessError: | 63 except subprocess.CalledProcessError: |
64 if utils.GetPlatform() is not 'mac': | 64 if utils.GetPlatform() is not 'mac': |
65 raise | 65 raise |
66 _WorkAroundMacNpmCorruptedDataOnInstall(command) | 66 _WorkAroundMacNpmCorruptedDataOnInstall(command) |
67 | 67 |
68 local_grunt_bin = os.path.join('node_modules', 'grunt-cli', 'bin', 'grunt') | 68 local_grunt_bin = os.path.join('node_modules', 'grunt-cli', 'bin', 'grunt') |
69 | 69 |
70 if not os.path.exists(local_grunt_bin): | 70 if not os.path.exists(local_grunt_bin): |
71 return ('Missing grunt-cli in the apprtc checkout; did ' | 71 return ('Missing grunt-cli in the apprtc checkout; did ' |
72 'npm install fail?') | 72 'npm install fail?') |
73 | 73 |
74 utils.RunSubprocessWithRetry([node_bin, local_grunt_bin, 'build']) | 74 utils.RunSubprocessWithRetry([node_bin, local_grunt_bin, 'build']) |
75 | 75 |
76 | 76 |
77 if __name__ == '__main__': | 77 if __name__ == '__main__': |
78 sys.exit(main()) | 78 sys.exit(main()) |
OLD | NEW |