Skip to content
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

Use libSwiftPM 5.6 to parse manifests #302

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
"repositoryURL": "https://github.com/apple/swift-argument-parser.git",
"state": {
"branch": null,
"revision": "83b23d940471b313427da226196661856f6ba3e0",
"version": "0.4.4"
"revision": "e394bf350e38cb100b6bc4172834770ede1b7232",
"version": "1.0.3"
}
},
{
Expand All @@ -78,25 +78,25 @@
"repositoryURL": "https://github.com/apple/swift-crypto.git",
"state": {
"branch": null,
"revision": "ddb07e896a2a8af79512543b1c7eb9797f8898a5",
"version": "1.1.7"
"revision": "3bea268b223651c4ab7b7b9ad62ef9b2d4143eb6",
"version": "1.1.6"
}
},
{
"package": "swift-driver",
"repositoryURL": "https://github.com/apple/swift-driver.git",
"state": {
"branch": "release/5.5",
"revision": "86c54dacd270e0c43374c0cb9b2ceb2924c9ea72",
"branch": "release/5.6",
"revision": "9982f32f96a2e0e597d1b4a0af4a7e997dc471be",
"version": null
}
},
{
"package": "llbuild",
"repositoryURL": "https://github.com/apple/swift-llbuild.git",
"state": {
"branch": "release/5.5",
"revision": "83c4bcb8dfca48cc065325287b55d08ff7b26428",
"branch": "release/5.6",
"revision": "acd686530e56122d916acd49a166beb9198e9b87",
"version": null
}
},
Expand Down Expand Up @@ -167,17 +167,17 @@
"package": "SwiftPM",
"repositoryURL": "https://github.com/apple/swift-package-manager.git",
"state": {
"branch": "release/5.5",
"revision": "a29154a4137747bdbfe83ca26db4b24f8c4fcd31",
"branch": "release/5.6",
"revision": "d53983abc7d1628a47ee26b24cbf35b06ac50f6e",
"version": null
}
},
{
"package": "swift-tools-support-core",
"repositoryURL": "https://github.com/apple/swift-tools-support-core.git",
"state": {
"branch": "release/5.5",
"revision": "3b586ce12865db205081acdcea79fe5509b28152",
"branch": "release/5.6",
"revision": "107e570e3565920174d5a25bc3a0340b32d16042",
"version": null
}
},
Expand Down
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription

