Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix -Wconf:src Windows path conversion#24772

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
mbland wants to merge1 commit intoscala:main
base:main
Choose a base branch
Loading
frommbland:issue/24771-wconf-src-fix-windows-path-conversion

Conversation

@mbland
Copy link

Updates the -Wconf:src filter to avoid usingjava.nio.file.Path.toURI in order to fix Windows source path conversions.

Path.toURI prepends the current working directory to Windows-like paths unconditionally, and converts backslashes in such paths to%5C escape sequences This can cause-Wconf:src filters that work on non-Windows platforms to fail on Windows.

For example, before this change, thePath.toURI conversion in theSourcePattern case fromMessageFilter.matches() produced:

original: Optional[C:\foo\bar\myfile.scala]resolved: /Users/mbland/src/scala/scala3/C:%5Cfoo%5Cbar%5Cmyfile.scala

After this change, it produces the following, which still prepends the current working directory, but properly converts path separators to/:

original: Optional[C:\foo\bar\myfile.scala]resolved: /Users/mbland/src/scala/scala3/C:/foo/bar/myfile.scala

This change is based onscala/scala#11192, and also adapts some test cases from that pull request to validate symlink and normalized path handling. This change also extracts thediagnosticWarning helper method to reduce duplication between new and existing test cases.

Fixes#24771. Review by@lrytz.

Gedochao reacted with thumbs up emoji
Updates the -Wconf:src filter to avoid using `java.nio.file.Path.toURI`in order to fix Windows source path conversions.`Path.toURI` prepends the current working directory to Windows-likepaths unconditionally, and converts backslashes in such paths to `%5C`escape sequences  This can cause `-Wconf:src` filters that work onnon-Windows platforms to fail on Windows.For example, before this change, the `Path.toURI` conversion in the`SourcePattern` case from `MessageFilter.matches()` produced:```txtoriginal: Optional[C:\foo\bar\myfile.scala]resolved: /Users/mbland/src/scala/scala3/C:%5Cfoo%5Cbar%5Cmyfile.scala```After this change, it produces the following, which still prepends thecurrent working directory, but properly converts path separators to `/`:```txtoriginal: Optional[C:\foo\bar\myfile.scala]resolved: /Users/mbland/src/scala/scala3/C:/foo/bar/myfile.scala```This change is based onscala/scala#11192, and also adapts some testcases from that pull request to validate symlink and normalized pathhandling. This change also extracts the `diagnosticWarning` helpermethod to reduce duplication between new and existing test cases.
@lrytz
Copy link
Member

After this change, it produces the following, which still prepends the current working directory, but properly converts path separators to/:

original: Optional[C:\foo\bar\myfile.scala]resolved: /Users/mbland/src/scala/scala3/C:/foo/bar/myfile.scala

After blowing the dust off my Windows VM, I can confirm this is platform dependent.

On Windows:

scala> java.io.File("C:\\foo\\..\\bar\\f.txt").toPath.toAbsolutePath.normalizevalres0: java.nio.file.Path=C:\bar\f.txtscala> java.io.File("C:\\foo\\..\\bar\\f.txt").toPath.toAbsolutePath.toUri.normalize.getRawPathvalres1:String=/C:/bar/f.txt

On macOS:

scala> java.io.File("C:\\foo\\..\\bar\\f.txt").toPath.toAbsolutePath.normalizevalres0: java.nio.file.Path=/Users/luc/code/scala/scala13/sandbox/C:\foo\..\bar\f.txtscala> java.io.File("C:\\foo\\..\\bar\\f.txt").toPath.toAbsolutePath.toUri.normalize.getRawPathvalres1:String=/Users/luc/code/scala/scala13/sandbox/C:%5Cfoo%5C..%5Cbar%5Cf.txt

So arguably the current implementation usingtoUri is also OK..?

@mbland
Copy link
Author

So arguably the current implementation using toUri is also OK..?

Hmm, arguably, yes. So if you want, I could:

  • Close this pull request outright (and maybe open a new one for Scala 2 that usestoURI and removes the Windows path assertions, to ensure parity between the implementations?)
  • Pare the changes down to only add the new tests (minus the Windows path test), which may be good to have
  • Keep the pull request as it is, to make the Scala 3 implementation closer to the implementation fromDon't resolve symlinks in -Wconf:src scala#11192

One other thing I noticed was that, unlike the Scala 2 implementation, thesrc filter doesn't automatically prepend/ to patterns to ensure they match an entire path component. For example, this currently fails:

@Testdef`Wconf src filter only matches entire directory path components`:Unit=valpath=Path("foobar/File.scala")valresult= wconfSrcFilterTest(      argsStr="-Wconf:src=bar/.*\\.scala:s",      warning= diagnosticWarning(util.SourceFile(newPlainFile(path),"UTF-8"))    )    assertEquals(result,Right(reporting.Action.Warning))

Note that the current tests reverse theexpected, actual ordering of theassertEquals parameters, so the assertion failure message reads backwards:

[error] Test dotty.tools.dotc.config.ScalaSettingsTests.Wconf src filter only matches entire directory path components failed:  java.lang.AssertionError: expected:<Right(Silent)> but was:<Right(Warning)>, took 0.001 sec[error]     at dotty.tools.dotc.config.ScalaSettingsTests.Wconf src filter only matches entire directory path components(ScalaSettingsTests.scala:308)

So the fourth option would be:

  • Repurpose this pull request so thatsrc path prefixes only match entire directory path components.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@som-snyttsom-snyttAwaiting requested review from som-snytt

@tgodziktgodzikAwaiting requested review from tgodzik

At least 1 approving review is required to merge this pull request.

Assignees

@tgodziktgodzik

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

-Wconf:src source path conversion to URI breaks Windows paths

3 participants

@mbland@lrytz@tgodzik

[8]ページ先頭

©2009-2025 Movatter.jp