Skip to content

[clang-format] Add --strip-trailing-cr to diff in docs_updated.test #119666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

owenca
Copy link
Contributor

@owenca owenca commented Dec 12, 2024

Fixes #119517.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang-format labels Dec 12, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 12, 2024

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

Changes

Also clean up dump_format_style.py and dump_format_help.py.


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

3 Files Affected:

  • (modified) clang/docs/tools/dump_format_help.py (+4-2)
  • (modified) clang/docs/tools/dump_format_style.py (+6-4)
  • (modified) clang/test/Format/docs_updated.test (+3-2)
diff --git a/clang/docs/tools/dump_format_help.py b/clang/docs/tools/dump_format_help.py
index baf90048ee1352..ba41ed8c02c817 100755
--- a/clang/docs/tools/dump_format_help.py
+++ b/clang/docs/tools/dump_format_help.py
@@ -72,5 +72,7 @@ def validate(text, columns):
 
 contents = substitute(contents, "FORMAT_HELP", help_text)
 
-with open(opts.output if opts.output else DOC_FILE, "wb") as output:
-    output.write(contents.encode())
+with open(
+    opts.output if opts.output else DOC_FILE, "w", newline="", encoding="utf-8"
+) as f:
+    f.write(contents)
diff --git a/clang/docs/tools/dump_format_style.py b/clang/docs/tools/dump_format_style.py
index f00f3ee8b20e87..f035143f6b3d14 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -411,8 +411,8 @@ class State:
                     state = State.InStruct
                     enums[enum.name] = enum
                 else:
-                    # Enum member without documentation. Must be documented where the enum
-                    # is used.
+                    # Enum member without documentation. Must be documented
+                    # where the enum is used.
                     pass
             elif state == State.InNestedEnum:
                 if line.startswith("///"):
@@ -492,5 +492,7 @@ class State:
 
 contents = substitute(contents, "FORMAT_STYLE_OPTIONS", options_text)
 
-with open(args.output if args.output else DOC_FILE, "wb") as output:
-    output.write(contents.encode())
+with open(
+    args.output if args.output else DOC_FILE, "w", newline="", encoding="utf-8"
+) as f:
+    f.write(contents)
diff --git a/clang/test/Format/docs_updated.test b/clang/test/Format/docs_updated.test
index 17066650a12677..98d330e37ef450 100644
--- a/clang/test/Format/docs_updated.test
+++ b/clang/test/Format/docs_updated.test
@@ -1,5 +1,6 @@
 // RUN: %python %S/../../docs/tools/dump_format_style.py -o %t.style
-// RUN: diff %t.style %S/../../docs/ClangFormatStyleOptions.rst
+// RUN: diff --strip-trailing-cr %t.style \
+// RUN:   %S/../../docs/ClangFormatStyleOptions.rst
 
 // RUN: %python %S/../../docs/tools/dump_format_help.py -o %t.help
-// RUN: diff %t.help %S/../../docs/ClangFormat.rst
+// RUN: diff --strip-trailing-cr %t.help %S/../../docs/ClangFormat.rst

@llvmbot
Copy link
Member

llvmbot commented Dec 12, 2024

@llvm/pr-subscribers-clang

Author: Owen Pan (owenca)

Changes

Also clean up dump_format_style.py and dump_format_help.py.


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

3 Files Affected:

  • (modified) clang/docs/tools/dump_format_help.py (+4-2)
  • (modified) clang/docs/tools/dump_format_style.py (+6-4)
  • (modified) clang/test/Format/docs_updated.test (+3-2)
diff --git a/clang/docs/tools/dump_format_help.py b/clang/docs/tools/dump_format_help.py
index baf90048ee1352..ba41ed8c02c817 100755
--- a/clang/docs/tools/dump_format_help.py
+++ b/clang/docs/tools/dump_format_help.py
@@ -72,5 +72,7 @@ def validate(text, columns):
 
 contents = substitute(contents, "FORMAT_HELP", help_text)
 
-with open(opts.output if opts.output else DOC_FILE, "wb") as output:
-    output.write(contents.encode())
+with open(
+    opts.output if opts.output else DOC_FILE, "w", newline="", encoding="utf-8"
+) as f:
+    f.write(contents)
diff --git a/clang/docs/tools/dump_format_style.py b/clang/docs/tools/dump_format_style.py
index f00f3ee8b20e87..f035143f6b3d14 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -411,8 +411,8 @@ class State:
                     state = State.InStruct
                     enums[enum.name] = enum
                 else:
-                    # Enum member without documentation. Must be documented where the enum
-                    # is used.
+                    # Enum member without documentation. Must be documented
+                    # where the enum is used.
                     pass
             elif state == State.InNestedEnum:
                 if line.startswith("///"):
@@ -492,5 +492,7 @@ class State:
 
 contents = substitute(contents, "FORMAT_STYLE_OPTIONS", options_text)
 
-with open(args.output if args.output else DOC_FILE, "wb") as output:
-    output.write(contents.encode())
+with open(
+    args.output if args.output else DOC_FILE, "w", newline="", encoding="utf-8"
+) as f:
+    f.write(contents)
diff --git a/clang/test/Format/docs_updated.test b/clang/test/Format/docs_updated.test
index 17066650a12677..98d330e37ef450 100644
--- a/clang/test/Format/docs_updated.test
+++ b/clang/test/Format/docs_updated.test
@@ -1,5 +1,6 @@
 // RUN: %python %S/../../docs/tools/dump_format_style.py -o %t.style
-// RUN: diff %t.style %S/../../docs/ClangFormatStyleOptions.rst
+// RUN: diff --strip-trailing-cr %t.style \
+// RUN:   %S/../../docs/ClangFormatStyleOptions.rst
 
 // RUN: %python %S/../../docs/tools/dump_format_help.py -o %t.help
-// RUN: diff %t.help %S/../../docs/ClangFormat.rst
+// RUN: diff --strip-trailing-cr %t.help %S/../../docs/ClangFormat.rst

Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the cleanup just running black? Would be better committed separately in my opinion. Either way, LGTM for both the cleanup and the test change.

@owenca
Copy link
Contributor Author

owenca commented Dec 13, 2024

Is the cleanup just running black? Would be better committed separately in my opinion.

See ea44647.

@owenca owenca merged commit d7a8e09 into llvm:main Dec 13, 2024
8 checks passed
@owenca owenca deleted the 119517 branch December 13, 2024 08:03
madanial0 added a commit that referenced this pull request Dec 17, 2024
#119666 adds the
`-strip-trailing-cr` flag to diff which is not supported on AIX switch
to use the python implementation of diff instead
@owenca owenca removed the clang Clang issues not falling into any other category label Jan 3, 2025
github-actions bot pushed a commit to arm/arm-toolchain that referenced this pull request Jan 9, 2025
…) (#120276)

llvm/llvm-project#119666 adds the
`-strip-trailing-cr` flag to diff which is not supported on AIX switch
to use the python implementation of diff instead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clang :: Format/docs_updated.test failed after building with MSVC
3 participants