phoglund@chromium.org | ee4b03c | 2015-01-27 10:16:55 | [diff] [blame] | 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 | |
kjellander@chromium.org | a35872b | 2015-02-06 11:46:43 | [diff] [blame] | 6 | """Invokes grunt build on AppRTC. |
phoglund@chromium.org | ee4b03c | 2015-01-27 10:16:55 | [diff] [blame] | 7 | |
| 8 | The AppRTC javascript code must be closure-compiled. This script uses |
| 9 | the node toolchain we downloaded earlier. |
| 10 | """ |
| 11 | |
phoglund@chromium.org | 9ef23ed | 2015-01-28 08:29:17 | [diff] [blame] | 12 | import fileinput |
phoglund@chromium.org | ee4b03c | 2015-01-27 10:16:55 | [diff] [blame] | 13 | import os |
| 14 | import shutil |
phoglund@chromium.org | ee4b03c | 2015-01-27 10:16:55 | [diff] [blame] | 15 | import sys |
| 16 | |
| 17 | import utils |
| 18 | |
| 19 | |
phoglund@chromium.org | 9ef23ed | 2015-01-28 08:29:17 | [diff] [blame] | 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') |
phoglund@chromium.org | 182db5a | 2015-01-28 10:43:27 | [diff] [blame] | 25 | if not os.path.exists(package_json): |
| 26 | raise Exception('Expected %s to exist.' % os.path.abspath(package_json)) |
phoglund@chromium.org | 9ef23ed | 2015-01-28 08:29:17 | [diff] [blame] | 27 | |
| 28 | for line in fileinput.input(package_json, inplace=True): |
| 29 | if not 'phantomjs' in line: |
phoglund@chromium.org | 3542c0e | 2015-01-29 13:47:20 | [diff] [blame] | 30 | sys.stdout.write(line) |
phoglund@chromium.org | 9ef23ed | 2015-01-28 08:29:17 | [diff] [blame] | 31 | |
| 32 | |
phoglund@chromium.org | ee4b03c | 2015-01-27 10:16:55 | [diff] [blame] | 33 | def main(): |
| 34 | node_path = os.path.abspath('node') |
| 35 | if not os.path.exists(node_path): |
| 36 | return 'Expected node at %s.' % node_path |
kjellander@chromium.org | a35872b | 2015-02-06 11:46:43 | [diff] [blame] | 37 | apprtc_path = os.path.join('src', 'out', 'apprtc') |
| 38 | if not os.path.exists(apprtc_path): |
| 39 | return 'Expected apprtc at %s.' % os.path.abspath(apprtc_path) |
phoglund@chromium.org | ee4b03c | 2015-01-27 10:16:55 | [diff] [blame] | 40 | |
kjellander@chromium.org | a35872b | 2015-02-06 11:46:43 | [diff] [blame] | 41 | _WorkaroundPhantomJsOnWin(apprtc_path) |
| 42 | os.chdir(apprtc_path) |
phoglund@chromium.org | ee4b03c | 2015-01-27 10:16:55 | [diff] [blame] | 43 | |
| 44 | if utils.GetPlatform() is 'win': |
| 45 | npm_bin = os.path.join(node_path, 'npm.cmd') |
| 46 | node_bin = os.path.join(node_path, 'node.exe') |
| 47 | else: |
| 48 | npm_bin = os.path.join(node_path, 'bin', 'npm') |
| 49 | node_bin = os.path.join(node_path, 'bin', 'node') |
| 50 | |
phoglund@chromium.org | 56c3c6a | 2015-01-27 13:00:10 | [diff] [blame] | 51 | utils.RunSubprocessWithRetry([npm_bin, 'install']) |
phoglund@chromium.org | ee4b03c | 2015-01-27 10:16:55 | [diff] [blame] | 52 | local_grunt_bin = os.path.join('node_modules', 'grunt-cli', 'bin', 'grunt') |
| 53 | |
| 54 | if not os.path.exists(local_grunt_bin): |
kjellander@chromium.org | a35872b | 2015-02-06 11:46:43 | [diff] [blame] | 55 | return ('Missing grunt-cli in the apprtc checkout; did ' |
phoglund@chromium.org | ee4b03c | 2015-01-27 10:16:55 | [diff] [blame] | 56 | 'npm install fail?') |
| 57 | |
kjellander@chromium.org | a35872b | 2015-02-06 11:46:43 | [diff] [blame] | 58 | utils.RunSubprocessWithRetry([node_bin, local_grunt_bin, 'build']) |
phoglund@chromium.org | ee4b03c | 2015-01-27 10:16:55 | [diff] [blame] | 59 | |
| 60 | |
| 61 | if __name__ == '__main__': |
| 62 | sys.exit(main()) |