xref: /aosp_15_r20/external/webrtc/rtc_tools/testing/build_apprtc.py (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker#!/usr/bin/env python
2*d9f75844SAndroid Build Coastguard Worker# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker#
4*d9f75844SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker# that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker# tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker# in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker# be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker"""Builds the AppRTC collider using the golang toolchain.
10*d9f75844SAndroid Build Coastguard Worker
11*d9f75844SAndroid Build Coastguard WorkerThe golang toolchain is downloaded by download_apprtc.py. We use that here
12*d9f75844SAndroid Build Coastguard Workerto build the AppRTC collider server.
13*d9f75844SAndroid Build Coastguard Worker
14*d9f75844SAndroid Build Coastguard WorkerThis script needs to know the path to the 'src' directory in apprtc, the
15*d9f75844SAndroid Build Coastguard Workerroot directory of 'go' and the output_dir.
16*d9f75844SAndroid Build Coastguard Worker"""
17*d9f75844SAndroid Build Coastguard Worker
18*d9f75844SAndroid Build Coastguard Workerimport fileinput
19*d9f75844SAndroid Build Coastguard Workerimport os
20*d9f75844SAndroid Build Coastguard Workerimport shutil
21*d9f75844SAndroid Build Coastguard Workerimport subprocess
22*d9f75844SAndroid Build Coastguard Workerimport sys
23*d9f75844SAndroid Build Coastguard Worker
24*d9f75844SAndroid Build Coastguard Workerimport utils
25*d9f75844SAndroid Build Coastguard Worker
26*d9f75844SAndroid Build Coastguard WorkerUSAGE_STR = "Usage: {} <apprtc_dir> <go_dir> <output_dir>"
27*d9f75844SAndroid Build Coastguard Worker
28*d9f75844SAndroid Build Coastguard Worker
29*d9f75844SAndroid Build Coastguard Workerdef _ConfigureApprtcServerToDeveloperMode(app_yaml_path):
30*d9f75844SAndroid Build Coastguard Worker  for line in fileinput.input(app_yaml_path, inplace=True):
31*d9f75844SAndroid Build Coastguard Worker    # We can't click past these in browser-based tests, so disable them.
32*d9f75844SAndroid Build Coastguard Worker    line = line.replace('BYPASS_JOIN_CONFIRMATION: false',
33*d9f75844SAndroid Build Coastguard Worker                        'BYPASS_JOIN_CONFIRMATION: true')
34*d9f75844SAndroid Build Coastguard Worker    sys.stdout.write(line)
35*d9f75844SAndroid Build Coastguard Worker
36*d9f75844SAndroid Build Coastguard Worker
37*d9f75844SAndroid Build Coastguard Workerdef main(argv):
38*d9f75844SAndroid Build Coastguard Worker  if len(argv) != 4:
39*d9f75844SAndroid Build Coastguard Worker    print(USAGE_STR.format(argv[0]))
40*d9f75844SAndroid Build Coastguard Worker
41*d9f75844SAndroid Build Coastguard Worker  apprtc_dir = os.path.abspath(argv[1])
42*d9f75844SAndroid Build Coastguard Worker  go_root_dir = os.path.abspath(argv[2])
43*d9f75844SAndroid Build Coastguard Worker  golang_workspace = os.path.abspath(argv[3])
44*d9f75844SAndroid Build Coastguard Worker
45*d9f75844SAndroid Build Coastguard Worker  app_yaml_path = os.path.join(apprtc_dir, 'out', 'app_engine', 'app.yaml')
46*d9f75844SAndroid Build Coastguard Worker  _ConfigureApprtcServerToDeveloperMode(app_yaml_path)
47*d9f75844SAndroid Build Coastguard Worker
48*d9f75844SAndroid Build Coastguard Worker  utils.RemoveDirectory(golang_workspace)
49*d9f75844SAndroid Build Coastguard Worker
50*d9f75844SAndroid Build Coastguard Worker  collider_dir = os.path.join(apprtc_dir, 'src', 'collider')
51*d9f75844SAndroid Build Coastguard Worker  shutil.copytree(collider_dir, os.path.join(golang_workspace, 'src'))
52*d9f75844SAndroid Build Coastguard Worker
53*d9f75844SAndroid Build Coastguard Worker  golang_path = os.path.join(go_root_dir, 'bin',
54*d9f75844SAndroid Build Coastguard Worker                             'go' + utils.GetExecutableExtension())
55*d9f75844SAndroid Build Coastguard Worker  golang_env = os.environ.copy()
56*d9f75844SAndroid Build Coastguard Worker  golang_env['GOROOT'] = go_root_dir
57*d9f75844SAndroid Build Coastguard Worker  golang_env['GOPATH'] = golang_workspace
58*d9f75844SAndroid Build Coastguard Worker  golang_env['GO111MODULE'] = 'off'
59*d9f75844SAndroid Build Coastguard Worker  collider_out = os.path.join(golang_workspace,
60*d9f75844SAndroid Build Coastguard Worker                              'collidermain' + utils.GetExecutableExtension())
61*d9f75844SAndroid Build Coastguard Worker  subprocess.check_call(
62*d9f75844SAndroid Build Coastguard Worker      [golang_path, 'build', '-o', collider_out, 'collidermain'],
63*d9f75844SAndroid Build Coastguard Worker      env=golang_env)
64*d9f75844SAndroid Build Coastguard Worker
65*d9f75844SAndroid Build Coastguard Worker
66*d9f75844SAndroid Build Coastguard Workerif __name__ == '__main__':
67*d9f75844SAndroid Build Coastguard Worker  sys.exit(main(sys.argv))
68