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

Adjusted file structure to accommodate two generated files #1299

Merged
merged 46 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1ccd370
Adjusted file structure to accommodate two generated files
art-divin Mar 11, 2024
0d077e8
Adjusted scripting
art-divin Mar 11, 2024
62eb306
Removed Description, Diffable, Equality for now
art-divin Mar 11, 2024
89609d6
Removed Stencil import
art-divin Mar 11, 2024
31c3d10
Updated templates
art-divin Mar 11, 2024
35e8d54
Updated scripting
art-divin Mar 11, 2024
77530f3
Updated generated coding
art-divin Mar 11, 2024
aa6212b
Disable build deletion (temp)
art-divin Mar 11, 2024
6373ea1
Updated template
art-divin Mar 11, 2024
93b3645
Updated generated code
art-divin Mar 11, 2024
38a5c57
updated generated code
art-divin Mar 11, 2024
0696104
Updated generated code
art-divin Mar 11, 2024
981a5f4
Adjusted scripting
art-divin Mar 11, 2024
f7f7148
Updated scripting
art-divin Mar 11, 2024
416bbb1
Updated generated code
art-divin Mar 11, 2024
8b7d715
Reverted template deletion
art-divin Mar 11, 2024
7a92e4f
Removed Stencil imports
art-divin Mar 11, 2024
5ae9b3b
Updated generated code
art-divin Mar 11, 2024
a07dc58
trigger CI
art-divin Mar 11, 2024
07abfe1
Removed description, diffable and equality stencil templates
art-divin Mar 11, 2024
442b4e7
Reverted temporary changes
art-divin Mar 11, 2024
d11d753
Commented failing tests
art-divin Mar 11, 2024
06d41eb
Skipping JSExport for description & hash
art-divin Mar 11, 2024
a58ab4e
Updated generated code
art-divin Mar 11, 2024
3110e80
Enabled failing tests
art-divin Mar 11, 2024
a350be9
Adding stencil templates back to test tests
art-divin Mar 12, 2024
8c5bb4d
Reset generated file for linux for test
art-divin Mar 12, 2024
78e3269
Reverted Extensions for testing
art-divin Mar 12, 2024
b224c17
Reverted ParserResultsComposed
art-divin Mar 12, 2024
ed49d33
Attempt to fix unit tests
art-divin Mar 12, 2024
ab65a84
Attempt to resolve unit test
art-divin Mar 12, 2024
7c29ee1
Reverted TypeName asSource
art-divin Mar 12, 2024
a210a17
Reverted TypeName revertion
art-divin Mar 12, 2024
2b8211d
Reverted revert of ParserResultComposed
art-divin Mar 12, 2024
aa8afdb
Reverted revert of Extensions
art-divin Mar 12, 2024
0fd642b
Reverted revert of Linux.content.generated
art-divin Mar 12, 2024
0d55f60
Reverted attempts to fix unit tests
art-divin Mar 12, 2024
c9cf66f
Fix for the failing codegen tests
art-divin Mar 12, 2024
16dedf5
Added clarifying comment
art-divin Mar 12, 2024
7f49d45
Removed description, diffable and equality stencil templates
art-divin Mar 12, 2024
4a07114
Updated generated code
art-divin Mar 12, 2024
e52c32d
Tinkering with optimization level for speed boost
art-divin Mar 12, 2024
86a0a05
Excluded stencil templates for codegen
art-divin Mar 12, 2024
c339133
Fixed wrong compiler flag
art-divin Mar 12, 2024
8761300
Removed speed optimization to a separate PR
art-divin Mar 12, 2024
d59503f
Reverted test code
art-divin Mar 12, 2024
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
10 changes: 10 additions & 0 deletions .sourcery-macOS.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sources:
- SourceryRuntime/Sources/Common
- SourceryRuntime/Sources/macOS
templates:
- Sourcery/Templates/Coding.stencil
- Sourcery/Templates/JSExport.ejs
- Sourcery/Templates/Typed.stencil
- Sourcery/Templates/TypedSpec.stencil
output:
SourceryRuntime/Sources/Generated
10 changes: 10 additions & 0 deletions .sourcery-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sources:
- SourceryRuntime/Sources/Common
- SourceryRuntime/Sources/Linux
templates:
- Sourcery/Templates/Coding.stencil
- Sourcery/Templates/JSExport.ejs
- Sourcery/Templates/Typed.stencil
- Sourcery/Templates/TypedSpec.stencil
output:
SourceryRuntime/Sources/Generated
6 changes: 0 additions & 6 deletions .sourcery.yml

