0001    //
0002    //  Module.swift
0003    //  SourceKitten
0004    //
0005    //  Created by JP Simard on 2015-01-07.
0006    //  Copyright (c) 2015 SourceKitten. All rights reserved.
0007    //
0008    
0009    import Foundation
0010    
0011    /// Represents source module to be documented.
0012    public struct Module
Module.swift:76
extension Module: CustomStringConvertible {
{ 0013 /// Module Name. 0014 public let name
Module.swift:68
        self.name = name
Module.swift:79
        return "Module(name: \(name), compilerArguments: \(compilerArguments), sourceFiles: \(sourceFiles))"
: String 0015 /// Compiler arguments required by SourceKit to process the source files in this Module. 0016 public let compilerArguments
Module.swift:29
                return SwiftDocs(file: file, arguments: compilerArguments)
Module.swift:69
        self.compilerArguments = compilerArguments
Module.swift:79
        return "Module(name: \(name), compilerArguments: \(compilerArguments), sourceFiles: \(sourceFiles))"
: [String] 0017 /// Source files to be documented in this Module. 0018 public let sourceFiles
Module.swift:23
        let sourceFilesCount = sourceFiles.count
Module.swift:24
        return sourceFiles.flatMap {
Module.swift:70
        sourceFiles = compilerArguments.filter({ $0.isSwiftFile() }).map { ($0 as NSString).stringByResolvingSymlinksInPath }
Module.swift:79
        return "Module(name: \(name), compilerArguments: \(compilerArguments), sourceFiles: \(sourceFiles))"
: [String] 0019 0020 /// Documentation for this Module. Typically expensive computed property. 0021 public var docs: [SwiftDocs] { 0022 var fileIndex = 1 0023 let sourceFilesCount = sourceFiles.count 0024 return sourceFiles.flatMap { 0025 let filename = ($0 as NSString).lastPathComponent 0026 if let file = File(path: $0) { 0027 fputs("Parsing \(filename) (\(fileIndex)/\(sourceFilesCount))\n", stderr) 0028 fileIndex += 1 0029 return SwiftDocs(file: file, arguments: compilerArguments) 0030 } 0031 fputs("Could not parse `\(filename)`. Please open an issue at https://github.com/jpsim/SourceKitten/issues with the file contents.\n", stderr) 0032 return nil 0033 } 0034 } 0035 0036 /** 0037 Failable initializer to create a Module by the arguments necessary pass in to `xcodebuild` to build it. 0038 Optionally pass in a `moduleName` and `path`. 0039 0040 - parameter xcodeBuildArguments: The arguments necessary pass in to `xcodebuild` to build this Module. 0041 - parameter name: Module name. Will be parsed from `xcodebuild` output if nil. 0042 - parameter path: Path to run `xcodebuild` from. Uses current path by default. 0043 */ 0044 public init?(xcodeBuildArguments: [String], name: String? = nil, inPath path: String = NSFileManager.defaultManager().currentDirectoryPath) { 0045 let xcodeBuildOutput = runXcodeBuild(xcodeBuildArguments, inPath: path) ?? "" 0046 guard let arguments = parseCompilerArguments(xcodeBuildOutput, language: .Swift, moduleName: name ?? moduleNameFromArguments(xcodeBuildArguments)) else { 0047 fputs("Could not parse compiler arguments from `xcodebuild` output.\n", stderr) 0048 fputs("Please confirm that `xcodebuild` is building a Swift module.\n", stderr) 0049 let file = NSURL(fileURLWithPath: NSTemporaryDirectory()).URLByAppendingPathComponent("xcodebuild-\(NSUUID().UUIDString).log") 0050 xcodeBuildOutput.dataUsingEncoding(NSUTF8StringEncoding)?.writeToURL(file, atomically: true) 0051 fputs("Saved `xcodebuild` log file: \(file.path!)\n", stderr) 0052 return nil 0053 } 0054 guard let moduleName = moduleNameFromArguments(arguments) else { 0055 fputs("Could not parse module name from compiler arguments.\n", stderr) 0056 return nil 0057 } 0058 self.init(name: moduleName, compilerArguments: arguments) 0059 } 0060 0061 /** 0062 Initializer to create a Module by name and compiler arguments. 0063 0064 - parameter name: Module name. 0065 - parameter compilerArguments: Compiler arguments required by SourceKit to process the source files in this Module. 0066 */ 0067 public init
Module.swift:58
        self.init(name: moduleName, compilerArguments: arguments)
(name: String, compilerArguments: [String]) { 0068 self.name = name 0069 self.compilerArguments = compilerArguments 0070 sourceFiles = compilerArguments.filter({ $0.isSwiftFile() }).map { ($0 as NSString).stringByResolvingSymlinksInPath } 0071 } 0072 } 0073 0074 // MARK: CustomStringConvertible 0075 0076 extension Module: CustomStringConvertible { 0077 /// A textual representation of `Module`. 0078 public var description: String { 0079 return "Module(name: \(name), compilerArguments: \(compilerArguments), sourceFiles: \(sourceFiles))" 0080 } 0081 } 0082