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

[#164] Improve Windows support #191

Merged
merged 3 commits into from
Nov 30, 2022

Conversation

Sorokin-Anton
Copy link
Contributor

@Sorokin-Anton Sorokin-Anton commented Oct 10, 2022

Description

When I tried to test xrefcheck on windows locally, I've found following problems:

Problem: it requires some dynamic libraries to run, and stack install place them in directory that is not on PATH by default
Solution: add this information and possible workarounds to README.md, create issue is stack


Problem: most Windows shells are not supporting utf8 by default. Sometimes printing of reports raise an error. hPutChar: invalid argument (Invalid argument)

Solution: use function withCP65001 from code-page package which
sets correct codepage on Windows and do nothing on other OSs


Problem: in markdown links, '/' should always be used as path separator ,
e.g. GitHub renderer is not threating link [x](a\b.md) as a link
to file in dir a
We use OS-dependent file separators everywhere, so
e.g. canonizeLocalRef "./a.md"="./a.md"` on Windows

Solution: replace '' to '/' while constructing repo tree if needed
and then use only '/', preferring functions from System.FilePath.Posix.
We can do this, since 'a/b' and a\b are equivalent paths on Windows


Also I've added github actions workflow that runs stack test xrefcheck:xrefcheck-tests and golden tests (this required modification of some tests)

Related issue(s)

Fixes #164

✅ Checklist for your Pull Request

Ideally a PR has all of the checkmarks set.

If something in this list is irrelevant to your PR, you should still set this
checkmark indicating that you are sure it is dealt with (be that by irrelevance).

Related changes (conditional)

  • Tests

    • If I added new functionality, I added tests covering it.
    • If I fixed a bug, I added a regression test to prevent the bug from
      silently reappearing again.
  • Documentation

    • I checked whether I should update the docs and did so if necessary:
  • Public contracts

    • Any modifications of public contracts comply with the Evolution
      of Public Contracts
      policy.
    • I added an entry to the changelog if my changes are visible to the users
      and
    • provided a migration guide for breaking changes if possible

Stylistic guide (mandatory)

@Sorokin-Anton Sorokin-Anton force-pushed the Sorokin-Anton/#164-ci-windows-tests branch 2 times, most recently from 178d3f8 to 65b4307 Compare October 11, 2022 20:44
@Sorokin-Anton Sorokin-Anton linked an issue Oct 12, 2022 that may be closed by this pull request
@Sorokin-Anton Sorokin-Anton changed the title Sorokin anton/#164 ci windows tests [#164] Improve Windows support Oct 12, 2022
@Sorokin-Anton Sorokin-Anton force-pushed the Sorokin-Anton/#164-ci-windows-tests branch 2 times, most recently from 6c37585 to 6fa646f Compare October 13, 2022 14:07
@Sorokin-Anton Sorokin-Anton marked this pull request as ready for review October 13, 2022 14:12
@Sorokin-Anton Sorokin-Anton requested review from dcastro and Sereja313 and removed request for dcastro October 13, 2022 14:12
@Sorokin-Anton Sorokin-Anton force-pushed the Sorokin-Anton/#164-ci-windows-tests branch from 6fa646f to 74361a3 Compare October 13, 2022 14:31
@Sorokin-Anton Sorokin-Anton force-pushed the Sorokin-Anton/#164-ci-windows-tests branch from 74361a3 to 2875291 Compare October 18, 2022 20:37
@Sorokin-Anton
Copy link
Contributor Author

Sorokin-Anton commented Oct 18, 2022

Ok, now I need to think how to add case-sensetivity on Windows

UPD: after rebase on #174, case sensetivity works correctly

@Sorokin-Anton Sorokin-Anton force-pushed the Sorokin-Anton/#164-ci-windows-tests branch from 2875291 to 44eba48 Compare October 19, 2022 09:26
@Sorokin-Anton Sorokin-Anton changed the base branch from master to Sereja313/#139-ignore-build-related-files October 19, 2022 09:27
@Sereja313 Sereja313 force-pushed the Sereja313/#139-ignore-build-related-files branch from 81b8ab4 to bfbe20a Compare October 21, 2022 12:13
Base automatically changed from Sereja313/#139-ignore-build-related-files to master October 21, 2022 12:16
@Sorokin-Anton Sorokin-Anton force-pushed the Sorokin-Anton/#164-ci-windows-tests branch from 44eba48 to e6663ad Compare October 21, 2022 12:39
@Sorokin-Anton Sorokin-Anton force-pushed the Sorokin-Anton/#164-ci-windows-tests branch from e6663ad to 3d74654 Compare November 3, 2022 12:38
@Sorokin-Anton Sorokin-Anton force-pushed the Sorokin-Anton/#164-ci-windows-tests branch from 3d74654 to fcaebbe Compare November 9, 2022 14:47
Copy link
Member

@Martoon-00 Martoon-00 left a comment

Choose a reason for hiding this comment

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

Looks good to me, leaving just a few minor comments.

I'll try to wrap my head around possible pitfalls for more and maybe will give another review later.

@@ -47,7 +48,7 @@ findFirstExistingFile = \case
if exists then pure (Just file) else findFirstExistingFile files

defaultAction :: Options -> IO ()
defaultAction Options{..} = do
defaultAction Options{..} = withCP65001 $ do
Copy link
Member

Choose a reason for hiding this comment

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

In Main.hs module we use withUtf8, which sort of tries to switch everything to UTF-8 so that the developer does not need to worry about all the changes that must be made.

How do you think, would it be justified to create an issue in their GitHub? (Actually, this is a Serokell's package, so it could be just an improvement suggestion)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Created issue in that repo, also moved withCP65001 to Main to keep such things in one place

Copy link
Member

Choose a reason for hiding this comment

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

Awesome 👍

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
when (config /= defConfigText GitHub) $
-- On Windows, git clone can replace \n with \r\n in some files
let removeCR = BS.filter (/= '\r')
when (removeCR config /= removeCR (defConfigText GitHub)) $
Copy link
Member

Choose a reason for hiding this comment

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

We use defConfigText in xrefcheck dump-config, will it be fine if we eventually print that text without \rs?

Copy link
Contributor Author

@Sorokin-Anton Sorokin-Anton Nov 10, 2022

Choose a reason for hiding this comment

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

Checked, this is not a problem for yaml parser

Copy link
Member

@Martoon-00 Martoon-00 Nov 13, 2022

Choose a reason for hiding this comment

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

How about the user that will try to open and edit that file? Won't they see everything displayed in one line (at least in some text editors)?

UPD: or maybe not in one line, rather without caret returns.

CHANGES.md Outdated Show resolved Hide resolved


# When editing this action, make sure it can run without using cached folders.
# Yes, it tries to install mingw-w64-x86_64-pcre twice
Copy link
Member

Choose a reason for hiding this comment

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

Pacman does not feel too well? 🧌

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just recorded my shell history, and then realized it's the way

Copy link
Member

Choose a reason for hiding this comment

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

It's just a bit of torture to see a mention of some magic without an explanation of why it is needed / why it works 😅

On the other hand, if all the possible explanation is "doing it once fails with X error, but somehow repeat helps both locally and in CI, no one knows why", then maybe it's really not necessary to provide.

@Sorokin-Anton Sorokin-Anton force-pushed the Sorokin-Anton/#164-ci-windows-tests branch from fdef5d0 to 156da98 Compare November 10, 2022 23:04
@Sorokin-Anton
Copy link
Contributor Author

Oh, looks like ci action fails because diff is now space-sensetive, so does not like cr-s. Locally on Windows everything passes (no cr-s) , for me it's still a question where and why cr-s appear. Luckily there is diff option specially for that

@Martoon-00
Copy link
Member

Oh, looks like ci action fails because diff is now space-sensetive

I would take a more thorough look at this, as it may point to a real UX issue of xrefcheck that will rise for some users.

I have two thoughts:

  1. AFAIR when I installed git in Windows, it asked me which line ending I want to use and whether do I want to replace non-matching line endings automatically.

    And looks like GitHub actions for Windows have this conversion enabled by default. People in that ticket also mention issues with testing, so given that this problem is common for tests, disabling automatic line endings conversion can be a way to go.

    If this is an issue in our case, I don't have strong opinion on where to fix it, in assert_diff or in the ci config via overriding the git settings.

  2. In xrefcheck's output, do we have cr-s or not?

    I suspect we need them, as otherwise not all terminals / editors (in case the user re-directs the output to a file) will manage to display that properly?

    On the other side, cr-s should already be included because TIL in Haskell's base package input/output streams are automatically updated to handle the newline endings 🤔

However judging by your symptops (as far as I got them correctly), I completely don't understand which of these points currently take place and which may need an adjustment.

@Sorokin-Anton
Copy link
Contributor Author

@Martoon-00 finally, I've got two results:
If I gather xrefcheck's output via xrefcheck.exe > tmpfile, there are \rs
If I run xrefcheck.exe dump-config -t GitHub, thee are Unix line endings (no \rs)
I will try to use a different function so the config would be dumped with \rs.
About diffs - I'd prefer to use checkout with \rs since this would also allow us to simplify one Haskell test.

@Sorokin-Anton Sorokin-Anton force-pushed the Sorokin-Anton/#164-ci-windows-tests branch from bbdf5ee to 1c22137 Compare November 26, 2022 14:24
@Sorokin-Anton Sorokin-Anton force-pushed the Sorokin-Anton/#164-ci-windows-tests branch from 1c22137 to e899d5d Compare November 26, 2022 14:34
@Sorokin-Anton
Copy link
Contributor Author

@Martoon-00 Bad news: if the repository was cloned with crlf's, output files have extra caret returns e.g. === Invalid references found ===\r\r\n\r\r\n
So I need some time to handle this

@Sorokin-Anton
Copy link
Contributor Author

Sorokin-Anton commented Nov 26, 2022

The reason of this is

ghci> TL.unlines ["a","b"]        
"a\nb\n"

and

ghci> TL.lines "a\r\nb\r\nc"
["a\r","b\r","c"]

while nyan-interpolation produced strings have \r's when they are in source file.
AFAIU in code we should think that no \r exists until printing anything.
I think the best way is to change nyan-interpolation code so interpolated strings never have \r's
Because if we have writeFile "aaaaaaaaaa" "a\nb\r\nc" (so in some places there was caret return and in some there were not), all \n s are transformed to \r\n during IO and those \r\r\n monsters appear

@Martoon-00
Copy link
Member

Awesome. Very nice investigation!

I agree with your conclusions. Quite sad that this was produced by nyan-interpolation (suddenly, initially I would never suspect it). We will have to get it fixed there.

Problem: xrefcheck uses utf8 symbols in reports, which are not supported
on most of Windows shells by default.
Sometimes they are printed as question marks (and it cause golden tests to fail)
and sometimes printing of them raise an error.

Solution: use function `withCP65001` from `code-page` package which
sets correct codepage on Windows and do nothing on other OSs
Problem: in markdown links, '/' should always be used as path separator ,
e.g. GitHub renderer is not threating link `[x](a\b.md)` as a link
to file in dir `a`
We use OS-dependent file separators everywhere, so
e.g. `canonizeLocalRef "./a.md"="./a.md`"` on Windows

Solution: replace '\' to '/' while constructing repo tree if needed
and then use only '/', preferring functions from `System.FilePath.Posix`.
We can do this, since 'a/b' and `a\b` are equivalent paths on Windows
@Sorokin-Anton Sorokin-Anton force-pushed the Sorokin-Anton/#164-ci-windows-tests branch from e899d5d to 109d1ce Compare November 29, 2022 19:42
@Sorokin-Anton
Copy link
Contributor Author

Sorokin-Anton commented Nov 29, 2022

@Martoon-00 interesting fact: to_temp from bats always creates a file with LF endings 😐
I can't see why, looks like it is not a problem with our helpers. Same problem with assert_output
Looks like it's impossible to run assert_output --partial on multiline output on WIndows (and we use this to check error message in some cases).
So I'm leaving --strip-trailing-cr in assert_diff and rewriting those checks using multiple assert_output --partial.
Maybe one should create an assert_stderr_diff function later

@Martoon-00
Copy link
Member

Meeh, I see.

Your solution to this sounds good. I have no other concerns.


Just a few words on this farewell I guess: that was a pleasure to review the work of yours. In my feeling, it required fewer review iterations than on average as you did everything mostly perfectly from the beginning. It was comfortable to me how initiative you were and has far you were ready to go when new issues arose. And concerns with English were pretty minor IMO.

Problem: we are not testing behavior of xrefcheck on Windows

Solution: and add workflow to run
golden and tasty tests on CI
via github-actions windows runner
Some subproblems appear:

1.
Problem: CI build fails beacuse it needs `pcre` package
Solution: add it (somehow), see `install pacman dependencies`
in ci.yml

2.
Problem: Network errors displayed different on different platforms
Solution: collect output from both and use
`assert_diff expected_linux.gold || assert_diff expected_windows.gold`

3:
Problem: "Config matches" test is failing because checkout action
clone files with CRLF, and test assert equality of two ByteStrings
Solution: manually remove CR
@Sorokin-Anton Sorokin-Anton force-pushed the Sorokin-Anton/#164-ci-windows-tests branch from fe7ec9b to fb77575 Compare November 30, 2022 19:01
@Sorokin-Anton Sorokin-Anton merged commit 6415828 into master Nov 30, 2022
@Sorokin-Anton Sorokin-Anton deleted the Sorokin-Anton/#164-ci-windows-tests branch December 1, 2022 12:01
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.

Setup CI to run tests on Windows
3 participants