Skip to content

refactor RelativePath to allow late stage canonicalization in support of windows #369

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
merged 7 commits into from
Apr 17, 2023

Conversation

tomerd
Copy link
Contributor

@tomerd tomerd commented Nov 17, 2022

motivation: delay canonicalization of relative path to the construction of absolute path from it, to better fit how windows paths work

changes:

  • remove the canonicalizing, non-throwing initializer of relative path
  • for tests, conform RelativePath and AbsolutePath to ExpressibleByStringLiteral and ExpressibleByStringInterpolation to make it easier to pass in string and static strings
  • remove incorrect validation of ~ as invalid relative path
  • update call sites and test

@tomerd tomerd changed the title refactoring of relative path to allow late stage canonicalization in support of windows [wip] refactoring of relative path to allow late stage canonicalization in support of windows Nov 17, 2022
@tomerd
Copy link
Contributor Author

tomerd commented Nov 17, 2022

companion: swiftlang/swift-package-manager#5910

@tomerd tomerd force-pushed the refactor/relative-path branch 2 times, most recently from 024c262 to 78feb0a Compare April 13, 2023 21:04
@tomerd tomerd changed the title [wip] refactoring of relative path to allow late stage canonicalization in support of windows refactore of relative path to allow late stage canonicalization in support of windows Apr 13, 2023
@tomerd tomerd force-pushed the refactor/relative-path branch from 78feb0a to 8edc44e Compare April 13, 2023 22:14
@tomerd
Copy link
Contributor Author

tomerd commented Apr 13, 2023

testing via swiftlang/swift-package-manager#5910

@tomerd tomerd changed the title refactore of relative path to allow late stage canonicalization in support of windows refactor RelativePath to allow late stage canonicalization in support of windows Apr 14, 2023
@compnerd
Copy link
Member

Hmm, merging this locally seems to not build on Windows? :/

@compnerd
Copy link
Member

@swift-ci please test Windows platform

@compnerd
Copy link
Member

@tomerd did you forget part of the commit?

S:\SourceCache\swift-project\swift-tools-support-core\Sources\TSCBasic\Path.swift:524:14: error: no exact matches in call to initializer
        self.init(normalizingAbsolutePath: path)

There is no Windowspath(normalizingAbsolutePath:) that I can see.

@compnerd
Copy link
Member

@swift-ci please test Windows platform

@compnerd
Copy link
Member

This does seem to regress the test suite:

Test Case 'ManifestSourceGenerationTests.testAdvancedFeatures' started at 2023-04-14 09:37:04.984
TSCBasic/Path.swift:974: Assertion failed
Current stack trace:
0    (null)                             0x00007ffe873af220 swift_stdlib_reportFatalErrorInFile + 132

@@ -338,6 +321,8 @@ public struct RelativePath: Hashable, Sendable {
}
}



Copy link
Contributor

Choose a reason for hiding this comment

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

why

@tomerd tomerd requested a review from MaxDesiatov as a code owner April 17, 2023 18:13
@tomerd tomerd force-pushed the refactor/relative-path branch from 968d308 to e913e15 Compare April 17, 2023 18:15
@tomerd
Copy link
Contributor Author

tomerd commented Apr 17, 2023

tested via swiftlang/swift-package-manager#5910

@tomerd tomerd merged commit b2527eb into swiftlang:main Apr 17, 2023
kcieplak added a commit to kcieplak/swift-tools-support-core that referenced this pull request May 9, 2025
PR#369 - swiftlang#369
Caused the majority of tests on Windows to fail, as normalization of
RelativePath was removed. This change  also removed the call to
'PathAllocCanonicalize' for AbsolutePath which had the long file
flag 'PATHCCH_ALLOW_LONG_PATHS'.

Reintroducing canonicalization of AbsolutePath path representation
to handle long paths.

* Update tests dealing with RelativePath to match implementation.
* Canonicalize the path representation for AbsolutePath which also allows
  for long path '\\?\' prefix addition when path > 260 in length.
* Strip trailing backslash on string representation of AbsolutePath to match
  definition. Only strips for non root paths.
* Add helper functions:
  - removeTrailingBackslash
  - stripPrefix
  - canonicalPathRepresentation
* Add Windows API Error helpers
* Add long path tests into each test case
* Ran swift format on code
* Update copyright dates
kcieplak added a commit to kcieplak/swift-tools-support-core that referenced this pull request May 9, 2025
PR#369 - swiftlang#369
Caused the majority of tests on Windows to fail, as normalization of
RelativePath was removed. This change  also removed the call to
'PathAllocCanonicalize' for AbsolutePath which had the long file
flag 'PATHCCH_ALLOW_LONG_PATHS'.

Reintroducing canonicalization of AbsolutePath path representation
to handle long paths.

* Update tests dealing with RelativePath to match implementation.
* Canonicalize the path representation for AbsolutePath which also allows
  for long path '\\?\' prefix addition when path > 260 in length.
* Strip trailing backslash on string representation of AbsolutePath to match
  definition. Only strips for non root paths.
* Add helper functions:
  - removeTrailingBackslash
  - stripPrefix
  - canonicalPathRepresentation
