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 instead of custom model types #194

Merged
merged 8 commits into from
Jan 20, 2021
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
42 changes: 39 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@
"version": "1.1.3"
}
},
{
"package": "swift-driver",
"repositoryURL": "https://github.com/apple/swift-driver.git",
"state": {
"branch": "release/5.4",
"revision": "b71abc6384dcf3e765854e2b28b83c618d3726a6",
"version": null
}
},
{
"package": "llbuild",
"repositoryURL": "https://github.com/apple/swift-llbuild.git",
"state": {
"branch": "release/5.4",
"revision": "eb56a00ed9dfd62c2ce4ec86183ff0bc0afda997",
"version": null
}
},
{
"package": "swift-log",
"repositoryURL": "https://github.com/apple/swift-log.git",
Expand Down Expand Up @@ -145,13 +163,22 @@
"version": "1.9.1"
}
},
{
"package": "SwiftPM",
"repositoryURL": "https://github.com/apple/swift-package-manager.git",
"state": {
"branch": "release/5.4",
"revision": "9c96dd770834d4b02c680cbf63949fab75fb6cca",
"version": null
}
},
{
"package": "swift-tools-support-core",
"repositoryURL": "https://github.com/apple/swift-tools-support-core.git",
"state": {
"branch": null,
"revision": "243beea77d20db46647a3de4765c96e2c801c7c7",
"version": "0.1.12"
"branch": "release/5.4",
"revision": "bc7961701fd94104528b017e969f63ea40bdb22b",
"version": null
}
},
{
Expand Down Expand Up @@ -180,6 +207,15 @@
"revision": "2b06a70dfcfa76a2e5079f60e3ae911511f09db0",
"version": "2.1.2"
}
},
{
"package": "Yams",
"repositoryURL": "https://github.com/jpsim/Yams.git",
"state": {
"branch": null,
"revision": "9003d51672e516cc59297b7e96bff1dfdedcb4ea",
"version": "4.0.4"
}
}
]
},
Expand Down
12 changes: 7 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ let package = Package(
url: "https://github.com/apple/swift-argument-parser.git",
.upToNextMinor(from: "0.3.0")
),
.package(
name: "SwiftPM",
url: "https://github.com/apple/swift-package-manager.git",
.branch("release/5.4")
),
.package(
url: "https://github.com/apple/swift-tools-support-core.git",
.upToNextMinor(from: "0.1.10")
.branch("release/5.4")
),
.package(url: "https://github.com/OpenCombine/OpenCombine.git", from: "0.10.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.29.3"),
Expand Down Expand Up @@ -65,7 +70,6 @@ let package = Package(
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
.product(name: "Vapor", package: "vapor"),
"CartonHelpers",
openCombineProduct,
Expand All @@ -76,7 +80,7 @@ let package = Package(
name: "SwiftToolchain",
dependencies: [
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This product dependency needs to be preserved, otherwise it causes linking issues on CI.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's a difference in resolution between 5.2 and 5.3. Without removing these lines it doesn't resolve on 5.3, and the 5.3 test fails for other reasons.

Copy link
Collaborator

@MaxDesiatov MaxDesiatov Dec 26, 2020

Choose a reason for hiding this comment

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

Fair enough, shouldn't be a problem after #195 is merged, where we have to drop support for 5.2.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't have access to develop on 5.2 ATM and making guess PRs until it works is not great. I suggest we merge #195 and move on.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Uh, I forgot about this bit. I can test with 5.2 on my side.

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean moving forward, since our dependency graph is large and there are (undocumented?) differences between the versions, plus 5.3 is stable and we have 5.4 to worry about - it's a good time to cut the chord IMO.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, it's the lack of output redirection with WAMR that I'm worried about. I'll try to get that sorted soon and we'll merge #195 after that.

.product(name: "SwiftPMDataModel", package: "SwiftPM"),
"CartonHelpers",
openCombineProduct,
"WasmTransformer",
Expand All @@ -86,7 +90,6 @@ let package = Package(
name: "CartonHelpers",
dependencies: [
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
openCombineProduct,
"Splash",
]
Expand All @@ -107,7 +110,6 @@ let package = Package(
dependencies: [
"Carton",
"CartonHelpers",
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
),
Expand Down
10 changes: 7 additions & 3 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ let package = Package(
url: "https://github.com/apple/swift-argument-parser.git",
.upToNextMinor(from: "0.3.0")
),
.package(
name: "SwiftPM",
url: "https://github.com/apple/swift-package-manager.git",
.branch("release/5.4")
),
.package(
url: "https://github.com/apple/swift-tools-support-core.git",
.upToNextMinor(from: "0.1.10")
.branch("release/5.4")
),
.package(url: "https://github.com/OpenCombine/OpenCombine.git", from: "0.10.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.29.3"),
Expand Down Expand Up @@ -59,7 +64,6 @@ let package = Package(
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
.product(name: "Vapor", package: "vapor"),
"CartonHelpers",
"OpenCombine",
Expand All @@ -70,6 +74,7 @@ let package = Package(
name: "SwiftToolchain",
dependencies: [
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.product(name: "SwiftPMDataModel", package: "SwiftPM"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
"CartonHelpers",
"OpenCombine",
Expand All @@ -92,7 +97,6 @@ let package = Package(
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
"CartonHelpers",
]
),
Expand Down
13 changes: 7 additions & 6 deletions Sources/CartonCLI/Commands/Bundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ArgumentParser
import CartonHelpers
import CartonKit
import Crypto
import PackageModel
import SwiftToolchain
import TSCBasic
import WasmTransformer
Expand Down Expand Up @@ -105,7 +106,7 @@ struct Bundle: ParsableCommand {
buildDirectory: AbsolutePath,
bundleDirectory: AbsolutePath,
toolchain: Toolchain,
product: Product
product: ProductDescription
) throws {
// Rename the final binary to use a part of its hash to bust browsers and CDN caches.
let optimizedHash = try localFileSystem.readFileContents(optimizedPath).hexSHA256.prefix(16)
Expand Down Expand Up @@ -137,9 +138,9 @@ struct Bundle: ParsableCommand {
))
)

let package = try toolchain.package.get()
for target in package.targets where target.type == .regular && !target.resources.isEmpty {
let targetPath = package.resourcesPath(for: target)
let manifest = try toolchain.manifest.get()
for target in manifest.targets where target.type == .regular && !target.resources.isEmpty {
let targetPath = manifest.resourcesPath(for: target)
let resourcesPath = buildDirectory.appending(component: targetPath)
let targetDirectory = bundleDirectory.appending(component: targetPath)

Expand All @@ -154,13 +155,13 @@ struct Bundle: ParsableCommand {
swiftlint:disable:next line_length
https://forums.swift.org/t/pitch-ability-to-declare-executable-targets-in-swiftpm-manifests-to-support-main/41968
*/
let inferredMainTarget = package.targets.first {
let inferredMainTarget = manifest.targets.first {
product.targets.contains($0.name)
}

guard let mainTarget = inferredMainTarget else { return }

let targetPath = package.resourcesPath(for: mainTarget)
let targetPath = manifest.resourcesPath(for: mainTarget)
let resourcesPath = buildDirectory.appending(component: targetPath)
for file in try localFileSystem.traverseRecursively(resourcesPath) {
let targetPath = bundleDirectory.appending(component: file.basename)
Expand Down
7 changes: 5 additions & 2 deletions Sources/CartonCLI/Commands/Dev.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ struct Dev: ParsableCommand {
@Option(name: .shortAndLong, help: "Set the HTTP port the development server will run on.")
var port = 8080

@Option(name: .shortAndLong, help: "Set the location where the development server will run. Default is `127.0.0.1`.")
@Option(
name: .shortAndLong,
help: "Set the location where the development server will run. Default is `127.0.0.1`."
)
var host = "127.0.0.1"

@Flag(name: .long, help: "Skip automatically opening app in system browser.")
Expand Down Expand Up @@ -114,7 +117,7 @@ struct Dev: ParsableCommand {
host: host,
customIndexContent: HTML.readCustomIndexPage(at: customIndexPage, on: localFileSystem),
// swiftlint:disable:next force_try
package: try! toolchain.package.get(),
manifest: try! toolchain.manifest.get(),
product: inferredProduct,
entrypoint: Self.entrypoint
),
Expand Down
2 changes: 1 addition & 1 deletion Sources/CartonCLI/Commands/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct Test: ParsableCommand {
host: host,
customIndexContent: nil,
// swiftlint:disable:next force_try
package: try! toolchain.package.get(),
manifest: try! toolchain.manifest.get(),
product: nil,
entrypoint: Self.entrypoint
),
Expand Down
4 changes: 2 additions & 2 deletions Sources/CartonHelpers/Parsers/ChromeStackTrace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public extension StringProtocol {
var chromeStackTrace: [StackTraceItem] {
split(separator: "\n").dropFirst().compactMap {
if let webpackMatch = webpackRegex.matchGroups(in: String($0)).first,
let symbol = webpackMatch.first,
let location = webpackMatch.last
let symbol = webpackMatch.first,
let location = webpackMatch.last
{
return StackTraceItem(symbol: symbol, location: location, kind: .javaScript)
} else if
Expand Down
6 changes: 3 additions & 3 deletions Sources/CartonHelpers/Parsers/DiagnosticsParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ public struct DiagnosticsParser: ProcessOutputParser {
var groupedMessages = [[CustomDiagnostic]]()
for message in messages {
if let lastLineStr = groupedMessages.last?.last?.line,
let lastLine = Int(lastLineStr),
let line = Int(message.line),
lastLine == line - 1 || lastLine == line
let lastLine = Int(lastLineStr),
let line = Int(message.line),
lastLine == line - 1 || lastLine == line
{
groupedMessages[groupedMessages.count - 1].append(message)
} else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/CartonHelpers/Parsers/FirefoxStackTrace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public extension StringProtocol {
var firefoxStackTrace: [StackTraceItem] {
split(separator: "\n").compactMap {
if let webpackMatch = webpackRegex.matchGroups(in: String($0)).first,
let symbol = webpackMatch.first,
let location = webpackMatch.last
let symbol = webpackMatch.first,
let location = webpackMatch.last
{
return StackTraceItem(symbol: symbol, location: location, kind: .javaScript)
} else if
Expand Down
2 changes: 1 addition & 1 deletion Sources/CartonHelpers/Parsers/SafariStackTrace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public extension StringProtocol {
var safariStackTrace: [StackTraceItem] {
split(separator: "\n").compactMap {
if let wasmMatch = wasmRegex.matchGroups(in: String($0)).first,
let symbol = wasmMatch.first
let symbol = wasmMatch.first
{
return StackTraceItem(
symbol: demangle(symbol),
Expand Down
8 changes: 4 additions & 4 deletions Sources/CartonHelpers/Parsers/String+Regex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension StringProtocol {
func matches(regex: NSRegularExpression) -> String.SubSequence? {
let str = String(self)
guard let range = str.range(of: regex),
range.upperBound < str.endIndex
range.upperBound < str.endIndex
else { return nil }
return str[range.upperBound..<str.endIndex]
}
Expand All @@ -29,7 +29,7 @@ extension StringProtocol {
let str = String(self)
let range = NSRange(location: 0, length: utf16.count)
guard let match = regex.firstMatch(in: str, options: [], range: range),
let matchRange = Range(match.range, in: str)
let matchRange = Range(match.range, in: str)
else {
return nil
}
Expand All @@ -40,7 +40,7 @@ extension StringProtocol {
let str = String(self)
let range = NSRange(location: 0, length: utf16.count)
guard let matches = regex.matches(in: str, options: [], range: range).first,
let matchRange = Range(matches.range(withName: name), in: str)
let matchRange = Range(matches.range(withName: name), in: str)
else {
return nil
}
Expand All @@ -50,7 +50,7 @@ extension StringProtocol {
func match(of regex: NSRegularExpression, named name: String) -> String.SubSequence? {
let str = String(self)
guard let range = str.range(of: regex, named: name),
range.upperBound < str.endIndex && range.lowerBound >= str.startIndex
range.upperBound < str.endIndex && range.lowerBound >= str.startIndex
else { return nil }
return str[range]
}
Expand Down
34 changes: 17 additions & 17 deletions Sources/CartonHelpers/Parsers/TestsParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private extension StringProtocol {
_ labelB: TestsParser.Regex.Label
) -> (String.SubSequence, String.SubSequence)? {
guard let a = match(of: regex, named: labelA.rawValue),
let b = match(of: regex, named: labelB.rawValue)
let b = match(of: regex, named: labelB.rawValue)
else {
return nil
}
Expand Down Expand Up @@ -93,10 +93,10 @@ public struct TestsParser: ProcessOutputParser {

enum Assertion: String, CaseIterable {
case equal = "Equal",
greaterThan = "GreaterThan",
lessThan = "LessThan",
greaterThanOrEqual = "GreaterThanOrEqual",
lessThanOrEqual = "LessThanOrEqual"
greaterThan = "GreaterThan",
lessThan = "LessThan",
greaterThanOrEqual = "GreaterThanOrEqual",
lessThanOrEqual = "LessThanOrEqual"

var funcName: String {
"XCTAssert\(rawValue)"
Expand Down Expand Up @@ -178,20 +178,20 @@ public struct TestsParser: ProcessOutputParser {
if let suite = line.match(of: Regex.suiteStarted, labelled: .suite) {
suites.append(.init(name: suite, cases: []))
} else if let testCase = line.match(of: Regex.caseFinished, labelled: .testCase),
let suite = line.match(of: Regex.caseFinished, labelled: .suite),
let suiteIdx = suites.firstIndex(where: { $0.name == suite }),
let status = line.match(of: Regex.caseFinished, labelled: .status),
let duration = line.match(of: Regex.caseFinished, labelled: .duration)
let suite = line.match(of: Regex.caseFinished, labelled: .suite),
let suiteIdx = suites.firstIndex(where: { $0.name == suite }),
let status = line.match(of: Regex.caseFinished, labelled: .status),
let duration = line.match(of: Regex.caseFinished, labelled: .duration)
{
suites[suiteIdx].cases.append(
.init(name: testCase, passed: status == "passed", duration: duration, problems: [])
)
} else if let problem = line.matches(regex: Regex.problem),
let path = line.match(of: Regex.problem, labelled: .path),
let lineNum = line.match(of: Regex.problem, labelled: .line),
let status = line.match(of: Regex.problem, labelled: .status),
let suite = line.match(of: Regex.problem, labelled: .suite),
let testCase = line.match(of: Regex.problem, labelled: .testCase)
let path = line.match(of: Regex.problem, labelled: .path),
let lineNum = line.match(of: Regex.problem, labelled: .line),
let status = line.match(of: Regex.problem, labelled: .status),
let suite = line.match(of: Regex.problem, labelled: .suite),
let testCase = line.match(of: Regex.problem, labelled: .testCase)
{
let diag = DiagnosticsParser.CustomDiagnostic(
kind: DiagnosticsParser.CustomDiagnostic.Kind(rawValue: String(status)) ?? .note,
Expand All @@ -202,7 +202,7 @@ public struct TestsParser: ProcessOutputParser {
message: String(problem)
)
if let suiteIdx = suites.firstIndex(where: { $0.name == suite }),
let caseIdx = suites[suiteIdx].cases.firstIndex(where: { $0.name == testCase })
let caseIdx = suites[suiteIdx].cases.firstIndex(where: { $0.name == testCase })
{
suites[suiteIdx].cases[caseIdx].problems.append(diag)
} else {
Expand All @@ -212,7 +212,7 @@ public struct TestsParser: ProcessOutputParser {
}
for problem in unmappedProblems {
if let suiteIdx = suites.firstIndex(where: { $0.name == problem.suite }),
let caseIdx = suites[suiteIdx].cases.firstIndex(where: { $0.name == problem.testCase })
let caseIdx = suites[suiteIdx].cases.firstIndex(where: { $0.name == problem.testCase })
{
suites[suiteIdx].cases[caseIdx].problems.append(problem.problem)
}
Expand Down Expand Up @@ -269,7 +269,7 @@ public struct TestsParser: ProcessOutputParser {
}
// Get the line of code from the file and output it for context.
if let lineNum = Int(problem.line),
lineNum > 0
lineNum > 0
{
var fileContents: String?
if let fileBuf = fileBufs.first(where: { $0.path == problem.file })?.contents {
Expand Down
Loading