Skip to content

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

Merged
merged 6 commits into from
Sep 28, 2021

Conversation

tomerd
Copy link
Contributor

@tomerd tomerd commented Sep 26, 2021

motivation: reduce dependency on string location information, in support of registry based dependencies

changes:

  • add location information to PackageReference::Kind
  • seperare out sourceControl dependencies to local and remote, where remote carries AbsolutePath and rmeote carries URL
  • adjust call sites
  • adjust tests and test utilities

rdar://82954076

@tomerd tomerd force-pushed the refactor/package-location-01 branch 5 times, most recently from c17e07d to d5cd15c Compare September 26, 2021 06:58
motivation: reduce dependency on string location information, in support of registry based dependencies

changes:
* add location information to PackageReference::Kind, using AbsolutePath and URL where appropriate
* seperate out sourceControl dependencies to local and remote, where remote carries AbsolutePath and rmeote carries URL
* add Location to RepositorySpecifier with local and remote, where remote carries AbsolutePath and rmeote carries URL
* expand IdentityResolver to resolve identity from PackageReference::Kind, AbsolutePath and URL
* adjust call sites (tons!)
* adjust tests and test utilities (tons!)

rdar://82954076
@tomerd tomerd force-pushed the refactor/package-location-01 branch from d5cd15c to 51fe9f9 Compare September 26, 2021 06:59
public enum Location: Equatable, Encodable {
case local(AbsolutePath)
case remote(Foundation.URL)
}
Copy link
Contributor Author

@tomerd tomerd Sep 26, 2021

Choose a reason for hiding this comment

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

👀 this new enum is another key change

case localSourceControl(AbsolutePath)

/// A remote source package.
case remoteSourceControl(Foundation.URL)
Copy link
Contributor Author

@tomerd tomerd Sep 26, 2021

Choose a reason for hiding this comment

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

