Skip to content
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

feat: case insensitive diff_test and fix manifest bug #527

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

peakschris
Copy link

In my work on windows quality in rulesets, a frequent issue I am finding is that diff_tests are failing due to differences in line endings -- either due to differences in the 'expected' values, or cross-platform differences in generators (e.g. buildifier always writes LF, whilst skydoc writes LF or CRLF depending on platform).

We can't expect rule authors to work around these differences, because in practice they do not have good access to windows dev hardware.

The goal of this PR is to make diff_test slightly less brittle and ignore line endings by default. An ignore_line_endings flag is provided to switch this behavior.

This flag is supported by the diff command on unix. On windows, it requires the tr.exe command that is part of most bash installs including msys2. If tr.exe cannot be found the ignore_line_endings flag is silently ignored and set to False.

This PR allows us to enable the 1 disabled test 'stardoc_with_diff_test' on windows CI, and also fixes many test failures in dependent rulesets such as rules_starlib and rules_bazel_integration_test

Copy link

google-cla bot commented Jun 29, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@peakschris peakschris changed the title feat: case insensitive diff_test feat: case insensitive diff_test and fix manifest bug Jun 29, 2024
cgrindel pushed a commit to bazel-contrib/rules_bazel_integration_test that referenced this pull request Jul 3, 2024
There are four issues when running on windows:

1.
#330
2.
#331
3.
#332
4.
#333

This PR fixes 3 and 4.

There are related PRs in bazel-skylib and bazel-starlib. There is no
dependency -- the PRs can close in any order.
- cgrindel/bazel-starlib#446 (fixes 1)
- bazelbuild/bazel-skylib#527 (fixes 2)

### Test results:
Before:
--enable_runfiles: 0 pass
--noenable_runfiles: 0 pass

After this PR:
--enable_runfiles: 52 pass, 19 failures
--noenable_runfiles: 51 pass, 20 failures (17 are doc diff-tests due to
bazel-starlib)

After this PR, together with wip PRs for 1 and 2:
--enable_runfiles: 71 pass, 0 failures
--noenable_runfiles: 51 pass, 20 failures (all due to bazel-starlib)
@peakschris
Copy link
Author

@brandjon @tetromino @comius @hvadehra @c-mita gentle ping, would it be possible for someone to review this? I have a chain of PRs to rulesets dependent on this one to improve windows support.

@cgrindel
Copy link
Contributor

cgrindel commented Jul 5, 2024

@peakschris Did you see this message? This may not be reviewed and merged. I will bring this up at the next Community for Bazel technical steering committee meeting which is scheduled for Tuesday, July 9.

Comment on lines +29 to +34
def _ignore_line_endings(ctx):
ignore_line_endings = "0"
if ctx.attr.ignore_line_endings:
ignore_line_endings = "1"
return ignore_line_endings

Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of a func for this, I'd opt for a one-liner on its call site. This way its a bit more readable, because I don't need to jump around file, to see what it does.

e.g. "1" if ctx.attr.ignore_line_endings else "0"

set "TR=C:\\msys64\\usr\\bin\\tr.exe"
)
if not exist !TR! (
echo>&2 WARNING: ignore_line_endings set but !TR! not found; line endings will be compared
Copy link
Collaborator

Choose a reason for hiding this comment

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

Bazel team is quite opinionated about warnings. This should be an error.

def _diff_test_impl(ctx):
if ctx.attr.is_windows:
bash_bin = ctx.toolchains["@bazel_tools//tools/sh:toolchain_type"].path
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that we require bash, I wonder if the maintenance of this rule would be simpler, to use the same bash script on windows (and maybe fallback to fc or just use diff)?

@@ -80,12 +80,13 @@ eof
echo bar > "$ws/$subdir/b.txt"

(cd "$ws" && \
bazel test ${flags} "//${subdir%/}:same" --test_output=errors 1>"$TEST_log" 2>&1 \
bazel test ${flags} "//${subdir%/}:same" --test_output=errors --noshow_progress 1>>"$TEST_log" 2>&1 \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you changing tests?

if ! diff {strip_trailing_cr}"$RF1" "$RF2"; then
MSG={fail_msg}
if [[ "${{MSG}}" == "" ]]; then
MSG="why? diff {strip_trailing_cr}"${{RF1}}" "${{RF2}}" | cat -v"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this message so different from the message before? Also use of RF1 is inconsistend with use of {file1} below.

Copy link
Collaborator

@comius comius left a comment

Choose a reason for hiding this comment

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

I think this is quite complicated change and this brings with it potentially higher mainteinance costs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants