blob: c1f91b2035a7a603024d7b6dabe361799ded88b6 [file] [log] [blame]
phoglund@chromium.orgee4b03c2015-01-27 10:16:551#!/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.orga35872b2015-02-06 11:46:436"""Invokes grunt build on AppRTC.
phoglund@chromium.orgee4b03c2015-01-27 10:16:557
8The AppRTC javascript code must be closure-compiled. This script uses
9the node toolchain we downloaded earlier.
10"""
11
phoglund@chromium.org9ef23ed2015-01-28 08:29:1712import fileinput
phoglund@chromium.orgee4b03c2015-01-27 10:16:5513import os
14import shutil
phoglund@chromium.orgee4b03c2015-01-27 10:16:5515import sys
16
17import utils
18
19
phoglund@chromium.org9ef23ed2015-01-28 08:29:1720# Phantomjs generates very deep paths in the node_modules structure and
21# Windows can't deal with that, so just hack that out.
22def _WorkaroundPhantomJsOnWin(samples_path):
23 if utils.GetPlatform() is 'win':
24 package_json = os.path.join(samples_path, 'package.json')
phoglund@chromium.org182db5a2015-01-28 10:43:2725 if not os.path.exists(package_json):
26 raise Exception('Expected %s to exist.' % os.path.abspath(package_json))
phoglund@chromium.org9ef23ed2015-01-28 08:29:1727
28 for line in fileinput.input(package_json, inplace=True):
29 if not 'phantomjs' in line:
phoglund@chromium.org3542c0e2015-01-29 13:47:2030 sys.stdout.write(line)
phoglund@chromium.org9ef23ed2015-01-28 08:29:1731
32
phoglund@chromium.orgee4b03c2015-01-27 10:16:5533def 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.orga35872b2015-02-06 11:46:4337 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.orgee4b03c2015-01-27 10:16:5540
kjellander@chromium.orga35872b2015-02-06 11:46:4341 _WorkaroundPhantomJsOnWin(apprtc_path)
42 os.chdir(apprtc_path)
phoglund@chromium.orgee4b03c2015-01-27 10:16:5543
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.org56c3c6a2015-01-27 13:00:1051 utils.RunSubprocessWithRetry([npm_bin, 'install'])
phoglund@chromium.orgee4b03c2015-01-27 10:16:5552 local_grunt_bin = os.path.join('node_modules', 'grunt-cli', 'bin', 'grunt')
53
54 if not os.path.exists(local_grunt_bin):
kjellander@chromium.orga35872b2015-02-06 11:46:4355 return ('Missing grunt-cli in the apprtc checkout; did '
phoglund@chromium.orgee4b03c2015-01-27 10:16:5556 'npm install fail?')
57
kjellander@chromium.orga35872b2015-02-06 11:46:4358 utils.RunSubprocessWithRetry([node_bin, local_grunt_bin, 'build'])
phoglund@chromium.orgee4b03c2015-01-27 10:16:5559
60
61if __name__ == '__main__':
62 sys.exit(main())