This file was deleted.

8 changes: 5 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ end

task :run_sourcery do
print_info "Generating internal boilerplate code"
sh "#{CLI_DIR}bin/sourcery"
sh "#{CLI_DIR}bin/sourcery --config .sourcery-macOS.yml"
sh "#{CLI_DIR}bin/sourcery --config .sourcery-ubuntu.yml"
end

desc "Update internal boilerplate code"
task :generate_internal_boilerplate_code => [:fat_build, :run_sourcery, :clean] do
sh "Scripts/package_content \"SourceryRuntime/Sources\" > \"SourcerySwift/Sources/SourceryRuntime.content.generated.swift\""
task :generate_internal_boilerplate_code => [:build, :run_sourcery] do
sh "Scripts/package_content \"SourceryRuntime/Sources/Common,SourceryRuntime/Sources/macOS,SourceryRuntime/Sources/Generated\" \"true\" > \"SourcerySwift/Sources/SourceryRuntime.content.generated.swift\""
sh "Scripts/package_content \"SourceryRuntime/Sources/Common,SourceryRuntime/Sources/Linux,SourceryRuntime/Sources/Generated\" \"false\" > \"SourcerySwift/Sources/SourceryRuntime_Linux.content.generated.swift\""
generated_files = `git status --porcelain`
.split("\n")
.select { |item| item.include?('.generated.') }
Expand Down
71 changes: 43 additions & 28 deletions Scripts/package_content
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
/// Merge all Swift files contained in FOLDER into swift code that can be used by the FolderSynchronizer.
/// Example: $0 Sources/SourceryRuntime > file.swift
/// Options:
/// FOLDER: the path where the Swift files to merge are
/// FOLDERS: the paths where the Swift files to merge are, separated with comma ","
/// isForDarwinPlatform: if true, the generated code will be compilable on Darwin platforms
/// -h: Display this help message
import Foundation

Expand Down Expand Up @@ -40,37 +41,45 @@ extension String {
}
}

