mbonadei | 9e5841a | 2017-05-09 00:13:47 -0700 | [diff] [blame] | 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. |
mbonadei | 9e5841a | 2017-05-09 00:13:47 -0700 | [diff] [blame] | 9 | """Builds the AppRTC collider using the golang toolchain. |
| 10 | |
oprypin | 1d7392a | 2017-05-16 05:36:15 -0700 | [diff] [blame] | 11 | The golang toolchain is downloaded by download_apprtc.py. We use that here |
mbonadei | 9e5841a | 2017-05-09 00:13:47 -0700 | [diff] [blame] | 12 | to build the AppRTC collider server. |
| 13 | |
| 14 | This script needs to know the path to the 'src' directory in apprtc, the |
oprypin | 1d7392a | 2017-05-16 05:36:15 -0700 | [diff] [blame] | 15 | root directory of 'go' and the output_dir. |
mbonadei | 9e5841a | 2017-05-09 00:13:47 -0700 | [diff] [blame] | 16 | """ |
| 17 | |
Oleh Prypin | 8058fbb | 2018-04-04 10:04:46 +0200 | [diff] [blame] | 18 | import fileinput |
mbonadei | 9e5841a | 2017-05-09 00:13:47 -0700 | [diff] [blame] | 19 | import os |
| 20 | import shutil |
| 21 | import subprocess |
| 22 | import sys |
| 23 | |
| 24 | import utils |
| 25 | |
Oleh Prypin | 8058fbb | 2018-04-04 10:04:46 +0200 | [diff] [blame] | 26 | USAGE_STR = "Usage: {} <apprtc_dir> <go_dir> <output_dir>" |
| 27 | |
| 28 | |
| 29 | def _ConfigureApprtcServerToDeveloperMode(app_yaml_path): |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 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) |
mbonadei | 9e5841a | 2017-05-09 00:13:47 -0700 | [diff] [blame] | 35 | |
| 36 | |
| 37 | def main(argv): |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 38 | if len(argv) != 4: |
| 39 | return USAGE_STR.format(argv[0]) |
mbonadei | 9e5841a | 2017-05-09 00:13:47 -0700 | [diff] [blame] | 40 | |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 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]) |
mbonadei | 9e5841a | 2017-05-09 00:13:47 -0700 | [diff] [blame] | 44 | |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 45 | app_yaml_path = os.path.join(apprtc_dir, 'out', 'app_engine', 'app.yaml') |
| 46 | _ConfigureApprtcServerToDeveloperMode(app_yaml_path) |
Oleh Prypin | 8058fbb | 2018-04-04 10:04:46 +0200 | [diff] [blame] | 47 | |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 48 | utils.RemoveDirectory(golang_workspace) |
mbonadei | 9e5841a | 2017-05-09 00:13:47 -0700 | [diff] [blame] | 49 | |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 50 | collider_dir = os.path.join(apprtc_dir, 'src', 'collider') |
| 51 | shutil.copytree(collider_dir, os.path.join(golang_workspace, 'src')) |
mbonadei | 9e5841a | 2017-05-09 00:13:47 -0700 | [diff] [blame] | 52 | |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 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 |
Mirko Bonadei | 7d9f0dc | 2022-08-12 08:58:59 +0200 | [diff] [blame^] | 58 | golang_env['GO111MODULE'] = 'off' |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 59 | collider_out = os.path.join( |
| 60 | golang_workspace, 'collidermain' + utils.GetExecutableExtension()) |
| 61 | subprocess.check_call( |
| 62 | [golang_path, 'build', '-o', collider_out, 'collidermain'], |
| 63 | env=golang_env) |
mbonadei | 9e5841a | 2017-05-09 00:13:47 -0700 | [diff] [blame] | 64 | |
| 65 | |
| 66 | if __name__ == '__main__': |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 67 | sys.exit(main(sys.argv)) |