blob: e93b7e06c7bf3182ee0a5476e978fb32f56b1e3e [file] [log] [blame]
mbonadei9e5841a2017-05-09 00:13:47 -07001#!/usr/bin/env python
2# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3#
4# Use of this source code is governed by a BSD-style license
5# that can be found in the LICENSE file in the root of the source
6# tree. An additional intellectual property rights grant can be found
7# in the file PATENTS. All contributing project authors may
8# be found in the AUTHORS file in the root of the source tree.
mbonadei9e5841a2017-05-09 00:13:47 -07009"""Builds the AppRTC collider using the golang toolchain.
10
oprypin1d7392a2017-05-16 05:36:15 -070011The golang toolchain is downloaded by download_apprtc.py. We use that here
mbonadei9e5841a2017-05-09 00:13:47 -070012to build the AppRTC collider server.
13
14This script needs to know the path to the 'src' directory in apprtc, the
oprypin1d7392a2017-05-16 05:36:15 -070015root directory of 'go' and the output_dir.
mbonadei9e5841a2017-05-09 00:13:47 -070016"""
17
Oleh Prypin8058fbb2018-04-04 10:04:46 +020018import fileinput
mbonadei9e5841a2017-05-09 00:13:47 -070019import os
20import shutil
21import subprocess
22import sys
23
24import utils
25
Oleh Prypin8058fbb2018-04-04 10:04:46 +020026USAGE_STR = "Usage: {} <apprtc_dir> <go_dir> <output_dir>"
27
28
29def _ConfigureApprtcServerToDeveloperMode(app_yaml_path):
Mirko Bonadei8cc66952020-10-30 10:13:45 +010030 for line in fileinput.input(app_yaml_path, inplace=True):
31 # We can't click past these in browser-based tests, so disable them.
32 line = line.replace('BYPASS_JOIN_CONFIRMATION: false',
33 'BYPASS_JOIN_CONFIRMATION: true')
34 sys.stdout.write(line)
mbonadei9e5841a2017-05-09 00:13:47 -070035
36
37def main(argv):
Mirko Bonadei8cc66952020-10-30 10:13:45 +010038 if len(argv) != 4:
39 return USAGE_STR.format(argv[0])
mbonadei9e5841a2017-05-09 00:13:47 -070040
Mirko Bonadei8cc66952020-10-30 10:13:45 +010041 apprtc_dir = os.path.abspath(argv[1])
42 go_root_dir = os.path.abspath(argv[2])
43 golang_workspace = os.path.abspath(argv[3])
mbonadei9e5841a2017-05-09 00:13:47 -070044
Mirko Bonadei8cc66952020-10-30 10:13:45 +010045 app_yaml_path = os.path.join(apprtc_dir, 'out', 'app_engine', 'app.yaml')
46 _ConfigureApprtcServerToDeveloperMode(app_yaml_path)
Oleh Prypin8058fbb2018-04-04 10:04:46 +020047
Mirko Bonadei8cc66952020-10-30 10:13:45 +010048 utils.RemoveDirectory(golang_workspace)
mbonadei9e5841a2017-05-09 00:13:47 -070049
Mirko Bonadei8cc66952020-10-30 10:13:45 +010050 collider_dir = os.path.join(apprtc_dir, 'src', 'collider')
51 shutil.copytree(collider_dir, os.path.join(golang_workspace, 'src'))
mbonadei9e5841a2017-05-09 00:13:47 -070052
Mirko Bonadei8cc66952020-10-30 10:13:45 +010053 golang_path = os.path.join(go_root_dir, 'bin',
54 'go' + utils.GetExecutableExtension())
55 golang_env = os.environ.copy()
56 golang_env['GOROOT'] = go_root_dir
57 golang_env['GOPATH'] = golang_workspace
58 collider_out = os.path.join(
59 golang_workspace, 'collidermain' + utils.GetExecutableExtension())
60 subprocess.check_call(
61 [golang_path, 'build', '-o', collider_out, 'collidermain'],
62 env=golang_env)
mbonadei9e5841a2017-05-09 00:13:47 -070063
64
65if __name__ == '__main__':
Mirko Bonadei8cc66952020-10-30 10:13:45 +010066 sys.exit(main(sys.argv))