forked from GStreamer/gst-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsys2_setup.py
184 lines (153 loc) · 7.06 KB
/
msys2_setup.py
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python3
"""Setup meson based GStreamer uninstalled environment based on msys2."""
import argparse
import itertools
import os
import re
import sys
import shlex
import shutil
import subprocess
import tempfile
from common import git
from setup import GstBuildConfigurer
PROJECTNAME = "GStreamer build"
ROOTDIR = os.path.abspath(os.path.dirname(__file__))
class Msys2Configurer(GstBuildConfigurer):
MESON_GIT = 'https://github.com/mesonbuild/meson.git'
DEPENDENCIES = ['git',
'bison',
'mingw-w64-x86_64-pkg-config',
'mingw-w64-x86_64-ninja',
'mingw-w64-x86_64-libxml2',
'mingw-w64-x86_64-ffmpeg',
'mingw-w64-x86_64-python3',
'mingw-w64-x86_64-json-glib']
LIBNAME_EXCEPTIONS = {
r'^zlib1.lib$': 'z.lib',
r'^nettle-.*': 'nettle.lib',
r'^hogweed-.*': 'hogweed.lib',
# Fancy, but it seems to be the correct way to do it
r'^eay32.lib$': 'crypto.lib',
r'^ssleay32.lib$': 'ssl.lib',
}
def get_libname(self, dll_name):
lib_name = re.sub(r'(?:lib)?(.*?)(?:-\d+)?\.dll', r'\1.lib', dll_name)
for exception_name, exception_libname in self.LIBNAME_EXCEPTIONS.items():
if re.findall(exception_name, lib_name):
return exception_libname
return lib_name
def make_lib(self, lib, dll, dll_name):
print('%s... ' % os.path.basename(lib), end='', flush=True)
try:
os.remove(lib)
except FileNotFoundError:
pass
dumpbin = subprocess.check_output(['dumpbin', '/exports', dll])
lines = dumpbin.decode().splitlines()
export_start = [i for i in enumerate(
lines) if i[1].find('ordinal hint') != -1][0][0] + 2
exports = itertools.takewhile(lambda x: x != '', lines[export_start:])
exports = [i.split() for i in exports]
def_file = tempfile.NamedTemporaryFile(
suffix='.def', delete=False, mode='w')
def_file.write('LIBRARY ' + dll_name + '\r\n')
def_file.write('EXPORTS\r\n')
for tmp in exports:
ordinal, name = tmp[0], tmp[3]
def_file.write(name + ' @' + ordinal + '\r\n')
def_file.close()
subprocess.check_output(['lib', '/def:' + def_file.name,
'/out:' + lib])
os.remove(def_file.name)
def make_lib_if_needed(self, dll):
if not dll.endswith('.dll'):
return
lib_dir, dll_name = os.path.split(dll)
if lib_dir.endswith('bin'):
lib_dir = lib_dir[:-3] + 'lib'
lib_name = self.get_libname(dll_name)
lib = os.path.join(lib_dir, lib_name)
if os.path.exists(lib) and os.stat(dll).st_mtime_ns < os.stat(lib).st_mtime_ns:
return
print('Generating .lib file for %s ...' % os.path.basename(dll), end='', flush=True)
self.make_lib(lib, dll, dll_name)
print('DONE', flush=True)
def make_libs(self):
base = os.path.join(self.options.msys2_path, 'mingw64', 'bin')
for f in os.listdir(base):
if f.endswith('.dll'):
self.make_lib_if_needed(os.path.join(base, f))
def get_configs(self):
return GstBuildConfigurer.get_configs(self) + [
'-D' + m + ':disable_introspection=true' for m in [
'gst-devtools', 'gstreamer', 'gst-plugins-base',
'gst-editing-services']]
def setup(self, args):
if not os.path.exists(self.options.msys2_path):
print("msys2 not found in %s. Please make sure to install"
" (from http://msys2.github.io/) specify --msys2-path"
" if you did not install in the default directory.", flush=True)
return False
for path in ['mingw64/bin', 'bin', 'usr/bin']:
os.environ['PATH'] = os.environ.get(
'PATH', '') + os.pathsep + os.path.normpath(os.path.join(self.options.msys2_path, path))
os.environ['PATH'] = os.environ['PATH'].replace(';;', ';')
os.environ['PKG_CONFIG_PATH'] = os.environ.get(
'PKG_CONFIG_PATH', '') + ':/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig'
subprocess.check_call(['pacman', '-S', '--needed', '--noconfirm'] + self.DEPENDENCIES)
source_path = os.path.abspath(os.path.curdir)
print('Making sure meson is present in root folder... ', end='', flush=True)
if not os.path.isdir(os.path.join(source_path, 'meson')):
print('\nCloning meson', flush=True)
git('clone', self.MESON_GIT, repository_path=source_path)
else:
print('\nDONE', flush=True)
print("Making libs", flush=True)
self.make_libs()
print("Done making .lib files.", flush=True)
if not os.path.exists(os.path.join(source_path, 'build', 'build.ninja')) or \
self.options.reconfigure:
print("Running meson", flush=True)
if not self.configure_meson():
return False
try:
if not args:
print("Getting into msys2 environment", flush=True)
subprocess.check_call([sys.executable,
os.path.join(source_path, 'gst-uninstalled.py'),
'--builddir', os.path.join(source_path, 'build')])
else:
print("Running %s" ' '.join(args), flush=True)
res = subprocess.check_call(args)
except subprocess.CalledProcessError as e:
return False
return True
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument("--no-error", action='store_true',
default=False, help="Do not error out on warnings")
parser.add_argument("--reconfigure", action='store_true',
default=False, help='Force a full reconfiguration'
' meaning the build/ folder is removed.'
' You can also use `ninja reconfigure` to just'
' make sure meson is rerun but the build folder'
' is kept.')
if os.name != 'nt':
print("Using this script outside windows does not make sense.", flush=True)
exit(1)
parser.add_argument("-m", "--msys2-path", dest="msys2_path",
help="Where to find msys2 root directory."
"(deactivates msys if unset)",
default="C:\msys64")
parser.add_argument("-c", "--command", dest="command",
help="Command to run instead of entering environment.",
default="")
options, args = parser.parse_known_args()
if not shutil.which('cl'):
print("Can not find MSVC on windows,"
" make sure you are in a 'Visual Studio"
" Native Tools Command Prompt'", flush=True)
exit(1)
configurer = Msys2Configurer(options, args)
exit(not configurer.setup(shlex.split(options.command)))