Skip to content

Commit 8329478

Browse files
committed
Add support for Swift 5
1 parent fcfb64a commit 8329478

15 files changed

+118
-61
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
os: osx
2-
osx_image: xcode10.2
2+
osx_image: xcode11.1
33
language: swift
44
branches:
55
only:

Package.resolved

+26-35
Original file line numberDiff line numberDiff line change
@@ -15,62 +15,62 @@
1515
"repositoryURL": "https://github.com/krzyzanowskim/CryptoSwift.git",
1616
"state": {
1717
"branch": null,
18-
"revision": "3a2acbb32ab68215ee1596ee6004da8e90c3721b",
19-
"version": "1.0.0"
18+
"revision": "90e5b7af823d869fa8dea5a3abc7d95b6cb04c8c",
19+
"version": "1.1.3"
2020
}
2121
},
2222
{
23-
"package": "Gzip",
24-
"repositoryURL": "https://github.com/1024jp/GzipSwift",
23+
"package": "CwlCatchException",
24+
"repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git",
2525
"state": {
2626
"branch": null,
27-
"revision": "eac1da34ec837f501b56d810bdf0fd68b3f91e19",
28-
"version": "4.1.0"
27+
"revision": "7cd2f8cacc4d22f21bc0b2309c3b18acf7957b66",
28+
"version": "1.2.0"
2929
}
3030
},
3131
{
32-
"package": "Nimble",
33-
"repositoryURL": "https://github.com/Quick/Nimble.git",
32+
"package": "CwlPreconditionTesting",
33+
"repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git",
3434
"state": {
3535
"branch": null,
36-
"revision": "f8657642dfdec9973efc79cc68bcef43a653a2bc",
37-
"version": "8.0.2"
36+
"revision": "c228db5d2ad1b01ebc84435e823e6cca4e3db98b",
37+
"version": "1.2.0"
3838
}
3939
},
4040
{
41-
"package": "Path.swift",
42-
"repositoryURL": "https://github.com/mxcl/Path.swift.git",
41+
"package": "Gzip",
42+
"repositoryURL": "https://github.com/1024jp/GzipSwift",
4343
"state": {
4444
"branch": null,
45-
"revision": "dac007e907a4f4c565cfdc55a9ce148a761a11d5",
46-
"version": "0.16.3"
45+
"revision": "ba0b6cb51cc6202f896e469b87d2889a46b10d1b",
46+
"version": "5.1.1"
4747
}
4848
},
4949
{
50-
"package": "PathKit",
51-
"repositoryURL": "https://github.com/kylef/PathKit.git",
50+
"package": "Nimble",
51+
"repositoryURL": "https://github.com/Quick/Nimble.git",
5252
"state": {
5353
"branch": null,
54-
"revision": "e2f5be30e4c8f531c9c1e8765aa7b71c0a45d7a0",
55-
"version": "0.9.2"
54+
"revision": "6abeb3f5c03beba2b9e4dbe20886e773b5b629b6",
55+
"version": "8.0.4"
5656
}
5757
},
5858
{
59-
"package": "Quick",
60-
"repositoryURL": "https://github.com/Quick/Quick.git",
59+
"package": "PathKit",
60+
"repositoryURL": "https://github.com/kylef/PathKit.git",
6161
"state": {
6262
"branch": null,
63-
"revision": "94df9b449508344667e5afc7e80f8bcbff1e4c37",
64-
"version": "2.1.0"
63+
"revision": "73f8e9dca9b7a3078cb79128217dc8f2e585a511",
64+
"version": "1.0.0"
6565
}
6666
},
6767
{
68-
"package": "Result",
69-
"repositoryURL": "https://github.com/antitypical/Result.git",
68+
"package": "Quick",
69+
"repositoryURL": "https://github.com/Quick/Quick.git",
7070
"state": {
7171
"branch": null,
72-
"revision": "12920a5c2595926efab9274d6003e29f503dbb66",
73-
"version": "5.0.0"
72+
"revision": "33682c2f6230c60614861dfc61df267e11a1602f",
73+
"version": "2.2.0"
7474
}
7575
},
7676
{
@@ -81,15 +81,6 @@
8181
"revision": "f14ff47f45642aa5703900980b014c2e9394b6e5",
8282
"version": "0.9.0"
8383
}
84-
},
85-
{
86-
"package": "Stencil",
87-
"repositoryURL": "https://github.com/stencilproject/Stencil.git",
88-
"state": {
89-
"branch": null,
90-
"revision": "0e9a78d6584e3812cd9c09494d5c7b483e8f533c",
91-
"version": "0.13.1"
92-
}
9384
}
9485
]
9586
},

