2016-11-19 13:18:33 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""Setup meson based GStreamer uninstalled environment based on msys2."""
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import itertools
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
2016-12-13 18:22:15 +00:00
|
|
|
import shlex
|
2016-11-19 13:18:33 +00:00
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import tempfile
|
|
|
|
|
2018-11-12 23:23:14 +00:00
|
|
|
from scripts.common import git
|
2016-11-19 13:18:33 +00:00
|
|
|
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 = {
|
2016-12-14 00:35:14 +00:00
|
|
|
r'^zlib1.lib$': 'z.lib',
|
|
|
|
r'^nettle-.*': 'nettle.lib',
|
|
|
|
r'^hogweed-.*': 'hogweed.lib',
|
2016-11-19 13:18:33 +00:00
|
|
|
# Fancy, but it seems to be the correct way to do it
|
2016-12-14 00:35:14 +00:00
|
|
|
r'^eay32.lib$': 'crypto.lib',
|
|
|
|
r'^ssleay32.lib$': 'ssl.lib',
|
2016-11-19 13:18:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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):
|
2016-12-14 00:35:14 +00:00
|
|
|
print('%s... ' % os.path.basename(lib), end='', flush=True)
|
2016-11-19 13:18:33 +00:00
|
|
|
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')
|
2017-09-25 17:14:53 +00:00
|
|
|
for tmp in exports:
|
|
|
|
ordinal, name = tmp[0], tmp[3]
|
2016-11-19 13:18:33 +00:00
|
|
|
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
|
|
|
|
|
2016-12-14 00:35:14 +00:00
|
|
|
print('Generating .lib file for %s ...' % os.path.basename(dll), end='', flush=True)
|
2016-11-19 13:18:33 +00:00
|
|
|
self.make_lib(lib, dll, dll_name)
|
2016-12-14 00:35:14 +00:00
|
|
|
print('DONE', flush=True)
|
2016-11-19 13:18:33 +00:00
|
|
|
|
|
|
|
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']]
|
|
|
|
|
2016-12-13 18:22:15 +00:00
|
|
|
def setup(self, args):
|
2016-11-19 13:18:33 +00:00
|
|
|
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"
|
2016-12-14 00:35:14 +00:00
|
|
|
" if you did not install in the default directory.", flush=True)
|
2016-11-19 13:18:33 +00:00
|
|
|
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'
|
|
|
|
|
2016-12-13 18:22:15 +00:00
|
|
|
subprocess.check_call(['pacman', '-S', '--needed', '--noconfirm'] + self.DEPENDENCIES)
|
2016-11-19 13:18:33 +00:00
|
|
|
source_path = os.path.abspath(os.path.curdir)
|
|
|
|
|
2016-12-14 00:35:14 +00:00
|
|
|
print('Making sure meson is present in root folder... ', end='', flush=True)
|
2016-11-19 13:18:33 +00:00
|
|
|
if not os.path.isdir(os.path.join(source_path, 'meson')):
|
2016-12-14 00:35:14 +00:00
|
|
|
print('\nCloning meson', flush=True)
|
2016-11-19 13:18:33 +00:00
|
|
|
git('clone', self.MESON_GIT, repository_path=source_path)
|
|
|
|
else:
|
2016-12-14 00:35:14 +00:00
|
|
|
print('\nDONE', flush=True)
|
2016-11-19 13:18:33 +00:00
|
|
|
|
2016-12-14 00:35:14 +00:00
|
|
|
print("Making libs", flush=True)
|
2016-11-19 13:18:33 +00:00
|
|
|
self.make_libs()
|
2016-12-14 00:35:14 +00:00
|
|
|
print("Done making .lib files.", flush=True)
|
2016-11-19 13:18:33 +00:00
|
|
|
if not os.path.exists(os.path.join(source_path, 'build', 'build.ninja')) or \
|
|
|
|
self.options.reconfigure:
|
2016-12-14 00:35:14 +00:00
|
|
|
print("Running meson", flush=True)
|
2016-11-19 13:18:33 +00:00
|
|
|
if not self.configure_meson():
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
2016-12-13 18:22:15 +00:00
|
|
|
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)
|
2016-11-19 13:18:33 +00:00
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(description='Process some integers.')
|
2016-12-14 00:36:25 +00:00
|
|
|
parser.add_argument("--no-error", action='store_true',
|
|
|
|
default=False, help="Do not error out on warnings")
|
2016-11-19 13:18:33 +00:00
|
|
|
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':
|
2016-12-14 00:35:14 +00:00
|
|
|
print("Using this script outside windows does not make sense.", flush=True)
|
2016-11-19 13:18:33 +00:00
|
|
|
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")
|
2016-12-13 18:22:15 +00:00
|
|
|
|
|
|
|
parser.add_argument("-c", "--command", dest="command",
|
|
|
|
help="Command to run instead of entering environment.",
|
|
|
|
default="")
|
2016-11-19 13:18:33 +00:00
|
|
|
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"
|
2016-12-14 00:35:14 +00:00
|
|
|
" Native Tools Command Prompt'", flush=True)
|
2016-11-19 13:18:33 +00:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
configurer = Msys2Configurer(options, args)
|
|
|
|
|
2016-12-13 18:22:15 +00:00
|
|
|
exit(not configurer.setup(shlex.split(options.command)))
|