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 the AppRTC closure compiler. | 6 """Invokes the AppRTC closure compiler. |
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 sys | 15 import sys |
16 | 16 |
17 import utils | 17 import utils |
18 | 18 |
19 | 19 |
20 # Phantomjs generates very deep paths in the node_modules structure and | 20 # Phantomjs generates very deep paths in the node_modules structure and |
21 # Windows can't deal with that, so just hack that out. | 21 # Windows can't deal with that, so just hack that out. |
22 def _WorkaroundPhantomJsOnWin(samples_path): | 22 def _WorkaroundPhantomJsOnWin(samples_path): |
23 if utils.GetPlatform() is 'win': | 23 if utils.GetPlatform() is 'win': |
24 package_json = os.path.join(samples_path, 'package.json') | 24 package_json = os.path.join(samples_path, 'package.json') |
| 25 if not os.path.exists(package_json): |
| 26 raise Exception('Expected %s to exist.' % os.path.abspath(package_json)) |
25 | 27 |
26 for line in fileinput.input(package_json, inplace=True): | 28 for line in fileinput.input(package_json, inplace=True): |
27 if not 'phantomjs' in line: | 29 if not 'phantomjs' in line: |
28 print line | 30 print line |
29 | 31 |
30 | 32 |
31 def main(): | 33 def main(): |
32 node_path = os.path.abspath('node') | 34 node_path = os.path.abspath('node') |
33 if not os.path.exists(node_path): | 35 if not os.path.exists(node_path): |
34 return 'Expected node at %s.' % node_path | 36 return 'Expected node at %s.' % node_path |
35 samples_path = os.path.join('src', 'out', 'webrtc-samples') | 37 samples_path = os.path.join('src', 'out', 'webrtc-samples') |
36 if not os.path.exists(samples_path): | 38 if not os.path.exists(samples_path): |
37 return 'Expected webrtc-samples at %s.' % os.path.abspath(samples_path) | 39 return 'Expected webrtc-samples at %s.' % os.path.abspath(samples_path) |
38 | 40 |
| 41 _WorkaroundPhantomJsOnWin(samples_path) |
39 os.chdir(samples_path) | 42 os.chdir(samples_path) |
40 _WorkaroundPhantomJsOnWin(samples_path) | |
41 | 43 |
42 if utils.GetPlatform() is 'win': | 44 if utils.GetPlatform() is 'win': |
43 npm_bin = os.path.join(node_path, 'npm.cmd') | 45 npm_bin = os.path.join(node_path, 'npm.cmd') |
44 node_bin = os.path.join(node_path, 'node.exe') | 46 node_bin = os.path.join(node_path, 'node.exe') |
45 else: | 47 else: |
46 npm_bin = os.path.join(node_path, 'bin', 'npm') | 48 npm_bin = os.path.join(node_path, 'bin', 'npm') |
47 node_bin = os.path.join(node_path, 'bin', 'node') | 49 node_bin = os.path.join(node_path, 'bin', 'node') |
48 | 50 |
49 utils.RunSubprocessWithRetry([npm_bin, 'install']) | 51 utils.RunSubprocessWithRetry([npm_bin, 'install']) |
50 local_grunt_bin = os.path.join('node_modules', 'grunt-cli', 'bin', 'grunt') | 52 local_grunt_bin = os.path.join('node_modules', 'grunt-cli', 'bin', 'grunt') |
51 | 53 |
52 if not os.path.exists(local_grunt_bin): | 54 if not os.path.exists(local_grunt_bin): |
53 return ('Missing grunt-cli in the webrtc-samples checkout; did ' | 55 return ('Missing grunt-cli in the webrtc-samples checkout; did ' |
54 'npm install fail?') | 56 'npm install fail?') |
55 | 57 |
56 utils.RunSubprocessWithRetry([node_bin, local_grunt_bin, | 58 utils.RunSubprocessWithRetry([node_bin, local_grunt_bin, |
57 'closurecompiler:debug']) | 59 'closurecompiler:debug']) |
58 | 60 |
59 | 61 |
60 if __name__ == '__main__': | 62 if __name__ == '__main__': |
61 sys.exit(main()) | 63 sys.exit(main()) |
OLD | NEW |