Fix CMake generation on Windows (#536)

pull/561/head
Hristo Stamenov 2021-05-15 23:57:05 +03:00 committed by GitHub
parent d68e629a7c
commit 476a870d6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 28 deletions

View File

@ -3,6 +3,7 @@ from __future__ import print_function
import json import json
import os import os
import errno import errno
from pathlib import Path
# Convenience function for using template get_node # Convenience function for using template get_node
def correct_method_name(method_list): def correct_method_name(method_list):
@ -19,23 +20,23 @@ def print_file_list(api_filepath, output_dir, headers=False, sources=False):
end = ';' end = ';'
with open(api_filepath) as api_file: with open(api_filepath) as api_file:
classes = json.load(api_file) classes = json.load(api_file)
include_gen_folder = os.path.join(output_dir, 'include', 'gen') include_gen_folder = Path(output_dir) / 'include' / 'gen'
source_gen_folder = os.path.join(output_dir, 'src', 'gen') source_gen_folder = Path(output_dir) / 'src' / 'gen'
for _class in classes: for _class in classes:
header_filename = os.path.join(include_gen_folder, strip_name(_class["name"]) + ".hpp") header_filename = include_gen_folder / (strip_name(_class["name"]) + ".hpp")
source_filename = os.path.join(source_gen_folder, strip_name(_class["name"]) + ".cpp") source_filename = source_gen_folder / (strip_name(_class["name"]) + ".cpp")
if headers: if headers:
print(header_filename, end=end) print(str(header_filename.as_posix()), end=end)
if sources: if sources:
print(source_filename, end=end) print(str(source_filename.as_posix()), end=end)
icall_header_filename = os.path.join(include_gen_folder, '__icalls.hpp') icall_header_filename = include_gen_folder / '__icalls.hpp'
register_types_filename = os.path.join(source_gen_folder, '__register_types.cpp') register_types_filename = source_gen_folder / '__register_types.cpp'
init_method_bindings_filename = os.path.join(source_gen_folder, '__init_method_bindings.cpp') init_method_bindings_filename = source_gen_folder / '__init_method_bindings.cpp'
if headers: if headers:
print(icall_header_filename, end=end) print(str(icall_header_filename.as_posix()), end=end)
if sources: if sources:
print(register_types_filename, end=end) print(str(register_types_filename.as_posix()), end=end)
print(init_method_bindings_filename, end=end) print(str(init_method_bindings_filename.as_posix()), end=end)
def generate_bindings(api_filepath, use_template_get_node, output_dir="."): def generate_bindings(api_filepath, use_template_get_node, output_dir="."):
@ -44,20 +45,22 @@ def generate_bindings(api_filepath, use_template_get_node, output_dir="."):
classes = json.load(api_file) classes = json.load(api_file)
icalls = set() icalls = set()
include_gen_folder = os.path.join(output_dir, 'include', 'gen') include_gen_folder = Path(output_dir) / 'include' / 'gen'
source_gen_folder = os.path.join(output_dir, 'src', 'gen') source_gen_folder = Path(output_dir) / 'src' / 'gen'
try: try:
os.makedirs(include_gen_folder) include_gen_folder.mkdir(parents=True)
except os.error as e: except os.error as e:
if e.errno == errno.EEXIST: if e.errno == errno.EEXIST:
print(include_gen_folder + ": " + os.strerror(e.errno)) print(str(source_gen_folder) + ": " + os.strerror(e.errno))
else: else:
exit(1) exit(1)
try: try:
os.makedirs(source_gen_folder) source_gen_folder.mkdir(parents=True)
except os.error as e: except os.error as e:
if e.errno == errno.EEXIST: if e.errno == errno.EEXIST:
print(source_gen_folder + ": " + os.strerror(e.errno)) print(str(source_gen_folder) + ": " + os.strerror(e.errno))
else: else:
exit(1) exit(1)
@ -71,24 +74,24 @@ def generate_bindings(api_filepath, use_template_get_node, output_dir="."):
impl = generate_class_implementation(icalls, used_classes, c, use_template_get_node) impl = generate_class_implementation(icalls, used_classes, c, use_template_get_node)
header_filename = os.path.join(include_gen_folder, strip_name(c["name"]) + ".hpp") header_filename = include_gen_folder / (strip_name(c["name"]) + ".hpp")
with open(header_filename, "w+") as header_file: with header_filename.open("w+") as header_file:
header_file.write(header) header_file.write(header)
source_filename = os.path.join(source_gen_folder, strip_name(c["name"]) + ".cpp") source_filename = source_gen_folder / (strip_name(c["name"]) + ".cpp")
with open(source_filename, "w+") as source_file: with source_filename.open("w+") as source_file:
source_file.write(impl) source_file.write(impl)
icall_header_filename = os.path.join(include_gen_folder, '__icalls.hpp') icall_header_filename = include_gen_folder / '__icalls.hpp'
with open(icall_header_filename, "w+") as icall_header_file: with icall_header_filename.open("w+") as icall_header_file:
icall_header_file.write(generate_icall_header(icalls)) icall_header_file.write(generate_icall_header(icalls))
register_types_filename = os.path.join(source_gen_folder, '__register_types.cpp') register_types_filename = source_gen_folder / '__register_types.cpp'
with open(register_types_filename, "w+") as register_types_file: with register_types_filename.open("w+") as register_types_file:
register_types_file.write(generate_type_registry(classes)) register_types_file.write(generate_type_registry(classes))
init_method_bindings_filename = os.path.join(source_gen_folder, '__init_method_bindings.cpp') init_method_bindings_filename = source_gen_folder / '__init_method_bindings.cpp'
with open(init_method_bindings_filename, "w+") as init_method_bindings_file: with init_method_bindings_filename.open("w+") as init_method_bindings_file:
init_method_bindings_file.write(generate_init_method_bindings(classes)) init_method_bindings_file.write(generate_init_method_bindings(classes))