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 """ |
11 | 11 |
12 import fileinput | 12 import fileinput |
13 import os | 13 import os |
14 import shutil | 14 import shutil |
| 15 import subprocess |
15 import sys | 16 import sys |
16 | 17 |
17 import utils | 18 import utils |
18 | 19 |
19 | 20 |
20 # Phantomjs generates very deep paths in the node_modules structure and | 21 # Phantomjs generates very deep paths in the node_modules structure and |
21 # Windows can't deal with that, so just hack that out. | 22 # Windows can't deal with that, so just hack that out. |
22 def _WorkaroundPhantomJsOnWin(samples_path): | 23 def _WorkaroundPhantomJsOnWin(samples_path): |
23 if utils.GetPlatform() is 'win': | 24 if utils.GetPlatform() is 'win': |
24 package_json = os.path.join(samples_path, 'package.json') | 25 package_json = os.path.join(samples_path, 'package.json') |
25 if not os.path.exists(package_json): | 26 if not os.path.exists(package_json): |
26 raise Exception('Expected %s to exist.' % os.path.abspath(package_json)) | 27 raise Exception('Expected %s to exist.' % os.path.abspath(package_json)) |
27 | 28 |
28 for line in fileinput.input(package_json, inplace=True): | 29 for line in fileinput.input(package_json, inplace=True): |
29 if not 'phantomjs' in line: | 30 if not 'phantomjs' in line: |
30 sys.stdout.write(line) | 31 sys.stdout.write(line) |
31 | 32 |
32 | 33 |
| 34 def _WorkAroundMacNpmCorruptedDataOnInstall(command): |
| 35 print 'Wiping .npm folder and trying again...' |
| 36 npm_storage = os.path.expanduser('~/.npm') |
| 37 assert npm_storage.endswith('.npm') |
| 38 shutil.rmtree(npm_storage, ignore_errors=True) |
| 39 utils.RunSubprocessWithRetry(command) |
| 40 |
| 41 |
33 def main(): | 42 def main(): |
34 node_path = os.path.abspath('node') | 43 node_path = os.path.abspath('node') |
35 if not os.path.exists(node_path): | 44 if not os.path.exists(node_path): |
36 return 'Expected node at %s.' % node_path | 45 return 'Expected node at %s.' % node_path |
37 apprtc_path = os.path.join('src', 'out', 'apprtc') | 46 apprtc_path = os.path.join('src', 'out', 'apprtc') |
38 if not os.path.exists(apprtc_path): | 47 if not os.path.exists(apprtc_path): |
39 return 'Expected apprtc at %s.' % os.path.abspath(apprtc_path) | 48 return 'Expected apprtc at %s.' % os.path.abspath(apprtc_path) |
40 | 49 |
41 _WorkaroundPhantomJsOnWin(apprtc_path) | 50 _WorkaroundPhantomJsOnWin(apprtc_path) |
42 os.chdir(apprtc_path) | 51 os.chdir(apprtc_path) |
43 | 52 |
44 if utils.GetPlatform() is 'win': | 53 if utils.GetPlatform() is 'win': |
45 npm_bin = os.path.join(node_path, 'npm.cmd') | 54 npm_bin = os.path.join(node_path, 'npm.cmd') |
46 node_bin = os.path.join(node_path, 'node.exe') | 55 node_bin = os.path.join(node_path, 'node.exe') |
47 else: | 56 else: |
48 npm_bin = os.path.join(node_path, 'bin', 'npm') | 57 npm_bin = os.path.join(node_path, 'bin', 'npm') |
49 node_bin = os.path.join(node_path, 'bin', 'node') | 58 node_bin = os.path.join(node_path, 'bin', 'node') |
50 | 59 |
51 utils.RunSubprocessWithRetry([npm_bin, 'install']) | 60 command = [npm_bin, 'install'] |
| 61 try: |
| 62 utils.RunSubprocessWithRetry(command) |
| 63 except subprocess.CalledProcessError: |
| 64 if utils.GetPlatform() is not 'mac': |
| 65 raise |
| 66 _WorkAroundMacNpmCorruptedDataOnInstall(command) |
| 67 |
52 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') |
53 | 69 |
54 if not os.path.exists(local_grunt_bin): | 70 if not os.path.exists(local_grunt_bin): |
55 return ('Missing grunt-cli in the apprtc checkout; did ' | 71 return ('Missing grunt-cli in the apprtc checkout; did ' |
56 'npm install fail?') | 72 'npm install fail?') |
57 | 73 |
58 utils.RunSubprocessWithRetry([node_bin, local_grunt_bin, 'build']) | 74 utils.RunSubprocessWithRetry([node_bin, local_grunt_bin, 'build']) |
59 | 75 |
60 | 76 |
61 if __name__ == '__main__': | 77 if __name__ == '__main__': |
62 sys.exit(main()) | 78 sys.exit(main()) |
OLD | NEW |