Package.swift

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
// swift-tools-version:4.2
1+
// swift-tools-version:5.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
77
name: "XCLogParser",
8+
platforms: [.macOS(.v10_13)],
89
products: [
910
.executable(name: "xclogparser", targets: ["XCLogParserApp"]),
1011
.library(name: "XCLogParser", targets: ["XCLogParser"])
1112
],
1213
dependencies: [
13-
.package(url: "https://github.com/1024jp/GzipSwift", from: "4.0.4"),
14-
.package(url: "https://github.com/stencilproject/Stencil.git", from: "0.13.1"),
15-
.package(url: "https://github.com/Carthage/Commandant.git", from: "0.16.0"),
14+
.package(url: "https://github.com/1024jp/GzipSwift", from: "5.1.0"),
15+
.package(url: "https://github.com/Carthage/Commandant.git", from: "0.17.0"),
1616
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.0.0"),
17-
.package(url: "https://github.com/mxcl/Path.swift.git", from: "0.13.0"),
18-
.package(url: "https://github.com/antitypical/Result.git", from: "5.0.0"),
17+
.package(url: "https://github.com/kylef/PathKit.git", from: "1.0.0"),
1918
],
2019
targets: [
2120
.target(
@@ -24,11 +23,11 @@ let package = Package(
2423
),
2524
.target(
2625
name: "XCLogParser",
27-
dependencies: ["Gzip", "Stencil", "XcodeHasher", "Path"]
26+
dependencies: ["Gzip", "XcodeHasher", "PathKit"]
2827
),
2928
.target(
3029
name: "XCLogParserApp",
31-
dependencies: ["XCLogParser", "Commandant", "Result"]
30+
dependencies: ["XCLogParser", "Commandant"]
3231
),
3332
.testTarget(
3433
name: "XCLogParserTests",

[email protected]

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// swift-tools-version:4.2
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "XCLogParser",
8+
products: [
9+
.executable(name: "xclogparser", targets: ["XCLogParserApp"]),
10+
.library(name: "XCLogParser", targets: ["XCLogParser"])
11+
],
12+
dependencies: [
13+
.package(url: "https://github.com/1024jp/GzipSwift", from: "4.1.0"),
14+
.package(url: "https://github.com/Carthage/Commandant.git", from: "0.16.0"),
15+
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "0.15.0"),
16+
.package(url: "https://github.com/kylef/PathKit.git", from: "1.0.0"),
17+
.package(url: "https://github.com/antitypical/Result.git", from: "4.0.0"),
18+
],
19+
targets: [
20+
.target(
21+
name:"XcodeHasher",
22+
dependencies: ["CryptoSwift"]
23+
),
24+
.target(
25+
name: "XCLogParser",
26+
dependencies: ["Gzip", "XcodeHasher", "PathKit"]
27+
),
28+
.target(
29+
name: "XCLogParserApp",
30+
dependencies: ["XCLogParser", "Commandant", "Result"]
31+
),
32+
.testTarget(
33+
name: "XCLogParserTests",
34+
dependencies: ["XCLogParser"]
35+
),
36+
]
37+
38+
)

Sources/XCLogParser/lexer/Lexer.swift

+11-2
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,13 @@ public final class Lexer {
165165
print("error parsing string")
166166
return nil
167167
}
168-
168+
#if swift(>=5.0)
169+
let start = String.Index(utf16Offset: scanner.scanLocation, in: scanner.string)
170+
let end = String.Index(utf16Offset: scanner.scanLocation + value, in: scanner.string)
171+
#else
169172
let start = String.Index(encodedOffset: scanner.scanLocation)
170173
let end = String.Index(encodedOffset: scanner.scanLocation + value)
174+
#endif
171175
scanner.scanLocation += value
172176
if redacted {
173177
return redactUserDir(string: String(scanner.string[start..<end]))
@@ -198,9 +202,14 @@ public final class Lexer {
198202

199203
extension Scanner {
200204
var approximateLine: String {
201-
let start = String.Index(encodedOffset: scanLocation)
202205
let endCount = string.count - scanLocation > 21 ? scanLocation + 21 : string.count - scanLocation
206+
#if swift(>=5.0)
207+
let start = String.Index(utf16Offset: scanLocation, in: self.string)
208+
let end = String.Index(utf16Offset: endCount, in: self.string)
209+
#else
210+
let start = String.Index(encodedOffset: scanLocation)
203211
let end = String.Index(encodedOffset: endCount)
212+
#endif
204213
if end <= start {
205214
return String(string[start..<string.endIndex])
206215
}

Sources/XCLogParser/output/FileOutput.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
// under the License.
1919

2020
import Foundation
21-
import Path
21+
import PathKit
2222

2323
public final class FileOutput: ReporterOutput {
2424

2525
let path: String
2626

2727
public init(path: String) {
28-
let absolutePath = Path(path) ?? Path.cwd/path
28+
let absolutePath = Path(path).absolute()
2929
self.path = absolutePath.string
3030
}
3131

Sources/XCLogParser/parser/SwiftFunctionTimesParser.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public class SwiftFunctionTimesParser {
120120
}
121121

122122
private func parseFunctionLocation(_ function: String) -> (String, String)? {
123-
guard let colonIndex = function.index(of: ":") else {
123+
guard let colonIndex = function.firstIndex(of: ":") else {
124124
return nil
125125
}
126126
let functionName = function[..<colonIndex]
@@ -131,7 +131,7 @@ public class SwiftFunctionTimesParser {
131131
}
132132

133133
private func parseLocation(_ location: String) -> (Int, Int)? {
134-
guard let colonIndex = location.index(of: ":") else {
134+
guard let colonIndex = location.firstIndex(of: ":") else {
135135
return nil
136136
}
137137
let line = location[..<colonIndex]

Sources/XCLogParser/reporter/HtmlReporter.swift

+7-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
// under the License.
1919

2020
import Foundation
21-
import Stencil
2221

2322
/// Reporter that creates an HTML report.
2423
/// It uses the html and javascript files from the Resources folder as templates
@@ -34,10 +33,10 @@ public struct HtmlReporter: LogReporter {
3433
guard let jsonString = String(data: json, encoding: .utf8) else {
3534
throw XCLogParserError.errorCreatingReport("Can't generate the JSON file.")
3635
}
37-
try writeHtmlReport(for: steps, context: ["build": jsonString], output: output)
36+
try writeHtmlReport(for: steps, jsonString: jsonString, output: output)
3837
}
3938

40-
private func writeHtmlReport(for build: BuildStep, context: [String: String], output: ReporterOutput) throws {
39+
private func writeHtmlReport(for build: BuildStep, jsonString: String, output: ReporterOutput) throws {
4140
var path = "build/xclogparser/reports"
4241
if let output = output as? FileOutput {
4342
path = output.path
@@ -57,9 +56,11 @@ public struct HtmlReporter: LogReporter {
5756
try HtmlReporterResources.indexHTML.write(toFile: "\(buildDir)/index.html", atomically: true, encoding: .utf8)
5857
try HtmlReporterResources.stepJS.write(toFile: "\(buildDir)/js/step.js", atomically: true, encoding: .utf8)
5958
try HtmlReporterResources.stepHTML.write(toFile: "\(buildDir)/step.html", atomically: true, encoding: .utf8)
60-
let template = Template(templateString: HtmlReporterResources.buildJS)
61-
let rendered = try template.render(context)
62-
try rendered.write(toFile: "\(buildDir)/js/build.js", atomically: true, encoding: .utf8)
59+
// let template = Template(templateString: HtmlReporterResources.buildJS)
60+
// let rendered = try template.render(context)
61+
let jsContent = HtmlReporterResources.buildJS.replacingOccurrences(of: "{{build}}", with: jsonString)
62+
try jsContent.write(toFile: "\(buildDir)/js/build.js", atomically: true, encoding: .utf8)
63+
// try rendered.write(toFile: "\(buildDir)/js/build.js", atomically: true, encoding: .utf8)
6364
print("Report written to \(buildDir)/index.html")
6465
}
6566

Sources/XCLogParserApp/commands/DumpCommand.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919

2020
import Foundation
2121
import Commandant
22-
import Result
2322
import XCLogParser
23+
#if !swift(>=5.0)
24+
import Result
25+
#endif
2426

2527
struct DumpCommand: CommandProtocol {
2628
typealias Options = DumpOptions

Sources/XCLogParserApp/commands/ManifestCommand.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919

2020
import Foundation
2121
import Commandant
22-
import Result
2322
import XCLogParser
23+
#if !swift(>=5.0)
24+
import Result
25+
#endif
2426

2527
struct ManifestCommand: CommandProtocol {
2628
typealias Options = ManifestOptions

Sources/XCLogParserApp/commands/ParseCommand.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919

2020
import Foundation
2121
import Commandant
22-
import Result
2322
import XCLogParser
23+
#if !swift(>=5.0)
24+
import Result
25+
#endif
2426

2527
struct ParseCommand: CommandProtocol {
2628
typealias Options = ParseOptions

Sources/XCLogParserApp/commands/VersionCommand.swift

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import Foundation
2121
import Commandant
2222
import XCLogParser
23+
#if !swift(>=5.0)
24+
import Result
25+
#endif
2326

2427
struct VersionCommand: CommandProtocol {
2528

Sources/XCLogParserApp/main.swift

+2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
import Foundation
2121
import Commandant
22+
#if !swift(>=5.0)
2223
import Result
24+
#endif
2325

2426
let registry = CommandRegistry<CommandantError<Swift.Error>>()
2527
registry.register(ParseCommand())

Sources/XcodeHasher/XcodeHasher.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,23 @@ public class XcodeHasher {
4343
guard let secondHalf = partitions.last else { throw HashingError.invalidPartitioning }
4444

4545
// We would need to reverse the bytes, so we just read them in big endian.
46+
#if swift(>=5.0)
47+
var startValue = UInt64(bigEndian: Data(firstHalf).withUnsafeBytes { $0.load(as: UInt64.self) })
48+
#else
4649
var startValue = UInt64(bigEndian: Data(firstHalf).withUnsafeBytes { $0.pointee })
50+
#endif
4751
for index in stride(from: 13, through: 0, by: -1) {
4852
// Take the startValue % 26 to restrict to alphabetic characters and add 'a' scalar value (97).
4953
let char = String(UnicodeScalar(Int(startValue % 26) + 97)!)
5054
result[index] = char
5155
startValue /= 26
5256
}
5357
// We would need to reverse the bytes, so we just read them in big endian.
54-
startValue = UInt64(bigEndian: Data(bytes: secondHalf).withUnsafeBytes { $0.pointee })
58+
#if swift(>=5.0)
59+
startValue = UInt64(bigEndian: Data(secondHalf).withUnsafeBytes { $0.load(as: UInt64.self) })
60+
#else
61+
startValue = UInt64(bigEndian: Data(secondHalf).withUnsafeBytes { $0.pointee })
62+
#endif
5563
for index in stride(from: 27, through: 14, by: -1) {
5664
// Take the startValue % 26 to restrict to alphabetic characters and add 'a' scalar value (97).
5765
let char = String(UnicodeScalar(Int(startValue % 26) + 97)!)

Tests/XCLogParserTests/LogFinderTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class LogFinderTests: XCTestCase {
7575
let projectFolder = try logFinder.getProjectFolderWithHash("/Users/user/projects/MyProject.xcworkspace")
7676
let logsFolder = projectFolder.appending("/Logs/Build")
7777
let projectLogFolder = derivedDataDir.appendingPathComponent(logsFolder, isDirectory: true)
78-
let url = try TestUtils.createSubdir(logsFolder, in: derivedDataDir)
78+
_ = try TestUtils.createSubdir(logsFolder, in: derivedDataDir)
7979
let now = Date()
8080
let olderDate = now.addingTimeInterval(-10)
8181
try TestUtils.createSubdir("anolder.xcactivitylog", in: projectLogFolder,

0 commit comments

Comments
 (0)