let package = Package(
name: "carton",
platforms: [.macOS(.v10_15)],
platforms: [.macOS("10.15.4")],
products: [
.library(name: "SwiftToolchain", targets: ["SwiftToolchain"]),
.library(name: "CartonHelpers", targets: ["CartonHelpers"]),
Expand All @@ -21,17 +21,17 @@ let package = Package(
),
.package(
url: "https://github.com/apple/swift-argument-parser.git",
from: "0.4.3"
.upToNextMinor(from: "1.0.3")
),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.34.0"),
.package(
name: "SwiftPM",
url: "https://github.com/apple/swift-package-manager.git",
.branch("release/5.5")
.branch("release/5.6")
),
.package(
url: "https://github.com/apple/swift-tools-support-core.git",
.branch("release/5.5")
.branch("release/5.6")
),
.package(url: "https://github.com/vapor/vapor.git", from: "4.53.0"),
.package(url: "https://github.com/apple/swift-crypto.git", from: "1.1.0"),
Expand Down
2 changes: 1 addition & 1 deletion Sources/CartonHelpers/Parsers/DiagnosticsParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public struct DiagnosticsParser: ProcessOutputParser {
for (file, messages) in diagnostics.sorted(by: { $0.key < $1.key }) {
guard messages.count > 0 else { continue }
terminal.write("\(" \(file) ", color: "[1m", "[7m")") // bold, reversed
terminal.write(" \(messages.first!.file)\(messages.first!.line)\n\n", inColor: .grey)
terminal.write(" \(messages.first!.file)\(messages.first!.line)\n\n", inColor: .gray)
// Group messages that occur on sequential lines to provie a more readable output
var groupedMessages = [[CustomDiagnostic]]()
for message in messages {
Expand Down
4 changes: 2 additions & 2 deletions Sources/CartonKit/Server/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ extension Server {
terminal.write("\nAn error occurred, here's a stack trace for it:\n", inColor: .red)
stackTrace.forEach { item in
terminal.write(" \(item.symbol)", inColor: .cyan)
terminal.write(" at \(item.location ?? "<unknown>")\n", inColor: .grey)
terminal.write(" at \(item.location ?? "<unknown>")\n", inColor: .gray)
}
} else {
terminal.write("\nAn error occurred, here's the raw stack trace for it:\n", inColor: .red)
terminal.write(" Please create an issue or PR to the Carton repository\n" +
" with your browser name and this raw stack trace so\n" +
" we can add support for it: https://github.com/swiftwasm/carton\n", inColor: .grey)
" we can add support for it: https://github.com/swiftwasm/carton\n", inColor: .gray)
terminal.write(rawStackTrace + "\n")
}

Expand Down
118 changes: 28 additions & 90 deletions Sources/SwiftToolchain/Manifest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,44 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import Basics
import CartonHelpers
import Foundation
import PackageModel
import PackageLoading
import TSCBasic
import Workspace

extension Manifest {
static func from(swiftPath: AbsolutePath, terminal: InteractiveWriter) throws -> Manifest {
static func from(path: AbsolutePath, swiftc: AbsolutePath, fileSystem: FileSystem, terminal: InteractiveWriter) async throws -> Manifest {
terminal.write("\nParsing package manifest: ", inColor: .yellow)
terminal.write("\(swiftPath) package dump-package\n")
let output = try Data(processDataOutput([swiftPath.pathString, "package", "dump-package"]))
let decoder = JSONDecoder()
let unencodedValues = DumpedManifest.Unencoded(
path: swiftPath,
url: swiftPath.asURL.absoluteString,
version: nil
let toolchain = ToolchainConfiguration(swiftCompilerPath: swiftc)
let loader = ManifestLoader(toolchain: toolchain)
let observability = ObservabilitySystem { _, diagnostic in
terminal.write("\n\(diagnostic)")
}
let workspace = try Workspace(fileSystem: fileSystem, forRootPackage: path, customManifestLoader: loader)
let manifest = try await workspace.loadRootManifest(
at: path,
observabilityScope: observability.topScope
)
decoder.userInfo[DumpedManifest.unencodedKey] = unencodedValues
let dumpedManifest = try decoder.decode(DumpedManifest.self, from: output)
return dumpedManifest.manifest
return manifest
}

public func resourcesPath(for target: TargetDescription) -> String {
"\(name)_\(target.name).resources"
"\(displayName)_\(target.name).resources"
}
}

extension Workspace {
func loadRootManifest(
at path: AbsolutePath,
observabilityScope: ObservabilityScope
) async throws -> Manifest {
try await withCheckedThrowingContinuation { continuation in
loadRootManifest(at: path, observabilityScope: observabilityScope) { result in
continuation.resume(with: result)
}
}
}
}

Expand All @@ -45,80 +60,3 @@ public enum PackageType: String {
case systemModule = "system-module"
case manifest
}

// MARK: Custom Decodable Wrappers

/// A wrapper around `Manifest` needed for decoding from `dump-package` output,
/// since when encoding several (required for initialization) keys are skipped.
/// When decoding this wrapper, callers must provide an `unencodedKey` in the
/// decoder's `userInfo`.
struct DumpedManifest: Decodable {
var manifest: Manifest

static let unencodedKey = CodingUserInfoKey(rawValue: "unencoded")!

/// The skipped keys during `dump-package` encoding
struct Unencoded {
let path: AbsolutePath
let url: String
let version: Version?
}

private enum CodingKeys: CodingKey {
case name, toolsVersion,
pkgConfig, providers, cLanguageStandard, cxxLanguageStandard, swiftLanguageVersions,
dependencies, products, targets, platforms, packageKind, revision,
defaultLocalization
}

init(from decoder: Decoder) throws {
guard let unencoded = decoder.userInfo[DumpedManifest.unencodedKey] as? Unencoded else {
let context = DecodingError.Context(
codingPath: [],
debugDescription: "Unencoded values are missing from Decoder's userInfo"
)
throw DecodingError.dataCorrupted(context)
}

let container = try decoder.container(keyedBy: CodingKeys.self)
let name = try container.decode(String.self, forKey: .name)
let toolsVersion = try container.decode(ToolsVersion.self, forKey: .toolsVersion)
let pkgConfig = try container.decode(String?.self, forKey: .pkgConfig)
let providers = try container.decode(
[SystemPackageProviderDescription]?.self,
forKey: .providers
)
let cLanguageStandard = try container.decode(String?.self, forKey: .cLanguageStandard)
let cxxLanguageStandard = try container.decode(String?.self, forKey: .cxxLanguageStandard)
let swiftLanguageVersions = try container.decode(
[SwiftLanguageVersion]?.self,
forKey: .swiftLanguageVersions
)
let dependencies = try container.decode(
[PackageDependencyDescription].self,
forKey: .dependencies
)
let products = try container.decode([ProductDescription].self, forKey: .products)
let targets = try container.decode([TargetDescription].self, forKey: .targets)
let platforms = try container.decode([PlatformDescription].self, forKey: .platforms)
let packageKind = try container.decode(PackageReference.Kind.self, forKey: .packageKind)

manifest = Manifest(
name: name,
path: unencoded.path,
packageKind: packageKind,
packageLocation: unencoded.path.parentDirectory.pathString,
platforms: platforms,
version: unencoded.version,
toolsVersion: toolsVersion,
pkgConfig: pkgConfig,
providers: providers,
cLanguageStandard: cLanguageStandard,
cxxLanguageStandard: cxxLanguageStandard,
swiftLanguageVersions: swiftLanguageVersions,
dependencies: dependencies,
products: products,
targets: targets
)
}
}
Loading