From bbe40790d1c76467138aad4859e100cf4035b2ad Mon Sep 17 00:00:00 2001 From: Jeff Raymakers Date: Sun, 23 Jun 2024 11:21:58 -0700 Subject: [PATCH] attempt to fix file problems in win --- generate-wrapper.py | 71 +++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/generate-wrapper.py b/generate-wrapper.py index 9d68cce3..2d6bb418 100644 --- a/generate-wrapper.py +++ b/generate-wrapper.py @@ -238,35 +238,36 @@ def get_lib_file_name(): raise Exception("Unsupported system: " + system) if __name__ == "__main__": + dir_path = os.path.dirname(os.path.realpath(__file__)) - with tempfile.TemporaryDirectory() as tmp: - dir_path = os.path.dirname(os.path.realpath(__file__)) - - zip_path = os.path.join(tmp, "libduckdb.zip") + with tempfile.TemporaryDirectory() as zip_tmp: + zip_path = os.path.join(zip_tmp, "libduckdb.zip") + release_zip_url = get_release_zip_url() - print("Downloading " + release_zip_url) urllib.request.urlretrieve(release_zip_url, zip_path) print("Extracting zip") zip = zipfile.ZipFile(zip_path) - lib_file_name = get_lib_file_name() - zip.extract(lib_file_name, tmp) - shutil.copy(os.path.join(tmp, lib_file_name), os.path.join(dir_path, "lib", "binding", "libduckdb")) + with tempfile.TemporaryDirectory() as ext_tmp: + lib_file_name = get_lib_file_name() + zip.extract(lib_file_name, ext_tmp) + shutil.copy(os.path.join(ext_tmp, lib_file_name), os.path.join(dir_path, "lib", "binding", "libduckdb")) - zip.extract("duckdb.h", "src") - zip.extract("duckdb.h", tmp) + zip.extract("duckdb.h", "src") + zip.extract("duckdb.h", ext_tmp) - print("Preprocessing duckdb.h") - os.system("sed -i -e 's/#include /#include /' %s" % os.path.join(tmp, "duckdb.h")) # until 0.10.0 has been released - os.system("gcc -DDUCKDB_NO_EXTENSION_FUNCTIONS -DDUCKDB_API_NO_DEPRECATED -E -D__builtin_va_list=int -D'__attribute__(x)=' %s > %s" % (os.path.join(tmp, "duckdb.h"), os.path.join(tmp, "duckdb-preprocessed.h"))) + print("Preprocessing duckdb.h") + os.system("sed -i -e 's/#include /#include /' %s" % os.path.join(ext_tmp, "duckdb.h")) # until 0.10.0 has been released + os.system("gcc -DDUCKDB_NO_EXTENSION_FUNCTIONS -DDUCKDB_API_NO_DEPRECATED -E -D__builtin_va_list=int -D'__attribute__(x)=' %s > %s" + % (os.path.join(ext_tmp, "duckdb.h"), os.path.join(ext_tmp, "duckdb-preprocessed.h"))) - print("Generating C code and TypeScript definitions") - cpp_result, types_result = create_func_defs(os.path.join(tmp, "duckdb-preprocessed.h")) + print("Generating C code and TypeScript definitions") + cpp_result, types_result = create_func_defs(os.path.join(ext_tmp, "duckdb-preprocessed.h")) - out = open(os.path.join(dir_path, "src", "duckdb_node_generated.cpp"), 'wb') - out.write('''// This file is generated by generate-wrapper.py, please do not edit + out = open(os.path.join(dir_path, "src", "duckdb_node_generated.cpp"), 'wb') + out.write('''// This file is generated by generate-wrapper.py, please do not edit #include "duckdb.h" #include "function_wrappers.hpp" @@ -274,26 +275,26 @@ def get_lib_file_name(): static void RegisterGenerated(Napi::Env env, Napi::Object exports, std::unordered_map &constructors) { '''.encode()) - out.write(cpp_result.encode()) - out.write('}\n'.encode()) + out.write(cpp_result.encode()) + out.write('}\n'.encode()) - types_out = open('lib/duckdb.d.ts', 'wb') - - types_out.write('// placeholder interfaces for pointer types\n'.encode()) - types_out.write('export interface idx_pointer extends pointer {}\n'.encode()) + types_out = open('lib/duckdb.d.ts', 'wb') + + types_out.write('// placeholder interfaces for pointer types\n'.encode()) + types_out.write('export interface idx_pointer extends pointer {}\n'.encode()) - types_out.write('// bindings-defined types\n'.encode()) - types_out.write('export class pointer {}\n'.encode()) - types_out.write('export class uint64_pointer {}\n'.encode()) - types_out.write('export class out_string_wrapper {}\n'.encode()) + types_out.write('// bindings-defined types\n'.encode()) + types_out.write('export class pointer {}\n'.encode()) + types_out.write('export class uint64_pointer {}\n'.encode()) + types_out.write('export class out_string_wrapper {}\n'.encode()) - types_out.write('// generated types and functions\n'.encode()) - types_out.write(types_result.encode()) + types_out.write('// generated types and functions\n'.encode()) + types_out.write(types_result.encode()) - types_out.write('// bindings-defined constants\n'.encode()) - types_out.write('export const sizeof_bool: number;\n'.encode()) + types_out.write('// bindings-defined constants\n'.encode()) + types_out.write('export const sizeof_bool: number;\n'.encode()) - types_out.write('// bindings-defined functions\n'.encode()) - types_out.write('export function copy_buffer(buffer: pointer, length: number): Uint8Array | null;\n'.encode()) - types_out.write('export function copy_buffer_double(buffer: number, length: number): Uint8Array | null;\n'.encode()) - types_out.write('export function out_get_string(string_wrapper: out_string_wrapper): string;\n'.encode()) + types_out.write('// bindings-defined functions\n'.encode()) + types_out.write('export function copy_buffer(buffer: pointer, length: number): Uint8Array | null;\n'.encode()) + types_out.write('export function copy_buffer_double(buffer: number, length: number): Uint8Array | null;\n'.encode()) + types_out.write('export function out_get_string(string_wrapper: out_string_wrapper): string;\n'.encode())