ci: use meson 1.1.1 in the 1.22 branch Windows CI
[platform/upstream/gstreamer.git] / subprojects / gstreamer-sharp / generate_code.py
1 #!/usr/bin/env python3
2
3 import argparse
4 import glob
5 import os
6 import re
7 import shutil
8 import subprocess
9
10
11 if __name__ == "__main__":
12     parser = argparse.ArgumentParser()
13     parser.add_argument("--api-raw")
14     parser.add_argument("--gapi-fixup")
15     parser.add_argument("--metadata")
16     parser.add_argument("--gapi-codegen")
17     parser.add_argument("--abi-includes", default="")
18     parser.add_argument("--abi-cs-usings", default="")
19     parser.add_argument("--assembly-name")
20     parser.add_argument("--extra-includes", action='append', default=[])
21     parser.add_argument("--out")
22     parser.add_argument("--files")
23     parser.add_argument("--symbols")
24     parser.add_argument("--schema")
25     parser.add_argument("--fake", action='store_true')
26
27     opts = parser.parse_args()
28     if opts.fake:
29         exit(0)
30
31     api_xml = os.path.join(opts.out, os.path.basename(
32         opts.api_raw).replace('.raw', '.xml'))
33
34     shutil.copyfile(opts.api_raw, api_xml)
35
36     if shutil.which('mono'):
37         launcher = ['mono', '--debug']
38     else:
39         launcher = []
40
41     cmd = [opts.gapi_fixup, "--api=" + api_xml]
42     if opts.metadata:
43         cmd += ["--metadata=" + opts.metadata]
44     if opts.symbols:
45         cmd.extend(['--symbols=' + opts.symbols])
46     subprocess.check_call(launcher + cmd)
47
48     cmd = [
49         opts.gapi_codegen, '--generate', api_xml,
50         '--outdir=' + opts.out,
51         '--assembly-name=' + opts.assembly_name,
52         '--glue-includes=' + opts.abi_includes,
53         '--abi-c-filename=' +
54         os.path.join(opts.out, opts.assembly_name + "-abi.c"),
55         '--abi-cs-filename=' +
56         os.path.join(opts.out, opts.assembly_name + "-abi.cs"),
57     ]
58
59     if opts.schema:
60         cmd += ['--schema=' + opts.schema]
61
62     if opts.abi_cs_usings:
63         cmd += ['--abi-cs-usings=' + opts.abi_cs_usings]
64
65     cmd += ['-I' + i for i in opts.extra_includes]
66
67     subprocess.check_call(launcher + cmd)
68
69     # WORKAROUND: Moving files into the out directory with special names
70     # as meson doesn't like path separator in output names.
71     regex = re.compile('_')
72     dirs = set()
73     expected_files = set(opts.files.split(';'))
74     for _f in expected_files:
75         dirs.add(os.path.dirname(_f))
76
77     generated = set(glob.glob(os.path.join('*/*.cs')))
78     rcode = 0
79     not_listed = generated - expected_files
80     if not_listed:
81         print("Following files were generated but not listed:\n    %s" %
82               '\n    '.join(["'%s/%s'," % (m.split(os.path.sep)[-2], m.split(os.path.sep)[-1])
83                              for m in not_listed]))
84         rcode = 1
85
86     not_generated = expected_files - generated
87     if not_generated:
88         print("Following files were generated but not listed:\n    %s" %
89               '\n    '.join(["'%s/%s'," % (m.split(os.path.sep)[-2], m.split(os.path.sep)[-1])
90                              for m in not_generated]))
91         rcode = 1
92
93     if rcode == 1:
94         generated = sorted(list(generated))
95         print("List of files to use in `meson.build`:\n    %s" %
96               '\n    '.join(["'%s/%s'," % (m.split(os.path.sep)[-2], m.split(os.path.sep)[-1])
97                              for m in generated]))
98
99     exit(rcode)