2012-04-03 03:34:16 +02:00
|
|
|
# Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
|
|
|
# reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
# can be found in the LICENSE file.
|
|
|
|
|
|
|
|
from cef_parser import *
|
|
|
|
|
|
|
|
def make_cpptoc_header(header, clsname):
|
|
|
|
cls = header.get_class(clsname)
|
|
|
|
if cls is None:
|
|
|
|
raise Exception('Class does not exist: '+clsname)
|
2015-04-26 20:40:01 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
dllside = cls.is_library_side()
|
2015-04-26 20:40:01 +02:00
|
|
|
|
|
|
|
directory = cls.get_file_directory()
|
|
|
|
defname = ''
|
|
|
|
if not directory is None:
|
|
|
|
defname += directory + '_'
|
|
|
|
defname += get_capi_name(clsname[3:], False)
|
|
|
|
defname = defname.upper()
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
capiname = cls.get_capi_name()
|
2015-04-26 20:40:01 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
result = get_copyright()
|
|
|
|
|
|
|
|
result += '#ifndef CEF_LIBCEF_DLL_CPPTOC_'+defname+'_CPPTOC_H_\n'+ \
|
|
|
|
'#define CEF_LIBCEF_DLL_CPPTOC_'+defname+'_CPPTOC_H_\n' + \
|
|
|
|
'#pragma once\n'
|
2015-04-26 20:40:01 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
if dllside:
|
|
|
|
result += """
|
2016-11-18 00:52:42 +01:00
|
|
|
#if !defined(BUILDING_CEF_SHARED)
|
|
|
|
#error This file can be included DLL-side only
|
|
|
|
#endif
|
2012-04-03 03:34:16 +02:00
|
|
|
"""
|
|
|
|
else:
|
|
|
|
result += """
|
2016-11-18 00:52:42 +01:00
|
|
|
#if !defined(WRAPPING_CEF_SHARED)
|
|
|
|
#error This file can be included wrapper-side only
|
|
|
|
#endif
|
2012-04-03 03:34:16 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
# include the headers for this class
|
|
|
|
result += '\n#include "include/'+cls.get_file_name()+'"\n' \
|
|
|
|
'#include "include/capi/'+cls.get_capi_file_name()+'"\n'
|
|
|
|
|
|
|
|
# include headers for any forward declared classes that are not in the same file
|
|
|
|
declares = cls.get_forward_declares()
|
|
|
|
for declare in declares:
|
|
|
|
dcls = header.get_class(declare)
|
|
|
|
if dcls.get_file_name() != cls.get_file_name():
|
|
|
|
result += '#include "include/'+dcls.get_file_name()+'"\n' \
|
|
|
|
'#include "include/capi/'+dcls.get_capi_file_name()+'"\n'
|
|
|
|
|
|
|
|
result += """#include "libcef_dll/cpptoc/cpptoc.h"
|
|
|
|
|
|
|
|
// Wrap a C++ class with a C structure.
|
|
|
|
"""
|
|
|
|
|
|
|
|
if dllside:
|
|
|
|
result += '// This class may be instantiated and accessed DLL-side only.\n'
|
|
|
|
else:
|
|
|
|
result += '// This class may be instantiated and accessed wrapper-side only.\n'
|
2015-04-26 20:40:01 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
result += 'class '+clsname+'CppToC\n'+ \
|
|
|
|
' : public CefCppToC<'+clsname+'CppToC, '+clsname+', '+capiname+'> {\n'+ \
|
|
|
|
' public:\n'+ \
|
2015-04-26 20:40:01 +02:00
|
|
|
' '+clsname+'CppToC();\n'+ \
|
2012-04-03 03:34:16 +02:00
|
|
|
'};\n\n'
|
2015-04-26 20:40:01 +02:00
|
|
|
|
|
|
|
result += '#endif // CEF_LIBCEF_DLL_CPPTOC_'+defname+'_CPPTOC_H_'
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return wrap_code(result)
|
|
|
|
|
|
|
|
|
|
|
|
def write_cpptoc_header(header, clsname, dir, backup):
|
2015-04-26 20:40:01 +02:00
|
|
|
# give the output file the same directory offset as the input file
|
|
|
|
cls = header.get_class(clsname)
|
|
|
|
dir = os.path.dirname(os.path.join(dir, cls.get_file_name()))
|
|
|
|
file = os.path.join(dir, get_capi_name(clsname[3:], False)+'_cpptoc.h')
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
if path_exists(file):
|
|
|
|
oldcontents = read_file(file)
|
|
|
|
else:
|
|
|
|
oldcontents = ''
|
2015-04-26 20:40:01 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
newcontents = make_cpptoc_header(header, clsname)
|
|
|
|
if newcontents != oldcontents:
|
|
|
|
if backup and oldcontents != '':
|
|
|
|
backup_file(file)
|
2016-01-19 21:09:01 +01:00
|
|
|
file_dir = os.path.split(file)[0]
|
|
|
|
if not os.path.isdir(file_dir):
|
|
|
|
make_dir(file_dir)
|
2012-04-03 03:34:16 +02:00
|
|
|
write_file(file, newcontents)
|
|
|
|
return True
|
2015-04-26 20:40:01 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
# test the module
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import sys
|
2015-04-26 20:40:01 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
# verify that the correct number of command-line arguments are provided
|
|
|
|
if len(sys.argv) < 3:
|
|
|
|
sys.stderr.write('Usage: '+sys.argv[0]+' <infile> <classname>')
|
|
|
|
sys.exit()
|
2015-04-26 20:40:01 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
# create the header object
|
|
|
|
header = obj_header()
|
|
|
|
header.add_file(sys.argv[1])
|
2015-04-26 20:40:01 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
# dump the result to stdout
|
|
|
|
sys.stdout.write(make_cpptoc_header(header, sys.argv[2]))
|