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 os | 13 import os |
13 import shutil | 14 import shutil |
14 import sys | 15 import sys |
15 | 16 |
16 import utils | 17 import utils |
17 | 18 |
18 | 19 |
20 # Phantomjs generates very deep paths in the node_modules structure and | |
21 # Windows can't deal with that, so just hack that out. | |
22 def _WorkaroundPhantomJsOnWin(samples_path): | |
23 if utils.GetPlatform() is 'win': | |
24 package_json = os.path.join(samples_path, 'package.json') | |
25 | |
26 for line in fileinput.input(package_json, inplace=True): | |
kjellander_chromium
2015/01/27 21:00:30
Ha, I didn't know about this module. Very neat for
phoglund_chromium
2015/01/28 08:29:02
It is short, but it's really, really strange that
| |
27 if not 'phantomjs' in line: | |
28 print line | |
29 | |
30 | |
19 def main(): | 31 def main(): |
20 node_path = os.path.abspath('node') | 32 node_path = os.path.abspath('node') |
21 if not os.path.exists(node_path): | 33 if not os.path.exists(node_path): |
22 return 'Expected node at %s.' % node_path | 34 return 'Expected node at %s.' % node_path |
23 samples_path = os.path.join('src', 'out', 'webrtc-samples') | 35 samples_path = os.path.join('src', 'out', 'webrtc-samples') |
24 if not os.path.exists(samples_path): | 36 if not os.path.exists(samples_path): |
25 return 'Expected webrtc-samples at %s.' % os.path.abspath(samples_path) | 37 return 'Expected webrtc-samples at %s.' % os.path.abspath(samples_path) |
26 | 38 |
27 os.chdir(samples_path) | 39 os.chdir(samples_path) |
40 _WorkaroundPhantomJsOnWin(samples_path) | |
28 | 41 |
29 if utils.GetPlatform() is 'win': | 42 if utils.GetPlatform() is 'win': |
30 npm_bin = os.path.join(node_path, 'npm.cmd') | 43 npm_bin = os.path.join(node_path, 'npm.cmd') |
31 node_bin = os.path.join(node_path, 'node.exe') | 44 node_bin = os.path.join(node_path, 'node.exe') |
32 else: | 45 else: |
33 npm_bin = os.path.join(node_path, 'bin', 'npm') | 46 npm_bin = os.path.join(node_path, 'bin', 'npm') |
34 node_bin = os.path.join(node_path, 'bin', 'node') | 47 node_bin = os.path.join(node_path, 'bin', 'node') |
35 | 48 |
36 utils.RunSubprocessWithRetry([npm_bin, 'install']) | 49 utils.RunSubprocessWithRetry([npm_bin, 'install']) |
37 local_grunt_bin = os.path.join('node_modules', 'grunt-cli', 'bin', 'grunt') | 50 local_grunt_bin = os.path.join('node_modules', 'grunt-cli', 'bin', 'grunt') |
38 | 51 |
39 if not os.path.exists(local_grunt_bin): | 52 if not os.path.exists(local_grunt_bin): |
40 return ('Missing grunt-cli in the webrtc-samples checkout; did ' | 53 return ('Missing grunt-cli in the webrtc-samples checkout; did ' |
41 'npm install fail?') | 54 'npm install fail?') |
42 | 55 |
43 utils.RunSubprocessWithRetry([node_bin, local_grunt_bin, | 56 utils.RunSubprocessWithRetry([node_bin, local_grunt_bin, |
44 'closurecompiler:debug']) | 57 'closurecompiler:debug']) |
45 | 58 |
46 | 59 |
47 if __name__ == '__main__': | 60 if __name__ == '__main__': |
48 sys.exit(main()) | 61 sys.exit(main()) |
OLD | NEW |