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

Replace Platform.IsMono with actual OS checks #356

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

rmunn
Copy link
Contributor

@rmunn rmunn commented Oct 29, 2024

Fix #355.

Some cases of Platform.IsMono are workarounds for bugs in older versions of mono. Those can probably be removed, but for safety's sake, we'll leave them alone for now.

Other cases are clearly trying to check the platform, to run Linux-only or Windows-only code. Those cases should be replaced by Platform.IsUnix or Platform.IsWindows as appropriate, because nearly everywhere that Chorus is being run on Linux these days, it's running under dotnet rather than mono, and the Platform.IsMono check returns false.


This change is Reviewable

Some cases of Platform.IsMono are workarounds for bugs in older versions
of mono. Those can probably be removed, but for safety's sake, we'll
leave them alone for now.

Other cases are clearly trying to check the platform, to run Linux-only
or Windows-only code. Those cases should be replaced by Platform.IsUnix
or Platform.IsWindows as appropriate, because nearly everywhere that
Chorus is being run on Linux these days, it's running under dotnet
rather than mono, and the Platform.IsMono check returns false.
@rmunn
Copy link
Contributor Author

rmunn commented Oct 29, 2024

@hahn-kev - This bug is "in the wild" in LfMerge. If LfMerge ever encounters a merge conflict between two .txt files, it will try to run Windows-only code and promptly error out, resulting in a Mercurial rollback because the merge conflict wasn't handled. Thankfully it's extremely unlikely that anyone will check .txt files into their FieldWorks project, let alone end up with a merge conflict in those files. However, I want to prioritize reviewing and merging this bugfix so that I can push a new LfMerge release that won't try to run Windows-only code.

Copy link

github-actions bot commented Oct 29, 2024

Test Results

       4 files  ±0     412 suites  ±0   2h 45m 51s ⏱️ +5s
   883 tests ±0     860 ✔️ ±0    23 💤 ±0  0 ±0 
4 040 runs  ±0  3 906 ✔️ ±0  134 💤 ±0  0 ±0 

Results for commit 4932740. ± Comparison against base commit a6a7041.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@hahn-kev hahn-kev 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, I'd rather not make any changes to RunProcess though, see comments

{
Process p = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
Copy link
Contributor

Choose a reason for hiding this comment

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

this startInfo isn't being used as far as I can tell

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that was leftover from an earlier attempt to solve the bug with quoting filenames with spaces. I'll remote it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 3b4f7d1.

quotedArgs.Add(arg);
}
}
p.StartInfo.Arguments = string.Join(" ", quotedArgs);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't love the idea of changing this, was there an issue with how it worked before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this code was not working, because the "test projéct" project has spaces in the filename and the quoting was incorrect. See https://github.com/sillsdev/chorus/actions/runs/11571890533/job/32210729290#step:7:4936 for an example of the errors that were happening: "ChorusMerge Error: Got error 2 diff3: extra operand '/tmp/hgmerge-ha1g3_90/one~other.txt'". That extra operand is because "test projéct", unquoted, was becoming two parameters, "test" and "projéct".

Furthermore, this failure was going unnoticed in the tests, because the test in question was expecting ChorusMerge to fail (due to an unresolvable merge conflict). But the diff3 code here was completely wrong, and so the ChorusMerge code these tests were supposed to test was never actually getting called.

}

protected static string SurroundWithQuotes(string path)
{
return "\"" + path + "\"";
}

public static string RunProcess(string filePath, string arguments)
public static string RunProcess(string filePath, string[] arguments)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a public API so it may be called from outside this project making this a breaking change, is it really required or can we just leave it as is.

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 can back the quoting code up to before the RunProcess call, I suppose. However, this is such an internal method that if anyone is calling it from outside, despite its being public, they're doing the wrong thing. This method really should be private. Note how it checks the exit code of the process of specific values and returns specific error messages (e.g. if the exit code is 2, then it throws an ApplicationException about merging text files). This is not a general-purpose method and should never be considered part of the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Commit 4932740 restores RunProcess to its original state and puts the quoting logic in the method that calls it.

@rmunn rmunn requested a review from hahn-kev November 5, 2024 08:42
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.

Fix occurrences of Platform.IsMono
2 participants