* Add Windows API Error helpers
* Add long path tests into each test case
* Ran swift format on code
* Update copyright dates
kcieplak added a commit to kcieplak/swift-tools-support-core that referenced this pull request May 9, 2025
PR#369 - swiftlang#369
Caused the majority of tests on Windows to fail, as normalization of
RelativePath was removed. This change  also removed the call to
'PathAllocCanonicalize' for AbsolutePath which had the long file
flag 'PATHCCH_ALLOW_LONG_PATHS'.

Reintroducing canonicalization of AbsolutePath path representation
to handle long paths.

* Update tests dealing with RelativePath to match implementation.
* Canonicalize the path representation for AbsolutePath which also allows
  for long path '\\?\' prefix addition when path > 260 in length.
* Strip trailing backslash on string representation of AbsolutePath to match
  definition. Only strips for non root paths.
* Add helper functions:
  - removeTrailingBackslash
  - stripPrefix
  - canonicalPathRepresentation
* Add Windows API Error helpers
* Add long path tests into each test case
* Fix up .suffix. '.' has no suffix
* Update copyright dates
kcieplak added a commit to kcieplak/swift-tools-support-core that referenced this pull request May 9, 2025
PR#369 - swiftlang#369
Caused the majority of tests on Windows to fail, as normalization of
RelativePath was removed. This change  also removed the call to
'PathAllocCanonicalize' for AbsolutePath which had the long file
flag 'PATHCCH_ALLOW_LONG_PATHS'.

Reintroducing canonicalization of AbsolutePath path representation
to handle long paths.

* Update tests dealing with RelativePath to match implementation.
* Canonicalize the path representation for AbsolutePath which also allows
  for long path '\\?\' prefix addition when path > 260 in length.
* Strip trailing backslash on string representation of AbsolutePath to match
  definition. Only strips for non root paths.
* Add helper functions:
  - removeTrailingBackslash
  - stripPrefix
  - canonicalPathRepresentation
* Add Windows API Error helpers
* Add long path tests into each test case
* Fix up .suffix. '.' has no suffix
* Update copyright dates
kcieplak added a commit to kcieplak/swift-tools-support-core that referenced this pull request May 9, 2025
PR#369 - swiftlang#369
Caused the majority of tests on Windows to fail, as normalization of
RelativePath was removed. This change  also removed the call to
'PathAllocCanonicalize' for AbsolutePath which had the long file
flag 'PATHCCH_ALLOW_LONG_PATHS'.

Reintroducing canonicalization of AbsolutePath path representation
to handle long paths.

* Update tests dealing with RelativePath to match implementation.
* Canonicalize the path representation for AbsolutePath which also allows
  for long path '\\?\' prefix addition when path > 260 in length.
* Strip trailing backslash on string representation of AbsolutePath to match
  definition. Only strips for non root paths.
* Add helper functions:
  - removeTrailingBackslash
  - stripPrefix
  - canonicalPathRepresentation
* Add Windows API Error helpers
* Add long path tests into each test case
* Fix up .suffix. '.' has no suffix
* Update copyright dates
kcieplak added a commit to kcieplak/swift-tools-support-core that referenced this pull request May 9, 2025
PR#369 - swiftlang#369
Caused the majority of tests on Windows to fail, as normalization of
RelativePath was removed. This change  also removed the call to
'PathAllocCanonicalize' for AbsolutePath which had the long file
flag 'PATHCCH_ALLOW_LONG_PATHS'.

Reintroducing canonicalization of AbsolutePath path representation
to handle long paths.

* Update tests dealing with RelativePath to match implementation.
* Canonicalize the path representation for AbsolutePath which also allows
  for long path '\\?\' prefix addition when path > 260 in length.
* Strip trailing backslash on string representation of AbsolutePath to match
  definition. Only strips for non root paths.
* Add helper functions:
  - removeTrailingBackslash
  - stripPrefix
  - canonicalPathRepresentation
* Add Windows API Error helpers
* Add long path tests into each test case
* Fix up .suffix. '.' has no suffix
* Update copyright dates
bkhouri pushed a commit that referenced this pull request May 16, 2025
* Resolves #505 - Fix handling for Windows long paths

PR#369 - #369
Caused the majority of tests on Windows to fail, as normalization of
RelativePath was removed. This change  also removed the call to
'PathAllocCanonicalize' for AbsolutePath which had the long file
flag 'PATHCCH_ALLOW_LONG_PATHS'.

Reintroducing canonicalization of AbsolutePath path representation
to handle long paths.

* Update tests dealing with RelativePath to match implementation.
* Canonicalize the path representation for AbsolutePath which also allows
  for long path '\\?\' prefix addition when path > 260 in length.
* Strip trailing backslash on string representation of AbsolutePath to match
  definition. Only strips for non root paths.
* Add helper functions:
  - removeTrailingBackslash
  - stripPrefix
  - canonicalPathRepresentation
* Add Windows API Error helpers
* Add long path tests into each test case
* Fix up .suffix. '.' has no suffix
* Update copyright dates

* Make PathCchStripPrefix and PathCchRemoveBackslash use temporary buffer.

- Move PathCchStripPrefix and PathCchRemoveBackslash to use a
mutable temporary buffer.
    - Could not use buffer.withMemoryRebound and getCstring() as
      on Windows this seem to produce corrupt data.
- Add more tests for unParsed '\\?\' and device '\\.\' paths
- Remove the PATHCCH_CANONICALIZE_SLASHES flag as it is not
  needed.
- Add Win32Error.swift to CMakeLists
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.

4 participants