👀 this enum change is the key change

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between fileSystem and localSourceControl? Do we do anything to ensure remoteSourceControl is indeed remote (e.g., what if URL scheme is file://?), or it doesn't matter?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, my plan is to further consolidate / cleanup after this initial but big PR lands.

return url.absoluteString
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👀 this new enum is another key change

@tomerd tomerd force-pushed the refactor/package-location-01 branch from 9943305 to de989b6 Compare September 26, 2021 08:14
@tomerd tomerd requested review from yim-lee and mattt September 26, 2021 08:15
@tomerd
Copy link
Contributor Author

tomerd commented Sep 26, 2021

@mattt this is the second PR designed to help with landing SE-0292, I think I prefer to take this one even before #3698

wdyt?

@tomerd tomerd self-assigned this Sep 26, 2021
@tomerd
Copy link
Contributor Author

tomerd commented Sep 26, 2021

@abertelrud @neonichu @elsh @yim-lee this PR includes refactoring we discussed several times with regards to how location is managed, and that is required to land SE-0292. its actually a pretty small change in the model itself but it has huge impact on call sites, especially in tests. given the large number of the lines changed, please focus on the core model changes which are highlighted in comments

note that this and #3698 are key PRs to help land SE-0292

@tomerd
Copy link
Contributor Author

tomerd commented Sep 26, 2021

@swift-ci please smoke test

@tomerd
Copy link
Contributor Author

tomerd commented Sep 26, 2021

@swift-ci please smoke test

if package.kind != .remote {
return queue.async {
let container = LocalPackageContainer(
if let repositorySpecifier = package.repositorySpecifier {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mattt here you would need to add a case for the registry, and probably we can rename RepositoryPackageContainerProvider to something more generic that deals with all PackageContainer types, perhaps rename to DefaultPackageContainerProvider

productFilter: .everything
)
} else {
throw StringError("invalid location: \(location)")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

with the new model, we can do things here much more safely

///
/// This could be a remote repository, local repository or local package.
public let location: String
// FIXME: we should not need this
//@available(*, deprecated)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

after landing this PR, there will be follow up to clean up call sites that still depend on location string. there are very few now, mostly for display so we are getting there

Copy link
Contributor

Choose a reason for hiding this comment

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

Great, this will do a lot to clarify the meaning of the code.

/// The URL of the repository.
public let url: String
// FIXME: transition url to location
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is for follow up PR

@@ -550,9 +550,19 @@ extension RepositoryManager.RepositoryHandle {
guard let status = Status(rawValue: repository.status) else {
throw StringError("unknown status :\(repository.status)")
}
// FIXME: encode the type
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is for follow up PR, its not too bad

}

/// Creates a package identity from a URL.
/// - Parameter url: The package's URL.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// - Parameter url: The package's URL.
/// - Parameter urlString: The package's URL.

case localSourceControl(AbsolutePath)

/// A remote source package.
case remoteSourceControl(Foundation.URL)
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between fileSystem and localSourceControl? Do we do anything to ensure remoteSourceControl is indeed remote (e.g., what if URL scheme is file://?), or it doesn't matter?

@tomerd
Copy link
Contributor Author

tomerd commented Sep 26, 2021

What's the difference between fileSystem and localSourceControl? Do we do anything to ensure remoteSourceControl is indeed remote (e.g., what if URL scheme is file://?), or it doesn't matter?

this is exactly one of the goals of this PR, fileSystem is a local dependency that is not necessarily a git repo, while localSourceControl must be a git repo. with this distinction the downstream code is much safe. we do not validate the prefix for URLs put into remoteSourceControl, that is a good idea to add

@tomerd
Copy link
Contributor Author

tomerd commented Sep 26, 2021

@swift-ci please smoke test

@tomerd
Copy link
Contributor Author

tomerd commented Sep 26, 2021

@swift-ci please test package compatibility

@mattt
Copy link
Contributor

mattt commented Sep 27, 2021

@mattt this is the second PR designed to help with landing SE-0292, I think I prefer to take this one even before #3698. wdyt?

If #3698 is ready to go, I think it'd be great to lock in our gains with that. But you're closer to the source material, so I defer to you on the best order of operations.

@tomerd tomerd added the ready Author believes the PR is ready to be merged & any feedback has been addressed label Sep 27, 2021
self = .sourceControl(identity: settings.identity, location: settings.location, requirement: settings.requirement)
switch settings.location {
case .local(let path):
self = .sourceControl(identity: settings.identity, location: path.pathString, requirement: settings.requirement)
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@abertelrud abertelrud Sep 28, 2021

Choose a reason for hiding this comment

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

Yes, absolutely less critical.

case .root(let _path), .fileSystem(let _path):
path = _path
default:
throw InternalError("invalid package type \(package.kind)")
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

case .root, .fileSystem:
break
default:
throw InternalError("invalid package type \(package.kind)")
Copy link
Contributor

Choose a reason for hiding this comment

The 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.


public enum Location: Equatable {
case local(AbsolutePath)
case remote(Foundation.URL)
Copy link
Contributor

Choose a reason for hiding this comment

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

In the past I think we had some issues with Foundation representing git@... URLs, at least on Darwin. I agree that using URL instead of String here makes more sense conceptually, but do we think there might be side effects? We should of course report them if there, but this might be something to watch for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this PR helps remove the logic that depends on checking if there is a scheme or not, and instead uses the type: localSourceControl vs remoteSourceControl, so ideally this should no longer be an issue regardless

Copy link
Contributor

@abertelrud abertelrud Sep 28, 2021

Choose a reason for hiding this comment

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

I see. Yes, if SwiftPM is no longer asking those same questions but mainly using the URL as a container of URL-formatted strings, then that might go better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes this is the goal - make the concrete location opaque to logic, so it only gets used when we pass it to git, where we use absoluteString to write out the full value

is there a specific use case you recall that we need to add a test for to make sure this works correctly in that sense?

@abertelrud abertelrud self-requested a review September 28, 2021 19:57
@tomerd tomerd merged commit 18c097d into swiftlang:main Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready Author believes the PR is ready to be merged & any feedback has been addressed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants