Skip to content

Commit

Permalink
Merge pull request #35 from spotify/linux
Browse files Browse the repository at this point in the history
Add Linux and Swift 5 support
  • Loading branch information
ecamacho committed Oct 30, 2019
2 parents fcfb64a + d74ab6a commit f7cf3de
Show file tree
Hide file tree
Showing 24 changed files with 254 additions and 77 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Expand Up @@ -4,6 +4,7 @@ included:

excluded:
- Sources/XCLogParser/generated
- Tests/XCLogParserTests/XCTestManifests.swift

disabled_rules:
- trailing_comma
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,5 +1,5 @@
os: osx
osx_image: xcode10.2
osx_image: xcode11.1
language: swift
branches:
only:
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
@@ -0,0 +1,3 @@
FROM swift:5.1
RUN apt-get update && apt-get install -y zlib1g-dev
CMD cd xclogparser && swift build
61 changes: 26 additions & 35 deletions Package.resolved
Expand Up @@ -15,62 +15,62 @@
"repositoryURL": "https://github.com/krzyzanowskim/CryptoSwift.git",
"state": {
"branch": null,
"revision": "3a2acbb32ab68215ee1596ee6004da8e90c3721b",
"version": "1.0.0"
"revision": "90e5b7af823d869fa8dea5a3abc7d95b6cb04c8c",
"version": "1.1.3"
}
},
{
"package": "Gzip",
"repositoryURL": "https://github.com/1024jp/GzipSwift",
"package": "CwlCatchException",
"repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git",
"state": {
"branch": null,
"revision": "eac1da34ec837f501b56d810bdf0fd68b3f91e19",
"version": "4.1.0"
"revision": "7cd2f8cacc4d22f21bc0b2309c3b18acf7957b66",
"version": "1.2.0"
}
},
{
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git",
"package": "CwlPreconditionTesting",
"repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state": {
"branch": null,
"revision": "f8657642dfdec9973efc79cc68bcef43a653a2bc",
"version": "8.0.2"
"revision": "c228db5d2ad1b01ebc84435e823e6cca4e3db98b",
"version": "1.2.0"
}
},
{
"package": "Path.swift",
"repositoryURL": "https://github.com/mxcl/Path.swift.git",
"package": "Gzip",
"repositoryURL": "https://github.com/1024jp/GzipSwift",
"state": {
"branch": null,
"revision": "dac007e907a4f4c565cfdc55a9ce148a761a11d5",
"version": "0.16.3"
"revision": "ba0b6cb51cc6202f896e469b87d2889a46b10d1b",
"version": "5.1.1"
}
},
{
"package": "PathKit",
"repositoryURL": "https://github.com/kylef/PathKit.git",
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "e2f5be30e4c8f531c9c1e8765aa7b71c0a45d7a0",
"version": "0.9.2"
"revision": "6abeb3f5c03beba2b9e4dbe20886e773b5b629b6",
"version": "8.0.4"
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick.git",
"package": "PathKit",
"repositoryURL": "https://github.com/kylef/PathKit.git",
"state": {
"branch": null,
"revision": "94df9b449508344667e5afc7e80f8bcbff1e4c37",
"version": "2.1.0"
"revision": "73f8e9dca9b7a3078cb79128217dc8f2e585a511",
"version": "1.0.0"
}
},
{
"package": "Result",
"repositoryURL": "https://github.com/antitypical/Result.git",
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick.git",
"state": {
"branch": null,
"revision": "12920a5c2595926efab9274d6003e29f503dbb66",
"version": "5.0.0"
"revision": "33682c2f6230c60614861dfc61df267e11a1602f",
"version": "2.2.0"
}
},
{
Expand All @@ -81,15 +81,6 @@
"revision": "f14ff47f45642aa5703900980b014c2e9394b6e5",
"version": "0.9.0"
}
},
{
"package": "Stencil",
"repositoryURL": "https://github.com/stencilproject/Stencil.git",
"state": {
"branch": null,
"revision": "0e9a78d6584e3812cd9c09494d5c7b483e8f533c",
"version": "0.13.1"
}
}
]
},
Expand Down
15 changes: 7 additions & 8 deletions Package.swift
@@ -1,21 +1,20 @@
// swift-tools-version:4.2
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "XCLogParser",
platforms: [.macOS(.v10_13)],
products: [
.executable(name: "xclogparser", targets: ["XCLogParserApp"]),
.library(name: "XCLogParser", targets: ["XCLogParser"])
],
dependencies: [
.package(url: "https://github.com/1024jp/GzipSwift", from: "4.0.4"),
.package(url: "https://github.com/stencilproject/Stencil.git", from: "0.13.1"),
.package(url: "https://github.com/Carthage/Commandant.git", from: "0.16.0"),
.package(url: "https://github.com/1024jp/GzipSwift", from: "5.1.0"),
.package(url: "https://github.com/Carthage/Commandant.git", from: "0.17.0"),
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.0.0"),
.package(url: "https://github.com/mxcl/Path.swift.git", from: "0.13.0"),
.package(url: "https://github.com/antitypical/Result.git", from: "5.0.0"),
.package(url: "https://github.com/kylef/PathKit.git", from: "1.0.0"),
],
targets: [
.target(
Expand All @@ -24,11 +23,11 @@ let package = Package(
),
.target(
name: "XCLogParser",
dependencies: ["Gzip", "Stencil", "XcodeHasher", "Path"]
dependencies: ["Gzip", "XcodeHasher", "PathKit"]
),
.target(
name: "XCLogParserApp",
dependencies: ["XCLogParser", "Commandant", "Result"]
dependencies: ["XCLogParser", "Commandant"]
),
.testTarget(
name: "XCLogParserTests",
Expand Down
38 changes: 38 additions & 0 deletions Package@swift-4.2.swift
@@ -0,0 +1,38 @@
// swift-tools-version:4.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "XCLogParser",
products: [
.executable(name: "xclogparser", targets: ["XCLogParserApp"]),
.library(name: "XCLogParser", targets: ["XCLogParser"])
],
dependencies: [
.package(url: "https://github.com/1024jp/GzipSwift", from: "4.1.0"),
.package(url: "https://github.com/Carthage/Commandant.git", from: "0.16.0"),
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "0.15.0"),
.package(url: "https://github.com/kylef/PathKit.git", from: "1.0.0"),
.package(url: "https://github.com/antitypical/Result.git", from: "4.0.0"),
],
targets: [
.target(
name:"XcodeHasher",
dependencies: ["CryptoSwift"]
),
.target(
name: "XCLogParser",
dependencies: ["Gzip", "XcodeHasher", "PathKit"]
),
.target(
name: "XCLogParserApp",
dependencies: ["XCLogParser", "Commandant", "Result"]
),
.testTarget(
name: "XCLogParserTests",
dependencies: ["XCLogParser"]
),
]

)
11 changes: 9 additions & 2 deletions README.md
Expand Up @@ -406,22 +406,29 @@ xclogparser parse --file path/to/log.xcactivitylog --reporter html --output buil

| Environment | Version |
| ----------- |-------------|
| 🛠 Xcode | 10.2 |
| 🐦 Language | Swift 4.2 |
| 🛠 Xcode | 11.0 |
| 🐦 Language | Swift 5.0 |

## Status

XCLogParser is currently in alpha status. We are using it internally and tested it on various projects, but we need the help from the community to test and improve it with more iOS and Mac applications.

## Development and Contributing

MacOS:

1. Clone the repo with `git clone git@github.com:spotify/XCLogParser.git`.
2. Run `rake gen_resources` to generate a static resource Swift file that is needed to compile the app.
3. Run `swift package generate-xcodeproj` to generate an Xcode project (or use any text editor).
4. Run tests in Xcode directly (CMD + U) or using `rake test`.
5. Create issue and discuss a possible solution or improvement.
6. Create a PR.

Linux:

1. A Dockerfile is provided, you can create an image with the tag xlogparser: `docker build --tag xclogparser .`
2. To compile the app in Linux, just run the shell script: `./run-in-docker.sh`

If you find a bug or you would like to propose an improvement, you're welcome to create an [issue](https://github.com/spotify/xclogparser/issues/new).

## Code of Conduct
Expand Down
2 changes: 1 addition & 1 deletion Sources/XCLogParser/commands/Version.swift
Expand Up @@ -21,6 +21,6 @@ import Foundation

public struct Version {

public static let current = "0.1.5"
public static let current = "0.1.6"

}
25 changes: 23 additions & 2 deletions Sources/XCLogParser/lexer/Lexer.swift
Expand Up @@ -63,7 +63,11 @@ public final class Lexer {
}

private func scanSLFHeader(scanner: Scanner) -> Bool {
#if os(Linux)
var format: String?
#else
var format: NSString?
#endif
return scanner.scanString(Lexer.SLFHeader, into: &format)
}

Expand All @@ -83,7 +87,11 @@ public final class Lexer {

private func scanPayload(scanner: Scanner) -> String? {
var payload: String = ""
#if os(Linux)
var char: String?
#else
var char: NSString?
#endif
let hexChars = "abcdef0123456789"
while scanner.scanCharacters(from: CharacterSet(charactersIn: hexChars), into: &char),
let char = char as String? {
Expand All @@ -93,7 +101,11 @@ public final class Lexer {
}

private func scanTypeDelimiter(scanner: Scanner) -> [TokenType]? {
#if os(Linux)
var delimiters: String?
#else
var delimiters: NSString?
#endif
if scanner.scanCharacters(from: typeDelimiters, into: &delimiters), let delimiters = delimiters {
let delimiters = String(delimiters)
if delimiters.count > 1 {
Expand Down Expand Up @@ -165,9 +177,13 @@ public final class Lexer {
print("error parsing string")
return nil
}

#if swift(>=5.0)
let start = String.Index(utf16Offset: scanner.scanLocation, in: scanner.string)
let end = String.Index(utf16Offset: scanner.scanLocation + value, in: scanner.string)
#else
let start = String.Index(encodedOffset: scanner.scanLocation)
let end = String.Index(encodedOffset: scanner.scanLocation + value)
#endif
scanner.scanLocation += value
if redacted {
return redactUserDir(string: String(scanner.string[start..<end]))
Expand Down Expand Up @@ -198,9 +214,14 @@ public final class Lexer {

extension Scanner {
var approximateLine: String {
let start = String.Index(encodedOffset: scanLocation)
let endCount = string.count - scanLocation > 21 ? scanLocation + 21 : string.count - scanLocation
#if swift(>=5.0)
let start = String.Index(utf16Offset: scanLocation, in: self.string)
let end = String.Index(utf16Offset: endCount, in: self.string)
#else
let start = String.Index(encodedOffset: scanLocation)
let end = String.Index(encodedOffset: endCount)
#endif
if end <= start {
return String(string[start..<string.endIndex])
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/XCLogParser/lexer/LexerModel.swift
Expand Up @@ -30,7 +30,7 @@ public enum TokenType: String, CaseIterable {

static func all() -> String {
return TokenType.allCases.reduce(String()) {
return String(format: "%@%@", $0, $1.rawValue)
return "\($0)\($1.rawValue)"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/XCLogParser/output/FileOutput.swift
Expand Up @@ -18,14 +18,14 @@
// under the License.

import Foundation
import Path
import PathKit

public final class FileOutput: ReporterOutput {

let path: String

public init(path: String) {
let absolutePath = Path(path) ?? Path.cwd/path
let absolutePath = Path(path).absolute()
self.path = absolutePath.string
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/XCLogParser/parser/SwiftFunctionTimesParser.swift
Expand Up @@ -120,7 +120,7 @@ public class SwiftFunctionTimesParser {
}

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

private func parseLocation(_ location: String) -> (Int, Int)? {
guard let colonIndex = location.index(of: ":") else {
guard let colonIndex = location.firstIndex(of: ":") else {
return nil
}
let line = location[..<colonIndex]
Expand Down
10 changes: 4 additions & 6 deletions Sources/XCLogParser/reporter/HtmlReporter.swift
Expand Up @@ -18,7 +18,6 @@
// under the License.

import Foundation
import Stencil

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

private func writeHtmlReport(for build: BuildStep, context: [String: String], output: ReporterOutput) throws {
private func writeHtmlReport(for build: BuildStep, jsonString: String, output: ReporterOutput) throws {
var path = "build/xclogparser/reports"
if let output = output as? FileOutput {
path = output.path
Expand All @@ -57,9 +56,8 @@ public struct HtmlReporter: LogReporter {
try HtmlReporterResources.indexHTML.write(toFile: "\(buildDir)/index.html", atomically: true, encoding: .utf8)
try HtmlReporterResources.stepJS.write(toFile: "\(buildDir)/js/step.js", atomically: true, encoding: .utf8)
try HtmlReporterResources.stepHTML.write(toFile: "\(buildDir)/step.html", atomically: true, encoding: .utf8)
let template = Template(templateString: HtmlReporterResources.buildJS)
let rendered = try template.render(context)
try rendered.write(toFile: "\(buildDir)/js/build.js", atomically: true, encoding: .utf8)
let jsContent = HtmlReporterResources.buildJS.replacingOccurrences(of: "{{build}}", with: jsonString)
try jsContent.write(toFile: "\(buildDir)/js/build.js", atomically: true, encoding: .utf8)
print("Report written to \(buildDir)/index.html")
}

Expand Down
4 changes: 3 additions & 1 deletion Sources/XCLogParserApp/commands/DumpCommand.swift
Expand Up @@ -19,8 +19,10 @@

import Foundation
import Commandant
import Result
import XCLogParser
#if !swift(>=5.0)
import Result
#endif

struct DumpCommand: CommandProtocol {
typealias Options = DumpOptions
Expand Down

0 comments on commit f7cf3de

Please sign in to comment.