2017-08-21 18:20:47 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("--api-raw")
|
|
|
|
parser.add_argument("--gapi-fixup")
|
|
|
|
parser.add_argument("--metadata")
|
|
|
|
parser.add_argument("--gapi-codegen")
|
2017-10-11 21:47:35 +00:00
|
|
|
parser.add_argument("--abi-includes", default="")
|
2017-10-04 19:02:53 +00:00
|
|
|
parser.add_argument("--abi-cs-usings", default="")
|
2017-08-21 18:20:47 +00:00
|
|
|
parser.add_argument("--assembly-name")
|
|
|
|
parser.add_argument("--extra-includes", action='append', default=[])
|
|
|
|
parser.add_argument("--out")
|
|
|
|
parser.add_argument("--files")
|
|
|
|
parser.add_argument("--symbols")
|
|
|
|
parser.add_argument("--schema")
|
2017-10-11 21:47:35 +00:00
|
|
|
parser.add_argument("--fake", action='store_true')
|
2017-08-21 18:20:47 +00:00
|
|
|
|
|
|
|
opts = parser.parse_args()
|
2017-10-11 21:47:35 +00:00
|
|
|
if opts.fake:
|
2017-08-21 18:20:47 +00:00
|
|
|
exit(0)
|
|
|
|
|
|
|
|
api_xml = os.path.join(opts.out, os.path.basename(
|
|
|
|
opts.api_raw).replace('.raw', '.xml'))
|
|
|
|
|
|
|
|
shutil.copyfile(opts.api_raw, api_xml)
|
|
|
|
|
2017-09-25 14:56:43 +00:00
|
|
|
if shutil.which('mono'):
|
2017-10-04 19:02:53 +00:00
|
|
|
launcher = ['mono', '--debug']
|
2017-09-25 14:56:43 +00:00
|
|
|
else:
|
|
|
|
launcher = []
|
|
|
|
|
|
|
|
cmd = [opts.gapi_fixup, "--api=" + api_xml]
|
|
|
|
if opts.metadata:
|
|
|
|
cmd += ["--metadata=" + opts.metadata]
|
2017-08-21 18:20:47 +00:00
|
|
|
if opts.symbols:
|
|
|
|
cmd.extend(['--symbols=' + opts.symbols])
|
2017-09-25 14:56:43 +00:00
|
|
|
subprocess.check_call(launcher + cmd)
|
2017-08-21 18:20:47 +00:00
|
|
|
|
|
|
|
cmd = [
|
|
|
|
opts.gapi_codegen, '--generate', api_xml,
|
|
|
|
'--outdir=' + opts.out,
|
2017-09-29 14:43:48 +00:00
|
|
|
'--assembly-name=' + opts.assembly_name,
|
2017-10-11 21:47:35 +00:00
|
|
|
'--glue-includes=' + opts.abi_includes,
|
2018-03-12 00:39:46 +00:00
|
|
|
'--abi-c-filename=' +
|
|
|
|
os.path.join(opts.out, opts.assembly_name + "-abi.c"),
|
|
|
|
'--abi-cs-filename=' +
|
|
|
|
os.path.join(opts.out, opts.assembly_name + "-abi.cs"),
|
2017-09-29 14:43:48 +00:00
|
|
|
]
|
2017-08-21 18:20:47 +00:00
|
|
|
|
|
|
|
if opts.schema:
|
|
|
|
cmd += ['--schema=' + opts.schema]
|
|
|
|
|
2017-10-04 19:02:53 +00:00
|
|
|
if opts.abi_cs_usings:
|
|
|
|
cmd += ['--abi-cs-usings=' + opts.abi_cs_usings]
|
|
|
|
|
2017-09-25 14:56:43 +00:00
|
|
|
cmd += ['-I' + i for i in opts.extra_includes]
|
2017-08-21 18:20:47 +00:00
|
|
|
|
2017-09-25 14:56:43 +00:00
|
|
|
subprocess.check_call(launcher + cmd)
|
2017-08-21 18:20:47 +00:00
|
|
|
|
|
|
|
# WORKAROUND: Moving files into the out directory with special names
|
|
|
|
# as meson doesn't like path separator in output names.
|
|
|
|
regex = re.compile('_')
|
|
|
|
dirs = set()
|
2018-03-12 00:39:46 +00:00
|
|
|
expected_files = set(opts.files.split(';'))
|
|
|
|
for _f in expected_files:
|
|
|
|
dirs.add(os.path.dirname(_f))
|
|
|
|
|
|
|
|
generated = set(glob.glob(os.path.join('*/*.cs')))
|
|
|
|
rcode = 0
|
|
|
|
not_listed = generated - expected_files
|
|
|
|
if not_listed:
|
|
|
|
print("Following files were generated but not listed:\n %s" %
|
|
|
|
'\n '.join(["'%s/%s'," % (m.split(os.path.sep)[-2], m.split(os.path.sep)[-1])
|
|
|
|
for m in not_listed]))
|
|
|
|
rcode = 1
|
2017-08-21 18:20:47 +00:00
|
|
|
|
2018-03-12 00:39:46 +00:00
|
|
|
not_generated = expected_files - generated
|
|
|
|
if not_generated:
|
2017-08-21 18:20:47 +00:00
|
|
|
print("Following files were generated but not listed:\n %s" %
|
2018-03-12 00:39:46 +00:00
|
|
|
'\n '.join(["'%s/%s'," % (m.split(os.path.sep)[-2], m.split(os.path.sep)[-1])
|
|
|
|
for m in not_generated]))
|
|
|
|
rcode = 1
|
2017-08-21 18:20:47 +00:00
|
|
|
|
2018-03-12 00:39:46 +00:00
|
|
|
exit(rcode)
|