Skip to content

Commit 9bf0c80

Browse files
committed
Add support for Linux
1 parent 8329478 commit 9bf0c80

File tree

9 files changed

+137
-34
lines changed

9 files changed

+137
-34
lines changed

Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM swift:5.1
2+
RUN apt-get update && apt-get install -y zlib1g-dev
3+
CMD cd xclogparser && swift build

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -406,22 +406,29 @@ xclogparser parse --file path/to/log.xcactivitylog --reporter html --output buil
406406

407407
| Environment | Version |
408408
| ----------- |-------------|
409-
| 🛠 Xcode | 10.2 |
410-
| 🐦 Language | Swift 4.2 |
409+
| 🛠 Xcode | 11.0 |
410+
| 🐦 Language | Swift 5.0 |
411411

412412
## Status
413413

414414
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.
415415

416416
## Development and Contributing
417417

418+
MacOS:
419+
418420
1. Clone the repo with `git clone [email protected]:spotify/XCLogParser.git`.
419421
2. Run `rake gen_resources` to generate a static resource Swift file that is needed to compile the app.
420422
3. Run `swift package generate-xcodeproj` to generate an Xcode project (or use any text editor).
421423
4. Run tests in Xcode directly (CMD + U) or using `rake test`.
422424
5. Create issue and discuss a possible solution or improvement.
423425
6. Create a PR.
424426

427+
Linux:
428+
429+
1. A Dockerfile is provided, you can create an image with the tag xlogparser: `docker build --tag xclogparser .`
430+
2. To compile the app in Linux, just run the shell script: `./run-in-docker.sh`
431+
425432
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).
426433

427434
## Code of Conduct

Sources/XCLogParser/lexer/Lexer.swift

+12
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ public final class Lexer {
6363
}
6464

6565
private func scanSLFHeader(scanner: Scanner) -> Bool {
66+
#if os(Linux)
67+
var format: String?
68+
#else
6669
var format: NSString?
70+
#endif
6771
return scanner.scanString(Lexer.SLFHeader, into: &format)
6872
}
6973

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

