-
Notifications
You must be signed in to change notification settings - Fork 1.4k
refactor location abstractions #3764
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ import TSCUtility | |
/// | ||
/// This class represent packages that are referenced locally in the file system. | ||
/// There is no need to perform any git operations on such packages and they | ||
/// should be used as-is. Infact, they might not even have a git repository. | ||
/// should be used as-is. In fact, they might not even have a git repository. | ||
/// Examples: Root packages, local dependencies, edited packages. | ||
public final class LocalPackageContainer: PackageContainer { | ||
public let package: PackageReference | ||
|
@@ -30,27 +30,35 @@ public final class LocalPackageContainer: PackageContainer { | |
private let toolsVersionLoader: ToolsVersionLoaderProtocol | ||
private let currentToolsVersion: ToolsVersion | ||
|
||
/// The file system that shoud be used to load this package. | ||
/// The file system that should be used to load this package. | ||
private let fileSystem: FileSystem | ||
|
||
/// cached version of the manifest | ||
private let manifest = ThreadSafeBox<Manifest>() | ||
|
||
private func loadManifest() throws -> Manifest { | ||
try manifest.memoize() { | ||
let path: AbsolutePath | ||
switch self.package.kind { | ||
case .root(let _path), .fileSystem(let _path): | ||
path = _path | ||
default: | ||
throw InternalError("invalid package type \(package.kind)") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add the package identity to the message here (or is it perhaps already part of the metadata?). That would make it much easier to try to figure out errors coming in from the field that have this message. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure. this is an internal error so a programmer error and not user one, so less important IMO |
||
} | ||
|
||
// Load the tools version. | ||
let toolsVersion = try self.toolsVersionLoader.load(at: AbsolutePath(self.package.location), fileSystem: self.fileSystem) | ||
let toolsVersion = try self.toolsVersionLoader.load(at: path, fileSystem: self.fileSystem) | ||
|
||
// Validate the tools version. | ||
try toolsVersion.validateToolsVersion(self.currentToolsVersion, packageIdentity: self.package.identity) | ||
|
||
// Load the manifest. | ||
// FIXME: this should not block | ||
return try temp_await { | ||
manifestLoader.load(at: AbsolutePath(self.package.location), | ||
manifestLoader.load(at: path, | ||
packageIdentity: self.package.identity, | ||
packageKind: self.package.kind, | ||
packageLocation: self.package.location, | ||
packageLocation: path.pathString, | ||
version: nil, | ||
revision: nil, | ||
toolsVersion: toolsVersion, | ||
|
@@ -80,8 +88,14 @@ public final class LocalPackageContainer: PackageContainer { | |
toolsVersionLoader: ToolsVersionLoaderProtocol, | ||
currentToolsVersion: ToolsVersion, | ||
fileSystem: FileSystem = localFileSystem | ||
) { | ||
assert(URL.scheme(package.location) == nil, "unexpected scheme \(URL.scheme(package.location)!) in \(package.location)") | ||
) throws { | ||
//assert(URL.scheme(package.location) == nil, "unexpected scheme \(URL.scheme(package.location)!) in \(package.location)") | ||
switch package.kind { | ||
case .root, .fileSystem: | ||
break | ||
default: | ||
throw InternalError("invalid package type \(package.kind)") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as the other message. If it's already part of the context for whatever handler wraps this call, so it will show up as metadata for a diagnostic, then that's even better. |
||
} | ||
self.package = package | ||
self.identityResolver = identityResolver | ||
self.manifestLoader = manifestLoader | ||
|
@@ -117,6 +131,6 @@ public final class LocalPackageContainer: PackageContainer { | |
|
||
extension LocalPackageContainer: CustomStringConvertible { | ||
public var description: String { | ||
return "LocalPackageContainer(\(package.location))" | ||
return "LocalPackageContainer(\(self.package.identity))" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do a follow-on to separate out the described location similarly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we could, less critical at this point imo
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, absolutely less critical.