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')
67 for ordinal, _, _, name in exports:
68 def_file.write(name + ' @' + ordinal + '\r\n')
70 subprocess.check_output(['lib', '/def:' + def_file.name,
72 os.remove(def_file.name)
74 def make_lib_if_needed(self, dll):
75 if not dll.endswith('.dll'):
78 lib_dir, dll_name = os.path.split(dll)
79 if lib_dir.endswith('bin'):
80 lib_dir = lib_dir[:-3] + 'lib'
82 lib_name = self.get_libname(dll_name)
83 lib = os.path.join(lib_dir, lib_name)
84 if os.path.exists(lib) and os.stat(dll).st_mtime_ns < os.stat(lib).st_mtime_ns:
87 print('Generating .lib file for %s ...' % os.path.basename(dll), end='', flush=True)
88 self.make_lib(lib, dll, dll_name)
89 print('DONE', flush=True)
92 base = os.path.join(self.options.msys2_path, 'mingw64', 'bin')
93 for f in os.listdir(base):
94 if f.endswith('.dll'):
95 self.make_lib_if_needed(os.path.join(base, f))
97 def get_configs(self):
98 return GstBuildConfigurer.get_configs(self) + [
99 '-D' + m + ':disable_introspection=true' for m in [
100 'gst-devtools', 'gstreamer', 'gst-plugins-base',
101 'gst-editing-services']]
103 def setup(self, args):
104 if not os.path.exists(self.options.msys2_path):
105 print("msys2 not found in %s. Please make sure to install"
106 " (from http://msys2.github.io/) specify --msys2-path"
107 " if you did not install in the default directory.", flush=True)
110 for path in ['mingw64/bin', 'bin', 'usr/bin']:
111 os.environ['PATH'] = os.environ.get(
112 'PATH', '') + os.pathsep + os.path.normpath(os.path.join(self.options.msys2_path, path))
113 os.environ['PATH'] = os.environ['PATH'].replace(';;', ';')
114 os.environ['PKG_CONFIG_PATH'] = os.environ.get(
115 'PKG_CONFIG_PATH', '') + ':/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig'
117 subprocess.check_call(['pacman', '-S', '--needed', '--noconfirm'] + self.DEPENDENCIES)
118 source_path = os.path.abspath(os.path.curdir)
120 print('Making sure meson is present in root folder... ', end='', flush=True)
121 if not os.path.isdir(os.path.join(source_path, 'meson')):
122 print('\nCloning meson', flush=True)
123 git('clone', self.MESON_GIT, repository_path=source_path)
125 print('\nDONE', flush=True)
127 print("Making libs", flush=True)
129 print("Done making .lib files.", flush=True)
130 if not os.path.exists(os.path.join(source_path, 'build', 'build.ninja')) or \
131 self.options.reconfigure:
132 print("Running meson", flush=True)
133 if not self.configure_meson():
138 print("Getting into msys2 environment", flush=True)
139 subprocess.check_call([sys.executable,
140 os.path.join(source_path, 'gst-uninstalled.py'),
141 '--builddir', os.path.join(source_path, 'build')])
143 print("Running %s" ' '.join(args), flush=True)
144 res = subprocess.check_call(args)
145 except subprocess.CalledProcessError as e:
151 if __name__ == "__main__":
152 parser = argparse.ArgumentParser(description='Process some integers.')
153 parser.add_argument("--reconfigure", action='store_true',
154 default=False, help='Force a full reconfiguration'
155 ' meaning the build/ folder is removed.'
156 ' You can also use `ninja reconfigure` to just'
157 ' make sure meson is rerun but the build folder'
160 print("Using this script outside windows does not make sense.", flush=True)
163 parser.add_argument("-m", "--msys2-path", dest="msys2_path",
164 help="Where to find msys2 root directory."
165 "(deactivates msys if unset)",
168 parser.add_argument("-c", "--command", dest="command",
169 help="Command to run instead of entering environment.",
171 options, args = parser.parse_known_args()
173 if not shutil.which('cl'):
174 print("Can not find MSVC on windows,"
175 " make sure you are in a 'Visual Studio"
176 " Native Tools Command Prompt'", flush=True)
179 configurer = Msys2Configurer(options, args)
181 exit(not configurer.setup(shlex.split(options.command)))