forked from vmolsa/libcrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·136 lines (95 loc) · 4.22 KB
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python
import os
import sys
import subprocess
import shutil
import tarfile
import platform
root_dir = os.path.dirname(os.path.realpath(__file__))
dist_dir = os.path.join(root_dir, 'dist')
dist_include_dir = os.path.join(dist_dir, 'include')
dist_lib_dir = os.path.join(dist_dir, 'lib')
out_dir = os.path.join(root_dir, 'out')
third_party_dir = os.path.join(root_dir, '3dparty')
target_platform = sys.platform
if sys.platform.startswith('linux'):
target_platform = 'linux'
target_os = target_platform
target_cpu = platform.machine()
if (target_cpu == 'x86_64'):
target_cpu = 'x64'
elif (target_cpu == 'i386'):
target_cpu = 'x86'
release_name = ''.join(subprocess.check_output(['git', 'describe', '--abbrev=0', '--tags']).split())
if (os.environ.get('WEBRTC_TARGET_OS')):
target_os = os.environ['WEBRTC_TARGET_OS']
if (os.environ.get('WEBRTC_TARGET_CPU')):
target_cpu = os.environ['WEBRTC_TARGET_CPU']
pkg_name = 'libcrtc-' + release_name + '-' + target_os + '-' + target_cpu + '.tar.gz'
def build_archive():
with tarfile.open(os.path.join(dist_dir, pkg_name), "w:gz") as tar:
tar.add(dist_include_dir, arcname='include')
tar.add(dist_lib_dir, arcname='lib')
depot_tools_dir = os.path.join(third_party_dir, 'depot_tools')
webrtc_dir = os.path.join(third_party_dir, 'webrtc')
webrtc_src_dir = os.path.join(webrtc_dir, 'src')
webrtc_crtc_dir = os.path.join(webrtc_src_dir, 'crtc')
webrtc_sync = os.path.join(third_party_dir, '.webrtc_sync')
gn_flags = '--args=is_debug=false is_component_build=true rtc_include_tests=false use_ozone=true is_desktop_linux=false rtc_use_gtk=false clang_use_chrome_plugins=true rtc_enable_protobuf=false'
if (target_os != target_platform):
gn_flags += ' target_os="' + target_os + '"'
if (target_cpu != platform.machine()):
gn_flags += ' target_cpu="' + target_cpu + '"'
if not os.path.exists(third_party_dir):
os.mkdir(third_party_dir)
if not os.path.exists(depot_tools_dir):
subprocess.call(['git', 'clone', 'https://chromium.googlesource.com/chromium/tools/depot_tools.git', depot_tools_dir])
os.environ['PATH'] += os.pathsep + depot_tools_dir
if not os.path.exists(webrtc_dir):
os.mkdir(webrtc_dir)
if not os.path.exists(webrtc_sync):
os.chdir(webrtc_dir)
if not os.path.exists(webrtc_src_dir):
subprocess.call(['fetch', '--nohooks', 'webrtc'])
else:
os.chdir(webrtc_src_dir)
subprocess.call(['git', 'fetch', 'origin'])
subprocess.call(['git', 'reset', '--hard', 'origin/master'])
subprocess.call(['git', 'checkout', 'origin/master'])
if subprocess.check_output(['git', 'branch', '--list', 'libcrtc']):
subprocess.call(['git', 'branch', '-D', 'libcrtc'])
subprocess.call(['git', 'clean', '-f'])
os.chdir(webrtc_dir)
subprocess.call(['gclient', 'sync', '--with_branch_heads', '--force'])
os.chdir(webrtc_src_dir)
subprocess.call(['git', 'checkout', '-b', 'libcrtc', 'refs/remotes/branch-heads/58'])
if os.path.exists(os.path.join(webrtc_src_dir, 'BUILD.gn')):
os.remove(os.path.join(webrtc_src_dir, 'BUILD.gn'))
if not os.path.exists(webrtc_crtc_dir):
os.symlink(root_dir, webrtc_crtc_dir)
os.symlink(os.path.join(root_dir, 'root.gn'), os.path.join(webrtc_src_dir, 'BUILD.gn'))
open(webrtc_sync, 'a').close()
os.chdir(root_dir)
os.chdir(webrtc_src_dir)
subprocess.call(['gn', 'gen', out_dir, gn_flags])
os.chdir(root_dir)
if os.environ.get('BUILD_WEBRTC_EXAMPLES') == 'true':
subprocess.call(['ninja', '-C', 'out', 'crtc-examples'])
else:
subprocess.call(['ninja', '-C', 'out', 'crtc'])
if os.path.exists(dist_dir):
shutil.rmtree(dist_dir)
os.mkdir(dist_dir)
os.mkdir(dist_include_dir)
os.mkdir(dist_lib_dir)
shutil.copy(os.path.join(root_dir, 'include', 'crtc.h'), dist_include_dir)
if sys.platform.startswith('linux'):
shutil.copy(os.path.join(out_dir, 'libcrtc.so'), dist_lib_dir)
shutil.copy(os.path.join(out_dir, 'libboringssl.so'), dist_lib_dir)
elif sys.platform.startswith('win32'):
shutil.copy(os.path.join(out_dir, 'libcrtc.dll'), dist_lib_dir)
shutil.copy(os.path.join(out_dir, 'libboringssl.dll'), dist_lib_dir)
elif sys.platform.startswith('darwin'):
shutil.copy(os.path.join(out_dir, 'libcrtc.dylib'), dist_lib_dir)
shutil.copy(os.path.join(out_dir, 'libboringssl.dylib'), dist_lib_dir)
build_archive()