blob: d2567c65adfed325dbc1ac113900d3e27df177ea [file]
#!/usr/bin/env python
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import subprocess
import sys
def main():
parser = argparse.ArgumentParser(description="Generate D-Bus bindings")
parser.add_argument("--output-c",
help="The source file to generate containing the GDBus proxy implementation")
parser.add_argument("--output-h",
help="The header file to generate containing the GDBus proxy interface")
# Parse our options and forward anything else.
options, extra_args = parser.parse_known_args()
if options.output_c:
subprocess.check_call(["gdbus-codegen", "--body", "--output", options.output_c] + extra_args)
with open(options.output_c) as f:
content = f.read()
# Replace configuration header file generated by gdbus-codegen.
content = content.replace('include "config.h"', 'include "BuildConfig.h"')
with open(options.output_c, "w") as f:
f.write(content)
if options.output_h:
subprocess.check_call(["gdbus-codegen", "--header", "--output", options.output_h] + extra_args)
with open(options.output_h) as f:
content = f.read()
# Code generated with new gdbus-codegen adds checks for `GLIB_VERSION_2_84` which might
# not yet be defined when compiling with older glib versions (e.g. cross-compilation).
# This manually provided definition solves the problem with undefined identifiers.
content = content.replace("G_BEGIN_DECLS", """
#ifndef GLIB_VERSION_2_84
#define GLIB_VERSION_2_84 G_ENCODE_VERSION(2, 84)
#endif
G_BEGIN_DECLS
""")
with open(options.output_h, "w") as f:
f.write(content)
return 0
if __name__ == '__main__':
sys.exit(main())