Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scanning multiple targets #193

Merged
merged 17 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ DerivedData/
*.perspectivev3
!default.perspectivev3
xcuserdata/
*.xcscmblueprint

## Other
*.moved-aside
Expand Down
Empty file added .gitmodules
Empty file.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ excluded: # paths to ignore during linting. Takes precedence over `included`.
- SourceryTests/Stub
- *.generated.swift
- *.stencil
- Xcode.swift

type_body_length:
- 700 #warning
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

### New Features

- Added `isMutable` property for `Variable`
- Added support for inline code generation without requiring explicit `// sourcery:inline` comments in the source files. To use, use `sourcery:inline:auto` in a template: `// sourcery:inline:auto:MyType`
- Added `isMutable` property for `Variable`
- Added support for scanning multiple targets

## 0.5.9

Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let package = Package(
.Package(url: "https://github.com/jpsim/SourceKitten.git", majorVersion: 0, minor: 15),
.Package(url: "https://github.com/vknabel/SwiftTryCatch.git", majorVersion: 1, minor: 1),
.Package(url: "https://github.com/IBM-Swift/CommonCrypto.git", majorVersion: 0),
.Package(url: "https://github.com/SwiftGen/StencilSwiftKit.git", majorVersion: 1)
.Package(url: "https://github.com/SwiftGen/StencilSwiftKit.git", majorVersion: 1),
.Package(url: "https://github.com/ilyapuchka/Xcode.swift.git", "0.4.0")
]
)
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,21 @@ args:
<name>: <value>
```

You can provide either sources paths or targets to scan:

```yaml
project:
file:
<path to xcodeproj file>
root:
<path to project sources root>
target:
name: <target name>
module: <module name> //required if different from target name
```

You can use several `project` objects to scan targets from different projects.

Options:

- `--watch` [default: false] - Watch both code and template folders for changes and regenerate automatically.
Expand Down
12 changes: 12 additions & 0 deletions Sourcery.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
0911DAF21E212817001FF3EB /* Annotations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0911DAF11E212817001FF3EB /* Annotations.swift */; };
0926CE1D1E5F9D8000C0D099 /* JSExport.generated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0926CE1B1E5F996B00C0D099 /* JSExport.generated.swift */; };
09346DC81E02195300D6358C /* StructSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09346DC71E02195300D6358C /* StructSpec.swift */; };
094415C81E78A46A00ABE04A /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 094415C71E78A46A00ABE04A /* Configuration.swift */; };
09618B3C1E61EEE100B49D5F /* JavaScriptTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09618B3B1E61EEE100B49D5F /* JavaScriptTemplate.swift */; };
09618B421E620D8600B49D5F /* ejsbundle.js in Resources */ = {isa = PBXBuildFile; fileRef = 09618B411E620D8600B49D5F /* ejsbundle.js */; };
09618B441E620E3200B49D5F /* JSExport.js in Resources */ = {isa = PBXBuildFile; fileRef = 09618B431E620E3200B49D5F /* JSExport.js */; };
Expand All @@ -28,6 +29,8 @@
09B1DD3E1E21ADD2009228EE /* VariableSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = E291D8D53A557DA9E6D27C3C /* VariableSpec.swift */; };
09B1DD3F1E21ADD8009228EE /* GeneratorSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = E291DF28602426F7A4C8D737 /* GeneratorSpec.swift */; };
09C61F9F1E749DFC005EA58A /* Yams+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09C61F9E1E749DFC005EA58A /* Yams+Extensions.swift */; };
09C61FA41E760FF2005EA58A /* Xcode.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 09C61FA31E760FF2005EA58A /* Xcode.framework */; };
09C61FA61E76109E005EA58A /* Xcode+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09C61FA51E76109E005EA58A /* Xcode+Extensions.swift */; };
09C6B0D21E11BA2500246CDF /* Class.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09C6B0D11E11BA2500246CDF /* Class.swift */; };
09C6B0D41E11C1C500246CDF /* ClassSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09C6B0D31E11C1C500246CDF /* ClassSpec.swift */; };
58A8D89B0B5015671E6B526C /* Pods_SourceryTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6F74DA40979C0911C0573C7A /* Pods_SourceryTests.framework */; };
Expand Down Expand Up @@ -178,6 +181,7 @@
0911DAF31E2141B7001FF3EB /* TypeNameSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeNameSpec.swift; sourceTree = "<group>"; };
0926CE1B1E5F996B00C0D099 /* JSExport.generated.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSExport.generated.swift; sourceTree = "<group>"; };
09346DC71E02195300D6358C /* StructSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StructSpec.swift; sourceTree = "<group>"; };
094415C71E78A46A00ABE04A /* Configuration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
09618B3B1E61EEE100B49D5F /* JavaScriptTemplate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JavaScriptTemplate.swift; sourceTree = "<group>"; };
09618B411E620D8600B49D5F /* ejsbundle.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = ejsbundle.js; sourceTree = "<group>"; };
09618B431E620E3200B49D5F /* JSExport.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = JSExport.js; sourceTree = "<group>"; };
Expand All @@ -193,6 +197,8 @@
098442741E2241F10051E1A1 /* Attribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Attribute.swift; sourceTree = "<group>"; };
09B1DD381E219D95009228EE /* TypedSpec.stencil */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TypedSpec.stencil; sourceTree = "<group>"; };
09C61F9E1E749DFC005EA58A /* Yams+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Yams+Extensions.swift"; sourceTree = "<group>"; };
09C61FA31E760FF2005EA58A /* Xcode.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Xcode.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Sourcery-gbqvopozrlnehjdzvxfvrvqwyvsg/Build/Products/Debug/Xcode.framework"; sourceTree = "<group>"; };
09C61FA51E76109E005EA58A /* Xcode+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Xcode+Extensions.swift"; sourceTree = "<group>"; };
09C6B0D11E11BA2500246CDF /* Class.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Class.swift; sourceTree = "<group>"; };
09C6B0D31E11C1C500246CDF /* ClassSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClassSpec.swift; sourceTree = "<group>"; };
3825CA349BD2B2AAB9605E7F /* Pods-Sourcery.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Sourcery.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Sourcery/Pods-Sourcery.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -276,6 +282,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
09C61FA41E760FF2005EA58A /* Xcode.framework in Frameworks */,
985E4D303A731C40BE326E5C /* Pods_Sourcery.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -294,6 +301,7 @@
003958827841F12BBF99EB67 /* Frameworks */ = {
isa = PBXGroup;
children = (
09C61FA31E760FF2005EA58A /* Xcode.framework */,
D7C9B21117B6C7EB409B9D49 /* Pods_Sourcery.framework */,
6F74DA40979C0911C0573C7A /* Pods_SourceryTests.framework */,
);
Expand Down Expand Up @@ -360,6 +368,7 @@
E291DB249799066B169A0F41 /* Parsing */,
E291DB64F90A7CCCD66B3801 /* Generating */,
E291DB6A95BAECDB6E978A76 /* Sourcery.swift */,
094415C71E78A46A00ABE04A /* Configuration.swift */,
CD754C951D853F000082B512 /* Info.plist */,
CD9C459C1DFAF76D00161C2C /* main.swift */,
);
Expand Down Expand Up @@ -527,6 +536,7 @@
C8E88CAF1E20579100102D17 /* Path+Extensions.swift */,
E291D0EF57C42E4A4B502F43 /* Sha.swift */,
09C61F9E1E749DFC005EA58A /* Yams+Extensions.swift */,
09C61FA51E76109E005EA58A /* Xcode+Extensions.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -815,6 +825,7 @@
0926CE1D1E5F9D8000C0D099 /* JSExport.generated.swift in Sources */,
C894A1AD1E1931500098327C /* GenerationContext.swift in Sources */,
C894A1A61E1930990098327C /* Coding.generated.swift in Sources */,
094415C81E78A46A00ABE04A /* Configuration.swift in Sources */,
CD812F5A1DFDCC1A0088B2F6 /* AccessLevel.swift in Sources */,
E291DCA363FD8EBF0455C712 /* Sourcery.swift in Sources */,
CDF68B761E1C143D007C5396 /* Typed.generated.swift in Sources */,
Expand All @@ -835,6 +846,7 @@
CDBEC15C1E242B9E0090E881 /* StencilTemplate.swift in Sources */,
E291D33EA3BB6FC777B3950E /* FolderWatcher.swift in Sources */,
E291D9FBE0B751C3C898E5B6 /* Array+Parallel.swift in Sources */,
09C61FA61E76109E005EA58A /* Xcode+Extensions.swift in Sources */,
E291D5EA18C2B12217A59EC9 /* Sha.swift in Sources */,
E291DA2409438D3B0DA5F3BB /* InlineParser.swift in Sources */,
E291DC4E4F6338FFFB67DA41 /* PhantomProtocols.swift in Sources */,
Expand Down
3 changes: 3 additions & 0 deletions Sourcery.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Sourcery/CodeGenerated/Description.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extension FileParserResult {
override var description: String {
var string = "\(type(of: self)): "
string += "path = \(self.path), "
string += "module = \(self.module), "
string += "types = \(self.types), "
string += "typealiases = \(self.typealiases), "
string += "inlineRanges = \(self.inlineRanges), "
Expand Down Expand Up @@ -145,6 +146,7 @@ extension TupleType {
extension Type {
override var description: String {
var string = "\(type(of: self)): "
string += "module = \(self.module), "
string += "typealiases = \(self.typealiases), "
string += "isExtension = \(self.isExtension), "
string += "kind = \(self.kind), "
Expand Down
2 changes: 2 additions & 0 deletions Sourcery/CodeGenerated/Diffable.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ extension FileParserResult: Diffable {
return results
}
results.append(contentsOf: DiffableResult(identifier: "path").trackDifference(actual: self.path, expected: rhs.path))
results.append(contentsOf: DiffableResult(identifier: "module").trackDifference(actual: self.module, expected: rhs.module))
results.append(contentsOf: DiffableResult(identifier: "types").trackDifference(actual: self.types, expected: rhs.types))
results.append(contentsOf: DiffableResult(identifier: "typealiases").trackDifference(actual: self.typealiases, expected: rhs.typealiases))
results.append(contentsOf: DiffableResult(identifier: "inlineRanges").trackDifference(actual: self.inlineRanges, expected: rhs.inlineRanges))
Expand Down Expand Up @@ -209,6 +210,7 @@ extension Type: Diffable {
results.append("Incorrect type <expected: Type, received: \(type(of: object))>")
return results
}
results.append(contentsOf: DiffableResult(identifier: "module").trackDifference(actual: self.module, expected: rhs.module))
results.append(contentsOf: DiffableResult(identifier: "typealiases").trackDifference(actual: self.typealiases, expected: rhs.typealiases))
results.append(contentsOf: DiffableResult(identifier: "isExtension").trackDifference(actual: self.isExtension, expected: rhs.isExtension))
results.append(contentsOf: DiffableResult(identifier: "accessLevel").trackDifference(actual: self.accessLevel, expected: rhs.accessLevel))
Expand Down
2 changes: 2 additions & 0 deletions Sourcery/CodeGenerated/Equality.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ extension FileParserResult {
override func isEqual(_ object: Any?) -> Bool {
guard let rhs = object as? FileParserResult else { return false }
if self.path != rhs.path { return false }
if self.module != rhs.module { return false }
if self.types != rhs.types { return false }
if self.typealiases != rhs.typealiases { return false }
if self.inlineRanges != rhs.inlineRanges { return false }
Expand Down Expand Up @@ -148,6 +149,7 @@ extension TupleType {
extension Type {
override func isEqual(_ object: Any?) -> Bool {
guard let rhs = object as? Type else { return false }
if self.module != rhs.module { return false }
if self.typealiases != rhs.typealiases { return false }
if self.isExtension != rhs.isExtension { return false }
if self.accessLevel != rhs.accessLevel { return false }
Expand Down
10 changes: 10 additions & 0 deletions Sourcery/CodeGenerated/JSExport.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ extension Attribute: AttributeAutoJSExport {}

@objc protocol ClassAutoJSExport: JSExport {
var kind: String { get }
var module: String? { get }
var accessLevel: String { get }
var name: String { get }
var globalName: String { get }
var isGeneric: Bool { get }
var localName: String { get }
var variables: [Variable] { get }
Expand Down Expand Up @@ -78,8 +80,10 @@ extension DictionaryType: DictionaryTypeAutoJSExport {}
var rawType: Type? { get }
var based: [String : String] { get }
var hasAssociatedValues: Bool { get }
var module: String? { get }
var accessLevel: String { get }
var name: String { get }
var globalName: String { get }
var isGeneric: Bool { get }
var localName: String { get }
var variables: [Variable] { get }
Expand Down Expand Up @@ -152,8 +156,10 @@ extension MethodParameter: MethodParameterAutoJSExport {}

@objc protocol ProtocolAutoJSExport: JSExport {
var kind: String { get }
var module: String? { get }
var accessLevel: String { get }
var name: String { get }
var globalName: String { get }
var isGeneric: Bool { get }
var localName: String { get }
var variables: [Variable] { get }
Expand Down Expand Up @@ -181,8 +187,10 @@ extension Protocol: ProtocolAutoJSExport {}

@objc protocol StructAutoJSExport: JSExport {
var kind: String { get }
var module: String? { get }
var accessLevel: String { get }
var name: String { get }
var globalName: String { get }
var isGeneric: Bool { get }
var localName: String { get }
var variables: [Variable] { get }
Expand Down Expand Up @@ -227,9 +235,11 @@ extension TupleElement: TupleElementAutoJSExport {}
extension TupleType: TupleTypeAutoJSExport {}

@objc protocol TypeAutoJSExport: JSExport {
var module: String? { get }
var kind: String { get }
var accessLevel: String { get }
var name: String { get }
var globalName: String { get }
var isGeneric: Bool { get }
var localName: String { get }
var variables: [Variable] { get }
Expand Down
88 changes: 88 additions & 0 deletions Sourcery/Configuration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import Foundation
import Xcode

struct Project {
let file: XCProjectFile
let root: Path
let targets: [Target]

struct Target {
let name: String
let module: String

init?(dict: [String: String]) {
guard let name = dict["name"] else {
return nil
}
self.name = name
self.module = dict["module"] ?? name
}
}

init?(dict: [String: Any]) {
guard let file = dict["file"] as? String,
let project = try? XCProjectFile(path: file),
let root = dict["root"] as? String else {
return nil
}
if let targets = dict["target"] as? [[String: String]] {
self.targets = targets.flatMap(Target.init(dict:))
} else if let target = dict["target"] as? [String: String] {
self.targets = [Target(dict: target)].flatMap({ $0 })
} else {
return nil
}

self.file = project
self.root = Path(root)
}

}

enum Source {
case projects([Project])
case sources([Path])

init(dict: [String: Any]) {
if let projects = dict["project"] as? [[String: Any]] {
self = .projects(projects.flatMap(Project.init(dict:)))
} else if let project = dict["project"] as? [String: Any] {
self = .projects([Project(dict: project)].flatMap({ $0 }))
} else {
let sources = (dict["sources"] as? [String])?.map({ Path($0) }) ?? []
self = .sources(sources)
}
}

var isEmpty: Bool {
switch self {
case let .sources(sources):
return sources.isEmpty
case let .projects(projects):
return projects.isEmpty
}
}
}

struct Configuration {

let source: Source
let templates: [Path]
let output: Path
let args: [String: NSObject]

init(dict: [String: Any]) {
self.source = Source(dict: dict)
self.templates = (dict["templates"] as? [String])?.map({ Path($0) }) ?? []
self.output = (dict["output"] as? String).map({ Path($0) }) ?? "."
self.args = dict["args"] as? [String: NSObject] ?? [:]
}

init(sources: [Path], templates: [Path], output: Path, args: [String: NSObject]) {
self.source = Source.sources(sources)
self.templates = templates
self.output = output
self.args = args
}

}
19 changes: 16 additions & 3 deletions Sourcery/Models/FileParserResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,38 @@ import Foundation

// sourcery: skipJSExport
@objc final class FileParserResult: NSObject, SourceryModel {
var path: String?
var types = [Type]()
let path: String?
let module: String?
var types = [Type]() {
didSet {
types.forEach { type in
guard type.module == nil, type.kind != "extensions" else { return }
type.module = module
}
}
}
var typealiases = [Typealias]()
var inlineRanges = [String: NSRange]()

var contentSha: String?
var sourceryVersion: String

init(path: String?, types: [Type], typealiases: [Typealias], inlineRanges: [String: NSRange] = [:], contentSha: String = "", sourceryVersion: String = "") {
init(path: String?, module: String?, types: [Type], typealiases: [Typealias] = [], inlineRanges: [String: NSRange] = [:], contentSha: String = "", sourceryVersion: String = "") {
self.path = path
self.module = module
self.types = types
self.typealiases = typealiases
self.inlineRanges = inlineRanges
self.contentSha = contentSha
self.sourceryVersion = sourceryVersion

types.forEach { type in type.module = module }
}

// sourcery:inline:FileParserResult.AutoCoding
required init?(coder aDecoder: NSCoder) {
self.path = aDecoder.decode(forKey: "path")
self.module = aDecoder.decode(forKey: "module")
guard let types: [Type] = aDecoder.decode(forKey: "types") else { NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: getVaList(["types"])); fatalError() }; self.types = types
guard let typealiases: [Typealias] = aDecoder.decode(forKey: "typealiases") else { NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: getVaList(["typealiases"])); fatalError() }; self.typealiases = typealiases
guard let inlineRanges: [String: NSRange] = aDecoder.decode(forKey: "inlineRanges") else { NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: getVaList(["inlineRanges"])); fatalError() }; self.inlineRanges = inlineRanges
Expand All @@ -39,6 +51,7 @@ import Foundation

func encode(with aCoder: NSCoder) {
aCoder.encode(self.path, forKey: "path")
aCoder.encode(self.module, forKey: "module")
aCoder.encode(self.types, forKey: "types")
aCoder.encode(self.typealiases, forKey: "typealiases")
aCoder.encode(self.inlineRanges, forKey: "inlineRanges")
Expand Down
Loading