From fdfe8cea43a4d2e4d4a98870be91bcd895933d35 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Sun, 28 Dec 2025 11:25:49 +0100 Subject: [PATCH] chore: add explicit UTF-8 encoding for FFI doc generation Add `encoding='utf-8'` to all file open operations in the FFI documentation generation scripts since the default Windows encoding doesnt seem to go well with it and lets the relevant `pre-commit` step fail for Windows in #253. Also improved error visibility in `verify_ffi.py` by capturing stderr when the subprocess fails. --- contrib/verify_ffi.py | 5 ++++- dash-spv-ffi/scripts/generate_ffi_docs.py | 4 ++-- key-wallet-ffi/scripts/generate_ffi_docs.py | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/contrib/verify_ffi.py b/contrib/verify_ffi.py index 9580fff2d..a4d0393f2 100755 --- a/contrib/verify_ffi.py +++ b/contrib/verify_ffi.py @@ -35,7 +35,10 @@ def generate_ffi_docs(crate_dir: Path) -> tuple[str, int, str]: capture_output=True, text=True ) - return crate_dir.name, result.returncode, result.stdout + output = result.stdout + if result.returncode != 0 and result.stderr: + output = result.stderr + return crate_dir.name, result.returncode, output def main(): diff --git a/dash-spv-ffi/scripts/generate_ffi_docs.py b/dash-spv-ffi/scripts/generate_ffi_docs.py index c0b65210a..1b8c9c4bb 100755 --- a/dash-spv-ffi/scripts/generate_ffi_docs.py +++ b/dash-spv-ffi/scripts/generate_ffi_docs.py @@ -29,7 +29,7 @@ def extract_ffi_functions(file_path: Path) -> List[FFIFunction]: """ functions: List[FFIFunction] = [] - with open(file_path, 'r') as f: + with open(file_path, 'r', encoding='utf-8') as f: content = f.read() # Iterate over all #[no_mangle] attribute occurrences @@ -370,7 +370,7 @@ def main(): # Write to file output_file = Path(__file__).parent.parent / "FFI_API.md" - with open(output_file, 'w') as f: + with open(output_file, 'w', encoding='utf-8') as f: f.write(markdown) print(f"Generated FFI documentation with {len(all_functions)} functions") diff --git a/key-wallet-ffi/scripts/generate_ffi_docs.py b/key-wallet-ffi/scripts/generate_ffi_docs.py index faa22e53d..57f27b16a 100755 --- a/key-wallet-ffi/scripts/generate_ffi_docs.py +++ b/key-wallet-ffi/scripts/generate_ffi_docs.py @@ -28,7 +28,7 @@ def extract_ffi_functions(file_path: Path) -> List[FFIFunction]: """ functions: List[FFIFunction] = [] - with open(file_path, 'r') as f: + with open(file_path, 'r', encoding='utf-8') as f: content = f.read() for m in re.finditer(r'(?m)^\s*#\[no_mangle\]\s*$', content): @@ -309,7 +309,7 @@ def main(): # Write to file output_file = Path(__file__).parent.parent / "FFI_API.md" - with open(output_file, 'w') as f: + with open(output_file, 'w', encoding='utf-8') as f: f.write(markdown) print(f"Generated FFI documentation with {len(all_functions)} functions")