8488
private func scanPayload(scanner: Scanner) -> String? {
8589
var payload: String = ""
90+
#if os(Linux)
91+
var char: String?
92+
#else
8693
var char: NSString?
94+
#endif
8795
let hexChars = "abcdef0123456789"
8896
while scanner.scanCharacters(from: CharacterSet(charactersIn: hexChars), into: &char),
8997
let char = char as String? {
@@ -93,7 +101,11 @@ public final class Lexer {
93101
}
94102

95103
private func scanTypeDelimiter(scanner: Scanner) -> [TokenType]? {
104+
#if os(Linux)
105+
var delimiters: String?
106+
#else
96107
var delimiters: NSString?
108+
#endif
97109
if scanner.scanCharacters(from: typeDelimiters, into: &delimiters), let delimiters = delimiters {
98110
let delimiters = String(delimiters)
99111
if delimiters.count > 1 {

Sources/XCLogParser/lexer/LexerModel.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public enum TokenType: String, CaseIterable {
3030

3131
static func all() -> String {
3232
return TokenType.allCases.reduce(String()) {
33-
return String(format: "%@%@", $0, $1.rawValue)
33+
return "\($0)\($1.rawValue)"
3434
}
3535
}
3636
}

Tests/LinuxMain.swift

+3-21
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
1-
// Copyright (c) 2019 Spotify AB.
2-
//
3-
// Licensed to the Apache Software Foundation (ASF) under one
4-
// or more contributor license agreements. See the NOTICE file
5-
// distributed with this work for additional information
6-
// regarding copyright ownership. The ASF licenses this file
7-
// to you under the Apache License, Version 2.0 (the
8-
// "License"); you may not use this file except in compliance
9-
// with the License. You may obtain a copy of the License at
10-
//
11-
// http://www.apache.org/licenses/LICENSE-2.0
12-
//
13-
// Unless required by applicable law or agreed to in writing,
14-
// software distributed under the License is distributed on an
15-
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16-
// KIND, either express or implied. See the License for the
17-
// specific language governing permissions and limitations
18-
// under the License.
19-
201
import XCTest
212

22-
import XcodeLogParserTests
3+
import XCLogParserTests
234

245
var tests = [XCTestCaseEntry]()
25-
tests += XcodeLogParserTests.allTests()
6+
tests += XCLogParserTests.__allTests()
7+
268
XCTMain(tests)

Tests/XCLogParserTests/LogFinderTests.swift

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class LogFinderTests: XCTestCase {
6767
}
6868
}
6969

70+
//Swift is crashing in Linux when trying to create a temp directory with a modificationDate
71+
#if !os(Linux)
7072
func testGetLatestLogForProjectFolder() throws {
7173
guard let derivedDataDir = derivedDataDir else {
7274
XCTFail("Unable to create test directories.")
@@ -87,6 +89,7 @@ class LogFinderTests: XCTestCase {
8789
XCTAssertTrue(latestLog.contains(xcactivitylogName),
8890
"latestLog \(latestLog) doesn't contains \(xcactivitylogName)")
8991
}
92+
#endif
9093

9194
func testLogsDirectoryForXcodeProject() throws {
9295
guard let dirWithProject = self.dirWithProject else {

Tests/XCLogParserTests/XCTestManifests.swift

+103-10
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,112 @@
1717
// specific language governing permissions and limitations
1818
// under the License.
1919

20+
#if !canImport(ObjectiveC)
2021
import XCTest
2122

22-
#if !os(macOS)
23-
public func allTests() -> [XCTestCaseEntry] {
23+
extension ActivityParserTests {
24+
// DO NOT MODIFY: This is autogenerated, use:
25+
// `swift test --generate-linuxmain`
26+
// to regenerate.
27+
static let __allTests__ActivityParserTests = [
28+
("testParseActivityLog", testParseActivityLog),
29+
("testParseDBGConsoleLog", testParseDBGConsoleLog),
30+
("testParseDVTTextDocumentLocation", testParseDVTTextDocumentLocation),
31+
("testParseIDEActivityLogAnalyzerResultMessage", testParseIDEActivityLogAnalyzerResultMessage),
32+
("testParseIDEActivityLogMessage", testParseIDEActivityLogMessage),
33+
("testParseIDEActivityLogSection", testParseIDEActivityLogSection),
34+
]
35+
}
36+
37+
extension ChromeTracerOutputTests {
38+
// DO NOT MODIFY: This is autogenerated, use:
39+
// `swift test --generate-linuxmain`
40+
// to regenerate.
41+
static let __allTests__ChromeTracerOutputTests = [
42+
("testTargetToTraceEvent", testTargetToTraceEvent),
43+
]
44+
}
45+
46+
extension LexerTests {
47+
// DO NOT MODIFY: This is autogenerated, use:
48+
// `swift test --generate-linuxmain`
49+
// to regenerate.
50+
static let __allTests__LexerTests = [
51+
("testTokenizeClassName", testTokenizeClassName),
52+
("testTokenizeClassNameRef", testTokenizeClassNameRef),
53+
("testTokenizeDouble", testTokenizeDouble),
54+
("testTokenizeError", testTokenizeError),
55+
("testTokenizeInt", testTokenizeInt),
56+
("testTokenizeList", testTokenizeList),
57+
("testTokenizeListNil", testTokenizeListNil),
58+
("testTokenizeString", testTokenizeString),
59+
("testTokenizeStringWithTokenDelimiters", testTokenizeStringWithTokenDelimiters),
60+
]
61+
}
62+
63+
extension LogFinderTests {
64+
// DO NOT MODIFY: This is autogenerated, use:
65+
// `swift test --generate-linuxmain`
66+
// to regenerate.
67+
static let __allTests__LogFinderTests = [
68+
("testGetLogManifestPathForNonExistingFile", testGetLogManifestPathForNonExistingFile),
69+
("testGetLogManifestPathWithWorkspace", testGetLogManifestPathWithWorkspace),
70+
("testGetLogManifestPathWithXcodeProj", testGetLogManifestPathWithXcodeProj),
71+
("testGetProjectFolderWithHash", testGetProjectFolderWithHash),
72+
("testLogsDirectoryForXcodeProject", testLogsDirectoryForXcodeProject),
73+
]
74+
}
75+
76+
extension LogManifestTests {
77+
// DO NOT MODIFY: This is autogenerated, use:
78+
// `swift test --generate-linuxmain`
79+
// to regenerate.
80+
static let __allTests__LogManifestTests = [
81+
("testGetLatestLogEntry", testGetLatestLogEntry),
82+
("testGetWithLogOptions", testGetWithLogOptions),
83+
]
84+
}
85+
86+
extension ParserTests {
87+
// DO NOT MODIFY: This is autogenerated, use:
88+
// `swift test --generate-linuxmain`
89+
// to regenerate.
90+
static let __allTests__ParserTests = [
91+
("testBuildIdentifierShouldUseMachineName", testBuildIdentifierShouldUseMachineName),
92+
("testDateFormatterUsesJSONFormat", testDateFormatterUsesJSONFormat),
93+
("testParseNote", testParseNote),
94+
("testParseWarning", testParseWarning),
95+
]
96+
}
97+
98+
extension ReporterTests {
99+
// DO NOT MODIFY: This is autogenerated, use:
100+
// `swift test --generate-linuxmain`
101+
// to regenerate.
102+
static let __allTests__ReporterTests = [
103+
("testMakeLogReporter", testMakeLogReporter),
104+
]
105+
}
106+
107+
extension SwiftFunctionTimesParserTests {
108+
// DO NOT MODIFY: This is autogenerated, use:
109+
// `swift test --generate-linuxmain`
110+
// to regenerate.
111+
static let __allTests__SwiftFunctionTimesParserTests = [
112+
("testParseFunctionTimes", testParseFunctionTimes),
113+
]
114+
}
115+
116+
public func __allTests() -> [XCTestCaseEntry] {
24117
return [
25-
testCase(ActivityParserTests.allTests),
26-
testCase(BuildTimeTests.allTests),
27-
testCase(ChromeTracerReporterTests.allTests),
28-
testCase(LexerTests.allTests),
29-
testCase(LogFinderTests.allTests),
30-
testCase(LogManifestTests.allTests),
31-
testCase(ParserTests.allTests),
32-
testCase(SwiftFunctionTimesParserTests.allTests),
118+
testCase(ActivityParserTests.__allTests__ActivityParserTests),
119+
testCase(ChromeTracerOutputTests.__allTests__ChromeTracerOutputTests),
120+
testCase(LexerTests.__allTests__LexerTests),
121+
testCase(LogFinderTests.__allTests__LogFinderTests),
122+
testCase(LogManifestTests.__allTests__LogManifestTests),
123+
testCase(ParserTests.__allTests__ParserTests),
124+
testCase(ReporterTests.__allTests__ReporterTests),
125+
testCase(SwiftFunctionTimesParserTests.__allTests__SwiftFunctionTimesParserTests),
33126
]
34127
}
35128
#endif

run_in_docker.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
docker run -it --mount src="$(pwd)",target=/xclogparser,type=bind xclogparser

0 commit comments

Comments
 (0)