func package(folder folderPath: String) throws {
func package(folders folderPaths: [String], isForDarwinPlatform: Bool) throws {
if !isForDarwinPlatform {
print("#if !canImport(ObjectiveC)")
} else {
print("#if canImport(ObjectiveC)")
}
print("let sourceryRuntimeFiles: [FolderSynchronizer.File] = [")
let folderURL = URL(fileURLWithPath: folderPath)
for folderPath in folderPaths {
let folderURL = URL(fileURLWithPath: folderPath)

guard let enumerator = FileManager.default.enumerator(at: folderURL, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) else {
print("Unable to retrieve file enumerator")
exit(1)
}
var files = [URL]()
for case let fileURL as URL in enumerator {
do {
let fileAttributes = try fileURL.resourceValues(forKeys:[.isRegularFileKey])
if fileAttributes.isRegularFile! {
files.append(fileURL)
guard let enumerator = FileManager.default.enumerator(at: folderURL, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) else {
print("Unable to retrieve file enumerator")
exit(1)
}
var files = [URL]()
for case let fileURL as URL in enumerator {
do {
let fileAttributes = try fileURL.resourceValues(forKeys:[.isRegularFileKey])
if fileAttributes.isRegularFile! {
files.append(fileURL)
}
} catch {
print(error, fileURL)
}
} catch {
print(error, fileURL)
}

try files
.sorted(by: { $0.lastPathComponent < $1.lastPathComponent })
.forEach { sourceFileURL in
print(" .init(name: \"\(sourceFileURL.lastPathComponent)\", content:")
print("\"\"\"")
let content = try String(contentsOf: sourceFileURL, encoding: .utf8)
.escapedSwiftTokens()
print(content)
print("\"\"\"),")
}
}

try files
.sorted(by: { $0.lastPathComponent < $1.lastPathComponent })
.forEach { sourceFileURL in
print(" .init(name: \"\(sourceFileURL.lastPathComponent)\", content:")
print("\"\"\"")
let content = try String(contentsOf: sourceFileURL, encoding: .utf8)
.escapedSwiftTokens()
print(content)
print("\"\"\"),")
}
print("]")
print("#endif")
}

func main() {
Expand All @@ -82,10 +91,16 @@ func main() {
print("Missing folderPath argument")
exit(1)
}
let folder = CommandLine.arguments[1]
guard CommandLine.arguments.count > 2 else {
print("Missing isForDarwinPlatform argument")
exit(1)
}
let foldersPaths = CommandLine.arguments[1]
let isForDarwinPlatform = Bool(CommandLine.arguments[2]) ?? false
let folders = foldersPaths.split(separator: ",").map(String.init)

do {
try package(folder: folder)
try package(folders: folders, isForDarwinPlatform: isForDarwinPlatform)
} catch {
print("Failed with error: \(error)")
exit(1)
Expand Down
2 changes: 2 additions & 0 deletions Sourcery/Templates/JSExport.ejs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// swiftlint:disable vertical_whitespace trailing_newline

#if canImport(JavaScriptCore)
import JavaScriptCore

<%_ for (type of types.implementing.AutoJSExport) { -%>
Expand All @@ -15,3 +16,4 @@ import JavaScriptCore
extension <%= type.name %>: <%= type.name %>AutoJSExport {}
<%_ } %>
<%_ } %>
#endif
2 changes: 2 additions & 0 deletions Sourcery/Templates/Typed.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ extension {{ type.name }} {
{{ type.accessLevel }} var isClosure: Bool { return typeName.isClosure }
/// Whether type is an array. Shorthand for `typeName.isArray`
{{ type.accessLevel }} var isArray: Bool { return typeName.isArray }
/// Whether type is a set. Shorthand for `typeName.isSet`
{{ type.accessLevel }} var isSet: Bool { return typeName.isSet }
/// Whether type is a dictionary. Shorthand for `typeName.isDictionary`
{{ type.accessLevel }} var isDictionary: Bool { return typeName.isDictionary }
}{% endfor %}
2 changes: 2 additions & 0 deletions Sourcery/Templates/TypedSpec.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class TypedSpec: QuickSpec {
return variable?.typeName ?? TypeName(name: "")
}

#if canImport(ObjectiveC)
it("can report optional via KVC") {
expect({{ type.name }}(typeName: typeName("Int?")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect({{ type.name }}(typeName: typeName("Int!")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
Expand Down Expand Up @@ -68,6 +69,7 @@ class TypedSpec: QuickSpec {
sut.typeName.actualTypeName = typeName("Int")
expect(sut.value(forKeyPath: "actualTypeName") as? TypeName).to(equal(typeName("Int")))
}
#endif
}
{% endfor %}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public final class Actor: Type {

/// Whether type is final
public var isFinal: Bool {
return modifiers.contains { $0.name == "final" }
modifiers.contains { $0.name == "final" }
}

/// :nodoc:
Expand Down Expand Up @@ -54,11 +54,12 @@ public final class Actor: Type {
}

/// :nodoc:
// sourcery: skipJSExport
override public var description: String {
var string = super.description
string += ", "
string += "kind = \(String(describing: self.kind)), "
string += "isFinal = \(String(describing: self.isFinal))"
string.append(", ")
string.append("kind = \(String(describing: self.kind)), ")
string.append("isFinal = \(String(describing: self.isFinal))")
return string
}

Expand All @@ -72,6 +73,8 @@ public final class Actor: Type {
return results
}

/// :nodoc:
// sourcery: skipJSExport
public override var hash: Int {
var hasher = Hasher()
hasher.combine(super.hash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ
return results
}

/// :nodoc:
// sourcery: skipJSExport
public override var hash: Int {
var hasher = Hasher()
hasher.combine(self.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public final class Class: Type {

/// Whether type is final
public var isFinal: Bool {
return modifiers.contains { $0.name == "final" }
modifiers.contains { $0.name == "final" }
}

/// :nodoc:
Expand Down Expand Up @@ -53,11 +53,12 @@ public final class Class: Type {
}

/// :nodoc:
// sourcery: skipJSExport
override public var description: String {
var string = super.description
string += ", "
string += "kind = \(String(describing: self.kind)), "
string += "isFinal = \(String(describing: self.isFinal))"
string.append(", ")
string.append("kind = \(String(describing: self.kind)), ")
string.append("isFinal = \(String(describing: self.isFinal))")
return string
}

Expand All @@ -71,6 +72,8 @@ public final class Class: Type {
return results
}

/// :nodoc:
// sourcery: skipJSExport
public override var hash: Int {
var hasher = Hasher()
hasher.combine(super.hash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class Import: NSObject, SourceryModelWithoutDescription, Diffable {
return results
}

/// :nodoc:
// sourcery: skipJSExport
public override var hash: Int {
var hasher = Hasher()
hasher.combine(self.kind)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class Modifier: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJS
return results
}

/// :nodoc:
// sourcery: skipJSExport
public override var hash: Int {
var hasher = Hasher()
hasher.combine(self.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public final class Protocol: Type {
}
}

// sourcery: skipCoding
/// list of generic requirements
public override var genericRequirements: [GenericRequirement] {
didSet {
Expand Down Expand Up @@ -75,11 +76,12 @@ public final class Protocol: Type {
}

/// :nodoc:
// sourcery: skipJSExport
override public var description: String {
var string = super.description
string += ", "
string += "kind = \(String(describing: self.kind)), "
string += "associatedTypes = \(String(describing: self.associatedTypes)), "
string.append(", ")
string.append("kind = \(String(describing: self.kind)), ")
string.append("associatedTypes = \(String(describing: self.associatedTypes)), ")
return string
}

Expand All @@ -94,6 +96,8 @@ public final class Protocol: Type {
return results
}

/// :nodoc:
// sourcery: skipJSExport
public override var hash: Int {
var hasher = Hasher()
hasher.combine(self.associatedTypes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public final class ProtocolComposition: Type {
}

/// :nodoc:
// sourcery: skipJSExport
override public var description: String {
var string = super.description
string += ", "
Expand All @@ -75,6 +76,8 @@ public final class ProtocolComposition: Type {
return results
}

/// :nodoc:
// sourcery: skipJSExport
public override var hash: Int {
var hasher = Hasher()
hasher.combine(self.composedTypeNames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public final class Struct: Type {
}

/// :nodoc:
// sourcery: skipJSExport
override public var description: String {
var string = super.description
string += ", "
Expand All @@ -75,6 +76,8 @@ public final class Struct: Type {
return results
}

/// :nodoc:
// sourcery: skipJSExport
public override var hash: Int {
var hasher = Hasher()
hasher.combine(super.hash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ public final class ArrayType: NSObject, SourceryModel, Diffable {
}

/// :nodoc:
// sourcery: skipJSExport
override public var description: String {
var string = "\(Swift.type(of: self)): "
string += "name = \(String(describing: self.name)), "
string += "elementTypeName = \(String(describing: self.elementTypeName)), "
string += "asGeneric = \(String(describing: self.asGeneric)), "
string += "asSource = \(String(describing: self.asSource))"
string.append("name = \(String(describing: self.name)), ")
string.append("elementTypeName = \(String(describing: self.elementTypeName)), ")
string.append("asGeneric = \(String(describing: self.asGeneric)), ")
string.append("asSource = \(String(describing: self.asSource))")
return string
}

Expand All @@ -54,6 +55,8 @@ public final class ArrayType: NSObject, SourceryModel, Diffable {
return results
}

/// :nodoc:
// sourcery: skipJSExport
public override var hash: Int {
var hasher = Hasher()
hasher.combine(self.name)
Expand Down
Loading
Loading