1#!/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. 9"""Builds the AppRTC collider using the golang toolchain. 10 11The golang toolchain is downloaded by download_apprtc.py. We use that here 12to build the AppRTC collider server. 13 14This script needs to know the path to the 'src' directory in apprtc, the 15root directory of 'go' and the output_dir. 16""" 17 18import fileinput 19import os 20import shutil 21import subprocess 22import sys 23 24import utils 25 26USAGE_STR = "Usage: {} <apprtc_dir> <go_dir> <output_dir>" 27 28 29def _ConfigureApprtcServerToDeveloperMode(app_yaml_path): 30 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) 35 36 37def main(argv): 38 if len(argv) != 4: 39 print(USAGE_STR.format(argv[0])) 40 41 apprtc_dir = os.path.abspath(argv[1]) 42 go_root_dir = os.path.abspath(argv[2]) 43 golang_workspace = os.path.abspath(argv[3]) 44 45 app_yaml_path = os.path.join(apprtc_dir, 'out', 'app_engine', 'app.yaml') 46 _ConfigureApprtcServerToDeveloperMode(app_yaml_path) 47 48 utils.RemoveDirectory(golang_workspace) 49 50 collider_dir = os.path.join(apprtc_dir, 'src', 'collider') 51 shutil.copytree(collider_dir, os.path.join(golang_workspace, 'src')) 52 53 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 golang_env['GO111MODULE'] = 'off' 59 collider_out = os.path.join(golang_workspace, 60 'collidermain' + utils.GetExecutableExtension()) 61 subprocess.check_call( 62 [golang_path, 'build', '-o', collider_out, 'collidermain'], 63 env=golang_env) 64 65 66if __name__ == '__main__': 67 sys.exit(main(sys.argv)) 68