Skip to content

Commit 1e80c0a

Browse files
xedinfurby-tm
authored andcommitted
[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 22237e1 commit 1e80c0a

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

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)