diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/python/cffi/gen/main.py | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/python/cffi/gen/main.py')
-rw-r--r-- | contrib/python/cffi/gen/main.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/contrib/python/cffi/gen/main.py b/contrib/python/cffi/gen/main.py new file mode 100644 index 00000000000..106293d3c53 --- /dev/null +++ b/contrib/python/cffi/gen/main.py @@ -0,0 +1,37 @@ +import os.path +import sys + +from cffi.setuptools_ext import execfile + +usage = '''Usage: {} INPUT:VAR OUTPUT +Generate CFFI C module source code. + +INPUT is a source .py file. +VAR is a cffi.FFI() object defined in the source file. +OUTPUT is a .c or .cpp output file. +''' + + +def main(): + if len(sys.argv) != 3 or ':' not in sys.argv[1]: + sys.stdout.write(usage.format(sys.argv[0])) + sys.exit(1) + + mod_spec, c_file = sys.argv[1:3] + build_file_name, ffi_var_name = mod_spec.rsplit(':', 1) + + source_dir = os.path.dirname(os.path.abspath(build_file_name)) + sys._MEIPASS = source_dir # For pygit2. + sys.dont_write_bytecode = True + sys.path = [source_dir] + mod_vars = {'__name__': '__cffi__', '__file__': build_file_name} + execfile(build_file_name, mod_vars) + + ffi = mod_vars[ffi_var_name] + if callable(ffi): + ffi = ffi() + ffi.emit_c_code(c_file) + + +if __name__ == '__main__': + main() |