OLD | NEW |
| (Empty) |
1 #!/usr/bin/python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 """Invokes grunt build on AppRTC. | |
7 | |
8 The AppRTC javascript code must be closure-compiled. This script uses | |
9 the node toolchain we downloaded earlier. | |
10 """ | |
11 | |
12 import fileinput | |
13 import os | |
14 import shutil | |
15 import subprocess | |
16 import sys | |
17 | |
18 import utils | |
19 | |
20 | |
21 # Phantomjs generates very deep paths in the node_modules structure and | |
22 # Windows can't deal with that, so just hack that out. | |
23 def _WorkaroundPhantomJsOnWin(samples_path): | |
24 if utils.GetPlatform() is 'win': | |
25 package_json = os.path.join(samples_path, 'package.json') | |
26 if not os.path.exists(package_json): | |
27 raise Exception('Expected %s to exist.' % os.path.abspath(package_json)) | |
28 | |
29 for line in fileinput.input(package_json, inplace=True): | |
30 if not 'phantomjs' in line: | |
31 sys.stdout.write(line) | |
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 utils.RemoveDirectory(npm_storage) | |
39 utils.RunSubprocessWithRetry(command) | |
40 | |
41 | |
42 def main(): | |
43 node_path = os.path.abspath('node') | |
44 if not os.path.exists(node_path): | |
45 return 'Expected node at %s.' % node_path | |
46 apprtc_path = os.path.join('src', 'out', 'apprtc') | |
47 if not os.path.exists(apprtc_path): | |
48 return 'Expected apprtc at %s.' % os.path.abspath(apprtc_path) | |
49 | |
50 _WorkaroundPhantomJsOnWin(apprtc_path) | |
51 os.chdir(apprtc_path) | |
52 | |
53 if utils.GetPlatform() is 'win': | |
54 npm_bin = os.path.join(node_path, 'npm.cmd') | |
55 node_bin = os.path.join(node_path, 'node.exe') | |
56 else: | |
57 npm_bin = os.path.join(node_path, 'bin', 'npm') | |
58 node_bin = os.path.join(node_path, 'bin', 'node') | |
59 | |
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 | |
68 local_grunt_bin = os.path.join('node_modules', 'grunt-cli', 'bin', 'grunt') | |
69 | |
70 if not os.path.exists(local_grunt_bin): | |
71 return ('Missing grunt-cli in the apprtc checkout; did ' | |
72 'npm install fail?') | |
73 | |
74 utils.RunSubprocessWithRetry([node_bin, local_grunt_bin, 'build']) | |
75 | |
76 | |
77 if __name__ == '__main__': | |
78 sys.exit(main()) | |
OLD | NEW |