Skip to content

Add PackageRegistryManager #3787

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 17 commits into from
Oct 7, 2021
Merged

Conversation

mattt
Copy link
Contributor

@mattt mattt commented Oct 4, 2021

A partial tree of #3640 containing additive changes that don't affect how dependencies are downloaded or resolved. This PR itself shouldn't affect the behavior of Swift Package Manager, and is intended to serve as a backstop should we need to rollback any changes related to package resolution.

Motivation:

Improve velocity of registry implementation and reduce risk of merging future changes.

Modifications:

  • Add RegistryManager and associated tests
  • Add SourceArchiver used by RegistryManager
  • Extract Registry from RegistryConfiguration
  • Add scopeAndName property to PackageIdentity
  • Raise error when dependency is declared using invalid package identifier
  • Rename identity to id in PackageDescription to match SE-0292

Result:

No changes.

@mattt
Copy link
Contributor Author

mattt commented Oct 4, 2021

@swift-ci Please smoke test

@mattt mattt added the ready Author believes the PR is ready to be merged & any feedback has been addressed label Oct 4, 2021
client.execute(request, progress: nil) { result in
switch result {
case .success(let response):
if response.statusCode == 200,
Copy link
Contributor

Choose a reason for hiding this comment

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

iirc one can configure the request with acceptable response codes to avoid such check, tho you do make other checks here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, if it were just the status check or a range of status codes, I would've gone with that. But it's less code overall to do it this way here.

}
}

private extension String {
Copy link
Contributor

Choose a reason for hiding this comment

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

move to Basics?

self.fileSystem = fileSystem
}

public func extract(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is some code in workspace that also does similar things (for binary artifacts). maybe we can reuse / converge on one implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's ZipArchiver in TSCUtility, which I based this type on: https://github.com/apple/swift-tools-support-core/blob/f9bbd6b80d67408021576adf6247e17c2e957d92/Sources/TSCUtility/Archiver.swift#L34

(Hence some of the callouts from copy-pasted code, like dispatching to the global queue)

I discuss the rationale for this type in the doc comments, but the main takeaway is that this is probably only useful for the registry. I'd also be interested in getting some more 👀 on this, especially from security folks.

As far as converging on a single implementation, there may be an opportunity to make the delegated system call and directory prefix stripping a configurable property. But at that point, I think you may as well have two separate implementations of the Archiver protocol.

Copy link
Contributor

@tomerd tomerd Oct 5, 2021

Choose a reason for hiding this comment

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

I discuss the rationale for this type in the doc comments, but the main takeaway is that this is probably only useful for the registry. I'd also be interested in getting some more 👀 on this, especially from security folks.

cc @andyp-apple and @robertlacroix

As far as converging on a single implementation, there may be an opportunity to make the delegated system call and directory prefix stripping a configurable property. But at that point, I think you may as well have two separate implementations of the Archiver protocol.

makes sense, we can revisit this later too

@tomerd tomerd self-assigned this Oct 4, 2021
@mattt mattt requested a review from tomerd October 4, 2021 22:15
@@ -571,6 +586,7 @@ public class SwiftTool {
sharedConfigurationDirectory: sharedConfigurationDirectory
),
mirrors: self.getMirrorsConfig(sharedConfigurationDirectory: sharedConfigurationDirectory).mirrors,
registries: try? self.getRegistriesConfig(sharedConfigurationDirectory: sharedConfigurationDirectory).configuration,
Copy link
Contributor

Choose a reason for hiding this comment

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

try? intentional? should it throw instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we throw here, package resolution would fail for anyone who doesn't have a .swiftpm/configuration/registries.json file, even if they only use URL-based dependencies. The check for valid registry configuration is pushed back to be done only when necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

in similar situation in SwiftTool we return nil when it okay for it to be missing. so how about changing self.getRegistriesConfig to return optional when configuration/registries.json does not exist, and throw if it exists but cant be loaded?

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 thing! Fixed by dd323fb.

And I was mistaken — doing try here shouldn't throw an error if the configuration file is missing. Instead, it should return an empty configuration object.

@tomerd
Copy link
Contributor

tomerd commented Oct 5, 2021

lgtm, couple of small things

@mattt

This comment has been minimized.

@mattt mattt requested a review from tomerd October 5, 2021 13:57
@mattt mattt force-pushed the package-registry-manager branch from bb59156 to 86d0a19 Compare October 5, 2021 18:59
@mattt

This comment has been minimized.

@mattt mattt force-pushed the package-registry-manager branch from 86d0a19 to fbf54f0 Compare October 5, 2021 19:19
@mattt

This comment has been minimized.

@mattt
Copy link
Contributor Author

mattt commented Oct 7, 2021

@swift-ci Please smoke test

@tomerd
Copy link
Contributor

tomerd commented Oct 7, 2021

@mattt seems like this is ready to go? do you want to squash and provide the commit message, or should I do best-effort while merging?

@mattt
Copy link
Contributor Author

mattt commented Oct 7, 2021

@tomerd Yeah, this is good to go. Thanks for your help on getting this ready. Feel free to squash and merge whenever you see the CI go ✅ .

@tomerd tomerd merged commit 9033d81 into swiftlang:main Oct 7, 2021
@mattt mattt deleted the package-registry-manager branch October 7, 2021 19:25
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.

3 participants