[clang] [clang-format] Explicitly open DOC_FILE with utf-8 in dump_format_style.py (PR #79805)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 29 02:48:07 PST 2024


https://github.com/rmarker created https://github.com/llvm/llvm-project/pull/79805

The dump_format_style.py script generates the clang-format style options documentation.
There was an issue where the script could include spurious characters in the output when run in windows. It appears that it wasn't defaulting to the correct encoding when reading the input.
This has been addressed by explicitly setting the encoding when opening the file.

>From 7e639edc339b3f09d8e67860b32b2c4bff3237d9 Mon Sep 17 00:00:00 2001
From: rmarker <rmarker at outlook.com>
Date: Mon, 29 Jan 2024 21:13:45 +1030
Subject: [PATCH] [clang-format] Explicitly open DOC_FILE with utf-8 in
 dump_format_style.py.

The dump_format_style script generates the clang-format style options documentation.
There was an issue where the script could include spurious characters in the output when run in windows.
It appears that it wasn't defaulting to the correct encoding when reading the input.
This has been addressed by explicitly setting the encoding when opening the file.
---
 clang/docs/tools/dump_format_style.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/tools/dump_format_style.py b/clang/docs/tools/dump_format_style.py
index 75d4a044ef19f68..e41891f07de2e32 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -474,7 +474,7 @@ class State:
 opts = sorted(opts, key=lambda x: x.name)
 options_text = "\n\n".join(map(str, opts))
 
-with open(DOC_FILE) as f:
+with open(DOC_FILE, encoding="utf-8") as f:
     contents = f.read()
 
 contents = substitute(contents, "FORMAT_STYLE_OPTIONS", options_text)



More information about the cfe-commits mailing list