Skip to content

Implement update command #67

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 10 commits into from
Oct 26, 2023
Merged

Conversation

patrickfreed
Copy link
Contributor

@patrickfreed patrickfreed commented Sep 26, 2023

Closes #5

See the README or the --help output in Update.swift for information on the semantics of the command.

/// HTTPClient wrapper used for interfacing with various APIs and downloading things.
public class HTTP {
public class SwiftlyHTTPClient {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of swiftly's test's runtime is devoted to downloading toolchains, and so in an effort to reduce that, I introduced the ability to mock toolchain downloads. This allows the update tests to run quickly while still verifying that updating works. We can consider expanding the use of mocking to other tests to reduce how long they run for, though I do think there is value in having the install command tests be non-mocked.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add some comment above ToolchainDownloader detailing why it is needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@patrickfreed patrickfreed marked this pull request as ready for review October 2, 2023 01:27
/// HTTPClient wrapper used for interfacing with various APIs and downloading things.
public class HTTP {
public class SwiftlyHTTPClient {
private static let client = HTTPClientWrapper()
Copy link
Contributor

Choose a reason for hiding this comment

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

You create a new HTTPClient with every instance of SwiftlyHTTPClient. Perhaps HTTPClientWrapper should be a wrapper for a global instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's how it used to be, but it was changed to be this way so that tests could construct individual commands with their own mocked HTTP clients. The lifetime of a swiftly process is only a single command in actual usage, so having them per-command is essentially the same as a singleton in practice.

}

/// Use a toolchain. This method modifies and saves the input config.
internal static func execute(_ toolchain: ToolchainVersion, config: inout Config) async throws {
internal static func execute(_ toolchain: ToolchainVersion, _ config: inout Config) async throws {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason you removed the config label from all the execute functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The config variables being passed in were almost always named config themselves, so the call sites looked a little duplicative.


public var httpClient = SwiftlyHTTPClient()

private enum CodingKeys: String, CodingKey {
Copy link
Contributor

Choose a reason for hiding this comment

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

What are the coding keys 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.

Decodable is a requirement of AsyncParsableCommand, which Update implements through SwiftlyCommand. The HTTP client isn't something that's decoded from the user input though, so I needed to introduce the coding keys to inform the Swift compiler that it should be skipped when autogenerating the Decodable conformance.

release.major == oldRelease.major
&& release.minor == oldRelease.minor
&& release.patch > oldRelease.patch
private func fetchNewToolchain(_ bounds: UpdateParameters) async throws -> ToolchainVersion? {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we function header comments here and on other functions. Is this downloading the toolchain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. This just queries the API to see if there is a toolchain that meets the requirements (e.g. if we're trying to update 5.0.0 to the latest patch version, is there one? If so, return it). I renamed this to lookupNewToolchain to better reflect that.

}
}

enum UpdateParameters {
Copy link
Contributor

Choose a reason for hiding this comment

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

Again comments please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

/// HTTPClient wrapper used for interfacing with various APIs and downloading things.
public class HTTP {
public class SwiftlyHTTPClient {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add some comment above ToolchainDownloader detailing why it is needed

reportProgress: reportProgress
)
} else {
let fileHandle = try FileHandle(forWritingTo: URL(fileURLWithPath: destination))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this not implemented as a ToolchainDownloader

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No good reason in particular, updated to be.

Copy link
Contributor

@adam-fowler adam-fowler left a comment

Choose a reason for hiding this comment

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

I think we are good

@patrickfreed patrickfreed merged commit 32c2355 into swiftlang:main Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement update command on Linux
2 participants