2 """Setup meson based GStreamer uninstalled environment based on msys2."""
14 from common import git
15 from setup import GstBuildConfigurer
18 PROJECTNAME = "GStreamer build"
20 ROOTDIR = os.path.abspath(os.path.dirname(__file__))
23 class Msys2Configurer(GstBuildConfigurer):
24 MESON_GIT = 'https://github.com/mesonbuild/meson.git'
25 DEPENDENCIES = ['git',
27 'mingw-w64-x86_64-pkg-config',
28 'mingw-w64-x86_64-ninja',
29 'mingw-w64-x86_64-libxml2',
30 'mingw-w64-x86_64-ffmpeg',
31 'mingw-w64-x86_64-python3',
32 'mingw-w64-x86_64-json-glib']
33 LIBNAME_EXCEPTIONS = {
34 r'^zlib1.lib$': 'z.lib',
35 r'^nettle-.*': 'nettle.lib',
36 r'^hogweed-.*': 'hogweed.lib',
37 # Fancy, but it seems to be the correct way to do it
38 r'^eay32.lib$': 'crypto.lib',
39 r'^ssleay32.lib$': 'ssl.lib',
42 def get_libname(self, dll_name):
43 lib_name = re.sub(r'(?:lib)?(.*?)(?:-\d+)?\.dll', r'\1.lib', dll_name)
45 for exception_name, exception_libname in self.LIBNAME_EXCEPTIONS.items():
46 if re.findall(exception_name, lib_name):
47 return exception_libname
50 def make_lib(self, lib, dll, dll_name):
51 print('%s... ' % os.path.basename(lib), end='', flush=True)
54 except FileNotFoundError:
57 dumpbin = subprocess.check_output(['dumpbin', '/exports', dll])
58 lines = dumpbin.decode().splitlines()
59 export_start = [i for i in enumerate(
60 lines) if i[1].find('ordinal hint') != -1][0][0] + 2
61 exports = itertools.takewhile(lambda x: x != '', lines[export_start:])
62 exports = [i.split() for i in exports]
63 def_file = tempfile.NamedTemporaryFile(
64 suffix='.def', delete=False, mode='w')
65 def_file.write('LIBRARY ' + dll_name + '\r\n')
66 def_file.write('EXPORTS\r\n')
68 ordinal, name = tmp[0], tmp[3]
69 def_file.write(name + ' @' + ordinal + '\r\n')
71 subprocess.check_output(['lib', '/def:' + def_file.name,
73 os.remove(def_file.name)
75 def make_lib_if_needed(self, dll):
76 if not dll.endswith('.dll'):
79 lib_dir, dll_name = os.path.split(dll)
80 if lib_dir.endswith('bin'):
81 lib_dir = lib_dir[:-3] + 'lib'
83 lib_name = self.get_libname(dll_name)
84 lib = os.path.join(lib_dir, lib_name)
85 if os.path.exists(lib) and os.stat(dll).st_mtime_ns < os.stat(lib).st_mtime_ns:
88 print('Generating .lib file for %s ...' % os.path.basename(dll), end='', flush=True)
89 self.make_lib(lib, dll, dll_name)
90 print('DONE', flush=True)
93 base = os.path.join(self.options.msys2_path, 'mingw64', 'bin')
94 for f in os.listdir(base):
95 if f.endswith('.dll'):
96 self.make_lib_if_needed(os.path.join(base, f))
98 def get_configs(self):
99 return GstBuildConfigurer.get_configs(self) + [
100 '-D' + m + ':disable_introspection=true' for m in [
101 'gst-devtools', 'gstreamer', 'gst-plugins-base',
102 'gst-editing-services']]
104 def setup(self, args):
105 if not os.path.exists(self.options.msys2_path):
106 print("msys2 not found in %s. Please make sure to install"
107 " (from http://msys2.github.io/) specify --msys2-path"
108 " if you did not install in the default directory.", flush=True)
111 for path in ['mingw64/bin', 'bin', 'usr/bin']:
112 os.environ['PATH'] = os.environ.get(
113 'PATH', '') + os.pathsep + os.path.normpath(os.path.join(self.options.msys2_path, path))
114 os.environ['PATH'] = os.environ['PATH'].replace(';;', ';')
115 os.environ['PKG_CONFIG_PATH'] = os.environ.get(
116 'PKG_CONFIG_PATH', '') + ':/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig'
118 subprocess.check_call(['pacman', '-S', '--needed', '--noconfirm'] + self.DEPENDENCIES)
119 source_path = os.path.abspath(os.path.curdir)
121 print('Making sure meson is present in root folder... ', end='', flush=True)
122 if not os.path.isdir(os.path.join(source_path, 'meson')):
123 print('\nCloning meson', flush=True)
124 git('clone', self.MESON_GIT, repository_path=source_path)
126 print('\nDONE', flush=True)
128 print("Making libs", flush=True)
130 print("Done making .lib files.", flush=True)
131 if not os.path.exists(os.path.join(source_path, 'build', 'build.ninja')) or \
132 self.options.reconfigure:
133 print("Running meson", flush=True)
134 if not self.configure_meson():
139 print("Getting into msys2 environment", flush=True)
140 subprocess.check_call([sys.executable,
141 os.path.join(source_path, 'gst-uninstalled.py'),
142 '--builddir', os.path.join(source_path, 'build')])
144 print("Running %s" ' '.join(args), flush=True)
145 res = subprocess.check_call(args)
146 except subprocess.CalledProcessError as e:
152 if __name__ == "__main__":
153 parser = argparse.ArgumentParser(description='Process some integers.')
154 parser.add_argument("--no-error", action='store_true',
155 default=False, help="Do not error out on warnings")
156 parser.add_argument("--reconfigure", action='store_true',
157 default=False, help='Force a full reconfiguration'
158 ' meaning the build/ folder is removed.'
159 ' You can also use `ninja reconfigure` to just'
160 ' make sure meson is rerun but the build folder'
163 print("Using this script outside windows does not make sense.", flush=True)
166 parser.add_argument("-m", "--msys2-path", dest="msys2_path",
167 help="Where to find msys2 root directory."
168 "(deactivates msys if unset)",
171 parser.add_argument("-c", "--command", dest="command",
172 help="Command to run instead of entering environment.",
174 options, args = parser.parse_known_args()
176 if not shutil.which('cl'):
177 print("Can not find MSVC on windows,"
178 " make sure you are in a 'Visual Studio"
179 " Native Tools Command Prompt'", flush=True)
182 configurer = Msys2Configurer(options, args)
184 exit(not configurer.setup(shlex.split(options.command)))