├── .gitignore ├── .swift-version ├── LICENSE ├── Package.swift ├── README.md ├── Sources ├── BuildCommand.swift ├── LogEntry.swift ├── LogProcessor.swift ├── NSURL+Time.swift ├── PathConfiguration.swift └── main.swift └── config.json /.gitignore: -------------------------------------------------------------------------------- 1 | .build/ 2 | 3 | # Xcode 4 | # 5 | build/ 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | xcuserdata 15 | *.xccheckout 16 | *.moved-aside 17 | DerivedData 18 | *.hmap 19 | *.ipa 20 | *.xcuserstate 21 | *.xcodeproj -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | DEVELOPMENT-SNAPSHOT-2016-08-18-a 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | import PackageDescription 2 | 3 | let package = Package( 4 | name: "SwiftCompilationPerformanceReporter" 5 | ) 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SwiftCompilationPerformanceReporter 2 | 3 | Inspired by [Brian](https://twitter.com/brianmichel/) and [Bryan](https://twitter.com/irace/)'s [prior](https://github.com/brianmichel/Swift-Analysis-Workflow) [work](http://irace.me/swift-profiling), we've decided to develop a Swift Package and script to generate automated reports for slow Swift compilation paths in specific targets! 4 | 5 | SwiftCompilationPerformanceReporter (nicknamed SwiftCPR) can be configured to build a specific target, output raw debug times to a specific location, and clean those logs to rank the slowest parts to compile. 6 | 7 | ## Requirements 8 | 9 | - [Xcode 8 Beta](https://developer.apple.com/download/) 10 | - [8/18/2016 Swift Trunk Development Snapshot](https://swift.org/builds/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2016-08-18-a/swift-DEVELOPMENT-SNAPSHOT-2016-08-18-a-osx.pkg) (We'll periodically update this repo to work with the latest snapshots) 11 | 12 | ## Configuration 13 | 14 | SwiftCompilationPerformanceReporter can be configured via the `config.json` file. Below is a description of the options available and a sample configuration: 15 | 16 | ```javascript 17 | { 18 | // Note: either a project or workspace file can be specified, _but not both_ 19 | "workspacePath": "/Users/jasdev/orangina/Orangina.xcworkspace", 20 | "projectPath": "/Users/jasdev/orangina/Orangina.xcodeproj", 21 | 22 | "scheme": "Orangina", 23 | "buildOutputDirectory": "/Users/jasdev/Desktop/CompilationLogs/", 24 | "reportOutputDirectory": "/Users/jasdev/Desktop/ProcessedLogs/", 25 | "limit": 10 26 | } 27 | ``` 28 | 29 | `workspacePath`: The absolute path to the workspace file to use. 30 | 31 | `projectPath`: The absolute path to the project file to use. 32 | 33 | `scheme`: The scheme to use 34 | 35 | `buildOutputDirectory`: The directory to store the raw build output files with Swift compilation times. 36 | 37 | `reportOutputDirectory`: The directory to store the processed logs derived from the raw log output. 38 | 39 | `limit`: The number of compilation paths to include in the final results (i.e. the slowest `limit` paths that compiler handled). 40 | 41 | ## Installation 42 | 43 | - Simply clone this repository on the machine that will be generating these reports. 44 | - Run `swift build` in the root directory 45 | - Make sure all directories used in `config.json` are set properly and exist. 46 | - If your desired scheme is built with a pre-3.x version of Swift, you'll want to `xcode-select` back to a stable version (i.e. `sudo xcode-select -s /Applications/Xcode.app`) 47 | - To kick off the script, run `.build/debug/SwiftCompilationPerformanceReporter` in the root directory! 48 | - If there are any errors, the script will output them. 49 | - The processed logs will be outputted as timestamped files in `reportOutputDirectory`. 50 | 51 | ## Output 52 | 53 | The processed logs will be outputted as a tab separated file with 3 columns after the first line (which holds the total build time). All time units are in seconds. 54 | 55 | `[Build Time]\t[Path and Line]\t[Detailed Description]` 56 | 57 | Sample output file: 58 | 59 | ``` 60 | Total build time: 1214.91016298532 61 | 17.0409 /Users/jasdev/orangina/Classes/PerformanceLoggingEvent.swift:278:37 final get {} 62 | 7.9331 /Users/jasdev/orangina/Components/ComposeUI/Classes/Election/LeaderboardTableView.swift:71:17 @objc final class func totalHeight(candidates: UInt, allowsLeaderboard: Bool) -> CGFloat 63 | 6.2961 /Users/jasdev/orangina/Classes/UniversalLink.swift:127:25 private final class func dictionaryOfAppArgumentsFromQueryString(string: String) -> [NSObject : AnyObject]? 64 | 4.2116 /Users/jasdev/orangina/Classes/ActivityViewController.swift:56:22 final get {} 65 | ``` 66 | -------------------------------------------------------------------------------- /Sources/BuildCommand.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /** 4 | * `BuildCommand` is a thin wrapper on the command needed to determine Swift compilation times for specific functions. 5 | */ 6 | struct BuildCommand { 7 | fileprivate var buildCommand: String { 8 | let pathFlag: String 9 | switch pathConfiguration { 10 | case .workspace(_): 11 | pathFlag = "-workspace" 12 | case .project(_): 13 | pathFlag = "-project" 14 | } 15 | 16 | return "xcodebuild " 17 | + "\(pathFlag) \"%@\" " 18 | + "-scheme \"%@\" " 19 | + "clean build OTHER_SWIFT_FLAGS=\"-Xfrontend -debug-time-function-bodies\" | " 20 | + "grep [1-9].[0-9]ms | " 21 | + "sort -nr > %@" 22 | } 23 | 24 | let pathConfiguration: PathConfiguration 25 | 26 | /// Name of the scheme to build 27 | let scheme: String 28 | 29 | /// Directory to output the raw Swift build logs. Make sure to set trailing slash. 30 | let buildOutputPath: URL 31 | 32 | /// Directory to output the processed logs. Make sure to set trailing slash. 33 | let reportOutputDirectory: URL 34 | 35 | /// The number of entries to output in the processed logs. Defaults to 20. 36 | let limit: UInt 37 | 38 | fileprivate enum JSONKeys: String { 39 | case workspacePath 40 | case projectPath 41 | case scheme 42 | case buildOutputDirectory 43 | case reportOutputDirectory 44 | case limit 45 | } 46 | } 47 | 48 | extension BuildCommand { 49 | /** 50 | Initializes a `BuildCommand` from a JSON dictionary. 51 | 52 | - parameter dictionary: The JSON dictionary to use. 53 | 54 | - returns: An instance of `BuildCommand` or `nil`, if parsing failed. 55 | */ 56 | init?(dictionary: [String: AnyObject]) { 57 | guard 58 | let scheme = dictionary[JSONKeys.scheme.rawValue] as? String, 59 | let buildOutputPathString = dictionary[JSONKeys.buildOutputDirectory.rawValue] as? String, 60 | let buildOutputPath = URL(string: buildOutputPathString), 61 | let reportOutputDirectoryString = dictionary[JSONKeys.reportOutputDirectory.rawValue] as? String, 62 | let reportOutputDirectory = URL(string: reportOutputDirectoryString) 63 | else { 64 | return nil 65 | } 66 | 67 | let workspacePathString = dictionary[JSONKeys.workspacePath.rawValue] as? String 68 | let projectPathString = dictionary[JSONKeys.projectPath.rawValue] as? String 69 | 70 | // We need to ensure that _either_ a workspace path or a project path is set, but not both simultaneously. 71 | switch (workspacePathString, projectPathString) { 72 | case (_?, _?), (nil, nil): 73 | return nil 74 | case let (workspaceString?, nil): 75 | guard let workspacePath = URL(string: workspaceString) else { return nil } 76 | pathConfiguration = .workspace(workspacePath) 77 | case let (nil, projectString?): 78 | guard let projectPath = URL(string: projectString) else { return nil } 79 | pathConfiguration = .project(projectPath) 80 | } 81 | 82 | self.scheme = scheme 83 | self.buildOutputPath = buildOutputPath 84 | self.reportOutputDirectory = reportOutputDirectory 85 | limit = dictionary[JSONKeys.limit.rawValue] as? UInt ?? 20 86 | } 87 | } 88 | 89 | extension BuildCommand { 90 | /** 91 | Computes the build command and raw output file path 92 | 93 | - returns: A tuple containing the path to the raw output file to be generated and the command string 94 | */ 95 | func buildInfo() -> (outputLogPath: String, buildCommandString: String) { 96 | let outputLogPath = "\(buildOutputPath.pathWithAppendedTimestamp.absoluteString).txt" 97 | 98 | // `NSString` casting needed to get around https://bugs.swift.org/browse/SR-957?jql=text%20~%20%22string%20cvararg%22 99 | return (outputLogPath: outputLogPath, 100 | String(format: buildCommand, 101 | (pathConfiguration.path.absoluteString) as NSString, 102 | scheme as NSString, 103 | outputLogPath as NSString)) 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Sources/LogEntry.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /** 4 | * Wrapper on a line of raw Swift debug time output 5 | */ 6 | struct LogEntry { 7 | fileprivate struct Constants { 8 | static let invalidLocation = "" 9 | } 10 | 11 | /// The compilation time in milliseconds 12 | let compilationTime: Double 13 | 14 | /// The location of the function 15 | let location: String 16 | 17 | /// More detail about the function provided from the compiler 18 | let detailedDescription: String 19 | } 20 | 21 | extension LogEntry { 22 | /** 23 | Builds a `LogEntry` from a line of compiler output 24 | 25 | - parameter line: The line of compiler output 26 | 27 | - returns: An instance of `LogEntry` or `nil`, if invalid. 28 | */ 29 | init?(line: String) { 30 | let components = line.components(separatedBy: "\t").map { $0.trimmingCharacters(in: NSCharacterSet.whitespaces) } 31 | 32 | guard 33 | components.count == 3 && 34 | components[1].range(of: Constants.invalidLocation) == nil, 35 | let compilationTime = Double( 36 | components[0].trimmingCharacters(in: NSCharacterSet.letters) 37 | ) 38 | else { 39 | return nil 40 | } 41 | 42 | self.compilationTime = compilationTime 43 | location = components[1] 44 | detailedDescription = components[2] 45 | } 46 | 47 | /** 48 | Updates the compilation time of a `LogEntry`. Used in merging duplicate logs. 49 | 50 | - parameter time: The new time to use. 51 | 52 | - returns: A mirrored `LogEntry` with a new `compilationTime` 53 | */ 54 | func updateCompilation(_ time: Double) -> LogEntry { 55 | return LogEntry(compilationTime: time, location: location, detailedDescription: detailedDescription) 56 | } 57 | } 58 | 59 | // MARK: - CustomStringConvertible 60 | 61 | extension LogEntry: CustomStringConvertible { 62 | var description: String { 63 | let formattedTime = "\(compilationTime/1000)" 64 | return [formattedTime, location, detailedDescription].joined(separator: "\t") 65 | } 66 | } 67 | 68 | // MARK: - Hashable 69 | 70 | extension LogEntry: Hashable { 71 | var hashValue: Int { 72 | return (location + detailedDescription).hashValue 73 | } 74 | } 75 | 76 | // MARK: - Equatable 77 | 78 | func ==(lhs: LogEntry, rhs: LogEntry) -> Bool { 79 | return lhs.location == rhs.location && lhs.detailedDescription == rhs.detailedDescription 80 | } 81 | -------------------------------------------------------------------------------- /Sources/LogProcessor.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /** 4 | * A processor for the raw logs outputted from the Swift compiler. 5 | */ 6 | struct LogProcessor { 7 | 8 | /// Location of the raw log file 9 | let path: String 10 | 11 | /// The output directory for the processed logs 12 | let outputPath: URL 13 | 14 | /// The total time it took for the build 15 | let totalBuildTime: Double 16 | 17 | /// The number of entities to include in the final log (e.g. top 10 functions that take the longest to compile) 18 | let limit: UInt 19 | 20 | /** 21 | Processes the raw log file and writes out the results to `outputPath` 22 | */ 23 | func process() { 24 | do { 25 | let fullText = try String(contentsOfFile: path) 26 | 27 | let entries = fullText.components(separatedBy: "\n").flatMap { LogEntry(line: $0) } 28 | let mergedEntries = mergeDuplicateEntries(entries) 29 | let buildTimePrompt = "Total build time: \(totalBuildTime)" 30 | let outputText = ([buildTimePrompt] + mergedEntries.prefix(upTo: Int(limit)).map { String(describing: $0) }).joined(separator: "\n") 31 | 32 | try outputText.write(toFile: "\(outputPath.pathWithAppendedTimestamp.absoluteString).txt", atomically: true, encoding: String.Encoding.utf8) 33 | } 34 | catch { 35 | fatalError("Log processing failed w/ error: \(error)") 36 | } 37 | } 38 | 39 | private func mergeDuplicateEntries(_ entries: [LogEntry]) -> [LogEntry] { 40 | var timeFrequencyMap = [LogEntry: Double]() 41 | 42 | entries.forEach { 43 | timeFrequencyMap[$0] = (timeFrequencyMap[$0] ?? 0) + $0.compilationTime 44 | } 45 | 46 | return timeFrequencyMap.enumerated().sorted { $0.element.1 > $1.element.1 }.map { 47 | $0.element.0.updateCompilation($0.element.1) 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Sources/NSURL+Time.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | extension URL { 4 | /// Appends the current epoch time in milliseconds to the path 5 | var pathWithAppendedTimestamp: URL { 6 | return appendingPathComponent("\(Int(Date().timeIntervalSince1970*1000))") 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Sources/PathConfiguration.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PathConfiguration.swift 3 | // SwiftCompilationPerformanceReporter 4 | // 5 | // Created by Jasdev Singh on 6/25/16. 6 | // 7 | // 8 | 9 | import Foundation 10 | 11 | /// Wrapper on the different path configurations that SwiftCPR supports 12 | enum PathConfiguration { 13 | // Build from a workspace file and its associated path on disk 14 | case workspace(URL) 15 | 16 | // Build from a project file and its associated path on disk 17 | case project(URL) 18 | 19 | // Allow easy access to the associated path 20 | var path: URL { 21 | switch self { 22 | case let .project(url): 23 | return url 24 | case let .workspace(url): 25 | return url 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Sources/main.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | private struct Constants { 4 | static let launchPath = "/bin/bash" 5 | static let commandFlag = "-c" 6 | } 7 | 8 | let JSONData = try? Data.init(contentsOf: URL(fileURLWithPath: "\(FileManager.default.currentDirectoryPath)/config.json")) 9 | guard let data = JSONData else { 10 | fatalError("Failed to read config.json!") 11 | } 12 | 13 | guard 14 | let JSONDict = (try? JSONSerialization.jsonObject(with: data, options: []) as? [String: AnyObject]) ?? nil, 15 | let buildCommand = BuildCommand(dictionary: JSONDict) 16 | else { 17 | fatalError("Invalid config.json. See README to make sure it's valid.") 18 | } 19 | 20 | let (outputPath, buildCommandString) = buildCommand.buildInfo() 21 | print(">>> Building \(buildCommand.scheme)...") 22 | 23 | let buildStartTime = Date() 24 | 25 | let task = Process.launchedProcess(launchPath: Constants.launchPath, arguments: [Constants.commandFlag, buildCommandString]) 26 | task.waitUntilExit() 27 | 28 | guard task.terminationStatus == 0 else { 29 | fatalError("Uh oh! The build command failed :( Try running the following command to debug and re-run this script:\n\(buildCommandString)") 30 | } 31 | 32 | print(">>> \(buildCommand.scheme) built successfully!") 33 | 34 | let elapsedTime = Date().timeIntervalSince(buildStartTime) 35 | 36 | let processor = LogProcessor(path: outputPath, 37 | outputPath: buildCommand.reportOutputDirectory, 38 | totalBuildTime: elapsedTime, 39 | limit: buildCommand.limit) 40 | processor.process() 41 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "workspacePath": "/Users/js/Projects/orangina/Orangina.xcworkspace", 3 | "scheme": "Orangina", 4 | "buildOutputDirectory": "/Users/js/Desktop/CompilationLogs/", 5 | "reportOutputDirectory": "/Users/js/Desktop/ProcessedLogs/", 6 | "limit": 10 7 | } 8 | --------------------------------------------------------------------------------