[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:36 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: None (rmarker)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/79805.diff


1 Files Affected:

- (modified) clang/docs/tools/dump_format_style.py (+1-1) 


``````````diff
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)

``````````

</details>


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


More information about the cfe-commits mailing list