-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Make add-dependency idempotent #8534
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
Make add-dependency idempotent #8534
Conversation
@swift-ci please test |
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.
praise: This looks good to me. Having these operations be idempotent will be a really good thing to have to make it easier for code that automates adding capabilities to your package where it may or may not already be there.
/// If the exact same dependency already exists, `false` is returned to indicate | ||
/// that no edits are needed. If a different dependency with the same id or url | ||
/// with different arguments exists, an error is thrown. | ||
private static func checkExistingDependency( |
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.
question: I know this is marked as a private function, but is there value is validate this function in isolation to ensure we can test all code paths to ensure the behaviour is as expected, as opposed to testing the implementation?
try await executeAddURLDependencyAndAssert( | ||
packagePath: path, | ||
initialManifest: manifest, | ||
url: "https://github.com/swiftlang/swift-syntax.git", |
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.
question: Does SwiftPM treat a package dependency of "https://github.com/swiftlang/swift-syntax.git"
the same as "https://github.com/swiftlang/swift-syntax"
? Is there value if documenting this specific case?
what about repositories that has the same name, but belong to different organizations/users?
@swift-ci test windows platform |
@swift-ci test |
If a manifest already contains the exact dependency is being added via a `add-dependency` call, don't add it twice. Instead, do nothing. This ensures we don't end up with an invalid manifest with two of the same dependencies in it. If a manifest contains a dependency with the supplied URL but a different version qualifier then throw an error explaining that the supplied dependency has already been added. Issue: swiftlang#8519
571350e
to
518c227
Compare
@swift-ci test |
@swift-ci please test windows |
@swift-ci test windows |
1 similar comment
@swift-ci test windows |
Motivation:
If the same dependency is added twice with different version specifiers the manifest is no longer valid. If the same dependency is added twice with the same version specifier it remains valid, but less maintainable.
Modifications:
If a manifest already contains the exact dependency and version that is being added via a
add-dependency
call, don't add it twice. Instead, do nothing.If a manifest contains a dependency with the supplied URL but a different version qualifier then throw an error explaining that the supplied dependency has already been added.
Result:
A manifest that continues to parse correctly.
Issue: #8519