-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Avoid realpath drive resolution to fix symlink-related test failures on Windows #68124
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
Closed
tristanlabelle
wants to merge
9
commits into
swiftlang:main
from
tristanlabelle:fix-symlink-test-failures-windows
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7d13da4
Remove realpath in lit site config.
tristanlabelle 5ced7eb
Fix symlink-related test failures on Windows.
tristanlabelle 7be6581
PR comments
tristanlabelle ed13aa3
Addressed PR comments
tristanlabelle 28bc3f0
Use ambient FileSystem instead of real one.
tristanlabelle a60f2e3
More PR feedback & path style param.
tristanlabelle 88a83c8
Switch to taking the FileSystem byref and more PR feedback
tristanlabelle 3fea9ee
Fix substitute drive check
tristanlabelle 83671a8
More thorough subst drive test
tristanlabelle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| //===--- SymbolicLinks.h ----------------------------------------*- C++ -*-===// | ||
| // | ||
| // This source file is part of the Swift.org open source project | ||
| // | ||
| // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors | ||
| // Licensed under Apache License v2.0 with Runtime Library Exception | ||
| // | ||
| // See https://swift.org/LICENSE.txt for license information | ||
| // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef SWIFT_BASIC_SYMBOLICLINKS_H | ||
| #define SWIFT_BASIC_SYMBOLICLINKS_H | ||
|
|
||
| #include "swift/Basic/LLVM.h" | ||
| #include "llvm/ADT/Optional.h" | ||
| #include "llvm/Support/Path.h" | ||
| #include "llvm/Support/VirtualFileSystem.h" | ||
| #include <string> | ||
| #include <optional> | ||
|
|
||
| namespace swift { | ||
|
|
||
| /// Tries to resolve symbolic links in a given path, but preserves | ||
| /// substitute drives on Windows to avoid MAX_PATH issues. | ||
| /// \param InputPath The path to be resolved. | ||
| /// \param FileSystem The FileSystem for resolving the path. | ||
| /// \param Style An optional path style to honor in the return value. | ||
| /// \returns The resolved path, or the original path on failure. | ||
| std::string resolveSymbolicLinks(llvm::StringRef InputPath, | ||
| llvm::vfs::FileSystem &FileSystem, | ||
| llvm::Optional<llvm::sys::path::Style> Style = llvm::None); | ||
|
|
||
| } // namespace swift | ||
|
|
||
| #endif // SWIFT_BASIC_BLOTSETVECTOR_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| //===--- SymbolicLinks.cpp - Utility functions for resolving symlinks -----===// | ||
| // | ||
| // This source file is part of the Swift.org open source project | ||
| // | ||
| // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors | ||
| // Licensed under Apache License v2.0 with Runtime Library Exception | ||
| // | ||
| // See https://swift.org/LICENSE.txt for license information | ||
| // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "swift/Basic/SymbolicLinks.h" | ||
| #include "llvm/ADT/SmallVector.h" | ||
| #include "llvm/Support/Path.h" | ||
|
|
||
| using namespace llvm; | ||
|
|
||
| static std::error_code resolveSymbolicLinks( | ||
| StringRef InputPath, | ||
| llvm::vfs::FileSystem &FileSystem, | ||
| SmallVectorImpl<char> &Result) { | ||
|
|
||
| if (auto ErrorCode = FileSystem.getRealPath(InputPath, Result)) { | ||
| return ErrorCode; | ||
| } | ||
|
|
||
| if (!is_style_windows(llvm::sys::path::Style::native)) { | ||
| return std::error_code(); | ||
| } | ||
|
|
||
| // For Windows paths, make sure we didn't resolve across drives. | ||
| SmallString<128> AbsPathBuf = InputPath; | ||
| if (auto ErrorCode = FileSystem.makeAbsolute(AbsPathBuf)) { | ||
| // We can't guarantee that the real path preserves the drive | ||
| return ErrorCode; | ||
| } | ||
|
|
||
| if (llvm::sys::path::root_name(StringRef(Result.data(), Result.size())) == | ||
| llvm::sys::path::root_name(AbsPathBuf)) { | ||
| // Success, the real path preserves the drive | ||
| return std::error_code(); | ||
| } | ||
|
|
||
| // Fallback to using the absolute path. | ||
| // Simplifying /../ is semantically valid on Windows even in the | ||
| // presence of symbolic links. | ||
| llvm::sys::path::remove_dots(AbsPathBuf, /*remove_dot_dot=*/ true); | ||
| Result.assign(AbsPathBuf); | ||
| return std::error_code(); | ||
| } | ||
|
|
||
| std::string swift::resolveSymbolicLinks( | ||
| StringRef InputPath, | ||
| llvm::vfs::FileSystem &FileSystem, | ||
| llvm::Optional<llvm::sys::path::Style> Style) { | ||
|
|
||
| llvm::SmallString<128> OutputPathBuf; | ||
| if (::resolveSymbolicLinks(InputPath, FileSystem, OutputPathBuf)) { | ||
| // Error, fallback on input path | ||
| OutputPathBuf = InputPath; | ||
| } | ||
|
|
||
| if (Style) { | ||
| llvm::sys::path::native(OutputPathBuf, *Style); | ||
| } | ||
|
|
||
| return std::string(OutputPathBuf); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.