Skip to content

Commit 2ad3bf2

Browse files
committed
[Workspace] NFC: Handle loading of provided library managed dependencies directly
Instead of going through the ManifestLoader machinery and special cases in validator let's just produce mainfest directly.
1 parent bb7f9e7 commit 2ad3bf2

File tree

4 files changed

+55
-68
lines changed

4 files changed

+55
-68
lines changed

Sources/PackageLoading/ManifestLoader+Validation.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ public struct ManifestValidator {
3434

3535
/// Validate the provided manifest.
3636
public func validate() -> [Basics.Diagnostic] {
37-
// Provided library manifest is synthesized by the package manager.
38-
if case .providedLibrary = self.manifest.packageKind {
39-
return []
40-
}
41-
4237
var diagnostics = [Basics.Diagnostic]()
4338

4439
diagnostics += self.validateTargets()

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,6 @@ extension ManifestLoaderProtocol {
206206
completion: @escaping (Result<Manifest, Error>) -> Void
207207
) {
208208
do {
209-
if case .providedLibrary = packageKind {
210-
let manifest = try self.loadLibrary(
211-
fileSystem: fileSystem,
212-
packagePath: packagePath,
213-
packageKind: packageKind,
214-
packageIdentity: packageIdentity,
215-
packageLocation: packageLocation,
216-
packageVersion: packageVersion?.version
217-
)
218-
completion(.success(manifest))
219-
return
220-
}
221-
222209
// find the manifest path and parse it's tools-version
223210
let manifestPath = try ManifestLoader.findManifest(packagePath: packagePath, fileSystem: fileSystem, currentToolsVersion: currentToolsVersion)
224211
let manifestToolsVersion = try ToolsVersionParser.parse(manifestPath: manifestPath, fileSystem: fileSystem)
@@ -279,53 +266,6 @@ extension ManifestLoaderProtocol {
279266
)
280267
}
281268
}
282-
283-
private func loadLibrary(
284-
fileSystem: FileSystem,
285-
packagePath: AbsolutePath,
286-
packageKind: PackageReference.Kind,
287-
packageIdentity: PackageIdentity,
288-
packageLocation: String,
289-
packageVersion: Version?
290-
) throws -> Manifest {
291-
let names = try fileSystem.getDirectoryContents(packagePath).filter {
292-
$0.hasSuffix("swiftmodule")
293-
}.map {
294-
let components = $0.split(separator: ".")
295-
return String(components[0])
296-
}
297-
298-
let products: [ProductDescription] = try names.map {
299-
try .init(name: $0, type: .library(.automatic), targets: [$0])
300-
}
301-
302-
let targets: [TargetDescription] = try names.map {
303-
try .init(
304-
name: $0,
305-
path: packagePath.pathString,
306-
type: .providedLibrary
307-
)
308-
}
309-
310-
return .init(
311-
displayName: packageIdentity.description,
312-
path: packagePath.appending(component: "provided-libraries.json"),
313-
packageKind: packageKind,
314-
packageLocation: packageLocation,
315-
defaultLocalization: nil,
316-
platforms: [],
317-
version: packageVersion,
318-
revision: nil,
319-
toolsVersion: .v6_0,
320-
pkgConfig: nil,
321-
providers: nil,
322-
cLanguageStandard: nil,
323-
cxxLanguageStandard: nil,
324-
swiftLanguageVersions: nil,
325-
products: products,
326-
targets: targets
327-
)
328-
}
329269
}
330270

331271
// MARK: - ManifestLoader

Sources/PackageModel/Manifest/Manifest.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,3 +554,50 @@ extension Manifest: Encodable {
554554
try container.encode(self.packageKind, forKey: .packageKind)
555555
}
556556
}
557+
558+
extension Manifest {
559+
package static func forProvidedLibrary(
560+
fileSystem: FileSystem,
561+
package: PackageReference,
562+
libraryPath: AbsolutePath,
563+
version: Version
564+
) throws -> Manifest {
565+
let names = try fileSystem.getDirectoryContents(libraryPath).filter {
566+
$0.hasSuffix("swiftmodule")
567+
}.map {
568+
let components = $0.split(separator: ".")
569+
return String(components[0])
570+
}
571+
572+
let products: [ProductDescription] = try names.map {
573+
try .init(name: $0, type: .library(.automatic), targets: [$0])
574+
}
575+
576+
let targets: [TargetDescription] = try names.map {
577+
try .init(
578+
name: $0,
579+
path: libraryPath.pathString,
580+
type: .providedLibrary
581+
)
582+
}
583+
584+
return .init(
585+
displayName: package.identity.description,
586+
path: libraryPath.appending(component: "provided-library.json"),
587+
packageKind: package.kind,
588+
packageLocation: package.locationString,
589+
defaultLocalization: nil,
590+
platforms: [],
591+
version: version,
592+
revision: nil,
593+
toolsVersion: .v6_0,
594+
pkgConfig: nil,
595+
providers: nil,
596+
cLanguageStandard: nil,
597+
cxxLanguageStandard: nil,
598+
swiftLanguageVersions: nil,
599+
products: products,
600+
targets: targets
601+
)
602+
}
603+
}

Sources/Workspace/Workspace+Manifests.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,14 @@ extension Workspace {
659659
case .registryDownload(let downloadedVersion):
660660
packageKind = managedDependency.packageRef.kind
661661
packageVersion = downloadedVersion
662-
case .providedLibrary(_, let version):
663-
packageKind = managedDependency.packageRef.kind
664-
packageVersion = version
662+
case .providedLibrary(let path, let version):
663+
let manifest: Manifest? = try? .forProvidedLibrary(
664+
fileSystem: fileSystem,
665+
package: managedDependency.packageRef,
666+
libraryPath: path,
667+
version: version
668+
)
669+
return completion(manifest)
665670
case .custom(let availableVersion, _):
666671
packageKind = managedDependency.packageRef.kind
667672
packageVersion = availableVersion

0 commit comments

Comments
 (0)