Minor improvement in the git function
[platform/upstream/gstreamer.git] / configure
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 git
11 from common import Colors
12
13
14 PROJECTNAME = "GStreamer 'all'"
15
16 ROOTDIR = os.path.abspath(os.path.dirname(__file__))
17
18
19 def get_meson():
20     print("Updating meson submodule... ", end='')
21     sys.stdout.flush()
22     git('submodule', 'update', '--init', repository_path=ROOTDIR)
23     print("DONE")
24
25     return os.path.join(ROOTDIR, 'meson', 'meson.py')
26
27
28 def accept_command(commands):
29     """Checks if @command --version works."""
30     for command in commands:
31         try:
32             subprocess.check_output([command, "--version"])
33             return command
34         except FileNotFoundError:
35             pass
36
37     return None
38
39
40 def get_configs(meson):
41      return ['-Dwerror=true']
42
43
44 def configure_meson(args):
45     """Configures meson and generate the Makefile."""
46     meson = get_meson()
47     if not meson:
48         print("Install mesonbuild to build %s: http://mesonbuild.com/\n"
49               "You can simply install it with:\n"
50               "    $ sudo pip3 install meson" % PROJECTNAME)
51         exit(1)
52
53     ninja = accept_command(["ninja", "ninja-build"])
54     if not ninja:
55         print("Install ninja-build to build %s: https://ninja-build.org/"
56               % PROJECTNAME)
57         exit(1)
58
59     build_dir = os.path.join(ROOTDIR, "build")
60     shutil.rmtree(build_dir, True)
61     os.mkdir(build_dir)
62     os.chdir(build_dir)
63
64     try:
65         subprocess.check_call([meson, "../"] + args + get_configs(meson))
66     except subprocess.CalledProcessError as e:
67         print("EXIT meson return %s" % e.returncode)
68         exit(1)
69
70
71 if __name__ == "__main__":
72     parser = argparse.ArgumentParser(description='Process some integers.')
73     parser.add_argument("--no-reconfigure", action='store_true',
74                         default=False, help='Avoid removing the build dir'
75                        ' if not necessary.')
76     options, args = parser.parse_known_args()
77     if options.no_reconfigure:
78         if os.path.exists(
79                 ROOTDIR + "/build/build.ninja") and os.path.exists(
80                     ROOTDIR + "/Makefile"):
81             print("Not reconfiguring")
82             exit(0)
83
84     configure_meson(args)