Skip to content

Remove use of AbsolutePath.appending(RelativePath(_:)) #4237

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 2 commits into from
Mar 21, 2022

Conversation

compnerd
Copy link
Member

This replaces the use of AbsolutePath.appending(RelativePath(_:)) in
the code base in favour of AbsolutPath(_:relativeTo:). This form
allows us to compute the absolute path prior to the normalization of the
path which ensures that we can validate the path properly. This is
particular important to enable the use of relative paths on Windows
which cannot normalize at the parent path without a reference as there
may be substitutions which need to be applied.

[One line description of your change]

Motivation:

[Explain here the context, and why you're making that change. What is the problem you're trying to solve.]

Modifications:

[Describe the modifications you've done.]

Result:

[After your change, what will change.]

This replaces the use of `AbsolutePath.appending(RelativePath(_:))` in
the code base in favour of `AbsolutPath(_:relativeTo:)`.  This form
allows us to compute the absolute path prior to the normalization of the
path which ensures that we can validate the path properly.  This is
particular important to enable the use of relative paths on Windows
which cannot normalize at the parent path without a reference as there
may be substitutions which need to be applied.
@compnerd
Copy link
Member Author

@swift-ci please smoke test

@millenomi
Copy link
Contributor

cc @tomerd Without this patch, C targets with complex header requirements do not build as their header search path settings may not be able to look in directories outside the target's in the package.

@millenomi
Copy link
Contributor

(Or any equivalent fix that prevents the stripping of '../'s from a header search path C setting.)

compnerd added a commit to compnerd/swift-tools-support-core that referenced this pull request Mar 19, 2022
When constructing a path relative to a root, compose the final path
before canonicalization as the canonicalization may require lookups
in the base location.

We additionally pay a small penalty to convert the slashes to native
separators.  This is purely for aesthetic purposes, it ensures that the
path is computed initially rather than delayed until use.

This in conjunction with swiftlang/swift-package-manager#4237 enables the
use of header search paths in SPM which are based in other targets.
@tomerd
Copy link
Contributor

tomerd commented Mar 19, 2022

thanks for this fix @compnerd. could we construct a few test cases to make sure this works correctly? eg Fixture based ones that test it end-to-end?

@abertelrud and @neonichu wdyt?

@compnerd
Copy link
Member Author

I think that the current tests cover this. This is effectively a change that has no impact on anything, simply goes through a different codepath to spell the same thing. On Windows, this path can then be changed to gain the proper behaviour (see swiftlang/swift-tools-support-core#298).

@tomerd
Copy link
Contributor

tomerd commented Mar 19, 2022

@swift-ci please smoke test

Add a test case for the handling of cross-target header lookups which
would fail on Windows.
@compnerd
Copy link
Member Author

@swift-ci please smoke test

@tomerd
Copy link
Contributor

tomerd commented Mar 19, 2022

thanks for adding a test. this seems fine to me. would like to get @abertelrud and @neonichu thoughts

@tomerd
Copy link
Contributor

tomerd commented Mar 19, 2022

@swift-ci smoke test

@abertelrud
Copy link
Contributor

thanks for adding a test. this seems fine to me. would like to get @abertelrud and @neonichu thoughts

Sorry for the delay in responding here. Yes, this looks like the right fix. IIRC AbsolutePath(_:relativeTo:) was added later which could explain why this code wasn't already using it. It's great to have added the additional specific test case. Thanks @compnerd

tomerd pushed a commit to swiftlang/swift-tools-support-core that referenced this pull request Mar 21, 2022
When constructing a path relative to a root, compose the final path
before canonicalization as the canonicalization may require lookups
in the base location.

We additionally pay a small penalty to convert the slashes to native
separators.  This is purely for aesthetic purposes, it ensures that the
path is computed initially rather than delayed until use.

This in conjunction with swiftlang/swift-package-manager#4237 enables the
use of header search paths in SPM which are based in other targets.
@neonichu
Copy link
Contributor

neonichu commented Mar 21, 2022

We should probably also remove/deprecate AbsolutePath.appending(RelativePath(_:)) so that new uses won't creep in?

@compnerd
Copy link
Member Author

I think that is a good idea, that will be in TSC, I can try to get to that soon.

@compnerd compnerd merged commit d8d62ad into swiftlang:main Mar 21, 2022
@compnerd compnerd deleted the relative-paths branch March 21, 2022 16:56
compnerd added a commit to compnerd/swift-tools-support-core that referenced this pull request Mar 21, 2022
This deprecates the `AbsolutePath.appending(_:)` overload for
constructing an `AbsolutePath` by appending a `RelativePath`.  Users
should prefer `AbsolutePath(_:relativeTo:)`.

Addresses feedback from swiftlang/swift-package-manager#4237
elsh pushed a commit to swiftlang/swift-tools-support-core that referenced this pull request Mar 21, 2022
This deprecates the `AbsolutePath.appending(_:)` overload for
constructing an `AbsolutePath` by appending a `RelativePath`.  Users
should prefer `AbsolutePath(_:relativeTo:)`.

Addresses feedback from swiftlang/swift-package-manager#4237
abertelrud pushed a commit to swiftlang/swift-tools-support-core that referenced this pull request Apr 4, 2022
When constructing a path relative to a root, compose the final path
before canonicalization as the canonicalization may require lookups
in the base location.

We additionally pay a small penalty to convert the slashes to native
separators.  This is purely for aesthetic purposes, it ensures that the
path is computed initially rather than delayed until use.

This in conjunction with swiftlang/swift-package-manager#4237 enables the
use of header search paths in SPM which are based in other targets.
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.

5 participants