-
Notifications
You must be signed in to change notification settings - Fork 238
common: util: stop using binary mode in SetContents #2371
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
hzeller
merged 4 commits into
chipsalliance:master
from
IEncinas10:fix-windows-newline-handling
May 19, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0b21c64
verilog: tools: formatter: use IsStdin against input filename
IEncinas10 f04149c
verilog: tools: formatter: output formatted files exactly as produced…
IEncinas10 b020a49
verible: formatting: make line terminator character configurable
IEncinas10 feaaa5a
parser: verilog.lex: remove \r from TK_EOL_COMMENT for DOS newlines
IEncinas10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
verible/verilog/tools/formatter/format_line_terminator_test.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2017-2025 The Verible Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
IEncinas10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
declare -r MY_INPUT_FILE="${TEST_TMPDIR}/myinput.txt" | ||
declare -r MY_OUTPUT_FILE="${TEST_TMPDIR}/myoutput.txt" | ||
declare -r MY_EXPECT_FILE="${TEST_TMPDIR}/myexpect.txt" | ||
|
||
# Get tool from argument | ||
[[ "$#" == 1 ]] || { | ||
echo "Expecting 1 positional argument, verible-verilog-format path." | ||
exit 1 | ||
} | ||
formatter="$(rlocation ${TEST_WORKSPACE}/${1})" | ||
|
||
# Create files with LF and CRLF line terminators. They are properly formatted, so running | ||
# the formatter should only change line endings | ||
printf "// some comment\n/* some other comment */\nmodule m;\nendmodule\n" > "${MY_INPUT_FILE}LF" | ||
printf "// some comment\r\n/* some other comment */\r\nmodule m;\r\nendmodule\r\n" > "${MY_INPUT_FILE}CRLF" | ||
|
||
|
||
for newline in LF CRLF; do | ||
cp "${MY_INPUT_FILE}$newline" "${MY_EXPECT_FILE}$newline" | ||
done | ||
|
||
# Test any combination of input line terminators and output line terminators. | ||
# Test both inline formatting and standard output | ||
for original_newline in LF CRLF; do | ||
for target_newline in LF CRLF; do | ||
PROPER_INPUT_FILE="${MY_INPUT_FILE}$original_newline" | ||
PROPER_EXPECT_FILE="${MY_EXPECT_FILE}$target_newline" | ||
|
||
${formatter} --line_terminator=$target_newline $PROPER_INPUT_FILE > ${MY_OUTPUT_FILE} | ||
cmp ${MY_OUTPUT_FILE} $PROPER_EXPECT_FILE || exit 1 | ||
|
||
cp $PROPER_INPUT_FILE ${MY_OUTPUT_FILE} | ||
${formatter} --line_terminator=$target_newline --inplace ${MY_OUTPUT_FILE} | ||
cmp ${MY_OUTPUT_FILE} $PROPER_EXPECT_FILE || exit 2 | ||
done | ||
done | ||
|
||
echo "PASS" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a follow-up, we should consider here some sort of 'auto' setting that then maybe looks at some statistics of the input newline-types it has seen and choose the corresponding output type. Not here, follow-up for later is sufficient.