From 476a870d6c02957df63f3b961df8823874549de1 Mon Sep 17 00:00:00 2001 From: Hristo Stamenov Date: Sat, 15 May 2021 23:57:05 +0300 Subject: [PATCH] Fix CMake generation on Windows (#536) --- binding_generator.py | 59 +++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/binding_generator.py b/binding_generator.py index 491acbe5..ba2ceead 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -3,6 +3,7 @@ from __future__ import print_function import json import os import errno +from pathlib import Path # Convenience function for using template get_node def correct_method_name(method_list): @@ -19,23 +20,23 @@ def print_file_list(api_filepath, output_dir, headers=False, sources=False): end = ';' with open(api_filepath) as api_file: classes = json.load(api_file) - include_gen_folder = os.path.join(output_dir, 'include', 'gen') - source_gen_folder = os.path.join(output_dir, 'src', 'gen') + include_gen_folder = Path(output_dir) / 'include' / 'gen' + source_gen_folder = Path(output_dir) / 'src' / 'gen' for _class in classes: - header_filename = os.path.join(include_gen_folder, strip_name(_class["name"]) + ".hpp") - source_filename = os.path.join(source_gen_folder, strip_name(_class["name"]) + ".cpp") + header_filename = include_gen_folder / (strip_name(_class["name"]) + ".hpp") + source_filename = source_gen_folder / (strip_name(_class["name"]) + ".cpp") if headers: - print(header_filename, end=end) + print(str(header_filename.as_posix()), end=end) if sources: - print(source_filename, end=end) - icall_header_filename = os.path.join(include_gen_folder, '__icalls.hpp') - register_types_filename = os.path.join(source_gen_folder, '__register_types.cpp') - init_method_bindings_filename = os.path.join(source_gen_folder, '__init_method_bindings.cpp') + print(str(source_filename.as_posix()), end=end) + icall_header_filename = include_gen_folder / '__icalls.hpp' + register_types_filename = source_gen_folder / '__register_types.cpp' + init_method_bindings_filename = source_gen_folder / '__init_method_bindings.cpp' if headers: - print(icall_header_filename, end=end) + print(str(icall_header_filename.as_posix()), end=end) if sources: - print(register_types_filename, end=end) - print(init_method_bindings_filename, end=end) + print(str(register_types_filename.as_posix()), end=end) + print(str(init_method_bindings_filename.as_posix()), end=end) 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) icalls = set() - include_gen_folder = os.path.join(output_dir, 'include', 'gen') - source_gen_folder = os.path.join(output_dir, 'src', 'gen') + include_gen_folder = Path(output_dir) / 'include' / 'gen' + source_gen_folder = Path(output_dir) / 'src' / 'gen' + try: - os.makedirs(include_gen_folder) + include_gen_folder.mkdir(parents=True) except os.error as e: if e.errno == errno.EEXIST: - print(include_gen_folder + ": " + os.strerror(e.errno)) + print(str(source_gen_folder) + ": " + os.strerror(e.errno)) else: exit(1) + try: - os.makedirs(source_gen_folder) + source_gen_folder.mkdir(parents=True) except os.error as e: if e.errno == errno.EEXIST: - print(source_gen_folder + ": " + os.strerror(e.errno)) + print(str(source_gen_folder) + ": " + os.strerror(e.errno)) else: 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) - header_filename = os.path.join(include_gen_folder, strip_name(c["name"]) + ".hpp") - with open(header_filename, "w+") as header_file: + header_filename = include_gen_folder / (strip_name(c["name"]) + ".hpp") + with header_filename.open("w+") as header_file: header_file.write(header) - source_filename = os.path.join(source_gen_folder, strip_name(c["name"]) + ".cpp") - with open(source_filename, "w+") as source_file: + source_filename = source_gen_folder / (strip_name(c["name"]) + ".cpp") + with source_filename.open("w+") as source_file: source_file.write(impl) - icall_header_filename = os.path.join(include_gen_folder, '__icalls.hpp') - with open(icall_header_filename, "w+") as icall_header_file: + icall_header_filename = include_gen_folder / '__icalls.hpp' + with icall_header_filename.open("w+") as icall_header_file: icall_header_file.write(generate_icall_header(icalls)) - register_types_filename = os.path.join(source_gen_folder, '__register_types.cpp') - with open(register_types_filename, "w+") as register_types_file: + register_types_filename = source_gen_folder / '__register_types.cpp' + with register_types_filename.open("w+") as register_types_file: register_types_file.write(generate_type_registry(classes)) - init_method_bindings_filename = os.path.join(source_gen_folder, '__init_method_bindings.cpp') - with open(init_method_bindings_filename, "w+") as init_method_bindings_file: + init_method_bindings_filename = source_gen_folder / '__init_method_bindings.cpp' + with init_method_bindings_filename.open("w+") as init_method_bindings_file: init_method_bindings_file.write(generate_init_method_bindings(classes))