Skip to content

Commit 4a33cc7

Browse files
authored
Add PackageIdentity to Workspace prebuilt delegate methods (#8740)
In order to associate what prebuilt artifact goes with what package, add the `PackageIdentity` as a parameter to the delegate methods for prebuilts on `WorkspaceDelegate`.
1 parent 5dc2e3c commit 4a33cc7

File tree

4 files changed

+61
-12
lines changed

4 files changed

+61
-12
lines changed

Sources/Commands/CommandWorkspaceDelegate.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ final class CommandWorkspaceDelegate: WorkspaceDelegate {
183183
}
184184

185185
/// The workspace has started downloading a binary artifact.
186-
func willDownloadPrebuilt(from url: String, fromCache: Bool) {
186+
func willDownloadPrebuilt(package: PackageIdentity, from url: String, fromCache: Bool) {
187187
if fromCache {
188188
self.outputHandler("Fetching package prebuilt \(url) from cache", false)
189189
} else {
@@ -193,6 +193,7 @@ final class CommandWorkspaceDelegate: WorkspaceDelegate {
193193

194194
/// The workspace has finished downloading a binary artifact.
195195
func didDownloadPrebuilt(
196+
package: PackageIdentity,
196197
from url: String,
197198
result: Result<(path: AbsolutePath, fromCache: Bool), Error>,
198199
duration: DispatchTimeInterval
@@ -209,7 +210,7 @@ final class CommandWorkspaceDelegate: WorkspaceDelegate {
209210
}
210211

211212
/// The workspace is downloading a binary artifact.
212-
func downloadingPrebuilt(from url: String, bytesDownloaded: Int64, totalBytesToDownload: Int64?) {
213+
func downloadingPrebuilt(package: PackageIdentity, from url: String, bytesDownloaded: Int64, totalBytesToDownload: Int64?) {
213214

214215
}
215216

Sources/Workspace/Workspace+Delegation.swift

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,25 @@ public protocol WorkspaceDelegate: AnyObject {
139139
func didDownloadAllBinaryArtifacts()
140140

141141
/// The workspace has started downloading a binary artifact.
142-
func willDownloadPrebuilt(from url: String, fromCache: Bool)
142+
func willDownloadPrebuilt(
143+
package: PackageIdentity,
144+
from url: String,
145+
fromCache: Bool
146+
)
143147
/// The workspace has finished downloading a binary artifact.
144148
func didDownloadPrebuilt(
149+
package: PackageIdentity,
145150
from url: String,
146151
result: Result<(path: AbsolutePath, fromCache: Bool), Error>,
147152
duration: DispatchTimeInterval
148153
)
149154
/// The workspace is downloading a binary artifact.
150-
func downloadingPrebuilt(from url: String, bytesDownloaded: Int64, totalBytesToDownload: Int64?)
155+
func downloadingPrebuilt(
156+
package: PackageIdentity,
157+
from url: String,
158+
bytesDownloaded: Int64,
159+
totalBytesToDownload: Int64?
160+
)
151161
/// The workspace finished downloading all binary artifacts.
152162
func didDownloadAllPrebuilts()
153163

@@ -444,20 +454,40 @@ struct WorkspacePrebuiltsManagerDelegate: Workspace.PrebuiltsManager.Delegate {
444454
self.workspaceDelegate = workspaceDelegate
445455
}
446456

447-
func willDownloadPrebuilt(from url: String, fromCache: Bool) {
448-
self.workspaceDelegate?.willDownloadPrebuilt(from: url, fromCache: fromCache)
457+
func willDownloadPrebuilt(
458+
for package: PackageIdentity,
459+
from url: String,
460+
fromCache: Bool
461+
) {
462+
self.workspaceDelegate?.willDownloadPrebuilt(
463+
package: package,
464+
from: url,
465+
fromCache: fromCache
466+
)
449467
}
450468

451469
func didDownloadPrebuilt(
470+
for package: PackageIdentity,
452471
from url: String,
453472
result: Result<(path: AbsolutePath, fromCache: Bool), Error>,
454473
duration: DispatchTimeInterval
455474
) {
456-
self.workspaceDelegate?.didDownloadPrebuilt(from: url, result: result, duration: duration)
475+
self.workspaceDelegate?.didDownloadPrebuilt(
476+
package: package,
477+
from: url,
478+
result: result,
479+
duration: duration
480+
)
457481
}
458482

459-
func downloadingPrebuilt(from url: String, bytesDownloaded: Int64, totalBytesToDownload: Int64?) {
483+
func downloadingPrebuilt(
484+
for package: PackageIdentity,
485+
from url: String,
486+
bytesDownloaded: Int64,
487+
totalBytesToDownload: Int64?
488+
) {
460489
self.workspaceDelegate?.downloadingPrebuilt(
490+
package: package,
461491
from: url,
462492
bytesDownloaded: bytesDownloaded,
463493
totalBytesToDownload: totalBytesToDownload

Sources/Workspace/Workspace+Prebuilts.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,21 @@ import struct TSCUtility.Version
2222
/// Delegate to notify clients about actions being performed by BinaryArtifactsDownloadsManage.
2323
public protocol PrebuiltsManagerDelegate {
2424
/// The workspace has started downloading a binary artifact.
25-
func willDownloadPrebuilt(from url: String, fromCache: Bool)
25+
func willDownloadPrebuilt(
26+
for package: PackageIdentity,
27+
from url: String,
28+
fromCache: Bool
29+
)
2630
/// The workspace has finished downloading a binary artifact.
2731
func didDownloadPrebuilt(
32+
for package: PackageIdentity,
2833
from url: String,
2934
result: Result<(path: AbsolutePath, fromCache: Bool), Error>,
3035
duration: DispatchTimeInterval
3136
)
3237
/// The workspace is downloading a binary artifact.
3338
func downloadingPrebuilt(
39+
for package: PackageIdentity,
3440
from url: String,
3541
bytesDownloaded: Int64,
3642
totalBytesToDownload: Int64?
@@ -446,8 +452,14 @@ extension Workspace {
446452
if artifactURL.scheme == "file" {
447453
let artifactPath = try AbsolutePath(validating: artifactURL.path)
448454
if fileSystem.exists(artifactPath) {
455+
self.delegate?.willDownloadPrebuilt(
456+
for: package.identity,
457+
from: artifactURL.absoluteString,
458+
fromCache: true
459+
)
449460
try fileSystem.copy(from: artifactPath, to: destination)
450461
self.delegate?.didDownloadPrebuilt(
462+
for: package.identity,
451463
from: artifactURL.absoluteString,
452464
result: .success((destination, false)),
453465
duration: fetchStart.distance(to: .now())
@@ -473,6 +485,7 @@ extension Workspace {
473485
request.options.validResponseCodes = [200]
474486

475487
self.delegate?.willDownloadPrebuilt(
488+
for: package.identity,
476489
from: artifactURL.absoluteString,
477490
fromCache: false
478491
)
@@ -481,6 +494,7 @@ extension Workspace {
481494
bytesDownloaded,
482495
totalBytesToDownload in
483496
self.delegate?.downloadingPrebuilt(
497+
for: package.identity,
484498
from: artifactURL.absoluteString,
485499
bytesDownloaded: bytesDownloaded,
486500
totalBytesToDownload: totalBytesToDownload
@@ -492,6 +506,7 @@ extension Workspace {
492506
underlyingError: error
493507
)
494508
self.delegate?.didDownloadPrebuilt(
509+
for: package.identity,
495510
from: artifactURL.absoluteString,
496511
result: .failure(error),
497512
duration: fetchStart.distance(to: .now())
@@ -505,6 +520,7 @@ extension Workspace {
505520
"Prebuilt artifact \(artifactFile) checksum mismatch"
506521
observabilityScope.emit(info: errorString)
507522
self.delegate?.didDownloadPrebuilt(
523+
for: package.identity,
508524
from: artifactURL.absoluteString,
509525
result: .failure(StringError(errorString)),
510526
duration: fetchStart.distance(to: .now())
@@ -513,6 +529,7 @@ extension Workspace {
513529
}
514530

515531
self.delegate?.didDownloadPrebuilt(
532+
for: package.identity,
516533
from: artifactURL.absoluteString,
517534
result: .success((destination, false)),
518535
duration: fetchStart.distance(to: .now())
@@ -592,7 +609,7 @@ extension Workspace {
592609
artifact: artifact,
593610
observabilityScope: observabilityScope
594611
)
595-
{
612+
{
596613
// Add to workspace state
597614
let managedPrebuilt = ManagedPrebuilt(
598615
identity: prebuilt.identity,

Sources/_InternalTestSupport/MockWorkspace.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,19 +1206,20 @@ public final class MockWorkspaceDelegate: WorkspaceDelegate {
12061206
// noop
12071207
}
12081208

1209-
public func willDownloadPrebuilt(from url: String, fromCache: Bool) {
1209+
public func willDownloadPrebuilt(package: PackageIdentity, from url: String, fromCache: Bool) {
12101210
self.append("downloading package prebuilt: \(url)")
12111211
}
12121212

12131213
public func didDownloadPrebuilt(
1214+
package: PackageIdentity,
12141215
from url: String,
12151216
result: Result<(path: AbsolutePath, fromCache: Bool), Error>,
12161217
duration: DispatchTimeInterval
12171218
) {
12181219
self.append("finished downloading package prebuilt: \(url)")
12191220
}
12201221

1221-
public func downloadingPrebuilt(from url: String, bytesDownloaded: Int64, totalBytesToDownload: Int64?) {
1222+
public func downloadingPrebuilt(package: PackageIdentity, from url: String, bytesDownloaded: Int64, totalBytesToDownload: Int64?) {
12221223
// noop
12231224
}
12241225

0 commit comments

Comments
 (0)