README: Warn about not using the Meson MSI
[platform/upstream/gstreamer.git] / setup.py
1 #!/usr/bin/env python3
2 """Script for generating the Makefiles."""
3
4 import argparse
5 import os
6 import sys
7 import shutil
8 import subprocess
9
10 from common import get_meson
11 from common import accept_command
12
13
14 PROJECTNAME = "GStreamer build"
15
16 ROOTDIR = os.path.abspath(os.path.dirname(__file__))
17
18
19 class GstBuildConfigurer:
20
21     def __init__(self, options, args):
22         self.options = options
23         self.args = args
24
25     def get_configs(self):
26         if self.options.werror:
27             return ['--werror']
28         return []
29
30     def configure_meson(self):
31         if not self.options.reconfigure:
32             if os.path.exists(ROOTDIR + "/build/build.ninja"):
33                 print("Not reconfiguring")
34                 return True
35
36         try:
37             meson = get_meson()
38         except RuntimeError:
39             print("Install mesonbuild to build %s: http://mesonbuild.com/\n"
40                   "You can simply install it with:\n"
41                   "    $ sudo pip3 install meson" % PROJECTNAME)
42             return False
43
44         ninja = accept_command(["ninja", "ninja-build"])
45         if not ninja:
46             print("Install ninja-build to build %s: https://ninja-build.org/"
47                   % PROJECTNAME)
48             return False
49
50         build_dir = os.path.join(ROOTDIR, "build")
51         shutil.rmtree(build_dir, True)
52         os.mkdir(build_dir)
53
54         try:
55             subprocess.check_call(meson + ["../"] + self.args + self.get_configs(),
56                                   cwd=build_dir)
57             print("\nYou can now build GStreamer and its various subprojects running:\n"
58                   " $ {} -C {!r}".format(os.path.basename(ninja), build_dir))
59         except subprocess.CalledProcessError:
60             return False
61
62         return True
63
64     def setup(self):
65         return self.configure_meson()
66
67
68
69 if __name__ == "__main__":
70     parser = argparse.ArgumentParser(description='Process some integers.')
71     parser.add_argument("--reconfigure", action='store_true',
72                         default=False, help='Force a full reconfiguration'
73                         ' meaning the build/ folder is removed.'
74                         ' You can also use `ninja reconfigure` to just'
75                         ' make sure meson is rerun but the build folder'
76                         ' is kept.')
77     parser.add_argument("--werror", action='store_true',
78                         default=False, help="Do not error out on warnings")
79
80     options, args = parser.parse_known_args()
81     configurer = GstBuildConfigurer(options, args)
82     exit(not configurer.setup())