Skip to content

Commit

Permalink
Caching swift templates (#240)
Browse files Browse the repository at this point in the history
* chore: saving swift template artifacts in cache

* code cleanup and refactoring

* addrssed code review comments

* removed unneeded runtime file

* compile all swift template runtime file together

this improves compile time until we find a good way to link precompiled framework and only build one file

* moved models to SourceryFramework

* copy SourceryFramework to template build folder and link it with binary

* minor improvements

* updated docs, added rake task to update docs

* moved framework sources to a single folder

* fixed yaml configuration

* renamed SourceryFramework to SourceryRuntime

* fixed swift build

* ignore package pins
  • Loading branch information
ilyapuchka authored May 9, 2017
1 parent b4bf8e0 commit 4e92079
Show file tree
Hide file tree
Showing 126 changed files with 1,585 additions and 3,055 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ playground.xcworkspace
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
Packages/
Package.pins
.build/

# CocoaPods
Expand Down
6 changes: 5 additions & 1 deletion .jazzy.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
author: Krzysztof Zabłocki
author_url: https://twitter.com/merowing_
module: Sourcery
module_version: 0.5.9
sourcekitten_sourcefile: docs.json
module_version: 0.6.0
github_url: https://github.com/krzysztofzablocki/Sourcery
copyright: 'Copyright © 2016 Pixle. All rights reserved.'
readme: About.md
documentation: guides/*.md
exclude:
- SourceryFramework/Utils/*
- SourceryFramework/CodeGenerated/*

custom_categories:
- name: Guides
Expand Down
2 changes: 1 addition & 1 deletion .sourcery.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sources:
- Sourcery/Models
- SourceryFramework/Sources
templates:
- Sourcery/Templates
output:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Added `isRequired` property for `Method`
- Improved parsing of closure types
- Check if Current Project Version match version in podspec in release task
- Improved swift templates performance

### Bug fixes

Expand Down
96 changes: 0 additions & 96 deletions Package.pins

This file was deleted.

3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import PackageDescription
let package = Package(
name: "Sourcery",
targets: [
Target(name: "sourcery", dependencies: [])
Target(name: "SourceryRuntime"),
Target(name: "sourcery", dependencies: ["SourceryRuntime"]),
],
dependencies: [
// https://github.com/kylef/Stencil/pull/84
Expand Down
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def print_info(str)
(red,clr) = (`tput colors`.chomp.to_i >= 8) ? %W(\e[33m \e[m) : ["", ""]
puts red, "== #{str.chomp} ==", clr
end

desc "Update docs"
task :docs do
print_info "Updating docs"
sh "sourcekitten doc --module-name SourceryFramework > docs.json && jazzy --clean --skip-undocumented && rm docs.json"
end

## [ Tests & Clean ] ##########################################################

desc "Run the Unit Tests"
Expand Down
470 changes: 295 additions & 175 deletions Sourcery.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions Sourcery.xcodeproj/xcshareddata/xcschemes/SourceryRuntime.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0830"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "64E201A21EAE8FBF00EAD8A2"
BuildableName = "SourceryRuntime.framework"
BlueprintName = "SourceryRuntime"
ReferencedContainer = "container:Sourcery.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "64E201A21EAE8FBF00EAD8A2"
BuildableName = "SourceryRuntime.framework"
BlueprintName = "SourceryRuntime"
ReferencedContainer = "container:Sourcery.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "64E201A21EAE8FBF00EAD8A2"
BuildableName = "SourceryRuntime.framework"
BlueprintName = "SourceryRuntime"
ReferencedContainer = "container:Sourcery.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
1 change: 1 addition & 0 deletions Sourcery/Generating/Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import Foundation
import Stencil
import SourceryRuntime

enum Generator {
static func generate(_ types: Types, template: Template, arguments: [String: NSObject] = [:]) throws -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import JavaScriptCore
import PathKit
import SourceryRuntime

final class JavaScriptTemplate: Template {

Expand Down
33 changes: 17 additions & 16 deletions Sourcery/Generating/Template/Stencil/StencilTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Foundation
import Stencil
import PathKit
import StencilSwiftKit
import SourceryRuntime

final class StencilTemplate: StencilSwiftKit.StencilSwiftTemplate, Template {
private(set) var sourcePath: Path = ""
Expand Down Expand Up @@ -36,9 +37,9 @@ final class StencilTemplate: StencilSwiftKit.StencilSwiftTemplate, Template {
ext.registerBoolFilterWithArguments("hasPrefix", filter: { (s1: String, s2) in s1.hasPrefix(s2) })
ext.registerBoolFilterWithArguments("hasSuffix", filter: { (s1: String, s2) in s1.hasSuffix(s2) })

ext.registerBoolFilter("computed", filter: { (v: Variable) in v.isComputed && !v.isStatic })
ext.registerBoolFilter("stored", filter: { (v: Variable) in !v.isComputed && !v.isStatic })
ext.registerBoolFilter("tuple", filter: { (v: Variable) in v.isTuple })
ext.registerBoolFilter("computed", filter: { (v: SourceryVariable) in v.isComputed && !v.isStatic })
ext.registerBoolFilter("stored", filter: { (v: SourceryVariable) in !v.isComputed && !v.isStatic })
ext.registerBoolFilter("tuple", filter: { (v: SourceryVariable) in v.isTuple })

ext.registerAccessLevelFilters(.open)
ext.registerAccessLevelFilters(.public)
Expand All @@ -58,20 +59,20 @@ final class StencilTemplate: StencilSwiftKit.StencilSwiftTemplate, Template {

ext.registerBoolFilter("enum", filter: { (t: Type) in t is Enum })
ext.registerBoolFilter("struct", filter: { (t: Type) in t is Struct })
ext.registerBoolFilter("protocol", filter: { (t: Type) in t is Protocol })
ext.registerBoolFilter("protocol", filter: { (t: Type) in t is SourceryProtocol })

ext.registerFilter("count", filter: count)

ext.registerBoolFilter("initializer", filter: { (m: Method) in m.isInitializer })
ext.registerBoolFilter("initializer", filter: { (m: SourceryMethod) in m.isInitializer })
ext.registerBoolFilterOr("class",
filter: { (t: Type) in t is Class },
other: { (m: Method) in m.isClass })
other: { (m: SourceryMethod) in m.isClass })
ext.registerBoolFilterOr("static",
filter: { (v: Variable) in v.isStatic },
other: { (m: Method) in m.isStatic })
filter: { (v: SourceryVariable) in v.isStatic },
other: { (m: SourceryMethod) in m.isStatic })
ext.registerBoolFilterOr("instance",
filter: { (v: Variable) in !v.isStatic },
other: { (m: Method) in !(m.isStatic || m.isClass) })
filter: { (v: SourceryVariable) in !v.isStatic },
other: { (m: SourceryMethod) in !(m.isStatic || m.isClass) })

ext.registerBoolFilterWithArguments("annotated", filter: { (a: Annotated, annotation) in a.isAnnotated(with: annotation) })

Expand Down Expand Up @@ -138,16 +139,16 @@ extension Stencil.Extension {
func registerAccessLevelFilters(_ accessLevel: AccessLevel) {
registerBoolFilterOr(accessLevel.rawValue,
filter: { (t: Type) in t.accessLevel == accessLevel.rawValue && t.accessLevel != AccessLevel.none.rawValue },
other: { (m: Method) in m.accessLevel == accessLevel.rawValue && m.accessLevel != AccessLevel.none.rawValue }
other: { (m: SourceryMethod) in m.accessLevel == accessLevel.rawValue && m.accessLevel != AccessLevel.none.rawValue }
)
registerBoolFilterOr("!\(accessLevel.rawValue)",
filter: { (t: Type) in t.accessLevel != accessLevel.rawValue && t.accessLevel != AccessLevel.none.rawValue },
other: { (m: Method) in m.accessLevel != accessLevel.rawValue && m.accessLevel != AccessLevel.none.rawValue }
other: { (m: SourceryMethod) in m.accessLevel != accessLevel.rawValue && m.accessLevel != AccessLevel.none.rawValue }
)
registerBoolFilter("\(accessLevel.rawValue)Get", filter: { (v: Variable) in v.readAccess == accessLevel.rawValue && v.readAccess != AccessLevel.none.rawValue })
registerBoolFilter("!\(accessLevel.rawValue)Get", filter: { (v: Variable) in v.readAccess != accessLevel.rawValue && v.readAccess != AccessLevel.none.rawValue })
registerBoolFilter("\(accessLevel.rawValue)Set", filter: { (v: Variable) in v.writeAccess == accessLevel.rawValue && v.writeAccess != AccessLevel.none.rawValue })
registerBoolFilter("!\(accessLevel.rawValue)Set", filter: { (v: Variable) in v.writeAccess != accessLevel.rawValue && v.writeAccess != AccessLevel.none.rawValue })
registerBoolFilter("\(accessLevel.rawValue)Get", filter: { (v: SourceryVariable) in v.readAccess == accessLevel.rawValue && v.readAccess != AccessLevel.none.rawValue })
registerBoolFilter("!\(accessLevel.rawValue)Get", filter: { (v: SourceryVariable) in v.readAccess != accessLevel.rawValue && v.readAccess != AccessLevel.none.rawValue })
registerBoolFilter("\(accessLevel.rawValue)Set", filter: { (v: SourceryVariable) in v.writeAccess == accessLevel.rawValue && v.writeAccess != AccessLevel.none.rawValue })
registerBoolFilter("!\(accessLevel.rawValue)Set", filter: { (v: SourceryVariable) in v.writeAccess != accessLevel.rawValue && v.writeAccess != AccessLevel.none.rawValue })
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//

import Foundation
import SourceryRuntime

/// Extends type so that inner types can be accessed via KVC e.g. Parent.Inner.Children
extension Type {
Expand Down
23 changes: 0 additions & 23 deletions Sourcery/Generating/Template/Swift/SwiftTemplate+Runtime.swift

This file was deleted.

Loading

0 comments on commit 4e92079

Please sign in to comment.